Changeset 5231
- Timestamp:
- 08/21/08 08:26:41 (3 months ago)
- Location:
- incubator/widgets/popuppanel/src/com/itmill/toolkit/ui
- Files:
-
- 2 modified
-
PopupPanel.java (modified) (11 diffs)
-
gwt/client/ui/IPopupPanel.java (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
incubator/widgets/popuppanel/src/com/itmill/toolkit/ui/PopupPanel.java
r4957 r5231 1 1 package com.itmill.toolkit.ui; 2 2 3 import java.util.ArrayList; 3 4 import java.util.Iterator; 4 import java.util.LinkedList;5 import java.util.List;6 5 import java.util.Map; 7 6 … … 11 10 public class PopupPanel extends AbstractComponentContainer { 12 11 13 java.lang.String smallView;14 Component largeView;15 Component currentPopupComponent;16 12 Content itsContent; 17 13 boolean popupVisible; 18 19 // To make this behave more like a container 20 List componentList = new LinkedList();21 22 /* **Constructors** */23 24 /**25 * A simple way to create a PopupPanel.14 ArrayList componentList; 15 16 /* Constructors */ 17 18 /** 19 * A simple way to create a PopupPanel. Note that the minimal representation 20 * may not be dynamically updated, to achieve this create your own Content 21 * object. 26 22 * 27 23 * @param small 28 * the minimal textual representation as HTML24 * the minimal textual representation as HTML 29 25 * @param large 30 * the full, Component-type representation26 * the full, Component-type representation 31 27 */ 32 28 public PopupPanel(final java.lang.String small, final Component large) { 33 super(); 34 PopupPanel.Content content = new PopupPanel.Content() { 29 this(new PopupPanel.Content() { 35 30 public java.lang.String getMinimizedValueAsHTML() { 36 31 return small; … … 40 35 return large; 41 36 } 42 }; 43 44 itsContent = content; 45 popupVisible = false; 37 }); 46 38 47 39 } … … 52 44 * 53 45 * @param content 54 * the PopupPanel.Content that contains the information for 55 * this 46 * the PopupPanel.Content that contains the information for this 56 47 */ 57 48 public PopupPanel(final PopupPanel.Content content) { … … 59 50 itsContent = content; 60 51 popupVisible = false; 61 } 62 63 /* These methods should be preferred */ 52 componentList = new ArrayList(1); 53 } 64 54 65 55 /** … … 68 58 * 69 59 * @param newContent 70 * PopupPanel.Content object containing new information for71 * thePopupPanel60 * PopupPanel.Content object containing new information for the 61 * PopupPanel 72 62 * 73 63 */ 74 64 public void setContent(PopupPanel.Content newContent) { 75 if (newContent != null) { 76 addComponent(newContent.getPopupComponent()); 77 itsContent = newContent; 78 79 } else { 80 removeAllComponents(); 81 } 82 65 itsContent = newContent; 83 66 requestRepaint(); 84 }85 86 /**87 * Returns the smaller, minimized representation of the data. Returns null88 * if the object has no content.89 *90 * @return minimal representation as HTML or null91 */92 public java.lang.String getSmallView() {93 if (itsContent != null) {94 return itsContent.getMinimizedValueAsHTML();95 }96 return null;97 }98 99 /**100 * Returns the larger, full representation of the data. Returns null if the101 * object has no internal content102 *103 * @return full representation as a Component or null104 */105 public Component getLargeView() {106 if (itsContent != null) {107 if (currentPopupComponent == null) {108 addComponent(itsContent.getPopupComponent());109 }110 return currentPopupComponent;111 }112 return null;113 67 } 114 68 … … 134 88 /* 135 89 * Methods inherited from AbstractComponentContainer. These are unnecessary 136 * (but mandatory). Some of them are not supported in this implementation. 137 */ 138 139 /** 140 * @see com.itmill.toolkit.ui.AbstractComponentContainer#attach() 141 */ 142 public void attach() { 143 super.attach(); 144 getLargeView().attach(); 145 } 146 147 /** 148 * @see com.itmill.toolkit.ui.AbstractComponentContainer#detach() 149 */ 150 public void detach() { 151 super.detach(); 152 getLargeView().detach(); 153 } 154 155 /** 156 * Returns an iterator for compatibility. The underlying List contains one 157 * element. 158 * 159 * @return an iterator with one Component element that == getLargeView() 90 * (but mandatory). They are not supported in this implementation. 91 */ 92 93 /** 94 * Not supported in this implementation. Will return an empty iterator. 95 * 160 96 * @see com.itmill.toolkit.ui.ComponentContainer#getComponentIterator() 161 97 */ 162 98 public Iterator getComponentIterator() { 163 99 return componentList.iterator(); 164 } 165 166 /** 167 * Clears both aspects of the PopupPanel. This is also true if the object is 168 * a dynamic PopupPanel. The object is guaranteed to be empty after this 169 * call. 100 101 } 102 103 /** 104 * Not supported in this implementation. 170 105 * 171 106 * @see com.itmill.toolkit.ui.AbstractComponentContainer#removeAllComponents() 107 * @throws UnsupportedOperationException 172 108 */ 173 109 public void removeAllComponents() { 174 if (currentPopupComponent != null) { 175 removeComponent(currentPopupComponent); 176 } 177 178 itsContent = null; 179 requestRepaint(); 110 throw new UnsupportedOperationException(); 180 111 } 181 112 … … 184 115 * UnsupportedOperationException. 185 116 * 186 *187 * @param source188 * contains the (single) component that is used as the189 * popup-view190 * @throws UnsupportedOperationException191 117 * @see com.itmill.toolkit.ui.AbstractComponentContainer#moveComponentsFrom(com.itmill.toolkit.ui.ComponentContainer) 118 * @throws UnsupportedOperationException 192 119 */ 193 120 public void moveComponentsFrom(ComponentContainer source) 194 121 throws UnsupportedOperationException { 195 122 196 throw new UnsupportedOperationException( 197 "moveComponentsFrom not supported"); 198 } 199 200 /** 201 * This adds a new Component as the full representation and removes the old 202 * one. It's effectively a replacement method. Users should remember that 203 * the only supported way of changing the contents of this object is through 204 * the PopupPanel.Content interface. 205 * 206 * 207 * @param c 208 * the component to be added 209 * @throws RuntimeException 123 throw new UnsupportedOperationException(); 124 } 125 126 /** 127 * Not supported in this implementation. 128 * 210 129 * @see com.itmill.toolkit.ui.AbstractComponentContainer#addComponent(com.itmill.toolkit.ui.Component) 211 */ 212 public void addComponent(Component c) throws RuntimeException { 213 if (c != null) { 214 if (currentPopupComponent != null) { 215 removeComponent(currentPopupComponent); 216 } 217 218 if (c instanceof AbstractComponent) 219 ((AbstractComponent) c).setImmediate(true); 220 221 currentPopupComponent = c; 222 223 componentList.add(c); 224 super.addComponent(c); 225 } 130 * @throws UnsupportedOperationException 131 */ 132 public void addComponent(Component c) throws UnsupportedOperationException { 133 throw new UnsupportedOperationException(); 134 226 135 } 227 136 … … 230 139 * UnsupportedOperationException. 231 140 * 232 * @param oldComponent233 * the existing component234 * @param newComponent235 * the new component236 * @throws UnsupportedOperationException237 141 * @see com.itmill.toolkit.ui.ComponentContainer#replaceComponent(com.itmill.toolkit.ui.Component, 238 142 * com.itmill.toolkit.ui.Component) 143 * @throws UnsupportedOperationException 239 144 */ 240 145 public void replaceComponent(Component oldComponent, Component newComponent) 241 146 throws UnsupportedOperationException { 242 147 243 throw new UnsupportedOperationException( 244 "Method replaceComponent not supported"); 245 } 246 247 /** 248 * Remove the larger view. Users should remember that the only supported way 249 * of changing the contents of this object is through the PopupPanel.Content 250 * interface. 251 * 252 * @param c 253 * the component to be removed, in this case must be c == 254 * getLargeView() 148 throw new UnsupportedOperationException(); 149 } 150 151 /** 152 * Not supported in this implementation 255 153 * 256 154 * @see com.itmill.toolkit.ui.AbstractComponentContainer#removeComponent(com.itmill.toolkit.ui.Component) 257 155 */ 258 public void removeComponent(Component c) throws RuntimeException { 259 if (currentPopupComponent != null) { 260 super.removeComponent(c); 261 componentList.remove(c); 262 currentPopupComponent = null; 263 } 156 public void removeComponent(Component c) 157 throws UnsupportedOperationException { 158 throw new UnsupportedOperationException(); 159 264 160 } 265 161 … … 284 180 super.paintContent(target); 285 181 286 target.addAttribute("html", getSmallView());182 target.addAttribute("html", itsContent.getMinimizedValueAsHTML()); 287 183 target.addAttribute("popupVisible", popupVisible); 288 184 289 Component componentToShow = getLargeView();290 291 185 if (popupVisible) { 186 Component c = itsContent.getPopupComponent(); 187 292 188 target.startTag("popupComponent"); 293 c omponentToShow.paint(target);189 c.paint(target); 294 190 target.endTag("popupComponent"); 295 } else {296 removeComponent(componentToShow);297 191 } 298 192 … … 307 201 public void changeVariables(Object source, Map variables) { 308 202 if (variables.containsKey("popupVisibility")) { 309 Boolean tmp = (Boolean) variables.get("popupVisibility"); 310 popupVisible = tmp.booleanValue(); 203 popupVisible = ((Boolean) variables.get("popupVisibility")) 204 .booleanValue(); 205 206 if (popupVisible) { 207 componentList.add(itsContent.getPopupComponent()); 208 } else { 209 componentList.clear(); 210 } 311 211 requestRepaint(); 312 212 } -
incubator/widgets/popuppanel/src/com/itmill/toolkit/ui/gwt/client/ui/IPopupPanel.java
r5227 r5231 10 10 import com.google.gwt.user.client.ui.ClickListener; 11 11 import com.google.gwt.user.client.ui.HTML; 12 import com.google.gwt.user.client.ui.HasFocus; 12 13 import com.google.gwt.user.client.ui.Label; 13 14 import com.google.gwt.user.client.ui.PopupListener; … … 87 88 hostPopupVisible = uidl.getBooleanAttribute("popupVisible"); 88 89 this.setHTML(uidl.getStringAttribute("html")); 90 91 if (uidl.hasAttribute("description")) { 92 this.setTitle(uidl.getStringAttribute("description")); 93 } 89 94 90 95 // Render the popup if visible and show it. The component inside can … … 132 137 int left = hostHorizontalCenter - offsetWidth / 2; 133 138 int top = hostVerticalCenter - offsetHeight / 2; 139 134 140 popup.setPopupPosition(left, top); 135 141 … … 163 169 164 170 public static native void nativeBlur(Element e) /*-{ 165 if(e.focus) {166 e.focus();167 e.blur();168 }169 }-*/;171 if(e.focus) { 172 e.focus(); 173 e.blur(); 174 } 175 }-*/; 170 176 171 177 private class CustomPopup extends ToolkitOverlay implements Container { … … 216 222 public void hide() { 217 223 // Notify children with focus 224 if ((popupComponentWidget instanceof HasFocus)) { 225 ((HasFocus) popupComponentWidget).setFocus(false); 226 } 227 218 228 for (Iterator iterator = activeChildren.iterator(); iterator 219 229 .hasNext();) {
