Example usage for com.google.gwt.user.client Command Command

List of usage examples for com.google.gwt.user.client Command Command

Introduction

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

Prototype

Command

Source Link

Usage

From source file:accelerator.client.view.desktop.DesktopMainMenuView.java

License:Open Source License

@UiHandler("createButton")
void onCreateButtonClick(ClickEvent e) {
    final PopupPanel popup = new PopupPanel(true, false);
    MenuBar menu = new MenuBar(true);
    menu.addItem("?", new Command() {
        public void execute() {
            popup.hide();//from  ww w.  j a v  a  2 s.c o m
            ProjectDialogBox dlg = new ProjectDialogBox();
            dlg.setHandler(new ProjectDialogBox.Handler() {
                public void onOk(Project input) {
                    handler.createProject(input);
                }
            });
            dlg.center();
        }
    });
    menu.addItem("?", new Command() {
        public void execute() {
            popup.hide();
            TagDialogBox dlg = new TagDialogBox();
            dlg.setHandler(new TagDialogBox.Handler() {
                public void onOk(Tag input) {
                    handler.createTag(input);
                }
            });
            dlg.center();
        }
    });
    popup.setWidget(menu);
    popup.setPopupPositionAndShow(new PositionCallback() {
        public void setPosition(int offsetWidth, int offsetHeight) {
            int left = createButton.getAbsoluteLeft();
            int top = createButton.getAbsoluteTop() - offsetHeight;
            popup.setPopupPosition(left, top);
        }
    });
}

From source file:accelerator.client.view.desktop.DesktopMainMenuView.java

License:Open Source License

@UiHandler("editButton")
void onEditButtonClick(ClickEvent e) {
    final PopupPanel popup = new PopupPanel(true, false);
    MenuBar menu = new MenuBar(true);

    {//from   ww w  .jav  a2 s .c om
        final Project p = getSelectedProject();
        final boolean isProjectSelected = p != null;

        // 
        MenuItem edit = new MenuItem("", new Command() {
            public void execute() {
                assert (p != null);
                popup.hide();
                ProjectDialogBox dlg = new ProjectDialogBox(p);
                dlg.setHandler(new ProjectDialogBox.Handler() {
                    public void onOk(Project input) {
                        handler.updateProject(input);
                    }
                });
                dlg.center();
            }
        });
        edit.setEnabled(isProjectSelected);
        menu.addItem(edit);

        // 
        MenuItem delete = new MenuItem("", new Command() {
            public void execute() {
                assert (p != null);
                popup.hide();
                handler.deleteProject(p);
            }
        });
        delete.setEnabled(isProjectSelected);
        menu.addItem(delete);
    }

    menu.addSeparator();

    {
        final Tag t = getSelectedTag();
        final boolean isTagSelected = t != null;

        // 
        MenuItem edit = new MenuItem("", new Command() {
            public void execute() {
                assert (t != null);
                popup.hide();
                TagDialogBox dlg = new TagDialogBox(t);
                dlg.setHandler(new TagDialogBox.Handler() {
                    public void onOk(Tag input) {
                        handler.updateTag(input);
                    }
                });
                dlg.center();
            }
        });
        edit.setEnabled(isTagSelected);
        menu.addItem(edit);

        // 
        MenuItem delete = new MenuItem("", new Command() {
            public void execute() {
                assert (t != null);
                popup.hide();
                handler.deleteTag(t);
            }
        });
        delete.setEnabled(isTagSelected);
        menu.addItem(delete);
    }

    popup.setWidget(menu);
    popup.setPopupPositionAndShow(new PositionCallback() {
        public void setPosition(int offsetWidth, int offsetHeight) {
            int left = editButton.getAbsoluteLeft();
            int top = editButton.getAbsoluteTop() - offsetHeight;
            popup.setPopupPosition(left, top);
        }
    });
}

From source file:anzsoft.xmpp4gwt.client.Bosh2Connector.java

License:Open Source License

