Example usage for com.google.gwt.user.client.ui TextBox setVisibleLength

List of usage examples for com.google.gwt.user.client.ui TextBox setVisibleLength

Introduction

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

Prototype

public void setVisibleLength(int length) 

Source Link

Document

Sets the number of visible characters in the text box.

Usage

From source file:org.gwtportlets.portlet.client.ui.PagePortlet.java

License:Open Source License

public void configure() {
    final TextBox appTitle = new TextBox();
    appTitle.setVisibleLength(30);
    appTitle.setTitle("Title used when no other title is available");
    appTitle.setText(this.appTitle);

    final TextBox prefix = new TextBox();
    prefix.setVisibleLength(30);/*from   w w w .ja v a 2 s  .c o  m*/
    prefix.setTitle("Prefix for title from first portlet on page for " + "browser window");
    prefix.setText(this.prefix);

    FormBuilder b = new FormBuilder();
    b.label("Application title").field(appTitle).endRow();
    b.label("Browser window title prefix").field(prefix).endRow();

    final Dialog dlg = new Dialog();
    dlg.setText("Configure " + getWidgetName());
    dlg.setWidget(b.getForm());

    dlg.addButton(new CssButton("OK", new ClickHandler() {
        public void onClick(ClickEvent event) {
            dlg.hide();
            PagePortlet.this.appTitle = appTitle.getText();
            PagePortlet.this.prefix = prefix.getText();
            updateTitle();
        }
    }));
    dlg.addCloseButton("Cancel");
    dlg.showNextTo(this);
}

From source file:org.jboss.as.console.client.shared.hosts.ConfigurationChangesEditor.java

License:Open Source License

private ToolStrip toolstripButtons() {

    final TextBox filter = new TextBox();
    filter.setMaxLength(30);/*ww  w . j  a  va 2s  .c o  m*/
    filter.setVisibleLength(20);
    filter.getElement().setAttribute("style", "float:right; width:120px;");
    filter.addKeyUpHandler(keyUpEvent -> {
        String word = filter.getText();
        if (word != null && word.trim().length() > 0) {
            filter(word);
        } else {
            clearFilter();
        }
    });

    ToolStrip topLevelTools = new ToolStrip();

    final HTML label = new HTML(Console.CONSTANTS.commom_label_filter() + ": ");
    label.getElement().setAttribute("style", "padding-top:8px;");
    topLevelTools.addToolWidget(label);
    topLevelTools.addToolWidget(filter);

    enableBtn = new ToolButton(Console.CONSTANTS.common_label_enable(), event -> presenter.enable());
    disableBtn = new ToolButton(Console.CONSTANTS.common_label_disable(), event -> presenter.disable());
    refreshBtn = new ToolButton(Console.CONSTANTS.common_label_refresh(), event -> presenter.loadChanges());

    topLevelTools.addToolButtonRight(enableBtn);
    topLevelTools.addToolButtonRight(disableBtn);
    topLevelTools.addToolButtonRight(refreshBtn);

    return topLevelTools;
}

From source file:org.jboss.as.console.client.shared.runtime.logging.files.LogFilesTable.java

License:Open Source License

