Example usage for com.vaadin.ui ComboBox addValueChangeListener

List of usage examples for com.vaadin.ui ComboBox addValueChangeListener

Introduction

In this page you can find the example usage for com.vaadin.ui ComboBox addValueChangeListener.

Prototype

@Override
    public Registration addValueChangeListener(HasValue.ValueChangeListener<T> listener) 

Source Link

Usage

From source file:org.hip.vif.web.util.DBDriverSelect.java

License:Open Source License

@SuppressWarnings("serial")
public static ComboBox getDBDriverSelection(final int inWidth, final boolean inAllowNull,
        final IProcessor inProcessor) {
    final ComboBox outSelect = new ComboBox(null, getDbDrivers());
    outSelect.setStyleName("vif-select"); //$NON-NLS-1$
    outSelect.setWidth(inWidth, Unit.PIXELS);
    outSelect.setNullSelectionAllowed(inAllowNull);
    outSelect.setImmediate(true);/*from   ww  w .ja  v a2  s  .com*/
    outSelect.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent inEvent) {
            final String lItemID = ((DBDriverBean) inEvent.getProperty().getValue()).getID();
            if (inProcessor != null) {
                inProcessor.process(lItemID);
            }
        }
    });
    return outSelect;
}

From source file:org.hip.vif.web.util.LanguageSelectHelper.java

License:Open Source License

/** Convenience method, create a language select containing the available languages.
 *
 * @param inLanguageProperty {@link Property} the property containing the language definition actually configured
 * @return {@link ComboBox} *//*from  www.  j  ava 2  s  . c  om*/
@SuppressWarnings({ "serial" })
public static ComboBox getLanguageSelection(final Property<String> inLanguageProperty) {
    final ComboBox outSelect = createSelect(inLanguageProperty.getValue().toString());
    outSelect.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent inEvent) {
            inLanguageProperty.setValue(inEvent.getProperty().getValue().toString());
        }
    });
    return outSelect;
}

From source file:org.ikasan.dashboard.ui.topology.window.WiretapConfigurationWindow.java

License:BSD License

/**
  * Helper method to initialise this object.
  * //from w  ww  .  j  a v  a  2 s  .co  m
  * @param message
  */
