001/*
002 * (C) Copyright 2006-2009 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     troger
018 */
019package org.nuxeo.ecm.platform.annotations.gwt.client;
020
021import org.nuxeo.ecm.platform.annotations.gwt.client.configuration.WebConfiguration;
022import org.nuxeo.ecm.platform.annotations.gwt.client.controler.AnnotationController;
023import org.nuxeo.ecm.platform.annotations.gwt.client.view.listener.AnnotatedEventListener;
024
025import com.allen_sauer.gwt.log.client.Log;
026import com.google.gwt.dom.client.Document;
027import com.google.gwt.user.client.DOM;
028import com.google.gwt.user.client.Event;
029
030/**
031 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
032 */
033public class AnnotationFrameApplication {
034
035    private static WebConfiguration WEB_CONFIGURATION;
036
037    private static AnnotationController controller;
038
039    private static AnnotatedEventListener annotatedEventListener;
040
041    public static AnnotationController getController() {
042        return controller;
043    }
044
045    public static AnnotatedEventListener getMainEventListener() {
046        return annotatedEventListener;
047    }
048
049    public static void build(WebConfiguration webConfiguration) {
050        WEB_CONFIGURATION = webConfiguration;
051        buildApplication();
052    }
053
054    private static void buildApplication() {
055        controller = new AnnotationController(WEB_CONFIGURATION, true);
056        annotatedEventListener = new AnnotatedEventListener(controller);
057        configureController();
058        setListeners();
059        controller.loadAnnotations();
060        notifyFrameModuleInitialized();
061    }
062
063    private static native void notifyFrameModuleInitialized() /*-{
064                                                              top['frameModuleInitialized'] = true;
065                                                              }-*/;
066
067    private static void configureController() {
068        PreviewSettings previewSettings = PreviewSettings.getInstance();
069        Log.debug("previewSettings = " + previewSettings);
070        if (previewSettings != null) {
071            controller.setImageOnly(previewSettings.isImageOnly());
072            controller.setMultiImage(previewSettings.isMultiImageAnnotation());
073            controller.setXPointerFilter(previewSettings.getXPointerFilterPath());
074            controller.setPointerAdapter(previewSettings.getPointerAdapter());
075            controller.setAnnotationDecoratorFunction(previewSettings.getAnnotationDecoratorFunction());
076        }
077        Document.get().getBody().setScrollTop(controller.getFrameScrollFromTop());
078    }
079
080    private static void setListeners() {
081        DOM.sinkEvents((com.google.gwt.user.client.Element) Document.get().cast(), Event.ONMOUSEMOVE | Event.ONCLICK
082                | Event.ONMOUSEDOWN | Event.ONMOUSEUP);
083        DOM.setEventListener((com.google.gwt.user.client.Element) Document.get().cast(), annotatedEventListener);
084    }
085
086}