@SuppressWarnings("unchecked")
public LogFilesTable(final Dispatcher circuit, final LogFilesPresenter presenter) {

    VerticalPanel panel = new VerticalPanel();
    panel.addStyleName("rhs-content-panel");
    panel.getElement().getStyle().setMarginBottom(0, PX);

    // header//from   w  ww  .  j a  v a 2  s .  com
    panel.add(new ContentHeaderLabel("Log Viewer"));
    panel.add(new ContentDescription(Console.CONSTANTS.logFilesOfSelectedServer()));

    // toolbar
    ToolStrip tools = new ToolStrip();
    HTML label = new HTML(Console.CONSTANTS.commom_label_filter() + ": ");
    label.getElement().setAttribute("style", "padding-top:8px;");
    final TextBox filter = new TextBox();
    filter.setMaxLength(30);
    filter.setVisibleLength(20);
    filter.getElement().setAttribute("style", "float:right; width:120px;");
    filter.addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent keyUpEvent) {
            String prefix = filter.getText();
            if (prefix != null && !prefix.equals("")) {
                // filter by prefix
                filterByPrefix(prefix);
            } else {
                clearFilter();
            }
        }
    });
    setId(filter, BASE_ID, "filter");
    tools.addToolWidget(label);
    tools.addToolWidget(filter);

    final ToolButton download = new ToolButton("Download", new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            ModelNode logFile = selectionModel.getSelectedObject();
            if (logFile != null) {
                circuit.dispatch(new DownloadLogFile(logFile.get(FILE_NAME).asString()));
            }
        }
    });
    download.setEnabled(false);
    // actually the attribute 'stream' is relevant for download, however we need to pass an operation here
    download.setOperationAddress("/{implicit.host}/{selected.server}/subsystem=logging/log-file=*",
            "read-log-file");
    setId(download, BASE_ID, "download");
    tools.addToolButtonRight(download);

    final ToolButton view = new ToolButton(Console.CONSTANTS.common_label_view(), new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            ModelNode logFile = selectionModel.getSelectedObject();
            if (logFile != null) {
                String name = logFile.get(FILE_NAME).asString();
                int fileSize = logFile.get(FILE_SIZE).asInt();
                presenter.onStreamLogFile(name, fileSize);
            }
        }
    });
    view.setEnabled(false);
    view.setOperationAddress("/{implicit.host}/{selected.server}/subsystem=logging/log-file=*",
            "read-log-file");
    setId(view, BASE_ID, "view");
    tools.addToolButtonRight(view);

    final ToolButton refresh = new ToolButton(Console.CONSTANTS.common_label_refresh(),
            event -> circuit.dispatch(new ReadLogFiles()));
    refresh.setOperationAddress("/{implicit.host}/{selected.server}/subsystem=logging", "read-resource");
    setId(refresh, BASE_ID, "refresh");
    tools.addToolButtonRight(refresh);

    panel.add(tools);

    // table
    backup = new ArrayList<>();
    ProvidesKey<ModelNode> providesKey = new ProvidesKey<ModelNode>() {
        @Override
        public Object getKey(ModelNode item) {
            return item.get(FILE_NAME);
        }
    };
    selectionModel = new SingleSelectionModel<>(providesKey);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            download.setEnabled(selectionModel.getSelectedObject() != null);
            view.setEnabled(selectionModel.getSelectedObject() != null);
        }
    });
    table = new ModelNodeCellTable(10, providesKey);
    table.setSelectionModel(selectionModel);
    dataProvider = new ListDataProvider<>(providesKey);
    dataProvider.addDataDisplay(table);
    ColumnSortEvent.ListHandler<ModelNode> sortHandler = new ColumnSortEvent.ListHandler<ModelNode>(
            dataProvider.getList());
    table.addColumnSortHandler(sortHandler);
    // TODO Find a way to combine the double click handler with RBAC like
    // foo.setOperationAddress("/{implicit.host}/{selected.server}/subsystem=logging/log-file=*", "read-log-file");
    //        table.addCellPreviewHandler(new CellPreviewEvent.Handler<ModelNode>() {
    //            @Override
    //            public void onCellPreview(CellPreviewEvent<ModelNode> event) {
    //                NativeEvent nativeEvent = event.getNativeEvent();
    //                if (BrowserEvents.DBLCLICK.equals(nativeEvent.getType())) {
    //                    ModelNode selectedValue = event.getValue();
    //
    //                }
    //            }
    //        });
    panel.add(table);

    DefaultPager pager = new DefaultPager();
    pager.setDisplay(table);
    panel.add(pager);

    // column: name
    nameColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode node) {
            return node.get(FILE_NAME).asString();
        }
    };
    nameColumn.setSortable(true);
    sortHandler.setComparator(nameColumn, new NameComparator());
    table.addColumn(nameColumn, "Log File Name");
    table.getColumnSortList().push(nameColumn);

    // column: last modified
    TextColumn<ModelNode> lastModifiedColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode node) {
            return node.get(LAST_MODIFIED_TIMESTAMP).asString();
        }
    };
    lastModifiedColumn.setSortable(true);
    sortHandler.setComparator(lastModifiedColumn, new Comparator<ModelNode>() {
        @Override
        public int compare(ModelNode node1, ModelNode node2) {
            return node1.get(LAST_MODIFIED_TIMESTAMP).asString()
                    .compareTo(node2.get(LAST_MODIFIED_TIMESTAMP).asString());
        }
    });
    table.addColumn(lastModifiedColumn, "Date - Time (UTC)");

    // column: size
    TextColumn<ModelNode> sizeColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode node) {
            double size = node.get(LogStore.FILE_SIZE).asLong() / 1048576.0;
            return SIZE_FORMAT.format(size);
        }
    };
    sizeColumn.setSortable(true);
    sizeColumn.setHorizontalAlignment(ALIGN_RIGHT);
    sortHandler.setComparator(sizeColumn, new Comparator<ModelNode>() {
        @Override
        public int compare(ModelNode node1, ModelNode node2) {
            return node1.get(FILE_SIZE).asInt() - node2.get(FILE_SIZE).asInt();
        }
    });
    table.addColumn(sizeColumn, "Size (MB)");

    ScrollPanel scroll = new ScrollPanel(panel);
    LayoutPanel layout = new LayoutPanel();
    layout.add(scroll);
    layout.setWidgetTopHeight(scroll, 0, PX, 100, Style.Unit.PCT);

    initWidget(layout);
}