public Bosh2Connector(final User user) {
    this.setUser(user);
    standardHandler = new RequestCallback() {

        public void onError(Request request, Throwable exception) {
            final String lastSendedBody = activeRequests.remove(request);
            if (exception instanceof RequestTimeoutException) {
                GWT.log("Request too old. Trying again.", null);
                DeferredCommand.addCommand(new Command() {
                    public void execute() {
                        if (lastSendedBody != null && state == State.connected && sid != null
                                && sid.length() > 0)
                            send(lastSendedBody, standardHandler);
                        else
                            continuousConnection(null);
                    }/*from www.  j  a  v a  2s. co  m*/
                });
            } else if (exception.getMessage().startsWith("Unable to read XmlHttpRequest.status;")) {
                GWT.log("Lost request. Ignored. Resend.", null);
                if (lastSendedBody != null) {
                    DeferredCommand.addCommand(new Command() {
                        public void execute() {
                            if (state == State.connected && sid != null && sid.length() > 0) {
                                send(lastSendedBody, standardHandler);
                            }
                        }
                    });
                }
            } else {
                state = State.disconnected;
                GWT.log("Connection error", exception);
                exception.printStackTrace();
                fireEventError(BoshErrorCondition.remote_connection_failed, null,
                        "Response error: " + exception.getMessage());
            }
        }

        public void onResponseReceived(Request request, Response response) {
            if (state == State.disconnected)
                return;

            final String httpResponse = response.getText();
            final int httpStatusCode = response.getStatusCode();
            final String lastSendedBody = activeRequests.remove(request);

            System.out.println(" IN (" + httpStatusCode + "): " + httpResponse);
            fireOnBodyReceive(response, httpResponse);

            final Packet body = parse2(response.getText().replaceAll(";", ";"));

            final String type = body == null ? null : body.getAtribute("type");
            final String receivedSid = body == null ? null : body.getAtribute("sid");
            String $tmp = body == null ? null : body.getAtribute("rid");
            //final Long rid = $tmp == null ? null : Long.valueOf($tmp);
            final String ack = body == null ? null : body.getAtribute("ack");
            $tmp = body == null ? null : body.getAtribute("condition");
            if ($tmp != null)
                $tmp = $tmp.replace("-", "_");
            final BoshErrorCondition boshCondition = $tmp == null ? null : BoshErrorCondition.valueOf($tmp);

            final String wait = body == null ? null : body.getAtribute("wait");
            final String inactivity = body == null ? null : body.getAtribute("inactivity");
            if (wait != null && inactivity != null) {
                try {
                    int w = Integer.parseInt(wait);
                    int i = Integer.parseInt(inactivity);
                    int t = (w + i / 2) * 1000;
                    builder.setTimeoutMillis(t);
                    GWT.log("New timeout: " + t + "ms", null);
                } catch (Exception e) {
                    GWT.log("Error in wait and inactivity attributes", e);
                }
            }

            if (httpStatusCode != 200 || body == null
                    || type != null && ("terminate".equals(type) || "error".equals(type))) {
                GWT.log("ERROR (" + httpStatusCode + "): " + httpResponse, null);
                ErrorCondition condition = body == null ? ErrorCondition.bad_request
                        : ErrorCondition.undefined_condition;
                String msg = null;
                Packet error = body == null ? null : body.getFirstChild("error");
                if (error != null) {
                    for (Packet c : error.getChildren()) {
                        String xmlns = c.getAtribute("xmlns");
                        if ("text".equals(c.getName())) {
                            msg = c.getCData();
                            break;
                        } else if (xmlns != null && "urn:ietf:params:xml:ns:xmpp-stanzas".equals(xmlns)) {
                            condition = getCondition(c.getName(), httpStatusCode);
                        }
                    }
                }

                if (condition == ErrorCondition.item_not_found) {
                    state = State.disconnected;
                    fireEventError(boshCondition, condition, msg);
                } else if (errorCounter < MAX_ERRORS) {
                    errorCounter++;
                    send(lastSendedBody, standardHandler);
                } else if (type != null && "terminate".equals(type)) {
                    GWT.log("Disconnected by server", null);
                    state = State.disconnected;
                    fireDisconnectByServer(boshCondition, condition, msg);
                } else {
                    state = State.disconnected;
                    if (msg == null) {
                        msg = "[" + httpStatusCode + "] " + condition.name().replace('_', '-');
                    }
                    fireEventError(boshCondition, condition, msg);
                }
            } else {
                errorCounter = 0;
                if (receivedSid != null && sid != null && !receivedSid.equals(sid)) {
                    state = State.disconnected;
                    fireEventError(BoshErrorCondition.policy_violation, ErrorCondition.unexpected_request,
                            "Unexpected session initialisation.");
                } else if (receivedSid != null && sid == null) {
                    sid = receivedSid;
                    Cookies.setCookie(user.getResource() + "sid", sid, null, null, "/", false);
                    state = State.connected;
                }

                final List<? extends Packet> children = body.getChildren();
                if (children.size() > 0) {
                    fireEventReceiveStanzas(children);
                }
                continuousConnection(ack);
            }
            System.out.println("............sid value is:" + sid);
        }
    };

    //added by zhongfanglin@antapp.com
    scriptHandler = new ScriptSyntaxRequestCallback() {
        public void onError(String callbackID) {
            state = State.disconnected;
            GWT.log("Connection error", null);
            fireEventError(BoshErrorCondition.remote_connection_failed, null,
                    "Response error: request timeout or 404!");
        }

        public void onResponseReceived(String callbackID, String responseText) {

            if (state == State.disconnected)
                return;

            final String httpResponse = responseText;
            final String lastSendedBody = activeScriptRequests.remove(callbackID);

            System.out.println(" IN:" + httpResponse);
            fireOnBodyReceive(null, httpResponse);

            final Packet body = parse2(responseText.replaceAll("&semi;", ";"));

            final String type = body == null ? null : body.getAtribute("type");
            final String receivedSid = body == null ? null : body.getAtribute("sid");
            String $tmp = body == null ? null : body.getAtribute("rid");
            //final Long rid = $tmp == null ? null : Long.valueOf($tmp);
            final String ack = body == null ? null : body.getAtribute("ack");
            $tmp = body == null ? null : body.getAtribute("condition");
            if ($tmp != null)
                $tmp = $tmp.replace("-", "_");
            final BoshErrorCondition boshCondition = $tmp == null ? null : BoshErrorCondition.valueOf($tmp);

            final String wait = body == null ? null : body.getAtribute("wait");
            final String inactivity = body == null ? null : body.getAtribute("inactivity");
            if (wait != null && inactivity != null) {
                try {
                    int w = Integer.parseInt(wait);
                    int i = Integer.parseInt(inactivity);
                    int t = (w + i / 2) * 1000;
                    scriptBuilder.setTimeoutMillis(t);
                    GWT.log("New timeout: " + t + "ms", null);
                } catch (Exception e) {
                    GWT.log("Error in wait and inactivity attributes", e);
                }
            }

            if (body == null || type != null && ("terminate".equals(type) || "error".equals(type))) {
                GWT.log("ERROR : " + httpResponse, null);
                ErrorCondition condition = body == null ? ErrorCondition.bad_request
                        : ErrorCondition.undefined_condition;
                String msg = null;
                Packet error = body == null ? null : body.getFirstChild("error");
                if (error != null) {
                    for (Packet c : error.getChildren()) {
                        String xmlns = c.getAtribute("xmlns");
                        if ("text".equals(c.getName())) {
                            msg = c.getCData();
                            break;
                        } else if (xmlns != null && "urn:ietf:params:xml:ns:xmpp-stanzas".equals(xmlns)) {
                            condition = getCondition(c.getName(), -1);
                        }
                    }
                }

                if (condition == ErrorCondition.item_not_found) {
                    state = State.disconnected;
                    fireEventError(boshCondition, condition, msg);
                } else if (errorCounter < MAX_ERRORS) {
                    errorCounter++;
                    send(lastSendedBody, scriptHandler);
                } else if (type != null && "terminate".equals(type)) {
                    GWT.log("Disconnected by server", null);
                    state = State.disconnected;
                    fireDisconnectByServer(boshCondition, condition, msg);
                } else {
                    state = State.disconnected;
                    if (msg == null) {
                        msg = condition.name().replace('_', '-');
                    }
                    fireEventError(boshCondition, condition, msg);
                }
            } else {
                errorCounter = 0;
                if (receivedSid != null && sid != null && !receivedSid.equals(sid)) {
                    state = State.disconnected;
                    fireEventError(BoshErrorCondition.policy_violation, ErrorCondition.unexpected_request,
                            "Unexpected session initialisation.");
                } else if (receivedSid != null && sid == null) {
                    sid = receivedSid;
                    Cookies.setCookie(user.getResource() + "sid", sid, null, null, "/", false);
                    state = State.connected;
                }

                List<? extends Packet> children = body.getChildren();
                if (children.size() > 0) {
                    fireEventReceiveStanzas(children);
                }
                continuousConnection(ack);
            }
        }

    };
    //end added 
}

