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

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

Introduction

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

Prototype

public void setMaxLength(int length) 

Source Link

Document

Sets the maximum allowable length of the text box.

Usage

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//w  w  w.  j  a v a  2s.  c o  m
    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/*from ww  w  . j av  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/*  ww  w.  ja va  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.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);
    filter.setVisibleLength(20);//from   w  w w  . ja  va 2  s. com
    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.jbpm.form.builder.ng.model.client.form.items.TextFieldFormItem.java

License:Apache License

private void populate(TextBox textBox) {
    if (this.defaultContent != null) {
        textBox.setValue(this.defaultContent);
    }// w w w.j a  v a2  s . co m
    if (this.name != null) {
        textBox.setName(this.name);
    }
    if (getHeight() != null) {
        textBox.setHeight(getHeight());
    }
    if (getWidth() != null) {
        textBox.setWidth(getWidth());
    }
    if (this.title != null) {
        textBox.setTitle(this.title);
    }
    if (this.maxlength != null) {
        textBox.setMaxLength(this.maxlength);
    }
}

From source file:org.metawidget.gwt.client.widgetbuilder.GwtWidgetBuilder.java

License:LGPL

public Widget buildWidget(String elementName, Map<String, String> attributes, GwtMetawidget metawidget) {

    // Hidden/*w  ww. ja va2 s  .c  o  m*/

    if (TRUE.equals(attributes.get(HIDDEN))) {
        return new Stub();
    }

    // Action

    if (ACTION.equals(elementName)) {
        return new Button(metawidget.getLabelString(attributes));
    }

    String type = GwtUtils.getActualClassOrType(attributes);

    // If no type, assume a String

    if (type == null) {
        type = String.class.getName();
    }

    // Support mandatory Booleans (can be rendered as a checkbox, even though they have a
    // Lookup)

    if ("Boolean".equals(type) && TRUE.equals(attributes.get(REQUIRED))) {
        return new CheckBox();
    }

    // Lookups

    String lookup = attributes.get(LOOKUP);

    if (lookup != null && !"".equals(lookup)) {
        ListBox listBox = new ListBox();
        listBox.setVisibleItemCount(1);

        addListBoxItems(listBox, GwtUtils.fromString(lookup, StringUtils.SEPARATOR_COMMA_CHAR),
                GwtUtils.fromString(attributes.get(LOOKUP_LABELS), StringUtils.SEPARATOR_COMMA_CHAR),
                attributes);
        return listBox;
    }

    if (GwtUtils.isPrimitive(type)) {
        // booleans

        if ("boolean".equals(type)) {
            return new CheckBox();
        }

        // chars

        if ("char".equals(type)) {
            TextBox textbox = new TextBox();
            textbox.setMaxLength(1);

            return textbox;
        }

        // Everything else

        return new TextBox();
    }

    // Strings

    if (String.class.getName().equals(type)) {
        if (TRUE.equals(attributes.get(MASKED))) {
            return new PasswordTextBox();
        }

        if (TRUE.equals(attributes.get(LARGE))) {
            return new TextArea();
        }

        TextBox textBox = new TextBox();

        String maximumLength = attributes.get(MAXIMUM_LENGTH);

        if (maximumLength != null && !"".equals(maximumLength)) {
            textBox.setMaxLength(Integer.parseInt(maximumLength));
        }

        return textBox;
    }

    // Dates

    if (Date.class.getName().equals(type)) {
        return new TextBox();
    }

    if (GwtUtils.isPrimitiveWrapper(type)) {
        // Characters

        if (Character.class.getName().equals(type)) {
            TextBox textbox = new TextBox();
            textbox.setMaxLength(1);

            return textbox;
        }

        // Numbers

        return new TextBox();
    }

    // Collections

    if (GwtUtils.isCollection(type)) {
        return new Stub();
    }

    // Not simple, but don't expand

    if (TRUE.equals(attributes.get(DONT_EXPAND))) {
        return new TextBox();
    }

    // Nested Metawidget

    return null;
}

From source file:org.sakaiproject.sgs2.client.Sgs2.java

License:Educational Community License