protected void init() {
    setModal(true);
    setHeight("90%");
    setWidth("90%");

    GridLayout layout = new GridLayout(2, 10);
    layout.setSizeFull();
    layout.setSpacing(true);
    layout.setMargin(true);
    layout.setColumnExpandRatio(0, .25f);
    layout.setColumnExpandRatio(1, .75f);

    Label wiretapLabel = new Label("Wiretap Configuration");
    wiretapLabel.setStyleName(ValoTheme.LABEL_HUGE);
    layout.addComponent(wiretapLabel);

    Label moduleNameLabel = new Label();
    moduleNameLabel.setContentMode(ContentMode.HTML);
    moduleNameLabel.setValue(VaadinIcons.ARCHIVE.getHtml() + " Module Name:");
    moduleNameLabel.setSizeUndefined();
    layout.addComponent(moduleNameLabel, 0, 1);
    layout.setComponentAlignment(moduleNameLabel, Alignment.MIDDLE_RIGHT);

    TextField moduleNameTextField = new TextField();
    moduleNameTextField.setRequired(true);
    moduleNameTextField.setValue(this.component.getFlow().getModule().getName());
    moduleNameTextField.setReadOnly(true);
    moduleNameTextField.setWidth("80%");
    layout.addComponent(moduleNameTextField, 1, 1);

    Label flowNameLabel = new Label();
    flowNameLabel.setContentMode(ContentMode.HTML);
    flowNameLabel.setValue(VaadinIcons.AUTOMATION.getHtml() + " Flow Name:");
    flowNameLabel.setSizeUndefined();
    layout.addComponent(flowNameLabel, 0, 2);
    layout.setComponentAlignment(flowNameLabel, Alignment.MIDDLE_RIGHT);

    TextField flowNameTextField = new TextField();
    flowNameTextField.setRequired(true);
    flowNameTextField.setValue(this.component.getFlow().getName());
    flowNameTextField.setReadOnly(true);
    flowNameTextField.setWidth("80%");
    layout.addComponent(flowNameTextField, 1, 2);

    Label componentNameLabel = new Label();
    componentNameLabel.setContentMode(ContentMode.HTML);
    componentNameLabel.setValue(VaadinIcons.COG.getHtml() + " Component Name:");
    componentNameLabel.setSizeUndefined();
    layout.addComponent(componentNameLabel, 0, 3);
    layout.setComponentAlignment(componentNameLabel, Alignment.MIDDLE_RIGHT);

    TextField componentNameTextField = new TextField();
    componentNameTextField.setRequired(true);
    componentNameTextField.setValue(this.component.getName());
    componentNameTextField.setReadOnly(true);
    componentNameTextField.setWidth("80%");
    layout.addComponent(componentNameTextField, 1, 3);

    Label errorCategoryLabel = new Label("Relationship:");
    errorCategoryLabel.setSizeUndefined();
    layout.addComponent(errorCategoryLabel, 0, 4);
    layout.setComponentAlignment(errorCategoryLabel, Alignment.MIDDLE_RIGHT);

    final ComboBox relationshipCombo = new ComboBox();
    //      relationshipCombo.addValidator(new StringLengthValidator(
    //               "An relationship must be selected!", 1, -1, false));
    relationshipCombo.setImmediate(false);
    relationshipCombo.setValidationVisible(false);
    relationshipCombo.setRequired(true);
    relationshipCombo.setRequiredError("A relationship must be selected!");
    relationshipCombo.setHeight("30px");
    relationshipCombo.setNullSelectionAllowed(false);
    layout.addComponent(relationshipCombo, 1, 4);
    relationshipCombo.addItem("before");
    relationshipCombo.setItemCaption("before", "Before");
    relationshipCombo.addItem("after");
    relationshipCombo.setItemCaption("after", "After");

    Label jobTypeLabel = new Label("Job Type:");
    jobTypeLabel.setSizeUndefined();
    layout.addComponent(jobTypeLabel, 0, 5);
    layout.setComponentAlignment(jobTypeLabel, Alignment.MIDDLE_RIGHT);

    final ComboBox jobTopCombo = new ComboBox();
    //      jobTopCombo.addValidator(new StringLengthValidator(
    //               "A job type must be selected!", 1, -1, false));
    jobTopCombo.setImmediate(false);
    jobTopCombo.setValidationVisible(false);
    jobTopCombo.setRequired(true);
    jobTopCombo.setRequiredError("A job type must be selected!");
    jobTopCombo.setHeight("30px");
    jobTopCombo.setNullSelectionAllowed(false);
    layout.addComponent(jobTopCombo, 1, 5);
    jobTopCombo.addItem("loggingJob");
    jobTopCombo.setItemCaption("loggingJob", "Logging Job");
    jobTopCombo.addItem("wiretapJob");
    jobTopCombo.setItemCaption("wiretapJob", "Wiretap Job");

    final Label timeToLiveLabel = new Label("Time to Live:");
    timeToLiveLabel.setSizeUndefined();
    timeToLiveLabel.setVisible(false);
    layout.addComponent(timeToLiveLabel, 0, 6);
    layout.setComponentAlignment(timeToLiveLabel, Alignment.MIDDLE_RIGHT);

    final TextField timeToLiveTextField = new TextField();
    timeToLiveTextField.setRequired(true);
    timeToLiveTextField.setValidationVisible(false);
    jobTopCombo.setRequiredError("A time to live value must be entered!");
    timeToLiveTextField.setVisible(false);
    timeToLiveTextField.setWidth("40%");
    layout.addComponent(timeToLiveTextField, 1, 6);

    jobTopCombo.addValueChangeListener(new ComboBox.ValueChangeListener() {

        /* (non-Javadoc)
         * @see com.vaadin.data.Property.ValueChangeListener#valueChange(com.vaadin.data.Property.ValueChangeEvent)
         */
        @Override
        public void valueChange(ValueChangeEvent event) {
            String value = (String) event.getProperty().getValue();

            if (value.equals("wiretapJob")) {
                timeToLiveLabel.setVisible(true);
                timeToLiveTextField.setVisible(true);
            } else {
                timeToLiveLabel.setVisible(false);
                timeToLiveTextField.setVisible(false);
            }
        }

    });

    GridLayout buttonLayouts = new GridLayout(3, 1);
    buttonLayouts.setSpacing(true);

    Button saveButton = new Button("Save");
    saveButton.setStyleName(ValoTheme.BUTTON_SMALL);
    saveButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                relationshipCombo.validate();
                jobTopCombo.validate();

                if (timeToLiveTextField.isVisible()) {
                    timeToLiveTextField.validate();
                }
            } catch (InvalidValueException e) {
                relationshipCombo.setValidationVisible(true);
                relationshipCombo.markAsDirty();
                jobTopCombo.setValidationVisible(true);
                jobTopCombo.markAsDirty();

                if (timeToLiveTextField.isVisible()) {
                    timeToLiveTextField.setValidationVisible(true);
                    timeToLiveTextField.markAsDirty();
                }

                Notification.show("There are errors on the wiretap creation form!", Type.ERROR_MESSAGE);
                return;
            }

            createWiretap((String) relationshipCombo.getValue(), (String) jobTopCombo.getValue(),
                    timeToLiveTextField.getValue());
        }
    });

    Button cancelButton = new Button("Cancel");
    cancelButton.setStyleName(ValoTheme.BUTTON_SMALL);
    cancelButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            close();
        }
    });

    buttonLayouts.addComponent(saveButton);
    buttonLayouts.addComponent(cancelButton);

    layout.addComponent(buttonLayouts, 0, 7, 1, 7);
    layout.setComponentAlignment(buttonLayouts, Alignment.MIDDLE_CENTER);

    Panel paramPanel = new Panel();
    paramPanel.setStyleName("dashboard");
    paramPanel.setWidth("100%");
    paramPanel.setContent(layout);

    triggerTable = new Table();

    Label existingWiretapLabel = new Label("Existing Wiretaps");
    existingWiretapLabel.setStyleName(ValoTheme.LABEL_HUGE);
    layout.addComponent(existingWiretapLabel, 0, 8, 1, 8);

    layout.addComponent(triggerTable, 0, 9, 1, 9);
    layout.setComponentAlignment(triggerTable, Alignment.TOP_CENTER);

    this.triggerTable.setWidth("80%");
    this.triggerTable.setHeight(150, Unit.PIXELS);
    this.triggerTable.setCellStyleGenerator(new IkasanCellStyleGenerator());
    this.triggerTable.addStyleName(ValoTheme.TABLE_SMALL);
    this.triggerTable.addStyleName("ikasan");
    this.triggerTable.addContainerProperty("Job Type", String.class, null);
    this.triggerTable.addContainerProperty("Relationship", String.class, null);
    this.triggerTable.addContainerProperty("Trigger Parameters", String.class, null);
    this.triggerTable.addContainerProperty("", Button.class, null);

    refreshTriggerTable();

    GridLayout wrapper = new GridLayout(1, 1);
    wrapper.setMargin(true);
    wrapper.setSizeFull();
    wrapper.addComponent(paramPanel);

    this.setContent(wrapper);
}