From source file:anzsoft.xmpp4gwt.client.Session.java

License:Open Source License

public void logout() {
    Presence presence = presencePlugin.offlinePresence();
    con.disconnect(presence);/* w ww.java2  s.  c  o  m*/
    DeferredCommand.addCommand(new Command() {

        public void execute() {
            reset();
        }
    });
    fireOnLoginOut();
}

From source file:ar.com.german.ExpresionesLibres.client.app.ApplicationPresenter.java

License:Apache License

@Override
protected void onBind() {

    MenuItem generadorReglas = new MenuItem("Generador de Reglas", false, new Command() {

        public void execute() {
            PlaceRequest request = new PlaceRequest.Builder().nameToken(NameTokens.generadorDeReglas).build();
            placeManager.revealPlace(request);
        }// w w w .j a v a 2 s .  com
    });

    getView().getMenuBar().addItem(generadorReglas);

    MenuItem probarReglas = new MenuItem("Probar Reglas", false, new Command() {
        public void execute() {
            PlaceRequest request = new PlaceRequest.Builder().nameToken(NameTokens.probador).build();
            placeManager.revealPlace(request);
        }
    });

    getView().getMenuBar().addItem(probarReglas);

    MenuItem archivos = new MenuItem("HTML 5 File API", false, new Command() {
        public void execute() {
            PlaceRequest request = new PlaceRequest.Builder().nameToken(NameTokens.filesystem).build();
            placeManager.revealPlace(request);
        }
    });

    getView().getMenuBar().addItem(archivos);

    super.onBind();

}

