Search in sources :

Example 11 with PopupPanel

use of com.google.gwt.user.client.ui.PopupPanel in project gwt-test-utils by gwt-test-utils.

the class PopupPanelTest method show.

@Test
public void show() {
    // Given
    PopupPanel popup = new PopupPanel();
    // Preconditions
    assertThat(popup.isVisible()).isTrue();
    assertThat(popup.isShowing()).isFalse();
    // When
    popup.show();
    // Then
    assertThat(popup.isShowing()).isTrue();
}
Also used : PopupPanel(com.google.gwt.user.client.ui.PopupPanel) Test(org.junit.Test)

Example 12 with PopupPanel

use of com.google.gwt.user.client.ui.PopupPanel in project rstudio by rstudio.

the class ToolbarButton method addMenuHandlers.

private void addMenuHandlers(final ToolbarPopupMenu popupMenu, final boolean rightAlign) {
    menu_ = popupMenu;
    /*
       * We want clicks on this button to toggle the visibility of the menu,
       * as well as having the menu auto-hide itself as it normally does.
       * It's necessary to manually track the visibility (menuShowing) because
       * in the case where the menu is showing, clicking on this button first
       * causes the menu to auto-hide and then our mouseDown handler is called
       * (so we can't rely on menu.isShowing(), it'll always be false by the
       * time you get into the mousedown handler).
       */
    final boolean[] menuShowing = new boolean[1];
    addMouseDownHandler(new MouseDownHandler() {

        public void onMouseDown(MouseDownEvent event) {
            event.preventDefault();
            event.stopPropagation();
            addStyleName(styles_.toolbarButtonPushed());
            // Some menus are rebuilt on every invocation. Ask the menu for 
            // the most up-to-date version before proceeding.
            popupMenu.getDynamicPopupMenu(new ToolbarPopupMenu.DynamicPopupMenuCallback() {

                @Override
                public void onPopupMenu(final ToolbarPopupMenu menu) {
                    if (menuShowing[0]) {
                        removeStyleName(styles_.toolbarButtonPushed());
                        menu.hide();
                    } else {
                        if (rightAlign) {
                            menu.setPopupPositionAndShow(new PositionCallback() {

                                @Override
                                public void setPosition(int offsetWidth, int offsetHeight) {
                                    menu.setPopupPosition((rightImageWidget_ != null ? rightImageWidget_.getAbsoluteLeft() : leftImageWidget_.getAbsoluteLeft()) + 20 - offsetWidth, ToolbarButton.this.getAbsoluteTop() + ToolbarButton.this.getOffsetHeight());
                                }
                            });
                        } else {
                            menu.showRelativeTo(ToolbarButton.this);
                        }
                        menuShowing[0] = true;
                    }
                }
            });
        }
    });
    popupMenu.addCloseHandler(new CloseHandler<PopupPanel>() {

        public void onClose(CloseEvent<PopupPanel> popupPanelCloseEvent) {
            removeStyleName(styles_.toolbarButtonPushed());
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                public void execute() {
                    menuShowing[0] = false;
                }
            });
        }
    });
}
Also used : PositionCallback(com.google.gwt.user.client.ui.PopupPanel.PositionCallback) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) PopupPanel(com.google.gwt.user.client.ui.PopupPanel)

Example 13 with PopupPanel

use of com.google.gwt.user.client.ui.PopupPanel in project rstudio by rstudio.

the class SupportPopupMenu method addMenuItem.