From source file:org.jdal.vaadin.ui.FormUtils.java

License:Apache License

/**
 * Add a link on primary and dependent ComboBoxes by property name. 
 * When selection changes on primary use propertyName to get a Collection and fill dependent ComboBox with it
 * @param primary ComboBox when selection changes
 * @param dependent ComboBox that are filled with collection   
 * @param propertyName the property name for get the collection from primary selected item
 * @param addNull if true, add a null as first combobox item
 *///from w  w  w .  j  a v a2s  .c o  m
@SuppressWarnings("rawtypes")
public static void link(final ComboBox primary, final ComboBox dependent, final String propertyName,
        final boolean addNull) {

    primary.addValueChangeListener(new ValueChangeListener() {

        public void valueChange(ValueChangeEvent event) {
            Object selected = event.getProperty().getValue();
            if (selected != null) {
                BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(selected);
                if (wrapper.isReadableProperty(propertyName)) {
                    Collection items = (Collection) wrapper.getPropertyValue(propertyName);
                    dependent.removeAllItems();

                    if (addNull)
                        dependent.addItem(null);

                    for (Object item : items)
                        dependent.addItem(item);
                } else {
                    log.error("Can't write on propety '" + propertyName + "' of class: '" + selected.getClass()
                            + "'");
                }
            }

        }
    });
}

From source file:org.jpos.qi.components.DateRangeComponent.java

License:Open Source License

private ComboBox createDateRanges() {
    ComboBox combo = new ComboBox(app.getMessage("or").toUpperCase());
    combo.setStyleName(ValoTheme.COMBOBOX_SMALL);
    combo.setEmptySelectionAllowed(false);
    combo.setItems((Object[]) DateRange.ranges);
    combo.setItemCaptionGenerator(range -> app.getMessage((String) range));
    combo.addValueChangeListener(event -> {
        if (event.getValue() != null) {
            datePickerFrom.setValue(null);
            datePickerTo.setValue(null);
            if (refreshBtn != null)
                refreshBtn.click();/*from   w w  w . java 2s . c  o  m*/
        }
    });
    return combo;
}

From source file:org.jumpmind.metl.ui.views.deploy.EditAgentDeploymentPanel.java

License:Open Source License

protected ComboBox getLogLevelComponent() {
    final ComboBox combo = new ComboBox("Log Level");
    combo.setNullSelectionAllowed(false);
    combo.setWidth(200, Unit.PIXELS);//from  w  w  w .j av a  2s. c om
    LogLevel[] levels = LogLevel.values();
    for (LogLevel logLevel : levels) {
        combo.addItem(logLevel.name());
    }
    combo.setValue(agentDeployment.getLogLevel());
    combo.addValueChangeListener(new ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            agentDeployment.setLogLevel((String) combo.getValue());
            saveAgentDeployment(agentDeployment);
        }
    });
    return combo;
}

From source file:org.jumpmind.metl.ui.views.deploy.EditAgentPanel.java

License:Open Source License

