Example usage for com.google.gwt.user.client Window getClientWidth

List of usage examples for com.google.gwt.user.client Window getClientWidth

Introduction

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

Prototype

public static int getClientWidth() 

Source Link

Usage

From source file:org.drools.guvnor.client.modeldriven.ui.RuleTemplateEditor.java

License:Apache License

private Widget buildTemplateTable() {

    String[] vars = model.getInterpolationVariablesList();
    if (vars.length == 0) {
        return new Label("");
    }/*  w  w  w. j  a  va 2s  .c  om*/

    FieldDef[] fds = new FieldDef[vars.length];
    ColumnConfig[] cols = new ColumnConfig[fds.length];

    int idx = 0;
    for (String var : vars) {
        cols[idx] = new ColumnConfig();
        cols[idx].setHeader(var);
        cols[idx].setDataIndex(var);
        cols[idx].setSortable(false);
        cols[idx].setWidth(50);
        cols[idx].setResizable(true);
        cols[idx].setEditor(new GridEditor(new TextField()));
        fds[idx] = new StringFieldDef(var);
        idx++;
    }
    final RecordDef recordDef = new RecordDef(fds);
    ArrayReader reader = new ArrayReader(recordDef);

    MemoryProxy proxy = new MemoryProxy(model.getTableAsArray());

    ColumnModel cm = new ColumnModel(cols);

    for (int i = 0; i < cm.getColumnCount(); i++) {
        cm.setEditable(i, true);
    }
    store = new GroupingStore(proxy, reader);
    store.load();
    grid = new EditorGridPanel(store, cm);
    grid.setStripeRows(true);

    //      GroupingView gv = new GroupingView();
    GridView gv = new GridView();

    // to stretch it out
    gv.setForceFit(true);
    //      gv.setGroupTextTpl("{text} ({[values.rs.length]} {[values.rs.length > 1 ? \"" // NON-NLS
    //            + constants.Items() + "\" : \"" + constants.Item() + "\"]})");

    grid.setView(gv);

    grid.setStore(store);
    grid.setAutoWidth(true);
    grid.setAutoHeight(true);

    Toolbar tb = new Toolbar();
    Menu menu = new Menu();

    menu.addItem(new Item(constants.AddRow(), new BaseItemListenerAdapter() {
        public void onClick(BaseItem item, EventObject e) {
            String[] rowData = new String[recordDef.getFields().length];
            for (int i = 0; i < rowData.length; i++) {
                rowData[i] = "";
            }
            Record newRecord = recordDef.createRecord(rowData);
            store.add(newRecord);
            model.addRow(newRecord.getId(), rowData);
        }
    }));

    menu.addItem(new Item(constants.RemoveSelectedRowS(), new BaseItemListenerAdapter() {
        public void onClick(BaseItem item, EventObject e) {
            removeSelectedRows(grid);
        }
    }));

    grid.addGridListener(new GridListenerAdapter() {

        public void onKeyPress(EventObject e) {
            int k = e.getKey();
            if (k == KeyCodes.KEY_DELETE || k == KeyCodes.KEY_BACKSPACE) {
                removeSelectedRows(grid);
            } else if (k == KeyCodes.KEY_ENTER) {
                int[] selectedCell = grid.getCellSelectionModel().getSelectedCell();
                grid.startEditing(selectedCell[0], selectedCell[1]);
            }
        }
    });
    //      grid.setSelectionModel(new RowSelectionModel(false));
    ToolbarMenuButton tbb = new ToolbarMenuButton(constants.Modify(), menu);
    tb.addButton(tbb);
    grid.add(tb);

    grid.addEditorGridListener(new EditorGridListenerAdapter() {
        @Override
        public void onAfterEdit(GridPanel grid, Record record, String field, Object newValue, Object oldValue,
                int rowIndex, int colIndex) {
            model.setValue(field, rowIndex, (String) newValue);
        }
    });
    grid.setWidth((int) (Window.getClientWidth() * 0.75));
    return grid;
}

From source file:org.drools.guvnor.client.moduleeditor.drools.PackageBuilderWidget.java

