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.templating.editor.client;
35
36 import info.magnolia.rendering.template.AreaDefinition;
37 import info.magnolia.templating.editor.client.dom.CMSBoundary;
38
39 import com.google.gwt.dom.client.Style.Float;
40 import com.google.gwt.event.dom.client.ClickEvent;
41 import com.google.gwt.event.dom.client.ClickHandler;
42 import com.google.gwt.event.dom.client.MouseDownEvent;
43 import com.google.gwt.event.dom.client.MouseDownHandler;
44 import com.google.gwt.event.dom.client.MouseOutEvent;
45 import com.google.gwt.event.dom.client.MouseOutHandler;
46 import com.google.gwt.event.dom.client.MouseOverEvent;
47 import com.google.gwt.event.dom.client.MouseOverHandler;
48 import com.google.gwt.user.client.ui.Button;
49
50 import static info.magnolia.templating.editor.client.PageEditor.getDictionary;
51
52
53
54
55 public class EditBarWidget extends AbstractBarWidget {
56
57 private String workspace;
58 private String path;
59 private String dialog;
60 private String id;
61 private String parentAreaType;
62 private boolean isInherited;
63
64 public EditBarWidget(final CMSBoundary boundary, final PageEditor pageEditor) {
65
66 super(boundary);
67 String content = boundary.getComment().getAttribute("content");
68 int i = content.indexOf(':');
69 this.workspace = content.substring(0, i);
70 this.path = content.substring(i + 1);
71
72 this.id = path.substring(path.lastIndexOf("/") + 1);
73
74 setId("__"+id);
75
76 this.dialog = boundary.getComment().getAttribute("dialog");
77
78 if(boundary.getParentArea() != null) {
79 this.parentAreaType = boundary.getParentArea().getComment().getAttribute("type");
80 }
81
82 this.isInherited = Boolean.parseBoolean(boundary.getComment().getAttribute("inherited"));
83
84 createButtons(pageEditor);
85
86 createMouseEventsHandlers(pageEditor);
87
88 setClassName("mgnlEditBar");
89 if (this.isInherited) {
90 addStyleName("mgnlInherited");
91 }
92
93 }
94
95 private void createMouseEventsHandlers(final PageEditor pageEditor) {
96
97 addDomHandler(new MouseDownHandler() {
98
99 @Override
100 public void onMouseDown(MouseDownEvent event) {
101 String parentPath = path.substring(0, path.lastIndexOf("/"));
102 pageEditor.moveComponentEnd((EditBarWidget)event.getSource(), parentPath);
103
104 }
105 }, MouseDownEvent.getType());
106
107 addDomHandler(new MouseOverHandler() {
108
109 @Override
110 public void onMouseOver(MouseOverEvent event) {
111 pageEditor.moveComponentOver((EditBarWidget)event.getSource());
112 }
113 }, MouseOverEvent.getType());
114
115 addDomHandler(new MouseOutHandler() {
116
117 @Override
118 public void onMouseOut(MouseOutEvent event) {
119 pageEditor.moveComponentOut((EditBarWidget)event.getSource());
120 }
121 }, MouseOutEvent.getType());
122 }
123
124 private void createButtons(final PageEditor pageEditor) {
125
126 if (!this.isInherited) {
127 final Button edit = new Button(getDictionary().get("buttons.edit.js"));
128 edit.addClickHandler(new ClickHandler() {
129 @Override
130 public void onClick(ClickEvent event) {
131 pageEditor.openDialog(dialog, workspace, path, null, null);
132
133 }
134 });
135 addButton(edit, Float.RIGHT);
136 }
137
138
139 if(AreaDefinition.TYPE_LIST.equals(parentAreaType)) {
140 final Button move = new Button(getDictionary().get("buttons.move.js"));
141 move.addClickHandler(new ClickHandler() {
142 @Override
143 public void onClick(ClickEvent event) {
144 pageEditor.moveComponentStart(id);
145 }
146 });
147 addButton(move, Float.RIGHT);
148 }
149
150 if (!this.isInherited) {
151 final Button removeButton = new Button(getDictionary().get("buttons.delete.js"));
152 removeButton.addClickHandler(new ClickHandler() {
153 @Override
154 public void onClick(ClickEvent event) {
155 pageEditor.deleteComponent(path);
156 }
157 });
158 removeButton.addStyleName("mgnlRemoveButton");
159 addButton(removeButton, Float.RIGHT);
160 }
161 }
162
163 }