public EditAgentPanel(ApplicationContext context, TabbedPanel tabbedPanel, Agent agent) {
    this.context = context;
    this.tabbedPanel = tabbedPanel;
    this.agent = agent;
    this.backgroundRefresherService = context.getBackgroundRefresherService();

    HorizontalLayout editAgentLayout = new HorizontalLayout();
    editAgentLayout.setSpacing(true);/*from   w w  w.ja  v a  2s  . co m*/
    editAgentLayout.setMargin(new MarginInfo(true, false, false, true));
    editAgentLayout.addStyleName(ValoTheme.LAYOUT_HORIZONTAL_WRAPPING);
    addComponent(editAgentLayout);

    final ComboBox startModeCombo = new ComboBox("Start Mode");
    startModeCombo.setImmediate(true);
    startModeCombo.setNullSelectionAllowed(false);
    AgentStartMode[] modes = AgentStartMode.values();
    for (AgentStartMode agentStartMode : modes) {
        startModeCombo.addItem(agentStartMode.name());
    }
    startModeCombo.setValue(agent.getStartMode());
    startModeCombo.addValueChangeListener(event -> {
        agent.setStartMode((String) startModeCombo.getValue());
        context.getConfigurationService().save((AbstractObject) EditAgentPanel.this.agent);
    });

    editAgentLayout.addComponent(startModeCombo);
    editAgentLayout.setComponentAlignment(startModeCombo, Alignment.BOTTOM_LEFT);

    Button parameterButton = new Button("Parameters");
    parameterButton.addClickListener(new ParameterClickListener());
    editAgentLayout.addComponent(parameterButton);
    editAgentLayout.setComponentAlignment(parameterButton, Alignment.BOTTOM_LEFT);

    HorizontalLayout buttonGroup = new HorizontalLayout();

    final TextField hostNameField = new TextField("Hostname");
    hostNameField.setImmediate(true);
    hostNameField.setTextChangeEventMode(TextChangeEventMode.LAZY);
    hostNameField.setTextChangeTimeout(100);
    hostNameField.setWidth(20, Unit.EM);
    hostNameField.setNullRepresentation("");
    hostNameField.setValue(agent.getHost());
    hostNameField.addValueChangeListener(event -> {
        agent.setHost((String) hostNameField.getValue());
        EditAgentPanel.this.context.getConfigurationService().save((AbstractObject) agent);
        EditAgentPanel.this.context.getAgentManager().refresh(agent);
    });

    buttonGroup.addComponent(hostNameField);
    buttonGroup.setComponentAlignment(hostNameField, Alignment.BOTTOM_LEFT);

    Button getHostNameButton = new Button("Get Host");
    getHostNameButton.addClickListener(event -> hostNameField.setValue(AppUtils.getHostName()));
    buttonGroup.addComponent(getHostNameButton);
    buttonGroup.setComponentAlignment(getHostNameButton, Alignment.BOTTOM_LEFT);

    editAgentLayout.addComponent(buttonGroup);
    editAgentLayout.setComponentAlignment(buttonGroup, Alignment.BOTTOM_LEFT);

    Button exportButton = new Button("Export Agent Config", event -> exportConfiguration());
    editAgentLayout.addComponent(exportButton);
    editAgentLayout.setComponentAlignment(exportButton, Alignment.BOTTOM_LEFT);

    CheckBox autoRefresh = new CheckBox("Auto Refresh", Boolean.valueOf(agent.isAutoRefresh()));
    autoRefresh.setImmediate(true);
    autoRefresh.addValueChangeListener(event -> {
        agent.setAutoRefresh(autoRefresh.getValue());
        EditAgentPanel.this.context.getConfigurationService().save((AbstractObject) agent);
        EditAgentPanel.this.context.getAgentManager().refresh(agent);
    });
    editAgentLayout.addComponent(autoRefresh);
    editAgentLayout.setComponentAlignment(autoRefresh, Alignment.BOTTOM_LEFT);

    CheckBox allowTestFlowsField = new CheckBox("Allow Test Flows", Boolean.valueOf(agent.isAllowTestFlows()));
    allowTestFlowsField.setImmediate(true);
    allowTestFlowsField.addValueChangeListener(event -> {
        agent.setAllowTestFlows(allowTestFlowsField.getValue());
        EditAgentPanel.this.context.getConfigurationService().save((AbstractObject) agent);
        EditAgentPanel.this.context.getAgentManager().refresh(agent);
    });
    editAgentLayout.addComponent(allowTestFlowsField);
    editAgentLayout.setComponentAlignment(allowTestFlowsField, Alignment.BOTTOM_LEFT);

    ButtonBar buttonBar = new ButtonBar();
    addComponent(buttonBar);

    addDeploymentButton = buttonBar.addButton("Add Deployment", Icons.DEPLOYMENT);
    addDeploymentButton.addClickListener(new AddDeploymentClickListener());

    editButton = buttonBar.addButton("Edit", FontAwesome.EDIT);
    editButton.addClickListener(event -> editClicked());

    enableButton = buttonBar.addButton("Enable", FontAwesome.CHAIN);
    enableButton.addClickListener(event -> enableClicked());

    disableButton = buttonBar.addButton("Disable", FontAwesome.CHAIN_BROKEN);
    disableButton.addClickListener(event -> disableClicked());

    removeButton = buttonBar.addButton("Remove", FontAwesome.TRASH_O);
    removeButton.addClickListener(event -> removeClicked());

    runButton = buttonBar.addButton("Run", Icons.RUN);
    runButton.addClickListener(event -> runClicked());

    container = new BeanItemContainer<AgentDeploymentSummary>(AgentDeploymentSummary.class);
    container.setItemSorter(new TableItemSorter());

    table = new Table();
    table.setSizeFull();
    table.setCacheRate(100);
    table.setPageLength(100);
    table.setImmediate(true);
    table.setSelectable(true);
    table.setMultiSelect(true);

    table.setContainerDataSource(container);
    table.setVisibleColumns("name", "projectName", "type", "status", "logLevel", "startType",
            "startExpression");
    table.setColumnHeaders("Deployment", "Project", "Type", "Status", "Log Level", "Start Type",
            "Start Expression");
    table.addGeneratedColumn("status", new StatusRenderer());
    table.addItemClickListener(new TableItemClickListener());
    table.addValueChangeListener(new TableValueChangeListener());
    table.setSortContainerPropertyId("type");
    table.setSortAscending(true);

    addComponent(table);
    setExpandRatio(table, 1.0f);
    refresh();
    setButtonsEnabled();
    backgroundRefresherService.register(this);
}