private Command getMenuFileSaveAsCommand() {
    return new Command() {
        public void execute() {
            final Sgs2DialogBox dialogBox = new Sgs2DialogBox();
            dialogBox.setTitle(i18nC.dialogText());
            dialogBox.setButtonText(i18nC.dialogCancelButton());
            HorizontalPanel horizontalPanel = new HorizontalPanel();
            horizontalPanel.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
            horizontalPanel.setSpacing(3);
            horizontalPanel.add(new Label(i18nC.dialogSaveName()));
            final TextBox textBox = new TextBox();
            textBox.setText((null != scriptName ? scriptName.getText() : ""));
            textBox.setMaxLength(AppConstants.SCRIPT_NAME_LENGTH);
            horizontalPanel.add(textBox);
            dialogBox.addContent(horizontalPanel);
            dialogBox.addButton(i18nC.dialogSaveButton(), new ClickHandler() {
                public void onClick(ClickEvent event) {
                    String name = textBox.getText();
                    // Check input name length < 255
                    if (name.length() > AppConstants.SCRIPT_NAME_LENGTH) {
                        displayErrorDialog(i18nC.dialogErrorMsg());
                    } else {
                        if (!"".equals(name)) {
                            if (name.contains("<script") || name.contains("</script")) {
                                displayErrorDialog(i18nC.dialogSaveNameErrorMessage());
                            } else {
                                groovyShellService.saveAs(scriptUuid, name, textArea.getText(),
                                        ActionType.USER_SAVE_AS, getSecureToken(), getSaveAsAsyncCallback());
                                dialogBox.hide();
                            }//from   w  w  w . j  av  a  2 s  . c  o  m
                        } else {
                            addConsoleMessage(i18nC.commandSaveAsMsg());
                        }
                    }
                }
            });

            dialogBox.center();
            dialogBox.show();
        }
    };
}

From source file:org.thechiselgroup.biomixer.client.workbench.init.WorkbenchInitializer.java

License:Apache License

protected void initBenchmarkResourceCreator() {
    if (DevelopmentSettings.isBenchmarkEnabled() || runsInDevelopmentMode()) {
        TextCommandPresenter presenter = new TextCommandPresenter(
                new CreateBenchmarkResourcesCommand(resourceSetFactory, dataSources), "Add");
        presenter.init();/*from   w ww. ja  v a  2 s . com*/
        TextBox textBox = presenter.getTextBox();
        textBox.setMaxLength(6);
        textBox.setWidth("50px");
        addWidget(DATA_PANEL, textBox);
        addWidget(DATA_PANEL, presenter.getExecuteButton());
    }
}

From source file:org.unitime.timetable.gwt.client.curricula.CurriculumFilterBox.java

License:Apache License

public CurriculumFilterBox() {
    super(null);/*from w ww.  java2s .c  om*/

    setShowSuggestionsOnFocus(false);

    iDepartments = new ListBox();
    iDepartments.setMultipleSelect(false);
    iDepartments.setWidth("100%");

    addFilter(new FilterBox.CustomFilter("department", MESSAGES.tagDepartment(), iDepartments) {
        @Override
        public void getSuggestions(List<Chip> chips, String text,
                AsyncCallback<Collection<Suggestion>> callback) {
            if (text.isEmpty()) {
                callback.onSuccess(null);
            } else {
                Chip oldChip = getChip("department");
                List<Suggestion> suggestions = new ArrayList<Suggestion>();
                for (int i = 0; i < iDepartments.getItemCount(); i++) {
                    Chip chip = new Chip("department", iDepartments.getValue(i))
                            .withTranslatedCommand(MESSAGES.tagDepartment());
                    String name = iDepartments.getItemText(i);
                    if (iDepartments.getValue(i).toLowerCase().startsWith(text.toLowerCase())) {
                        suggestions.add(new Suggestion(name, chip, oldChip));
                    } else if (text.length() > 2 && (name.toLowerCase().contains(" " + text.toLowerCase())
                            || name.toLowerCase().contains(" (" + text.toLowerCase()))) {
                        suggestions.add(new Suggestion(name, chip, oldChip));
                    }
                }
                callback.onSuccess(suggestions);
            }
        }
    });
    iDepartments.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            Chip oldChip = getChip("department");
            Chip newChip = (iDepartments.getSelectedIndex() <= 0 ? null
                    : new Chip("department", iDepartments.getValue(iDepartments.getSelectedIndex()))
                            .withTranslatedCommand(MESSAGES.tagDepartment()));
            if (oldChip != null) {
                if (newChip == null) {
                    removeChip(oldChip, true);
                } else {
                    if (!oldChip.getValue().equals(newChip.getValue())) {
                        removeChip(oldChip, false);
                        addChip(newChip, true);
                    }
                }
            } else {
                if (newChip != null)
                    addChip(newChip, true);
            }
        }
    });

    addFilter(new FilterBox.StaticSimpleFilter("area", MESSAGES.tagAcademicArea()));
    addFilter(new FilterBox.StaticSimpleFilter("major", MESSAGES.tagMajor()));
    addFilter(new FilterBox.StaticSimpleFilter("classification", MESSAGES.tagClassification()));
    addFilter(new FilterBox.StaticSimpleFilter("curriculum", MESSAGES.tagCurriculum()));

    final TextBox curriculum = new TextBox();
    curriculum.setStyleName("unitime-TextArea");
    curriculum.setMaxLength(100);
    curriculum.setWidth("200px");

    iOther = new FilterBox.CustomFilter("other", MESSAGES.tagOther(), new Label(MESSAGES.propCurriculum()),
            curriculum);
    addFilter(iOther);

    curriculum.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            boolean removed = removeChip(new Chip("curriculum", null), false);
            if (curriculum.getText().isEmpty()) {
                if (removed)
                    fireValueChangeEvent();
            } else {
                addChip(new Chip("curriculum", curriculum.getText())
                        .withTranslatedCommand(MESSAGES.tagCurriculum()), true);
            }
        }
    });

    addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            if (!isFilterPopupShowing()) {
                iDepartments.setSelectedIndex(0);
                for (int i = 1; i < iDepartments.getItemCount(); i++) {
                    String value = iDepartments.getValue(i);
                    if (hasChip(new Chip("department", value))) {
                        iDepartments.setSelectedIndex(i);
                        break;
                    }
                }
                Chip chip = getChip("curriculum");
                if (chip == null)
                    curriculum.setText("");
                else
                    curriculum.setText(chip.getValue());
            }
            init(false, getAcademicSessionId(), new Command() {
                @Override
                public void execute() {
                    if (isFilterPopupShowing())
                        showFilterPopup();
                }
            });
        }
    });
}

