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

public ComboBox() 

Source Link

Document

Constructs an empty combo box without a caption.

Usage

From source file:org.investovator.ui.utils.dashboard.dataplayback.BasicMainView.java

License:Open Source License

private Component setupBuySellForm() {
    VerticalLayout formContent = new VerticalLayout();

    FormLayout form = new FormLayout();

    //account balance
    this.accBalance = new Label("");
    this.accBalance.setCaption("Account Balance");

    //stocks list
    final ComboBox stocksList = new ComboBox();
    stocksList.setCaption("Stock");
    stocksList.setNullSelectionAllowed(false);
    for (String stock : DataPlaybackEngineStates.playingSymbols) {
        stocksList.addItem(stock);//from w  w  w  .j  a  v  a2  s.  c o m
    }
    //stocksList.setWidth("75%");

    //side
    final NativeSelect orderSide = new NativeSelect();
    orderSide.setCaption("Side");
    orderSide.addItem(OrderType.BUY);
    orderSide.addItem(OrderType.SELL);
    //orderSide.setWidth("90%");
    orderSide.setSizeFull();
    orderSide.select(OrderType.BUY);
    orderSide.setNullSelectionAllowed(false);
    orderSide.setImmediate(true);

    //Quantity
    final TextField quantity = new TextField("Amount");
    //quantity.setWidth("75%");

    form.addComponent(accBalance);
    form.addComponent(stocksList);
    form.addComponent(orderSide);
    form.addComponent(quantity);

    formContent.addComponent(form);

    HorizontalLayout bBar = getBuySellForumButtons(stocksList, quantity, orderSide);
    formContent.addComponent(bBar);
    formContent.setComponentAlignment(bBar, Alignment.BOTTOM_RIGHT);
    //content.setComponentAlignment(nextDayB, Alignment.MIDDLE_CENTER);

    return formContent;
}

From source file:org.investovator.ui.utils.dashboard.dataplayback.BasicStockDataView.java

License:Open Source License

private HorizontalLayout setUpTopBar() {
    HorizontalLayout components = new HorizontalLayout();
    components.setWidth("100%");

    HorizontalLayout addChartComponents = new HorizontalLayout();
    components.addComponent(addChartComponents);

    //create the stocks drop down list
    availableStocksList = new ComboBox();
    addChartComponents.addComponent(availableStocksList);
    availableStocksList.setImmediate(true);

    //        availableStocksList.setCaption("Stock");
    availableStocksList.setNullSelectionAllowed(false);
    for (String stock : DataPlaybackEngineStates.playingSymbols) {
        availableStocksList.addItem(stock);
    }//from w  w  w  .  java 2 s  . co  m
    availableStocksList.select(availableStocksList.getItemIds().toArray()[0]);

    //available attributes list
    availableDataItems = new NativeSelect();
    addChartComponents.addComponent(availableDataItems);
    //        availableDataItems.setCaption("Data: ");

    for (TradingDataAttribute attr : setSelectableAttributes()) {
        availableDataItems.addItem(attr);
    }
    availableDataItems.setNullSelectionAllowed(false);
    availableDataItems.select(availableDataItems.getItemIds().toArray()[0]);

    availableDataItems.setImmediate(true);

    //add chart button
    Button addChartButton = new Button("Add");
    addChartComponents.addComponent(addChartButton);
    addChartButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            addPlotToChart();
        }
    });

    //Remove charts section
    HorizontalLayout removeChartsComponents = new HorizontalLayout();
    components.addComponent(removeChartsComponents);

    //plotted charts list
    this.plottedItemsList = new ComboBox();
    removeChartsComponents.addComponent(this.plottedItemsList);
    this.plottedItemsList.setImmediate(true);
    //        this.plottedItemsList.setCaption("Drawn Charts");
    this.plottedItemsList.setNullSelectionAllowed(true);

    //remove plot button
    Button removeChartButton = new Button("Remove");
    removeChartsComponents.addComponent(removeChartButton);
    removeChartButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            removePlotFromChart();
        }
    });

    //clear all button
    Button clearAllButton = new Button("Clear All");
    removeChartsComponents.addComponent(clearAllButton);

    clearAllButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            clearTimeline();
        }
    });

    //set the alignments
    components.setComponentAlignment(addChartComponents, Alignment.MIDDLE_CENTER);
    components.setComponentAlignment(removeChartsComponents, Alignment.MIDDLE_CENTER);
    components.setHeight(50, Unit.PIXELS);

    return components;
}

From source file:org.investovator.ui.utils.dashboard.DecisionMakerPanel.java

License:Open Source License

/**
 * Sets up the basic components//from  ww  w .  ja  v a 2s  . c  o  m
 */