From source file:org.jumpmind.metl.ui.views.design.EditModelPanel.java

License:Open Source License

public EditModelPanel(ApplicationContext context, String modelId, boolean readOnly) {
    this.context = context;
    this.model = new Model(modelId);
    this.readOnly = readOnly;
    context.getConfigurationService().refresh(model);

    ButtonBar buttonBar = new ButtonBar();
    addComponent(buttonBar);// w w w  .  j av a 2s .c  o  m

    if (!readOnly) {
        addEntityButton = buttonBar.addButton("Add Entity", FontAwesome.TABLE);
        addEntityButton.addClickListener(new AddEntityClickListener());

        addAttributeButton = buttonBar.addButton("Add Attribute", FontAwesome.COLUMNS);
        addAttributeButton.addClickListener(new AddAttributeClickListener());

        editButton = buttonBar.addButton("Edit", FontAwesome.EDIT);
        editButton.addClickListener(new EditClickListener());

        removeButton = buttonBar.addButton("Remove", FontAwesome.TRASH_O);
        removeButton.addClickListener(new RemoveClickListener());

        importButton = buttonBar.addButton("Import ...", FontAwesome.DOWNLOAD);
        importButton.addClickListener(new ImportClickListener());
    }

    filterField = buttonBar.addFilter();
    filterField.addTextChangeListener(new TextChangeListener() {
        public void textChange(TextChangeEvent event) {
            filterField.setValue(event.getText());
            treeTable.removeAllItems();
            addAll(event.getText(), EditModelPanel.this.model.getModelEntities());
        }
    });

    treeTable.setSizeFull();
    treeTable.setCacheRate(100);
    treeTable.setPageLength(100);
    treeTable.setImmediate(true);
    treeTable.setSelectable(true);
    treeTable.setMultiSelect(true);
    treeTable.addGeneratedColumn("name", new ColumnGenerator() {
        public Object generateCell(Table source, Object itemId, Object columnId) {
            final AbstractObject obj = (AbstractObject) itemId;
            if (lastEditItemIds.contains(itemId) && !readOnly) {
                ImmediateUpdateTextField t = new ImmediateUpdateTextField(null) {
                    protected void save(String text) {
                        obj.setName(text);
                        EditModelPanel.this.context.getConfigurationService().save(obj);
                    };
                };
                t.setWidth(100, Unit.PERCENTAGE);
                t.setValue(obj.getName());
                t.focus();
                t.selectAll();
                return t;
            } else {
                return UiUtils.getName(filterField.getValue(), obj.getName());
            }
        }
    });
    treeTable.setColumnHeader("name", "Name");

    treeTable.addGeneratedColumn("description", new ColumnGenerator() {
        public Object generateCell(Table source, Object itemId, Object columnId) {
            if (itemId instanceof ModelAttribute) {
                final ModelAttribute obj = (ModelAttribute) itemId;
                if (lastEditItemIds.contains(itemId) && !readOnly) {
                    ImmediateUpdateTextField t = new ImmediateUpdateTextField(null) {
                        protected void save(String text) {
                            obj.setDescription(text);
                            EditModelPanel.this.context.getConfigurationService().save(obj);
                        };
                    };
                    t.setWidth(100, Unit.PERCENTAGE);
                    t.setValue(obj.getDescription());
                    return t;
                } else {
                    return UiUtils.getName(filterField.getValue(), obj.getDescription());
                }
            }
            if (itemId instanceof ModelEntity) {
                final ModelEntity obj = (ModelEntity) itemId;
                if (lastEditItemIds.contains(itemId) && !readOnly) {
                    ImmediateUpdateTextField t = new ImmediateUpdateTextField(null) {
                        protected void save(String text) {
                            obj.setDescription(text);
                            EditModelPanel.this.context.getConfigurationService().save(obj);
                        };
                    };
                    t.setWidth(100, Unit.PERCENTAGE);
                    t.setValue(obj.getDescription());
                    return t;
                } else {
                    return UiUtils.getName(filterField.getValue(), obj.getDescription());
                }
            } else
                return null;
        }
    });
    treeTable.setColumnHeader("description", "Description");

    treeTable.addGeneratedColumn("type", new ColumnGenerator() {
        public Object generateCell(Table source, Object itemId, Object columnId) {
            if (itemId instanceof ModelAttribute) {
                final ModelAttribute obj = (ModelAttribute) itemId;
                if (lastEditItemIds.contains(itemId) && !readOnly) {
                    final ComboBox cbox = new ComboBox();
                    cbox.setNullSelectionAllowed(false);
                    for (DataType dataType : DataType.values()) {
                        cbox.addItem(dataType.name());
                    }
                    cbox.setValue(obj.getType());
                    cbox.addValueChangeListener(new ValueChangeListener() {
                        public void valueChange(ValueChangeEvent event) {
                            obj.setType((String) cbox.getValue());
                            EditModelPanel.this.context.getConfigurationService().save(obj);
                        }
                    });
                    cbox.addBlurListener(new BlurListener() {
                        public void blur(BlurEvent event) {
                            Collection<?> items = treeTable.getItemIds();
                            boolean found = false;
                            for (Object item : items) {
                                if (item.equals(obj)) {
                                    found = true;
                                } else if (found) {
                                    selectOnly(item);
                                    editSelectedItem();
                                    break;
                                }
                            }
                        }
                    });

                    return cbox;
                } else {
                    return obj.getType();
                }
            } else {
                return null;
            }
        }
    });
    treeTable.setColumnHeader("type", "Type");

    treeTable.addGeneratedColumn("pk", new ColumnGenerator() {
        public Object generateCell(Table source, Object itemId, Object columnId) {
            if (itemId instanceof ModelAttribute) {
                final ModelAttribute obj = (ModelAttribute) itemId;
                if (lastEditItemIds.contains(itemId) && !readOnly) {
                    final CheckBox cbox = new CheckBox();
                    cbox.setValue(obj.isPk());
                    cbox.setImmediate(true);
                    cbox.addValueChangeListener(event -> togglePk(obj));
                    cbox.addBlurListener(new BlurListener() {
                        public void blur(BlurEvent event) {
                            Collection<?> items = treeTable.getItemIds();
                            boolean found = false;
                            for (Object item : items) {
                                if (item.equals(obj)) {
                                    found = true;
                                } else if (found) {
                                    selectOnly(item);
                                    editSelectedItem();
                                    break;
                                }
                            }
                        }
                    });

                    return cbox;
                } else if (obj.isPk()) {
                    return new Label(FontAwesome.KEY.getHtml(), ContentMode.HTML);
                }
            }
            return null;
        }
    });
    treeTable.setColumnHeader("pk", "PK");
    treeTable.setColumnWidth("pk", 40);

    treeTable.addItemClickListener(new TreeTableItemClickListener());
    treeTable.addValueChangeListener(new TreeTableValueChangeListener());
    enterKeyListener = new ShortcutListener("Enter", KeyCode.ENTER, null) {
        public void handleAction(Object sender, Object target) {
            lastEditItemIds = Collections.emptySet();
            treeTable.refreshRowCache();
        }
    };

    addComponent(treeTable);
    setExpandRatio(treeTable, 1.0f);

    HorizontalLayout hlayout = new HorizontalLayout();
    addComponent(hlayout);

    Button collapseAll = new Button("Collapse All");
    collapseAll.addStyleName(ValoTheme.BUTTON_LINK);
    collapseAll.addStyleName(ValoTheme.BUTTON_SMALL);
    hlayout.addComponent(collapseAll);
    collapseAll.addClickListener(new ClickListener() {
        public void buttonClick(ClickEvent event) {
            for (Object itemId : treeTable.getItemIds()) {
                treeTable.setCollapsed(itemId, true);
            }
        }
    });

    Button expandAll = new Button("Expand All");
    expandAll.addStyleName(ValoTheme.BUTTON_LINK);
    expandAll.addStyleName(ValoTheme.BUTTON_SMALL);
    hlayout.addComponent(expandAll);
    expandAll.addClickListener(new ClickListener() {
        public void buttonClick(ClickEvent event) {
            for (Object itemId : treeTable.getItemIds()) {
                treeTable.setCollapsed(itemId, false);
            }
        }
    });

    addAll("", model.getModelEntities());

    setButtonsEnabled();
}

