List of usage examples for com.vaadin.ui GridLayout setColumns
public void setColumns(int columns)
From source file:org.eclipse.hawkbit.ui.rollout.rollout.AddUpdateRolloutWindowLayout.java
License:Open Source License
private GridLayout createSimpleGroupDefinitionTab() { final GridLayout layout = new GridLayout(); layout.setSpacing(true);/*ww w . j a va2s.co m*/ layout.setColumns(3); layout.setRows(4); layout.setStyleName("marginTop"); layout.addComponent(getLabel("caption.rollout.generate.groups"), 0, 0, 2, 0); layout.addComponent(getMandatoryLabel("prompt.number.of.groups"), 0, 1); layout.addComponent(noOfGroups, 1, 1); noOfGroups.addValidator(nullValidator); layout.addComponent(groupSizeLabel, 2, 1); layout.addComponent(getMandatoryLabel("prompt.tigger.threshold"), 0, 2); layout.addComponent(triggerThreshold, 1, 2); triggerThreshold.addValidator(nullValidator); layout.addComponent(getPercentHintLabel(), 2, 2); layout.addComponent(getMandatoryLabel("prompt.error.threshold"), 0, 3); layout.addComponent(errorThreshold, 1, 3); errorThreshold.addValidator(nullValidator); layout.addComponent(errorThresholdOptionGroup, 2, 3); return layout; }
From source file:org.hoot.HootView.java
License:Apache License
/** * {@inheritDoc}//from www. java2 s. c o m */ @Override protected void initializeComponents() { final int columnCount = 5; final int rowCount = 3; final GridLayout layout = this; layout.setMargin(true); layout.setSpacing(true); layout.setColumns(columnCount); layout.setRows(rowCount); //layout.setColumnExpandRatio(0, MARGIN_COLUMN_EXPAND_RATIO); //layout.setColumnExpandRatio(MARGIN_COLUMN_RIGTH_INDEX, MARGIN_COLUMN_EXPAND_RATIO); layout.setRowExpandRatio(1, 1.0f); layout.setColumnExpandRatio(2, 1.0f); layout.setSizeFull(); final AbstractComponent logoComponent = getComponent("logo"); logoComponent.setWidth(NAVIGATION_COLUMN_WIDTH, Unit.PIXELS); layout.addComponent(logoComponent, 1, 0); final AbstractComponent navigationComponent = getComponent("navigation"); navigationComponent.setWidth(NAVIGATION_COLUMN_WIDTH, Unit.PIXELS); navigationComponent.setHeight(NAVIGATION_HEIGHT, Unit.PIXELS); layout.addComponent(navigationComponent, 1, 1); //final AbstractComponent headerComponent = getComponent("header"); //headerComponent.setWidth(CONTENT_COLUMN_WIDTH, Unit.PIXELS); //headerComponent.setSizeFull(); //layout.addComponent(headerComponent, 2, 0); final AbstractComponent contentComponent = getComponent("content"); //contentComponent.setWidth(CONTENT_COLUMN_WIDTH, Unit.PIXELS); contentComponent.setSizeFull(); layout.addComponent(contentComponent, 2, 0, 2, 2); //final AbstractComponent footerComponent = getComponent("footer"); //headerComponent.setWidth(CONTENT_COLUMN_WIDTH, Unit.PIXELS); //layout.addComponent(footerComponent, 2, 2); }
From source file:org.opennms.features.vaadin.dashboard.config.ui.DashletSpecEditor.java
License:Open Source License
/** * Constructor for the DashletSpecEditor. * * @param wallboardEditor the {@link WallboardEditor} wallboard editor this editor belongs to * @param dashletSelector the {@link DashletSelector} used to query available {@link DashletFactory} instances * @param dashletSpec the associated {@link DashletSpec} instance *//*www . j a v a 2s .c o m*/ public DashletSpecEditor(WallboardEditor wallboardEditor, DashletSelector dashletSelector, DashletSpec dashletSpec) { /** * Setting the member fields */ this.m_wallboardEditor = wallboardEditor; this.m_dashletSpec = dashletSpec; this.m_dashletSelector = dashletSelector; /** * Setting defaults */ DashletFactory dashletFactory = dashletSelector.getDashletFactoryForName(dashletSpec.getDashletName()); final Map<String, String> requiredParameters = dashletFactory.getRequiredParameters(); for (Map.Entry<String, String> entry : requiredParameters.entrySet()) { if (!dashletSpec.getParameters().containsKey(entry.getKey())) { dashletSpec.getParameters().put(entry.getKey(), requiredParameters.get(entry.getKey())); } } /** * Setting up this component with size and layout */ setWidth(100.0f, Unit.PERCENTAGE); GridLayout gridLayout = new GridLayout(); gridLayout.setColumns(6); gridLayout.setRows(1); gridLayout.setMargin(true); /** * Priority field setup, layout and adding listener and validator */ final TextField priorityField = new TextField(); priorityField.setValue(String.valueOf(dashletSpec.getPriority())); priorityField.setImmediate(true); priorityField.setCaption("Priority"); priorityField.setDescription("Priority of this dashlet"); priorityField.addValidator(new AbstractStringValidator("Only numbers allowed here") { @Override protected boolean isValidValue(String s) { try { Integer.parseInt(s); } catch (NumberFormatException numberFormatException) { return false; } return true; } }); priorityField.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent valueChangeEvent) { if (priorityField.isValid()) { m_dashletSpec.setPriority(Integer.valueOf((String) valueChangeEvent.getProperty().getValue())); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Priority"); } } }); /** * Boost priority field setup, layout and adding listener and validator */ final TextField boostPriorityField = new TextField(); boostPriorityField.setValue(String.valueOf(dashletSpec.getBoostPriority())); boostPriorityField.setImmediate(true); boostPriorityField.setCaption("Boost-Priority"); boostPriorityField.setDescription("Boost priority of this dashlet"); boostPriorityField.addValidator(new AbstractStringValidator("Only numbers allowed here") { @Override protected boolean isValidValue(String s) { try { Integer.parseInt(s); } catch (NumberFormatException numberFormatException) { return false; } return true; } }); boostPriorityField.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent valueChangeEvent) { if (boostPriorityField.isValid()) { m_dashletSpec .setBoostPriority(Integer.valueOf((String) valueChangeEvent.getProperty().getValue())); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Priority"); } } }); /** * Duration field setup, layout and adding listener and validator */ final TextField durationField = new TextField(); durationField.setValue(String.valueOf(dashletSpec.getDuration())); durationField.setImmediate(true); durationField.setCaption("Duration"); durationField.setDescription("Duration for this dashlet"); durationField.addValidator(new AbstractStringValidator("Only numbers allowed here") { @Override protected boolean isValidValue(String s) { try { Integer.parseInt(s); } catch (NumberFormatException numberFormatException) { return false; } return true; } }); durationField.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent valueChangeEvent) { if (durationField.isValid()) { m_dashletSpec.setDuration(Integer.valueOf((String) valueChangeEvent.getProperty().getValue())); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Duration"); } } }); /** * Boost duration field setup, layout and adding listener and validator */ final TextField boostDurationField = new TextField(); boostDurationField.setValue(String.valueOf(dashletSpec.getBoostDuration())); boostDurationField.setImmediate(true); boostDurationField.setCaption("Boost-Duration"); boostDurationField.setDescription("Boost duration for this dashlet"); boostDurationField.addValidator(new AbstractStringValidator("Only numbers allowed here") { @Override protected boolean isValidValue(String s) { try { Integer.parseInt(s); } catch (NumberFormatException numberFormatException) { return false; } return true; } }); boostDurationField.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent valueChangeEvent) { if (boostDurationField.isValid()) { m_dashletSpec .setBoostDuration(Integer.valueOf((String) valueChangeEvent.getProperty().getValue())); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Duration"); } } }); boolean boostable = m_dashletSelector.getDashletFactoryForName(m_dashletSpec.getDashletName()) .isBoostable(); boostPriorityField.setEnabled(boostable); boostDurationField.setEnabled(boostable); /** * Setting up the dashlet selection */ m_dashletSelect = new NativeSelect(); m_dashletSelect.setCaption("Dashlet"); updateDashletSelection(dashletSelector.getDashletFactoryList()); m_dashletSelect.setImmediate(true); m_dashletSelect.setNewItemsAllowed(false); m_dashletSelect.setNullSelectionItemId("Undefined"); m_dashletSelect.setNullSelectionAllowed(false); m_dashletSelect.select(dashletSpec.getDashletName()); m_dashletSelect.setDescription("Dashlet selection"); m_dashletSelect.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent valueChangeEvent) { if (m_savingDisabled) { return; } if (valueChangeEvent.getProperty().getValue() == null) { m_dashletSpec.setDashletName("Undefined"); } else { m_dashletSpec.setDashletName(valueChangeEvent.getProperty().getValue().toString()); m_dashletSelect.removeItem("Undefined"); } m_dashletSpec.getParameters().clear(); Map<String, String> requiredParameters = m_dashletSelector .getDashletFactoryForName(m_dashletSpec.getDashletName()).getRequiredParameters(); for (Map.Entry<String, String> entry : requiredParameters.entrySet()) { m_dashletSpec.getParameters().put(entry.getKey(), entry.getValue()); } m_propertiesButton.setEnabled(requiredParameters.size() > 0); boolean boostable = m_dashletSelector.getDashletFactoryForName(m_dashletSpec.getDashletName()) .isBoostable(); boostPriorityField.setEnabled(boostable); boostDurationField.setEnabled(boostable); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Dashlet"); } }); m_titleField = new TextField(); m_titleField.setValue(dashletSpec.getTitle()); m_titleField.setImmediate(true); m_titleField.setCaption("Title"); m_titleField.setDescription("Title for this dashlet instance"); m_titleField.addValueChangeListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent valueChangeEvent) { m_dashletSpec.setTitle((String) valueChangeEvent.getProperty().getValue()); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Title"); } }); FormLayout f1 = new FormLayout(); f1.addComponent(m_dashletSelect); f1.addComponent(m_titleField); /** * Adding the required input fields and buttons to several {@link FormLayout} instances for better layout. */ FormLayout f2 = new FormLayout(); f2.addComponent(priorityField); f2.addComponent(durationField); FormLayout f3 = new FormLayout(); f3.addComponent(boostPriorityField); f3.addComponent(boostDurationField); /** * Adding the properties button... */ m_propertiesButton = new Button("Properties"); m_propertiesButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { DashletConfigurationWindow configurationWindow = m_dashletSelector .getDashletFactoryForName(m_dashletSpec.getDashletName()) .configurationWindow(m_dashletSpec); getUI().addWindow(configurationWindow); } }); m_propertiesButton.setEnabled(m_dashletSelector.getDashletFactoryForName(m_dashletSpec.getDashletName()) .getRequiredParameters().size() > 0); m_propertiesButton.setStyleName("small"); m_propertiesButton.setDescription("Open properties dialog for this dashlet"); /** * ...and the remove button */ Button removeButton = new Button("Remove"); removeButton.setDescription("Remove this dashlet entry"); FormLayout f4 = new FormLayout(); f4.addComponent(m_propertiesButton); f4.addComponent(removeButton); removeButton.addClickListener(new Button.ClickListener() { public void buttonClick(Button.ClickEvent clickEvent) { m_wallboardEditor.removeDashletSpecEditor(DashletSpecEditor.this); } }); removeButton.setStyleName("small"); Button upButton = new Button(); upButton.setStyleName("small"); upButton.setIcon(new ThemeResource("../runo/icons/16/arrow-up.png")); upButton.setDescription("Move this a dashlet entry one position up"); Button downButton = new Button(); downButton.setStyleName("small"); downButton.setIcon(new ThemeResource("../runo/icons/16/arrow-down.png")); downButton.setDescription("Move this a dashlet entry one position down"); FormLayout f5 = new FormLayout(); f5.addComponent(upButton); f5.addComponent(downButton); Button previewButton = new Button("Preview"); previewButton.setStyleName("small"); previewButton.setDescription("Preview this single dashlet entry"); Wallboard wallboard = new Wallboard(); wallboard.getDashletSpecs().add(m_dashletSpec); previewButton.addClickListener(new PreviewClickListener(this, wallboard)); FormLayout f6 = new FormLayout(); f6.addComponent(previewButton); upButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { m_wallboardEditor.swapDashletSpec(m_dashletSpec, -1); } }); downButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { m_wallboardEditor.swapDashletSpec(m_dashletSpec, +1); } }); /** * Adding the different {@link FormLayout} instances to a {@link GridLayout} */ f1.setMargin(true); f2.setMargin(true); f3.setMargin(true); f4.setMargin(true); f5.setMargin(true); f6.setMargin(true); gridLayout.addComponent(f1); gridLayout.addComponent(f2); gridLayout.addComponent(f3); gridLayout.addComponent(f4); gridLayout.addComponent(f5); gridLayout.addComponent(f6); setContent(gridLayout); }
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 ww w .j a va 2 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.vaadin.addons.sitekit.site.FixedWidthView.java
License:Apache License
/** * {@inheritDoc}/*from www . ja v a 2s . c o m*/ */ @Override protected void initializeComponents() { final int columnCount = 5; final int rowCount = 3; final GridLayout layout = this; layout.setMargin(true); layout.setColumns(columnCount); layout.setRows(rowCount); layout.setColumnExpandRatio(0, MARGIN_COLUMN_EXPAND_RATIO); layout.setColumnExpandRatio(MARGIN_COLUMN_RIGTH_INDEX, MARGIN_COLUMN_EXPAND_RATIO); layout.setRowExpandRatio(1, 1.0f); layout.setSizeFull(); layout.setMargin(false); layout.setSpacing(true); final AbstractComponent logoComponent = getComponent("logo"); logoComponent.setWidth(NAVIGATION_COLUMN_WIDTH, Unit.PIXELS); layout.addComponent(logoComponent, 1, 0); final AbstractComponent navigationComponent = getComponent("navigation"); navigationComponent.setWidth(NAVIGATION_COLUMN_WIDTH, Unit.PIXELS); navigationComponent.setHeight(NAVIGATION_HEIGHT, Unit.PIXELS); layout.addComponent(navigationComponent, 1, 1); final AbstractComponent headerComponent = getComponent("header"); headerComponent.setWidth(CONTENT_COLUMN_WIDTH, Unit.PIXELS); headerComponent.setSizeFull(); layout.addComponent(headerComponent, 2, 0); final AbstractComponent contentComponent = getComponent("content"); contentComponent.setWidth(CONTENT_COLUMN_WIDTH, Unit.PIXELS); contentComponent.setSizeFull(); layout.addComponent(contentComponent, 2, 1); final AbstractComponent footerComponent = getComponent("footer"); headerComponent.setWidth(CONTENT_COLUMN_WIDTH, Unit.PIXELS); layout.addComponent(footerComponent, 2, 2); }
From source file:probe.com.view.body.welcomelayout.PublicationsInformationWindow.java
public PublicationsInformationWindow(List<Object[]> publicationList) { int height = Page.getCurrent().getBrowserWindowHeight() - 100; int width = Page.getCurrent().getBrowserWindowWidth() - 100; int columnNum = width / 250; width = columnNum * 250;/* ww w . java2s. com*/ VerticalLayout popupBodyWrapper = new VerticalLayout(); popupBodyWrapper.setWidth("100%"); popupBodyWrapper.setHeight("100%"); VerticalLayout popupBody = new VerticalLayout(); popupBody.setWidth((width) + "px"); popupBody.setHeightUndefined(); popupBody.setStyleName(Reindeer.LAYOUT_WHITE); popupBody.setMargin(true); popupBody.setSpacing(true); popupBodyWrapper.addComponent(popupBody); popupBodyWrapper.setComponentAlignment(popupBody, Alignment.TOP_CENTER); popupWindow = new Window() { @Override public void close() { popupWindow.setVisible(false); } }; popupWindow.setContent(popupBodyWrapper); popupWindow.setWindowMode(WindowMode.NORMAL); popupWindow.setWidth((width + 22) + "px"); popupWindow.setVisible(false); popupWindow.setResizable(false); popupWindow.setClosable(false); popupWindow.setStyleName(Reindeer.WINDOW_LIGHT); popupWindow.setModal(true); popupWindow.setDraggable(false); popupWindow.setCaption( "<font color='gray' style='font-weight: bold;!important'> Publication Information</font>"); UI.getCurrent().addWindow(popupWindow); popupWindow.center(); popupWindow.setCaptionAsHtml(true); popupWindow.setClosable(true); GridLayout publicationContainer = new GridLayout(); publicationContainer.setWidth("100%"); publicationContainer.setSpacing(true); publicationContainer.setMargin(true); popupBody.addComponent(publicationContainer); publicationContainer.setColumns(columnNum); publicationContainer.setRows(publicationList.size()); this.addLayoutClickListener(PublicationsInformationWindow.this); int row = 0; int col = 0; for (Object[] obj : publicationList) { VerticalLayout publicationLayout = initPublicationLayout(obj); String btnName = "<font size=1 >" + obj[0].toString() + "</font><br/>" + obj[1].toString() + "<br/><font size=1 >" + obj[2].toString() + "</font><br/><font size=1 >#Proteins: " + obj[5].toString() /*+ "/" + obj[5].toString() + */ + " #Peptides: " + obj[7].toString() /*+ "/" + obj[7].toString() +*/ + "</font>"; PopupInfoBtn publicationBtn = new PopupInfoBtn(publicationLayout, btnName, obj[1].toString()); publicationContainer.addComponent(publicationBtn, col++, row); publicationContainer.setComponentAlignment(publicationBtn, Alignment.TOP_CENTER); if (col >= columnNum) { row++; col = 0; } } height = Math.min((++row * 85) + 200, height); popupWindow.setHeight((height) + "px"); }
From source file:probe.com.view.core.SingleStudyFilterLayout.java
/** * * @param dataset/* w w w . java 2 s . co m*/ * @param datasetIndex * @param uniqueAttr * @param view */ public SingleStudyFilterLayout(QuantDatasetObject dataset, int datasetIndex, boolean[] uniqueAttr, boolean view) { init(); this.setMargin(new MarginInfo(false, false, false, false)); VerticalLayout miniLayout = new VerticalLayout(); Label miniAttrLabel = new Label(); if (!dataset.getUniqueValues().equalsIgnoreCase("")) { miniAttrLabel.setValue("[ " + dataset.getUniqueValues() + "]"); } miniLayout.addComponent(miniAttrLabel); GridLayout studyInfo = new GridLayout(); studyInfo.setColumns(3); studyInfo.setWidth("100%"); SubTreeHideOnClick layout = new SubTreeHideOnClick("Dataset " + datasetIndex, studyInfo, miniLayout, view); this.addComponent(layout); this.setComponentAlignment(layout, Alignment.MIDDLE_CENTER); for (int i = 0; i < uniqueAttr.length; i++) { boolean check = uniqueAttr[i]; if (check) { if (!dataset.getProperty(i).toString().trim().equalsIgnoreCase("Not Available") && !dataset.getProperty(i).toString().trim().equalsIgnoreCase("0") && !dataset.getProperty(i).toString().trim().equalsIgnoreCase("-1")) { if (publicationInfoLayoutComponents[i] != null) { studyInfo.addComponent(publicationInfoLayoutComponents[i]); ((InformationField) publicationInfoLayoutComponents[i]) .setValue(dataset.getProperty(i).toString(), null); } } } } Button btn = new Button("Load Dataset"); btn.setStyleName(Reindeer.BUTTON_SMALL); VerticalLayout btnLayout = new VerticalLayout(); btnLayout.setMargin(true); btnLayout.setHeight("30px"); btnLayout.addComponent(btn); int rowNum = studyInfo.getRows(); if (studyInfo.getComponentCount() % 3 != 0) { studyInfo.addComponent(btnLayout, 2, rowNum - 1); } else { studyInfo.setRows(rowNum + 1); studyInfo.addComponent(btnLayout, 2, rowNum); } studyInfo.setComponentAlignment(btnLayout, Alignment.BOTTOM_LEFT); }