License:Apache License

/**
 * Popup the view source dialog, showing the given content.
 *///from   w w  w .  j av a 2s  . co m
public static void showSource(final String content, String name) {
    int windowWidth = Window.getClientWidth() / 2;
    int windowHeight = Window.getClientHeight() / 2;
    Image image = new Image(DroolsGuvnorImageResources.INSTANCE.viewSource());
    image.setAltText(Constants.INSTANCE.ViewSource());
    final FormStylePopup pop = new FormStylePopup(image, Constants.INSTANCE.ViewingSourceFor0(name),
            windowWidth);

    String[] rows = content.split("\n");

    FlexTable table = new FlexTable();
    for (int i = 0; i < rows.length; i++) {

        table.setHTML(i, 0, "<span style='color:grey;'>" + (i + 1) + ".</span>");
        table.setHTML(i, 1, "<span style='color:green;' >|</span>");
        table.setHTML(i, 2, addSyntaxHilights(rows[i]));
    }

    ScrollPanel scrollPanel = new ScrollPanel(table);

    scrollPanel.setHeight(windowHeight + "px");
    scrollPanel.setWidth(windowWidth + "px");

    pop.addRow(scrollPanel);

    LoadingPopup.close();

    pop.show();

}

From source file:org.drools.guvnor.client.moduleeditor.soa.SOAServiceBuilderWidget.java

License:Apache License

/**
 * Popup the view source dialog, showing the given content.
 *//* w  w w.j a v a  2  s.  c o  m*/
public static void showSource(final String content, String name) {
    Constants constants = GWT.create(Constants.class);
    int windowWidth = Window.getClientWidth() / 2;
    int windowHeight = Window.getClientHeight() / 2;
    final FormStylePopup pop = new FormStylePopup(images.viewSource(), constants.ViewingSourceFor0(name),
            windowWidth);

    String[] rows = content.split("\n");

    FlexTable table = new FlexTable();
    for (int i = 0; i < rows.length; i++) {

        table.setHTML(i, 0, "<span style='color:grey;'>" + (i + 1) + ".</span>");
        table.setHTML(i, 1, "<span style='color:green;' >|</span>");
        table.setHTML(i, 2, addSyntaxHilights(rows[i]));
    }

    ScrollPanel scrollPanel = new ScrollPanel(table);

    scrollPanel.setHeight(windowHeight + "px");
    scrollPanel.setWidth(windowWidth + "px");

    pop.addRow(scrollPanel);

    LoadingPopup.close();

    pop.show();

}

From source file:org.drools.guvnor.client.widgets.PopupListWidget.java

License:Apache License

/**
 * Width of pop-up, 75% of the client width or minimumWidth
 * //  w w w .  j  av a2  s .c o  m
 * @return
 */
private int getPopupWidth() {
    int w = (int) (Window.getClientWidth() * 0.75);
    if (w < minimumWidth) {
        w = minimumWidth;
    }
    return w;
}

From source file:org.drools.workbench.screens.guided.dtable.client.widget.AbstractBRLColumnViewImpl.java

License:Apache License

/**
 * Width of pop-up, 50% of the client width or MIN_WIDTH
 * @return//from   w  ww.  j  a  va 2  s .  c  o  m
 */
private int getPopupWidth() {
    int w = (int) (Window.getClientWidth() * 0.5);
    if (w < MIN_WIDTH) {
        w = MIN_WIDTH;
    }
    return w;
}

From source file:org.drools.workbench.screens.guided.dtable.client.widget.GuidedDecisionTableWidget.java

License:Apache License

