Example usage for com.google.gwt.user.client.ui Widget setWidth

List of usage examples for com.google.gwt.user.client.ui Widget setWidth

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui Widget setWidth.

Prototype

public void setWidth(String width) 

Source Link

Document

Sets the object's width.

Usage

From source file:co.fxl.gui.gwt.GWTVerticalPanel.java

License:Open Source License

@Override
public void add(Widget widget) {
    if (stretch && !(widget instanceof HorizontalPanel))
        widget.setWidth("100%");
    if (innerSpace > 0 && container.widget.getWidgetCount() > 0)
        addSpace(innerSpace);/* w  w w.ja v a2s  . co m*/
    if (widget instanceof HasVerticalAlignment)
        ((HasVerticalAlignment) widget).setVerticalAlignment(VerticalPanel.ALIGN_TOP);
    container.widget.add(widget);
}

From source file:co.fxl.gui.gwt.ObservableSplitLayoutPanel.java

License:Open Source License

@Override
public void onResize() {
    super.onResize();
    Widget left = getWidget(0);
    owner.splitPosition = left.getElement().getParentElement().getOffsetWidth();
    left.setWidth(owner.splitPosition + "px");
    owner.onResize(owner.splitPosition);
}

From source file:co.fxl.gui.gwt.ObservableSplitLayoutPanel.java

License:Open Source License

void updatePosition() {
    if (getWidgetCount() == 0)
        return;//from  w  w  w  . j  a  v  a  2  s  . c o  m
    final Widget left = getWidget(0);
    LayoutData layout = (LayoutData) left.getLayoutData();
    layout.oldSize = layout.size;
    layout.size = owner.splitPosition;
    animate(500, new AnimationCallback() {

        @Override
        public void onLayout(Layer layer, double progress) {
        }

        @Override
        public void onAnimationComplete() {
            left.getElement().getParentElement().getStyle().setWidth(owner.splitPosition, Unit.PX);
            left.setWidth(owner.splitPosition + "px");
        }
    });
}

From source file:com.bearsoft.gwt.ui.widgets.grid.Grid.java