From source file:asquare.gwt.sb.client.util.CommandQueueDeferred.java

License:Apache License

protected void deferRun() {
    //      Debug.println("CommandQueue.deferRun()");
    if (m_runScheduled)
        return;/* w ww  . j  a  v  a  2s . c o m*/

    m_runScheduled = true;

    DeferredCommand.addCommand(new Command() {
        public void execute() {
            m_runScheduled = false;
            run();
        }
    });
}

From source file:asquare.gwt.tk.uitest.alertdialog.client.Demo.java

License:Apache License

public void onModuleLoad() {
    Debug.enable();//from   ww w .  j  a v a 2  s.  co  m

    new DebugEventListener('x', Event.ONMOUSEDOWN, null) {
        @Override
        protected void doEvent(Event event) {
            Element target = DOM.eventGetTarget(event);
            Debug.println("target=" + DebugUtil.prettyPrintElement(target));
            int screenX = DOM.eventGetScreenX(event);
            int screenY = DOM.eventGetScreenY(event);
            int clientX = DOM.eventGetClientX(event);
            int clientY = DOM.eventGetClientY(event);
            int absLeft = DOM.getAbsoluteLeft(target);
            int absTop = DOM.getAbsoluteTop(target);
            int offsetLeft = getOffsetLeft(target);
            int offsetTop = getOffsetTop(target);
            int docScrollX = Window.getScrollLeft();
            int docScrollY = Window.getScrollTop();
            Debug.println("screenX=" + screenX + ",screenY=" + screenY + ",clientX=" + clientX + ",clientY="
                    + clientY + ",absLeft=" + absLeft + ",absTop=" + absTop + ",offsetLeft=" + offsetLeft
                    + ",offsetTop=" + offsetTop + ",docScrollX=" + docScrollX + ",docScrollY=" + docScrollY);
        }
    }.install();
    new DebugEventListener('z', Event.ONMOUSEDOWN, "Offset hierarchy inspector") {
        @Override
        protected void doEvent(Event event) {
            Element target = DOM.eventGetTarget(event);
            printOffsetTopHierarchy(target);
        }
    }.install();

    new DebugHierarchyInspector().install();

    new DebugElementDumpInspector().install();

    new DebugEventListener(Event.ONMOUSEDOWN | Event.ONMOUSEUP).install();

    if (!GWT.isScript()) {
        DebugConsole.getInstance().disable();
    }

    final Button button = new Button();
    button.setText("Default Info dialog");
    button.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            final AlertDialog alert = AlertDialog.createInfo(new Command() {
                public void execute() {
                    Debug.println("OK clicked");
                }
            }, "Info Dialog", "this is a default info dialog");
            alert.show();
        }
    });
    RootPanel.get().add(button);

    Command showDialog = new Command() {
        private AlertDialog m_dialog;

        public void execute() {
            if (m_dialog == null) {
                m_dialog = AlertDialog.createWarning(this, "Caption text", null);
                ScrollPanel message = new ScrollPanel();
                message.setAlwaysShowScrollBars(true);
                message.setWidth("100%");
                message.setHeight("100px");
                message.setWidget(new Label(
                        "These packages contain reference information about the main GWT user interface and utility classes. For higher-level explanations of how to take advantage of all this stuff, check out the Developer Guide. Among other things, there's a handy widget gallery and an explanation of how remote procedure calls work.These packages contain reference information about the main GWT user interface and utility classes. For higher-level explanations of how to take advantage of all this stuff, check out the Developer Guide. Among other things, there's a handy widget gallery and an explanation of how remote procedure calls work."));
                m_dialog.setMessage(message);
                m_dialog.setSize("400px", "300px");
                m_dialog.addController(new ControllerAdaptor(Controller.class, Event.ONMOUSEDOWN) {
                    @Override
                    public void onBrowserEvent(Widget widget, Event event) {
                        int x = DomUtil.eventGetAbsoluteX(event) - DOM.getAbsoluteLeft(widget.getElement());
                        int y = DomUtil.eventGetAbsoluteY(event) - DOM.getAbsoluteTop(widget.getElement());
                        Debug.println("onMouseDown(" + x + "," + y + ")");
                    }
                });
            }
            m_dialog.show();
        }
    };
    showDialog.execute();
}

