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.tabsheet.tab.widget;
35
36 import info.magnolia.ui.vaadin.gwt.client.tabsheet.event.ActiveTabChangedEvent;
37 import info.magnolia.ui.vaadin.gwt.client.tabsheet.event.TabCloseEvent;
38
39 import com.google.gwt.dom.client.NativeEvent;
40 import com.google.gwt.dom.client.Style;
41 import com.google.gwt.dom.client.Style.Display;
42 import com.google.gwt.event.dom.client.ClickEvent;
43 import com.google.gwt.event.dom.client.ClickHandler;
44 import com.google.gwt.user.client.DOM;
45 import com.google.gwt.user.client.Element;
46 import com.google.gwt.user.client.Event;
47 import com.google.gwt.user.client.ui.SimplePanel;
48 import com.google.web.bindery.event.shared.EventBus;
49 import com.googlecode.mgwt.dom.client.event.touch.TouchEndEvent;
50 import com.googlecode.mgwt.dom.client.event.touch.TouchEndHandler;
51 import com.googlecode.mgwt.ui.client.widget.touch.TouchDelegate;
52 import com.vaadin.client.ui.VButton;
53
54
55
56
57
58
59 @Deprecated
60 public class MagnoliaTabLabel extends SimplePanel {
61
62 private Element indicatorsWrapper = DOM.createDiv();
63
64 private final Element notificationBox = DOM.createDiv();
65
66 private final Element closeElement = DOM.createSpan();
67
68 private final Element iconElement = DOM.createSpan();
69
70 private final Element errorIndicator = DOM.createDiv();
71
72 private final VButton textWrapper = new VButton();
73
74 private MagnoliaTabWidget tab;
75
76 private final TouchDelegatent/widget/touch/TouchDelegate.html#TouchDelegate">TouchDelegate touchDelegate = new TouchDelegate(this);
77
78 private EventBus eventBus;
79
80 public MagnoliaTabLabel() {
81 super(DOM.createElement("li"));
82
83 indicatorsWrapper.addClassName("indicators-wrapper");
84 textWrapper.getElement().setClassName("tab-title");
85 this.add(textWrapper);
86
87 indicatorsWrapper = getElement();
88
89 closeElement.setClassName("v-shell-tab-close");
90 closeElement.addClassName("icon-close");
91 notificationBox.setClassName("v-shell-tab-notification");
92 errorIndicator.setClassName("v-shell-tab-error");
93
94 getElement().appendChild(closeElement);
95 getElement().appendChild(notificationBox);
96 getElement().appendChild(errorIndicator);
97
98 DOM.sinkEvents(getElement(), Event.MOUSEEVENTS | Event.TOUCHEVENTS| Event.FOCUSEVENTS
99 | Event.KEYEVENTS);
100 hideNotification();
101 setHasError(false);
102
103 setWidth("100px");
104 }
105
106 @Override
107 protected void onLoad() {
108 super.onLoad();
109 bindHandlers();
110 }
111
112 private void bindHandlers() {
113
114 touchDelegate.addTouchEndHandler(new TouchEndHandler() {
115 @Override
116 public void onTouchEnd(TouchEndEvent event) {
117 onClickGeneric(event.getNativeEvent());
118 }
119 });
120
121 textWrapper.addClickHandler(new ClickHandler(){
122 @Override
123 public void onClick(ClickEvent event) {
124 onClickGeneric(event.getNativeEvent());
125 }
126 });
127 }
128
129 private void onClickGeneric(NativeEvent nativeEvent) {
130 textWrapper.setFocus(false);
131 final Element target = (Element) nativeEvent.getEventTarget().cast();
132 boolean wasActive = getStyleName().contains("active");
133 if (closeElement.isOrHasChild(target)) {
134 eventBus.fireEvent(new TabCloseEvent(tab));
135 } else if (!wasActive) {
136 eventBus.fireEvent(new ActiveTabChangedEvent(tab));
137 }
138 nativeEvent.stopPropagation();
139 }
140
141 public void setTab(final MagnoliaTabWidget tab) {
142 this.tab = tab;
143 }
144
145 public MagnoliaTabWidget getTab() {
146 return tab;
147 }
148
149 public String getCaption() {
150 return textWrapper.getElement().getInnerText();
151 }
152
153 public void updateCaption(final String caption) {
154 textWrapper.getElement().setInnerText(caption);
155 setWidth("");
156 }
157
158 public void setClosable(boolean isClosable) {
159 closeElement.getStyle().setDisplay(isClosable ? Display.INLINE : Display.NONE);
160 }
161
162 public void updateNotification(final String text) {
163 if (text != null && !text.isEmpty()) {
164 notificationBox.getStyle().setDisplay(Display.INLINE_BLOCK);
165 notificationBox.setInnerText(text);
166 }
167 }
168
169 public void hideNotification() {
170 notificationBox.getStyle().setDisplay(Display.NONE);
171 }
172
173 public void setHasError(boolean hasError) {
174 errorIndicator.getStyle().setDisplay(hasError ? Display.INLINE_BLOCK : Display.NONE);
175 }
176
177
178
179
180 public void setEventBus(EventBus eventBus) {
181 this.eventBus = eventBus;
182 }
183
184 public void setIcon(String icon) {
185 textWrapper.getElement().getStyle().setDisplay(Display.INLINE_BLOCK);
186 iconElement.setClassName(icon);
187 iconElement.getStyle().setMarginRight(5, Style.Unit.PX);
188 getElement().insertFirst(iconElement);
189 }
190 }