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

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

Introduction

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

Prototype

PopupPanel.PositionCallback

Source Link

Usage

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

private static void renderActuatorPopups() {
    stop();//from   ww w  .j ava2 s  .  co m
    for (String controller : Data.controllerActuatorList.keySet()) {
        ArrayList<PopupPanel> popups = new ArrayList<>();
        for (String actuators : Data.controllerActuatorList.get(controller)) {
            ArrayList<String> attributes = Data.actuatorAttributeList.get(actuators);
            String name = attributes.get(0);
            String status = attributes.get(2);
            final double x = Double.parseDouble(attributes.get(3));
            final double y = Double.parseDouble(attributes.get(4));
            String controlType = attributes.get(5);

            String icon = Images.getImage(Images.ACTUATOR_CURRENT_ICON, 25);

            Actuator temp = new Actuator(icon, name, status, controlType);

            final PopupPanel container = new PopupPanel();

            actuatorIcons.add(container);

            container.add(temp);
            container.getElement().getStyle().setBackgroundColor("rgba(255,0,0,0.0)");
            container.getElement().getStyle().setBorderWidth(0, Unit.PX);
            container.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
                public void setPosition(int offsetWidth, int offsetHeight) {
                    int left = sitePic.getAbsoluteLeft() + (int) (x * (double) sitePic.getWidth());
                    int top = sitePic.getAbsoluteTop() + (int) (y * (double) sitePic.getHeight());
                    container.setPopupPosition(left, top);
                }
            });
            container.setVisible(false);
            popups.add(container);
        }
        controllerActuatorPopupList.put(controller, popups);
    }
}

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

private static void renderControllerPopups() {
    for (String site : Data.siteControllerList.keySet()) {
        ArrayList<PopupPanel> popups = new ArrayList<>();

        for (String controller : Data.siteControllerList.get(site)) {
            ArrayList<String> attributes = Data.controllerAttributeList.get(controller);

            final String name = attributes.get(0);
            final double x = Double.parseDouble(attributes.get(2));
            final double y = Double.parseDouble(attributes.get(3));

            Controller cToggle = new Controller(controller);

            final PopupPanel container = new PopupPanel();

            controllerIcons.add(container);

            container.add(cToggle);/* www .  ja  v a 2 s . co  m*/
            container.getElement().getStyle().setBackgroundColor("rgba(255,0,0,0.0)");
            container.getElement().getStyle().setBorderWidth(0, Unit.PX);
            container.setTitle(name);

            container.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
                public void setPosition(int offsetWidth, int offsetHeight) {
                    int left = sitePic.getAbsoluteLeft() + (int) (x * (double) sitePic.getWidth());
                    int top = sitePic.getAbsoluteTop() + (int) (y * (double) sitePic.getHeight());
                    container.setPopupPosition(left, top);
                }
            });
            container.setVisible(false);
            popups.add(container);
        }
        siteControllerPopupList.put(site, popups);
    }
}

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

private static void renderSensorPopups() {
    for (String controller : Data.controllerSensorList.keySet()) {
        ArrayList<PopupPanel> popups = new ArrayList<>();
        for (String sensors : Data.controllerSensorList.get(controller)) {
            ArrayList<String> attributes = Data.sensorAttributeList.get(sensors);

            String name = attributes.get(0);
            String type = attributes.get(1);
            final double x = Double.parseDouble(attributes.get(9));
            final double y = Double.parseDouble(attributes.get(10));
            String icon = setSensorIcon(type);

            Sensor temp = new Sensor(icon, name);

            final PopupPanel container = new PopupPanel();

            sensorIcons.add(container);/*from ww  w .ja  v a2s .  c om*/

            container.add(temp);
            container.getElement().getStyle().setBackgroundColor("rgba(255,0,0,0.0)");
            container.getElement().getStyle().setBorderWidth(0, Unit.PX);
            container.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
                public void setPosition(int offsetWidth, int offsetHeight) {
                    int left = sitePic.getAbsoluteLeft() + (int) (x * (double) sitePic.getWidth());
                    int top = sitePic.getAbsoluteTop() + (int) (y * (double) sitePic.getHeight());
                    container.setPopupPosition(left, top);
                }
            });
            container.setVisible(false);
            popups.add(container);
        }
        controllerSensorPopupList.put(controller, popups);
    }
}

From source file:cz.filmtit.client.subgestbox.SubgestBox.java

License:Open Source License

/**
 * Display the suggestion widget with the suggestions from the underlying
 * TranslationResult.//from   w  w  w.j ava2  s. co m
 */
