Example usage for com.vaadin.ui TextField setValue

List of usage examples for com.vaadin.ui TextField setValue

Introduction

In this page you can find the example usage for com.vaadin.ui TextField setValue.

Prototype

@Override
public void setValue(String value) 

Source Link

Document

Sets the value of this text field.

Usage

From source file:com.peergreen.webconsole.scope.system.internal.bundle.BundleView.java

License:Open Source License

@PostConstruct
public void createView() {
    setMargin(true);//from  ww  w .j  a  va  2 s  . c o  m
    setSpacing(true);

    /*
    Page.Styles styles = Page.getCurrent().getStyles();
    styles.add(".no-padding {padding: 0em 0em 0em 0em !important; }");
    */

    HorizontalLayout header = new HorizontalLayout();
    //        header.setWidth("100%");
    header.setSpacing(true);
    header.setMargin(true);

    Label title = new Label("OSGi Bundles");
    title.addStyleName("h1");
    //        title.setSizeUndefined();
    header.addComponent(title);
    header.setComponentAlignment(title, Alignment.MIDDLE_LEFT);

    final TextField filter = new TextField();
    filter.addTextChangeListener(new FieldEvents.TextChangeListener() {
        @Override
        public void textChange(final FieldEvents.TextChangeEvent event) {
            data.removeAllContainerFilters();
            String trimmed = event.getText().trim();
            Container.Filter or = new Or(new SimpleStringFilter(BUNDLE_ID_COLUMN, trimmed, true, false),
                    new SimpleStringFilter(BUNDLE_NAME_COLUMN, trimmed, true, false),
                    new SimpleStringFilter(BUNDLE_SYMBOLICNAME_COLUMN, trimmed, true, false),
                    new SimpleStringFilter(VERSION_COLUMN, trimmed, true, false),
                    new SimpleStringFilter(PRETTY_STATE_COLUMN, trimmed, true, false));

            data.addContainerFilter(or);
        }
    });

    filter.setInputPrompt("Filter");
    filter.addShortcutListener(new ShortcutListener("Clear", ShortcutAction.KeyCode.ESCAPE, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            filter.setValue("");
            data.removeAllContainerFilters();
        }
    });
    header.addComponent(filter);
    header.setExpandRatio(filter, 1);
    header.setComponentAlignment(filter, Alignment.MIDDLE_LEFT);

    // Store the header in the vertical layout (this)
    addComponent(header);

    addComponent(tabSheet);

    table = new Table();
    table.setContainerDataSource(data);
    table.setSizeFull();
    table.setSortContainerPropertyId(BUNDLE_ID_COLUMN);
    table.setSortAscending(true);
    table.setImmediate(true);
    table.setColumnHeader(BUNDLE_ID_COLUMN, "Bundle ID");
    table.setColumnHeader(PRETTY_NAME_COLUMN, "Bundle Name");
    table.setColumnHeader(VERSION_COLUMN, "Version");
    table.setColumnHeader(PRETTY_STATE_COLUMN, "State");
    table.setColumnHeader("actions", "Actions");

    table.setColumnWidth(BUNDLE_ID_COLUMN, 100);

    table.setColumnAlignment(BUNDLE_ID_COLUMN, Table.Align.CENTER);
    table.setColumnAlignment(PRETTY_STATE_COLUMN, Table.Align.CENTER);
    table.setColumnAlignment(VERSION_COLUMN, Table.Align.CENTER);

    table.addGeneratedColumn("actions", new Table.ColumnGenerator() {
        @Override
        public Object generateCell(final Table source, final Object itemId, final Object columnId) {
            HorizontalLayout layout = new HorizontalLayout();
            BeanItem<BundleItem> item = (BeanItem<BundleItem>) source.getContainerDataSource().getItem(itemId);
            Bundle bundle = item.getBean().getBundle();
            if (BundleHelper.isState(bundle, Bundle.INSTALLED)
                    || BundleHelper.isState(bundle, Bundle.RESOLVED)) {
                Button changeState = new Button();
                changeState.addClickListener(new StartBundleClickListener(bundle, notifierService));
                //changeState.addStyleName("no-padding");
                changeState.setCaption("Start");
                //changeState.setIcon(new ClassResource(BundleViewer.class, "/images/go-next.png"));
                if (!securityManager.isUserInRole("admin")) {
                    changeState.setDisableOnClick(true);
                }
                layout.addComponent(changeState);
            }
            if (BundleHelper.isState(bundle, Bundle.ACTIVE)) {
                Button changeState = new Button();
                changeState.addClickListener(new StopBundleClickListener(bundle, notifierService));
                //changeState.addStyleName("no-padding");
                changeState.setCaption("Stop");
                if (!securityManager.isUserInRole("admin")) {
                    changeState.setDisableOnClick(true);
                }
                //changeState.setIcon(new ClassResource(BundleViewer.class, "/images/media-record.png"));
                layout.addComponent(changeState);
            }

            // Update
            Button update = new Button();
            update.addClickListener(new UpdateBundleClickListener(bundle, notifierService));
            //update.addStyleName("no-padding");
            update.setCaption("Update");
            if (!securityManager.isUserInRole("admin")) {
                update.setDisableOnClick(true);
            }
            //update.setIcon(new ClassResource(BundleViewer.class, "/images/view-refresh.png"));
            layout.addComponent(update);

            // Trash
            Button trash = new Button();
            trash.addClickListener(new UninstallBundleClickListener(bundle, notifierService));
            //trash.addStyleName("no-padding");
            trash.setCaption("Delete");
            if (!securityManager.isUserInRole("admin")) {
                trash.setDisableOnClick(true);
            }
            //trash.setIcon(new ClassResource(BundleViewer.class, "/images/user-trash-full.png"));
            layout.addComponent(trash);

            return layout;
        }
    });

    table.setVisibleColumns(BUNDLE_ID_COLUMN, PRETTY_NAME_COLUMN, VERSION_COLUMN, PRETTY_STATE_COLUMN,
            "actions");

    table.addItemClickListener(new ItemClickEvent.ItemClickListener() {
        @Override
        public void itemClick(final ItemClickEvent event) {
            if (event.isDoubleClick()) {
                BeanItem<BundleItem> item = (BeanItem<BundleItem>) table.getContainerDataSource()
                        .getItem(event.getItemId());
                Bundle bundle = item.getBean().getBundle();
                showBundle(bundle);
            }
        }
    });

    createBundleTracker();

    tabSheet.setSizeFull();
    selectedTabListener = new SelectedTabListener(uiContext.getViewNavigator());
    selectedTabListener.addLocation(table, uiContext.getViewNavigator().getLocation(this.getClass().getName()));
    tabSheet.addSelectedTabChangeListener(selectedTabListener);
    tabSheet.addTab(table, "Bundles", new ClassResource(BundleView.class, "/images/22x22/user-home.png"));
    setExpandRatio(tabSheet, 1.5f);

    tabSheet.setCloseHandler(new TabSheet.CloseHandler() {
        @Override
        public void onTabClose(TabSheet tabsheet, Component tabContent) {
            for (Map.Entry<Long, Component> tab : openTabs.entrySet()) {
                if (tabContent.equals(tab.getValue())) {
                    openTabs.remove(tab.getKey());
                }
            }
            tabsheet.removeComponent(tabContent);
            selectedTabListener.removeLocation(tabContent);
        }
    });
}

