Example usage for com.vaadin.ui ComboBox ComboBox

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

Introduction

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

Prototype

protected ComboBox(DataCommunicator<T> dataCommunicator) 

Source Link

Document

Constructs and initializes an empty combo box.

Usage

From source file:org.jumpmind.metl.ui.views.admin.NotificationEditPanel.java

License:Open Source License

public NotificationEditPanel(final ApplicationContext context, final Notification notification) {
    this.context = context;
    this.notification = notification;

    sampleSubjectByEvent = new HashMap<String, String>();
    sampleSubjectByEvent.put(Notification.EventType.FLOW_START.toString(), "Flow $(_flowName) started");
    sampleSubjectByEvent.put(Notification.EventType.FLOW_END.toString(), "Flow $(_flowName) ended");
    sampleSubjectByEvent.put(Notification.EventType.FLOW_ERROR.toString(), "Flow $(_flowName) - ERROR");

    sampleMessageByEvent = new HashMap<String, String>();
    sampleMessageByEvent.put(Notification.EventType.FLOW_START.toString(),
            "Started flow $(_flowName) on agent $(_agentName) at $(_time) on $(_date)");
    sampleMessageByEvent.put(Notification.EventType.FLOW_END.toString(),
            "Ended flow $(_flowName) on agent $(_agent) at $(_time) on $(_date)");
    sampleMessageByEvent.put(Notification.EventType.FLOW_ERROR.toString(),
            "Error in flow $(_flowName) on agent $(_agentName) at $(_time) on $(_date)\n\n$(_errorText)");

    FormLayout form = new FormLayout();
    form.setSizeFull();//from   w ww . j  av  a2  s .  c o m
    form.setSpacing(true);

    levelField = new NativeSelect("Level");
    for (Notification.Level level : Notification.Level.values()) {
        levelField.addItem(level.toString());
    }
    levelField.setNullSelectionAllowed(false);
    levelField.setImmediate(true);
    levelField.setWidth(15f, Unit.EM);
    levelField.addValueChangeListener(new LevelFieldListener());
    form.addComponent(levelField);

    linkField = new ComboBox("Linked To");
    linkField.setNullSelectionAllowed(false);
    linkField.setImmediate(true);
    linkField.setWidth(15f, Unit.EM);
    linkField.addValueChangeListener(new LinkFieldListener());
    form.addComponent(linkField);

    eventField = new NativeSelect("Event");
    eventField.setNullSelectionAllowed(false);
    eventField.setImmediate(true);
    eventField.setWidth(15f, Unit.EM);
    eventField.addValueChangeListener(new EventFieldListener());
    form.addComponent(eventField);

    nameField = new ImmediateUpdateTextField("Name") {
        protected void save(String value) {
            notification.setName(value);
            saveNotification();
        }
    };
    nameField.setValue(StringUtils.trimToEmpty(notification.getName()));
    nameField.setWidth(20f, Unit.EM);
    nameField.setDescription("Display name for the notification");
    form.addComponent(nameField);

    ImmediateUpdateTextArea recipientsField = new ImmediateUpdateTextArea("Recipients") {
        protected void save(String value) {
            notification.setRecipients(value);
            saveNotification();
        }
    };
    recipientsField.setValue(StringUtils.trimToEmpty(notification.getRecipients()));
    recipientsField.setColumns(20);
    recipientsField.setRows(10);
    recipientsField.setInputPrompt("address1@example.com\r\naddress2@example.com");
    recipientsField.setDescription("Email addresses of recipients, separated by commas.");
    form.addComponent(recipientsField);

    subjectField = new ImmediateUpdateTextField("Subject") {
        protected void save(String value) {
            notification.setSubject(value);
            saveNotification();
        }
    };
    subjectField.setValue(StringUtils.trimToEmpty(notification.getSubject()));
    subjectField.setWidth(40f, Unit.EM);
    subjectField.setDescription("The subject of the email can contain...");
    form.addComponent(subjectField);

    messageField = new ImmediateUpdateTextArea("Message") {
        protected void save(String value) {
            notification.setMessage(value);
            saveNotification();
        }
    };
    messageField.setValue(StringUtils.trimToEmpty(notification.getMessage()));
    messageField.setColumns(40);
    messageField.setRows(10);
    messageField.setDescription("The body of the email can contain...");
    form.addComponent(messageField);

    CheckBox enableField = new CheckBox("Enabled", notification.isEnabled());
    enableField.setImmediate(true);
    enableField.addValueChangeListener(new ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            notification.setEnabled((Boolean) event.getProperty().getValue());
            saveNotification();
        }
    });
    form.addComponent(enableField);

    if (notification.getLevel() == null) {
        isInit = true;
        levelField.setValue(Notification.Level.GLOBAL.toString());
        notification.setLevel(Notification.Level.GLOBAL.toString());
        notification.setNotifyType(Notification.NotifyType.MAIL.toString());
        updateLinks();
        updateEventTypes();
        updateName();
    } else {
        levelField.setValue(notification.getLevel());
        updateLinks();
        updateEventTypes();
        linkField.setValue(notification.getLinkId());
        eventField.setValue(notification.getEventType());
        isInit = true;
    }

    addComponent(form);
    setMargin(true);
    autoSave = true;
}

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);// w w  w  . j av  a 2 s.  c o  m
    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.EditAgentDeploymentPanel.java

