List of usage examples for com.google.gwt.user.client.ui Widget getParent
public Widget getParent()
From source file:com.vaadin.terminal.gwt.client.ui.VAbsoluteLayout.java
License:Open Source License
public RenderSpace getAllocatedSpace(Widget child) { // TODO needs some special handling for components with only on edge // horizontally or vertically defined AbsoluteWrapper wrapper = (AbsoluteWrapper) child.getParent(); int w;/*from w ww. ja v a2s.c o m*/ if (wrapper.left != null && wrapper.right != null) { w = wrapper.getOffsetWidth(); } else if (wrapper.right != null) { // left == null // available width == right edge == offsetleft + width w = wrapper.getOffsetWidth() + wrapper.getElement().getOffsetLeft(); } else { // left != null && right == null || left == null && // right == null // available width == canvas width - offset left w = canvas.getOffsetWidth() - wrapper.getElement().getOffsetLeft(); } int h; if (wrapper.top != null && wrapper.bottom != null) { h = wrapper.getOffsetHeight(); } else if (wrapper.bottom != null) { // top not defined, available space 0... bottom of wrapper h = wrapper.getElement().getOffsetTop() + wrapper.getOffsetHeight(); } else { // top defined or both undefined, available space == canvas - top h = canvas.getOffsetHeight() - wrapper.getElement().getOffsetTop(); } return new RenderSpace(w, h); }
From source file:com.vaadin.terminal.gwt.client.ui.VDragAndDropWrapper.java
License:Open Source License
/** * Starts a drag and drop operation from mousedown or touchstart event if * required conditions are met.//from ww w .j av a2s. c o m * * @param event * @return true if the event was handled as a drag start event */ private boolean startDrag(NativeEvent event) { if (dragStartMode == WRAPPER || dragStartMode == COMPONENT) { VTransferable transferable = new VTransferable(); transferable.setDragSource(VDragAndDropWrapper.this); Paintable paintable; Widget w = Util.findWidget((Element) event.getEventTarget().cast(), null); while (w != null && !(w instanceof Paintable)) { w = w.getParent(); } paintable = (Paintable) w; transferable.setData("component", paintable); VDragEvent dragEvent = VDragAndDropManager.get().startDrag(transferable, event, true); transferable.setData("mouseDown", new MouseEventDetails(event).serialize()); if (dragStartMode == WRAPPER) { dragEvent.createDragImage(getElement(), true); } else { dragEvent.createDragImage(((Widget) paintable).getElement(), true); } return true; } return false; }
From source file:com.vaadin.terminal.gwt.client.ui.VWindow.java
License:Open Source License
@Override public boolean onEventPreview(Event event) { if (dragging) { onDragEvent(event);//from w w w .j av a2s.co m return false; } else if (resizing) { onResizeEvent(event); return false; } else if (vaadinModality) { // return false when modal and outside window final Element target = event.getEventTarget().cast(); if (DOM.getCaptureElement() != null) { // Allow events when capture is set return true; } if (!DOM.isOrHasChild(getElement(), target)) { // not within the modal window, but let's see if it's in the // debug window Widget w = Util.findWidget(target, null); while (w != null) { if (w instanceof Console) { return true; // allow debug-window clicks } else if (w instanceof Paintable) { return false; } w = w.getParent(); } return false; } } return true; }
From source file:com.vaadin.terminal.gwt.client.Util.java
License:Open Source License
/** * Called when the size of one or more widgets have changed during * rendering. Finds parent container and notifies them of the size change. * // w w w . j a v a 2 s . c o m * @param paintables */ public static void componentSizeUpdated(Set<Paintable> paintables) { if (paintables.isEmpty()) { return; } Map<Container, Set<Paintable>> childWidgets = new HashMap<Container, Set<Paintable>>(); for (Paintable paintable : paintables) { Widget widget = (Widget) paintable; if (!widget.isAttached()) { continue; } // ApplicationConnection.getConsole().log( // "Widget " + Util.getSimpleName(widget) + " size updated"); Widget parent = widget.getParent(); while (parent != null && !(parent instanceof Container)) { parent = parent.getParent(); } if (parent != null) { Set<Paintable> set = childWidgets.get(parent); if (set == null) { set = new HashSet<Paintable>(); childWidgets.put((Container) parent, set); } set.add(paintable); } } Set<Paintable> parentChanges = new HashSet<Paintable>(); for (Container parent : childWidgets.keySet()) { if (!parent.requestLayout(childWidgets.get(parent))) { parentChanges.add(parent); } } componentSizeUpdated(parentChanges); }
From source file:com.vaadin.terminal.gwt.client.Util.java
License:Open Source License
/** * Returns closest parent Widget in hierarchy that implements Container * interface/*w ww . java 2 s. c o m*/ * * @param component * @return closest parent Container */ public static Container getLayout(Widget component) { Widget parent = component.getParent(); while (parent != null && !(parent instanceof Container)) { parent = parent.getParent(); } if (parent != null) { assert ((Container) parent).hasChildComponent(component); return (Container) parent; } return null; }
From source file:com.vaadin.terminal.gwt.client.Util.java
License:Open Source License
/** * Helper method to find first instance of given Widget type found by * traversing DOM upwards from given element. * //from w ww. jav a2 s . c o m * @param element * the element where to start seeking of Widget * @param class1 * the Widget type to seek for */ public static <T> T findWidget(Element element, Class<? extends Widget> class1) { if (element != null) { /* First seek for the first EventListener (~Widget) from dom */ EventListener eventListener = null; while (eventListener == null && element != null) { eventListener = Event.getEventListener(element); if (eventListener == null) { element = (Element) element.getParentElement(); } } if (eventListener != null) { /* * Then find the first widget of type class1 from widget * hierarchy */ Widget w = (Widget) eventListener; while (w != null) { if (class1 == null || w.getClass() == class1) { return (T) w; } w = w.getParent(); } } } return null; }
From source file:com.zipsoft.widgets.client.lazylayout.VLazyLayout.java
License:Apache License
/** * This method re-evaluates the component the scroll adjustment should base * upon.//from ww w . j a va 2 s .c o m * * @see #fixScrollbar() */ private void updateScrollAdjustmentReference() { final int currentScrollPos = getCurrentScrollPos(); final Widget referenceWidget = getFirstNonPlaceholderWidgetInOrAfter(currentScrollPos); if (referenceWidget != null) { this.referenceWidget = referenceWidget; debug("is parent: " + (referenceWidget.getParent() == panel)); scrollOffsetToReferenceWidgetPx = currentScrollPos - referenceWidget.getElement().getOffsetTop(); debug("scroll offset: " + scrollOffsetToReferenceWidgetPx); } else { this.referenceWidget = null; scrollOffsetToReferenceWidgetPx = -1; } }
From source file:cz.filmtit.client.pages.TranslationWorkspace.java
License:Open Source License
/** * Hide the currently active (visible) popup with suggestions */// w ww. j a va2 s .co m public void deactivateSuggestionWidget() { Widget w = this.activeSuggestionWidget; if (w != null) { if (w instanceof PopupPanel) { //((PopupPanel)w).hide(); w.setVisible(false); } else { ((Panel) (w.getParent())).remove(w); } setActiveSuggestionWidget(null); } }
From source file:cz.filmtit.client.pages.TranslationWorkspace.java
License:Open Source License
public void deactivatePosteditWidget() { Widget w = this.activePosteditWidget; if (w != null) { if (w instanceof PopupPanel) { ((PopupPanel) w).setVisible(false); } else {// www .ja v a2s . c o m ((Panel) w.getParent()).remove(w); } setActivePosteditWidget(null); } }
From source file:de.decidr.modelingtoolbase.client.ui.selection.SelectionHandler.java
License:Apache License
@Override public void onMouseDown(MouseDownEvent event) { // workaround for Firefox: prevent propagation of the event to // underlying objects (workflow or container), so that the selected item // stays selected! event.stopPropagation();/*from w w w . ja v a 2s. c o m*/ Object source = event.getSource(); // System.out.println(source.getClass()); // select the clicked node or connection Widget w = (Widget) source; if ((source instanceof FocusPanel) && (w.getParent() instanceof Node)) { Node node = (Node) w.getParent(); select(node); } else if (source instanceof ConnectionLine) { Connection connection = ((ConnectionLine) source).getConnection(); select(connection); } else if (source instanceof ConnectionDragBox) { Connection connection = ((ConnectionDragBox) source).getConnection(); if (connection != null) { select(connection); } } else if (source instanceof DragBox) { // do not unselect item, it is being dragged } else { // unselect selected item unselect(); } }