From source file:com.peergreen.webconsole.scope.system.internal.service.ServiceViewer.java

License:Open Source License

private void initHeader() {
    HorizontalLayout header = new HorizontalLayout();
    header.setWidth("100%");
    header.setSpacing(true);//from ww  w. j  av  a 2s .  c  om
    header.setMargin(true);

    Label title = new Label("OSGi Services");
    title.addStyleName("h1");
    title.setSizeUndefined();
    header.addComponent(title);
    header.setComponentAlignment(title, Alignment.MIDDLE_LEFT);

    final TextField filter = new TextField();
    filter.addTextChangeListener(new FieldEvents.TextChangeListener() {
        @Override
        public void textChange(final FieldEvents.TextChangeEvent event) {
            data.removeAllContainerFilters();
            String trimmed = event.getText().trim();
            Container.Filter or = new Or(new SimpleStringFilter(SERVICE_ID_COLUMN, trimmed, true, false),
                    new InterfacesFilter(trimmed), new BundleFilter(trimmed),
                    new ServicePropertiesFilter(trimmed));

            data.addContainerFilter(or);
        }
    });

    filter.setInputPrompt("Filter");
    filter.addShortcutListener(new ShortcutListener("Clear", ShortcutAction.KeyCode.ESCAPE, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            filter.setValue("");
            data.removeAllContainerFilters();
        }
    });
    header.addComponent(filter);
    header.setExpandRatio(filter, 1);
    header.setComponentAlignment(filter, Alignment.MIDDLE_LEFT);

    // Store the header in the vertical layout (this)
    addComponent(header);
}

From source file:com.peergreen.webconsole.scope.system.internal.shell.ShellConsoleView.java

License:Open Source License

private void initConsole() {

    Table table = new Table();
    table.addStyleName("console-font");
    table.addStyleName("borderless");
    table.setColumnHeaderMode(Table.ColumnHeaderMode.HIDDEN);
    IndexedContainer container = new IndexedContainer();
    table.setContainerDataSource(container);
    table.setImmediate(true);/*from  w  w w .j av  a  2  s.  com*/
    table.setSizeFull();
    table.addContainerProperty("line", Label.class, null);

    addComponent(table);
    // Magic number: use all the empty space
    setExpandRatio(table, 1.5f);

    OutputStream out = new HtmlAnsiOutputStream(new WebConsoleOutputStream(table, container));
    this.printStream = new PrintStream(out);

    session = processor.createSession(new ByteArrayInputStream("".getBytes()), printStream, printStream);

    final TextField input = new TextField();
    input.setWidth("100%");
    input.setInputPrompt(">$ ");

    final ShortcutListener shortcut = new ShortcutListener("Execute", ShortcutAction.KeyCode.ENTER, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            try {
                String value = input.getValue();
                printStream.printf(">$ %s\n", value);
                Object result = session.execute(value);
                //session.put(Constants.LAST_RESULT_VARIABLE, result);
                if (result != null) {
                    session.getConsole().println(session.format(result, Converter.INSPECT));
                }
            } catch (Exception e) {
                printException(printStream, e);
            }
            input.setValue("");
        }
    };

    // Install the shortcut listener only when the input text-field has the focus
    input.addFocusListener(new FieldEvents.FocusListener() {
        @Override
        public void focus(final FieldEvents.FocusEvent event) {
            input.addShortcutListener(shortcut);
        }
    });
    input.addBlurListener(new FieldEvents.BlurListener() {
        @Override
        public void blur(final FieldEvents.BlurEvent event) {
            input.removeShortcutListener(shortcut);
        }
    });

    addComponent(input);

    doSessionBranding(printStream);
}