From source file:at.ait.dme.yuma.client.image.annotation.ImageAnnotationComposite.java

License:EUPL

/**
 * the image annotation composite constructor. needs an image composite
 * to show and hide fragments./*www .  j  a  v a 2s.c  o m*/
 * 
 * @param imageComposite
 */
public ImageAnnotationComposite(ImageComposite imageComposite, ImageAnnotationForm imageAnnotationForm,
        Set<String> shapeTypes) {
    this.imageComposite = imageComposite;
    this.imageAnnotationForm = imageAnnotationForm;
    this.shapeTypes = shapeTypes;

    // Container panel for annotation tree & controls
    containerPanel.setStyleName("imageAnnotation-composite");
    containerPanel.add(createHeader(), new BorderLayoutData(BorderLayout.Region.NORTH));

    // 'Loading' panel
    loadingPanel.setHorizontalAlignment(DockPanel.ALIGN_CENTER);
    loadingPanel.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
    loadingPanel.add(loadingImage, DockPanel.CENTER);

    // Annotation tree
    createTree(shapeTypes);

    // Register annotation selection handler on image composite
    imageComposite.addImageAnnotationSelectionHandler(new ImageAnnotationSelectionHandler() {
        @Override
        public void onAnnotationSelection(ImageAnnotationSelectionEvent event) {
            final ImageAnnotationTreeNode node = annotationTree.getAnnotationNode(event.getAnnotation());
            if (node == null)
                return;

            annotationTree.selectAnnotationTreeNode(node, event.isSelected());
            if (event.isSelected()) {
                DeferredCommand.addCommand(new Command() {
                    public void execute() {
                        scrollPanel.ensureVisible(node.getAnnotationTreeItem());
                    }
                });
            }
        }
    });

    deckPanel.add(loadingPanel);
    deckPanel.add(scrollPanel);

    enableLoadingImage();

    containerPanel.add(deckPanel);
    initWidget(containerPanel);
}