From source file:org.jboss.as.console.client.shared.runtime.logging.viewer.LogFileTable.java

License:Open Source License

@SuppressWarnings("unchecked")
public LogFileTable(final Dispatcher circuit) {

    VerticalPanel panel = new VerticalPanel();
    panel.addStyleName("fill-layout-width");
    panel.getElement().getStyle().setPadding(30, Style.Unit.PX);

    panel.getElement().getStyle().setMarginBottom(0, PX);

    // header/* ww  w  .  j a  v a  2 s  .  co  m*/
    panel.add(new ContentHeaderLabel("Log Viewer"));
    panel.add(new ContentDescription("Log files of selected server"));

    // toolbar
    ToolStrip tools = new ToolStrip();
    HTML label = new HTML(Console.CONSTANTS.commom_label_filter() + ":&nbsp;");
    label.getElement().setAttribute("style", "padding-top:8px;");
    final TextBox filter = new TextBox();
    filter.setMaxLength(30);
    filter.setVisibleLength(20);
    filter.getElement().setAttribute("style", "float:right; width:120px;");
    filter.addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent keyUpEvent) {
            String prefix = filter.getText();
            if (prefix != null && !prefix.equals("")) {
                // filter by prefix
                filterByPrefix(prefix);
            } else {
                clearFilter();
            }
        }
    });
    setId(filter, BASE_ID, "filter");
    tools.addToolWidget(label);
    tools.addToolWidget(filter);

    final ToolButton view = new ToolButton(Console.CONSTANTS.common_label_view(), new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            ModelNode logFile = selectionModel.getSelectedObject();
            if (logFile != null) {
                circuit.dispatch(new OpenLogFile(logFile.get(FILE_NAME).asString()));
            }
        }
    });
    view.setEnabled(false);
    view.setOperationAddress("/{implicit.host}/{selected.server}/subsystem=logging", "read-log-file");
    setId(view, BASE_ID, "view");
    tools.addToolButtonRight(view);
    panel.add(tools);

    // table
    backup = new ArrayList<>();
    ProvidesKey<ModelNode> providesKey = new ProvidesKey<ModelNode>() {
        @Override
        public Object getKey(ModelNode item) {
            return item.get(FILE_NAME);
        }
    };
    selectionModel = new SingleSelectionModel<>(providesKey);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            view.setEnabled(selectionModel.getSelectedObject() != null);
        }
    });
    table = new ModelNodeCellTable(10, providesKey);
    table.setSelectionModel(selectionModel);
    dataProvider = new ListDataProvider<>(providesKey);
    dataProvider.addDataDisplay(table);
    ColumnSortEvent.ListHandler<ModelNode> sortHandler = new ColumnSortEvent.ListHandler<ModelNode>(
            dataProvider.getList());
    table.addColumnSortHandler(sortHandler);
    panel.add(table);

    DefaultPager pager = new DefaultPager();
    pager.setDisplay(table);
    panel.add(pager);

    // column: name
    nameColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode node) {
            return node.get(FILE_NAME).asString();
        }
    };
    nameColumn.setSortable(true);
    sortHandler.setComparator(nameColumn, new NameComparator());
    table.addColumn(nameColumn, "Log File Name");

    // column: last modified
    TextColumn<ModelNode> lastModifiedColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode node) {
            return node.get(LAST_MODIFIED_TIMESTAMP).asString();
        }
    };
    lastModifiedColumn.setSortable(true);
    sortHandler.setComparator(lastModifiedColumn, new Comparator<ModelNode>() {
        @Override
        public int compare(ModelNode node1, ModelNode node2) {
            return node1.get(LAST_MODIFIED_TIMESTAMP).asString()
                    .compareTo(node2.get(LAST_MODIFIED_TIMESTAMP).asString());
        }
    });
    table.addColumn(lastModifiedColumn, "Date - Time (UTC)");

    // column: size
    TextColumn<ModelNode> sizeColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode node) {
            double size = node.get(LogStore.FILE_SIZE).asLong() / 1024.0;
            return SIZE_FORMAT.format(size);
        }
    };
    sizeColumn.setSortable(true);
    sizeColumn.setHorizontalAlignment(ALIGN_RIGHT);
    sortHandler.setComparator(sizeColumn, new Comparator<ModelNode>() {
        @Override
        public int compare(ModelNode node1, ModelNode node2) {
            return node1.get(FILE_SIZE).asInt() - node2.get(FILE_SIZE).asInt();
        }
    });
    table.addColumn(sizeColumn, "Size (kb)");

    ScrollPanel scroll = new ScrollPanel(panel);
    LayoutPanel layout = new LayoutPanel();
    layout.add(scroll);
    layout.setWidgetTopHeight(scroll, 0, PX, 100, Style.Unit.PCT);

    initWidget(layout);
}

