List of usage examples for com.google.gwt.user.client.ui Widget getParent
public Widget getParent()
From source file:org.gems.ajax.client.util.Util.java
License:Open Source License
public static int getOffsetWidth(Widget w) { if (w.getParent() == null) { RootPanel.get().add(w);//w ww . j av a 2 s . c o m int width = w.getOffsetWidth(); RootPanel.get().remove(w); return width; } else { return w.getOffsetWidth(); } }
From source file:org.gems.ajax.client.util.Util.java
License:Open Source License
public static int getOffsetHeight(Widget w) { if (w.getParent() == null) { RootPanel.get().add(w);/*from ww w . j av a 2s . c o m*/ int h = w.getOffsetHeight(); RootPanel.get().remove(w); return h; } else { return w.getOffsetHeight(); } }
From source file:org.gwt.mosaic.ui.client.layout.CustomGridLayout.java
License:Apache License
/** * Lays out the specified {@link LayoutPanel} using this layout. * <p>//from w w w .ja v a2 s .co m * The grid layout manager determines the size of individual widgets by * dividing the free space in the panel into equal-sized portions according to * the number of rows and columns in the layout. The container's free space * equals the container's size minus any margins and any specified horizontal * or vertical gap. * * @param layoutPanel the panel in which to do the layout * * @see org.gwt.mosaic.ui.client.layout.LayoutManager#layoutPanel(org.gwt.mosaic.ui.client.layout.LayoutPanel) */ public void layoutPanel(LayoutPanel layoutPanel) { try { if (layoutPanel == null || !init(layoutPanel)) { return; } final Dimension box = DOM.getClientSize(layoutPanel.getElement()); final int left = paddingLeftMeasure.sizeOf(layoutPanel); final int top = paddingTopMeasure.sizeOf(layoutPanel); int width = box.width - (left + paddingRightMeasure.sizeOf(layoutPanel)); int height = box.height - (top + paddingBottomMeasure.sizeOf(layoutPanel)); final int spacing = layoutPanel.getWidgetSpacing(); // adjust for spacing width -= ((cols - 1) * spacing); height -= ((rows - 1) * spacing); final int colWidth = width / cols; final int rowHeight = height / rows; for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { Widget widget = widgetMatrix[c][r]; if (widget == null || widget == SPAN) { continue; } if (widget instanceof InternalDecoratorPanel) { widget = ((InternalDecoratorPanel) widget).getWidget(); } int cellWidth; int cellHeight; final GridLayoutData layoutData = (GridLayoutData) widget.getLayoutData(); final Widget parent = widget.getParent(); if (parent instanceof InternalDecoratorPanel) { final InternalDecoratorPanel decPanel = (InternalDecoratorPanel) parent; final int borderSizes[] = decPanel.getBorderSizes(); final Dimension decPanelFrameSize = new Dimension(borderSizes[1] + borderSizes[3], borderSizes[0] + borderSizes[0]); cellWidth = colWidth * layoutData.colspan - decPanelFrameSize.width + spacing * (layoutData.colspan - 1); cellHeight = rowHeight * layoutData.rowspan - decPanelFrameSize.height + spacing * (layoutData.rowspan - 1); } else { cellWidth = colWidth * layoutData.colspan + spacing * (layoutData.colspan - 1); cellHeight = rowHeight * layoutData.rowspan + spacing * (layoutData.rowspan - 1); } HorizontalAlignmentConstant hAlignment = layoutData.getHorizontalAlignment(); if (hAlignment == null) { hAlignment = getHorizontalAlignment(); } Dimension prefSize = null; if (hAlignment == null) { layoutData.targetLeft = left + (spacing + colWidth) * c; layoutData.targetWidth = cellWidth; } else { // (ggeorg) this call to WidgetHelper.getPreferredSize() is // required even for ALIGN_LEFT prefSize = new Dimension(preferredWidthMeasure.sizeOf(widget), preferredHeightMeasure.sizeOf(widget)); if (HasHorizontalAlignment.ALIGN_LEFT == hAlignment) { layoutData.targetLeft = left + (spacing + colWidth) * c; } else if (HasHorizontalAlignment.ALIGN_CENTER == hAlignment) { layoutData.targetLeft = left + (spacing + colWidth) * c + (cellWidth / 2) - prefSize.width / 2; } else { layoutData.targetLeft = left + (spacing + colWidth) * c + cellWidth - prefSize.width; } layoutData.targetWidth = prefSize.width; } VerticalAlignmentConstant vAlignment = layoutData.getVerticalAlignment(); if (vAlignment == null) { vAlignment = getVerticalAlignment(); } if (vAlignment == null) { layoutData.targetTop = top + (spacing + rowHeight) * r; layoutData.targetHeight = cellHeight; } else { if (prefSize == null) { // (ggeorg) this call to WidgetHelper.getPreferredSize() is // required even for ALIGN_TOP prefSize = new Dimension(preferredWidthMeasure.sizeOf(widget), preferredHeightMeasure.sizeOf(widget)); } if (HasVerticalAlignment.ALIGN_TOP == vAlignment) { layoutData.targetTop = top + (spacing + rowHeight) * r; } else if (HasVerticalAlignment.ALIGN_MIDDLE == vAlignment) { layoutData.targetTop = top + (spacing + rowHeight) * r + (cellHeight / 2) - prefSize.height / 2; } else { layoutData.targetTop = top + (spacing + rowHeight) * r + cellHeight - prefSize.height; } layoutData.targetHeight = prefSize.height; } if (layoutPanel.isAnimationEnabled()) { layoutData.setSourceLeft(widget.getAbsoluteLeft() - layoutPanel.getAbsoluteLeft()); layoutData.setSourceTop(widget.getAbsoluteTop() - layoutPanel.getAbsoluteTop()); layoutData.setSourceWidth(widget.getOffsetWidth()); layoutData.setSourceHeight(widget.getOffsetHeight()); } } } super.layoutPanel(layoutPanel); } catch (Exception e) { GWT.log(e.getMessage(), e); Window.alert(this.getClass().getName() + ".layoutPanel(): " + e.getLocalizedMessage()); } }
From source file:org.gwtbootstrap3.client.ui.form.error.DefaultErrorHandler.java
License:Apache License
/** * Find the sibling {@link HelpBlock}.//from w w w .j ava 2s . c om * * @param widget the {@link Widget} to search. * @return the found {@link HelpBlock} of null if not found. */ private HelpBlock findHelpBlock(Widget widget) { if (widget instanceof HelpBlock) { return (HelpBlock) widget; } // Try and find the HelpBlock in the children of the given widget. if (widget instanceof HasWidgets) { for (Widget w : (HasWidgets) widget) { if (w instanceof HelpBlock) { return (HelpBlock) w; } } } if (!(widget instanceof HasValidationState)) { // Try and find the HelpBlock in the parent of widget. return findHelpBlock(widget.getParent()); } return null; }
From source file:org.gwtbootstrap3.client.ui.form.error.DefaultErrorHandler.java
License:Apache License
/** * Initialize the instance. We find the parent {@link HasValidationState} and sibling {@link HelpBlock} * only 1 time on initialization.//from w ww . j av a 2 s . c om */ public void init() { if (initialized) { return; } Widget parent = inputWidget.getParent(); while (parent != null && !parent.getClass().getName().equals("com.google.gwt.user.client.ui.Widget")) { if (parent instanceof HasValidationState) { validationStateParent = (HasValidationState) parent; validationStateHelpBlock = findHelpBlock(inputWidget); break; } parent = parent.getParent(); } if (inputWidget.isAttached() || validationStateParent != null) { initialized = true; } }
From source file:org.gwtbootstrap3.client.ui.SuggestBox.java
License:Apache License
@Override protected void onAttach() { super.onAttach(); // Try and set the z-index. Integer zIndex = null;/* w ww . j av a2 s . c o m*/ Widget widget = this; while (zIndex == null && widget != null) { if (!widget.getElement().getStyle().getZIndex().equals("")) { try { zIndex = Integer.valueOf(widget.getElement().getStyle().getZIndex()); zIndex += 10; } catch (Exception e) { zIndex = null; } } widget = widget.getParent(); } if (zIndex != null) { getElement().getStyle().setZIndex(zIndex); } }
From source file:org.gwtportlets.portlet.client.edit.DefaultWidgetEditor.java
License:Open Source License
/** * Change the style of the widget. Includes undo support. *//*from w w w . j av a2 s. c om*/ protected void changeStyleName(PageEditor manager, Widget widget, String styleName) { String c = widget.getStyleName(); if (styleName.equals(c)) { return; } manager.beginUndo(styleName.length() == 0 ? "Remove Style " + c : "Set Style " + styleName); widget.setStyleName(styleName); Widget p = widget.getParent(); if (p instanceof Container) { ((Container) p).layout(); // border or padding of widget may have changed } }
From source file:org.gwtportlets.portlet.client.edit.PageEditor.java
License:Open Source License
/** * Replace old with nw. If addOldToNew is true then nw must be a Container * and old is added to it./*w w w . jav a 2s. c o m*/ */ private void replaceWidgetImpl(Widget old, Widget nw, boolean addOldToNew, Widget placeholder) { Container con = (Container) old.getParent(); int index = con.getWidgetIndex(old); LayoutConstraints constraints = con.getLayoutConstraints(old); con.remove(old); if (addOldToNew) { Container newCon = (Container) nw; newCon.add(old); if (placeholder != null) { newCon.add(placeholder); } } else { onWidgetDeleted(old); } con.insert(nw, index, constraints); con.layout(); // con may not be at current edit depth so we may not get a // layoutUpdated notification so schedule an update scheduleUpdate(); }
From source file:org.gwtportlets.portlet.client.edit.row.RowLayoutEditor.java
License:Open Source License
public boolean dropWidget(Widget widget, LayoutConstraints constraints, String overflow, int clientX, int clientY) { int i = getDropIndex(clientX, clientY); if (widget.getParent() == container) { int ci = container.getWidgetIndex(widget); int wc = container.getWidgetCount(); if (i == ci || ci == wc - 1 && i == wc) { return false; }//ww w . j av a2 s.c o m if (i > ci + 1) { --i; } } if (overflow == null) { } widget.removeFromParent(); container.insert(widget, i, constraints instanceof RowLayout.Constraints ? constraints : new RowLayout.Constraints(0.0f, 1.0f, overflow)); return true; }
From source file:org.gwtportlets.portlet.client.edit.WidgetReplacer.java
License:Open Source License
/** * Replace old with nw. Throws UnsupportedOperationException if this is * not possible i.e. the parent of old is not one we know how to deal * with./*from ww w.jav a 2 s . c o m*/ */ public void replace(Widget old, Widget nw) { Widget parent = old.getParent(); if (parent instanceof Container) { Container c = (Container) parent; LayoutConstraints lc = c.getLayoutConstraints(old); int i = c.getWidgetIndex(old); c.remove(i); c.insert(nw, i, lc); c.layout(); } else if (parent instanceof HasWidgets) { HasWidgets hw = (HasWidgets) parent; hw.remove(old); hw.add(nw); } else { throw new UnsupportedOperationException( "Unsupported parent " + parent == null ? "null" : parent.getClass().getName()); } }