001/*
002 * (C) Copyright 2006-2009 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     troger
016 */
017package org.nuxeo.ecm.platform.annotations.gwt.client;
018
019import org.nuxeo.ecm.platform.annotations.gwt.client.configuration.WebConfiguration;
020import org.nuxeo.ecm.platform.annotations.gwt.client.controler.AnnotationController;
021import org.nuxeo.ecm.platform.annotations.gwt.client.view.listener.AnnotatedEventListener;
022
023import com.allen_sauer.gwt.log.client.Log;
024import com.google.gwt.dom.client.Document;
025import com.google.gwt.user.client.DOM;
026import com.google.gwt.user.client.Event;
027
028/**
029 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
030 */
031public class AnnotationFrameApplication {
032
033    private static WebConfiguration WEB_CONFIGURATION;
034
035    private static AnnotationController controller;
036
037    private static AnnotatedEventListener annotatedEventListener;
038
039    public static AnnotationController getController() {
040        return controller;
041    }
042
043    public static AnnotatedEventListener getMainEventListener() {
044        return annotatedEventListener;
045    }
046
047    public static void build(WebConfiguration webConfiguration) {
048        WEB_CONFIGURATION = webConfiguration;
049        buildApplication();
050    }
051
052    private static void buildApplication() {
053        controller = new AnnotationController(WEB_CONFIGURATION, true);
054        annotatedEventListener = new AnnotatedEventListener(controller);
055        configureController();
056        setListeners();
057        controller.loadAnnotations();
058        notifyFrameModuleInitialized();
059    }
060
061    private static native void notifyFrameModuleInitialized() /*-{
062                                                              top['frameModuleInitialized'] = true;
063                                                              }-*/;
064
065    private static void configureController() {
066        PreviewSettings previewSettings = PreviewSettings.getInstance();
067        Log.debug("previewSettings = " + previewSettings);
068        if (previewSettings != null) {
069            controller.setImageOnly(previewSettings.isImageOnly());
070            controller.setMultiImage(previewSettings.isMultiImageAnnotation());
071            controller.setXPointerFilter(previewSettings.getXPointerFilterPath());
072            controller.setPointerAdapter(previewSettings.getPointerAdapter());
073            controller.setAnnotationDecoratorFunction(previewSettings.getAnnotationDecoratorFunction());
074        }
075        Document.get().getBody().setScrollTop(controller.getFrameScrollFromTop());
076    }
077
078    private static void setListeners() {
079        DOM.sinkEvents((com.google.gwt.user.client.Element) Document.get().cast(), Event.ONMOUSEMOVE | Event.ONCLICK
080                | Event.ONMOUSEDOWN | Event.ONMOUSEUP);
081        DOM.setEventListener((com.google.gwt.user.client.Element) Document.get().cast(), annotatedEventListener);
082    }
083
084}