public Grid(ProvidesKey<T> aKeyProvider) {
    super();//from   w  w w .  j a v a2  s .  com
    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.cms.gwt.fs.client.view.calendar.ExtMultiView.java

License:Apache License

private void showCurrent(DatePanel newShows) {
    if (currentView != null) {
        Widget real = (Widget) currentView;
        body.remove(real);//from   ww  w  .  j  a va 2 s.co m
    }

    Widget newReal = (Widget) newShows;

    currentView = newShows;
    body.setWidget(newReal);
    body.setCornerStyleName(FtrGwtDateCss.TAB_SELECTED);
    newReal.setWidth("100%");
    setHeight(height);
    setDate(centerDate);
}

From source file:com.dimdim.conference.ui.resources.client.ResourceTypeListEntryPopupPanel.java

License:Open Source License

private void writeListPanel(DockPanel outer) {
    Vector vec = new Vector();
    UIResourceObject currentActiveResource = ConferenceGlobals.getCurrentSharedResource();
    numberOfItems = 0;/*w  w w .  j av  a  2  s  . c  om*/

    int size = this.resourceList.getListSize();
    for (int i = 0; i < size; i++) {
        UIResourceObject res = ((ResourceListEntry) this.resourceList.getListEntryAt(i)).getResource();
        if (res.getResourceType().equals(this.typeName)) {
            Label resLabel = new FixedLengthLabel(res.getResourceName(), 26);
            //            resLabel.setStyleName("tool-entry");
            resLabel.setStyleName("resource-entry");
            resLabel.addStyleName("anchor-cursor");
            resLabel.addClickListener(this);
            resLabel.addClickListener(this.rtpcp.getNameLabelClickListener(res));

            HorizontalPanel h1 = new HorizontalPanel();
            Widget img = new HorizontalPanel();

            if (currentActiveResource != null
                    && currentActiveResource.getResourceId().equals(res.getResourceId())) {
                img = this.getSharingInProgressImageUrl();
                //               h2.add(img);
                //               h2.setCellVerticalAlignment(img, VerticalPanel.ALIGN_MIDDLE);
                //               h2.setCellHorizontalAlignment(img, HorizontalPanel.ALIGN_CENTER);
            } else {
                img = new Label(" ");
                img.setWidth("18px");
                //               h2.add(filler);
            }
            //            h2.setWidth("18px");
            h1.add(img);
            //            h1.setCellWidth(img, "100%");
            h1.setCellHeight(img, "100%");
            h1.setCellHorizontalAlignment(img, HorizontalPanel.ALIGN_LEFT);
            h1.setCellVerticalAlignment(img, VerticalPanel.ALIGN_MIDDLE);
            h1.add(resLabel);
            h1.setCellWidth(resLabel, "100%");
            h1.setCellHeight(resLabel, "100%");
            h1.setCellVerticalAlignment(resLabel, VerticalPanel.ALIGN_MIDDLE);
            h1.setStyleName("resource-entry-panel");
            if (numberOfItems == 0) {
                h1.addStyleName("first-resource-entry-panel");
            }
            resLabel.addMouseListener(new ResourceHoverStyler(h1));
            vec.add(h1);
            //            panel.add(h1);
            //            panel.setCellWidth(h1, "100%");
            //            panel.setCellHorizontalAlignment(h1, HorizontalPanel.ALIGN_LEFT);
            //            panel.setCellVerticalAlignment(h1, VerticalPanel.ALIGN_MIDDLE);
            numberOfItems++;
        }
    }

    if (numberOfItems != 0) {
        int scrollLimit = UIParams.getUIParams().getBrowserParamIntValue("resource_popup_scroll_limit", 5);
        if (numberOfItems > scrollLimit) {
            ScrollPanel sp = new ScrollPanel();
            int width = UIParams.getUIParams().getBrowserParamIntValue("resource_popup_scroll_width", 250);
            int barWidth = UIParams.getUIParams().getBrowserParamIntValue("resource_popup_scroll_bar_width",
                    250);
            int height = UIParams.getUIParams().getBrowserParamIntValue("resource_popup_scroll_height", 150);
            sp.setSize(width + "px", height + "px");
            VerticalPanel panel = new VerticalPanel();
            panel.setSize((width - barWidth) + "px", height + "px");
            sp.add(panel);
            outer.add(sp, DockPanel.NORTH);
            outer.setCellHorizontalAlignment(sp, HorizontalPanel.ALIGN_LEFT);
            outer.setCellVerticalAlignment(sp, VerticalPanel.ALIGN_MIDDLE);
            int size2 = vec.size();
            for (int i = 0; i < size2; i++) {
                HorizontalPanel h = (HorizontalPanel) vec.elementAt(i);
                panel.add(h);
                panel.setCellWidth(h, "100%");
                panel.setCellHorizontalAlignment(h, HorizontalPanel.ALIGN_LEFT);
                panel.setCellVerticalAlignment(h, VerticalPanel.ALIGN_MIDDLE);
            }
        } else {
            int size2 = vec.size();
            for (int i = 0; i < size2; i++) {
                HorizontalPanel h = (HorizontalPanel) vec.elementAt(i);
                outer.add(h, DockPanel.NORTH);
                outer.setCellWidth(h, "100%");
                outer.setCellHorizontalAlignment(h, HorizontalPanel.ALIGN_LEFT);
                outer.setCellVerticalAlignment(h, VerticalPanel.ALIGN_MIDDLE);
            }
        }
    } else {
    }
}

From source file:com.eas.grid.Grid.java

public Grid(ProvidesKey<T> aKeyProvider) {
    super();//ww w  .jav a2 s .co  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.ephesoft.gxt.core.client.ui.widget.ScreenNavigatorWidget.java

License:Open Source License

private HorizontalPanel getPageMenuInnerHorizontalPanel(Widget firstWidget, final Widget secondWidget,
        final String url) {
    final HorizontalPanel widgetHorizontalPanel = new HorizontalPanel();
    widgetHorizontalPanel.add(firstWidget);
    widgetHorizontalPanel.add(secondWidget);
    widgetHorizontalPanel.getElement().setAttribute("cellPadding", "2");
    widgetHorizontalPanel.setSpacing(1);
    widgetHorizontalPanel.addStyleName("panelWidth");
    secondWidget.setVisible(false);/*from   w w w  . j  av a  2  s .c o m*/
    secondWidget.setWidth("100px");
    secondWidget.addStyleName("panelLabelStyle");
    if (!url.equalsIgnoreCase(CoreCommonConstant.EMPTY_STRING)) {
        String currentURL = Window.Location.getHref();
        String baseUrl = currentURL.substring(0, currentURL.lastIndexOf('/'));
        StringBuffer newUrl = new StringBuffer();
        newUrl.append(baseUrl).append(url);
        if (currentURL.equalsIgnoreCase(newUrl.toString())) {
            widgetHorizontalPanel.addStyleName("setSelectedPageStyle");
        }
    }
    widgetHorizontalPanel.addDomHandler(new MouseOverHandler() {

        public void onMouseOver(MouseOverEvent event) {
            widgetHorizontalPanel.addStyleName("horizontalPanelMouseHover");
            if (null != previosMenuBar) {
                previosMenuBar.closeAllChildren(false);
            }
        }
    }, MouseOverEvent.getType());

    widgetHorizontalPanel.addDomHandler(new MouseOutHandler() {

        public void onMouseOut(MouseOutEvent event) {
            widgetHorizontalPanel.removeStyleName("horizontalPanelMouseHover");
        }
    }, MouseOutEvent.getType());
    widgetHorizontalPanel.addDomHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (!url.equalsIgnoreCase(CoreCommonConstant.EMPTY_STRING)) {
                String href = Window.Location.getHref();
                String baseUrl = href.substring(0, href.lastIndexOf('/'));
                StringBuffer newUrl = new StringBuffer();
                newUrl.append(baseUrl).append(url);
                Window.Location.assign(newUrl.toString());
            }
        }
    }, ClickEvent.getType());
    return widgetHorizontalPanel;
}

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");
}

From source file:com.fullmetalgalaxy.client.MAppMessagesStack.java

License:Open Source License

public void showMessage(Widget p_wgt) {
    if (p_wgt == null) {
        return;/*from www  .j a v a2 s  .com*/
    }

    PopupTimer timer = s_messagesPanels.get(p_wgt);
    if (timer == null) {
        p_wgt.setWidth("100%");
        timer = new PopupTimer(p_wgt);
        s_messagesPanels.put(p_wgt, timer);
        m_panel.add(p_wgt);
    } else {
        timer.cancel();
    }
    timer.schedule(FmpConstant.clientMessagesLivePeriod * 1000);
}