1 /** 2 * This file Copyright (c) 2011 Magnolia International 3 * Ltd. (http://www.magnolia-cms.com). All rights reserved. 4 * 5 * 6 * This file is dual-licensed under both the Magnolia 7 * Network Agreement and the GNU General Public License. 8 * You may elect to use one or the other of these licenses. 9 * 10 * This file is distributed in the hope that it will be 11 * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the 12 * implied warranty of MERCHANTABILITY or FITNESS FOR A 13 * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT. 14 * Redistribution, except as permitted by whichever of the GPL 15 * or MNA you select, is prohibited. 16 * 17 * 1. For the GPL license (GPL), you can redistribute and/or 18 * modify this file under the terms of the GNU General 19 * Public License, Version 3, as published by the Free Software 20 * Foundation. You should have received a copy of the GNU 21 * General Public License, Version 3 along with this program; 22 * if not, write to the Free Software Foundation, Inc., 51 23 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 24 * 25 * 2. For the Magnolia Network Agreement (MNA), this file 26 * and the accompanying materials are made available under the 27 * terms of the MNA which accompanies this distribution, and 28 * is available at http://www.magnolia-cms.com/mna.html 29 * 30 * Any modifications to this file must keep this entire header 31 * intact. 32 * 33 */ 34 package info.magnolia.templating.editor.client; 35 36 37 import info.magnolia.templating.editor.client.dom.CMSComment; 38 import info.magnolia.templating.editor.client.dom.MgnlElement; 39 40 import com.google.gwt.dom.client.Element; 41 import com.google.gwt.dom.client.Node; 42 import com.google.gwt.dom.client.Style; 43 import com.google.gwt.dom.client.Style.Float; 44 45 46 import com.google.gwt.user.client.ui.Button; 47 import com.google.gwt.user.client.ui.FlowPanel; 48 import com.google.gwt.user.client.ui.InlineLabel; 49 import com.google.gwt.user.client.ui.Label; 50 51 /** 52 * Base class for horizontal bars with buttons. 53 */ 54 public abstract class AbstractBarWidget extends FlowPanel { 55 56 private MgnlElement boundary; 57 protected boolean hasControls = false; 58 private String label = ""; 59 private boolean toggleSelection = false; 60 61 public AbstractBarWidget(MgnlElement boundary, CMSComment comment) { 62 63 this.setBoundary(boundary); 64 if (comment != null) { 65 this.label = comment.getAttribute("label"); 66 } 67 68 if (this.label != null && !this.label.isEmpty()) { 69 Label areaName = new InlineLabel(this.label); 70 //tooltip. Nice to have when area label is truncated because too long. 71 areaName.setTitle(this.label); 72 73 //setStylePrimaryName(..) replaces gwt default css class, in this case gwt-Label 74 areaName.setStylePrimaryName("mgnlAreaLabel"); 75 add(areaName); 76 } 77 78 } 79 80 /** 81 * Called when this bar widget is selected/clicked. Default implementation does nothing. 82 */ 83 protected void select() { 84 85 this.addStyleName("selected"); 86 /* Document.get().getElementById("mgnlBoundary").getStyle().setTop(boundary.getMinCoordinate().getTop(), Style.Unit.PX); 87 Document.get().getElementById("mgnlBoundary").getStyle().setLeft(boundary.getMinCoordinate().getLeft(), Style.Unit.PX); 88 Document.get().getElementById("mgnlBoundary").getStyle().setHeight(boundary.getMaxCoordinate().getTop()-boundary.getMinCoordinate().getTop(), Style.Unit.PX); 89 Document.get().getElementById("mgnlBoundary").getStyle().setHeight(boundary.getMaxCoordinate().getLeft()-boundary.getMinCoordinate().getLeft(), Style.Unit.PX);*/ 90 } 91 92 protected void deSelect() { 93 94 this.removeStyleName("selected"); 95 96 } 97 98 protected void setId(String id){ 99 getElement().setId(id); 100 } 101 102 protected void addButton(final Button button, final Float cssFloat) { 103 button.setStylePrimaryName("mgnlControlButton"); 104 button.getElement().getStyle().setFloat(cssFloat); 105 106 /* button.addMouseDownHandler(new MouseDownHandler() { 107 108 @Override 109 public void onMouseDown(MouseDownEvent event) { 110 //add push button style 111 button.setStyleName("mgnlControlButton_PUSHED", true); 112 } 113 }); 114 button.addMouseUpHandler(new MouseUpHandler() { 115 116 @Override 117 public void onMouseUp(MouseUpEvent event) { 118 //remove push button style 119 button.setStyleName("mgnlControlButton_PUSHED", false); 120 } 121 });*/ 122 add(button); 123 hasControls = true; 124 } 125 126 protected void setClassName(String className) { 127 getElement().setClassName(className); 128 } 129 130 /** 131 * @return the element's underlying {@link Style}. You can use this object to manipulate the css style attribute of this bar widget. 132 */ 133 protected Style getStyle() { 134 return getElement().getStyle(); 135 } 136 137 /** 138 * TODO: we should not have to call onAttach ourself? 139 */ 140 public void attach(Element element) { 141 final Node parentNode = element.getParentNode(); 142 parentNode.insertAfter(getElement(), element); 143 onAttach(); 144 } 145 146 /** 147 * TODO: we should not have to call onAttach ourself? 148 */ 149 public void attach(Node node) { 150 final Node parentNode = node.getParentNode(); 151 parentNode.insertAfter(getElement(), node); 152 onAttach(); 153 } 154 public void setBoundary(MgnlElement boundary) { 155 this.boundary = boundary; 156 } 157 158 public MgnlElement getBoundary() { 159 return boundary; 160 } 161 }