Example usage for com.google.gwt.user.client.ui PopupPanel setAutoHideEnabled

List of usage examples for com.google.gwt.user.client.ui PopupPanel setAutoHideEnabled

Introduction

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

Prototype

public void setAutoHideEnabled(boolean autoHide) 

Source Link

Document

Enable or disable the autoHide feature.

Usage

From source file:com.bearsoft.gwt.ui.widgets.DropDownButton.java

protected void showMenu() {
    if (menu != null) {
        final PopupPanel pp = new PopupPanel();
        pp.setAutoHideEnabled(true);
        pp.setAutoHideOnHistoryEventsEnabled(true);
        pp.setAnimationEnabled(true);// w w  w.jav a2  s .co m
        pp.setWidget(menu);
        pp.showRelativeTo(chevron);
    }
}

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

public Grid(ProvidesKey<T> aKeyProvider) {
    super();// w  w w  . j a  v  a 2  s .  co  m
    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.widgets.boxes.DropDownButton.java

protected void showMenu() {
    if (menu != null) {
        final PopupPanel pp = new PopupPanel();
        pp.setAutoHideEnabled(true);
        pp.setAutoHideOnHistoryEventsEnabled(true);
        pp.setAnimationEnabled(true);/*from  www . j  a va  2  s .  c  om*/
        pp.setWidget(menu);
        pp.showRelativeTo(chevronMenu);
    }
}

From source file:com.google.gwt.sample.stockwatcher.client.Menu.java

public void setPopupParam(PopupPanel popup, final VerticalPanel vpanel) {
    popup.addStyleName("gwt-PopUpPanel");
    popup.setAnimationEnabled(true);/*  w ww  . j  a  va 2 s.c  o  m*/
    popup.setAnimationType(AnimationType.ROLL_DOWN);
    popup.setAutoHideEnabled(true);
    popup.getElement().getStyle().setBorderWidth(0, Unit.PX);
    popup.getElement().getStyle().setBackgroundColor("black");
    popup.hide();

    popup.addCloseHandler(new CloseHandler<PopupPanel>() {
        @Override
        public void onClose(CloseEvent<PopupPanel> event) {
            vpanel.getElement().getStyle().setBackgroundColor("#000000");
        }
    });
}

From source file:org.eclipse.swt.widgets.Control.java

License:Open Source License

/**
 * Sets the receiver's pop up menu to the argument. All controls may
 * optionally have a pop up menu that is displayed when the user requests
 * one for the control. The sequence of key strokes, button presses and/or
 * button releases that are used to request a pop up menu is platform
 * specific./*  w  ww  .  jav  a  2s .  c om*/
 * <p>
 * Note: Disposing of a control that has a pop up menu will dispose of the
 * menu. To avoid this behavior, set the menu to null before the control is
 * disposed.
 * </p>
 * 
 * @param menu
 *            the new pop up menu
 * 
 * @exception IllegalArgumentException
 *                <ul>
 *                <li>ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu</li>
 *                <li>ERROR_INVALID_PARENT - if the menu is not in the same
 *                widget tree</li>
 *                <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed
 *                </li>
 *                </ul>
 * @exception SWTException
 *                <ul>
 *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been
 *                disposed</li>
 *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
 *                thread that created the receiver</li>
 *                </ul>
 */
public void setMenu(Menu menu) {
    this.menu = menu;
    if (menu != null) {
        com.google.gwt.user.client.ui.Widget gwtWidget = getGwtWidget();
        if (gwtWidget != null) {

            addMouseListener(new MouseListener() {

                @Override
                public void mouseUp(MouseEvent e) {
                    if (e.button == 2) {
                        final PopupPanel popupPanel;
                        popupPanel = new PopupPanel();
                        popupPanel.addCloseHandler(new CloseHandler<PopupPanel>() {

                            @Override
                            public void onClose(CloseEvent<PopupPanel> event) {
                                for (int i = 0; i < getMenu().getItemCount(); i++) {
                                    getMenu().removeMenuItem(getMenu().getItem(i));
                                }
                            }
                        });
                        int scrollTop = RootPanel.get().getElement().getOwnerDocument().getScrollTop();
                        int scrollLeft = RootPanel.get().getElement().getOwnerDocument().getScrollLeft();
                        int clientLeft = e.x;
                        int clientTop = e.y;
                        popupPanel.setPopupPosition(clientLeft + scrollLeft, clientTop + scrollTop);
                        Menu menu = getMenu();

                        MenuBar menuBar = new MenuBar(true);
                        buildMenuBar(menu, menuBar);

                        popupPanel.add(menuBar);

                        popupPanel.show();
                        Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

                            @Override
                            public boolean execute() {
                                popupPanel.setAutoHideEnabled(true);
                                return false;
                            }
                        }, 200);
                    }
                }

                @Override
                public void mouseDown(MouseEvent e) {

                }

                @Override
                public void mouseDoubleClick(MouseEvent e) {

                }
            });
        }
    } else {
        com.google.gwt.user.client.ui.Widget gwtWidget = getGwtWidget();
        if (gwtWidget != null) {
            if (contextMenuDisablerHR != null) {
                contextMenuDisablerHR.removeHandler();
                contextMenuDisablerHR = null;
                contextMenuDisabler = null;
            }
        }
    }
}