From source file:org.jumpmind.metl.ui.views.design.EditScriptPanel.java

License:Open Source License

@SuppressWarnings("serial")
protected void buildUI() {
    ButtonBar buttonBar = new ButtonBar();
    addComponent(buttonBar);//w ww .ja va 2  s  .c o  m

    editor = CommonUiUtils.createAceEditor();
    editor.setTextChangeEventMode(TextChangeEventMode.LAZY);
    editor.setTextChangeTimeout(200);

    editor.setMode(AceMode.java);

    final ComboBox select = new ComboBox();
    select.setWidth(40, Unit.EM);
    select.setTextInputAllowed(false);

    select.addItem(Script.IMPORTS);
    select.setItemCaption(Script.IMPORTS, SCRIPT_IMPORTS);
    select.addItem(Script.METHODS);
    select.setItemCaption(Script.METHODS, SCRIPT_METHODS);
    select.addItem(Script.INIT_SCRIPT);
    select.setItemCaption(Script.INIT_SCRIPT, SCRIPT_ON_INIT);
    select.addItem(Script.HANDLE_SCRIPT);
    select.setItemCaption(Script.HANDLE_SCRIPT, SCRIPT_ON_HANDLE);
    select.addItem(Script.ON_FLOW_SUCCESS);
    select.setItemCaption(Script.ON_FLOW_SUCCESS, SCRIPT_ON_SUCCESS);
    select.addItem(Script.ON_FLOW_ERROR);
    select.setItemCaption(Script.ON_FLOW_ERROR, SCRIPT_ON_ERROR);

    select.setImmediate(true);
    select.setNullSelectionAllowed(false);
    select.setNewItemsAllowed(false);
    select.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(ValueChangeEvent event) {
            String key = (String) select.getValue();
            editor.setReadOnly(false);
            editor.setValue(EditScriptPanel.this.component.get(key,
                    componentDefinition.findXMLSetting(key).getDefaultValue()));
            editor.setReadOnly(readOnly);
        }
    });
    select.setValue(Script.HANDLE_SCRIPT);
    buttonBar.addLeft(select);

    if (!readOnly) {
        editor.addTextChangeListener(new TextChangeListener() {

            @Override
            public void textChange(TextChangeEvent event) {
                String key = (String) select.getValue();
                EditScriptPanel.this.component.put(key, event.getText());
                EditScriptPanel.this.context.getConfigurationService()
                        .save(EditScriptPanel.this.component.findSetting(key));
            }
        });
    }

    addComponent(editor);
    setExpandRatio(editor, 1);

}

