gt:         if (m_highlighting == null) {
context: /*
   * This library is part of OpenCms -
   * the Open Source Content Management System
   *
   * Copyright (c) Alkacon Software GmbH (http://www.alkacon.com)
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
   * This library is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   * Lesser General Public License for more details.
   *
   * For further information about Alkacon Software, please see the
   * company website: http://www.alkacon.com
   *
   * For further information about OpenCms, please see the
   * project website: http://www.opencms.org
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this library; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
  
  package org.opencms.ade.containerpage.client.ui;
  
  import org.opencms.acacia.client.CmsEditorBase;
  import org.opencms.acacia.client.I_CmsInlineFormParent;
  import org.opencms.ade.containerpage.client.CmsContainerpageController;
  import org.opencms.ade.containerpage.client.ui.css.I_CmsLayoutBundle;
  import org.opencms.ade.containerpage.shared.CmsInheritanceInfo;
  import org.opencms.ade.contenteditor.client.CmsContentEditor;
  import org.opencms.gwt.client.dnd.I_CmsDraggable;
  import org.opencms.gwt.client.dnd.I_CmsDropTarget;
  import org.opencms.gwt.client.ui.CmsHighlightingBorder;
  import org.opencms.gwt.client.ui.CmsListItemWidget;
  import org.opencms.gwt.client.ui.css.I_CmsImageBundle;
  import org.opencms.gwt.client.util.CmsDomUtil;
  import org.opencms.gwt.client.util.CmsDomUtil.Tag;
  import org.opencms.gwt.client.util.CmsPositionBean;
  import org.opencms.gwt.shared.CmsListInfoBean;
  import org.opencms.util.CmsStringUtil;
  import org.opencms.util.CmsUUID;
  
  import java.util.Arrays;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import java.util.Map.Entry;
  
  import com.google.common.collect.Lists;
  import com.google.gwt.core.client.JavaScriptObject;
  import com.google.gwt.core.client.Scheduler;
  import com.google.gwt.core.client.Scheduler.ScheduledCommand;
  import com.google.gwt.dom.client.Element;
  import com.google.gwt.dom.client.NodeList;
  import com.google.gwt.dom.client.Style;
  import com.google.gwt.dom.client.Style.Display;
  import com.google.gwt.dom.client.Style.Position;
  import com.google.gwt.dom.client.Style.Unit;
  import com.google.gwt.event.dom.client.ClickEvent;
  import com.google.gwt.event.dom.client.ClickHandler;
  import com.google.gwt.event.dom.client.HasClickHandlers;
  import com.google.gwt.event.shared.HandlerRegistration;
  import com.google.gwt.user.client.DOM;
  import com.google.gwt.user.client.Event;
  import com.google.gwt.user.client.Event.NativePreviewEvent;
  import com.google.gwt.user.client.Event.NativePreviewHandler;
  import com.google.gwt.user.client.Timer;
  import com.google.gwt.user.client.ui.AbsolutePanel;
  import com.google.gwt.user.client.ui.Image;
  import com.google.gwt.user.client.ui.IsWidget;
  import com.google.gwt.user.client.ui.RootPanel;
  
  /**
   * Content element within a container-page.<p>
   *
   * @since 8.0.0
   */
  public class CmsContainerPageElementPanel extends AbsolutePanel
  implements I_CmsDraggable, HasClickHandlers, I_CmsInlineFormParent {
  
      /** Highlighting border for this element. */
      protected CmsHighlightingBorder m_highlighting;
  
      /** A flag which indicates whether the height has already been checked. */
      private boolean m_checkedHeight;
  
      /** Flag indicating the the editables are currently being checked. */
      private boolean m_checkingEditables;
  
      /** The elements client id. */
      private String m_clientId;
  
      /** The 'create new' flag. */
      private boolean m_createNew;
  
      /**
       * Flag which indicates whether the new editor is disabled for this element.<p>
       */
      private boolean m_disableNewEditor;
  
      /** The direct edit bar instances. */
      private Map<Element, CmsListCollectorEditor> m_editables;
  
      /** The editor click handler registration. */
      private HandlerRegistration m_editorClickHandlerRegistration;
  
      /** The option bar, holding optional function buttons. */
      private CmsElementOptionBar m_elementOptionBar;
  
      /** The element element view. */
      private CmsUUID m_elementView;
  
      /** The overlay for expired elements. */
      private Element m_expiredOverlay;
  
      /** Indicates whether this element has settings to edit. */
      private boolean m_hasSettings;
  
      /** The inheritance info for this element. */
      private CmsInheritanceInfo m_inheritanceInfo;
  
      /** The is new element type. */
      private String m_newType;
  
      /** The registered node insert event handler. */
      private JavaScriptObject m_nodeInsertHandler;
  
      /** The no edit reason, if empty editing is allowed. */
      private String m_noEditReason;
  
      /** The parent drop target. */
      private I_CmsDropContainer m_parent;
  
      /** The drag and drop parent div. */
      private Element m_provisionalParent;
  
      /** Flag indicating if the element resource is currently released and not expired. */
      private boolean m_releasedAndNotExpired;
  
      /** The resource type. */
      private String m_resourceType;
  
      /** The element resource site-path. */
      private String m_sitePath;
  
      /** The sub title. */
      private String m_subTitle;
  
      /** The resource title. */
      private String m_title;
  
      /**
       * Indicates if the current user has view permissions on the element resource.
       * Without view permissions, the element can neither be edited, nor moved.
       **/
      private boolean m_viewPermission;
  
      /**
       * Indicates if the current user has write permissions on the element resource.
       * Without write permissions, the element can not be edited.
       **/
      private boolean m_writePermission;
  
      /**
       * Constructor.<p>
       *
       * @param element the DOM element
       * @param parent the drag parent
       * @param clientId the client id
       * @param sitePath the element site-path
       * @param noEditReason the no edit reason, if empty, editing is allowed
       * @param title the resource title
       * @param subTitle the sub title
       * @param resourceType the resource type
       * @param hasSettings should be true if the element has settings which can be edited
       * @param hasViewPermission indicates if the current user has view permissions on the element resource
       * @param hasWritePermission indicates if the current user has write permissions on the element resource
       * @param releasedAndNotExpired <code>true</code> if the element resource is currently released and not expired
       * @param disableNewEditor flag to disable the new editor for this element
       * @param elementView theelement view of the element
       */
      public CmsContainerPageElementPanel(
          Element element,
          I_CmsDropContainer parent,
          String clientId,
          String sitePath,
          String noEditReason,
          String title,
          String subTitle,
          String resourceType,
          boolean hasSettings,
          boolean hasViewPermission,
          boolean hasWritePermission,
          boolean releasedAndNotExpired,
          boolean disableNewEditor,
          CmsUUID elementView) {
  
          super(element);
          m_clientId = clientId;
          m_sitePath = sitePath;
          m_title = title;
          m_subTitle = subTitle;
          m_resourceType = resourceType;
          m_noEditReason = noEditReason;
          m_hasSettings = hasSettings;
          m_parent = parent;
          m_disableNewEditor = disableNewEditor;
          setViewPermission(hasViewPermission);
          setWritePermission(hasWritePermission);
          setReleasedAndNotExpired(releasedAndNotExpired);
          getElement().addClassName(I_CmsLayoutBundle.INSTANCE.dragdropCss().dragElement());
          m_elementView = elementView;
      }
  
      /**
       * Checks if the element is an overlay for a container page element.<p>
       *
       * @param element the element to check
       * @return true if the element is an overlay
       */
      public static boolean isOverlay(Element element) {
  
          for (String overlayClass : Arrays.asList(
              I_CmsLayoutBundle.INSTANCE.containerpageCss().expiredOverlay(),
              CmsElementOptionBar.CSS_CLASS)) {
              if (element.hasClassName(overlayClass)) {
                  return true;
              }
          }
          return false;
  
      }
  
      /**
       * @see com.google.gwt.event.dom.client.HasClickHandlers#addClickHandler(com.google.gwt.event.dom.client.ClickHandler)
       */
      public HandlerRegistration addClickHandler(ClickHandler handler) {
  
          return addDomHandler(handler, ClickEvent.getType());
      }
  
      /**
       * @see org.opencms.acacia.client.I_CmsInlineFormParent#adoptWidget(com.google.gwt.user.client.ui.IsWidget)
       */
      public void adoptWidget(IsWidget widget) {
  
          getChildren().add(widget.asWidget());
          adopt(widget.asWidget());
      }
  
      /**
       * @see org.opencms.gwt.client.dnd.I_CmsDraggable#getDragHelper(org.opencms.gwt.client.dnd.I_CmsDropTarget)
       */
      public Element getDragHelper(I_CmsDropTarget target) {
  
          CmsListInfoBean info = new CmsListInfoBean(m_title, m_subTitle, null);
          info.setResourceType(m_resourceType);
          CmsListItemWidget helperWidget = new CmsListItemWidget(info);
          helperWidget.setWidth("600px");
          helperWidget.truncate("ggg", 550);
          Element helper = helperWidget.getElement();
          Element button = DOM.createDiv();
          button.appendChild((new Image(I_CmsImageBundle.INSTANCE.icons().moveIconActive())).getElement());
          button.addClassName(I_CmsLayoutBundle.INSTANCE.dragdropCss().dragHandle());
          helper.appendChild(button);
          helper.addClassName(org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.generalCss().shadow());
          Element parentElement = getElement().getParentElement();
          int elementTop = getElement().getAbsoluteTop();
          int parentTop = parentElement.getAbsoluteTop();
          m_provisionalParent = DOM.createElement(parentElement.getTagName());
          RootPanel.getBodyElement().appendChild(m_provisionalParent);
          m_provisionalParent.addClassName(
              org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.generalCss().clearStyles());
          m_provisionalParent.getStyle().setWidth(parentElement.getOffsetWidth(), Unit.PX);
          m_provisionalParent.appendChild(helper);
          Style style = helper.getStyle();
          style.setWidth(helper.getOffsetWidth(), Unit.PX);
          // the dragging class will set position absolute
          helper.addClassName(org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.listItemWidgetCss().dragging());
          style.setTop(elementTop - parentTop, Unit.PX);
          m_provisionalParent.getStyle().setPosition(Position.ABSOLUTE);
          m_provisionalParent.getStyle().setTop(parentTop, Unit.PX);
          m_provisionalParent.getStyle().setLeft(parentElement.getAbsoluteLeft(), Unit.PX);
          m_provisionalParent.getStyle().setZIndex(I_CmsLayoutBundle.INSTANCE.constants().css().zIndexDND());
  
          return helper;
      }
  
      /**
       * Returns the option bar of this element.<p>
       *
       * @return the option bar widget
       */
      public CmsElementOptionBar getElementOptionBar() {
  
          return m_elementOptionBar;
      }
  
      /**
       * Returns the elements element view.<p>
       *
       * @return the element view
       */
      public CmsUUID getElementView() {
  
          return m_elementView;
      }
  
      /**
       * @see org.opencms.gwt.client.dnd.I_CmsDraggable#getId()
       */
      public String getId() {
  
          return m_clientId;
      }
  
      /**
       * Returns the inheritance info for this element.<p>
       *
       * @return the inheritance info for this element
       */
      public CmsInheritanceInfo getInheritanceInfo() {
  
          return m_inheritanceInfo;
      }
  
      /**
       * Returns the new element type.
       *
       * @return the new element type
       */
      public String getNewType() {
  
          return m_newType;
      }
  
      /**
       * Returns the no edit reason.<p>
       *
       * @return the no edit reason
       */
      public String getNoEditReason() {
  
          return m_noEditReason;
      }
  
      /**
       * @see org.opencms.gwt.client.dnd.I_CmsDraggable#getParentTarget()
       */
      public I_CmsDropContainer getParentTarget() {
  
          return m_parent;
      }
  
      /**
       * @see org.opencms.gwt.client.dnd.I_CmsDraggable#getPlaceholder(org.opencms.gwt.client.dnd.I_CmsDropTarget)
       */
      public Element getPlaceholder(I_CmsDropTarget target) {
  
          Element placeholder = CmsDomUtil.clone(getElement());
          placeholder.addClassName(I_CmsLayoutBundle.INSTANCE.dragdropCss().dragPlaceholder());
          return placeholder;
      }
  
      /**
       * Returns if the element resource is currently released and not expired.<p>
       *
       * @return <code>true</code> if the element resource is currently released and not expired
       */
      public boolean getReleasedAndNotExpired() {
  
          return m_releasedAndNotExpired;
      }
  
      /**
       * Returns the site-path.<p>
       *
       * @return the site-path
       */
      public String getSitePath() {
  
          return m_sitePath;
      }
  
      /**
       * Returns the structure id of the element.<p>
       *
       * @return the structure id of the element
       */
      public CmsUUID getStructureId() {
  
          if (m_clientId == null) {
              return null;
          }
          return new CmsUUID(CmsContainerpageController.getServerId(m_clientId));
      }
  
      /**
       * Returns true if the element has settings to edit.<p>
       *
       * @return true if the element has settings to edit
       */
      public boolean hasSettings() {
  
          return m_hasSettings;
      }
  
      /**
       * Returns if the current user has view permissions for the element resource.<p>
       *
       * @return <code>true</code> if the current user has view permissions for the element resource
       */
      public boolean hasViewPermission() {
  
          return m_viewPermission;
      }
  
      /**
       * Returns if the user has write permission.<p>
       *
       * @return <code>true</code> if the user has write permission
       */
      public boolean hasWritePermission() {
  
          return m_writePermission;
      }
  
      /**
       * Hides list collector direct edit buttons, if present.<p>
       */
      public void hideEditableListButtons() {
  
          if (m_editables != null) {
              for (CmsListCollectorEditor editor : m_editables.values()) {
                  editor.getElement().getStyle().setDisplay(Display.NONE);
              }
          }
      }
  
      /**
       * Puts a highlighting border around the element.<p>
       */
      public void highlightElement() {
  
  