From source file:com.pms.component.ganttchart.scheduletask.TaskGanntChart.java

License:Apache License

private void openStepEditor(AbstractStep step) {
    final Window win = new Window("More Info");
    win.setResizable(false);/*w w w  . ja  v  a 2 s  .  co  m*/
    win.center();

    VerticalLayout content = new VerticalLayout();
    content.setMargin(true);
    content.setSpacing(true);
    win.setContent(content);

    String taskName = step.getCaption();
    UserStoryDAO userStoryDAO = (UserStoryDAO) DashboardUI.context.getBean("UserStory");
    UserStory userStory = userStoryDAO.getCurrentWorkingUserStory(project);

    TaskDAO taskDAO = (TaskDAO) DashboardUI.context.getBean("Task");
    Task task1 = taskDAO.getTaskFromUserStroyNameAndTaskName(userStory.getName(), taskName);

    TextField userStoryNameField = new TextField("Task Name");
    userStoryNameField.setValue(task1.getName());

    TextField userStoryPriority = new TextField("Priority");
    userStoryPriority.setValue(String.valueOf(task1.getPriority()));

    TextField userStoryState = new TextField("State");
    userStoryState.setValue(task1.getState());

    TextField projectName = new TextField("Project Name");
    projectName.setValue(project.getName());

    TextField userStoryName = new TextField("UserStoryName Name");
    userStoryName.setValue(userStory.getName());

    content.addComponent(userStoryNameField);
    content.addComponent(userStoryPriority);
    content.addComponent(userStoryState);
    content.addComponent(projectName);
    content.addComponent(userStoryName);

    Button ok = new Button("Ok", new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {

            win.close();
        }

    });

    content.addComponent(ok);
    win.setClosable(true);

    DashboardUI.getCurrent().getUI().addWindow(win);
}

From source file:com.pms.component.ganttchart.scheduletask.UserStoryGanntChart.java

License:Apache License

private void openStepEditor(AbstractStep step) {
    final Window win = new Window("More Info");
    win.setResizable(false);//  w  w w.java 2 s. com
    win.center();

    VerticalLayout content = new VerticalLayout();
    content.setMargin(true);
    content.setSpacing(true);
    win.setContent(content);

    String userStoryName = step.getCaption();
    UserStoryDAO userStoryDAO = (UserStoryDAO) DashboardUI.context.getBean("UserStory");
    UserStory userStory = userStoryDAO.getUserStoryFormProjectNameAndUserStoryName(project.getName(),
            userStoryName);

    TextField userStoryNameField = new TextField("User Story Name");
    userStoryNameField.setValue(userStory.getName());

    TextField userStoryPriority = new TextField("Priority");
    userStoryPriority.setValue(String.valueOf(userStory.getPriority()));

    TextField userStoryState = new TextField("State");
    userStoryState.setValue(userStory.getState());

    TextField projectName = new TextField("Project Name");
    projectName.setValue(project.getName());

    content.addComponent(userStoryNameField);
    content.addComponent(userStoryPriority);
    content.addComponent(userStoryState);
    content.addComponent(projectName);

    Button ok = new Button("Ok", new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {

            win.close();
        }

    });

    content.addComponent(ok);
    win.setClosable(true);

    DashboardUI.getCurrent().getUI().addWindow(win);
}

From source file:com.skysql.manager.ui.GeneralSettings.java

License:Open Source License

/**
 * Time layout./*from w ww.j  av a  2 s. co  m*/
 *
 * @return the vertical layout
 */