From source file:org.jumpmind.metl.ui.views.manage.ExecutionRunPanel.java

License:Open Source License

public ExecutionRunPanel(String executionId, ApplicationContext context, TabbedPanel parentTabSheet,
        IFlowRunnable flowRunnable) {//from  www . ja va 2  s.c o  m
    this.executionService = context.getExecutionService();
    this.executionId = executionId;
    this.context = context;
    this.parentTabSheet = parentTabSheet;
    this.flowRunnable = flowRunnable;

    Execution execution = executionService.findExecution(executionId);
    this.flow = context.getConfigurationService().findFlow(execution.getFlowId());

    HorizontalLayout topBar = new HorizontalLayout();
    topBar.setMargin(new MarginInfo(true, true, false, true));
    topBar.setWidth(100, Unit.PERCENTAGE);

    HorizontalLayout left = new HorizontalLayout();
    topBar.addComponent(left);

    HorizontalLayout right = new HorizontalLayout();
    right.setSpacing(true);
    topBar.addComponent(right);
    topBar.setComponentAlignment(right, Alignment.MIDDLE_RIGHT);

    Label limitLabel = new Label("Max Log Messages To Show :");
    right.addComponent(limitLabel);
    right.setComponentAlignment(limitLabel, Alignment.MIDDLE_RIGHT);
    limitField = new ImmediateUpdateTextField(null) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void save(String text) {
            Setting setting = context.getUser().findSetting(UserSetting.SETTING_MAX_LOG_MESSAGE_TO_SHOW);
            setting.setValue(Integer.toString(getMaxToShow(text)));
            context.getConfigurationService().save(setting);
        }
    };
    limitField.setWidth("5em");
    limitField.setValue(context.getUser().get(UserSetting.SETTING_MAX_LOG_MESSAGE_TO_SHOW, "1000"));
    right.addComponent(limitField);
    right.setComponentAlignment(limitField, Alignment.MIDDLE_RIGHT);

    showDiagramCheckbox = new CheckBox("Show Diagram");
    showDiagramCheckbox.addValueChangeListener((event) -> {
        if (showDiagramCheckbox.getValue()) {
            showDiagram();
        } else {
            showDetails();
        }
    });
    right.addComponent(showDiagramCheckbox);
    right.setComponentAlignment(showDiagramCheckbox, Alignment.MIDDLE_RIGHT);

    addComponent(topBar);

    ButtonBar buttonBar = new ButtonBar();

    rerunButton = buttonBar.addButton("Rerun", Icons.RUN, event -> rerun());
    rerunButton.setVisible(false);
    removeButton = buttonBar.addButton("Remove", Icons.DELETE, event -> remove());
    removeButton.setVisible(false);
    cancelButton = buttonBar.addButton("Cancel", Icons.CANCEL, event -> cancel());

    addComponent(buttonBar);

    HorizontalLayout header1 = new HorizontalLayout();
    header1.addComponent(new Label("<b>Flow:</b>", ContentMode.HTML));
    header1.addComponent(flowLabel);
    header1.addComponent(new Label("<b>Start:</b>", ContentMode.HTML));
    header1.addComponent(startLabel);
    header1.setSpacing(true);
    header1.setMargin(new MarginInfo(false, true, false, true));
    header1.setWidth("100%");
    addComponent(header1);

    HorizontalLayout header2 = new HorizontalLayout();
    header2.addComponent(new Label("<b>Status:</b>", ContentMode.HTML));
    header2.addComponent(statusLabel);
    header2.addComponent(new Label("<b>End:</b>", ContentMode.HTML));
    header2.addComponent(endLabel);
    header2.setSpacing(true);
    header2.setMargin(new MarginInfo(false, true, true, true));
    header2.setWidth("100%");
    addComponent(header2);

    stepContainer.setBeanIdProperty("id");

    diagramLayout = new VerticalLayout();
    diagramLayout.setWidth(10000, Unit.PIXELS);
    diagramLayout.setHeight(10000, Unit.PIXELS);

    flowPanel = new Panel();
    flowPanel.setSizeFull();
    flowPanel.addStyleName(ValoTheme.PANEL_WELL);

    flowPanel.setContent(diagramLayout);

    stepTable.setContainerDataSource(stepContainer);
    stepTable.setSelectable(true);
    stepTable.setMultiSelect(true);
    stepTable.setImmediate(true);
    stepTable.setSizeFull();
    stepTable.setVisibleColumns(
            new Object[] { "componentName", "threadNumber", "status", "payloadReceived", "messagesReceived",
                    "messagesProduced", "payloadProduced", "startTime", "endTime", "handleDurationString" });
    stepTable.setColumnHeaders(new String[] { "Component Name", "Thread", "Status", "Payload Recvd",
            "Msgs Recvd", "Msgs Sent", "Payload Sent", "Start", "End", "Run Duration" });
    stepTable.setColumnWidth("status", 100);
    stepTable.setColumnWidth("messagesReceived", 100);
    stepTable.setColumnWidth("messagesProduced", 100);
    stepTable.setColumnWidth("payloadReceived", 100);
    stepTable.setColumnWidth("payloadProduced", 100);
    stepTable.setColumnWidth("threadNumber", 100);
    stepTable.setColumnWidth("startTime", 170);
    stepTable.setColumnWidth("endTime", 170);
    stepTable.setColumnExpandRatio("handleDurationString", 1);
    stepTable.addValueChangeListener(event -> {
        @SuppressWarnings("unchecked")
        Set<String> executionStepIds = (Set<String>) event.getProperty().getValue();
        logContainer.removeAllItems();
        List<ExecutionStepLog> logs = executionService.findExecutionStepLogs(executionStepIds, getMaxToShow());
        logContainer.addAll(logs);
    });

    stepTable.addValueChangeListener(event -> {
        @SuppressWarnings("unchecked")
        Set<String> executionStepIds = (Set<String>) event.getProperty().getValue();
        logContainer.removeAllItems();
        List<ExecutionStepLog> logs = executionService.findExecutionStepLogs(executionStepIds, getMaxToShow());
        logContainer.addAll(logs);
    });

    logTable = new Grid();
    logTable.addColumn("level", String.class).setHeaderCaption("Level").setWidth(110).setMaximumWidth(200);
    logTable.addColumn("createTime", Date.class).setHeaderCaption("Time").setWidth(120).setMaximumWidth(200)
            .setRenderer(new DateRenderer(UiConstants.TIME_FORMAT));
    logTable.addColumn("logText", String.class).setHeaderCaption("Message").setExpandRatio(1);
    logTable.setContainerDataSource(logContainer);
    logTable.setSizeFull();
    logTable.addItemClickListener(event -> logTableCellClicked(logTable, event));
    logTable.addSortListener(event -> {
        lastSortOrder = event.getSortOrder();
    });

    HeaderRow filteringHeader = logTable.appendHeaderRow();
    HeaderCell logTextFilterCell = filteringHeader.getCell("logText");
    TextField filterField = new TextField();
    filterField.setInputPrompt("Filter");
    filterField.addStyleName(ValoTheme.TEXTFIELD_TINY);
    filterField.setWidth("100%");

    // Update filter When the filter input is changed
    filterField.addTextChangeListener(change -> {
        // Can't modify filters so need to replace
        logContainer.removeContainerFilters("logText");

        // (Re)create the filter if necessary
        if (!change.getText().isEmpty())
            logContainer.addContainerFilter(new SimpleStringFilter("logText", change.getText(), true, false));
    });
    logTextFilterCell.setComponent(filterField);

    HeaderCell levelFilterCell = filteringHeader.getCell("level");
    ComboBox levelFilter = new ComboBox();
    levelFilter.setWidth(8, Unit.EM);
    levelFilter.setNullSelectionAllowed(true);
    LogLevel[] levels = LogLevel.values();
    for (LogLevel logLevel : levels) {
        levelFilter.addItem(logLevel.name());
    }
    levelFilter.addValueChangeListener(change -> {
        logContainer.removeContainerFilters("level");
        String text = (String) levelFilter.getValue();
        if (isNotBlank(text)) {
            logContainer.addContainerFilter(new SimpleStringFilter("level", text, true, false));
        }
    });
    levelFilterCell.setComponent(levelFilter);

    levelFilter.addStyleName(ValoTheme.COMBOBOX_TINY);

    splitPanel = new VerticalSplitPanel();
    splitPanel.setFirstComponent(flowPanel);
    splitPanel.setSecondComponent(logTable);
    splitPanel.setSplitPosition(50f);
    splitPanel.setSizeFull();
    addComponent(splitPanel);
    setExpandRatio(splitPanel, 1.0f);

    showDiagramCheckbox.setValue(context.getUser().getBoolean(UserSetting.SETTING_SHOW_RUN_DIAGRAM, true));
    if (!showDiagramCheckbox.getValue()) {
        showDetails();
    }

    context.getBackgroundRefresherService().register(this);
}