001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.ade.contenteditor.widgetregistry.client; 029 030import org.opencms.acacia.client.widgets.I_CmsEditWidget; 031 032import com.google.gwt.core.client.JavaScriptObject; 033import com.google.gwt.dom.client.Element; 034 035/** 036 * Overlay object for native java script widgets.<p> 037 */ 038public final class NativeEditWidget extends JavaScriptObject { 039 040 /** 041 * Constructor.<p> 042 */ 043 protected NativeEditWidget() { 044 045 } 046 047 /** 048 * Wraps a GWT edit widget instance to be used from within another GWT module.<p> 049 * 050 * @param widget the widget to wrap 051 * @param isFormWidget in case of a form widget 052 * 053 * @return the wrapping native java script object 054 */ 055 public static native NativeEditWidget wrapWidget(I_CmsEditWidget widget, boolean isFormWidget)/*-{ 056 var nat = { 057 instance : widget 058 }; 059 nat.getElement = function() { 060 return this.instance.@org.opencms.acacia.client.widgets.I_CmsEditWidget::asWidget()().@com.google.gwt.user.client.ui.Widget::getElement()(); 061 } 062 nat.isActive = function() { 063 return this.instance.@org.opencms.acacia.client.widgets.I_CmsEditWidget::isActive()(); 064 } 065 nat.setActive = function(active) { 066 return this.instance.@org.opencms.acacia.client.widgets.I_CmsEditWidget::setActive(Z)(active); 067 } 068 nat.getValue = function() { 069 return this.instance.@org.opencms.acacia.client.widgets.I_CmsEditWidget::getValue()(); 070 } 071 nat.setValue = function(value, fireEvent) { 072 this.instance.@org.opencms.acacia.client.widgets.I_CmsEditWidget::setValue(Ljava/lang/String;Z)(value, fireEvent); 073 } 074 if (isFormWidget) { 075 nat.setWidgetInfo = function(label, help) { 076 this.instance.@org.opencms.acacia.client.widgets.I_CmsFormEditWidget::setWidgetInfo(Ljava/lang/String;Ljava/lang/String;)(label,help); 077 } 078 } else { 079 nat.setWidgetInfo = function() { 080 } 081 } 082 nat.onAttachWidget = function() { 083 this.instance.@org.opencms.acacia.client.widgets.I_CmsEditWidget::onAttachWidget()(); 084 } 085 nat.onChange = function() { 086 if (this.onChangeCommand != null) { 087 this.onChangeCommand(); 088 } 089 }; 090 nat.onFocus = function() { 091 if (this.onFocusCommand != null) { 092 this.onFocusCommand(); 093 } 094 }; 095 var nativeHandler = @org.opencms.ade.contenteditor.widgetregistry.client.NativeEditWidget::getNativeHandler(Lorg/opencms/ade/contenteditor/widgetregistry/client/NativeEditWidget;)(nat); 096 widget.@org.opencms.acacia.client.widgets.I_CmsEditWidget::addValueChangeHandler(Lcom/google/gwt/event/logical/shared/ValueChangeHandler;)(nativeHandler); 097 widget.@org.opencms.acacia.client.widgets.I_CmsEditWidget::addFocusHandler(Lcom/google/gwt/event/dom/client/FocusHandler;)(nativeHandler); 098 return nat; 099 }-*/; 100 101 /** 102 * Returns an event handler that delegates to a native java script object.<p> 103 * 104 * @param connector the native java script object 105 * 106 * @return the event handler 107 */ 108 private static NativeEventHandler getNativeHandler(NativeEditWidget connector) { 109 110 return new NativeEventHandler(connector); 111 } 112 113 public native boolean shouldSetDefaultWhenDisabled() /*-{ 114 return this.shouldSetDefaultWhenDisabled 115 && this.shouldSetDefaultWhenDisabled(); 116 }-*/; 117 118 /** 119 * Gets the display direction for popups used by this widget using the 'getDisplayingDirection' JavaScript method (or returns "none" if that method isn't available). 120 * 121 * @return the direction in which this widget displays popups ('above', 'below' or 'none') 122 */ 123 protected native String getDisplayingDirection() /*-{ 124 var result = null; 125 if (this.getDisplayingDirection) { 126 result = this.getDisplayingDirection(); 127 } 128 if (!result) { 129 result = "none"; 130 } 131 return result; 132 }-*/; 133 134 /** 135 * Returns the widget element.<p> 136 * 137 * @return the widget element 138 */ 139 protected native Element getElement() /*-{ 140 return this.getElement(); 141 }-*/; 142 143 /** 144 * Returns the widget value.<p> 145 * 146 * @return the widget value 147 */ 148 protected native String getValue()/*-{ 149 return this.getValue(); 150 }-*/; 151 152 /** 153 * Returns if the widget is active.<p> 154 * 155 * @return <code>true</code> if the widget is active 156 */ 157 protected native boolean isActive() /*-{ 158 return this.isActive(); 159 }-*/; 160 161 /** 162 * Call when the widget was added into the window document.<p> 163 */ 164 protected native void onAttachWidget()/*-{ 165 this.onAttachWidget(); 166 }-*/; 167 168 /** 169 * Sets the widget active.<p> 170 * 171 * @param active <code>true</code> to activate the widget 172 */ 173 protected native void setActive(boolean active)/*-{ 174 this.setActive(active); 175 }-*/; 176 177 /** 178 * Sets the widget value.<p> 179 * 180 * @param value the value 181 */ 182 protected native void setValue(String value)/*-{ 183 this.setValue(value, false); 184 }-*/; 185 186 /** 187 * Sets the widget value.<p> 188 * 189 * @param value the value 190 * @param fireEvent <code>true</code> to fire the value change event 191 */ 192 protected native void setValue(String value, boolean fireEvent)/*-{ 193 this.setValue(value, fireEvent); 194 }-*/; 195 196 /** 197 * Sets the widget label and help text.<p> 198 * 199 * @param label the widget label text 200 * @param help the widget help text 201 */ 202 protected native void setWidgetInfo(String label, String help)/*-{ 203 this.setWidgetInfo(label, help); 204 }-*/; 205}