From source file:org.jboss.as.console.client.shared.runtime.logviewer.LogFileTable.java

License:Open Source License

@SuppressWarnings("unchecked")
public LogFileTable(final Dispatcher circuit) {

    VerticalPanel panel = new VerticalPanel();
    panel.addStyleName("rhs-content-panel");
    panel.getElement().getStyle().setMarginBottom(0, PX);

    // header/*from   w w  w  .  j a v a2s .c  o m*/
    panel.add(new ContentHeaderLabel("Log Viewer"));
    panel.add(new ContentDescription("Log files of selected server"));

    // toolbar
    ToolStrip tools = new ToolStrip();
    HTML label = new HTML(Console.CONSTANTS.commom_label_filter() + ":&nbsp;");
    label.getElement().setAttribute("style", "padding-top:8px;");
    final TextBox filter = new TextBox();
    filter.getElement().setId("TX_" + BASE_ID + "_filter");
    filter.setMaxLength(30);
    filter.setVisibleLength(20);
    filter.getElement().setAttribute("style", "float:right; width:120px;");
    filter.addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent keyUpEvent) {
            String prefix = filter.getText();
            if (prefix != null && !prefix.equals("")) {
                // filter by prefix
                filterByPrefix(prefix);
            } else {
                clearFilter();
            }
        }
    });
    tools.addToolWidget(label);
    tools.addToolWidget(filter);

    final ToolButton download = new ToolButton("Download", new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            ModelNode logFile = selectionModel.getSelectedObject();
            if (logFile != null) {
                // TODO Implement download
            }
        }
    });
    download.setEnabled(false);
    download.getElement().setId("BT_" + BASE_ID + "_download");
    // TODO Enable when the server side download is in place
    // tools.addToolButtonRight(download);

    final ToolButton view = new ToolButton(Console.CONSTANTS.common_label_view(), new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            ModelNode logFile = selectionModel.getSelectedObject();
            if (logFile != null) {
                circuit.dispatch(new OpenLogFile(logFile.get(FILE_NAME).asString()));
            }
        }
    });
    view.setEnabled(false);
    view.getElement().setId("BT_" + BASE_ID + "_view");
    tools.addToolButtonRight(view);
    panel.add(tools);

    // table
    backup = new ArrayList<>();
    ProvidesKey<ModelNode> providesKey = new ProvidesKey<ModelNode>() {
        @Override
        public Object getKey(ModelNode item) {
            return item.get(FILE_NAME);
        }
    };
    selectionModel = new SingleSelectionModel<>(providesKey);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            download.setEnabled(selectionModel.getSelectedObject() != null);
            view.setEnabled(selectionModel.getSelectedObject() != null);
        }
    });
    table = new ModelNodeCellTable(10, providesKey);
    table.setSelectionModel(selectionModel);
    dataProvider = new ListDataProvider<>(providesKey);
    dataProvider.addDataDisplay(table);
    ColumnSortEvent.ListHandler<ModelNode> sortHandler = new ColumnSortEvent.ListHandler<ModelNode>(
            dataProvider.getList());
    table.addColumnSortHandler(sortHandler);
    panel.add(table);

    DefaultPager pager = new DefaultPager();
    pager.setDisplay(table);
    panel.add(pager);

    // column: name
    TextColumn<ModelNode> nameColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode node) {
            return node.get(FILE_NAME).asString();
        }
    };
    nameColumn.setSortable(true);
    sortHandler.setComparator(nameColumn, new NameComparator());
    table.addColumn(nameColumn, "Log File Name");

    // column: last modified
    TextColumn<ModelNode> lastModifiedColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode node) {
            return node.get(LAST_MODIFIED_DATE).asString();
        }
    };
    lastModifiedColumn.setSortable(true);
    sortHandler.setComparator(lastModifiedColumn, new Comparator<ModelNode>() {
        @Override
        public int compare(ModelNode node1, ModelNode node2) {
            return node1.get(LAST_MODIFIED_DATE).asString().compareTo(node2.get(LAST_MODIFIED_DATE).asString());
        }
    });
    table.addColumn(lastModifiedColumn, "Date - Time (UTC)");

    // column: size
    TextColumn<ModelNode> sizeColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode node) {
            double size = node.get(LogStore.FILE_SIZE).asLong() / 1024.0;
            return SIZE_FORMAT.format(size);
        }
    };
    sizeColumn.setSortable(true);
    sortHandler.setComparator(sizeColumn, new Comparator<ModelNode>() {
        @Override
        public int compare(ModelNode node1, ModelNode node2) {
            return node1.get(FILE_SIZE).asInt() - node2.get(FILE_SIZE).asInt();
        }
    });
    table.addColumn(sizeColumn, "Size (kb)");

    ScrollPanel scroll = new ScrollPanel(panel);
    LayoutPanel layout = new LayoutPanel();
    layout.add(scroll);
    layout.setWidgetTopHeight(scroll, 0, PX, 100, Style.Unit.PCT);

    initWidget(layout);
}

