List of usage examples for com.vaadin.ui Button setClickShortcut
public void setClickShortcut(int keyCode, int... modifiers)
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 *///from w w w . j a v a2 s . c om 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 */// w ww .ja va2 s. 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.core.template.DefaultConfirmDialogFactory.java
License:Open Source License
public ConfirmDialog create(final String caption, final String message, final String okCaption, final String cancelCaption) { // Create a confirm dialog final ConfirmDialog confirm = new ConfirmDialog(); confirm.setCaption(caption != null ? caption : DEFAULT_CAPTION); // Close listener implementation confirm.addListener(new Window.CloseListener() { private static final long serialVersionUID = 1971800928047045825L; public void windowClose(CloseEvent ce) { confirm.setConfirmed(false); if (confirm.getListener() != null) { confirm.getListener().onClose(confirm); }/*from w w w .ja v a2 s.c o m*/ } }); // Create content VerticalLayout c = (VerticalLayout) confirm.getContent(); c.setSizeFull(); c.setSpacing(true); // Panel for scrolling lengthty messages. Panel scroll = new Panel(new VerticalLayout()); scroll.setScrollable(true); c.addComponent(scroll); scroll.setWidth("100%"); scroll.setHeight("100%"); scroll.setStyleName(Reindeer.PANEL_LIGHT); c.setExpandRatio(scroll, 1f); // Always HTML, but escape Label text = new Label("", Label.CONTENT_RAW); scroll.addComponent(text); confirm.setMessageLabel(text); confirm.setMessage(message); HorizontalLayout buttons = new HorizontalLayout(); c.addComponent(buttons); buttons.setSpacing(true); buttons.setHeight(format(BUTTON_HEIGHT) + "em"); buttons.setWidth("100%"); Label spacer = new Label(""); buttons.addComponent(spacer); spacer.setWidth("100%"); buttons.setExpandRatio(spacer, 1f); final Button cancel = new Button(cancelCaption != null ? cancelCaption : DEFAULT_CANCEL_CAPTION); cancel.setData(false); cancel.setClickShortcut(KeyCode.ESCAPE, null); buttons.addComponent(cancel); buttons.setComponentAlignment(cancel, Alignment.MIDDLE_RIGHT); confirm.setCancelButton(cancel); final Button ok = new Button(okCaption != null ? okCaption : DEFAULT_OK_CAPTION); ok.setData(true); ok.setClickShortcut(KeyCode.ENTER, null); ok.setStyleName(Reindeer.BUTTON_DEFAULT); ok.focus(); buttons.addComponent(ok); buttons.setComponentAlignment(ok, Alignment.MIDDLE_RIGHT); confirm.setOkButton(ok); // Create a listener for buttons Button.ClickListener cb = new Button.ClickListener() { private static final long serialVersionUID = 3525060915814334881L; public void buttonClick(ClickEvent event) { // Copy the button date to window for passing through either // "OK" or "CANCEL" confirm.setConfirmed(event.getButton() == ok); // This has to be invoked as the window.close // event is not fired when removed. if (confirm.getListener() != null) { confirm.getListener().onClose(confirm); } confirm.close(); } }; cancel.addListener(cb); ok.addListener(cb); // Approximate the size of the dialog double[] dim = getDialogDimensions(message, ConfirmDialog.CONTENT_TEXT_WITH_NEWLINES); confirm.setWidth(format(dim[0]) + "em"); confirm.setHeight(format(dim[1]) + "em"); confirm.setResizable(false); return confirm; }
From source file:org.vaadin.dialogs.DefaultConfirmDialogFactory.java
License:Mozilla Public License
public ConfirmDialog create(final String caption, final String message, final String okCaption, final String cancelCaption) { // Create a confirm dialog final ConfirmDialog confirm = new ConfirmDialog(); confirm.setCaption(caption != null ? caption : DEFAULT_CAPTION); // Close listener implementation confirm.addListener(new Window.CloseListener() { private static final long serialVersionUID = 1971800928047045825L; public void windowClose(CloseEvent ce) { // Only process if still enabled if (confirm.isEnabled()) { confirm.setEnabled(false); // avoid double processing confirm.setConfirmed(false); if (confirm.getListener() != null) { confirm.getListener().onClose(confirm); }//from w w w . ja v a 2 s .co m } } }); // Create content VerticalLayout c = (VerticalLayout) confirm.getContent(); c.setSizeFull(); c.setSpacing(true); // Panel for scrolling lengthty messages. Panel scroll = new Panel(new VerticalLayout()); scroll.setScrollable(true); c.addComponent(scroll); scroll.setWidth("100%"); scroll.setHeight("100%"); scroll.setStyleName(Reindeer.PANEL_LIGHT); c.setExpandRatio(scroll, 1f); // Always HTML, but escape Label text = new Label("", Label.CONTENT_RAW); scroll.addComponent(text); confirm.setMessageLabel(text); confirm.setMessage(message); HorizontalLayout buttons = new HorizontalLayout(); c.addComponent(buttons); buttons.setSpacing(true); buttons.setHeight(format(BUTTON_HEIGHT) + "em"); buttons.setWidth("100%"); Label spacerLeft = new Label(""); buttons.addComponent(spacerLeft); spacerLeft.setWidth("100%"); buttons.setExpandRatio(spacerLeft, 1f); final Button cancel = new Button(cancelCaption != null ? cancelCaption : DEFAULT_CANCEL_CAPTION); cancel.setData(false); cancel.setClickShortcut(KeyCode.ESCAPE, null); buttons.addComponent(cancel); confirm.setCancelButton(cancel); final Button ok = new Button(okCaption != null ? okCaption : DEFAULT_OK_CAPTION); ok.setData(true); ok.setClickShortcut(KeyCode.ENTER, null); ok.focus(); buttons.addComponent(ok); confirm.setOkButton(ok); Label spacerRight = new Label(""); buttons.addComponent(spacerRight); spacerRight.setWidth("100%"); buttons.setExpandRatio(spacerRight, 1f); // Create a listener for buttons Button.ClickListener cb = new Button.ClickListener() { private static final long serialVersionUID = 3525060915814334881L; public void buttonClick(ClickEvent event) { // Copy the button date to window for passing through either // "OK" or "CANCEL". Only process id still enabled. if (confirm.isEnabled()) { confirm.setEnabled(false); // Avoid double processing confirm.setConfirmed(event.getButton() == ok); // We need to cast this way, because of the backward // compatibility issue in 6.4 series. Component parent = confirm.getParent(); if (parent instanceof Window) { try { Method m = Window.class.getDeclaredMethod("removeWindow", Window.class); m.invoke(parent, confirm); } catch (Exception e) { throw new RuntimeException( "Failed to remove confirmation dialog from the parent window.", e); } } // This has to be invoked as the window.close // event is not fired when removed. if (confirm.getListener() != null) { confirm.getListener().onClose(confirm); } } } }; cancel.addListener(cb); ok.addListener(cb); // Approximate the size of the dialog double[] dim = getDialogDimensions(message, ConfirmDialog.CONTENT_TEXT_WITH_NEWLINES); confirm.setWidth(format(dim[0]) + "em"); confirm.setHeight(format(dim[1]) + "em"); confirm.setResizable(false); return confirm; }
From source file:ru.codeinside.adm.ui.employee.TableEmployee.java
License:Mozilla Public License
protected void edit(final CustomTable table) { final Item item = table.getItem(table.getValue()); final String login = (String) item.getItemProperty("login").getValue(); final UserItem userItem = AdminServiceProvider.get().getUserItem(login); final Pattern snilsPattern = Pattern.compile("\\d{11}"); final Pattern splitSnilsPattern = Pattern.compile("(\\d{3})(\\d{3})(\\d{3})(\\d{2})"); final Panel layout = new Panel(); ((Layout.SpacingHandler) layout.getContent()).setSpacing(true); layout.setSizeFull();//from w ww. ja v a 2 s.c om layout.addComponent(new Label("? ? " + login)); String widthColumn = "100px"; final PasswordField fieldPass = addPasswordField(layout, widthColumn, ""); final PasswordField fieldPassRepeat = addPasswordField(layout, widthColumn, " ?"); fieldPassRepeat.addValidator(new RepeatPasswordValidator(fieldPass)); final MaskedTextField fieldSnils = addMaskedTextField(layout, widthColumn, "?"); fieldSnils.setMask("###-###-### ##"); final TextField fieldFIO = addTextField(layout, widthColumn, ""); final String snils = userItem.getSnils() == null ? "" : userItem.getSnils(); final Matcher maskMatcher = snilsPattern.matcher(snils); final Matcher splitMatcher = splitSnilsPattern.matcher(snils); if (maskMatcher.matches()) { String maskedSnils = splitMatcher.replaceAll("$1-$2-$3 $4"); fieldSnils.setValue(maskedSnils); } fieldFIO.setValue(userItem.getFio()); HorizontalLayout l1 = new HorizontalLayout(); Label labelRole = new Label(""); labelRole.setWidth(widthColumn); l1.addComponent(labelRole); l1.setComponentAlignment(labelRole, Alignment.MIDDLE_LEFT); final OptionGroup roleOptionGroup = TableEmployee.createRoleOptionGroup(null); roleOptionGroup.setValue(userItem.getRoles()); l1.addComponent(roleOptionGroup); layout.addComponent(l1); final CertificateBlock certificateBlock = new CertificateBlock(userItem); layout.addComponent(certificateBlock); final ExecutorGroupsBlock executorGroupsBlock = new ExecutorGroupsBlock(userItem); layout.addComponent(executorGroupsBlock); final HorizontalLayout supervisorGroupsEmp = new HorizontalLayout(); supervisorGroupsEmp.setMargin(true, true, true, false); supervisorGroupsEmp.setSpacing(true); supervisorGroupsEmp .setCaption("? ? ? ?"); final FilterTable allSupervisorGroupsEmp = new FilterTable(); allSupervisorGroupsEmp.setCaption("?"); table(supervisorGroupsEmp, allSupervisorGroupsEmp); final FilterTable currentSupervisorGroupsEmp = new FilterTable(); currentSupervisorGroupsEmp.setCaption(""); table(supervisorGroupsEmp, currentSupervisorGroupsEmp); for (String groupName : AdminServiceProvider.get().getEmpGroupNames()) { for (Group group : AdminServiceProvider.get().findGroupByName(groupName)) { if (userItem.getEmployeeGroups().contains(groupName)) { currentSupervisorGroupsEmp.addItem(new Object[] { groupName, group.getTitle() }, groupName); } else { allSupervisorGroupsEmp.addItem(new Object[] { groupName, group.getTitle() }, groupName); } } } addListener(allSupervisorGroupsEmp, currentSupervisorGroupsEmp); addListener(currentSupervisorGroupsEmp, allSupervisorGroupsEmp); layout.addComponent(supervisorGroupsEmp); final HorizontalLayout supervisorGroupsOrg = new HorizontalLayout(); supervisorGroupsOrg.setMargin(true, true, true, false); supervisorGroupsOrg.setSpacing(true); supervisorGroupsOrg .setCaption("? ? ?"); final FilterTable allSupervisorGroupsOrg = new FilterTable(); allSupervisorGroupsOrg.setCaption("?"); table(supervisorGroupsOrg, allSupervisorGroupsOrg); final FilterTable currentSupervisorGroupsOrg = new FilterTable(); currentSupervisorGroupsOrg.setCaption(""); table(supervisorGroupsOrg, currentSupervisorGroupsOrg); for (String groupName : AdminServiceProvider.get().getOrgGroupNames()) { for (Group group : AdminServiceProvider.get().findGroupByName(groupName)) { if (userItem.getOrganizationGroups().contains(groupName)) { currentSupervisorGroupsOrg.addItem(new Object[] { groupName, group.getTitle() }, groupName); } else { allSupervisorGroupsOrg.addItem(new Object[] { groupName, group.getTitle() }, groupName); } } } addListener(allSupervisorGroupsOrg, currentSupervisorGroupsOrg); addListener(currentSupervisorGroupsOrg, allSupervisorGroupsOrg); layout.addComponent(supervisorGroupsOrg); setRolesEnabled(roleOptionGroup, certificateBlock, executorGroupsBlock, supervisorGroupsEmp, supervisorGroupsOrg); roleOptionGroup.addListener(new Listener() { private static final long serialVersionUID = 1L; public void componentEvent(Event event) { setRolesEnabled(roleOptionGroup, certificateBlock, executorGroupsBlock, supervisorGroupsEmp, supervisorGroupsOrg); } }); Button cancel = new Button("", new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(Button.ClickEvent event) { removeComponent(layout); addComponent(table); table.setValue(null); if (hr != null) { hr.setVisible(true); } setExpandRatio(table, 1f); } }); Button apply = new Button("", new Button.ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { String password = (String) fieldPass.getValue(); String passwordRepeat = (String) fieldPassRepeat.getValue(); if (!fieldPassRepeat.isValid() || !(password.equals(passwordRepeat))) { getWindow().showNotification( "? ? ? ?", Window.Notification.TYPE_ERROR_MESSAGE); return; } String snilsFieldValue = fieldSnils.getValue() == null ? "" : (String) fieldSnils.getValue(); String snilsValue = snilsFieldValue.replaceAll("\\D+", ""); Matcher snilsMatcher = snilsPattern.matcher(snilsValue); if (!snilsFieldValue.isEmpty() && !snilsMatcher.matches()) { getWindow().showNotification("? ", Window.Notification.TYPE_ERROR_MESSAGE); return; } if (!AdminServiceProvider.get().isUniqueSnils(login, snilsValue)) { getWindow().showNotification(" ? ", Window.Notification.TYPE_ERROR_MESSAGE); return; } String fio = (String) fieldFIO.getValue(); Set<Role> roles = (Set) roleOptionGroup.getValue(); TreeSet<String> groupExecutor = executorGroupsBlock.getGroups(); TreeSet<String> groupSupervisorEmp = new TreeSet<String>( (Collection<String>) currentSupervisorGroupsEmp.getItemIds()); TreeSet<String> groupSupervisorOrg = new TreeSet<String>( (Collection<String>) currentSupervisorGroupsOrg.getItemIds()); boolean modified = false; if (certificateBlock.isCertificateWasRemoved()) { userItem.setX509(null); modified = true; } if (!password.equals("") && password.equals(passwordRepeat)) { userItem.setPassword1(password); userItem.setPassword2(passwordRepeat); modified = true; } if (!fio.trim().equals("") && !fio.equals(userItem.getFio())) { userItem.setFio(fio); userItem.setX509(null); modified = true; } if (!snilsValue.equals(userItem.getSnils())) { userItem.setSnils(snilsValue); modified = true; } if (!roles.equals(userItem.getRoles())) { userItem.setRoles(roles); modified = true; } if (!groupExecutor.equals(userItem.getGroups())) { userItem.setGroups(groupExecutor); modified = true; } if (!groupSupervisorEmp.equals(userItem.getEmployeeGroups())) { userItem.setEmployeeGroups(groupSupervisorEmp); modified = true; } if (!groupSupervisorOrg.equals(userItem.getOrganizationGroups())) { userItem.setOrganizationGroups(groupSupervisorOrg); modified = true; } if (modified) { // TODO : userInfoPanel // if (getApplication().getUser().equals(login)) { // ((AdminApp) getApplication()).getUserInfoPanel().setRole( // userItem.getRoles().toString()); // } AdminServiceProvider.get().setUserItem(login, userItem); final Container container = table.getContainerDataSource(); if (container instanceof LazyLoadingContainer2) { ((LazyLoadingContainer2) container).fireItemSetChange(); } getWindow().showNotification(" " + login + " "); } else { getWindow().showNotification(" "); } removeComponent(layout); addComponent(table); table.setValue(null); if (hr != null) { hr.setVisible(true); } setExpandRatio(table, 1f); refresh(table); } }); cancel.setClickShortcut(KeyCode.ESCAPE, 0); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); buttons.addComponent(apply); buttons.addComponent(cancel); layout.addComponent(buttons); removeComponent(table); addComponent(layout); setExpandRatio(layout, 1f); }
From source file:ru.codeinside.adm.ui.employee.TableEmployee.java
License:Mozilla Public License
protected void view(final AbstractSelect table) { final String login = (String) table.getItem(table.getValue()).getItemProperty("login").getValue(); Button cancel = new Button("?"); EmployeeInfo info = new EmployeeInfo(login, cancel); cancel.addListener(new BackAction(info, table)); cancel.setClickShortcut(KeyCode.ESCAPE, 0); addComponent(info);/* w w w.ja v a 2 s. c o m*/ setExpandRatio(info, 1f); removeComponent(table); }
From source file:ru.codeinside.adm.ui.TreeTableOrganization.java
License:Mozilla Public License
void createGroupEditor(final long id, final Set<String> names) { final Organization org = AdminServiceProvider.get().findOrganizationById(id); final Set<String> all = AdminServiceProvider.get().getOrgGroupNames(); final VerticalLayout layout = new VerticalLayout(); layout.setSpacing(true);/* ww w . ja v a2s .c om*/ final TwinColSelect twin = new TwinColSelect(); twin.setSizeFull(); twin.setNullSelectionAllowed(true); twin.setLeftColumnCaption("?"); twin.setRightColumnCaption(" ? " + org.getName()); twin.setImmediate(true); for (final String name : all) { twin.addItem(name); if (names.contains(name)) { twin.select(name); } } layout.addComponent(twin); final HorizontalLayout h = new HorizontalLayout(); h.setSpacing(true); Button cancel = new Button("", new Button.ClickListener() { private static final long serialVersionUID = -2885182304929510066L; @Override public void buttonClick(Button.ClickEvent event) { showOrganization(id); } }); cancel.setClickShortcut(KeyCode.ESCAPE, 0); Button ok = new Button("", new Button.ClickListener() { private static final long serialVersionUID = -3182280627040233669L; @Override public void buttonClick(Button.ClickEvent event) { AdminServiceProvider.get().setOrgGroupNames(id, new TreeSet<String>((Collection<String>) twin.getValue())); showOrganization(id); } }); ok.setClickShortcut(KeyCode.O, ModifierKey.CTRL); h.addComponent(ok); h.addComponent(cancel); layout.addComponent(h); layout.setSizeFull(); panel.removeAllComponents(); panel.addComponent(layout); twin.focus(); }
From source file:ru.codeinside.gses.webui.executor.ExecutorFactory.java
License:Mozilla Public License
static void showTask(final Changer changer, final Task task, final ProcessDefinitionEntity def) { final VerticalLayout layout = new VerticalLayout(); layout.setMargin(true);/* w w w .j a v a2 s . c o m*/ layout.setSpacing(true); layout.setSizeFull(); final Button cancel = new Button("?", new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { changer.back(); } }); cancel.setClickShortcut(KeyCode.ESCAPE, 0); layout.addComponent(cancel); HorizontalLayout hl = new HorizontalLayout(); hl.setSizeFull(); hl.setSpacing(true); layout.addComponent(hl); layout.setExpandRatio(cancel, 0.01f); layout.setExpandRatio(hl, 0.99f); VerticalLayout vl = new VerticalLayout(); vl.setSizeFull(); vl.setSpacing(true); hl.addComponent(vl); final String procedureName = Flash.flash().getExecutorService().getProcedureNameByDefinitionId(def.getId()); vl.addComponent(new ProcedureHistoryPanel(task.getId())); ShowDiagramComponentParameterObject parameterObject = new ShowDiagramComponentParameterObject(); final String procVersion = def.getVersion() + ""; parameterObject.windowHeader = procedureName + "v. " + procVersion; parameterObject.width = "600px"; parameterObject.executionId = task.getExecutionId(); parameterObject.changer = changer; parameterObject.processDefinitionId = def.getId(); parameterObject.caption = ""; ShowDiagramComponent showDiagramComponent = new ShowDiagramComponent(parameterObject); hl.addComponent(showDiagramComponent); hl.setExpandRatio(vl, 0.5f); hl.setExpandRatio(showDiagramComponent, 0.5f); changer.change(layout); cancel.focus(); }