From source file:at.ait.dme.yuma.client.image.annotation.ImageAnnotationComposite.java

License:EUPL

/**
 * shows the annotation form either underneath a tree node in case of an
 * update or reply to an existing annotation, or above the annotation tree
 * in case of an new annotation. if it is a fragment annotation it will also
 * show the active fragment panel.//www .  j  a v a 2s . c  om
 * 
 * @param annotationTreeNode
 * @param fragmentAnnotation true if annotation has a fragment, otherwise false
 * @param update true if the user updates an existing annotation, otherwise false
 */
public void showAnnotationForm(final ImageAnnotationTreeNode annotationTreeNode, boolean fragmentAnnotation,
        boolean update) {

    imageAnnotationForm = imageAnnotationForm.createNew(this, annotationTreeNode, fragmentAnnotation, update);

    scrollPosition = scrollPanel.getScrollPosition();

    if (annotationTreeNode != null) {
        annotationTreeNode.showAnnotationForm(imageAnnotationForm);
        DeferredCommand.addCommand(new Command() {
            public void execute() {
                scrollPanel.ensureVisible(imageAnnotationForm);
            }
        });

        if (fragmentAnnotation) {
            // if we update an existing annotation we first have to remove the
            // existing fragment and show an active fragment panel instead.
            if (update && annotationTreeNode.getImageFragment() != null) {
                imageComposite.showActiveFragmentPanel(annotationTreeNode.getAnnotation(), true);
                imageComposite.hideFragment(annotationTreeNode.getAnnotation());
            } else {
                imageComposite.showActiveFragmentPanel(null, true);
            }
        }
    } else {
        annotateButton.setEnabled(false);
        annotateFragmentButton.setEnabled(false);
        annotationFormPanel.add(imageAnnotationForm);
        if (fragmentAnnotation)
            imageComposite.showActiveFragmentPanel(null, true);
    }

    layout();
}

From source file:at.ait.dme.yuma.client.image.annotation.ImageAnnotationComposite.java

License:EUPL

/**
 *  hides the annotation form, again either from above the annotation tree or from
 *  underneath a tree node, also hides the active fragment panel. if in case of
 *  an update the operation was canceled we have to restore a possible fragment.
 *  //from ww  w .  ja v  a 2  s.c om
 *  @param annotationTreeNode
 *    @param canceled true if the user canceled the operation, otherwise false
 *  @see #showAnnotationForm(ImageAnnotationTreeNode, boolean, boolean)
 */
public void hideAnnotationForm(final ImageAnnotationTreeNode annotationTreeNode, boolean canceled) {

    if (annotationTreeNode == null) {
        annotationFormPanel.clear();
        annotateButton.setEnabled(true);
        annotateFragmentButton.setEnabled(true);
    } else {
        annotationTreeNode.hideAnnotationForm();
        DeferredCommand.addCommand(new Command() {
            public void execute() {
                scrollPanel.setScrollPosition(scrollPosition);
                annotationTree.setSelectedItem(annotationTreeNode.getAnnotationTreeItem());
            }
        });
    }

    imageComposite.hideActiveFragmentPanel();
    if (canceled && annotationTreeNode != null && annotationTreeNode.getImageFragment() != null) {
        imageComposite.showFragment(annotationTreeNode.getAnnotation());
    }

    layout();
}