public void showSuggestions() {

    if (this.getSuggestions().size() > 0) {

        // showing the suggestions always below this SubgestBox:
        final UIObject relativeObject = this;
        suggestPanel.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
            @Override
            public void setPosition(int offsetWidth, int offsetHeight) {
                // Calculate left position for the popup
                int left = relativeObject.getAbsoluteLeft();
                // Calculate top position for the popup
                int top = relativeObject.getAbsoluteTop();
                // Position below the textbox:
                top += relativeObject.getOffsetHeight();
                suggestPanel.setPopupPosition(left, top);
            }
        });
        suggestionWidget.setWidth(this.getOffsetWidth() + "px");
    }
}

From source file:org.codehaus.enunciate.samples.petclinic.app.client.Owners.java

License:Apache License

public Owners() {
    final ClinicAsync clinic = ClinicAsync.Util.getInstance();
    FlowPanel searchPanel = new FlowPanel();
    final Grid grid = new Grid();
    final VerticalPanel layout = new VerticalPanel();
    final TextBox searchBox = new TextBox();
    searchPanel.add(searchBox);//from  w  w  w. java  2 s  .c o  m
    searchPanel.add(new Button("find", new ClickListener() {
        public void onClick(Widget widget) {
            if (searchBox.getText().length() > 0) {
                clinic.findOwners(searchBox.getText(), new AsyncCallback<Collection<Owner>>() {
                    public void onSuccess(Collection<Owner> collection) {
                        if (collection.size() == 0) {
                            grid.resize(1, 1);
                            grid.setWidget(0, 0, new Label(
                                    "No owners of last name '" + searchBox.getText() + "' were found."));
                        } else {
                            grid.resize(collection.size() + 1, 4);
                            grid.setWidget(0, 0, new Label("name"));
                            grid.setWidget(0, 1, new Label("phone"));
                            grid.setWidget(0, 2, new Label("address"));
                            grid.setWidget(0, 3, new Label("city"));
                            grid.getCellFormatter().setWidth(0, 1, "12em");
                            grid.getCellFormatter().setHorizontalAlignment(0, 0, HasAlignment.ALIGN_CENTER);
                            grid.getCellFormatter().setHorizontalAlignment(0, 1, HasAlignment.ALIGN_CENTER);
                            grid.getCellFormatter().setHorizontalAlignment(0, 2, HasAlignment.ALIGN_CENTER);
                            grid.getCellFormatter().setHorizontalAlignment(0, 3, HasAlignment.ALIGN_CENTER);
                            grid.getRowFormatter().setStyleName(0, "clinic-tables-header");
                            int row = 1;
                            Iterator<Owner> it = collection.iterator();
                            while (it.hasNext()) {
                                final Owner owner = it.next();
                                final Label nameLabel = new Label(
                                        owner.getFirstName() + " " + owner.getLastName());
                                nameLabel.addStyleName("clinic-clickable");
                                nameLabel.addClickListener(new ClickListener() {
                                    public void onClick(Widget widget) {
                                        final DialogBox detailsPanel = new DialogBox(true);
                                        final VerticalPanel petList = new VerticalPanel();
                                        petList.add(new Label("Pets of " + nameLabel.getText() + ":"));
                                        detailsPanel.setWidget(petList);
                                        detailsPanel.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
                                            public void setPosition(int offsetWidth, int offsetHeight) {
                                                detailsPanel.setPopupPosition(nameLabel.getAbsoluteLeft(),
                                                        nameLabel.getAbsoluteTop());
                                            }
                                        });
                                        Iterator petsIt = owner.getPetIds().iterator();
                                        while (petsIt.hasNext()) {
                                            final Integer petId = (Integer) petsIt.next();
                                            clinic.loadPet(petId.intValue(), new AsyncCallback<Pet>() {
                                                public void onSuccess(Pet response) {
                                                    petList.add(new Label("A " + response.getType().getName()
                                                            + " named " + response.getName() + "."));
                                                }

                                                public void onFailure(Throwable throwable) {
                                                    petList.add(new Label("Error loading pet " + petId + ": "
                                                            + throwable.getMessage()));
                                                }
                                            });
                                        }
                                    }
                                });
                                grid.setWidget(row, 0, nameLabel);
                                grid.setWidget(row, 1, new Label(owner.getTelephone()));
                                grid.setWidget(row, 2, new Label(owner.getAddress()));
                                grid.setWidget(row, 3, new Label(owner.getCity()));
                                row++;
                            }
                        }
                    }

                    public void onFailure(Throwable throwable) {
                        grid.resize(1, 1);
                        grid.setWidget(0, 0, new Label("ERROR: " + throwable.getMessage()));
                    }
                });
            }
        }
    }));
    layout.add(searchPanel);
    layout.add(grid);
    initWidget(layout);
}

