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.I_CmsWidgetFactory;
031import org.opencms.acacia.client.widgets.I_CmsFormEditWidget;
032
033import com.google.gwt.dom.client.Element;
034
035/**
036 * Use this widget factory to use stand alone widgets.<p>
037 */
038public abstract class A_NativeWidgetFactory implements I_CmsWidgetFactory {
039
040    /**
041     * Exports the widget factory.<p>
042     */
043    public native void exportFactory()/*-{
044                                      var self = this;
045                                      $wnd[this.@org.opencms.ade.contenteditor.widgetregistry.client.A_NativeWidgetFactory::getInitCallName()()] = function() {
046                                      var factory = {
047                                      instance : self,
048                                      widgetName : self.@org.opencms.ade.contenteditor.widgetregistry.client.A_NativeWidgetFactory::getWidgetName()(),
049                                      createNativeWidget : function(configuration) {
050
051                                      return this.instance.@org.opencms.ade.contenteditor.widgetregistry.client.A_NativeWidgetFactory::createNativeWidget(Ljava/lang/String;)(configuration);
052                                      },
053                                      createNativeWrapedElement : function(configuration, element) {
054                                      return this.instance.@org.opencms.ade.contenteditor.widgetregistry.client.A_NativeWidgetFactory::createNativeWrapedElement(Ljava/lang/String;Lcom/google/gwt/dom/client/Element;)(configuration, element);
055                                      }
056                                      };
057
058                                      if ($wnd[@org.opencms.ade.contenteditor.widgetregistry.client.WidgetRegistry::REGISTER_WIDGET_FACTORY_FUNCTION] != null
059                                      && typeof $wnd[@org.opencms.ade.contenteditor.widgetregistry.client.WidgetRegistry::REGISTER_WIDGET_FACTORY_FUNCTION] == 'function') {
060                                      $wnd[@org.opencms.ade.contenteditor.widgetregistry.client.WidgetRegistry::REGISTER_WIDGET_FACTORY_FUNCTION]
061                                      (factory);
062                                      } else {
063                                      throw 'Registry not available';
064                                      }
065                                      }
066                                      }-*/;
067
068    /**
069     * Returns the name of the initialization call.<p>
070     *
071     * @return the name of the initialization call
072     */
073    protected abstract String getInitCallName();
074
075    /**
076     * Returns the widget name.<p>
077     *
078     * @return the widget name
079     */
080    protected abstract String getWidgetName();
081
082    /**
083     * Creates a widget wrapped in a native java script object.<p>
084     *
085     * @param configuration the widget configuration
086     *
087     * @return the wrapped widget
088     */
089    private NativeEditWidget createNativeWidget(String configuration) {
090
091        I_CmsFormEditWidget widget = createFormWidget(configuration);
092        return NativeEditWidget.wrapWidget(widget, true);
093    }
094
095    /**
096     * Creates a widget wrapped in a native java script object.<p>
097     *
098     * @param configuration the widget configuration
099     * @param element the element to use
100     *
101     * @return the wrapped widget
102     */
103    private NativeEditWidget createNativeWrapedElement(String configuration, Element element) {
104
105        return NativeEditWidget.wrapWidget(createInlineWidget(configuration, element), false);
106    }
107
108}