From source file:org.jboss.as.console.client.shared.subsys.jberet.ui.JobsRuntimePanel.java

License:Open Source License

private ToolStrip buttonsTool() {
    ToolStrip tools = new ToolStrip();

    final TextBox filter = new TextBox();
    filter.setMaxLength(30);/*  ww  w  .j  a v a2  s.c om*/
    filter.setVisibleLength(20);
    filter.getElement().setAttribute("style", "float:right; width:120px;");
    filter.addKeyUpHandler(keyUpEvent -> {
        String word = filter.getText();
        if (word != null && word.trim().length() > 0) {
            filter(word);
        } else {
            clearFilter();
        }
    });

    this.btnStart = new ToolButton(Console.CONSTANTS.common_label_start(), event -> {
        Job job = selectionModel.getSelectedObject();
        circuit.dispatch(
                new StartJob(job.getDeploymentName(), job.getSubdeploymentName(), job.getJobXmlName()));
    });

    this.btnStop = new ToolButton(Console.CONSTANTS.common_label_stop(), event -> {
        Job job = selectionModel.getSelectedObject();
        circuit.dispatch(new StopJob(job.getDeploymentName(), job.getSubdeploymentName(), job.getName(),
                job.getExecutionId()));
    });

    this.btnRestart = new ToolButton(Console.CONSTANTS.common_label_restart(), event -> {
        Job job = selectionModel.getSelectedObject();
        if ("COMPLETED".equals(job.getCurrentStatus())) {
            Console.warning(Console.MESSAGES.batch_cannot_restart(job.getExecutionId()));
        } else {
            circuit.dispatch(new RestartJob(job.getDeploymentName(), job.getSubdeploymentName(), job.getName(),
                    job.getExecutionId()));
        }
    });

    final HTML label = new HTML(Console.CONSTANTS.commom_label_filter() + ":&nbsp;");
    label.getElement().setAttribute("style", "padding-top:8px;");
    tools.addToolWidget(label);
    tools.addToolWidget(filter);

    tools.addToolButtonRight(new ToolButton(Console.CONSTANTS.common_label_refresh(),
            event -> circuit.dispatch(new LoadJobsMetrics())));

    tools.addToolButtonRight(btnStart);
    tools.addToolButtonRight(btnStop);
    tools.addToolButtonRight(btnRestart);
    return tools;
}