From source file:org.codehaus.enunciate.samples.petclinic.app.client.Vets.java

License:Apache License

public Vets() {
    grid = new Grid();
    final ClinicAsync clinic = ClinicAsync.Util.getInstance();
    clinic.getVets(new AsyncCallback<Collection<Vet>>() {
        public void onSuccess(Collection<Vet> collection) {
            grid.resize(collection.size() + 1, 2);
            grid.setWidget(0, 0, new Label("name"));
            grid.setWidget(0, 1, new Label("action"));
            grid.getCellFormatter().setWidth(0, 1, "12em");
            grid.getCellFormatter().setHorizontalAlignment(0, 0, HasAlignment.ALIGN_CENTER);
            grid.getCellFormatter().setHorizontalAlignment(0, 1, HasAlignment.ALIGN_CENTER);
            grid.getRowFormatter().setStyleName(0, "clinic-tables-header");
            int row = 1;
            Iterator<Vet> vetsIt = collection.iterator();
            while (vetsIt.hasNext()) {
                final Vet vet = vetsIt.next();
                final Label details = new Label(vet.getFirstName() + " " + vet.getLastName());
                details.addClickListener(new ClickListener() {
                    public void onClick(Widget widget) {
                        final DialogBox detailsPanel = new DialogBox(true);
                        String html = "Id: " + vet.getId() + "<br/>First Name: " + vet.getFirstName()
                                + "<br/>Last Name: " + vet.getLastName() + "<br/>Phone: " + vet.getTelephone()
                                + "<br/>Specialties: ";
                        Iterator specialtiesIt = vet.getSpecialties().iterator();
                        while (specialtiesIt.hasNext()) {
                            Specialty specialty = (Specialty) specialtiesIt.next();
                            html = html + specialty.getName();
                            if (specialtiesIt.hasNext()) {
                                html += ",";
                            }//from w w w. j  a  va 2s.c  o m
                        }
                        HTML htmlValue = new HTML(html);
                        htmlValue.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
                        detailsPanel.setWidget(htmlValue);
                        detailsPanel.setTitle(vet.getFirstName() + " " + vet.getLastName());
                        detailsPanel.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
                            public void setPosition(int offsetWidth, int offsetHeight) {
                                detailsPanel.setPopupPosition(details.getAbsoluteLeft(),
                                        details.getAbsoluteTop());
                            }
                        });
                    }
                });
                details.addStyleName("clinic-clickable");
                grid.setWidget(row, 0, details);
                grid.setWidget(row, 1, new Button("delete", new ClickListener() {
                    public void onClick(Widget widget) {
                        Window.alert("You don't have permission to delete a vet");
                    }
                }));
                row++;
            }
        }

        public void onFailure(Throwable throwable) {
            grid.resize(1, 1);
            grid.setWidget(0, 0, new Label("ERROR: " + throwable.getMessage()));
        }
    });
    initWidget(grid);
}

From source file:org.rstudio.studio.client.workbench.views.files.ui.FileUploadDialog.java

License:Open Source License

@Override
protected void positionAndShowDialog(final Command onCompleted) {
    final PopupPanel thisPanel = this;
    setPopupPositionAndShow(new PopupPanel.PositionCallback() {
        public void setPosition(int offsetWidth, int offsetHeight) {
            int left = (Window.getClientWidth() / 2) - (offsetWidth / 2);
            int top = (Window.getClientHeight() / 2) - (offsetHeight / 2);
            // clip the top so the choose file dialog always appears 
            // over the file upload dialog (mostly a problem on osx)
            top = Math.min(top, 200);

            thisPanel.setPopupPosition(left, top);

            onCompleted.execute();/*  ww  w .j a v  a2 s  .c  om*/
        }
    });
}

From source file:org.seamless.gwt.notify.client.PopupNotificationDisplay.java

License:Open Source License

@Override
public void showMessage(final Message message) {

    final PopupMessagePanel messagePanel = new PopupMessagePanel(message);

    messagePanel.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
        public void setPosition(int offsetWidth, int offsetHeight) {
            int originLeft = Window.getScrollLeft() + Window.getClientWidth() - offsetWidth
                    - MARGIN_RIGHT_PIXEL;
            int originTop = Window.getScrollTop() + Window.getClientHeight() - offsetHeight
                    - MARGIN_BOTTOM_PIXEL;
            setRelativePosition(messagePanels.values(), messagePanel, originLeft, originTop, originTop,
                    offsetHeight, offsetWidth);
        }//ww w . j a v  a 2 s.  com
    });

    messagePanels.put(message, messagePanel);
}