1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.ui.vaadin.gwt.client.widget.controlbar;
35
36 import info.magnolia.ui.vaadin.gwt.client.editor.dom.MgnlElement;
37
38 import com.google.gwt.dom.client.Style;
39 import com.google.gwt.user.client.ui.FlowPanel;
40 import com.google.gwt.user.client.ui.Label;
41 import com.google.gwt.user.client.ui.Widget;
42
43
44
45
46 public abstract class AbstractBar extends FlowPanel {
47
48 private final static String EDITOR_BAR_CLASS_NAME = "mgnlEditorBar";
49 private final static String EDITOR_BAR_LABEL_CLASS_NAME = "mgnlEditorBarLabel";
50 private final static String EDITOR_BAR_BUTTONS_CLASS_NAME = "mgnlEditorBarButtons";
51 private final static String FOCUS_CLASS_NAME = "focus";
52 private final static String CHILD_FOCUS_CLASS_NAME = "childFocus";
53 private final static String MGNL_LEVEL_CLASS_NAME = "mgnlLevel-";
54
55 protected final static String EDITOR_CLASS_NAME = "mgnlEditor";
56 protected final static String AREA_CLASS_NAME = "area";
57 protected final static String COMPONENT_CLASS_NAME = "component";
58
59 protected final static String ICON_CLASS_NAME = "editorIcon";
60 protected final static String EDIT_CLASS_NAME = "icon-edit";
61 protected final static String ADD_CLASS_NAME = "icon-add-item";
62
63 private final static int MAX_LEVEL = 6;
64 private final int level;
65
66 private FlowPanel buttonWrapper;
67
68 public AbstractBar(MgnlElement mgnlElement) {
69
70 setStyleName(EDITOR_BAR_CLASS_NAME);
71 addStyleName(EDITOR_CLASS_NAME);
72 this.level = mgnlElement.getLevel();
73
74 setVisible(false);
75 }
76
77 protected void initLayout() {
78 buttonWrapper = new FlowPanel();
79 buttonWrapper.setStylePrimaryName(EDITOR_BAR_BUTTONS_CLASS_NAME);
80 add(buttonWrapper);
81
82 String label = getLabel();
83 if (label != null && !label.isEmpty()) {
84 Label areaName = new Label(label);
85
86 areaName.setTitle(label);
87 areaName.setStylePrimaryName(EDITOR_BAR_LABEL_CLASS_NAME);
88 String mgnlLevel = String.valueOf(level);
89 if (level > MAX_LEVEL) {
90 mgnlLevel = "max";
91 }
92 areaName.addStyleName(MGNL_LEVEL_CLASS_NAME + mgnlLevel);
93
94 add(areaName);
95 }
96
97 createControls();
98 }
99
100 protected abstract String getLabel();
101
102 protected abstract void createControls();
103
104 @Override
105 public void onAttach() {
106 super.onAttach();
107 }
108
109 protected void setId(String id) {
110 getElement().setId(id);
111 }
112
113 protected void addButton(final Widget button) {
114 buttonWrapper.add(button);
115 }
116
117
118
119
120
121
122
123 protected Style getStyle() {
124 return getElement().getStyle();
125 }
126
127 public void removeFocus() {
128 removeStyleName(FOCUS_CLASS_NAME);
129 removeStyleName(CHILD_FOCUS_CLASS_NAME);
130 }
131
132 public void setFocus(boolean child) {
133 String CLASS_NAME = (child) ? CHILD_FOCUS_CLASS_NAME : FOCUS_CLASS_NAME;
134 addStyleName(CLASS_NAME);
135 }
136 }