private Widget newColumn() {
    AddButton addButton = new AddButton();
    addButton.setText(GuidedDecisionTableConstants.INSTANCE.NewColumn());
    addButton.setTitle(GuidedDecisionTableConstants.INSTANCE.AddNewColumn());

    addButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent w) {
            final FormStylePopup pop = new FormStylePopup(GuidedDecisionTableConstants.INSTANCE.AddNewColumn());

            //List of basic column types
            final ListBox choice = new ListBox();
            choice.setVisibleItemCount(NewColumnTypes.values().length);
            choice.setWidth((Window.getClientWidth() * 0.25) + "px");

            choice.addItem(GuidedDecisionTableConstants.INSTANCE.AddNewMetadataOrAttributeColumn(),
                    NewColumnTypes.METADATA_ATTRIBUTE.name());
            choice.addItem(SECTION_SEPARATOR);
            choice.addItem(GuidedDecisionTableConstants.INSTANCE.AddNewConditionSimpleColumn(),
                    NewColumnTypes.CONDITION_SIMPLE.name());
            choice.addItem(SECTION_SEPARATOR);
            choice.addItem(GuidedDecisionTableConstants.INSTANCE.SetTheValueOfAField(),
                    NewColumnTypes.ACTION_UPDATE_FACT_FIELD.name());
            choice.addItem(GuidedDecisionTableConstants.INSTANCE.SetTheValueOfAFieldOnANewFact(),
                    NewColumnTypes.ACTION_INSERT_FACT_FIELD.name());
            choice.addItem(GuidedDecisionTableConstants.INSTANCE.DeleteAnExistingFact(),
                    NewColumnTypes.ACTION_RETRACT_FACT.name());

            //Checkbox to include Advanced Action types
            final CheckBox chkIncludeAdvancedOptions = new CheckBox(
                    SafeHtmlUtils.fromString(GuidedDecisionTableConstants.INSTANCE.IncludeAdvancedOptions()));
            chkIncludeAdvancedOptions.setValue(false);
            chkIncludeAdvancedOptions.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    if (chkIncludeAdvancedOptions.getValue()) {
                        addItem(3, GuidedDecisionTableConstants.INSTANCE.AddNewConditionBRLFragment(),
                                NewColumnTypes.CONDITION_BRL_FRAGMENT.name());
                        addItem(GuidedDecisionTableConstants.INSTANCE.WorkItemAction(),
                                NewColumnTypes.ACTION_WORKITEM.name());
                        addItem(GuidedDecisionTableConstants.INSTANCE.WorkItemActionSetField(),
                                NewColumnTypes.ACTION_WORKITEM_UPDATE_FACT_FIELD.name());
                        addItem(GuidedDecisionTableConstants.INSTANCE.WorkItemActionInsertFact(),
                                NewColumnTypes.ACTION_WORKITEM_INSERT_FACT_FIELD.name());
                        addItem(GuidedDecisionTableConstants.INSTANCE.AddNewActionBRLFragment(),
                                NewColumnTypes.ACTION_BRL_FRAGMENT.name());
                    } else {
                        removeItem(NewColumnTypes.CONDITION_BRL_FRAGMENT.name());
                        removeItem(NewColumnTypes.ACTION_WORKITEM.name());
                        removeItem(NewColumnTypes.ACTION_WORKITEM_UPDATE_FACT_FIELD.name());
                        removeItem(NewColumnTypes.ACTION_WORKITEM_INSERT_FACT_FIELD.name());
                        removeItem(NewColumnTypes.ACTION_BRL_FRAGMENT.name());
                    }//from ww w  . j a  va 2  s  . co m
                }

                private void addItem(int index, String item, String value) {
                    for (int itemIndex = 0; itemIndex < choice.getItemCount(); itemIndex++) {
                        if (choice.getValue(itemIndex).equals(value)) {
                            return;
                        }
                    }
                    choice.insertItem(item, value, index);
                }

                private void addItem(String item, String value) {
                    for (int itemIndex = 0; itemIndex < choice.getItemCount(); itemIndex++) {
                        if (choice.getValue(itemIndex).equals(value)) {
                            return;
                        }
                    }
                    choice.addItem(item, value);
                }

                private void removeItem(String value) {
                    for (int itemIndex = 0; itemIndex < choice.getItemCount(); itemIndex++) {
                        if (choice.getValue(itemIndex).equals(value)) {
                            choice.removeItem(itemIndex);
                            break;
                        }
                    }
                }

            });

            //OK button to create column
            final ModalFooterOKCancelButtons footer = new ModalFooterOKCancelButtons(new Command() {
                @Override
                public void execute() {
                    String s = choice.getValue(choice.getSelectedIndex());
                    if (s.equals(NewColumnTypes.METADATA_ATTRIBUTE.name())) {
                        showMetaDataAndAttribute();
                    } else if (s.equals(NewColumnTypes.CONDITION_SIMPLE.name())) {
                        showConditionSimple();
                    } else if (s.equals(NewColumnTypes.CONDITION_BRL_FRAGMENT.name())) {
                        showConditionBRLFragment();
                    } else if (s.equals(NewColumnTypes.ACTION_UPDATE_FACT_FIELD.name())) {
                        showActionSet();
                    } else if (s.equals(NewColumnTypes.ACTION_INSERT_FACT_FIELD.name())) {
                        showActionInsert();
                    } else if (s.equals(NewColumnTypes.ACTION_RETRACT_FACT.name())) {
                        showActionRetract();
                    } else if (s.equals(NewColumnTypes.ACTION_WORKITEM.name())) {
                        showActionWorkItemAction();
                    } else if (s.equals(NewColumnTypes.ACTION_WORKITEM_UPDATE_FACT_FIELD.name())) {
                        showActionWorkItemActionSet();
                    } else if (s.equals(NewColumnTypes.ACTION_WORKITEM_INSERT_FACT_FIELD.name())) {
                        showActionWorkItemActionInsert();
                    } else if (s.equals(NewColumnTypes.ACTION_BRL_FRAGMENT.name())) {
                        showActionBRLFragment();
                    }
                    pop.hide();
                }

                private void showMetaDataAndAttribute() {
                    // show choice of attributes
                    final Image image = GuidedDecisionTableImageResources508.INSTANCE.Config();
                    final FormStylePopup pop = new FormStylePopup(image,
                            GuidedDecisionTableConstants.INSTANCE.AddAnOptionToTheRule());
                    final ListBox list = RuleAttributeWidget.getAttributeList();

                    //This attribute is only used for Decision Tables
                    list.addItem(GuidedDecisionTable52.NEGATE_RULE_ATTR);

                    // Remove any attributes already added
                    for (AttributeCol52 col : model.getAttributeCols()) {
                        for (int iItem = 0; iItem < list.getItemCount(); iItem++) {
                            if (list.getItemText(iItem).equals(col.getAttribute())) {
                                list.removeItem(iItem);
                                break;
                            }
                        }
                    }

                    final Image addbutton = GuidedDecisionTableImageResources508.INSTANCE.NewItem();
                    final TextBox box = new TextBox();
                    box.setVisibleLength(15);

                    list.setSelectedIndex(0);

                    list.addChangeHandler(new ChangeHandler() {
                        public void onChange(ChangeEvent event) {
                            AttributeCol52 attr = new AttributeCol52();
                            attr.setAttribute(list.getItemText(list.getSelectedIndex()));
                            dtable.addColumn(attr);
                            refreshAttributeWidget();
                            pop.hide();
                        }
                    });

                    addbutton.setTitle(GuidedDecisionTableConstants.INSTANCE.AddMetadataToTheRule());

                    addbutton.addClickHandler(new ClickHandler() {
                        public void onClick(ClickEvent w) {

                            String metadata = box.getText();
                            if (!isUnique(metadata)) {
                                Window.alert(GuidedDecisionTableConstants.INSTANCE
                                        .ThatColumnNameIsAlreadyInUsePleasePickAnother());
                                return;
                            }
                            MetadataCol52 met = new MetadataCol52();
                            met.setHideColumn(true);
                            met.setMetadata(metadata);
                            dtable.addColumn(met);
                            refreshAttributeWidget();
                            pop.hide();
                        }

                        private boolean isUnique(String metadata) {
                            for (MetadataCol52 mc : model.getMetadataCols()) {
                                if (metadata.equals(mc.getMetadata())) {
                                    return false;
                                }
                            }
                            return true;
                        }

                    });
                    DirtyableHorizontalPane horiz = new DirtyableHorizontalPane();
                    horiz.add(box);
                    horiz.add(addbutton);

                    pop.addAttribute(new StringBuilder(GuidedDecisionTableConstants.INSTANCE.Metadata1())
                            .append(GuidedDecisionTableConstants.COLON).toString(), horiz);
                    pop.addAttribute(GuidedDecisionTableConstants.INSTANCE.Attribute(), list);
                    pop.show();
                }

                private void showConditionSimple() {
                    final ConditionCol52 column = makeNewConditionColumn();
                    ConditionPopup dialog = new ConditionPopup(model, oracle, new ConditionColumnCommand() {
                        public void execute(Pattern52 pattern, ConditionCol52 column) {

                            //Update UI
                            dtable.addColumn(pattern, column);
                            refreshConditionsWidget();
                        }
                    }, column, true, isReadOnly);
                    dialog.show();
                }

                private void showConditionBRLFragment() {
                    final BRLConditionColumn column = makeNewConditionBRLFragment();
                    switch (model.getTableFormat()) {
                    case EXTENDED_ENTRY:
                        BRLConditionColumnViewImpl popup = new BRLConditionColumnViewImpl(path, model, oracle,
                                ruleNameService, column, eventBus, true, isReadOnly);
                        popup.setPresenter(BRL_CONDITION_PRESENTER);
                        popup.show();
                        break;
                    case LIMITED_ENTRY:
                        LimitedEntryBRLConditionColumnViewImpl limtedEntryPopup = new LimitedEntryBRLConditionColumnViewImpl(
                                path, model, oracle, ruleNameService, (LimitedEntryBRLConditionColumn) column,
                                eventBus, true, isReadOnly);
                        limtedEntryPopup.setPresenter(LIMITED_ENTRY_BRL_CONDITION_PRESENTER);
                        limtedEntryPopup.show();
                        break;
                    }
                }

                private void showActionInsert() {
                    final ActionInsertFactCol52 afc = makeNewActionInsertColumn();
                    ActionInsertFactPopup ins = new ActionInsertFactPopup(model, oracle,
                            new GenericColumnCommand() {
                                public void execute(DTColumnConfig52 column) {
                                    newActionAdded((ActionCol52) column);
                                }
                            }, afc, true, isReadOnly);
                    ins.show();
                }

                private void showActionSet() {
                    final ActionSetFieldCol52 afc = makeNewActionSetColumn();
                    ActionSetFieldPopup set = new ActionSetFieldPopup(model, oracle,
                            new GenericColumnCommand() {
                                public void execute(DTColumnConfig52 column) {
                                    newActionAdded((ActionCol52) column);
                                }
                            }, afc, true, isReadOnly);
                    set.show();
                }

                private void showActionRetract() {
                    final ActionRetractFactCol52 arf = makeNewActionRetractFact();
                    ActionRetractFactPopup popup = new ActionRetractFactPopup(model,
                            new GenericColumnCommand() {
                                public void execute(DTColumnConfig52 column) {
                                    newActionAdded((ActionCol52) column);
                                }
                            }, arf, true, isReadOnly);
                    popup.show();
                }

                private void showActionWorkItemAction() {
                    final ActionWorkItemCol52 awi = makeNewActionWorkItem();
                    ActionWorkItemPopup popup = new ActionWorkItemPopup(path, model,
                            GuidedDecisionTableWidget.this, new GenericColumnCommand() {
                                public void execute(DTColumnConfig52 column) {
                                    newActionAdded((ActionCol52) column);
                                }
                            }, awi, workItemDefinitions, true, isReadOnly);
                    popup.show();
                }

                private void showActionWorkItemActionSet() {
                    final ActionWorkItemSetFieldCol52 awisf = makeNewActionWorkItemSetField();
                    ActionWorkItemSetFieldPopup popup = new ActionWorkItemSetFieldPopup(model, oracle,
                            new GenericColumnCommand() {
                                public void execute(DTColumnConfig52 column) {
                                    newActionAdded((ActionCol52) column);
                                }
                            }, awisf, true, isReadOnly);
                    popup.show();
                }

                private void showActionWorkItemActionInsert() {
                    final ActionWorkItemInsertFactCol52 awiif = makeNewActionWorkItemInsertFact();
                    ActionWorkItemInsertFactPopup popup = new ActionWorkItemInsertFactPopup(model, oracle,
                            new GenericColumnCommand() {
                                public void execute(DTColumnConfig52 column) {
                                    newActionAdded((ActionCol52) column);
                                }
                            }, awiif, true, isReadOnly);
                    popup.show();
                }

                private void showActionBRLFragment() {
                    final BRLActionColumn column = makeNewActionBRLFragment();
                    switch (model.getTableFormat()) {
                    case EXTENDED_ENTRY:
                        BRLActionColumnViewImpl popup = new BRLActionColumnViewImpl(path, model, oracle,
                                ruleNameService, column, eventBus, true, isReadOnly);
                        popup.setPresenter(BRL_ACTION_PRESENTER);
                        popup.show();
                        break;
                    case LIMITED_ENTRY:
                        LimitedEntryBRLActionColumnViewImpl limtedEntryPopup = new LimitedEntryBRLActionColumnViewImpl(
                                path, model, oracle, ruleNameService, (LimitedEntryBRLActionColumn) column,
                                eventBus, true, isReadOnly);
                        limtedEntryPopup.setPresenter(LIMITED_ENTRY_BRL_ACTION_PRESENTER);
                        limtedEntryPopup.show();
                        break;
                    }

                }

                private void newActionAdded(ActionCol52 column) {
                    dtable.addColumn(column);
                    refreshActionsWidget();
                }
            }, new Command() {
                @Override
                public void execute() {
                    pop.hide();
                }
            });

            //If a separator is clicked disable OK button
            choice.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    int itemIndex = choice.getSelectedIndex();
                    if (itemIndex < 0) {
                        return;
                    }
                    footer.enableOkButton(!choice.getValue(itemIndex).equals(SECTION_SEPARATOR));
                }

            });

            pop.setTitle(GuidedDecisionTableConstants.INSTANCE.AddNewColumn());
            pop.addAttribute(GuidedDecisionTableConstants.INSTANCE.TypeOfColumn(), choice);
            pop.addAttribute("", chkIncludeAdvancedOptions);
            pop.add(footer);
            pop.show();
        }

        private ConditionCol52 makeNewConditionColumn() {
            switch (model.getTableFormat()) {
            case LIMITED_ENTRY:
                return new LimitedEntryConditionCol52();
            default:
                return new ConditionCol52();
            }
        }

        private ActionInsertFactCol52 makeNewActionInsertColumn() {
            switch (model.getTableFormat()) {
            case LIMITED_ENTRY:
                return new LimitedEntryActionInsertFactCol52();
            default:
                return new ActionInsertFactCol52();
            }
        }

        private ActionSetFieldCol52 makeNewActionSetColumn() {
            switch (model.getTableFormat()) {
            case LIMITED_ENTRY:
                return new LimitedEntryActionSetFieldCol52();
            default:
                return new ActionSetFieldCol52();
            }
        }

        private ActionRetractFactCol52 makeNewActionRetractFact() {
            switch (model.getTableFormat()) {
            case LIMITED_ENTRY:
                LimitedEntryActionRetractFactCol52 ler = new LimitedEntryActionRetractFactCol52();
                ler.setValue(new DTCellValue52(""));
                return ler;
            default:
                return new ActionRetractFactCol52();
            }
        }

        private ActionWorkItemCol52 makeNewActionWorkItem() {
            //WorkItems are defined within the column and always boolean (i.e. Limited Entry) in the table
            return new ActionWorkItemCol52();
        }

        private ActionWorkItemSetFieldCol52 makeNewActionWorkItemSetField() {
            //Actions setting Field Values from Work Item Result Parameters are always boolean (i.e. Limited Entry) in the table
            return new ActionWorkItemSetFieldCol52();
        }

        private ActionWorkItemInsertFactCol52 makeNewActionWorkItemInsertFact() {
            //Actions setting Field Values from Work Item Result Parameters are always boolean (i.e. Limited Entry) in the table
            return new ActionWorkItemInsertFactCol52();
        }

        private BRLActionColumn makeNewActionBRLFragment() {
            switch (model.getTableFormat()) {
            case LIMITED_ENTRY:
                return new LimitedEntryBRLActionColumn();
            default:
                return new BRLActionColumn();
            }
        }

        private BRLConditionColumn makeNewConditionBRLFragment() {
            switch (model.getTableFormat()) {
            case LIMITED_ENTRY:
                return new LimitedEntryBRLConditionColumn();
            default:
                return new BRLConditionColumn();
            }
        }

    });

    return addButton;
}