From source file:org.unitime.timetable.gwt.client.sectioning.SectioningStatusFilterBox.java

License:Apache License

public SectioningStatusFilterBox(boolean online) {
    super(null);//from   www.  ja v a2  s. com

    iOnline = online;

    FilterBox.StaticSimpleFilter mode = new FilterBox.StaticSimpleFilter("mode",
            GWT_MESSAGES.tagSectioningMode());
    mode.setMultipleSelection(false);
    addFilter(mode);

    addFilter(new FilterBox.StaticSimpleFilter("type", GWT_MESSAGES.tagSectioningType()));

    addFilter(new FilterBox.StaticSimpleFilter("status", GWT_MESSAGES.tagSectioningStatus()));
    addFilter(new FilterBox.StaticSimpleFilter("approver", GWT_MESSAGES.tagApprover()));

    addFilter(new FilterBox.StaticSimpleFilter("area", GWT_MESSAGES.tagAcademicArea()));
    addFilter(new FilterBox.StaticSimpleFilter("major", GWT_MESSAGES.tagMajor()));
    addFilter(new FilterBox.StaticSimpleFilter("classification", GWT_MESSAGES.tagClassification()));
    addFilter(new FilterBox.StaticSimpleFilter("group", GWT_MESSAGES.tagStudentGroup()));
    addFilter(new FilterBox.StaticSimpleFilter("accommodation", GWT_MESSAGES.tagStudentAccommodation()));

    addFilter(new FilterBox.StaticSimpleFilter("assignment", GWT_MESSAGES.tagSectioningAssignment()) {
        @Override
        public void validate(String text, AsyncCallback<Chip> callback) {
            String translatedValue = null;
            if ("assigned".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.assignmentType()[0];
            else if ("reserved".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.assignmentType()[1];
            else if ("not assigned".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.assignmentType()[2];
            else if ("wait-listed".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.assignmentType()[3];
            callback.onSuccess(new Chip(getCommand(), text).withTranslatedCommand(getLabel())
                    .withTranslatedValue(translatedValue));
        }
    });

    addFilter(new FilterBox.StaticSimpleFilter("consent", GWT_MESSAGES.tagSectioningConsent()) {
        @Override
        public void validate(String text, AsyncCallback<Chip> callback) {
            String translatedValue = null;
            if ("consent".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.consentTypeAbbv()[0];
            else if ("no consent".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.consentTypeAbbv()[1];
            else if ("waiting".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.consentTypeAbbv()[2];
            else if ("approved".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.consentTypeAbbv()[3];
            else if ("to do".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.consentTypeAbbv()[3];
            callback.onSuccess(new Chip(getCommand(), text).withTranslatedCommand(getLabel())
                    .withTranslatedValue(translatedValue));
        }
    });

    FilterBox.StaticSimpleFilter op = new FilterBox.StaticSimpleFilter("operation",
            GWT_MESSAGES.tagSectioningOperation());
    op.setMultipleSelection(true);
    addFilter(op);

    final TextBox curriculum = new TextBox();
    curriculum.setStyleName("unitime-TextArea");
    curriculum.setMaxLength(100);
    curriculum.setWidth("200px");

    curriculum.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            boolean removed = removeChip(new Chip("curriculum", null), false);
            if (curriculum.getText().isEmpty()) {
                if (removed)
                    fireValueChangeEvent();
            } else {
                addChip(new Chip("curriculum", curriculum.getText())
                        .withTranslatedCommand(GWT_MESSAGES.tagCurriculum()), true);
            }
        }
    });

    Label courseLab = new Label(MESSAGES.propCourse());
    iCourse = new AriaSuggestBox(new CourseOracle());
    iCourse.setStyleName("unitime-TextArea");
    iCourse.setWidth("200px");
    addFilter(new FilterBox.StaticSimpleFilter("course", GWT_MESSAGES.tagCourse()));
    iCourse.getValueBox().addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            courseChanged(true);
        }
    });
    iCourse.getValueBox().addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                @Override
                public void execute() {
                    courseChanged(false);
                }
            });
        }
    });
    iCourse.getValueBox().addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE)
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                    @Override
                    public void execute() {
                        courseChanged(false);
                    }
                });
        }
    });
    iCourse.getValueBox().addBlurHandler(new BlurHandler() {
        @Override
        public void onBlur(BlurEvent event) {
            courseChanged(true);
        }
    });
    iCourse.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
        @Override
        public void onSelection(SelectionEvent<com.google.gwt.user.client.ui.SuggestOracle.Suggestion> event) {
            courseChanged(true);
        }
    });

    Label studentLab = new Label(MESSAGES.propStudent());
    studentLab.getElement().getStyle().setMarginLeft(10, Unit.PX);
    iStudent = new AriaSuggestBox(new StudentOracle());
    iStudent.setStyleName("unitime-TextArea");
    iStudent.setWidth("200px");
    addFilter(new FilterBox.StaticSimpleFilter("student", GWT_MESSAGES.tagStudent()));
    iStudent.getValueBox().addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            studentChanged(true);
        }
    });
    iStudent.getValueBox().addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                @Override
                public void execute() {
                    studentChanged(false);
                }
            });
        }
    });
    iStudent.getValueBox().addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE)
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                    @Override
                    public void execute() {
                        studentChanged(false);
                    }
                });
        }
    });
    iStudent.getValueBox().addBlurHandler(new BlurHandler() {
        @Override
        public void onBlur(BlurEvent event) {
            studentChanged(true);
        }
    });
    iStudent.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
        @Override
        public void onSelection(SelectionEvent<com.google.gwt.user.client.ui.SuggestOracle.Suggestion> event) {
            studentChanged(true);
        }
    });

    addFilter(new FilterBox.CustomFilter("Other", GWT_MESSAGES.tagOther(), courseLab, iCourse, studentLab,
            iStudent) {
        @Override
        public void getSuggestions(final List<Chip> chips, final String text,
                AsyncCallback<Collection<FilterBox.Suggestion>> callback) {
            if (text.isEmpty()) {
                callback.onSuccess(null);
            } else {
                List<FilterBox.Suggestion> suggestions = new ArrayList<FilterBox.Suggestion>();
                Chip old = null;
                for (Chip c : chips) {
                    if (c.getCommand().equals("limit")) {
                        old = c;
                        break;
                    }
                }
                try {
                    Integer.parseInt(text);
                    suggestions.add(new Suggestion(
                            new Chip("limit", text).withTranslatedCommand(GWT_MESSAGES.tagLimit()), old));
                } catch (NumberFormatException e) {
                }
                callback.onSuccess(suggestions);
            }
        }
    });

    addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            iLastCourse = getChip("course");
            iLastStudent = getChip("student");

            if (!isFilterPopupShowing()) {
                Chip chip = getChip("curriculum");
                if (chip == null)
                    curriculum.setText("");
                else
                    curriculum.setText(chip.getValue());

                Chip course = getChip("course");
                if (course == null)
                    iCourse.setText("");
                else
                    iCourse.setText(course.getValue());

                Chip student = getChip("student");
                if (student == null)
                    iStudent.setText("");
                else
                    iStudent.setText(student.getValue());
            }

            init(false, getAcademicSessionId(), new Command() {
                @Override
                public void execute() {
                    if (isFilterPopupShowing())
                        showFilterPopup();
                }
            });
        }
    });
}