private VerticalLayout timeLayout() {

    VerticalLayout layout = new VerticalLayout();
    layout.setWidth("100%");
    layout.setSpacing(true);
    layout.setMargin(new MarginInfo(false, true, false, true));

    HorizontalLayout titleLayout = new HorizontalLayout();
    titleLayout.setSpacing(true);
    layout.addComponent(titleLayout);

    final Label title = new Label("<h3>Date & Time Presentation</h3>", ContentMode.HTML);
    title.setSizeUndefined();
    titleLayout.addComponent(title);

    Embedded info = new Embedded(null, new ThemeResource("img/info.png"));
    info.addStyleName("infoButton");
    info.setDescription(
            "Determines if date & time stamps are displayed in the originally recorded format or adjusted to the local timezone.<br/>The format can be customized by using the following Java 6 SimpleDateFormat patterns:"
                    + "</blockquote>"
                    + " <table border=0 cellspacing=3 cellpadding=0 summary=\"Chart shows pattern letters, date/time component, presentation, and examples.\">\n"
                    + "     <tr bgcolor=\"#ccccff\">\n" + "         <th align=left>Letter\n"
                    + "         <th align=left>Date or Time Component\n"
                    + "         <th align=left>Presentation\n" + "         <th align=left>Examples\n"
                    + "     <tr>\n" + "         <td><code>G</code>\n" + "         <td>Era designator\n"
                    + "         <td><a href=\"#text\">Text</a>\n" + "         <td><code>AD</code>\n"
                    + "     <tr bgcolor=\"#eeeeff\">\n" + "         <td><code>y</code>\n"
                    + "         <td>Year\n" + "         <td><a href=\"#year\">Year</a>\n"
                    + "         <td><code>1996</code>; <code>96</code>\n" + "     <tr>\n"
                    + "         <td><code>M</code>\n" + "         <td>Month in year\n"
                    + "         <td><a href=\"#month\">Month</a>\n"
                    + "         <td><code>July</code>; <code>Jul</code>; <code>07</code>\n"
                    + "     <tr bgcolor=\"#eeeeff\">\n" + "         <td><code>w</code>\n"
                    + "         <td>Week in year\n" + "         <td><a href=\"#number\">Number</a>\n"
                    + "         <td><code>27</code>\n" + "     <tr>\n" + "         <td><code>W</code>\n"
                    + "         <td>Week in month\n" + "         <td><a href=\"#number\">Number</a>\n"
                    + "         <td><code>2</code>\n" + "     <tr bgcolor=\"#eeeeff\">\n"
                    + "         <td><code>D</code>\n" + "         <td>Day in year\n"
                    + "         <td><a href=\"#number\">Number</a>\n" + "         <td><code>189</code>\n"
                    + "     <tr>\n" + "         <td><code>d</code>\n" + "         <td>Day in month\n"
                    + "         <td><a href=\"#number\">Number</a>\n" + "         <td><code>10</code>\n"
                    + "     <tr bgcolor=\"#eeeeff\">\n" + "         <td><code>F</code>\n"
                    + "         <td>Day of week in month\n" + "         <td><a href=\"#number\">Number</a>\n"
                    + "         <td><code>2</code>\n" + "     <tr>\n" + "         <td><code>E</code>\n"
                    + "         <td>Day in week\n" + "         <td><a href=\"#text\">Text</a>\n"
                    + "         <td><code>Tuesday</code>; <code>Tue</code>\n"
                    + "     <tr bgcolor=\"#eeeeff\">\n" + "         <td><code>a</code>\n"
                    + "         <td>Am/pm marker\n" + "         <td><a href=\"#text\">Text</a>\n"
                    + "         <td><code>PM</code>\n" + "     <tr>\n" + "         <td><code>H</code>\n"
                    + "         <td>Hour in day (0-23)\n" + "         <td><a href=\"#number\">Number</a>\n"
                    + "         <td><code>0</code>\n" + "     <tr bgcolor=\"#eeeeff\">\n"
                    + "         <td><code>k</code>\n" + "         <td>Hour in day (1-24)\n"
                    + "         <td><a href=\"#number\">Number</a>\n" + "         <td><code>24</code>\n"
                    + "     <tr>\n" + "         <td><code>K</code>\n" + "         <td>Hour in am/pm (0-11)\n"
                    + "         <td><a href=\"#number\">Number</a>\n" + "         <td><code>0</code>\n"
                    + "     <tr bgcolor=\"#eeeeff\">\n" + "         <td><code>h</code>\n"
                    + "         <td>Hour in am/pm (1-12)\n" + "         <td><a href=\"#number\">Number</a>\n"
                    + "         <td><code>12</code>\n" + "     <tr>\n" + "         <td><code>m</code>\n"
                    + "         <td>Minute in hour\n" + "         <td><a href=\"#number\">Number</a>\n"
                    + "         <td><code>30</code>\n" + "     <tr bgcolor=\"#eeeeff\">\n"
                    + "         <td><code>s</code>\n" + "         <td>Second in minute\n"
                    + "         <td><a href=\"#number\">Number</a>\n" + "         <td><code>55</code>\n"
                    + "     <tr>\n" + "         <td><code>S</code>\n" + "         <td>Millisecond\n"
                    + "         <td><a href=\"#number\">Number</a>\n" + "         <td><code>978</code>\n"
                    + "     <tr bgcolor=\"#eeeeff\">\n" + "         <td><code>z</code>\n"
                    + "         <td>Time zone\n" + "         <td><a href=\"#timezone\">General time zone</a>\n"
                    + "         <td><code>Pacific Standard Time</code>; <code>PST</code>; <code>GMT-08:00</code>\n"
                    + "     <tr>\n" + "         <td><code>Z</code>\n" + "         <td>Time zone\n"
                    + "         <td><a href=\"#rfc822timezone\">RFC 822 time zone</a>\n"
                    + "         <td><code>-0800</code>\n" + " </table>\n" + " </blockquote>\n" + "");
    titleLayout.addComponent(info);
    titleLayout.setComponentAlignment(info, Alignment.MIDDLE_CENTER);

    final DateConversion dateConversion = VaadinSession.getCurrent().getAttribute(DateConversion.class);

    OptionGroup option = new OptionGroup("Display options");
    option.addItem(false);
    option.setItemCaption(false, "Show time in UTC/GMT");
    option.addItem(true);
    option.setItemCaption(true, "Adjust to local timezone (" + dateConversion.getClientTZname() + ")");

    String propertyTimeAdjust = userObject.getProperty(UserObject.PROPERTY_TIME_ADJUST);
    option.select(propertyTimeAdjust == null ? DEFAULT_TIME_ADJUST : Boolean.valueOf(propertyTimeAdjust));
    option.setNullSelectionAllowed(false);
    option.setHtmlContentAllowed(true);
    option.setImmediate(true);
    layout.addComponent(option);

    final HorizontalLayout defaultLayout = new HorizontalLayout();
    defaultLayout.setSpacing(true);
    layout.addComponent(defaultLayout);

    final Form form = new Form();
    form.setFooter(null);
    final TextField timeFormat = new TextField("Format");
    form.addField("timeFormat", timeFormat);
    defaultLayout.addComponent(form);

    option.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent event) {
            boolean value = (Boolean) event.getProperty().getValue();
            dateConversion.setAdjustedToLocal(value);
            userObject.setProperty(UserObject.PROPERTY_TIME_ADJUST, String.valueOf(value));
            settingsDialog.setRefresh(true);
            if (value == false) {
                timeFormat.removeAllValidators();
                timeFormat.setComponentError(null);
                form.setComponentError(null);
                form.setValidationVisible(false);
                settingsDialog.setClose(true);
            } else {
                timeFormat.addValidator(new TimeFormatValidator());
                timeFormat.setInputPrompt(DateConversion.DEFAULT_TIME_FORMAT);
                //timeFormat.setClickShortcut(KeyCode.ENTER);
            }
        }
    });

    String propertyTimeFormat = userObject.getProperty(UserObject.PROPERTY_TIME_FORMAT);
    propertyTimeFormat = (propertyTimeFormat == null ? DateConversion.DEFAULT_TIME_FORMAT
            : String.valueOf(propertyTimeFormat));

    timeFormat.setColumns(16);
    timeFormat.setValue(propertyTimeFormat);
    timeFormat.setImmediate(true);
    timeFormat.setRequired(true);
    timeFormat.setRequiredError("Format cannot be empty.");
    timeFormat.addValidator(new TimeFormatValidator());

    timeFormat.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent event) {
            String value = (String) event.getProperty().getValue();
            try {
                form.setComponentError(null);
                form.commit();
                timeFormat.setComponentError(null);
                form.setValidationVisible(false);
                dateConversion.setFormat(value);
                userObject.setProperty(UserObject.PROPERTY_TIME_FORMAT, value);
                settingsDialog.setClose(true);
                settingsDialog.setRefresh(true);
            } catch (InvalidValueException e) {
                settingsDialog.setClose(false);
                timeFormat.setComponentError(new UserError("Invalid Format (Java SimpleDateFormat)."));
                timeFormat.focus();
            }
        }
    });

    Button defaultButton = new Button("Restore Default");
    defaultLayout.addComponent(defaultButton);
    defaultLayout.setComponentAlignment(defaultButton, Alignment.MIDDLE_LEFT);
    defaultButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void buttonClick(Button.ClickEvent event) {
            timeFormat.setValue(DateConversion.DEFAULT_TIME_FORMAT);
        }
    });

    return layout;
}