private void addMenuItem(FlexTable supportTable, String caption, final String email, final GlobalDisplay globalDisplay) {
    // maintain reference to containing class for closing
    final PopupPanel popupPanel = this;
    // create a hyperlink label for this URL
    HyperlinkLabel link = new HyperlinkLabel(caption, new ClickHandler() {

        public void onClick(ClickEvent event) {
            globalDisplay.openEmailComposeWindow(email, null);
            popupPanel.hide();
        }
    });
    int row = supportTable.getRowCount();
    supportTable.setWidget(row, 0, link);
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ThemedPopupPanel(org.rstudio.core.client.widget.ThemedPopupPanel) PopupPanel(com.google.gwt.user.client.ui.PopupPanel) HyperlinkLabel(org.rstudio.core.client.widget.HyperlinkLabel)

Example 14 with PopupPanel

use of com.google.gwt.user.client.ui.PopupPanel in project rstudio by rstudio.

the class EditingTargetInlineChunkExecution method execute.

public void execute(Range range) {
    // synthesize an identifier for this chunk execution
    final String chunkId = "i" + StringUtil.makeRandomId(12);
    // are, remove it to make way for the new one
    for (ChunkInlineOutput output : outputs_.values()) {
        if (output.range().isEqualTo(range)) {
            if (output.state() == ChunkInlineOutput.State.Finished) {
                // remove old, completed output for this input
                output.hide();
                outputs_.remove(output.chunkId());
            } else {
                // unintended duplicate.
                return;
            }
        }
    }
    // create dummy scope for execution
    Scope scope = Scope.createRScopeNode(chunkId, range.getStart(), range.getEnd(), Scope.SCOPE_TYPE_CHUNK);
    // create popup panel to host output
    final ChunkInlineOutput output = new ChunkInlineOutput(chunkId, display_.createAnchoredSelection(range.getStart(), range.getEnd()));
    // auto dismiss the panel when the cursor leaves the inline chunk
    final Mutable<HandlerRegistration> cursorHandler = new Mutable<HandlerRegistration>();
    cursorHandler.set(display_.addCursorChangedHandler(new CursorChangedHandler() {

        @Override
        public void onCursorChanged(CursorChangedEvent event) {
            Position position = event.getPosition();
            if (!output.range().contains(position)) {
                output.hide();
            }
        }
    }));
    // when the popup is dismissed, clean up local state
    output.addCloseHandler(new CloseHandler<PopupPanel>() {

        @Override
        public void onClose(CloseEvent<PopupPanel> event) {
            outputs_.remove(chunkId);
            cursorHandler.get().removeHandler();
        }
    });
    // render offscreen until complete
    output.setPopupPosition(-100000, -100000);
    output.show();
    outputs_.put(chunkId, output);
    SendToChunkConsoleEvent event = new SendToChunkConsoleEvent(docId_, scope, range, NotebookQueueUnit.EXEC_SCOPE_INLINE);
    events_.fireEvent(event);
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) PopupPanel(com.google.gwt.user.client.ui.PopupPanel) CursorChangedEvent(org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedEvent) ChunkInlineOutput(org.rstudio.studio.client.workbench.views.source.editors.text.ChunkInlineOutput) Mutable(org.rstudio.core.client.Mutable) Scope(org.rstudio.studio.client.workbench.views.source.editors.text.Scope) CursorChangedHandler(org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedHandler) SendToChunkConsoleEvent(org.rstudio.studio.client.rmarkdown.events.SendToChunkConsoleEvent)

Example 15 with PopupPanel

use of com.google.gwt.user.client.ui.PopupPanel in project gerrit by GerritCodeReview.

the class CherryPickAction method call.

static void call(final Button b, final ChangeInfo info, final String revision, String project, final String commitMessage) {
    // TODO Replace CherryPickDialog with a nicer looking display.
    b.setEnabled(false);
    new CherryPickDialog(new Project.NameKey(project)) {

        {
            sendButton.setText(Util.C.buttonCherryPickChangeSend());
            if (info.status() == Change.Status.MERGED) {
                message.setText(Util.M.cherryPickedChangeDefaultMessage(commitMessage.trim(), revision));
            } else {
                message.setText(commitMessage.trim());
            }
        }

        @Override
        public void onSend() {
            ChangeApi.cherrypick(info.legacyId().get(), revision, getDestinationBranch(), getMessageText(), new GerritCallback<ChangeInfo>() {

                @Override
                public void onSuccess(ChangeInfo result) {
                    sent = true;
                    hide();
                    Gerrit.display(PageLinks.toChange(result.legacyId()));
                }

                @Override
                public void onFailure(Throwable caught) {
                    enableButtons(true);
                    super.onFailure(caught);
                }
            });
        }

        @Override
        public void onClose(CloseEvent<PopupPanel> event) {
            super.onClose(event);
            b.setEnabled(true);
        }
    }.center();
}
Also used : GerritCallback(com.google.gerrit.client.rpc.GerritCallback) CherryPickDialog(com.google.gerrit.client.ui.CherryPickDialog) ChangeInfo(com.google.gerrit.client.info.ChangeInfo) PopupPanel(com.google.gwt.user.client.ui.PopupPanel)

Aggregations

PopupPanel (com.google.gwt.user.client.ui.PopupPanel)28 Test (org.junit.Test)5 ChangeInfo (com.google.gerrit.client.info.ChangeInfo)4 GerritCallback (com.google.gerrit.client.rpc.GerritCallback)4 PositionCallback (com.google.gwt.user.client.ui.PopupPanel.PositionCallback)4 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 Button (com.google.gwt.user.client.ui.Button)2 CherryPickDialog (com.google.gerrit.client.ui.CherryPickDialog)1 CreateChangeDialog (com.google.gerrit.client.ui.CreateChangeDialog)1 RebaseDialog (com.google.gerrit.client.ui.RebaseDialog)1 TextAreaActionDialog (com.google.gerrit.client.ui.TextAreaActionDialog)1 JsArray (com.google.gwt.core.client.JsArray)1 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 Style (com.google.gwt.dom.client.Style)1 FocusEvent (com.google.gwt.event.dom.client.FocusEvent)1 ResizeEvent (com.google.gwt.event.logical.shared.ResizeEvent)1 ResizeHandler (com.google.gwt.event.logical.shared.ResizeHandler)1 HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)1 Request (com.google.gwt.http.client.Request)1