private void setUpUI() {
    ////section on indicator selection
    HorizontalLayout indicatorContainer = new HorizontalLayout();
    this.content.addComponent(indicatorContainer);
    //        this.content.setColumnExpandRatio(0,1);
    //        this.content.setColumnExpandRatio(1,1);

    Label indicatorName = new Label("Market Trend Indicator : ");
    indicatorContainer.addComponent(indicatorName);

    this.indicators = new ComboBox();
    indicatorContainer.addComponent(this.indicators);
    this.indicators.setNullSelectionAllowed(false);
    //add the indicators
    for (SigGenMAType type : SigGenMAType.values()) {
        this.indicators.addItem(type);
    }
    this.indicators.select(this.indicators.getItemIds().toArray()[0]);
    //add an event listener
    this.indicators.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            try {
                changeSignalGenerator();
            } catch (InvalidParamException e) {
                e.printStackTrace();
            }
        }
    });
    //create a signal generator
    try {
        changeSignalGenerator();
    } catch (InvalidParamException e) {
        e.printStackTrace();
    }
    ////

    //section on stocks table
    VerticalLayout tableContainer = new VerticalLayout();
    this.stockList = createStocksTable();
    tableContainer.addComponent(this.stockList);
    this.content.addComponent(tableContainer, 0, 1);
    ////

    //section on tool description
    CssLayout descriptionContainer = createPanel(getToolDescription());
    this.content.addComponent(descriptionContainer, 1, 0, 1, 1);

}

From source file:org.jdal.vaadin.ui.form.ComboBoxFieldBuilder.java

License:Apache License

/**
 * {@inheritDoc}//  w w w  . j  a v  a  2  s  . c o m
 */
public Field<?> build(Class<?> clazz, String name) {
    ComboBox combo = new ComboBox();
    fillComboBox(combo, clazz, name);
    combo.setItemCaptionMode(ItemCaptionMode.ID);

    return combo;
}

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);// ww w  .jav  a2  s .co  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 w  w.  j a  va2  s.  c om

    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.design.EditTransformerPanel.java

License:Open Source License

protected void buildUI() {
    ButtonBar buttonBar = new ButtonBar();
    addComponent(buttonBar);//from  ww  w.j a v a 2  s.c o  m

    filterPopField = new ComboBox();
    filterPopField.addItem(SHOW_ALL);
    filterPopField.addItem(SHOW_POPULATED_ENTITIES);
    filterPopField.addItem(SHOW_POPULATED_ATTRIBUTES);
    filterPopField.setNullSelectionAllowed(false);
    filterPopField.setImmediate(true);
    filterPopField.setWidth(20, Unit.EM);
    filterPopField.setValue(SHOW_ALL);
    filterPopField.addValueChangeListener(new ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            updateTable(filterField.getValue());
        }
    });
    buttonBar.addLeft(filterPopField);

    filterField = buttonBar.addFilter();
    filterField.addTextChangeListener(new TextChangeListener() {

        @Override
        public void textChange(TextChangeEvent event) {
            filterField.setValue(event.getText());
            updateTable(event.getText());
        }
    });

    addComponent(buttonBar);

    table.setContainerDataSource(container);

    table.setSelectable(true);
    table.setSortEnabled(false);
    table.setImmediate(true);
    table.setSortEnabled(true);
    table.setSizeFull();
    table.addGeneratedColumn("entityName", new ColumnGenerator() {

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            ComponentAttributeSetting setting = (ComponentAttributeSetting) itemId;
            Model model = component.getInputModel();
            ModelAttribute attribute = model.getAttributeById(setting.getAttributeId());
            ModelEntity entity = model.getEntityById(attribute.getEntityId());
            return UiUtils.getName(filterField.getValue(), entity.getName());
        }
    });
    table.addGeneratedColumn("attributeName", new ColumnGenerator() {

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            ComponentAttributeSetting setting = (ComponentAttributeSetting) itemId;
            Model model = component.getInputModel();
            ModelAttribute attribute = model.getAttributeById(setting.getAttributeId());
            return UiUtils.getName(filterField.getValue(), attribute.getName());
        }
    });
    table.setVisibleColumns(new Object[] { "entityName", "attributeName", "value" });
    table.setColumnWidth("entityName", 250);
    table.setColumnWidth("attributeName", 250);
    table.setColumnHeaders(new String[] { "Entity Name", "Attribute Name", "Transform" });
    table.setColumnExpandRatio("value", 1);
    table.setTableFieldFactory(new EditFieldFactory());
    table.setEditable(true);
    addComponent(table);
    setExpandRatio(table, 1.0f);

    if (component.getInputModel() != null) {

        componentAttributes = component.getAttributeSettings();

        List<ComponentAttributeSetting> toRemove = new ArrayList<ComponentAttributeSetting>();
        for (ComponentAttributeSetting componentAttribute : componentAttributes) {
            Model model = component.getInputModel();
            ModelAttribute attribute1 = model.getAttributeById(componentAttribute.getAttributeId());
            if (attribute1 == null) {
                /* invalid attribute.  model must have changed.  lets remove it */
                toRemove.add(componentAttribute);
            }
        }

        for (ComponentAttributeSetting componentAttributeSetting : toRemove) {
            componentAttributes.remove(componentAttributeSetting);
            context.getConfigurationService().delete(componentAttributeSetting);
        }

        for (ModelEntity entity : component.getInputModel().getModelEntities()) {
            for (ModelAttribute attr : entity.getModelAttributes()) {
                boolean found = false;
                for (ComponentAttributeSetting componentAttribute : componentAttributes) {
                    if (componentAttribute.getAttributeId().equals(attr.getId())
                            && componentAttribute.getName().equals(Transformer.TRANSFORM_EXPRESSION)) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    componentAttributes.add(new ComponentAttributeSetting(attr.getId(), component.getId(),
                            Transformer.TRANSFORM_EXPRESSION, null));
                }
            }
        }

        Collections.sort(componentAttributes, new Comparator<ComponentAttributeSetting>() {
            @Override
            public int compare(ComponentAttributeSetting o1, ComponentAttributeSetting o2) {
                Model model = component.getInputModel();
                ModelAttribute attribute1 = model.getAttributeById(o1.getAttributeId());
                ModelEntity entity1 = model.getEntityById(attribute1.getEntityId());

                ModelAttribute attribute2 = model.getAttributeById(o2.getAttributeId());
                ModelEntity entity2 = model.getEntityById(attribute2.getEntityId());

                int compare = entity1.getName().compareTo(entity2.getName());
                if (compare == 0) {
                    compare = attribute1.getName().compareTo(attribute2.getName());
                }
                return compare;
            }
        });
    }

    updateTable(null);

}

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

