List of usage examples for com.vaadin.ui TextField setValue
@Override public void setValue(String value)
From source file:org.opennms.features.vaadin.surveillanceviews.ui.SurveillanceViewConfigurationCategoryWindow.java
License:Open Source License
/** * The constructor for instantiating this component. * * @param surveillanceViewService the surveillance view service to be used. * @param defs the column/row defs * @param def the def to be edited * @param saveActionListener the listener for the saving action *//* ww w . j a v a 2 s . c o m*/ public SurveillanceViewConfigurationCategoryWindow(final SurveillanceViewService surveillanceViewService, final Collection<?> defs, final Def def, final SaveActionListener saveActionListener) { /** * calling the super constructor */ super("Window title"); /** * Check whether this dialog is for a column or row and alter the window title */ if (def instanceof RowDef) { super.setCaption("Row definition"); } else { super.setCaption("Column definition"); } /** * Setting the modal and size properties */ setModal(true); setClosable(false); setResizable(false); setWidth(30, Sizeable.Unit.PERCENTAGE); setHeight(400, Unit.PIXELS); /** * Title and refresh seconds */ final TextField labelField = new TextField(); labelField.setValue(def.getLabel()); labelField.setImmediate(true); labelField.setCaption("Label"); labelField.setDescription("Label of this category"); labelField.setWidth(100, Unit.PERCENTAGE); /** * Creating a simple validator for the title field */ labelField.addValidator( new AbstractStringValidator("Please use an unique name for this column/row definition") { @Override protected boolean isValidValue(String s) { if ("".equals(s.trim())) { return false; } /** * check if the name clashes with other defs */ for (Def defx : (Collection<Def>) defs) { if (defx.getLabel().equals(s)) { if (defx != def) { return false; } } } return true; } }); /** * Categories table */ final Table categoriesTable = new Table(); categoriesTable.setSizeFull(); categoriesTable.setHeight(250.0f, Unit.PIXELS); categoriesTable.setCaption("Categories"); categoriesTable.setSortEnabled(true); categoriesTable.addContainerProperty("name", String.class, ""); categoriesTable.setColumnHeader("name", "Category"); categoriesTable.setColumnExpandRatio("Category", 1.0f); categoriesTable.setSelectable(true); categoriesTable.setMultiSelect(true); final List<OnmsCategory> categories = surveillanceViewService.getOnmsCategories(); final Map<Integer, OnmsCategory> categoriesMap = new HashMap<>(); for (OnmsCategory onmsCategory : categories) { categoriesTable.addItem(new Object[] { onmsCategory.getName() }, onmsCategory.getId()); categoriesMap.put(onmsCategory.getId(), onmsCategory); if (def.containsCategory(onmsCategory.getName())) { categoriesTable.select(onmsCategory.getId()); } } /** * Create form layouts... */ FormLayout baseFormLayout = new FormLayout(); baseFormLayout.setSizeFull(); baseFormLayout.setMargin(true); baseFormLayout.addComponent(labelField); baseFormLayout.addComponent(categoriesTable); /** * Creating the vertical layout... */ VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setSizeFull(); verticalLayout.addComponent(baseFormLayout); verticalLayout.setExpandRatio(baseFormLayout, 1.0f); /** * Using an additional {@link com.vaadin.ui.HorizontalLayout} for layouting the buttons */ HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setMargin(true); horizontalLayout.setSpacing(true); horizontalLayout.setWidth(100, Unit.PERCENTAGE); /** * Adding the cancel button... */ Button cancel = new Button("Cancel"); cancel.setDescription("Cancel editing properties"); cancel.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { close(); } }); cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); horizontalLayout.addComponent(cancel); horizontalLayout.setExpandRatio(cancel, 1); horizontalLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT); /** * ...and the OK button */ Button ok = new Button("Save"); ok.setDescription("Save properties and close"); ok.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { Def finalDef = null; if (def instanceof RowDef) { finalDef = new RowDef(); } if (def instanceof ColumnDef) { finalDef = new ColumnDef(); } Set<Object> categories = (Set<Object>) categoriesTable.getValue(); if (!labelField.isValid()) { ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error", "Please use an unique label for this category", Notification.Type.ERROR_MESSAGE); return; } if (categories.isEmpty()) { ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error", "You must choose at least one surveillance category", Notification.Type.ERROR_MESSAGE); return; } for (Object object : categories) { Category category = new Category(); category.setName(categoriesMap.get(object).getName()); finalDef.getCategories().add(category); } finalDef.setLabel(labelField.getValue()); saveActionListener.save(finalDef); close(); } }); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); horizontalLayout.addComponent(ok); verticalLayout.addComponent(horizontalLayout); setContent(verticalLayout); }
From source file:org.opennms.features.vaadin.surveillanceviews.ui.SurveillanceViewConfigurationWindow.java
License:Open Source License
/** * The constructor for instantiating this component. * * @param surveillanceViewService the surveillance view service to be used * @param view the view to edit * @param saveActionListener the save action listener *//*from w ww.j av a 2s . c o m*/ public SurveillanceViewConfigurationWindow(final SurveillanceViewService surveillanceViewService, final View view, final SaveActionListener saveActionListener) { /** * Setting the title */ super("Surveillance view configuration"); /** * Setting the modal and size properties */ setModal(true); setClosable(false); setResizable(false); setWidth(80, Sizeable.Unit.PERCENTAGE); setHeight(75, Sizeable.Unit.PERCENTAGE); /** * Title field */ final TextField titleField = new TextField(); titleField.setValue(view.getName()); titleField.setImmediate(true); titleField.setCaption("Title"); titleField.setDescription("Title of this surveillance view"); titleField.setWidth(25, Unit.PERCENTAGE); /** * Adding simple validator */ titleField.addValidator(new AbstractStringValidator("Please use an unique name for the surveillance view") { @Override protected boolean isValidValue(String string) { if ("".equals(string.trim())) { return false; } if (SurveillanceViewProvider.getInstance().containsView(string) && !view.getName().equals(string)) { return false; } return true; } }); /** * Refresh seconds field setup and validator */ final TextField refreshSecondsField = new TextField(); refreshSecondsField.setValue(String.valueOf(view.getRefreshSeconds())); refreshSecondsField.setImmediate(true); refreshSecondsField.setCaption("Refresh seconds"); refreshSecondsField.setDescription("Refresh duration in seconds"); refreshSecondsField.addValidator(new AbstractStringValidator("Only numbers allowed here") { @Override protected boolean isValidValue(String s) { int number; try { number = Integer.parseInt(s); } catch (NumberFormatException numberFormatException) { return false; } return (number >= 0); } }); /** * Columns table */ final Table columnsTable = new Table(); columnsTable.setSortEnabled(false); columnsTable.setWidth(25, Unit.PERCENTAGE); final BeanItemContainer<ColumnDef> columns = new BeanItemContainer<ColumnDef>(ColumnDef.class, view.getColumns()); final Map<ColumnDef, Integer> columnOrder = new HashMap<>(); int c = 0; for (ColumnDef columnDef : view.getColumns()) { columnOrder.put(columnDef, c++); } columnsTable.setContainerDataSource(columns); columnsTable.setVisibleColumns("label"); columnsTable.setColumnHeader("label", "Columns"); columnsTable.setColumnExpandRatio("label", 1.0f); columnsTable.setSelectable(true); columnsTable.setMultiSelect(false); /** * Create custom sorter */ columns.setItemSorter(new DefaultItemSorter() { @Override public int compare(Object o1, Object o2) { if (o1 == null) { if (o2 == null) { return 0; } else { return -1; } } if (o2 == null) { return 1; } if (columnOrder.get(o1).intValue() == columnOrder.get(o2).intValue()) { return 0; } else { if (columnOrder.get(o1).intValue() > columnOrder.get(o2).intValue()) { return 1; } else { return -1; } } } }); /** * Adding the buttons... */ final Button columnsAddButton = new Button("Add"); columnsAddButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService, columnsTable.getItemIds(), new ColumnDef(), new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() { @Override public void save(Def def) { columns.addItem((ColumnDef) def); columnOrder.put((ColumnDef) def, columnOrder.size()); columns.sort(new Object[] { "label" }, new boolean[] { true }); columnsTable.refreshRowCache(); } })); } }); columnsAddButton.setEnabled(true); columnsAddButton.setStyleName("small"); columnsAddButton.setDescription("Add column"); columnsAddButton.setEnabled(true); final Button columnsEditButton = new Button("Edit"); columnsEditButton.setEnabled(true); columnsEditButton.setStyleName("small"); columnsEditButton.setDescription("Edit column"); columnsEditButton.setEnabled(false); columnsEditButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService, columnsTable.getItemIds(), (ColumnDef) columnsTable.getValue(), new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() { @Override public void save(Def def) { ColumnDef columnToBeReplaced = (ColumnDef) columnsTable.getValue(); int index = columnOrder.get(columnToBeReplaced); columns.removeItem(columnToBeReplaced); columnOrder.remove(columnToBeReplaced); columns.addItem((ColumnDef) def); columnOrder.put((ColumnDef) def, index); columns.sort(new Object[] { "label" }, new boolean[] { true }); columnsTable.refreshRowCache(); } })); } }); final Button columnsRemoveButton = new Button("Remove"); columnsRemoveButton.setEnabled(true); columnsRemoveButton.setStyleName("small"); columnsRemoveButton.setDescription("Remove column"); columnsRemoveButton.setEnabled(false); columnsRemoveButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { ColumnDef columnDef = (ColumnDef) columnsTable.getValue(); if (columnDef != null) { columnsTable.unselect(columnDef); columns.removeItem(columnDef); } columnsTable.refreshRowCache(); } }); final Button columnUpButton = new Button(); columnUpButton.setStyleName("small"); columnUpButton.setIcon(new ThemeResource("../runo/icons/16/arrow-up.png")); columnUpButton.setDescription("Move this a column entry one position up"); columnUpButton.setEnabled(false); columnUpButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { ColumnDef columnDef = (ColumnDef) columnsTable.getValue(); if (columnDef != null) { int columnDefIndex = columnOrder.get(columnDef); ColumnDef columnDefToSwap = null; for (Map.Entry<ColumnDef, Integer> entry : columnOrder.entrySet()) { if (entry.getValue().intValue() == columnDefIndex - 1) { columnDefToSwap = entry.getKey(); break; } } if (columnDefToSwap != null) { columnsTable.unselect(columnDef); columnOrder.remove(columnDef); columnOrder.remove(columnDefToSwap); columnOrder.put(columnDef, columnDefIndex - 1); columnOrder.put(columnDefToSwap, columnDefIndex); columns.sort(new Object[] { "label" }, new boolean[] { true }); columnsTable.refreshRowCache(); columnsTable.select(columnDef); } } } }); final Button columnDownButton = new Button(); columnDownButton.setStyleName("small"); columnDownButton.setIcon(new ThemeResource("../runo/icons/16/arrow-down.png")); columnDownButton.setDescription("Move this a column entry one position down"); columnDownButton.setEnabled(false); columnDownButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { ColumnDef columnDef = (ColumnDef) columnsTable.getValue(); if (columnDef != null) { int columnDefIndex = columnOrder.get(columnDef); ColumnDef columnDefToSwap = null; for (Map.Entry<ColumnDef, Integer> entry : columnOrder.entrySet()) { if (entry.getValue().intValue() == columnDefIndex + 1) { columnDefToSwap = entry.getKey(); break; } } if (columnDefToSwap != null) { columnsTable.unselect(columnDef); columnOrder.remove(columnDef); columnOrder.remove(columnDefToSwap); columnOrder.put(columnDef, columnDefIndex + 1); columnOrder.put(columnDefToSwap, columnDefIndex); columns.sort(new Object[] { "label" }, new boolean[] { true }); columnsTable.refreshRowCache(); columnsTable.select(columnDef); } } } }); columnsTable.setSizeFull(); columnUpButton.setSizeFull(); columnDownButton.setSizeFull(); columnsAddButton.setSizeFull(); columnsEditButton.setSizeFull(); columnsRemoveButton.setSizeFull(); columnsTable.setImmediate(true); /** * ...and a listener */ columnsTable.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { boolean somethingSelected = (columnsTable.getValue() != null); columnsRemoveButton.setEnabled(somethingSelected); columnsEditButton.setEnabled(somethingSelected); columnsAddButton.setEnabled(true); columnUpButton .setEnabled(somethingSelected && columnOrder.get(columnsTable.getValue()).intValue() > 0); columnDownButton.setEnabled(somethingSelected && columnOrder.get(columnsTable.getValue()).intValue() < columnOrder.size() - 1); } }); /** * Rows table */ final Table rowsTable = new Table(); rowsTable.setSortEnabled(false); rowsTable.setWidth(25, Unit.PERCENTAGE); final BeanItemContainer<RowDef> rows = new BeanItemContainer<RowDef>(RowDef.class, view.getRows()); final Map<RowDef, Integer> rowOrder = new HashMap<>(); int r = 0; for (RowDef rowDef : view.getRows()) { rowOrder.put(rowDef, r++); } rowsTable.setContainerDataSource(rows); rowsTable.setVisibleColumns("label"); rowsTable.setColumnHeader("label", "Rows"); rowsTable.setColumnExpandRatio("label", 1.0f); rowsTable.setSelectable(true); rowsTable.setMultiSelect(false); /** * Create custom sorter */ rows.setItemSorter(new DefaultItemSorter() { @Override public int compare(Object o1, Object o2) { if (o1 == null) { if (o2 == null) { return 0; } else { return -1; } } if (o2 == null) { return 1; } if (rowOrder.get(o1).intValue() == rowOrder.get(o2).intValue()) { return 0; } else { if (rowOrder.get(o1).intValue() > rowOrder.get(o2).intValue()) { return 1; } else { return -1; } } } }); /** * Adding the buttons... */ final Button rowsAddButton = new Button("Add"); rowsAddButton.setEnabled(true); rowsAddButton.setStyleName("small"); rowsAddButton.setDescription("Add row"); rowsAddButton.setEnabled(true); rowsAddButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService, rowsTable.getItemIds(), new RowDef(), new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() { @Override public void save(Def def) { rows.addItem((RowDef) def); rowOrder.put((RowDef) def, rowOrder.size()); rows.sort(new Object[] { "label" }, new boolean[] { true }); rowsTable.refreshRowCache(); } })); } }); final Button rowsEditButton = new Button("Edit"); rowsEditButton.setEnabled(true); rowsEditButton.setStyleName("small"); rowsEditButton.setDescription("Edit row"); rowsEditButton.setEnabled(false); rowsEditButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService, rowsTable.getItemIds(), (RowDef) rowsTable.getValue(), new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() { @Override public void save(Def def) { RowDef rowToBeReplaced = (RowDef) rowsTable.getValue(); int index = rowOrder.get(rowToBeReplaced); rows.removeItem(rowToBeReplaced); rowOrder.remove(rowToBeReplaced); rows.addItem((RowDef) def); rowOrder.put((RowDef) def, index); rows.sort(new Object[] { "label" }, new boolean[] { true }); rowsTable.refreshRowCache(); } })); } }); final Button rowsRemoveButton = new Button("Remove"); rowsRemoveButton.setEnabled(true); rowsRemoveButton.setStyleName("small"); rowsRemoveButton.setDescription("Remove row"); rowsRemoveButton.setEnabled(false); rowsRemoveButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { RowDef rowDef = (RowDef) rowsTable.getValue(); if (rowDef != null) { rowsTable.unselect(rowDef); rows.removeItem(rowDef); } rowsTable.refreshRowCache(); } }); final Button rowUpButton = new Button(); rowUpButton.setStyleName("small"); rowUpButton.setIcon(new ThemeResource("../runo/icons/16/arrow-up.png")); rowUpButton.setDescription("Move this a row entry one position up"); rowUpButton.setEnabled(false); rowUpButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { RowDef rowDef = (RowDef) rowsTable.getValue(); if (rowDef != null) { int rowDefIndex = rowOrder.get(rowDef); RowDef rowDefToSwap = null; for (Map.Entry<RowDef, Integer> entry : rowOrder.entrySet()) { if (entry.getValue().intValue() == rowDefIndex - 1) { rowDefToSwap = entry.getKey(); break; } } if (rowDefToSwap != null) { rowsTable.unselect(rowDef); rowOrder.remove(rowDef); rowOrder.remove(rowDefToSwap); rowOrder.put(rowDef, rowDefIndex - 1); rowOrder.put(rowDefToSwap, rowDefIndex); rows.sort(new Object[] { "label" }, new boolean[] { true }); rowsTable.refreshRowCache(); rowsTable.select(rowDef); } } } }); final Button rowDownButton = new Button(); rowDownButton.setStyleName("small"); rowDownButton.setIcon(new ThemeResource("../runo/icons/16/arrow-down.png")); rowDownButton.setDescription("Move this a row entry one position down"); rowDownButton.setEnabled(false); rowDownButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { RowDef rowDef = (RowDef) rowsTable.getValue(); if (rowDef != null) { int rowDefIndex = rowOrder.get(rowDef); RowDef rowDefToSwap = null; for (Map.Entry<RowDef, Integer> entry : rowOrder.entrySet()) { if (entry.getValue().intValue() == rowDefIndex + 1) { rowDefToSwap = entry.getKey(); break; } } if (rowDefToSwap != null) { rowsTable.unselect(rowDef); rowOrder.remove(rowDef); rowOrder.remove(rowDefToSwap); rowOrder.put(rowDef, rowDefIndex + 1); rowOrder.put(rowDefToSwap, rowDefIndex); rows.sort(new Object[] { "label" }, new boolean[] { true }); rowsTable.refreshRowCache(); rowsTable.select(rowDef); } } } }); rowsTable.setSizeFull(); rowUpButton.setSizeFull(); rowDownButton.setSizeFull(); rowsAddButton.setSizeFull(); rowsEditButton.setSizeFull(); rowsRemoveButton.setSizeFull(); rowsTable.setImmediate(true); /** * ...and a listener */ rowsTable.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { boolean somethingSelected = (rowsTable.getValue() != null); rowsRemoveButton.setEnabled(somethingSelected); rowsEditButton.setEnabled(somethingSelected); rowsAddButton.setEnabled(true); rowUpButton.setEnabled(somethingSelected && rowOrder.get(rowsTable.getValue()).intValue() > 0); rowDownButton.setEnabled( somethingSelected && rowOrder.get(rowsTable.getValue()).intValue() < rowOrder.size() - 1); } }); /** * Create form layouts... */ FormLayout baseFormLayout = new FormLayout(); baseFormLayout.addComponent(titleField); baseFormLayout.addComponent(refreshSecondsField); FormLayout columnTableFormLayout = new FormLayout(); columnTableFormLayout.addComponent(columnsAddButton); columnTableFormLayout.addComponent(columnsEditButton); columnTableFormLayout.addComponent(columnsRemoveButton); columnTableFormLayout.addComponent(columnUpButton); columnTableFormLayout.addComponent(columnDownButton); FormLayout rowTableFormLayout = new FormLayout(); rowTableFormLayout.addComponent(rowsAddButton); rowTableFormLayout.addComponent(rowsEditButton); rowTableFormLayout.addComponent(rowsRemoveButton); rowTableFormLayout.addComponent(rowUpButton); rowTableFormLayout.addComponent(rowDownButton); /** * Adding the different {@link com.vaadin.ui.FormLayout} instances to a {@link com.vaadin.ui.GridLayout} */ baseFormLayout.setMargin(true); columnTableFormLayout.setMargin(true); rowTableFormLayout.setMargin(true); GridLayout gridLayout = new GridLayout(); gridLayout.setSizeFull(); gridLayout.setColumns(4); gridLayout.setRows(1); gridLayout.setMargin(true); gridLayout.addComponent(rowsTable); gridLayout.addComponent(rowTableFormLayout); gridLayout.addComponent(columnsTable); gridLayout.addComponent(columnTableFormLayout); gridLayout.setColumnExpandRatio(1, 0.5f); gridLayout.setColumnExpandRatio(2, 1.0f); gridLayout.setColumnExpandRatio(3, 0.5f); gridLayout.setColumnExpandRatio(4, 1.0f); /** * Creating the vertical layout... */ VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.addComponent(baseFormLayout); verticalLayout.addComponent(gridLayout); /** * Using an additional {@link com.vaadin.ui.HorizontalLayout} for layouting the buttons */ HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setMargin(true); horizontalLayout.setSpacing(true); horizontalLayout.setWidth(100, Unit.PERCENTAGE); /** * Adding the cancel button... */ Button cancel = new Button("Cancel"); cancel.setDescription("Cancel editing properties"); cancel.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { close(); } }); cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); horizontalLayout.addComponent(cancel); horizontalLayout.setExpandRatio(cancel, 1); horizontalLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT); /** * ...and the OK button */ Button ok = new Button("Save"); ok.setDescription("Save properties and close"); ok.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (!titleField.isValid()) { ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error", "Please use an unique title", Notification.Type.ERROR_MESSAGE); return; } if (!refreshSecondsField.isValid()) { ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error", "Please enter a valid number in the \"Refresh seconds\" field", Notification.Type.ERROR_MESSAGE); return; } if (columns.getItemIds().isEmpty() || rows.getItemIds().isEmpty()) { ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error", "You must define at least one row category and one column category", Notification.Type.ERROR_MESSAGE); return; } View finalView = new View(); for (ColumnDef columnDef : columns.getItemIds()) { finalView.getColumns().add(columnDef); } for (RowDef rowDef : rows.getItemIds()) { finalView.getRows().add(rowDef); } finalView.setName(titleField.getValue()); finalView.setRefreshSeconds(Integer.parseInt(refreshSecondsField.getValue())); saveActionListener.save(finalView); close(); } }); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); horizontalLayout.addComponent(ok); verticalLayout.addComponent(horizontalLayout); setContent(verticalLayout); }
From source file:org.processbase.ui.bpm.admin.ActivityWindow.java
License:Open Source License
public void addParticipantInfo() throws ParticipantNotFoundException, ProcessNotFoundException, ActivityNotFoundException, ProcessNotFoundException, Exception { participantLayout.removeAllComponents(); Set<String> groupNames = ProcessbaseApplication.getCurrent().getBpmModule() .getProcessActivity(task.getProcessDefinitionUUID(), task.getActivityName()).getPerformers();// ParticipantDefinition participantDefinition = bpmModule.getProcessParticipant(processDefinition.getProcessDefinitionUUID(), participantName); for (String name : groupNames) { groupList.addItem(name);/*w ww.ja va2 s . c om*/ } // groupList.setWidth("200px"); groupList.setNullSelectionAllowed(false); groupList.setRows(6); // Participant Form if (task.getTaskCandidates() != null && task.getTaskCandidates().size() > 0) { for (String candidate : task.getTaskCandidates()) { candidatesList.addItem(candidate); } } candidatesList.setNullSelectionAllowed(false); candidatesList.setWidth("100%"); candidatesList.setRows(6); unAssignBtn.setValue(task.isTaskAssigned()); TextField taskUserField = new TextField( ProcessbaseApplication.getCurrent().getPbMessages().getString("taskAssignedBy")); if (task.isTaskAssigned()) { taskUserField.setValue(task.getTaskUser()); } // taskUserField.setWidth(""); taskUserField.setNullRepresentation(""); taskUserField.setEnabled(false); taskUserField.setSizeFull(); participantLayout.addComponent(groupList, 0, 0, 0, 1); participantLayout.addComponent(candidatesList, 1, 0, 2, 1); participantLayout.addComponent(reassignBtn, 1, 2, 1, 2); participantLayout.setComponentAlignment(reassignBtn, Alignment.MIDDLE_LEFT); participantLayout.addComponent(assignBtn, 2, 2, 2, 2); participantLayout.setComponentAlignment(assignBtn, Alignment.MIDDLE_RIGHT); participantLayout.addComponent(taskUserField, 3, 0, 3, 0); participantLayout.addComponent(unAssignBtn, 3, 1, 3, 1); assignUpdatesTable.removeAllItems(); assignUpdatesTable.removeGeneratedColumn("UpdatedDate"); assignUpdatesTable.addContainerProperty("UpdatedDate", Date.class, null, ProcessbaseApplication.getCurrent().getPbMessages().getString("taskUpdatedDate"), null, null); assignUpdatesTable.addGeneratedColumn("UpdatedDate", new PbColumnGenerator()); assignUpdatesTable.addContainerProperty("UpdatedBy", String.class, null, ProcessbaseApplication.getCurrent().getPbMessages().getString("taskUpdatedBy"), null, null); assignUpdatesTable.addContainerProperty("Candidates", String.class, null, ProcessbaseApplication.getCurrent().getPbMessages().getString("taskCandidates"), null, null); assignUpdatesTable.addContainerProperty("AssignedUserId", String.class, null, ProcessbaseApplication.getCurrent().getPbMessages().getString("taskAssignedBy"), null, null); for (AssignUpdate assignUpdate : task.getAssignUpdates()) { Item woItem = assignUpdatesTable.addItem(assignUpdate); woItem.getItemProperty("UpdatedDate").setValue(assignUpdate.getUpdatedDate()); woItem.getItemProperty("UpdatedBy").setValue(assignUpdate.getUpdatedBy()); woItem.getItemProperty("AssignedUserId").setValue(assignUpdate.getAssignedUserId()); woItem.getItemProperty("Candidates").setValue(assignUpdate.getCandidates()); } assignUpdatesTable.setSortContainerPropertyId("UpdatedDate"); assignUpdatesTable.setSortAscending(false); assignUpdatesTable.sort(); assignUpdatesTable.setPageLength(8); assignUpdatesTable .setCaption(ProcessbaseApplication.getCurrent().getPbMessages().getString("taskAssignUpdates")); assignUpdatesTable.setSizeFull(); participantLayout.addComponent(assignUpdatesTable, 0, 3, 3, 3); participantLayout.setWidth("100%"); participantLayout.setSpacing(true); participantLayout.setMargin(true, false, false, false); }
From source file:org.processbase.ui.bpm.admin.UserWindow.java
License:Open Source License
private void refreshTableMetadata() { try {// ww w . j a va 2 s. c om tableMetadata.removeAllItems(); BPMModule bpmModule = ProcessbaseApplication.getCurrent().getBpmModule(); List<ProfileMetadata> metadatas = bpmModule.getAllProfileMetadata(); for (ProfileMetadata profileMetadata : metadatas) { Item woItem = tableMetadata.addItem(profileMetadata); woItem.getItemProperty("name").setValue(profileMetadata.getName()); TextField metadataValue = new TextField(); metadataValue.setWidth("100%"); metadataValue.setNullRepresentation(""); metadataValue.setValue(bpmModule.getUserMetadataValue(user, profileMetadata.getName())); woItem.getItemProperty("value").setValue(metadataValue); } } catch (Exception ex) { } }
From source file:org.processbase.ui.bpm.identity.UserWindow.java
License:Open Source License
private void refreshTableMetadata() { try {//w ww. ja v a 2 s .c o m tableMetadata.removeAllItems(); List<ProfileMetadata> metadatas = ProcessbaseApplication.getCurrent().getBpmModule() .getAllProfileMetadata(); for (ProfileMetadata profileMetadata : metadatas) { Item woItem = tableMetadata.addItem(profileMetadata); woItem.getItemProperty("name").setValue(profileMetadata.getName()); TextField metadataValue = new TextField(); metadataValue.setWidth("100%"); metadataValue.setNullRepresentation(""); metadataValue.setValue(getUserMetadataValue(profileMetadata.getName())); woItem.getItemProperty("value").setValue(metadataValue); } } catch (Exception ex) { } }
From source file:org.rubicone.poc.vpush.uil.sending.SendingUI.java
License:Apache License
private FormLayout createPushMessageSendingForm() { FormLayout pushMessageSendingForm = new FormLayout(); Panel pushMessageSendingPanel = new Panel("push message sending form"); pushMessageSendingPanel.setContent(pushMessageSendingForm); TextField inputField = new TextField("text to send"); inputField.setValueChangeMode(ValueChangeMode.EAGER); pushMessageSendingForm.addComponent(inputField); Button sendButton = new Button("send", VaadinIcons.LOCATION_ARROW); sendButton.setDisableOnClick(true);/*from w w w . j a va2 s. c o m*/ sendButton.setEnabled(false); sendButton.addClickListener(event -> { this.broadcaster.broadcast(inputField.getValue()); this.sentMessages.addComponent(new Label(new Date() + ": " + inputField.getValue())); inputField.setValue(""); }); inputField.addValueChangeListener(event -> { sendButton.setEnabled(!event.getValue().isEmpty()); }); pushMessageSendingForm.addComponent(sendButton); return pushMessageSendingForm; }
From source file:org.semanticsoft.vaaclipse.p2.install.ui.impl.RepositoryLoader.java
License:Open Source License
public void initUI() { final Label errorLabel = new Label(); errorLabel.setImmediate(true);/*w w w .ja va2 s .c o m*/ Label label = new Label("Enter URI here"); final TextField textField = new TextField(); textField.setValue("http://localhost/MyUpdateSite"); textField.setImmediate(true); textField.setSizeFull(); mainLayout.addComponent(errorLabel); mainLayout.addComponent(label); mainLayout.addComponent(textField); textField.addShortcutListener(new ShortcutListener("Enter URI", ShortcutAction.KeyCode.ENTER, null) { @Override public void handleAction(Object sender, Object target) { // TODO Auto-generated method stub errorLabel.setValue(""); validate = true; loadRepository.clear(); String value = textField.getValue(); if (value != null && !value.trim().isEmpty()) { try { loadRepository.addAll(getInstallService().loadRepository(value, getProvisioningAgent())); } catch (Exception e) { validate = false; e.printStackTrace(); errorLabel.setValue("URI is not valid"); errorMessage = e.getMessage(); } iRepositoryExplorer.addRepositories(loadRepository); } } }); }
From source file:org.tltv.gantt.demo.DemoUI.java
License:Apache License
private void openStepEditor(AbstractStep step) { final Window win = new Window("Step Editor"); win.setResizable(false);/* w ww .ja v a 2 s.c om*/ win.center(); final Collection<Component> hidden = new ArrayList<Component>(); BeanItem<AbstractStep> item = new BeanItem<AbstractStep>(step); final FieldGroup group = new FieldGroup(item); group.setBuffered(true); TextField captionField = new TextField("Caption"); captionField.setNullRepresentation(""); group.bind(captionField, "caption"); TextField descriptionField = new TextField("Description"); descriptionField.setNullRepresentation(""); group.bind(descriptionField, "description"); descriptionField.setVisible(false); hidden.add(descriptionField); NativeSelect captionMode = new NativeSelect("Caption Mode"); captionMode.addItem(Step.CaptionMode.TEXT); captionMode.addItem(Step.CaptionMode.HTML); group.bind(captionMode, "captionMode"); captionMode.setVisible(false); hidden.add(captionMode); CheckBox showProgress = new CheckBox("Show progress"); group.bind(showProgress, "showProgress"); showProgress.setVisible(false); hidden.add(showProgress); Slider progress = new Slider("Progress"); progress.setWidth(100, Unit.PERCENTAGE); group.bind(progress, "progress"); progress.setVisible(false); hidden.add(progress); NativeSelect predecessorSelect = new NativeSelect("Predecessor Step"); predecessorSelect.setWidth(100, Unit.PERCENTAGE); fillPredecessorCanditatesToSelect(step, predecessorSelect); predecessorSelect.setEnabled(step instanceof Step); if (step instanceof Step) { group.bind(predecessorSelect, "predecessor"); } predecessorSelect.setVisible(false); hidden.add(predecessorSelect); final NativeSelect parentStepSelect = new NativeSelect("Parent Step"); parentStepSelect.setWidth(100, Unit.PERCENTAGE); parentStepSelect.setEnabled(false); fillParentStepCanditatesToSelect(step, parentStepSelect); parentStepSelect.setVisible(false); hidden.add(parentStepSelect); HorizontalLayout colorLayout = new HorizontalLayout(); colorLayout.setWidth(100, Unit.PERCENTAGE); colorLayout.setVisible(false); hidden.add(colorLayout); final TextField bgField = new TextField("Background color"); bgField.setNullRepresentation(""); group.bind(bgField, "backgroundColor"); bgField.setEnabled(false); final ColorPicker bgColorPicker = new ColorPicker(); bgColorPicker.setPosition(300, 100); bgColorPicker.setColor(new CssColorToColorPickerConverter().convertToModel(step.getBackgroundColor())); bgColorPicker.addColorChangeListener(new ColorChangeListener() { @Override public void colorChanged(ColorChangeEvent event) { bgField.setValue(event.getColor().getCSS()); } }); colorLayout.addComponent(bgField); colorLayout.addComponent(bgColorPicker); colorLayout.setExpandRatio(bgField, 1); colorLayout.setComponentAlignment(bgColorPicker, Alignment.BOTTOM_LEFT); DateField startDate = new DateField("Start date"); startDate.setLocale(gantt.getLocale()); startDate.setTimeZone(gantt.getTimeZone()); startDate.setResolution(Resolution.SECOND); startDate.setConverter(new DateToLongConverter()); group.bind(startDate, "startDate"); DateField endDate = new DateField("End date"); endDate.setLocale(gantt.getLocale()); endDate.setTimeZone(gantt.getTimeZone()); endDate.setResolution(Resolution.SECOND); endDate.setConverter(new DateToLongConverter()); group.bind(endDate, "endDate"); CheckBox showMore = new CheckBox("Show all settings"); showMore.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { for (Component c : hidden) { c.setVisible((Boolean) event.getProperty().getValue()); } win.center(); } }); VerticalLayout content = new VerticalLayout(); content.setMargin(true); content.setSpacing(true); win.setContent(content); content.addComponent(captionField); content.addComponent(captionMode); content.addComponent(descriptionField); content.addComponent(showProgress); content.addComponent(progress); content.addComponent(predecessorSelect); content.addComponent(parentStepSelect); content.addComponent(colorLayout); content.addComponent(startDate); content.addComponent(endDate); content.addComponent(showMore); HorizontalLayout buttons = new HorizontalLayout(); content.addComponent(buttons); Button ok = new Button("Ok", new ClickListener() { @Override public void buttonClick(ClickEvent event) { commit(win, group, parentStepSelect); } }); Button cancel = new Button("Cancel", new ClickListener() { @Override public void buttonClick(ClickEvent event) { cancel(win, group); } }); Button delete = new Button("Delete", new ClickListener() { @Override public void buttonClick(ClickEvent event) { delete(win, group); } }); buttons.addComponent(ok); buttons.addComponent(cancel); buttons.addComponent(delete); win.setClosable(true); getUI().addWindow(win); }
From source file:org.vaadin.addons.locationtextfield.LocationUpdateApplication.java
License:Apache License
public void init() { Window mainWindow = new Window("Location update"); VerticalLayout vl = new VerticalLayout(); vl.setWidth("500px"); vl.setHeight("250px"); vl.setMargin(true);/*from w w w . java2 s . c o m*/ final LocationTextField ltf = new LocationTextField(OpenStreetMapGeocoder.getInstance(), "Address: "); ltf.setWidth("100%"); vl.addComponent(ltf); final TextField lat = new TextField("Latitude: "); final TextField lon = new TextField("Longitude: "); vl.addComponent(lat); vl.addComponent(lon); ltf.addListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent event) { GeocodedLocation loc = ltf.getValue(); if (loc != null) { lat.setValue("" + loc.getLat()); lon.setValue("" + loc.getLon()); } else { lat.setValue(""); lon.setValue(""); } } }); mainWindow.setContent(vl); setMainWindow(mainWindow); }
From source file:org.vaadin.alump.fancylayouts.demo.ImageDemo.java
License:Apache License
public ImageDemo() { setMargin(true);//www .j a v a2 s. c o m setSpacing(true); setWidth("100%"); Label desc = new Label( "FancyImage can be used when you want to present multiple images in one place. This component allows you to select which image to show when or just enabled the automatic slide show mode."); addComponent(desc); final FancyImage image = new FancyImage(); image.setWidth("500px"); image.setHeight("281px"); // Setting images used final List<Resource> resources = getImageResources(); for (Resource resource : resources) { image.addResource(resource); } // Setting slideshow timeout to 3 seconds (3000 millisecs) image.setSlideShowTimeout(3000); HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); addComponent(buttonLayout); addComponent(image); setComponentAlignment(image, Alignment.TOP_CENTER); for (int i = 0; i < resources.size(); ++i) { final Button button = new Button("Pic " + (i + 1)); buttonLayout.addComponent(button); final Resource res = resources.get(i); button.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { image.showResource(res); } }); disableWhenAutoPlay.add(button); } CheckBox auto = new CheckBox("Slide show"); auto.setImmediate(true); buttonLayout.addComponent(auto); CheckBox fade = new CheckBox("Fade"); fade.setDescription("Fade image when changing"); fade.setImmediate(true); fade.setValue(image.isFadeTransition()); buttonLayout.addComponent(fade); CheckBox rotate = new CheckBox("Rotate"); rotate.setDescription("Rotate image when changing"); rotate.setImmediate(true); rotate.setValue(image.isRotateTransition()); buttonLayout.addComponent(rotate); horizontal = new CheckBox("Horizontal"); horizontal.setDescription("Should rotate happen horizontally or vertically."); horizontal.setValue(true); buttonLayout.addComponent(horizontal); TextField timeout = new TextField(); timeout.setCaption("Slide show millisecs"); timeout.setValue(String.valueOf(image.getSlideShowTimeout())); timeout.setDescription("How many millisec the slideshow shows one image"); buttonLayout.addComponent(timeout); timeout.addTextChangeListener(new TextChangeListener() { @Override public void textChange(TextChangeEvent event) { try { int value = Integer.parseInt(event.getText()); // Change slide show value image.setSlideShowTimeout(value); } catch (NumberFormatException e) { } } }); auto.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { Boolean value = (Boolean) event.getProperty().getValue(); // Enable/disable slideshow mode image.setSlideShowEnabled(value); for (Component component : disableWhenAutoPlay) { component.setEnabled(!value); } } }); fade.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { Boolean value = (Boolean) event.getProperty().getValue(); image.setFadeTransition(value.booleanValue()); } }); rotate.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { Boolean value = (Boolean) event.getProperty().getValue(); image.setRotateTransition(value.booleanValue(), horizontal.getValue()); } }); horizontal.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { if (image.isRotateTransition()) { image.setRotateTransition(true, (Boolean) event.getProperty().getValue()); } } }); }