License:Open Source License

protected ComboBox getStartTypeComponent() {
    startTypeCombo = new ComboBox("Start Type");
    startTypeCombo.setWidth(200, Unit.PIXELS);
    startTypeCombo.setNullSelectionAllowed(false);
    StartType[] values = StartType.values();
    for (StartType value : values) {
        startTypeCombo.addItem(value.name());
    }/*from w ww .java2s. c om*/
    startTypeCombo.setValue(agentDeployment.getStartType());
    startTypeCombo.addValueChangeListener(new ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            agentDeployment.setStartType((String) startTypeCombo.getValue());
            updateScheduleEnable();
            for (int i = 0; i < 7; i++) {
                ListSelect listSelect = ((ListSelect) cronLayout.getComponent(i));
                for (Object itemId : listSelect.getItemIds()) {
                    listSelect.unselect(itemId);
                }
                listSelect.select(listSelect.getItemIds().iterator().next());
            }
            String startExpression = null;
            if (agentDeployment.getStartType().equals(StartType.SCHEDULED_CRON.name())) {
                startExpression = "0 0 0 * * ?";
            }
            startExpressionTextField.setValue(startExpression);
            agentDeployment.setStartExpression(startExpression);
            updateScheduleFields();
            saveAgentDeployment(agentDeployment);
        }
    });
    return startTypeCombo;
}

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);/*  w  w w.  j  a v a  2 s.  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.PropertySheet.java

License:Open Source License

protected void addOutputModelCombo(XMLComponent componentDefintion, FormLayout formLayout,
        final Component component) {
    FlowStep step = getSingleFlowStep();
    if (step != null) {
        String projectVersionId = step.getComponent().getProjectVersionId();
        if ((componentDefintion.getOutputMessageType() == MessageType.ENTITY
                || componentDefintion.getOutputMessageType() == MessageType.ANY)
                && !componentDefintion.isInputOutputModelsMatch()) {
            final AbstractSelect combo = new ComboBox("Output Model");
            combo.setImmediate(true);/*from w  ww.ja va  2s . co  m*/
            combo.setNullSelectionAllowed(true);
            List<ModelName> models = context.getConfigurationService().findModelsInProject(projectVersionId);
            if (models != null) {
                for (ModelName model : models) {
                    combo.addItem(model);
                    if (isNotBlank(component.getOutputModelId())
                            && component.getOutputModelId().equals(model.getId())) {
                        combo.setValue(model);
                    }
                }
            }
            combo.addValueChangeListener(new ValueChangeListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void valueChange(ValueChangeEvent event) {
                    ModelName model = (ModelName) combo.getValue();
                    if (model != null) {
                        component.setOutputModel(context.getConfigurationService().findModel(model.getId()));
                    } else {
                        component.setOutputModel(null);
                    }
                    context.getConfigurationService().save((AbstractObject) component);
                    setSource(value);
                }
            });
            combo.setReadOnly(readOnly);
            formLayout.addComponent(combo);
        }
    }
}

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