From source file:com.skysql.manager.ui.MonitorsSettings.java

License:Open Source License

/**
 * Monitor form.//from w w w .  j  a  va2  s  . co m
 *
 * @param monitor the monitor
 * @param title the title
 * @param description the description
 * @param button the button
 */
public void monitorForm(final MonitorRecord monitor, String title, String description, String button) {
    final TextField monitorName = new TextField("Monitor Name");
    final TextField monitorDescription = new TextField("Description");
    final TextField monitorUnit = new TextField("Measurement Unit");
    final TextArea monitorSQL = new TextArea("SQL Statement");
    final CheckBox monitorDelta = new CheckBox("Is Delta");
    final CheckBox monitorAverage = new CheckBox("Is Average");
    final NativeSelect validationTarget = new NativeSelect("Validate SQL on");
    final NativeSelect monitorInterval = new NativeSelect("Sampling interval");
    final NativeSelect monitorChartType = new NativeSelect("Default display");

    secondaryDialog = new ModalWindow(title, null);
    UI.getCurrent().addWindow(secondaryDialog);
    secondaryDialog.addCloseListener(this);

    final VerticalLayout formContainer = new VerticalLayout();
    formContainer.setMargin(new MarginInfo(true, true, false, true));
    formContainer.setSpacing(false);

    final Form form = new Form();
    formContainer.addComponent(form);
    form.setImmediate(false);
    form.setFooter(null);
    form.setDescription(description);

    String value;

    if ((value = monitor.getName()) != null) {
        monitorName.setValue(value);
    }
    form.addField("monitorName", monitorName);
    form.getField("monitorName").setRequired(true);
    form.getField("monitorName").setRequiredError("Monitor Name is missing");
    monitorName.focus();
    monitorName.setImmediate(true);
    monitorName.addValidator(new MonitorNameValidator(monitor.getName()));

    if ((value = monitor.getDescription()) != null) {
        monitorDescription.setValue(value);
    }
    monitorDescription.setWidth("24em");
    form.addField("monitorDescription", monitorDescription);

    if ((value = monitor.getUnit()) != null) {
        monitorUnit.setValue(value);
    }
    form.addField("monitorUnit", monitorUnit);

    if ((value = monitor.getSql()) != null) {
        monitorSQL.setValue(value);
    }
    monitorSQL.setWidth("24em");
    monitorSQL.addValidator(new SQLValidator());
    form.addField("monitorSQL", monitorSQL);

    final String noValidation = "None - Skip Validation";
    validationTarget.setImmediate(true);
    validationTarget.setNullSelectionAllowed(false);
    validationTarget.addItem(noValidation);
    validationTarget.select(noValidation);
    OverviewPanel overviewPanel = getSession().getAttribute(OverviewPanel.class);
    ArrayList<NodeInfo> nodes = overviewPanel.getNodes();

    if (nodes == null || nodes.isEmpty()) {
        SystemInfo systemInfo = VaadinSession.getCurrent().getAttribute(SystemInfo.class);
        String systemID = systemInfo.getCurrentID();
        String systemType = systemInfo.getCurrentSystem().getSystemType();
        if (systemID.equals(SystemInfo.SYSTEM_ROOT)) {
            ClusterComponent clusterComponent = VaadinSession.getCurrent().getAttribute(ClusterComponent.class);
            systemID = clusterComponent.getID();
            systemType = clusterComponent.getSystemType();
        }
        nodes = new ArrayList<NodeInfo>();
        for (String nodeID : systemInfo.getSystemRecord(systemID).getNodes()) {
            NodeInfo nodeInfo = new NodeInfo(systemID, systemType, nodeID);
            nodes.add(nodeInfo);
        }

    }

    for (NodeInfo node : nodes) {
        validationTarget.addItem(node.getID());
        validationTarget.setItemCaption(node.getID(), node.getName());
    }
    validationTarget.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {
            nodeID = (String) event.getProperty().getValue();
            validateSQL = nodeID.equals(noValidation) ? false : true;
        }

    });
    form.addField("validationTarget", validationTarget);

    monitorDelta.setValue(monitor.isDelta());
    form.addField("monitorDelta", monitorDelta);

    monitorAverage.setValue(monitor.isAverage());
    form.addField("monitorAverage", monitorAverage);

    SettingsValues intervalValues = new SettingsValues(SettingsValues.SETTINGS_MONITOR_INTERVAL);
    String[] intervals = intervalValues.getValues();
    for (String interval : intervals) {
        monitorInterval.addItem(Integer.parseInt(interval));
    }

    Collection<?> validIntervals = monitorInterval.getItemIds();
    if (validIntervals.contains(monitor.getInterval())) {
        monitorInterval.select(monitor.getInterval());
    } else {
        SystemInfo systemInfo = getSession().getAttribute(SystemInfo.class);
        String defaultInterval = systemInfo.getSystemRecord(systemID).getProperties()
                .get(SystemInfo.PROPERTY_DEFAULTMONITORINTERVAL);
        if (defaultInterval != null && validIntervals.contains(Integer.parseInt(defaultInterval))) {
            monitorInterval.select(Integer.parseInt(defaultInterval));
        } else if (!validIntervals.isEmpty()) {
            monitorInterval.select(validIntervals.toArray()[0]);
        } else {
            new ErrorDialog(null, "No set of permissible monitor intervals found");
        }

        monitorInterval.setNullSelectionAllowed(false);
        form.addField("monitorInterval", monitorInterval);
    }

    for (UserChart.ChartType type : UserChart.ChartType.values()) {
        monitorChartType.addItem(type.name());
    }
    monitorChartType
            .select(monitor.getChartType() == null ? UserChart.ChartType.values()[0] : monitor.getChartType());
    monitorChartType.setNullSelectionAllowed(false);
    form.addField("monitorChartType", monitorChartType);

    HorizontalLayout buttonsBar = new HorizontalLayout();
    buttonsBar.setStyleName("buttonsBar");
    buttonsBar.setSizeFull();
    buttonsBar.setSpacing(true);
    buttonsBar.setMargin(true);
    buttonsBar.setHeight("49px");

    Label filler = new Label();
    buttonsBar.addComponent(filler);
    buttonsBar.setExpandRatio(filler, 1.0f);

    Button cancelButton = new Button("Cancel");
    buttonsBar.addComponent(cancelButton);
    buttonsBar.setComponentAlignment(cancelButton, Alignment.MIDDLE_RIGHT);

    cancelButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void buttonClick(ClickEvent event) {
            form.discard();
            secondaryDialog.close();
        }
    });

    Button okButton = new Button(button);
    okButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void buttonClick(ClickEvent event) {
            try {
                form.setComponentError(null);
                form.commit();
                monitor.setName(monitorName.getValue());
                monitor.setDescription(monitorDescription.getValue());
                monitor.setUnit(monitorUnit.getValue());
                monitor.setSql(monitorSQL.getValue());
                monitor.setDelta(monitorDelta.getValue());
                monitor.setAverage(monitorAverage.getValue());
                monitor.setInterval((Integer) monitorInterval.getValue());
                monitor.setChartType((String) monitorChartType.getValue());
                String ID;
                if ((ID = monitor.getID()) == null) {
                    if (Monitors.setMonitor(monitor)) {
                        ID = monitor.getID();
                        select.addItem(ID);
                        select.select(ID);
                        Monitors.reloadMonitors();
                        monitorsAll = Monitors.getMonitorsList(systemType);
                    }
                } else {
                    Monitors.setMonitor(monitor);
                    ChartProperties chartProperties = getSession().getAttribute(ChartProperties.class);
                    chartProperties.setDirty(true);
                    settingsDialog.setRefresh(true);
                }

                if (ID != null) {
                    select.setItemCaption(ID, monitor.getName());
                    displayMonitorRecord(ID);
                    secondaryDialog.close();
                }

            } catch (EmptyValueException e) {
                return;
            } catch (InvalidValueException e) {
                return;
            } catch (Exception e) {
                ManagerUI.error(e.getMessage());
                return;
            }
        }
    });
    buttonsBar.addComponent(okButton);
    buttonsBar.setComponentAlignment(okButton, Alignment.MIDDLE_RIGHT);

    VerticalLayout windowLayout = (VerticalLayout) secondaryDialog.getContent();
    windowLayout.setSpacing(false);
    windowLayout.setMargin(false);
    windowLayout.addComponent(formContainer);
    windowLayout.addComponent(buttonsBar);

}

