List of usage examples for com.google.gwt.user.client.ui Widget setHeight
public void setHeight(String height)
From source file:asquare.gwt.tk.client.ui.behavior.impl.GlassPanelControllerStandard.java
License:Apache License
@Override public void plugIn(Widget widget) { m_widget = widget;//w w w .j a v a2s. com widget.setWidth(calculateWidth()); widget.setHeight(calculateHeight()); m_xScroll = canScrollX(); m_yScroll = canScrollY(); m_windowResizeRegistration = Window.addResizeHandler(this); }
From source file:cc.alcina.framework.gwt.client.util.WidgetUtils.java
License:Apache License
public static void resizeUsingInfo(int containerHeight, int containerWidth, Iterator<Widget> widgets, int parentAdjustHeight, int parentAdjustWidth) { while (widgets.hasNext()) { Widget widget = widgets.next(); if (widget == null || !widget.isVisible()) { continue; }/* www . j av a 2 s .c o m*/ int availableHeight = containerHeight; int availableWidth = containerWidth; if (widget instanceof HasLayoutInfo) { String name = widget.getClass().getName(); if (debug) { GWT.log(CommonUtils.formatJ("%s: ", CommonUtils.simpleClassName(widget.getClass())), null); } LayoutInfo info = ((HasLayoutInfo) widget).getLayoutInfo(); info.beforeLayout(); if (info.to100percentOfAvailableHeight() || info.to100percentOfAvailableWidth()) { int usedHeight = 0; int usedWidth = 0; Widget parent = widget.getParent(); Iterator<Widget> childIterator = null; availableHeight = info.useBestOffsetForParentHeight() ? getBestOffsetHeight(parent.getElement(), true) : containerHeight; availableHeight = Math.min(availableHeight, containerHeight); availableWidth = info.useBestOffsetForParentWidth() ? getBestOffsetWidth(parent.getElement(), true) : containerWidth; availableWidth = Math.min(availableWidth, containerWidth); if (parent instanceof HasLayoutInfo) { childIterator = ((HasLayoutInfo) parent).getLayoutInfo().getLayoutWidgets(); } else if (parent instanceof HasWidgets) { childIterator = ((HasWidgets) parent).iterator(); } boolean ignoreChildrenForHeight = info.to100percentOfAvailableHeight() && (isDirectionalLayoutPanel(parent, true) || info.ignoreSiblingsForHeight()); boolean ignoreChildrenForWidth = info.to100percentOfAvailableWidth() && (isDirectionalLayoutPanel(parent, false) || info.ignoreSiblingsForWidth()); if (childIterator != null) { while (childIterator.hasNext()) { Widget cw = childIterator.next(); if (cw != widget && WidgetUtils.isVisibleWithOffsetParent(cw.getElement()) && cw.isAttached()) { if (!ignoreChildrenForHeight) { usedHeight += getBestOffsetHeight(cw.getElement(), true, false); } if (!ignoreChildrenForWidth) { usedWidth += getBestOffsetWidth(cw.getElement()); } } } } if (info.to100percentOfAvailableHeight()) { availableHeight = availableHeight - usedHeight - parentAdjustHeight - info.getAdjustHeight(); if (debug) { GWT.log(CommonUtils.formatJ("%s: %s - comp %s", CommonUtils.simpleClassName(widget.getClass()), availableHeight, containerHeight), null); } if (availableHeight >= 0) { widget.setHeight((availableHeight) + "px"); } } if (info.to100percentOfAvailableWidth()) { availableWidth = availableWidth - usedWidth - parentAdjustWidth - info.getAdjustWidth(); if (availableWidth >= 0) { widget.setWidth((availableWidth) + "px"); } } } Iterator<Widget> toResize = info.getWidgetsToResize(); while (toResize.hasNext()) { toResize.next().setHeight(containerHeight + "px"); } resizeUsingInfo(availableHeight, availableWidth, info.getLayoutWidgets(), info.getClientAdjustHeight(), info.getClientAdjustWidth()); info.afterLayout(); } // haslayoutinfo else if (widget instanceof HasWidgets) { resizeUsingInfo(availableHeight, availableWidth, ((HasWidgets) widget).iterator(), 0, 0); } } // while }
From source file:cc.alcina.framework.gwt.client.widget.dialog.RelativePopupPanel.java
License:Apache License
/** * We control size by setting our child widget's size. However, if we don't * currently have a child, we record the size the user wanted so that when * we do get a child, we can set it correctly. Until size is explicitly * cleared, any child put into the popup will be given that size. *//*from w w w . j a v a2 s .c o m*/ void maybeUpdateSize() { // For subclasses of RelativePopupPanel, we want the default behavior of // setWidth // and setHeight to change the dimensions of RelativePopupPanel's child // widget. // We do this because RelativePopupPanel's child widget is the first // widget in // the hierarchy which provides structure to the panel. DialogBox is // an example of this. We want to set the dimensions on DialogBox's // FlexTable, which is RelativePopupPanel's child widget. However, it is // not // DialogBox's child widget. To make sure that we are actually getting // RelativePopupPanel's child widget, we have to use super.getWidget(). Widget w = super.getWidget(); if (w != null) { if (desiredHeight != null) { w.setHeight(desiredHeight); } if (desiredWidth != null) { w.setWidth(desiredWidth); } } }
From source file:cc.kune.gspace.client.viewers.AbstractFolderViewerPanel.java
License:GNU Affero Public License
/** * Resize height./*from w w w.ja va 2s . co m*/ * * @param w * the w */ protected void resizeHeight(final Widget w) { w.setHeight(String.valueOf(gsArmor.getDocContainerHeight())); }
From source file:ch.eaternity.client.Search.java
License:Apache License
public void setVDraggerHeight(String height) { // SplitLayoutPanel p = (SplitLayoutPanel) this.getWidget (); SplitLayoutPanel p = subMealsSplitPanels; int widgetCount = p.getWidgetCount(); for (int i = 0; i < widgetCount; i++) { Widget w = p.getWidget(i); if (w.getStyleName().equals("gwt-SplitLayoutPanel-VDragger")) { w.setHeight(height); }/*from w w w.j ava 2s .c o m*/ } }
From source file:co.fxl.gui.gwt.GWTDockPanel.java
License:Open Source License
@Override public void add(Widget widget) { // if (!(widget instanceof ScrollPanel)) // widget.getElement().getStyle().setOverflow(Overflow.HIDDEN); DockLayoutConstant location = positions.remove(0); container.widget.add(widget, location); if (widget instanceof HasHorizontalAlignment) { ((HasHorizontalAlignment) widget).setHorizontalAlignment(HorizontalPanel.ALIGN_LEFT); }//from w w w .j av a2 s .com if (widget instanceof HasVerticalAlignment) { ((HasVerticalAlignment) widget).setVerticalAlignment(VerticalPanel.ALIGN_TOP); } if (location.equals(DockPanel.SOUTH) || location.equals(DockPanel.NORTH) || location.equals(DockPanel.CENTER)) { container.widget.setCellWidth(widget, "100%"); widget.setWidth("100%"); } if (location.equals(DockPanel.EAST) || location.equals(DockPanel.WEST) || location.equals(DockPanel.CENTER)) { container.widget.setCellHeight(widget, height != -1 ? height + "px" : "100%"); widget.setHeight(height != -1 ? height + "px" : "100%"); } }
From source file:co.fxl.gui.gwt.GWTSplitPane.java
License:Open Source License
private void prepare(Widget widget) { widget.setWidth("100%"); widget.setHeight("100%"); }
From source file:com.bearsoft.gwt.ui.widgets.grid.Grid.java
public Grid(ProvidesKey<T> aKeyProvider) { super();/* w ww .j av a2 s. c om*/ getElement().getStyle().setPosition(Style.Position.RELATIVE); getElement().appendChild(tdsStyleElement); getElement().appendChild(cellsStyleElement); getElement().appendChild(oddRowsStyleElement); getElement().appendChild(evenRowsStyleElement); setRowsHeight(25); hive = new FlexTable(); setWidget(hive); hive.setCellPadding(0); hive.setCellSpacing(0); hive.setBorderWidth(0); headerLeft = new GridSection<T>(aKeyProvider); headerLeftContainer = new ScrollPanel(headerLeft); headerRight = new GridSection<T>(aKeyProvider); headerRightContainer = new ScrollPanel(headerRight); frozenLeft = new GridSection<T>(aKeyProvider) { @Override protected void replaceAllChildren(List<T> values, SafeHtml html) { super.replaceAllChildren(values, html); footerLeft.redrawFooters(); } @Override protected void replaceChildren(List<T> values, int start, SafeHtml html) { super.replaceChildren(values, start, html); footerLeft.redrawFooters(); } }; frozenLeftContainer = new ScrollPanel(frozenLeft); frozenRight = new GridSection<T>(aKeyProvider) { @Override protected void replaceAllChildren(List<T> values, SafeHtml html) { super.replaceAllChildren(values, html); footerRight.redrawFooters(); } @Override protected void replaceChildren(List<T> values, int start, SafeHtml html) { super.replaceChildren(values, start, html); footerRight.redrawFooters(); } }; frozenRightContainer = new ScrollPanel(frozenRight); scrollableLeft = new GridSection<T>(aKeyProvider) { @Override protected void replaceAllChildren(List<T> values, SafeHtml html) { super.replaceAllChildren(values, html); footerLeft.redrawFooters(); } @Override protected void replaceChildren(List<T> values, int start, SafeHtml html) { super.replaceChildren(values, start, html); footerLeft.redrawFooters(); } }; scrollableLeftContainer = new ScrollPanel(scrollableLeft); scrollableRight = new GridSection<T>(aKeyProvider) { @Override protected void replaceAllChildren(List<T> values, SafeHtml html) { super.replaceAllChildren(values, html); footerRight.redrawFooters(); } @Override protected void replaceChildren(List<T> values, int start, SafeHtml html) { super.replaceChildren(values, start, html); footerRight.redrawFooters(); } }; scrollableRightContainer = new ScrollPanel(scrollableRight); footerLeft = new GridSection<>(aKeyProvider); footerLeftContainer = new ScrollPanel(footerLeft); footerRight = new GridSection<>(aKeyProvider); footerRightContainer = new ScrollPanel(footerRight); // positioning context / overflow setup // overflow for (Widget w : new Widget[] { headerLeftContainer, headerRightContainer, frozenLeftContainer, frozenRightContainer, scrollableLeftContainer, footerLeftContainer, footerRightContainer }) { w.getElement().getStyle().setOverflow(Style.Overflow.HIDDEN); } // scrollableRightContainer.getElement().getStyle().setOverflow(Style.Overflow.AUTO); // default value // context for (Widget w : new Widget[] { headerLeftContainer, headerRightContainer, frozenLeftContainer, frozenRightContainer, scrollableLeftContainer, scrollableRightContainer, footerLeftContainer, footerRightContainer }) { w.getElement().getFirstChildElement().getStyle().setPosition(Style.Position.ABSOLUTE); } // propagation of some widths headerLeft.setWidthPropagator(new GridWidthPropagator<T>(headerLeft) { @Override public void changed() { super.changed(); propagateHeaderWidth(); } }); for (GridSection<T> section : (GridSection<T>[]) new GridSection<?>[] { headerRight, frozenLeft, frozenRight, scrollableLeft, scrollableRight, footerLeft, footerRight }) { section.setWidthPropagator(new GridWidthPropagator<>(section)); } headerLeft.setColumnsPartners(new AbstractCellTable[] { frozenLeft, scrollableLeft, footerLeft }); headerRight.setColumnsPartners(new AbstractCellTable[] { frozenRight, scrollableRight, footerRight }); ColumnsRemover leftColumnsRemover = new ColumnsRemoverAdapter<T>(headerLeft, frozenLeft, scrollableLeft, footerLeft); ColumnsRemover rightColumnsRemover = new ColumnsRemoverAdapter<T>(headerRight, frozenRight, scrollableRight, footerRight); for (GridSection<T> section : (GridSection<T>[]) new GridSection<?>[] { headerLeft, frozenLeft, scrollableLeft, footerLeft }) { section.setColumnsRemover(leftColumnsRemover); } for (GridSection<T> section : (GridSection<T>[]) new GridSection<?>[] { headerRight, frozenRight, scrollableRight, footerRight }) { section.setColumnsRemover(rightColumnsRemover); } for (GridSection<T> section : (GridSection<T>[]) new GridSection<?>[] { frozenLeft, scrollableLeft, footerLeft }) { section.setHeaderSource(headerLeft); } for (GridSection<T> section : (GridSection<T>[]) new GridSection<?>[] { frozenRight, scrollableRight, footerRight }) { section.setHeaderSource(headerRight); } for (GridSection<T> section : (GridSection<T>[]) new GridSection<?>[] { headerLeft, frozenLeft, scrollableLeft }) { section.setFooterSource(footerLeft); } for (GridSection<T> section : (GridSection<T>[]) new GridSection<?>[] { headerRight, frozenRight, scrollableRight }) { section.setFooterSource(footerRight); } // hive organization hive.setWidget(0, 0, headerLeftContainer); hive.setWidget(0, 1, headerRightContainer); hive.setWidget(1, 0, frozenLeftContainer); hive.setWidget(1, 1, frozenRightContainer); hive.setWidget(2, 0, scrollableLeftContainer); hive.setWidget(2, 1, scrollableRightContainer); hive.setWidget(3, 0, footerLeftContainer); hive.setWidget(3, 1, footerRightContainer); for (Widget w : new Widget[] { headerLeftContainer, headerRightContainer, frozenLeftContainer, frozenRightContainer, scrollableLeftContainer, scrollableRightContainer, footerLeftContainer, footerRightContainer }) { w.setWidth("100%"); w.setHeight("100%"); } // misc for (Widget w : new Widget[] { headerRightContainer, frozenRightContainer, footerRightContainer, scrollableLeftContainer }) { w.getElement().getParentElement().getStyle().setOverflow(Style.Overflow.HIDDEN); } hive.getElement().getStyle().setTableLayout(Style.TableLayout.FIXED); hive.getElement().getStyle().setPosition(Style.Position.RELATIVE); for (CellTable<?> tbl : new CellTable<?>[] { headerLeft, headerRight, frozenLeft, frozenRight, scrollableLeft, scrollableRight, footerLeft, footerRight }) { tbl.setTableLayoutFixed(true); } // header headerLeft.setHeaderBuilder(new ThemedHeaderOrFooterBuilder<T>(headerLeft, false, this)); headerLeft.setFooterBuilder(new NullHeaderOrFooterBuilder<T>(headerLeft, true)); headerRight.setHeaderBuilder(new ThemedHeaderOrFooterBuilder<T>(headerRight, false, this)); headerRight.setFooterBuilder(new NullHeaderOrFooterBuilder<T>(headerRight, true)); // footer footerLeft.setHeaderBuilder(new NullHeaderOrFooterBuilder<T>(footerLeft, false)); footerLeft.setFooterBuilder(new ThemedHeaderOrFooterBuilder<T>(footerLeft, true)); footerRight.setHeaderBuilder(new NullHeaderOrFooterBuilder<T>(footerRight, false)); footerRight.setFooterBuilder(new ThemedHeaderOrFooterBuilder<T>(footerRight, true)); // data bodies for (GridSection<?> section : new GridSection<?>[] { frozenLeft, frozenRight, scrollableLeft, scrollableRight }) { GridSection<T> gSection = (GridSection<T>) section; gSection.setHeaderBuilder(new NullHeaderOrFooterBuilder<T>(gSection, false)); gSection.setFooterBuilder(new NullHeaderOrFooterBuilder<T>(gSection, true)); } for (GridSection<?> section : new GridSection<?>[] { headerLeft, headerRight, frozenLeft, frozenRight, scrollableLeft, scrollableRight, footerLeft, footerRight }) { section.setAutoHeaderRefreshDisabled(true); } for (GridSection<?> section : new GridSection<?>[] { headerLeft, headerRight, footerLeft, footerRight }) { section.setAutoFooterRefreshDisabled(true); } // cells installCellBuilders(); scrollableRightContainer.addScrollHandler(new ScrollHandler() { @Override public void onScroll(ScrollEvent event) { int aimTop = scrollableRightContainer.getElement().getScrollTop(); int aimLeft = scrollableRightContainer.getElement().getScrollLeft(); scrollableLeftContainer.getElement().setScrollTop(aimTop); int factTopDelta = aimTop - scrollableLeftContainer.getElement().getScrollTop(); if (factTopDelta > 0) { scrollableLeftContainer.getElement().getStyle().setBottom(factTopDelta, Style.Unit.PX); } else { scrollableLeftContainer.getElement().getStyle().clearBottom(); } headerRightContainer.getElement().setScrollLeft(aimLeft); int factLeftDelta0 = aimLeft - headerRightContainer.getElement().getScrollLeft(); if (factLeftDelta0 > 0) { headerRightContainer.getElement().getStyle().setRight(factLeftDelta0, Style.Unit.PX); } else { headerRightContainer.getElement().getStyle().clearRight(); } frozenRightContainer.getElement().setScrollLeft(aimLeft); int factLeftDelta1 = aimLeft - frozenRightContainer.getElement().getScrollLeft(); if (factLeftDelta1 > 0) { frozenRightContainer.getElement().getStyle().setRight(factLeftDelta1, Style.Unit.PX); } else { frozenRightContainer.getElement().getStyle().clearRight(); } footerRightContainer.getElement() .setScrollLeft(scrollableRightContainer.getElement().getScrollLeft()); int factLeftDelta2 = aimLeft - footerRightContainer.getElement().getScrollLeft(); if (factLeftDelta2 > 0) { footerRightContainer.getElement().getStyle().setRight(factLeftDelta2, Style.Unit.PX); } else { footerRightContainer.getElement().getStyle().clearRight(); } } }); ghostLine = Document.get().createDivElement(); ghostLine.addClassName(RULER_STYLE); ghostLine.getStyle().setPosition(Style.Position.ABSOLUTE); ghostLine.getStyle().setTop(0, Style.Unit.PX); ghostColumn = Document.get().createDivElement(); ghostColumn.addClassName(COLUMN_PHANTOM_STYLE); ghostColumn.getStyle().setPosition(Style.Position.ABSOLUTE); ghostColumn.getStyle().setTop(0, Style.Unit.PX); addDomHandler(new DragEnterHandler() { @Override public void onDragEnter(DragEnterEvent event) { if (DraggedColumn.instance != null) { if (DraggedColumn.instance.isMove()) { event.preventDefault(); event.stopPropagation(); DraggedColumn<T> target = findTargetDraggedColumn(event.getNativeEvent().getEventTarget()); if (target != null) { showColumnMoveDecorations(target); event.getDataTransfer().<XDataTransfer>cast().setDropEffect("move"); } else { event.getDataTransfer().<XDataTransfer>cast().setDropEffect("none"); } } else { } } else { event.getDataTransfer().<XDataTransfer>cast().setDropEffect("none"); } } }, DragEnterEvent.getType()); addDomHandler(new DragHandler() { @Override public void onDrag(DragEvent event) { if (DraggedColumn.instance != null && DraggedColumn.instance.isResize()) { event.stopPropagation(); /* int newWidth = event.getNativeEvent().getClientX() - DraggedColumn.instance.getCellElement().getAbsoluteLeft(); if (newWidth > MINIMUM_COLUMN_WIDTH) { event.getDataTransfer().<XDataTransfer> cast().setDropEffect("move"); } else { event.getDataTransfer().<XDataTransfer> cast().setDropEffect("none"); } */ } } }, DragEvent.getType()); addDomHandler(new DragOverHandler() { @Override public void onDragOver(DragOverEvent event) { if (DraggedColumn.instance != null) { event.preventDefault(); event.stopPropagation(); if (DraggedColumn.instance.isMove()) { DraggedColumn<T> target = findTargetDraggedColumn(event.getNativeEvent().getEventTarget()); if (target != null) { event.getDataTransfer().<XDataTransfer>cast().setDropEffect("move"); } else { hideColumnDecorations(); event.getDataTransfer().<XDataTransfer>cast().setDropEffect("none"); } } else { Element hostElement = Grid.this.getElement(); int clientX = event.getNativeEvent().getClientX(); int hostAbsX = hostElement.getAbsoluteLeft(); int hostScrollX = hostElement.getScrollLeft(); int docScrollX = hostElement.getOwnerDocument().getScrollLeft(); int relativeX = clientX - hostAbsX + hostScrollX + docScrollX; ghostLine.getStyle().setLeft(relativeX, Style.Unit.PX); ghostLine.getStyle().setHeight(hostElement.getClientHeight(), Style.Unit.PX); if (ghostLine.getParentElement() != hostElement) { hostElement.appendChild(ghostLine); } } } } }, DragOverEvent.getType()); addDomHandler(new DragLeaveHandler() { @Override public void onDragLeave(DragLeaveEvent event) { if (DraggedColumn.instance != null) { event.stopPropagation(); if (DraggedColumn.instance.isMove()) { if (event.getNativeEvent().getEventTarget() == (JavaScriptObject) Grid.this.getElement()) { hideColumnDecorations(); } } } } }, DragLeaveEvent.getType()); addDomHandler(new DragEndHandler() { @Override public void onDragEnd(DragEndEvent event) { event.stopPropagation(); hideColumnDecorations(); DraggedColumn.instance = null; } }, DragEndEvent.getType()); addDomHandler(new DropHandler() { @Override public void onDrop(DropEvent event) { DraggedColumn<?> source = DraggedColumn.instance; DraggedColumn<T> target = targetDraggedColumn; hideColumnDecorations(); DraggedColumn.instance = null; if (source != null) { event.preventDefault(); event.stopPropagation(); if (source.isMove()) { AbstractCellTable<T> sourceSection = (AbstractCellTable<T>) source.getTable(); // target table may be any section in our grid if (target != null) { Header<?> sourceHeader = source.getHeader(); Header<?> targetHeader = target.getHeader(); if (sourceHeader instanceof DraggableHeader<?> && targetHeader instanceof DraggableHeader<?>) { DraggableHeader<T> sourceDH = (DraggableHeader<T>) sourceHeader; DraggableHeader<T> targetDH = (DraggableHeader<T>) targetHeader; moveColumnNode(sourceDH.getHeaderNode(), targetDH.getHeaderNode()); } else { int sourceIndex = source.getColumnIndex(); int targetIndex = target.getColumnIndex(); GridSection<T> targetSection = (GridSection<T>) target.getTable(); boolean isSourceLeft = sourceSection == headerLeft || sourceSection == frozenLeft || sourceSection == scrollableLeft || sourceSection == footerLeft; boolean isTargetLeft = targetSection == headerLeft || targetSection == frozenLeft || targetSection == scrollableLeft || targetSection == footerLeft; sourceSection = isSourceLeft ? headerLeft : headerRight; targetSection = isTargetLeft ? headerLeft : headerRight; int generalSourceIndex = isSourceLeft ? sourceIndex : sourceIndex + frozenColumns; int generalTargetIndex = isTargetLeft ? targetIndex : targetIndex + frozenColumns; Header<?> header = sourceSection.getHeader(sourceIndex); if (header instanceof DraggableHeader) { ((DraggableHeader) header).setTable(targetSection); } if (generalSourceIndex != generalTargetIndex) { Column<T, ?> column = (Column<T, ?>) source.getColumn(); if (!(header instanceof DraggableHeader) || ((DraggableHeader) header).isMoveable()) { moveColumn(generalSourceIndex, generalTargetIndex); } } } } } else { Header<?> header = source.getHeader(); if (!(header instanceof DraggableHeader) || ((DraggableHeader) header).isResizable()) { int newWidth = Math.max( event.getNativeEvent().getClientX() - source.getCellElement().getAbsoluteLeft(), MINIMUM_COLUMN_WIDTH); // Source and target tables are the same, so we can // cast to DraggedColumn<T> with no care setColumnWidthFromHeaderDrag(((DraggedColumn<T>) source).getColumn(), newWidth, Style.Unit.PX); } } } } }, DropEvent.getType()); columnsChevron.getElement().getStyle().setPosition(Style.Position.ABSOLUTE); columnsChevron.getElement().addClassName(COLUMNS_CHEVRON_STYLE); getElement().appendChild(columnsChevron.getElement()); columnsChevron.addDomHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { PopupPanel pp = new PopupPanel(); pp.setAutoHideEnabled(true); pp.setAutoHideOnHistoryEventsEnabled(true); pp.setAnimationEnabled(true); MenuBar columnsMenu = new MenuBar(true); fillColumns(columnsMenu, headerLeft); fillColumns(columnsMenu, headerRight); pp.setWidget(columnsMenu); pp.setPopupPosition(columnsChevron.getAbsoluteLeft(), columnsChevron.getAbsoluteTop()); pp.showRelativeTo(columnsChevron); } private void fillColumns(MenuBar aTarget, final GridSection<T> aSection) { for (int i = 0; i < aSection.getColumnCount(); i++) { Header<?> h = aSection.getHeader(i); final Column<T, ?> column = aSection.getColumn(i); SafeHtml rendered; if (h.getValue() instanceof String) { String hVal = (String) h.getValue(); rendered = hVal.startsWith("<html>") ? SafeHtmlUtils.fromTrustedString(hVal.substring(6)) : SafeHtmlUtils.fromString(hVal); } else { Cell.Context context = new Cell.Context(0, i, h.getKey()); SafeHtmlBuilder sb = new SafeHtmlBuilder(); h.render(context, sb); rendered = sb.toSafeHtml(); } MenuItemCheckBox miCheck = new MenuItemCheckBox(!aSection.isColumnHidden(column), rendered.asString(), true); miCheck.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { if (Boolean.TRUE.equals(event.getValue())) { showColumn(column); } else { hideColumn(column); } Grid.this.onResize(); } }); aTarget.addItem(miCheck); } } }, ClickEvent.getType()); ColumnSortEvent.Handler sectionSortHandler = new ColumnSortEvent.Handler() { @Override public void onColumnSort(ColumnSortEvent event) { boolean isCtrlKey = ((GridSection<?>) event.getSource()).isCtrlKey(); boolean contains = false; int containsAt = -1; for (int i = 0; i < sortList.size(); i++) { if (sortList.get(i).getColumn() == event.getColumn()) { contains = true; containsAt = i; break; } } if (!contains) { if (!isCtrlKey) { sortList.clear(); } sortList.insert(sortList.size(), new ColumnSortList.ColumnSortInfo(event.getColumn(), true)); } else { boolean wasAscending = sortList.get(containsAt).isAscending(); if (!isCtrlKey) { sortList.clear(); if (wasAscending) { sortList.push(new ColumnSortList.ColumnSortInfo(event.getColumn(), false)); } } else { sortList.remove(sortList.get(containsAt)); if (wasAscending) { sortList.insert(containsAt, new ColumnSortList.ColumnSortInfo(event.getColumn(), false)); } } } ColumnSortEvent.fire(Grid.this, sortList); } }; headerLeft.getColumnSortList().setLimit(1); headerLeft.addColumnSortHandler(sectionSortHandler); headerRight.getColumnSortList().setLimit(1); headerRight.addColumnSortHandler(sectionSortHandler); gridColor = PublishedColor.create(211, 211, 211, 255); regenerateDynamicTDStyles(); regenerateDynamicOddRowsStyles(); getElement().<XElement>cast().addResizingTransitionEnd(this); }
From source file:com.eas.grid.Grid.java
public Grid(ProvidesKey<T> aKeyProvider) { super();/*from w w w . j ava2s .c o m*/ getElement().getStyle().setPosition(Style.Position.RELATIVE); getElement().appendChild(tdsStyleElement); getElement().appendChild(cellsStyleElement); getElement().appendChild(oddRowsStyleElement); getElement().appendChild(evenRowsStyleElement); setRowsHeight(30); hive = new FlexTable(); setWidget(hive); hive.setCellPadding(0); hive.setCellSpacing(0); hive.setBorderWidth(0); headerLeft = new GridSection<T>(aKeyProvider); headerLeftContainer = new ScrollPanel(headerLeft); headerRight = new GridSection<T>(aKeyProvider); headerRightContainer = new ScrollPanel(headerRight); frozenLeft = new GridSection<T>(aKeyProvider) { @Override protected void replaceAllChildren(List<T> values, SafeHtml html) { super.replaceAllChildren(values, html); footerLeft.redrawFooters(); frozenLeftRendered(); } @Override protected void replaceChildren(List<T> values, int start, SafeHtml html) { super.replaceChildren(values, start, html); footerLeft.redrawFooters(); frozenLeftRendered(); } @Override protected void onFocus() { super.onFocus(); Element focused = getKeyboardSelectedElement(); if (focused != null) focused.setTabIndex(tabIndex); FocusEvent.fireNativeEvent(Document.get().createFocusEvent(), Grid.this); } @Override protected void onBlur() { super.onBlur(); FocusEvent.fireNativeEvent(Document.get().createBlurEvent(), Grid.this); } }; frozenLeftContainer = new ScrollPanel(frozenLeft); frozenRight = new GridSection<T>(aKeyProvider) { @Override protected void replaceAllChildren(List<T> values, SafeHtml html) { super.replaceAllChildren(values, html); footerRight.redrawFooters(); frozenRightRendered(); } @Override protected void replaceChildren(List<T> values, int start, SafeHtml html) { super.replaceChildren(values, start, html); footerRight.redrawFooters(); frozenRightRendered(); } @Override protected void onFocus() { super.onFocus(); Element focused = getKeyboardSelectedElement(); if (focused != null) focused.setTabIndex(tabIndex); FocusEvent.fireNativeEvent(Document.get().createFocusEvent(), Grid.this); } @Override protected void onBlur() { super.onBlur(); FocusEvent.fireNativeEvent(Document.get().createBlurEvent(), Grid.this); } }; frozenRightContainer = new ScrollPanel(frozenRight); scrollableLeft = new GridSection<T>(aKeyProvider) { @Override protected void replaceAllChildren(List<T> values, SafeHtml html) { super.replaceAllChildren(values, html); footerLeft.redrawFooters(); scrollableLeftRendered(); } @Override protected void replaceChildren(List<T> values, int start, SafeHtml html) { super.replaceChildren(values, start, html); footerLeft.redrawFooters(); scrollableLeftRendered(); } @Override protected void onFocus() { super.onFocus(); Element focused = getKeyboardSelectedElement(); if (focused != null) focused.setTabIndex(tabIndex); FocusEvent.fireNativeEvent(Document.get().createFocusEvent(), Grid.this); } @Override protected void onBlur() { super.onBlur(); FocusEvent.fireNativeEvent(Document.get().createBlurEvent(), Grid.this); } }; scrollableLeftContainer = new ScrollPanel(scrollableLeft); scrollableRight = new GridSection<T>(aKeyProvider) { @Override protected void replaceAllChildren(List<T> values, SafeHtml html) { super.replaceAllChildren(values, html); footerRight.redrawFooters(); scrollableRightRendered(); } @Override protected void replaceChildren(List<T> values, int start, SafeHtml html) { super.replaceChildren(values, start, html); footerRight.redrawFooters(); scrollableRightRendered(); } @Override protected void onFocus() { super.onFocus(); Element focused = getKeyboardSelectedElement(); if (focused != null) focused.setTabIndex(tabIndex); FocusEvent.fireNativeEvent(Document.get().createFocusEvent(), Grid.this); } @Override protected void onBlur() { super.onBlur(); FocusEvent.fireNativeEvent(Document.get().createBlurEvent(), Grid.this); } }; scrollableRightContainer = new ScrollPanel(scrollableRight); footerLeft = new GridSection<>(aKeyProvider); footerLeftContainer = new ScrollPanel(footerLeft); footerRight = new GridSection<>(aKeyProvider); footerRightContainer = new ScrollPanel(footerRight); // positioning context / overflow setup // overflow for (Widget w : new Widget[] { headerLeftContainer, headerRightContainer, frozenLeftContainer, frozenRightContainer, scrollableLeftContainer, footerLeftContainer, footerRightContainer }) { w.getElement().getStyle().setOverflow(Style.Overflow.HIDDEN); } // scrollableRightContainer.getElement().getStyle().setOverflow(Style.Overflow.AUTO); // default value // context for (Widget w : new Widget[] { headerLeftContainer, headerRightContainer, frozenLeftContainer, frozenRightContainer, scrollableLeftContainer, scrollableRightContainer, footerLeftContainer, footerRightContainer }) { w.getElement().getFirstChildElement().getStyle().setPosition(Style.Position.ABSOLUTE); } // propagation of some widths headerLeft.setWidthPropagator(new GridWidthPropagator<T>(headerLeft) { @Override public void changed() { super.changed(); propagateHeaderWidth(); } }); for (GridSection<T> section : (GridSection<T>[]) new GridSection<?>[] { headerRight, frozenLeft, frozenRight, scrollableLeft, scrollableRight, footerLeft, footerRight }) { section.setWidthPropagator(new GridWidthPropagator<>(section)); } headerLeft.setColumnsPartners(new AbstractCellTable[] { frozenLeft, scrollableLeft, footerLeft }); headerRight.setColumnsPartners(new AbstractCellTable[] { frozenRight, scrollableRight, footerRight }); ColumnsRemover leftColumnsRemover = new ColumnsRemoverAdapter<T>(headerLeft, frozenLeft, scrollableLeft, footerLeft); ColumnsRemover rightColumnsRemover = new ColumnsRemoverAdapter<T>(headerRight, frozenRight, scrollableRight, footerRight); for (GridSection<T> section : (GridSection<T>[]) new GridSection<?>[] { headerLeft, frozenLeft, scrollableLeft, footerLeft }) { section.setColumnsRemover(leftColumnsRemover); } for (GridSection<T> section : (GridSection<T>[]) new GridSection<?>[] { headerRight, frozenRight, scrollableRight, footerRight }) { section.setColumnsRemover(rightColumnsRemover); } for (GridSection<T> section : (GridSection<T>[]) new GridSection<?>[] { frozenLeft, scrollableLeft, footerLeft }) { section.setHeaderSource(headerLeft); } for (GridSection<T> section : (GridSection<T>[]) new GridSection<?>[] { frozenRight, scrollableRight, footerRight }) { section.setHeaderSource(headerRight); } for (GridSection<T> section : (GridSection<T>[]) new GridSection<?>[] { headerLeft, frozenLeft, scrollableLeft }) { section.setFooterSource(footerLeft); } for (GridSection<T> section : (GridSection<T>[]) new GridSection<?>[] { headerRight, frozenRight, scrollableRight }) { section.setFooterSource(footerRight); } // hive organization hive.setWidget(0, 0, headerLeftContainer); hive.setWidget(0, 1, headerRightContainer); hive.setWidget(1, 0, frozenLeftContainer); hive.setWidget(1, 1, frozenRightContainer); hive.setWidget(2, 0, scrollableLeftContainer); hive.setWidget(2, 1, scrollableRightContainer); hive.setWidget(3, 0, footerLeftContainer); hive.setWidget(3, 1, footerRightContainer); for (Widget w : new Widget[] { headerLeftContainer, headerRightContainer, frozenLeftContainer, frozenRightContainer, scrollableLeftContainer, scrollableRightContainer, footerLeftContainer, footerRightContainer }) { w.setWidth("100%"); w.setHeight("100%"); } // misc for (Widget w : new Widget[] { headerRightContainer, frozenRightContainer, footerRightContainer, scrollableLeftContainer }) { w.getElement().getParentElement().getStyle().setOverflow(Style.Overflow.HIDDEN); } hive.getElement().getStyle().setTableLayout(Style.TableLayout.FIXED); hive.getElement().getStyle().setPosition(Style.Position.RELATIVE); for (CellTable<?> tbl : new CellTable<?>[] { headerLeft, headerRight, frozenLeft, frozenRight, scrollableLeft, scrollableRight, footerLeft, footerRight }) { tbl.setTableLayoutFixed(true); } // header headerLeft.setHeaderBuilder(new ThemedHeaderOrFooterBuilder<T>(headerLeft, false, this)); headerLeft.setFooterBuilder(new NullHeaderOrFooterBuilder<T>(headerLeft, true)); headerRight.setHeaderBuilder(new ThemedHeaderOrFooterBuilder<T>(headerRight, false, this)); headerRight.setFooterBuilder(new NullHeaderOrFooterBuilder<T>(headerRight, true)); // footer footerLeft.setHeaderBuilder(new NullHeaderOrFooterBuilder<T>(footerLeft, false)); footerLeft.setFooterBuilder(new ThemedHeaderOrFooterBuilder<T>(footerLeft, true)); footerRight.setHeaderBuilder(new NullHeaderOrFooterBuilder<T>(footerRight, false)); footerRight.setFooterBuilder(new ThemedHeaderOrFooterBuilder<T>(footerRight, true)); // data bodies for (GridSection<?> section : new GridSection<?>[] { frozenLeft, frozenRight, scrollableLeft, scrollableRight }) { GridSection<T> gSection = (GridSection<T>) section; gSection.setHeaderBuilder(new NullHeaderOrFooterBuilder<T>(gSection, false)); gSection.setFooterBuilder(new NullHeaderOrFooterBuilder<T>(gSection, true)); } for (GridSection<?> section : new GridSection<?>[] { headerLeft, headerRight, frozenLeft, frozenRight, scrollableLeft, scrollableRight, footerLeft, footerRight }) { section.setAutoHeaderRefreshDisabled(true); } for (GridSection<?> section : new GridSection<?>[] { headerLeft, headerRight, footerLeft, footerRight }) { section.setAutoFooterRefreshDisabled(true); } // cells installCellBuilders(); scrollableRightContainer.addScrollHandler(new ScrollHandler() { @Override public void onScroll(ScrollEvent event) { int aimLeft = scrollableRightContainer.getElement().getScrollLeft(); if (isHeaderVisible()) { headerRightContainer.getElement().setScrollLeft(aimLeft); int factLeftDelta0 = aimLeft - headerRightContainer.getElement().getScrollLeft(); if (factLeftDelta0 > 0) { headerRightContainer.getElement().getStyle().setRight(factLeftDelta0, Style.Unit.PX); } else { headerRightContainer.getElement().getStyle().clearRight(); } } if (frozenColumns > 0 || frozenRows > 0) { int aimTop = scrollableRightContainer.getElement().getScrollTop(); scrollableLeftContainer.getElement().setScrollTop(aimTop); int factTopDelta = aimTop - scrollableLeftContainer.getElement().getScrollTop(); if (factTopDelta > 0) { scrollableLeftContainer.getElement().getStyle().setBottom(factTopDelta, Style.Unit.PX); } else { scrollableLeftContainer.getElement().getStyle().clearBottom(); } frozenRightContainer.getElement().setScrollLeft(aimLeft); int factLeftDelta1 = aimLeft - frozenRightContainer.getElement().getScrollLeft(); if (factLeftDelta1 > 0) { frozenRightContainer.getElement().getStyle().setRight(factLeftDelta1, Style.Unit.PX); } else { frozenRightContainer.getElement().getStyle().clearRight(); } footerRightContainer.getElement() .setScrollLeft(scrollableRightContainer.getElement().getScrollLeft()); int factLeftDelta2 = aimLeft - footerRightContainer.getElement().getScrollLeft(); if (factLeftDelta2 > 0) { footerRightContainer.getElement().getStyle().setRight(factLeftDelta2, Style.Unit.PX); } else { footerRightContainer.getElement().getStyle().clearRight(); } } } }); ghostLine = Document.get().createDivElement(); ghostLine.addClassName(RULER_STYLE); ghostLine.getStyle().setPosition(Style.Position.ABSOLUTE); ghostLine.getStyle().setTop(0, Style.Unit.PX); ghostColumn = Document.get().createDivElement(); ghostColumn.addClassName(COLUMN_PHANTOM_STYLE); ghostColumn.getStyle().setPosition(Style.Position.ABSOLUTE); ghostColumn.getStyle().setTop(0, Style.Unit.PX); addDomHandler(new DragEnterHandler() { @Override public void onDragEnter(DragEnterEvent event) { if (DraggedColumn.instance != null) { if (DraggedColumn.instance.isMove()) { event.preventDefault(); event.stopPropagation(); DraggedColumn<T> target = findTargetDraggedColumn(event.getNativeEvent().getEventTarget()); if (target != null) { showColumnMoveDecorations(target); event.getDataTransfer().<XDataTransfer>cast().setDropEffect("move"); } else { event.getDataTransfer().<XDataTransfer>cast().setDropEffect("none"); } } else { } } } }, DragEnterEvent.getType()); addDomHandler(new DragHandler() { @Override public void onDrag(DragEvent event) { if (DraggedColumn.instance != null && DraggedColumn.instance.isResize()) { event.stopPropagation(); } } }, DragEvent.getType()); addDomHandler(new DragOverHandler() { @Override public void onDragOver(DragOverEvent event) { if (DraggedColumn.instance != null) { event.preventDefault(); event.stopPropagation(); if (DraggedColumn.instance.isMove()) { DraggedColumn<T> target = findTargetDraggedColumn(event.getNativeEvent().getEventTarget()); if (target != null) { event.getDataTransfer().<XDataTransfer>cast().setDropEffect("move"); } else { hideColumnDecorations(); event.getDataTransfer().<XDataTransfer>cast().setDropEffect("none"); } } else { Element hostElement = Grid.this.getElement(); int clientX = event.getNativeEvent().getClientX(); int hostAbsX = hostElement.getAbsoluteLeft(); int hostScrollX = hostElement.getScrollLeft(); int docScrollX = hostElement.getOwnerDocument().getScrollLeft(); int relativeX = clientX - hostAbsX + hostScrollX + docScrollX; ghostLine.getStyle().setLeft(relativeX, Style.Unit.PX); ghostLine.getStyle().setHeight(hostElement.getClientHeight(), Style.Unit.PX); if (ghostLine.getParentElement() != hostElement) { hostElement.appendChild(ghostLine); } } } } }, DragOverEvent.getType()); addDomHandler(new DragLeaveHandler() { @Override public void onDragLeave(DragLeaveEvent event) { if (DraggedColumn.instance != null) { event.stopPropagation(); if (DraggedColumn.instance.isMove()) { if (event.getNativeEvent().getEventTarget() == (JavaScriptObject) Grid.this.getElement()) { hideColumnDecorations(); } } } } }, DragLeaveEvent.getType()); addDomHandler(new DragEndHandler() { @Override public void onDragEnd(DragEndEvent event) { if (DraggedColumn.instance != null) { event.stopPropagation(); hideColumnDecorations(); DraggedColumn.instance = null; } } }, DragEndEvent.getType()); addDomHandler(new DropHandler() { @Override public void onDrop(DropEvent event) { DraggedColumn<?> source = DraggedColumn.instance; DraggedColumn<T> target = targetDraggedColumn; hideColumnDecorations(); DraggedColumn.instance = null; if (source != null) { event.preventDefault(); event.stopPropagation(); if (source.isMove()) { AbstractCellTable<T> sourceSection = (AbstractCellTable<T>) source.getTable(); // target table may be any section in our grid if (target != null) { Header<?> sourceHeader = source.getHeader(); Header<?> targetHeader = target.getHeader(); if (sourceHeader instanceof DraggableHeader<?> && targetHeader instanceof DraggableHeader<?>) { DraggableHeader<T> sourceDH = (DraggableHeader<T>) sourceHeader; DraggableHeader<T> targetDH = (DraggableHeader<T>) targetHeader; moveColumnNode(sourceDH.getHeaderNode(), targetDH.getHeaderNode()); } else { int sourceIndex = source.getColumnIndex(); int targetIndex = target.getColumnIndex(); GridSection<T> targetSection = (GridSection<T>) target.getTable(); boolean isSourceLeft = sourceSection == headerLeft || sourceSection == frozenLeft || sourceSection == scrollableLeft || sourceSection == footerLeft; boolean isTargetLeft = targetSection == headerLeft || targetSection == frozenLeft || targetSection == scrollableLeft || targetSection == footerLeft; sourceSection = isSourceLeft ? headerLeft : headerRight; targetSection = isTargetLeft ? headerLeft : headerRight; int generalSourceIndex = isSourceLeft ? sourceIndex : sourceIndex + frozenColumns; int generalTargetIndex = isTargetLeft ? targetIndex : targetIndex + frozenColumns; Header<?> header = sourceSection.getHeader(sourceIndex); if (header instanceof DraggableHeader) { ((DraggableHeader) header).setTable(targetSection); } if (generalSourceIndex != generalTargetIndex) { Column<T, ?> column = (Column<T, ?>) source.getColumn(); if (!(header instanceof DraggableHeader) || ((DraggableHeader) header).isMoveable()) { moveColumn(generalSourceIndex, generalTargetIndex); } } } } } else { Header<?> header = source.getHeader(); if (!(header instanceof DraggableHeader) || ((DraggableHeader) header).isResizable()) { int newWidth = Math.max( event.getNativeEvent().getClientX() - source.getCellElement().getAbsoluteLeft(), MINIMUM_COLUMN_WIDTH); // Source and target tables are the same, so we can // cast to DraggedColumn<T> with no care setColumnWidthFromHeaderDrag(((DraggedColumn<T>) source).getColumn(), newWidth, Style.Unit.PX); } } } } }, DropEvent.getType()); columnsChevron.getElement().getStyle().setPosition(Style.Position.ABSOLUTE); columnsChevron.getElement().addClassName(COLUMNS_CHEVRON_STYLE); getElement().appendChild(columnsChevron.getElement()); columnsChevron.addDomHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { PlatypusPopupMenu columnsMenu = new PlatypusPopupMenu(); fillColumns(columnsMenu, headerLeft); fillColumns(columnsMenu, headerRight); columnsMenu.setPopupPosition(columnsChevron.getAbsoluteLeft(), columnsChevron.getAbsoluteTop()); columnsMenu.showRelativeTo(columnsChevron); } private void fillColumns(MenuBar aTarget, final GridSection<T> aSection) { for (int i = 0; i < aSection.getColumnCount(); i++) { Header<?> h = aSection.getHeader(i); final Column<T, ?> column = aSection.getColumn(i); SafeHtml rendered; if (h.getValue() instanceof String) { String hVal = (String) h.getValue(); rendered = hVal.startsWith("<html>") ? SafeHtmlUtils.fromTrustedString(hVal.substring(6)) : SafeHtmlUtils.fromString(hVal); } else { Cell.Context context = new Cell.Context(0, i, h.getKey()); SafeHtmlBuilder sb = new SafeHtmlBuilder(); h.render(context, sb); rendered = sb.toSafeHtml(); } MenuItemCheckBox miCheck = new MenuItemCheckBox(!aSection.isColumnHidden(column), rendered.asString(), true); miCheck.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { if (Boolean.TRUE.equals(event.getValue())) { showColumn(column); } else { hideColumn(column); } Grid.this.onResize(); } }); aTarget.addItem(miCheck); } } }, ClickEvent.getType()); ColumnSortEvent.Handler sectionSortHandler = new ColumnSortEvent.Handler() { @Override public void onColumnSort(ColumnSortEvent event) { boolean isCtrlKey = ((GridSection<?>) event.getSource()).isCtrlKey(); boolean contains = false; int containsAt = -1; for (int i = 0; i < sortList.size(); i++) { if (sortList.get(i).getColumn() == event.getColumn()) { contains = true; containsAt = i; break; } } if (!contains) { if (!isCtrlKey) { sortList.clear(); } sortList.insert(sortList.size(), new ColumnSortList.ColumnSortInfo(event.getColumn(), true)); } else { boolean wasAscending = sortList.get(containsAt).isAscending(); if (!isCtrlKey) { sortList.clear(); if (wasAscending) { sortList.push(new ColumnSortList.ColumnSortInfo(event.getColumn(), false)); } } else { sortList.remove(sortList.get(containsAt)); if (wasAscending) { sortList.insert(containsAt, new ColumnSortList.ColumnSortInfo(event.getColumn(), false)); } } } ColumnSortEvent.fire(Grid.this, sortList); } }; headerLeft.getColumnSortList().setLimit(1); headerLeft.addColumnSortHandler(sectionSortHandler); headerRight.getColumnSortList().setLimit(1); headerRight.addColumnSortHandler(sectionSortHandler); gridColor = PublishedColor.create(211, 211, 211, 255); regenerateDynamicTDStyles(); regenerateDynamicOddRowsStyles(); getElement().<XElement>cast().addResizingTransitionEnd(this); setStyleName(GRID_SHELL_STYLE); }
From source file:com.facebook.tsdb.tsdash.client.presenter.GraphPresenter.java
License:Apache License
private void resetDimensions(ApplicationState appState) { Widget w = (Widget) widget.container(); w.setHeight(estimateHeight(appState) + "px"); w.setWidth(estimateWidth(appState) + "px"); }