License:Open Source License

protected void addInputModelCombo(XMLComponent componentDefintion, FormLayout formLayout,
        final Component component) {
    FlowStep step = getSingleFlowStep();
    if (step != null) {
        String projectVersionId = step.getComponent().getProjectVersionId();
        if (componentDefintion.getInputMessageType() == MessageType.ENTITY
                || componentDefintion.getInputMessageType() == MessageType.ANY) {
            final AbstractSelect combo = new ComboBox("Input Model");
            combo.setImmediate(true);/*w  ww  .  j a  v  a2 s .c  o m*/
            combo.setNullSelectionAllowed(true);
            List<ModelName> models = context.getConfigurationService().findModelsInProject(projectVersionId);
            if (models != null) {
                for (ModelName model : models) {
                    combo.addItem(model);
                    if (isNotBlank(component.getInputModelId())
                            && component.getInputModelId().equals(model.getId())) {
                        combo.setValue(model);
                    }
                }
            }
            combo.addValueChangeListener(new ValueChangeListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void valueChange(ValueChangeEvent event) {
                    ModelName model = (ModelName) combo.getValue();
                    if (model != null) {
                        component.setInputModel(context.getConfigurationService().findModel(model.getId()));
                    } else {
                        component.setInputModel(null);
                    }
                    if (componentDefintion.isInputOutputModelsMatch()) {
                        component.setOutputModel(component.getInputModel());
                    }
                    context.getConfigurationService().save((AbstractObject) component);
                    setSource(value);
                }
            });
            combo.setReadOnly(readOnly);
            formLayout.addComponent(combo);
        }
    }
}

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

License:Open Source License

protected void addResourceCombo(XMLComponent componentDefintion, FormLayout formLayout,
        final Component component) {
    if (componentDefintion == null) {
        log.info("null kaboom " + component.getName() + " " + component.getType());
    }//from  ww  w  . jav  a 2 s . com
    FlowStep step = getSingleFlowStep();
    if (componentDefintion.getResourceCategory() != null
            && componentDefintion.getResourceCategory() != ResourceCategory.NONE && step != null) {
        final AbstractSelect resourcesCombo = new ComboBox("Resource");
        resourcesCombo.setImmediate(true);
        List<String> types = context.getResourceFactory()
                .getResourceTypes(componentDefintion.getResourceCategory());
        String projectVersionId = step.getComponent().getProjectVersionId();
        if (types != null) {
            List<Resource> resources = context.getConfigurationService().findResourcesByTypes(projectVersionId,
                    types.toArray(new String[types.size()]));
            if (resources != null) {
                for (Resource resource : resources) {
                    resourcesCombo.addItem(resource);
                }

                resourcesCombo.setValue(component.getResource());
            }
        }
        resourcesCombo.addValueChangeListener(new ValueChangeListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void valueChange(ValueChangeEvent event) {
                component.setResource((Resource) resourcesCombo.getValue());
                context.getConfigurationService().save(component);
            }
        });

        formLayout.addComponent(resourcesCombo);
    }
}

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

License:Open Source License