From source file:org.eclipse.che.ide.notification.NotificationMessageStack.java

License:Open Source License

/** Show notification message. */
private void showMessage() {
    int left = Window.getClientWidth() - NotificationMessage.WIDTH - 30;
    for (int i = 0, top = 53; i < POPUP_COUNT
            && i < messages.size(); i++, top += NotificationMessage.HEIGHT + 20) {
        NotificationMessage popup = messages.get(i);
        if (popup.isShowing()) {
            popup.setPopupPosition(left, top);
        } else {//  w w w  .j av  a  2s.  c  o  m
            popup.show(left, top);
        }
    }
}

From source file:org.eclipse.che.ide.toolbar.MenuLockLayer.java

License:Open Source License

public MenuLockLayer(CloseMenuHandler closeMenuCallback, int topOffset) {
    this.closeMenuCallback = closeMenuCallback;
    this.topOffset = topOffset;

    RootPanel.get().add(this, 0, topOffset);
    int width = Window.getClientWidth();
    int height = Window.getClientHeight() - topOffset;
    setWidth("" + width + "px");
    setHeight("" + height + "px");
    DOM.setElementAttribute(getElement(), "id", "menu-lock-layer-id");
    DOM.setStyleAttribute(getElement(), "zIndex", "" + (Integer.MAX_VALUE - 5));

    AbsolutePanel blockMouseEventsPanel = new LockLayer();
    blockMouseEventsPanel.setStyleName("exo-lockLayer");
    int lockWidth = Window.getClientWidth();
    int lockHeight = Window.getClientHeight() - topOffset;
    blockMouseEventsPanel.setWidth("" + lockWidth + "px");
    blockMouseEventsPanel.setHeight("" + lockHeight + "px");
    add(blockMouseEventsPanel, 0, 0);/*from   ww w . j  a  v  a  2s. co m*/
}