From source file:org.kie.guvnor.guided.dtable.client.widget.GuidedDecisionTableWidget.java

License:Apache License

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

    addButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent w) {
            final FormStylePopup pop = new FormStylePopup();
            pop.setModal(false);// w ww .  ja v a2  s  .com

            //List of basic column types
            final ListBox choice = new ListBox();
            choice.setVisibleItemCount(NewColumnTypes.values().length);

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

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

                public void onClick(ClickEvent event) {
                    if (chkIncludeAdvancedOptions.getValue()) {
                        addItem(3, Constants.INSTANCE.AddNewConditionBRLFragment(),
                                NewColumnTypes.CONDITION_BRL_FRAGMENT.name());
                        addItem(Constants.INSTANCE.WorkItemAction(), NewColumnTypes.ACTION_WORKITEM.name());
                        addItem(Constants.INSTANCE.WorkItemActionSetField(),
                                NewColumnTypes.ACTION_WORKITEM_UPDATE_FACT_FIELD.name());
                        addItem(Constants.INSTANCE.WorkItemActionInsertFact(),
                                NewColumnTypes.ACTION_WORKITEM_INSERT_FACT_FIELD.name());
                        addItem(Constants.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());
                    }
                    pop.center();
                }

                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 Button ok = new Button(Constants.INSTANCE.OK());
            ok.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent w) {
                    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 = ImageResources508.INSTANCE.Config();
                    final FormStylePopup pop = new FormStylePopup(image,
                            Constants.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 = ImageResources508.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(Constants.INSTANCE.AddMetadataToTheRule());

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

                            String metadata = box.getText();
                            if (!isUnique(metadata)) {
                                Window.alert(
                                        Constants.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(Constants.INSTANCE.Metadata1(), horiz);
                    pop.addAttribute(Constants.INSTANCE.Attribute(), list);
                    pop.show();
                }

                private void showConditionSimple() {
                    final ConditionCol52 column = makeNewConditionColumn();
                    ConditionPopup dialog = new ConditionPopup(oracle, model, 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, oracle, model,
                                column, eventBus, true, isReadOnly);
                        popup.setPresenter(BRL_CONDITION_PRESENTER);
                        popup.show();
                        break;
                    case LIMITED_ENTRY:
                        LimitedEntryBRLConditionColumnViewImpl limtedEntryPopup = new LimitedEntryBRLConditionColumnViewImpl(
                                path, oracle, model, (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(oracle, model,
                            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(oracle, model,
                            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, true, isReadOnly);
                    popup.show();
                }

                private void showActionWorkItemActionSet() {
                    final ActionWorkItemSetFieldCol52 awisf = makeNewActionWorkItemSetField();
                    ActionWorkItemSetFieldPopup popup = new ActionWorkItemSetFieldPopup(oracle, model,
                            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(oracle, model,
                            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, oracle, model, column,
                                eventBus, true, isReadOnly);
                        popup.setPresenter(BRL_ACTION_PRESENTER);
                        popup.show();
                        break;
                    case LIMITED_ENTRY:
                        LimitedEntryBRLActionColumnViewImpl limtedEntryPopup = new LimitedEntryBRLActionColumnViewImpl(
                                path, oracle, model, (LimitedEntryBRLActionColumn) column, eventBus, true,
                                isReadOnly);
                        limtedEntryPopup.setPresenter(LIMITED_ENTRY_BRL_ACTION_PRESENTER);
                        limtedEntryPopup.show();
                        break;
                    }

                }

                private void newActionAdded(ActionCol52 column) {
                    dtable.addColumn(column);
                    refreshActionsWidget();
                }
            });

            //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;
                    }
                    ok.setEnabled(!choice.getValue(itemIndex).equals(SECTION_SEPARATOR));
                }

            });

            pop.setTitle(Constants.INSTANCE.AddNewColumn());
            pop.addAttribute(Constants.INSTANCE.TypeOfColumn(), choice);
            pop.addAttribute("", chkIncludeAdvancedOptions);
            pop.addAttribute("", ok);
            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.kie.guvnor.guided.rule.client.editor.factPattern.PopupCreator.java