From source file:com.swifta.mats.web.usermanagement.AddUserModule.java

private void clearFields() {
    isValidatorAdded = false;/*from  w  w w  .j a  v a 2 s  .co  m*/
    for (Field<?> f : arrLAllFields) {

        if (f instanceof TextField) {
            TextField tf = ((TextField) f);
            tf.setValue("");
            tf.setComponentError(null);

        }
        if (f instanceof ComboBox) {

            ComboBox combo = ((ComboBox) f);
            combo.setComponentError(null);
            combo.select(null);
            continue;
        }

        if (f instanceof OptionGroup) {

            OptionGroup opt = ((OptionGroup) f);
            opt.select(null);
            opt.setComponentError(null);

            continue;

        }
        if (f instanceof CheckBox) {

            CheckBox chk = ((CheckBox) f);
            chk.setValue(false);
            chk.setComponentError(null);

            continue;

        }
        if (f instanceof PopupDateField) {
            Date date = null;
            PopupDateField d = ((PopupDateField) f);
            d.setValue(date);
            d.setComponentError(null);

            continue;

        }
    }

}

From source file:com.swifta.mats.web.usermanagement.UserDetailsModule.java

private VerticalLayout getUDContainer(String strUID) {

    if (bee == null)
        bee = new UserDetailsBackEnd();

    hm = bee.getUD(strUID);/* ww  w. j  av  a2  s.com*/

    String strProf = hm.get("Profile Type");

    VerticalLayout cAgentInfo = new VerticalLayout();
    cAgentInfo.setMargin(new MarginInfo(true, false, true, false));
    cAgentInfo.setStyleName("c_details_test");
    cAgentInfo.setSizeUndefined();

    FormLayout cBasic = new FormLayout();

    // cBasic.setSpacing(true);
    Label lbB = new Label();
    lbB.setCaption("General");
    lbB.setStyleName("label_search_user u_d_t");

    cBasic.addComponent(lbB);
    String cap = "First Name";
    TextField tF = new TextField(cap);
    tFFN = tF;
    tFFN.setRequired(true);
    tF.setValue(hm.get(cap));

    addDatum("Username", hm.get("Username"), cBasic);
    addDatum("Profile", strProf, cBasic);
    addDatum("Account Status", hm.get("Status"), cBasic);
    addDatum("First Name", hm.get("First Name"), cBasic);

    tF = new TextField("Middle Name");
    addDatum("Middle Name", hm.get("Middle Name"), cBasic);
    addDatum("Last Name", hm.get("Last Name"), cBasic);
    addDatum("Gender", hm.get("Gender"), cBasic);
    addDatum("Occupation", hm.get("Occupation"), cBasic);
    addDatum("Date of Birth", hm.get("Date of Birth"), cBasic);
    addDatum("Country", hm.get("Country"), cBasic);
    addDatum("State", hm.get("State"), cBasic);
    addDatum("Local Government", hm.get("Local Government"), cBasic);

    VerticalLayout cC = new VerticalLayout();

    HorizontalLayout cBAndCAndAcc = new HorizontalLayout();
    cBAndCAndAcc.addComponent(cBasic);
    cBAndCAndAcc.addComponent(cC);

    FormLayout cCompany = new FormLayout();
    // Label lbC = new Label("Company");
    Label lbC = new Label();
    lbC.setCaption("Identification");
    lbC.setStyleName("label_search_user lb_frm_add_user u_d_t");

    combo = new ComboBox("ID Type");

    combo.addItem("Passport Number");
    combo.addItem("National Registration Identification Number");
    combo.addItem("Drivers License Number");
    combo.addItem("Identification Card");
    combo.addItem("Employer Identification Number");
    combo.select("Passport Number");
    comboIDType = combo;
    comboIDType.setRequired(true);

    cCompany.addComponent(lbC);
    addDatum("ID Type", hm.get("ID Type"), cCompany);
    addDatum("ID No.", hm.get("ID No."), cCompany);
    addDatum("Issuer", hm.get("Issuer"), cCompany);
    addDatum("Issue Date", hm.get("Issue Date"), cCompany);
    addDatum("Expiry Date", hm.get("Expiry Date"), cCompany);
    cC.addComponent(cCompany);

    FormLayout pC = new FormLayout();
    lbC = new Label();
    lbC.setCaption("Primary Contacts");
    lbC.setStyleName("label_search_user u_d_t");
    pC.addComponent(lbC);
    addDatum("Mobile Phone No.", hm.get("P-Mobile Phone No."), pC);
    addDatum("Alt. Phone No.", hm.get("P-Alt. Phone No."), pC);
    addDatum("Email Address", hm.get("Email"), pC);
    cC.addComponent(pC);

    FormLayout sC = new FormLayout();
    lbC = new Label();
    lbC.setCaption("Secondary Contacts");
    lbC.setStyleName("label_search_user lb_frm_add_user u_d_t");
    sC.addComponent(lbC);
    addDatum("Mobile Phone No.", hm.get("S-Mobile Phone No."), sC);
    addDatum("Alt. Phone No.", hm.get("S-Alt. Phone No."), sC);
    addDatum("Email Address", hm.get("Email"), sC);
    cC.addComponent(sC);

    FormLayout physicalC = new FormLayout();
    lbC = new Label();
    lbC.setCaption("Physical Address");
    lbC.setStyleName("label_search_user lb_frm_add_user u_d_t");
    physicalC.addComponent(lbC);
    StringBuilder sbAddr = new StringBuilder();

    String strp = hm.get("Postal Code");
    sbAddr.append((strp == null || strp.trim().isEmpty()) ? "" : "P.O.Box " + strp + ", ");
    strp = hm.get("Street");
    sbAddr.append((strp == null || strp.trim().isEmpty()) ? "" : strp + ", ");
    strp = hm.get("Province");
    sbAddr.append((strp == null || strp.trim().isEmpty()) ? "" : strp + ", ");

    strp = hm.get("State");
    sbAddr.append((strp == null || strp.trim().isEmpty()) ? "" : strp + ", ");

    strp = hm.get("Country");
    sbAddr.append((strp == null || strp.trim().isEmpty()) ? "." : strp);

    Label lb = new Label();
    lbC.setContentMode(ContentMode.HTML);

    lb.setStyleName("label_ud");
    lb.setCaption(sbAddr.toString());

    physicalC.addComponent(lb);

    cC.addComponent(physicalC);
    cC.addComponent(cBtnEditCancel);

    cC.setMargin(new MarginInfo(false, true, false, true));
    cAgentInfo.addComponent(cBAndCAndAcc);

    return cAgentInfo;
}