From source file:org.eclipse.che.ide.toolbar.PopupMenu.java

License:Open Source License

private void openSubPopup(final Element tableRowElement) {
    if (tableRowElement == null) {
        return;//from   ww w.  j av  a  2s .c om
    }

    if (openedSubPopup != null) {
        if (tableRowElement == subPopupAnchor) {
            return;
        }

        openedSubPopup.closePopup();
    }

    if (subPopupAnchor != null) {
        Element e = subPopupAnchor;
        subPopupAnchor = null;
        setStyleNormal(e);
    }

    subPopupAnchor = tableRowElement;
    setStyleHovered(subPopupAnchor);

    int itemIndex = Integer.parseInt(tableRowElement.getAttribute("item-index"));
    Action menuItem = list.get(itemIndex);

    String idPrefix = itemIdPrefix;
    if (idPrefix != null) {
        idPrefix += "/" + presentationFactory.getPresentation(menuItem).getText();
    }

    openedSubPopup = new PopupMenu((ActionGroup) menuItem, actionManager, place, presentationFactory, lockLayer,
            actionSelectedHandler, keyBindingAgent, idPrefix);

    final int HORIZONTAL_OFFSET = 3;
    final int VERTICAL_OFFSET = 1;

    openedSubPopup.getElement().getStyle().setVisibility(Visibility.HIDDEN);
    lockLayer.add(openedSubPopup, 0, 0);

    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        @Override
        public void execute() {
            int left = getAbsoluteLeft() + getOffsetWidth() - HORIZONTAL_OFFSET;
            int top = tableRowElement.getAbsoluteTop() - lockLayer.getTopOffset() - VERTICAL_OFFSET;

            if (left + openedSubPopup.getOffsetWidth() > Window.getClientWidth()) {
                if (left > openedSubPopup.getOffsetWidth()) {
                    left = getAbsoluteLeft() - openedSubPopup.getOffsetWidth() + HORIZONTAL_OFFSET;
                } else {
                    int diff = left + openedSubPopup.getOffsetWidth() - Window.getClientWidth();
                    left -= diff;
                }
            }

            if (top + openedSubPopup.getOffsetHeight() > Window.getClientHeight()) {
                if (top > openedSubPopup.getOffsetHeight()) {
                    top = tableRowElement.getAbsoluteTop() - openedSubPopup.getOffsetHeight() + VERTICAL_OFFSET;
                } else {
                    int diff = top + openedSubPopup.getOffsetHeight() - Window.getClientHeight();
                    top -= diff;
                }
            }

            openedSubPopup.getElement().getStyle().setLeft(left, Unit.PX);
            openedSubPopup.getElement().getStyle().setTop(top, Unit.PX);
            openedSubPopup.getElement().getStyle().setVisibility(Visibility.VISIBLE);
        }
    });
}