protected void addSettingField(final XMLSetting definition, final AbstractObjectWithSettings obj,
        FormLayout formLayout) {//from  w w w .ja  v a  2  s . co m
    boolean required = definition.isRequired();
    if (definition.isVisible()) {
        Component component = null;
        if (obj instanceof Component) {
            component = (Component) obj;
        }
        String description = definition.getDescription();
        Type type = definition.getType();
        FlowStep step = null;
        switch (type) {
        case BOOLEAN:
            final CheckBox checkBox = new CheckBox(definition.getName());
            checkBox.setImmediate(true);
            boolean defaultValue = false;
            if (isNotBlank(definition.getDefaultValue())) {
                defaultValue = Boolean.parseBoolean(definition.getDefaultValue());
            }
            checkBox.setValue(obj.getBoolean(definition.getId(), defaultValue));
            checkBox.setRequired(required);
            checkBox.setDescription(description);

            checkBox.addValueChangeListener(new ValueChangeListener() {

                private static final long serialVersionUID = 1L;

                @Override
                public void valueChange(ValueChangeEvent event) {
                    saveSetting(definition.getId(), checkBox.getValue().toString(), obj);
                    if (listener != null) {
                        List<Component> components = new ArrayList<Component>(1);
                        components.add((Component) obj);
                        listener.componentChanged(components);
                    }
                }
            });
            checkBox.setReadOnly(readOnly);
            formLayout.addComponent(checkBox);
            break;
        case CHOICE:
            final AbstractSelect choice = new ComboBox(definition.getName());
            choice.setImmediate(true);
            List<String> choices = definition.getChoices() != null ? definition.getChoices().getChoice()
                    : new ArrayList<String>(0);
            for (String c : choices) {
                choice.addItem(c);
            }
            choice.setValue(obj.get(definition.getId(), definition.getDefaultValue()));
            choice.setDescription(description);
            choice.setNullSelectionAllowed(false);
            choice.addValueChangeListener(new ValueChangeListener() {

                private static final long serialVersionUID = 1L;

                @Override
                public void valueChange(ValueChangeEvent event) {
                    saveSetting(definition.getId(), (String) choice.getValue(), obj);
                }
            });
            choice.setReadOnly(readOnly);
            formLayout.addComponent(choice);
            break;
        case PASSWORD:
            ImmediateUpdatePasswordField passwordField = new ImmediateUpdatePasswordField(
                    definition.getName()) {
                private static final long serialVersionUID = 1L;

                protected void save(String text) {
                    saveSetting(definition.getId(), text, obj);
                };
            };
            passwordField.setValue(obj.get(definition.getId(), definition.getDefaultValue()));
            passwordField.setRequired(required);
            passwordField.setDescription(description);
            passwordField.setReadOnly(readOnly);
            formLayout.addComponent(passwordField);
            break;
        case INTEGER:
            ImmediateUpdateTextField integerField = new ImmediateUpdateTextField(definition.getName()) {
                private static final long serialVersionUID = 1L;

                protected void save(String text) {
                    saveSetting(definition.getId(), text, obj);
                };
            };
            integerField.setConverter(Integer.class);
            integerField.setValue(obj.get(definition.getId(), definition.getDefaultValue()));
            integerField.setRequired(required);
            integerField.setDescription(description);
            integerField.setReadOnly(readOnly);
            formLayout.addComponent(integerField);
            break;
        case TEXT:
            ImmediateUpdateTextField textField = new ImmediateUpdateTextField(definition.getName()) {
                private static final long serialVersionUID = 1L;

                protected void save(String text) {
                    saveSetting(definition.getId(), text, obj);
                };
            };
            textField.setValue(obj.get(definition.getId(), definition.getDefaultValue()));
            textField.setRequired(required);
            textField.setDescription(description);
            textField.setReadOnly(readOnly);
            formLayout.addComponent(textField);
            break;
        case SOURCE_STEP:
            step = getSingleFlowStep();
            if (step != null) {
                Flow flow = context.getConfigurationService().findFlow(step.getFlowId());
                final AbstractSelect sourceStepsCombo = new ComboBox(definition.getName());
                sourceStepsCombo.setImmediate(true);

                List<FlowStepLink> sourceSteps = flow.findFlowStepLinksWithTarget(step.getId());
                for (FlowStepLink flowStepLink : sourceSteps) {
                    FlowStep sourceStep = flow.findFlowStepWithId(flowStepLink.getSourceStepId());
                    sourceStepsCombo.addItem(sourceStep.getId());
                    sourceStepsCombo.setItemCaption(sourceStep.getId(), sourceStep.getName());
                }
                sourceStepsCombo.setValue(obj.get(definition.getId()));
                sourceStepsCombo.setDescription(description);
                sourceStepsCombo.setNullSelectionAllowed(false);
                sourceStepsCombo.addValueChangeListener(new ValueChangeListener() {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void valueChange(ValueChangeEvent event) {
                        saveSetting(definition.getId(), (String) sourceStepsCombo.getValue(), obj);
                    }
                });
                sourceStepsCombo.setReadOnly(readOnly);
                formLayout.addComponent(sourceStepsCombo);
            }
            break;
        case FLOW:
            step = getSingleFlowStep();
            if (step != null) {
                String projectVersionId = step.getComponent().getProjectVersionId();
                List<FlowName> flows = context.getConfigurationService().findFlowsInProject(projectVersionId,
                        false);
                final AbstractSelect combo = new ComboBox(definition.getName());
                combo.setImmediate(true);
                for (FlowName name : flows) {
                    if (!step.getFlowId().equals(name.getId())) {
                        combo.addItem(name.getId());
                        combo.setItemCaption(name.getId(), name.getName());
                    }
                }
                combo.setValue(obj.get(definition.getId()));
                combo.setDescription(description);
                combo.setNullSelectionAllowed(false);
                combo.addValueChangeListener(new ValueChangeListener() {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void valueChange(ValueChangeEvent event) {
                        saveSetting(definition.getId(), (String) combo.getValue(), obj);
                    }
                });
                combo.setReadOnly(readOnly);
                formLayout.addComponent(combo);
            }
            break;
        case STREAMABLE_RESOURCE:
            formLayout.addComponent(createResourceCombo(definition, obj, ResourceCategory.STREAMABLE));
            break;
        case DATASOURCE_RESOURCE:
            formLayout.addComponent(createResourceCombo(definition, obj, ResourceCategory.DATASOURCE));
            break;
        case ENTITY_COLUMN:
            if (component != null) {
                List<ModelEntity> entities = new ArrayList<ModelEntity>();
                Model model = component.getInputModel();
                if (model != null) {
                    model.sortAttributes();
                    entities.addAll(model.getModelEntities());
                }
                model = component.getOutputModel();
                if (model != null) {
                    model.sortAttributes();
                    entities.addAll(model.getModelEntities());
                }
                AbstractObjectNameBasedSorter.sort(entities);

                final AbstractSelect entityColumnCombo = new ComboBox(definition.getName());
                entityColumnCombo.setImmediate(true);

                for (ModelEntity modelEntity : entities) {
                    for (ModelAttribute attribute : modelEntity.getModelAttributes()) {
                        entityColumnCombo.addItem(attribute.getId());
                        entityColumnCombo.setItemCaption(attribute.getId(),
                                modelEntity.getName() + "." + attribute.getName());
                    }
                }
                String currentValue = obj.get(definition.getId());
                if (currentValue != null) {
                    entityColumnCombo.setValue(obj.get(definition.getId()));
                }
                entityColumnCombo.setDescription(description);
                entityColumnCombo.setNullSelectionAllowed(definition.isRequired());
                entityColumnCombo.addValueChangeListener(new ValueChangeListener() {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void valueChange(ValueChangeEvent event) {
                        saveSetting(definition.getId(), (String) entityColumnCombo.getValue(), obj);
                    }
                });
                entityColumnCombo.setReadOnly(readOnly);
                formLayout.addComponent(entityColumnCombo);
            }
            break;
        case SCRIPT:
            final AceEditor editor = CommonUiUtils.createAceEditor();
            editor.setTextChangeEventMode(TextChangeEventMode.LAZY);
            editor.setTextChangeTimeout(200);
            editor.setMode(AceMode.java);
            editor.setHeight(10, Unit.EM);
            editor.setCaption(definition.getName());
            editor.setShowGutter(false);
            editor.setShowPrintMargin(false);
            editor.setValue(obj.get(definition.getId(), definition.getDefaultValue()));
            editor.addTextChangeListener(new TextChangeListener() {
                @Override
                public void textChange(TextChangeEvent event) {
                    Setting data = obj.findSetting(definition.getId());
                    data.setValue(event.getText());
                    context.getConfigurationService().save(data);
                }
            });
            editor.setReadOnly(readOnly);
            formLayout.addComponent(editor);
            break;
        case MULTILINE_TEXT:
        case XML:
            ImmediateUpdateTextArea area = new ImmediateUpdateTextArea(definition.getName()) {
                private static final long serialVersionUID = 1L;

                protected void save(String text) {
                    saveSetting(definition.getId(), text, obj);
                };
            };
            area.setValue(obj.get(definition.getId(), definition.getDefaultValue()));
            area.setRows(5);
            area.setRequired(required);
            area.setDescription(description);
            area.setReadOnly(readOnly);
            formLayout.addComponent(area);
            break;
        default:
            break;

        }
    }
}

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

