| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Florian Pirchner <florian.pirchner@gmail.com> - Initial implementation |
| */ |
| package org.eclipse.osbp.vaadin.addons.designer.overlay.client; |
| |
| import org.eclipse.osbp.vaadin.addons.designer.overlay.client.widgets.AlignmentInfo; |
| import org.eclipse.osbp.vaadin.addons.designer.overlay.client.widgets.OAlignmentWidget; |
| import org.eclipse.osbp.vaadin.addons.designer.overlay.client.widgets.OButtonWidget; |
| |
| import com.google.gwt.user.client.ui.FlowPanel; |
| import com.vaadin.client.ui.VImage; |
| import com.vaadin.shared.ComponentConstants; |
| |
| /** |
| * Overlay for designer stuff. |
| */ |
| public class ODesignerOverlay extends OAbstractOverlay { |
| |
| /** The Constant CLASSNAME. */ |
| private static final String CLASSNAME = "o-designer-overlay"; |
| |
| /** The alignment widget. */ |
| private OAlignmentWidget alignmentWidget; |
| |
| /** The remove button. */ |
| private OButtonWidget removeButton; |
| |
| /** The root. */ |
| private FlowPanel root; |
| |
| /** The editable button. */ |
| private OButtonWidget editableButton; |
| |
| /** The open properties button. */ |
| private OButtonWidget openPropertiesButton; |
| |
| /** The margin button. */ |
| private OButtonWidget marginButton; |
| |
| /** The spacing button. */ |
| private OButtonWidget spacingButton; |
| |
| /** The add button. */ |
| private OButtonWidget addButton; |
| |
| /** |
| * Shows alignment lines for drag and resize operations. |
| */ |
| public ODesignerOverlay() { |
| |
| getElement().setClassName(CLASSNAME); |
| } |
| |
| /** |
| * Initialize. |
| * |
| * @param connector the connector |
| */ |
| private void initialize(DesignerExtensionConnector connector) { |
| root = new FlowPanel(); |
| add(root); |
| |
| if (connector.getResourceUrl(ComponentConstants.ICON_RESOURCE) != null) { |
| VImage image = new VImage(); |
| root.add(image); |
| String iconUrl = connector.getResourceUrl(ComponentConstants.ICON_RESOURCE); |
| image.setUrl(iconUrl); |
| } |
| |
| if (connector.getState().supportsAlignments) { |
| alignmentWidget = new OAlignmentWidget(); |
| alignmentWidget.setTitle(connector.getState().descriptionAlignments); |
| root.add(alignmentWidget); |
| alignmentWidget.setAlignmentChangedHandler(connector); |
| } |
| |
| if (connector.getState().supportsMargins) { |
| marginButton = new OButtonWidget(); |
| marginButton.addStyleName(OIConstants.EVENT_TYPE__SWITCH_MARGIN); |
| marginButton.setCustomEventType(OIConstants.EVENT_TYPE__SWITCH_MARGIN); |
| marginButton.setTitle(connector.getState().descriptionMargins); |
| root.add(marginButton); |
| marginButton.setClickHandler(connector); |
| } |
| if (connector.getState().supportsSpacing) { |
| spacingButton = new OButtonWidget(); |
| spacingButton.addStyleName(OIConstants.EVENT_TYPE__SWITCH_SPACING); |
| spacingButton.setCustomEventType(OIConstants.EVENT_TYPE__SWITCH_SPACING); |
| spacingButton.setTitle(connector.getState().descriptionSpacing); |
| root.add(spacingButton); |
| spacingButton.setClickHandler(connector); |
| } |
| |
| if (connector.getState().supportsEditable) { |
| editableButton = new OButtonWidget(); |
| editableButton.addStyleName(OIConstants.EVENT_TYPE__SWITCH_EDITABLE); |
| editableButton.setCustomEventType(OIConstants.EVENT_TYPE__SWITCH_EDITABLE); |
| editableButton.setTitle(connector.getState().descriptionEditable); |
| root.add(editableButton); |
| editableButton.setClickHandler(connector); |
| } |
| |
| if (connector.getState().supportsRemove) { |
| removeButton = new OButtonWidget(); |
| removeButton.addStyleName(OIConstants.EVENT_TYPE__REMOVE_CHILD); |
| removeButton.setCustomEventType(OIConstants.EVENT_TYPE__REMOVE_CHILD); |
| removeButton.setTitle(connector.getState().descriptionRemove); |
| root.add(removeButton); |
| removeButton.setClickHandler(connector); |
| } |
| |
| if (connector.getState().supportsAdd) { |
| addButton = new OButtonWidget(); |
| addButton.addStyleName(OIConstants.EVENT_TYPE__ADD_CHILD); |
| addButton.setCustomEventType(OIConstants.EVENT_TYPE__ADD_CHILD); |
| addButton.setTitle(connector.getState().descriptionAdd); |
| root.add(addButton); |
| addButton.setClickHandler(connector); |
| } |
| |
| if (connector.getState().supportsPropertiesDialog) { |
| openPropertiesButton = new OButtonWidget(); |
| openPropertiesButton.addStyleName(OIConstants.EVENT_TYPE__OPEN_PROPERTIES); |
| openPropertiesButton.setCustomEventType(OIConstants.EVENT_TYPE__OPEN_PROPERTIES); |
| openPropertiesButton.setTitle(connector.getState().descriptionPropertiesDialog); |
| root.add(openPropertiesButton); |
| openPropertiesButton.setClickHandler(connector); |
| } |
| } |
| |
| /** |
| * Sets the connector. |
| * |
| * @param connector the new connector |
| */ |
| public void setConnector(DesignerExtensionConnector connector) { |
| initialize(connector); |
| } |
| |
| /** |
| * Sets the alignment info. |
| * |
| * @param alignment the new alignment info |
| */ |
| public void setAlignmentInfo(AlignmentInfo alignment) { |
| if(alignmentWidget != null) { |
| alignmentWidget.setAlignmentInfo(alignment); |
| } |
| } |
| |
| /** |
| * Destroy. |
| */ |
| public void destroy() { |
| if (alignmentWidget != null) { |
| alignmentWidget.destroy(); |
| } |
| if (editableButton != null) { |
| editableButton.destroy(); |
| } |
| if (removeButton != null) { |
| removeButton.destroy(); |
| } |
| if (addButton != null) { |
| addButton.destroy(); |
| } |
| if (openPropertiesButton != null) { |
| openPropertiesButton.destroy(); |
| } |
| if (spacingButton != null) { |
| spacingButton.destroy(); |
| } |
| if (marginButton != null) { |
| marginButton.destroy(); |
| } |
| } |
| } |