From source file:org.jboss.as.console.client.shared.subsys.SubsystemTreeBuilder.java

License:Open Source License

private static void displaySubsystemHelp(LHSTreeSection subsysTree) {
    PopupPanel help = new PopupPanel();
    help.setStyleName("help-panel-open");
    help.getElement().setAttribute("style", "padding:15px");
    help.setWidget(new HTML("Mostly likely there is no UI provided to manage a particular subsystem. "
            + "It might as well be, that the profile doesn't include any subsystems at all."));
    help.setPopupPosition(subsysTree.getAbsoluteLeft() + 50, subsysTree.getAbsoluteTop() + 20);
    help.setWidth("240px");
    help.setHeight("80px");
    help.setAutoHideEnabled(true);
    help.show();//from www .j  a va2s  .c  om

}

From source file:org.mklab.taskit.client.ui.cell.TooltipCell.java

License:Apache License

/**
 * {@inheritDoc}// w w w.  j av a  2 s  .c o m
 */
@SuppressWarnings({ "nls", "unused" })
@Override
public void onBrowserEvent(com.google.gwt.cell.client.Cell.Context context, Element parent, C value,
        NativeEvent event, ValueUpdater<C> valueUpdater) {
    if ("click".equals(event.getType()) == false)
        return;

    final PopupPanel popup = new PopupPanel();
    popup.setAutoHideEnabled(true);
    popup.add(getTooltipOf(value));
    popup.setPopupPosition(event.getClientX(), event.getClientY());
    popup.show();
}

From source file:org.mklab.taskit.client.ui.HelpCallListViewImpl.java

License:Apache License

private static void showUserMap(final int x, final int y, String userId) {
    final Image image = new Image("roommap?id=" + userId); //$NON-NLS-1$
    final PopupPanel popup = new PopupPanel();
    popup.setAutoHideEnabled(true);
    popup.add(image);//  www  . j  a  va 2 s. co  m
    popup.setVisible(false);
    popup.show();
    image.addLoadHandler(new LoadHandler() {

        @Override
        public void onLoad(@SuppressWarnings("unused") LoadEvent event) {
            popup.setPopupPosition(x - image.getWidth(), y);
            popup.setVisible(true);
        }
    });
}

From source file:org.psystems.dicom.browser.client.component.StudyCard.java

License:Open Source License

/**
 * ?  ? ???/*  w  w w.j a va 2 s  . c o  m*/
 * 
 * @param fileProxy
 * @return
 */
private Image makeItemImage(final DcmFileProxy fileProxy) {

    Image image = new Image("images/" + fileProxy.getId() + ".100x100");
    image.addStyleName("Image");
    image.setTitle(" ?   ");

    Integer w = fileProxy.getImageWidth();
    Integer h = fileProxy.getImageHeight();

    final float k = w / h;
    int hNew = 100;
    int wNew = (int) (hNew / k);

    image.setHeight(hNew + "px");
    image.setWidth(wNew + "px");

    ClickHandler clickOpenHandler = new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {

            final PopupPanel pGlass = new PopupPanel();
            // pGlass.setModal(true);
            pGlass.setGlassEnabled(true);
            pGlass.setAutoHideEnabled(true);

            VerticalPanel vp = new VerticalPanel();
            pGlass.add(vp);
            vp.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);

            String patientBirthDate = Utils.dateFormatUser
                    .format(Utils.dateFormatSql.parse(proxy.getPatientBirthDate()));
            String studyDate = Utils.dateFormatUser.format(Utils.dateFormatSql.parse(proxy.getStudyDate()));

            Label lTitle = new Label(proxy.getPatientName() + " [" + patientBirthDate + "]"
                    + " ??  " + studyDate);

            lTitle.setStyleName("DicomItemValue");

            vp.add(lTitle);

            final Image imageFull = new Image("images/" + fileProxy.getId() + ".fullsize");
            imageFull.addStyleName("Image");
            imageFull.setTitle(" ?   ");

            int fullhNew = 600;
            int fullwNew = (int) (fullhNew / k);

            imageFull.setHeight(fullhNew + "px");
            imageFull.setWidth(fullwNew + "px");

            vp.add(imageFull);

            imageFull.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    pGlass.hide();
                }

            });

            HTML link = new HTML();
            link.setHTML("&nbsp;&nbsp;<a href='" + "images/" + fileProxy.getId() + ".fullsize"
                    + "' target='new'>     </a>");
            link.setStyleName("DicomItemName");
            vp.add(link);

            pGlass.show();
            pGlass.center();
        }

    };

    image.addClickHandler(clickOpenHandler);
    return image;

}