From source file:com.swifta.mats.web.usermanagement.UserDetailsModule.java

private HorizontalLayout getADC() {

    // Notification.show(strTbName);

    VerticalLayout cAgentInfo = new VerticalLayout();
    cAgentInfo.setMargin(new MarginInfo(true, true, true, true));
    cAgentInfo.setStyleName("c_details_test");

    // VerticalLayout cAcc = new VerticalLayout();
    Label lbAcc = new Label();

    lbAcc.setCaption("Account");
    lbAcc.setStyleName("label_search_user lb_frm_add_user u_d_t");

    // lbC.setCaption("Identification");
    // lbC.setStyleName("label_search_user lb_frm_add_user u_d_t");
    // lbAcc.setStyleName("lb_frm_add_user");

    ComboBox comboHierarchy = null;/*from www .j  av  a2s .  c o  m*/

    comboHierarchy = new ComboBox("Profile");

    final FormLayout cLBody = new FormLayout();
    cLBody.addComponent(lbAcc);
    // cLBody.setSpacing(true);

    comboHierarchy.addItem(1);
    comboHierarchy.setItemCaption(1, "MATS_ADMIN_USER_PROFILE");
    comboHierarchy.select(1);
    comboProfile = comboHierarchy;
    comboProfile.setRequired(true);
    // cAcc.addComponent(comboHierarchy);

    addDatum("Profile", hm.get("Profile Type"), cLBody);

    TextField tF = new TextField("Username");
    tF.setValue("Livepwndz");
    tFUN = tF;
    tFUN.setRequired(true); // cLBody.addComponent(tF);

    addDatum("Username", hm.get("Username"), cLBody);

    tF = new TextField("MSISDN");
    tF.setValue("+256774191152");
    tFMSISDN = tF;
    tFMSISDN.setRequired(true); // cLBody.addComponent(tF);

    addDatum("MSISDN", hm.get("MSISDN"), cLBody);

    tF = new TextField("PIN"); // / cLBody.addComponent(tF);

    tF = new TextField("Email");
    tFAccEmail = tF;
    tFAccEmail.setRequired(true);
    tFAccEmail.setValue("ppounds1@gmail.com"); //
    // cLBody.addComponent(tF);
    addDatum("Email", hm.get("Email"), cLBody);

    combo = new ComboBox("Bank Domain");
    combo.addItem("Stanbic Bank");
    combo.select("Stanbic Bank");
    comboBDomain = combo; //
    // cLBody.addComponent(combo);
    addDatum("Bank Domain", hm.get("Bank"), cLBody);

    combo = new ComboBox("Bank Code ID");
    combo.addItem("001");
    combo.select("001");
    comboBID = combo; // cLBody.addComponent(combo);
    addDatum("Bank Code ID", hm.get("Bank Code"), cLBody);

    tF = new TextField("Bank Account");
    tF.setValue("00232333452315");
    tFBAcc = tF; // tFBAcc.setValidationVisible(true); //
    tFBAcc.addValidator(new NoNull()); // cLBody.addComponent(tF);
    addDatum("Bank Account", hm.get("Bank Account"), cLBody);

    combo.addItem(1);
    combo.setItemCaption(1, "US Dollars");
    combo.select(1);
    comboCur = combo; // cLBody.addComponent(combo);

    addDatum("Currency", hm.get("Currency"), cLBody);

    tF = new TextField("Clearing Number");
    tF.setValue("00212");
    tFClrNo = tF; // cLBody.addComponent(tF);
    addDatum("Clearing No. ", hm.get("Clearing No."), cLBody);

    String strNameCap = "Username";

    tF = new TextField(strNameCap);

    HorizontalLayout cAccBody = new HorizontalLayout();
    cAccBody.addComponent(cLBody);
    cLBody.addComponent(cBtnEditCancel);

    cLBody.setStyleName("c_body_visible");

    // cAcc.addComponent(cAccBody);
    cAgentInfo.addComponent(cLBody);

    // cBAndCAndAcc.addComponent(cAcc);
    HorizontalLayout c = new HorizontalLayout();
    c.addComponent(cAgentInfo);

    return c;

}