License:Apache License

/**
 * This adds in (optionally) the editor for changing the bound variable
 * name. If its a bindable pattern, it will show the editor, if it is
 * already bound, and the name is used, it should not be editable.
 *//*from  w  w  w .  ja  va2 s. co  m*/
private void doBindingEditor(final FormStylePopup popup) {
    if (bindable || !(modeller.getModel().isBoundFactUsed(pattern.getBoundName()))) {
        HorizontalPanel varName = new HorizontalPanel();
        final TextBox varTxt = new BindingTextBox();
        if (pattern.getBoundName() == null) {
            varTxt.setText("");
        } else {
            varTxt.setText(pattern.getBoundName());
        }

        varTxt.setVisibleLength(6);
        varName.add(varTxt);

        Button bindVar = new Button(HumanReadableConstants.INSTANCE.Set());
        bindVar.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                String var = varTxt.getText();
                if (modeller.isVariableNameUsed(var)) {
                    Window.alert(Constants.INSTANCE.TheVariableName0IsAlreadyTaken(var));
                    return;
                }
                pattern.setBoundName(varTxt.getText());
                modeller.refreshWidget();
                popup.hide();
            }
        });

        varName.add(bindVar);
        popup.addAttribute(Constants.INSTANCE.VariableName(), varName);

    }
}

From source file:org.kie.guvnor.guided.rule.client.editor.MethodParameterValueEditor.java

License:Apache License

private TextBox boundTextBox(final ActionFieldValue c) {
    final TextBox box = TextBoxFactory.getTextBox(methodParameter.getType());
    box.setStyleName("constraint-value-Editor");
    if (c.getValue() == null) {
        box.setText("");
    } else {//from  w  ww.j  a va2  s .c  om
        if (c.getValue().trim().equals("")) {
            c.setType("");
        }
        box.setText(c.getValue());
    }

    if (c.getValue() == null || c.getValue().length() < 5) {
        box.setVisibleLength(6);
    } else {
        box.setVisibleLength(c.getValue().length() - 1);
    }

    box.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            c.setValue(box.getText());
            if (onValueChangeCommand != null) {
                onValueChangeCommand.execute();
            }
            makeDirty();
        }

    });

    box.addKeyUpHandler(new KeyUpHandler() {

        public void onKeyUp(KeyUpEvent event) {
            box.setVisibleLength(box.getText().length());
        }
    });

    return box;
}

From source file:org.kie.guvnor.guided.rule.client.editor.RuleAttributeWidget.java

License:Apache License

private TextBox textBoxEditor(final RuleAttribute at, final boolean isReadOnly) {
    final TextBox box = new TextBox();
    box.setEnabled(!isReadOnly);// ww w  . j  ava 2s  . c  o m
    box.setVisibleLength((at.getValue().length() < 3) ? 3 : at.getValue().length());
    box.setText(at.getValue());
    box.addChangeHandler(new ChangeHandler() {
        public void onChange(ChangeEvent event) {
            at.setValue(box.getText());
        }
    });

    if (at.getAttributeName().equals(DATE_EFFECTIVE_ATTR) || at.getAttributeName().equals(DATE_EXPIRES_ATTR)) {
        if (at.getValue() == null || "".equals(at.getValue())) {
            box.setText("");
        }

        box.setVisibleLength(10);
    }

    box.addKeyUpHandler(new KeyUpHandler() {
        public void onKeyUp(KeyUpEvent event) {
            int length = box.getText().length();
            box.setVisibleLength(length > 0 ? length : 1);
        }
    });
    return box;
}