001/* 002 * (C) Copyright 2006-2008 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 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.platform.annotations.gwt.client; 023 024import org.nuxeo.ecm.platform.annotations.gwt.client.configuration.WebConfiguration; 025import org.nuxeo.ecm.platform.annotations.gwt.client.controler.AnnotationController; 026import org.nuxeo.ecm.platform.annotations.gwt.client.view.AnnotationManagerPanel; 027import org.nuxeo.ecm.platform.annotations.gwt.client.view.HideManagerButton; 028 029import com.google.gwt.dom.client.BaseElement; 030import com.google.gwt.dom.client.Document; 031import com.google.gwt.user.client.ui.DockPanel; 032import com.google.gwt.user.client.ui.Frame; 033import com.google.gwt.user.client.ui.RootPanel; 034 035/** 036 * @author <a href="mailto:[email protected]">Thomas Roger</a> 037 */ 038public class AnnotationApplication { 039 040 private static WebConfiguration WEB_CONFIGURATION; 041 042 private static DockPanel applicationPanel = new DockPanel(); 043 044 private static Frame PREVIEW_FRAME; 045 046 public static void build(WebConfiguration webConfiguration) { 047 WEB_CONFIGURATION = webConfiguration; 048 buildApplication(); 049 } 050 051 private static void buildApplication() { 052 AnnotationConfiguration annotationConfiguration = AnnotationConfiguration.getInstance(); 053 Document document = Document.get(); 054 BaseElement baseElement = document.getElementsByTagName("base").getItem(0).cast(); 055 registerBaseHref(baseElement.getHref()); 056 registerAnnoteaServerUrl(annotationConfiguration.getAnnoteaServerUrl()); 057 registerDocUrl(annotationConfiguration.getDocumentUrl()); 058 registerDateFormatPattern(annotationConfiguration.getDateFormatPattern()); 059 notifyAnnoteaServerUrlRegistered(); 060 061 applicationPanel.setStyleName("annotationApplicationPanel"); 062 applicationPanel.setWidth("100%"); 063 064 RootPanel display = RootPanel.get("display"); 065 String height = Integer.toString(display.getOffsetHeight()) + "px"; 066 applicationPanel.setHeight(height); 067 applicationPanel.setHorizontalAlignment(DockPanel.ALIGN_LEFT); 068 069 PREVIEW_FRAME = new Frame(annotationConfiguration.getPreviewUrl()); 070 PREVIEW_FRAME.setStyleName("previewFrame"); 071 PREVIEW_FRAME.setWidth("100%"); 072 PREVIEW_FRAME.setHeight(height); 073 applicationPanel.add(PREVIEW_FRAME, DockPanel.CENTER); 074 applicationPanel.setCellWidth(PREVIEW_FRAME, "100%"); 075 076 AnnotationController controller = new AnnotationController(WEB_CONFIGURATION, false); 077 AnnotationManagerPanel annotationManagerPanel = new AnnotationManagerPanel(controller, WEB_CONFIGURATION); 078 controller.addModelChangeListener(annotationManagerPanel); 079 080 HideManagerButton hideManagerButton = new HideManagerButton(controller, annotationManagerPanel, PREVIEW_FRAME); 081 082 annotationManagerPanel.setWidth("250px"); 083 applicationPanel.add(annotationManagerPanel, DockPanel.WEST); 084 085 hideManagerButton.setHeight(height); 086 applicationPanel.add(hideManagerButton, DockPanel.WEST); 087 088 display.add(applicationPanel); 089 090 controller.loadAnnotations(); 091 } 092 093 private static native void registerBaseHref(String baseHref) /*-{ 094 top['baseHref'] = baseHref; 095 }-*/; 096 097 private static native void registerAnnoteaServerUrl(String url) /*-{ 098 top['annoteaServerUrl'] = url; 099 }-*/; 100 101 private static native void notifyAnnoteaServerUrlRegistered() /*-{ 102 top['annoteaServerUrlRegistered'] = true; 103 }-*/; 104 105 private static native void registerDocUrl(String docUrl) /*-{ 106 top['docUrl'] = docUrl; 107 }-*/; 108 109 private static native void registerDateFormatPattern(String dateFormatPattern) /*-{ 110 top['dateFormatPattern'] = dateFormatPattern; 111 }-*/; 112 113}