List of usage examples for com.google.gwt.user.client.ui Widget getParent
public Widget getParent()
From source file:com.sun.labs.aura.dbbrowser.client.query.ResultsPanel.java
License:Open Source License
public ResultsPanel(ItemDesc[] items, final TabbedQueryUI parent) { this.items = items; this.parent = parent; results = new FlexTable(); setStylePrimaryName("db-ResultsPanel"); setSpacing(5);//from w w w . java2s .com // // Put in the headers results.setText(0, NAME_COL, "Item Name"); results.setText(0, KEY_COL, "Item Key"); results.setText(0, TYPE_COL, "Type"); results.setText(0, SRC_ATTN_COL, "Attn For Source"); results.setText(0, TRG_ATTN_COL, "Attn for Target"); results.setText(0, DELETE_COL, "Delete?"); RowFormatter rf = results.getRowFormatter(); rf.setStylePrimaryName(0, "db-TableHeader"); fillItems(); center.add(results); add(center, CENTER); ItemDesc time = items[0]; add(new Label("Query took: " + time.getQueryTime() + "ms"), SOUTH); Button close = new Button("Close"); close.addClickListener(new ClickListener() { public void onClick(Widget arg0) { parent.removeTab(arg0.getParent()); } }); add(close, SOUTH); itemInfo = new DialogBox(true); service = GWTMainEntryPoint.getDBService(); }
From source file:com.tasktop.c2c.server.common.web.client.view.AbstractComposite.java
License:Open Source License
private FormSectionPanel getFormSectionPanel(Widget w) { // Time for some recursion. Check for our two possible end cases - either w is null, or it's an instance of the // class we want. if (w == null || w instanceof FormSectionPanel) { return (FormSectionPanel) w; }// w ww . ja v a 2 s. c o m // If it's neither of these, then recurse. return getFormSectionPanel(w.getParent()); }
From source file:com.thingtrack.com.vaadin.addons.slidedata.gwt.client.VIkarusListItem.java
License:Apache License
public boolean hasChildComponent(Widget component) { return component.getParent() == this; }
From source file:com.vaadin.addon.spreadsheet.client.SheetWidget.java
private void addCustomWidgetToCell(Cell cell, Widget customWidget) { cell.setValue(null);/*from w ww. j a va 2s .c om*/ Widget parent = customWidget.getParent(); if (parent != null) { if (equals(parent)) { cell.getElement().appendChild(customWidget.getElement()); } else { customWidget.removeFromParent(); cell.getElement().appendChild(customWidget.getElement()); adopt(customWidget); } } else { cell.getElement().appendChild(customWidget.getElement()); adopt(customWidget); } }
From source file:com.vaadin.addon.spreadsheet.client.SheetWidget.java
public void displayCustomCellEditor(Widget customEditorWidget) { customCellEditorDisplayed = true;//from w ww . j a v a 2s .c o m jsniUtil.replaceSelector(editedCellFreezeColumnStyle, ".notusedselector", 0); this.customEditorWidget = customEditorWidget; Cell selectedCell = getSelectedCell(); selectedCell.setValue(null); Widget parent = customEditorWidget.getParent(); if (parent != null && !equals(parent)) { customEditorWidget.removeFromParent(); } DivElement element = selectedCell.getElement(); element.addClassName(CUSTOM_EDITOR_CELL_CLASSNAME); element.appendChild(customEditorWidget.getElement()); if (parent == null || (parent != null && !equals(parent))) { adopt(customEditorWidget); } focusSheet(); }
From source file:com.vaadin.addon.spreadsheet.client.SheetWidget.java
@Override public boolean remove(Widget child) { try {// w ww . ja v a 2 s .c om Element element = child.getElement(); com.google.gwt.dom.client.Element parentElement = element.getParentElement(); Widget widgetParent = child.getParent(); boolean isAttachedToPanes = sheet.equals(parentElement) || topLeftPane.equals(parentElement) || topRightPane.equals(parentElement) || bottomLeftPane.equals(parentElement); if (isAttachedToPanes || child.equals(customEditorWidget) || (parentElement != null && parentElement.getParentNode() != null && sheet.isOrHasChild(parentElement.getParentNode()))) { orphan(child); element.removeFromParent(); return true; } else if (equals(widgetParent)) { orphan(child); return true; } else { return false; } } catch (Exception e) { debugConsole.log(Level.WARNING, "Exception while removing child widget from SheetWidget"); } return false; }
From source file:com.vaadin.client.componentlocator.LegacyLocatorStrategy.java
License:Apache License
@Override public String getPathForElement(Element targetElement) { ComponentConnector connector = Util.findPaintable(client, targetElement); Widget w = null;/* w w w . jav a 2s . c om*/ if (connector != null) { // If we found a Paintable then we use that as reference. We should // find the Paintable for all but very special cases (like // overlays). w = connector.getWidget(); /* * Still if the Paintable contains a widget that implements * SubPartAware, we want to use that as a reference */ Widget targetParent = findParentWidget(targetElement, w); while (targetParent != w && targetParent != null) { if (targetParent instanceof SubPartAware) { /* * The targetParent widget is a child of the Paintable and * the first parent (of the targetElement) that implements * SubPartAware */ w = targetParent; break; } targetParent = targetParent.getParent(); } } if (w == null) { // Check if the element is part of a widget that is attached // directly to the root panel RootPanel rootPanel = RootPanel.get(); int rootWidgetCount = rootPanel.getWidgetCount(); for (int i = 0; i < rootWidgetCount; i++) { Widget rootWidget = rootPanel.getWidget(i); if (rootWidget.getElement().isOrHasChild(targetElement)) { // The target element is contained by this root widget w = findParentWidget(targetElement, rootWidget); break; } } if (w != null) { // We found a widget but we should still see if we find a // SubPartAware implementor (we cannot find the Paintable as // there is no link from VOverlay to its paintable/owner). Widget subPartAwareWidget = findSubPartAwareParentWidget(w); if (subPartAwareWidget != null) { w = subPartAwareWidget; } } } if (w == null) { // Containing widget not found return null; } // Determine the path for the target widget String path = getPathForWidget(w); if (path == null) { /* * No path could be determined for the target widget. Cannot create * a locator string. */ return null; } // The parent check is a work around for Firefox 15 which fails to // compare elements properly (#9534) if (w.getElement() == targetElement) { /* * We are done if the target element is the root of the target * widget. */ return path; } else if (w instanceof SubPartAware) { /* * If the widget can provide an identifier for the targetElement we * let it do that */ String elementLocator = ((SubPartAware) w).getSubPartName(DOM.asOld(targetElement)); if (elementLocator != null) { return path + LegacyLocatorStrategy.SUBPART_SEPARATOR + elementLocator; } } /* * If everything else fails we use the DOM path to identify the target * element */ String domPath = getDOMPathForElement(targetElement, w.getElement()); if (domPath == null) { return path; } else { return path + domPath; } }
From source file:com.vaadin.client.componentlocator.LegacyLocatorStrategy.java
License:Apache License
/** * Finds the first widget in the hierarchy (moving upwards) that implements * SubPartAware. Returns the SubPartAware implementor or null if none is * found./* w ww. j av a 2s. co m*/ * * @param w * The widget to start from. This is returned if it implements * SubPartAware. * @return The first widget (upwards in hierarchy) that implements * SubPartAware or null */ Widget findSubPartAwareParentWidget(Widget w) { while (w != null) { if (w instanceof SubPartAware) { return w; } w = w.getParent(); } return null; }
From source file:com.vaadin.client.componentlocator.LegacyLocatorStrategy.java
License:Apache License
/** * Creates a locator String for the given widget. The path can be used to * locate the widget using {@link #getWidgetFromPath(String, Widget)}. * <p/>//from w w w . ja v a 2 s . c om * Returns null if no path can be determined for the widget or if the widget * is null. * * @param w * The target widget * @return A String locator for the widget */ private String getPathForWidget(Widget w) { if (w == null) { return null; } String elementId = w.getElement().getId(); if (elementId != null && !elementId.isEmpty() && !elementId.startsWith("gwt-uid-")) { // Use PID_S+id if the user has set an id but do not use it for auto // generated id:s as these might not be consistent return "PID_S" + elementId; } else if (w instanceof VUI) { return ""; } else if (w instanceof VWindow) { Connector windowConnector = ConnectorMap.get(client).getConnector(w); List<WindowConnector> subWindowList = client.getUIConnector().getSubWindows(); int indexOfSubWindow = subWindowList.indexOf(windowConnector); return PARENTCHILD_SEPARATOR + "VWindow[" + indexOfSubWindow + "]"; } else if (w instanceof RootPanel) { return ROOT_ID; } Widget parent = w.getParent(); String basePath = getPathForWidget(parent); if (basePath == null) { return null; } String simpleName = Util.getSimpleName(w); /* * Check if the parent implements Iterable. At least VPopupView does not * implement HasWdgets so we cannot check for that. */ if (!(parent instanceof Iterable<?>)) { // Parent does not implement Iterable so we cannot find out which // child this is return null; } Iterator<?> i = ((Iterable<?>) parent).iterator(); int pos = 0; while (i.hasNext()) { Object child = i.next(); if (child == w) { return basePath + PARENTCHILD_SEPARATOR + simpleName + "[" + pos + "]"; } String simpleName2 = Util.getSimpleName(child); if (simpleName.equals(simpleName2)) { pos++; } } return null; }
From source file:com.vaadin.client.ComponentLocator.java
License:Apache License
/** * Generates a String locator which uniquely identifies the target element. * The {@link #getElementByPath(String)} method can be used for the inverse * operation, i.e. locating an element based on the return value from this * method.// www . j a v a 2 s . c o m * <p> * Note that getElementByPath(getPathForElement(element)) == element is not * always true as {@link #getPathForElement(Element)} can return a path to * another element if the widget determines an action on the other element * will give the same result as the action on the target element. * </p> * * @since 5.4 * @param targetElement * The element to generate a path for. * @return A String locator that identifies the target element or null if a * String locator could not be created. */ public String getPathForElement(Element targetElement) { String pid = null; targetElement = getElement(targetElement); Element e = targetElement; while (true) { pid = ConnectorMap.get(client).getConnectorId(e); if (pid != null) { break; } e = DOM.getParent(e); if (e == null) { break; } } Widget w = null; if (pid != null) { // If we found a Paintable then we use that as reference. We should // find the Paintable for all but very special cases (like // overlays). w = ((ComponentConnector) ConnectorMap.get(client).getConnector(pid)).getWidget(); /* * Still if the Paintable contains a widget that implements * SubPartAware, we want to use that as a reference */ Widget targetParent = findParentWidget(targetElement, w); while (targetParent != w && targetParent != null) { if (targetParent instanceof SubPartAware) { /* * The targetParent widget is a child of the Paintable and * the first parent (of the targetElement) that implements * SubPartAware */ w = targetParent; break; } targetParent = targetParent.getParent(); } } if (w == null) { // Check if the element is part of a widget that is attached // directly to the root panel RootPanel rootPanel = RootPanel.get(); int rootWidgetCount = rootPanel.getWidgetCount(); for (int i = 0; i < rootWidgetCount; i++) { Widget rootWidget = rootPanel.getWidget(i); if (rootWidget.getElement().isOrHasChild(targetElement)) { // The target element is contained by this root widget w = findParentWidget(targetElement, rootWidget); break; } } if (w != null) { // We found a widget but we should still see if we find a // SubPartAware implementor (we cannot find the Paintable as // there is no link from VOverlay to its paintable/owner). Widget subPartAwareWidget = findSubPartAwareParentWidget(w); if (subPartAwareWidget != null) { w = subPartAwareWidget; } } } if (w == null) { // Containing widget not found return null; } // Determine the path for the target widget String path = getPathForWidget(w); if (path == null) { /* * No path could be determined for the target widget. Cannot create * a locator string. */ return null; } // The parent check is a work around for Firefox 15 which fails to // compare elements properly (#9534) if (w.getElement() == targetElement) { /* * We are done if the target element is the root of the target * widget. */ return path; } else if (w instanceof SubPartAware) { /* * If the widget can provide an identifier for the targetElement we * let it do that */ String elementLocator = ((SubPartAware) w).getSubPartName(targetElement); if (elementLocator != null) { return path + SUBPART_SEPARATOR + elementLocator; } } /* * If everything else fails we use the DOM path to identify the target * element */ String domPath = getDOMPathForElement(targetElement, w.getElement()); if (domPath == null) { return path; } else { return path + domPath; } }