License:Open Source License

protected void buildUI() {
    ButtonBar buttonBar = new ButtonBar();
    addComponent(buttonBar);//w ww.j  a va2  s  .c  o  m

    Button editButton = buttonBar.addButton("Edit Template", FontAwesome.FILE_CODE_O);
    editButton.addClickListener(new EditTemplateClickListener());

    Button importButton = buttonBar.addButton("Import Template", FontAwesome.DOWNLOAD);
    importButton.addClickListener(new ImportTemplateClickListener());

    filterPopField = new ComboBox();
    filterPopField.addItem(SHOW_ALL);
    filterPopField.addItem(SHOW_POPULATED_ENTITIES);
    filterPopField.setNullSelectionAllowed(false);
    filterPopField.setImmediate(true);
    filterPopField.setValue(SHOW_ALL);
    filterPopField.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {
            updateTable(filterTextField.getValue(), filterPopField.getValue().equals(SHOW_POPULATED_ENTITIES));
        }
    });
    buttonBar.addRight(filterPopField);

    filterTextField = buttonBar.addFilter();
    filterTextField.addTextChangeListener(this);

    table.setContainerDataSource(container);
    table.setSelectable(true);
    table.setSortEnabled(false);
    table.setImmediate(true);
    table.setSizeFull();
    table.setVisibleColumns(new Object[] { "entityName", "attributeName", "xpath" });
    table.setColumnHeaders(new String[] { "Entity Name", "Attribute Name", "XPath" });
    table.setTableFieldFactory(new EditFieldFactory());
    table.setEditable(true);
    addComponent(table);
    setExpandRatio(table, 1.0f);

    updateTable(null, false);
    saveXPathSettings();
    buildXpathChoices();
}

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

License:Open Source License

protected void buildUI() {
    ButtonBar buttonBar = new ButtonBar();
    addComponent(buttonBar);// w w w  .j  av  a  2s  .  c om

    Button editButton = buttonBar.addButton("Edit Template", FontAwesome.FILE_CODE_O);
    editButton.addClickListener(new EditTemplateClickListener());

    Button importButton = buttonBar.addButton("Import Template", FontAwesome.DOWNLOAD);
    importButton.addClickListener(new ImportTemplateClickListener());

    filterPopField = new ComboBox();
    filterPopField.addItem(SHOW_ALL);
    filterPopField.addItem(SHOW_POPULATED_ENTITIES);
    filterPopField.setNullSelectionAllowed(false);
    filterPopField.setImmediate(true);
    filterPopField.setValue(SHOW_ALL);
    filterPopField.addValueChangeListener(new ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            updateTable(filterTextField.getValue(), filterPopField.getValue().equals(SHOW_POPULATED_ENTITIES));
        }
    });
    buttonBar.addRight(filterPopField);

    filterTextField = buttonBar.addFilter();
    filterTextField.addTextChangeListener(this);

    table.setContainerDataSource(container);
    table.setSelectable(true);
    table.setSortEnabled(false);
    table.setImmediate(true);
    table.setSizeFull();
    table.setVisibleColumns(new Object[] { "entityName", "attributeName", "xpath" });
    table.setColumnHeaders(new String[] { "Entity Name", "Attribute Name", "XPath" });
    table.setTableFieldFactory(new EditFieldFactory());
    table.setEditable(true);
    addComponent(table);
    setExpandRatio(table, 1.0f);

    updateTable(null, false);
    saveXPathSettings();
    buildXpathChoices();
}

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  w  ww  .  j a  v  a2  s .  co  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);
}