License:Open Source License

protected AbstractSelect createResourceCombo(XMLSetting definition, AbstractObjectWithSettings obj,
        ResourceCategory category) {//w  w  w.  j  av a 2  s.com
    FlowStep step = getSingleFlowStep();
    String projectVersionId = step.getComponent().getProjectVersionId();
    final AbstractSelect combo = new ComboBox(definition.getName());
    combo.setImmediate(true);
    combo.setDescription(definition.getDescription());
    combo.setNullSelectionAllowed(false);
    List<String> types = context.getResourceFactory().getResourceTypes(category);
    if (types != null) {
        List<Resource> resources = context.getConfigurationService().findResourcesByTypes(projectVersionId,
                types.toArray(new String[types.size()]));
        if (resources != null) {
            for (Resource resource : resources) {
                combo.addItem(resource.getId());
                combo.setItemCaption(resource.getId(), resource.getName());
            }

            combo.setValue(obj.get(definition.getId()));
        }
    }
    combo.addValueChangeListener(event -> saveSetting(definition.getId(), (String) combo.getValue(), obj));
    combo.setReadOnly(readOnly);
    return combo;
}

From source file:org.jumpmind.metl.ui.views.ManageView.java

License:Open Source License

@SuppressWarnings("serial")
@PostConstruct//from w ww . j ava2s  .co m
protected void init() {
    viewButton = new Button("View Log");
    viewButton.setEnabled(false);
    viewButton.addClickListener(new ClickListener() {
        public void buttonClick(ClickEvent event) {
            viewLog(table.getValue());
        }
    });

    VerticalLayout mainTab = new VerticalLayout();
    mainTab.setSizeFull();
    HorizontalLayout header = new HorizontalLayout();
    header.addComponent(viewButton);
    header.setComponentAlignment(viewButton, Alignment.BOTTOM_RIGHT);

    statusSelect = new ComboBox("Status");
    statusSelect.setNewItemsAllowed(false);
    statusSelect.setNullSelectionAllowed(false);
    statusSelect.addItem(ANY);
    statusSelect.setValue(ANY);
    for (ExecutionStatus status : ExecutionStatus.values()) {
        statusSelect.addItem(status.toString());
    }
    ;
    statusSelect.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(ValueChangeEvent event) {
            refreshUI(getBackgroundData());
        }
    });
    header.addComponent(statusSelect);
    header.setComponentAlignment(statusSelect, Alignment.BOTTOM_RIGHT);

    HorizontalLayout limitLayout = new HorizontalLayout();
    limitLayout.setSpacing(true);
    Label limitLabel = new Label("Limit:");
    limitLayout.addComponent(limitLabel);
    limitLayout.setComponentAlignment(limitLabel, Alignment.MIDDLE_CENTER);
    TextField limitField = new TextField(null, String.valueOf(DEFAULT_LIMIT));
    limitField.setWidth("5em");
    limitField.setImmediate(true);
    limitField.setTextChangeEventMode(TextChangeEventMode.LAZY);
    limitField.setTextChangeTimeout(200);
    limitField.addTextChangeListener(new TextChangeListener() {
        public void textChange(TextChangeEvent event) {
            try {
                limit = Integer.parseInt(event.getText());
            } catch (Exception e) {
            }
            refreshUI(getBackgroundData());
        }
    });
    limitLayout.addComponent(limitField);
    limitLayout.setComponentAlignment(limitField, Alignment.BOTTOM_RIGHT);
    header.addComponent(limitLayout);
    header.setComponentAlignment(limitLayout, Alignment.BOTTOM_RIGHT);
    header.setExpandRatio(limitLayout, 1.0f);

    TextField filterField = new TextField();
    filterField.setInputPrompt("Filter");
    filterField.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);
    filterField.setIcon(FontAwesome.SEARCH);
    filterField.setImmediate(true);
    filterField.setTextChangeEventMode(TextChangeEventMode.LAZY);
    filterField.setTextChangeTimeout(200);
    filterField.addTextChangeListener(new TextChangeListener() {
        public void textChange(TextChangeEvent event) {
            executionContainer.removeAllContainerFilters();
            if (!StringUtils.isBlank(event.getText())) {
                executionContainer.addContainerFilter(new MultiPropertyFilter(event.getText(), new String[] {
                        "agentName", "hostName", "flowName", "status", "startTime", "endTime" }));
            }
        }
    });
    header.addComponent(filterField);
    header.setComponentAlignment(filterField, Alignment.BOTTOM_RIGHT);

    header.setSpacing(true);
    header.setMargin(true);
    header.setWidth("100%");
    mainTab.addComponent(header);

    table = new Table();
    table.setContainerDataSource(executionContainer);
    table.setSelectable(true);
    table.setMultiSelect(false);
    table.setSizeFull();
    table.addItemClickListener(new ItemClickListener() {
        @Override
        public void itemClick(ItemClickEvent event) {
            if (event.isDoubleClick()) {
                viewLog(event.getItemId());
            }
        }
    });
    table.setVisibleColumns(
            new Object[] { "agentName", "deploymentName", "hostName", "status", "startTime", "endTime" });
    table.setColumnHeaders(new String[] { "Agent", "Deployment", "Host", "Status", "Start", "End" });
    table.setSortContainerPropertyId("startTime");
    table.setSortAscending(false);
    table.addValueChangeListener(new ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            viewButton.setEnabled(table.getValue() != null);
        }
    });
    mainTab.addComponent(table);
    mainTab.setExpandRatio(table, 1.0f);

    tabs = new TabbedPanel();
    tabs.setMainTab("Executions", Icons.EXECUTION, mainTab);

    HorizontalSplitPanel split = new HorizontalSplitPanel();
    split.setSizeFull();
    split.setSplitPosition(AppConstants.DEFAULT_LEFT_SPLIT, Unit.PIXELS, false);

    manageNavigator = new ManageNavigator(FolderType.AGENT, context);
    manageNavigator.addValueChangeListener(new ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            refreshUI(getBackgroundData());
        }
    });
    split.setFirstComponent(manageNavigator);

    VerticalLayout container = new VerticalLayout();
    container.setSizeFull();
    container.addComponent(tabs);
    split.setSecondComponent(container);

    addComponent(split);
    setSizeFull();
    context.getBackgroundRefresherService().register(this);
}