From source file:org.eclipse.che.ide.ui.toolbar.PopupMenu.java

License:Open Source License

private void openSubPopup(final Element tableRowElement) {
    if (tableRowElement == null) {
        return;/*from   w w  w.j  a  v a 2s  .  c  o  m*/
    }

    if (openedSubPopup != null) {
        if (tableRowElement == subPopupAnchor) {
            return;
        }

        openedSubPopup.closePopup();
    }

    if (subPopupAnchor != null) {
        Element e = subPopupAnchor;
        subPopupAnchor = null;
        setStyleNormal(e);
    }

    subPopupAnchor = tableRowElement;
    setStyleHovered(subPopupAnchor);

    int itemIndex = Integer.parseInt(tableRowElement.getAttribute("item-index"));
    Action menuItem = list.get(itemIndex);

    String idPrefix = itemIdPrefix;
    if (idPrefix != null) {
        idPrefix += "/" + presentationFactory.getPresentation(menuItem).getText();
    }

    openedSubPopup = new PopupMenu((ActionGroup) menuItem, actionManager, managerProvider, presentationFactory,
            lockLayer, actionSelectedHandler, keyBindingAgent, idPrefix);

    final int HORIZONTAL_OFFSET = 3;
    final int VERTICAL_OFFSET = 1;

    openedSubPopup.getElement().getStyle().setVisibility(Visibility.HIDDEN);
    lockLayer.add(openedSubPopup, 0, 0);

    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        @Override
        public void execute() {
            int left = getAbsoluteLeft() + getOffsetWidth() - HORIZONTAL_OFFSET;
            int top = tableRowElement.getAbsoluteTop() - lockLayer.getTopOffset() - VERTICAL_OFFSET;

            if (left + openedSubPopup.getOffsetWidth() > Window.getClientWidth()) {
                if (left > openedSubPopup.getOffsetWidth()) {
                    left = getAbsoluteLeft() - openedSubPopup.getOffsetWidth() + HORIZONTAL_OFFSET;
                } else {
                    int diff = left + openedSubPopup.getOffsetWidth() - Window.getClientWidth();
                    left -= diff;
                }
            }

            if (top + openedSubPopup.getOffsetHeight() > Window.getClientHeight()) {
                if (top > openedSubPopup.getOffsetHeight()) {
                    top = tableRowElement.getAbsoluteTop() - openedSubPopup.getOffsetHeight() + VERTICAL_OFFSET;
                } else {
                    int diff = top + openedSubPopup.getOffsetHeight() - Window.getClientHeight();
                    top -= diff;
                }
            }

            openedSubPopup.getElement().getStyle().setLeft(left, Unit.PX);
            openedSubPopup.getElement().getStyle().setTop(top, Unit.PX);
            openedSubPopup.getElement().getStyle().setVisibility(Visibility.VISIBLE);
        }
    });
}