List of usage examples for com.vaadin.ui Grid setColumnReorderingAllowed
public void setColumnReorderingAllowed(boolean columnReorderingAllowed)
From source file:com.rex.components.valo.Tables.java
License:Apache License
static void configure(Table table, Grid grid, boolean footer, boolean sized, boolean expandRatios, boolean stripes, boolean verticalLines, boolean horizontalLines, boolean borderless, boolean headers, boolean compact, boolean small, boolean rowIndex, boolean rowCaption, boolean rowIcon, boolean componentsInRows) { table.setSelectable(true);//from w w w. j a va 2 s .c o m table.setMultiSelect(true); grid.setSelectionMode(SelectionMode.MULTI); table.setSortEnabled(true); for (Column c : grid.getColumns()) { if (!c.getPropertyId().equals("icon")) { c.setSortable(true); } c.setHidable(true); } table.setColumnCollapsingAllowed(true); table.setColumnReorderingAllowed(true); grid.setColumnReorderingAllowed(true); table.setPageLength(6); grid.setHeightByRows(6); table.addActionHandler(ReportEngineUI.getActionHandler()); table.setDragMode(TableDragMode.MULTIROW); table.setDropHandler(new DropHandler() { @Override public AcceptCriterion getAcceptCriterion() { return AcceptAll.get(); } @Override public void drop(DragAndDropEvent event) { Notification.show(event.getTransferable().toString()); } }); table.setColumnAlignment(ReportEngineUI.DESCRIPTION_PROPERTY, Align.RIGHT); table.setColumnAlignment(ReportEngineUI.INDEX_PROPERTY, Align.CENTER); table.removeContainerProperty("textfield"); table.removeGeneratedColumn("textfield"); table.removeContainerProperty("button"); table.removeGeneratedColumn("button"); table.removeContainerProperty("label"); table.removeGeneratedColumn("label"); table.removeContainerProperty("checkbox"); table.removeGeneratedColumn("checkbox"); table.removeContainerProperty("datefield"); table.removeGeneratedColumn("datefield"); table.removeContainerProperty("combobox"); table.removeGeneratedColumn("combobox"); table.removeContainerProperty("optiongroup"); table.removeGeneratedColumn("optiongroup"); table.removeContainerProperty("slider"); table.removeGeneratedColumn("slider"); table.removeContainerProperty("progress"); table.removeGeneratedColumn("progress"); if (componentsInRows) { table.addContainerProperty("textfield", TextField.class, null); table.addGeneratedColumn("textfield", new ColumnGenerator() { @Override public Object generateCell(Table source, Object itemId, Object columnId) { TextField tf = new TextField(); tf.setInputPrompt("Type here"); // tf.addStyleName("compact"); if ((Integer) itemId % 2 == 0) { tf.addStyleName("borderless"); } return tf; } }); table.addContainerProperty("datefield", TextField.class, null); table.addGeneratedColumn("datefield", new ColumnGenerator() { @Override public Object generateCell(Table source, Object itemId, Object columnId) { DateField tf = new DateField(); tf.addStyleName("compact"); if ((Integer) itemId % 2 == 0) { tf.addStyleName("borderless"); } return tf; } }); table.addContainerProperty("combobox", TextField.class, null); table.addGeneratedColumn("combobox", new ColumnGenerator() { @Override public Object generateCell(Table source, Object itemId, Object columnId) { ComboBox tf = new ComboBox(); tf.setInputPrompt("Select"); tf.addStyleName("compact"); if ((Integer) itemId % 2 == 0) { tf.addStyleName("borderless"); } return tf; } }); table.addContainerProperty("button", Button.class, null); table.addGeneratedColumn("button", new ColumnGenerator() { @Override public Object generateCell(Table source, Object itemId, Object columnId) { Button b = new Button("Button"); b.addStyleName("small"); return b; } }); table.addContainerProperty("label", TextField.class, null); table.addGeneratedColumn("label", new ColumnGenerator() { @Override public Object generateCell(Table source, Object itemId, Object columnId) { Label label = new Label("Label component"); label.setSizeUndefined(); label.addStyleName("bold"); return label; } }); table.addContainerProperty("checkbox", TextField.class, null); table.addGeneratedColumn("checkbox", new ColumnGenerator() { @Override public Object generateCell(Table source, Object itemId, Object columnId) { CheckBox cb = new CheckBox(null, true); return cb; } }); table.addContainerProperty("optiongroup", TextField.class, null); table.addGeneratedColumn("optiongroup", new ColumnGenerator() { @Override public Object generateCell(Table source, Object itemId, Object columnId) { OptionGroup op = new OptionGroup(); op.addItem("Male"); op.addItem("Female"); op.addStyleName("horizontal"); return op; } }); table.addContainerProperty("slider", TextField.class, null); table.addGeneratedColumn("slider", new ColumnGenerator() { @Override public Object generateCell(Table source, Object itemId, Object columnId) { Slider s = new Slider(); s.setValue(30.0); return s; } }); table.addContainerProperty("progress", TextField.class, null); table.addGeneratedColumn("progress", new ColumnGenerator() { @Override public Object generateCell(Table source, Object itemId, Object columnId) { ProgressBar bar = new ProgressBar(); bar.setValue(0.7f); return bar; } }); } table.setFooterVisible(footer); if (footer) { table.setColumnFooter(ReportEngineUI.CAPTION_PROPERTY, "caption"); table.setColumnFooter(ReportEngineUI.DESCRIPTION_PROPERTY, "description"); table.setColumnFooter(ReportEngineUI.ICON_PROPERTY, "icon"); table.setColumnFooter(ReportEngineUI.INDEX_PROPERTY, "index"); } if (sized) { table.setWidth("400px"); grid.setWidth("400px"); table.setHeight("300px"); grid.setHeight("300px"); } else { table.setSizeUndefined(); grid.setSizeUndefined(); } if (componentsInRows) { table.setWidth("100%"); } else { table.setWidth(null); } if (expandRatios) { if (!sized) { table.setWidth("100%"); } } table.setColumnExpandRatio(ReportEngineUI.CAPTION_PROPERTY, expandRatios ? 1.0f : 0); table.setColumnExpandRatio(ReportEngineUI.DESCRIPTION_PROPERTY, expandRatios ? 1.0f : 0); if (!stripes) { table.addStyleName("no-stripes"); } else { table.removeStyleName("no-stripes"); } if (!verticalLines) { table.addStyleName("no-vertical-lines"); } else { table.removeStyleName("no-vertical-lines"); } if (!horizontalLines) { table.addStyleName("no-horizontal-lines"); } else { table.removeStyleName("no-horizontal-lines"); } if (borderless) { table.addStyleName("borderless"); } else { table.removeStyleName("borderless"); } if (!headers) { table.addStyleName("no-header"); } else { table.removeStyleName("no-header"); } if (compact) { table.addStyleName("compact"); } else { table.removeStyleName("compact"); } if (small) { table.addStyleName("small"); } else { table.removeStyleName("small"); } if (!rowIndex && !rowCaption && rowIcon) { table.setRowHeaderMode(RowHeaderMode.HIDDEN); } if (rowIndex) { table.setRowHeaderMode(RowHeaderMode.INDEX); } if (rowCaption) { table.setRowHeaderMode(RowHeaderMode.PROPERTY); table.setItemCaptionPropertyId(ReportEngineUI.CAPTION_PROPERTY); } else { table.setItemCaptionPropertyId(null); } if (rowIcon) { table.setRowHeaderMode(RowHeaderMode.ICON_ONLY); table.setItemIconPropertyId(ReportEngineUI.ICON_PROPERTY); } else { table.setItemIconPropertyId(null); } }
From source file:org.eclipse.hawkbit.ui.common.AbstractMetadataPopupLayout.java
License:Open Source License
protected Grid createMetadataGrid() { final Grid metadataGrid = new Grid(); metadataGrid.addStyleName(SPUIStyleDefinitions.METADATA_GRID); metadataGrid.setImmediate(true);/*from w w w .j a va 2 s . c om*/ metadataGrid.setHeight("100%"); metadataGrid.setWidth("100%"); metadataGrid.setId(UIComponentIdProvider.METDATA_TABLE_ID); metadataGrid.setSelectionMode(SelectionMode.SINGLE); metadataGrid.setColumnReorderingAllowed(true); metadataGrid.setContainerDataSource(getMetadataContainer()); metadataGrid.getColumn(KEY).setHeaderCaption(i18n.getMessage("header.key")); metadataGrid.getColumn(VALUE).setHeaderCaption(i18n.getMessage("header.value")); metadataGrid.getColumn(VALUE).setHidden(true); metadataGrid.addSelectionListener(this::onRowClick); metadataGrid.getColumn(DELETE_BUTTON).setHeaderCaption(""); metadataGrid.getColumn(DELETE_BUTTON).setRenderer(new HtmlButtonRenderer(this::onDelete)); metadataGrid.getColumn(DELETE_BUTTON).setWidth(50); metadataGrid.getColumn(KEY).setExpandRatio(1); return metadataGrid; }
From source file:org.jpos.qi.QIEntityView.java
License:Open Source License
public Grid createGrid() { Grid g = new Grid(); g.setSizeFull();//from w ww. j av a2 s . c o m g.setSelectionMode(Grid.SelectionMode.SINGLE); g.setColumnReorderingAllowed(true); g.addItemClickListener(event -> { navigateToSpecificView(event); }); return g; }
From source file:org.jumpmind.vaadin.ui.common.CommonUiUtils.java
License:Open Source License
@SuppressWarnings("unchecked") public static Grid putResultsInGrid(final ResultSet rs, List<Integer> pkcolumns, int maxResultSize, final boolean showRowNumbers, String... excludeValues) throws SQLException { final Grid grid = new Grid(); grid.setImmediate(true);/*from w w w . ja v a 2s .co m*/ grid.setSelectionMode(SelectionMode.MULTI); grid.setColumnReorderingAllowed(true); grid.setData(new HashMap<Object, List<Object>>()); final ResultSetMetaData meta = rs.getMetaData(); int columnCount = meta.getColumnCount(); grid.addColumn("#", Integer.class).setHeaderCaption("#").setHidable(true); Set<String> columnNames = new HashSet<String>(); Set<Integer> skipColumnIndexes = new HashSet<Integer>(); int[] types = new int[columnCount]; for (int i = 1; i <= columnCount; i++) { String realColumnName = meta.getColumnName(i); String columnName = realColumnName; if (!Arrays.asList(excludeValues).contains(columnName)) { int index = 1; while (columnNames.contains(columnName)) { columnName = realColumnName + "_" + index++; } columnNames.add(columnName); Class<?> typeClass = Object.class; int type = meta.getColumnType(i); types[i - 1] = type; switch (type) { case Types.FLOAT: case Types.DOUBLE: case Types.NUMERIC: case Types.REAL: case Types.DECIMAL: typeClass = BigDecimal.class; break; case Types.TINYINT: case Types.SMALLINT: case Types.BIGINT: case Types.INTEGER: typeClass = Long.class; break; case Types.VARCHAR: case Types.CHAR: case Types.NVARCHAR: case Types.NCHAR: case Types.CLOB: typeClass = String.class; default: break; } Column column = grid.addColumn(columnName, typeClass).setHeaderCaption(columnName).setHidable(true); if (typeClass.equals(Long.class)) { column.setConverter(new StringToLongConverter() { private static final long serialVersionUID = 1L; @Override public String convertToPresentation(Long value, Class<? extends String> targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (value == null) { return NULL_TEXT; } else { return value.toString(); } } }); } else if (typeClass.equals(BigDecimal.class)) { column.setConverter(new StringToBigDecimalConverter() { private static final long serialVersionUID = 1L; @Override public String convertToPresentation(BigDecimal value, Class<? extends String> targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (value == null) { return NULL_TEXT; } else { return value.toString(); } } }); } else { column.setConverter(new Converter<String, Object>() { private static final long serialVersionUID = 1L; @Override public Object convertToModel(String value, Class<? extends Object> targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { return null; } @Override public String convertToPresentation(Object value, Class<? extends String> targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (value == null) { return NULL_TEXT; } else { return value.toString(); } } @Override public Class<Object> getModelType() { return Object.class; } @Override public Class<String> getPresentationType() { return String.class; } }); } } else { skipColumnIndexes.add(i - 1); } } int rowNumber = 1; while (rs.next() && rowNumber <= maxResultSize) { Object[] row = new Object[columnNames.size() + 1]; row[0] = new Integer(rowNumber); int rowIndex = 1; for (int i = 0; i < columnCount; i++) { if (!skipColumnIndexes.contains(i)) { Object o = getObject(rs, i + 1); int type = types[i]; switch (type) { case Types.FLOAT: case Types.DOUBLE: case Types.REAL: case Types.NUMERIC: case Types.DECIMAL: if (o != null && !(o instanceof BigDecimal)) { o = new BigDecimal(castToNumber(o.toString())); } break; case Types.TINYINT: case Types.SMALLINT: case Types.BIGINT: case Types.INTEGER: if (o != null && !(o instanceof Long)) { o = new Long(castToNumber(o.toString())); } break; default: break; } List<Object> primaryKeys = new ArrayList<Object>(); for (Integer pkcolumn : pkcolumns) { primaryKeys.add(getObject(rs, pkcolumn + 1)); } ((HashMap<Object, List<Object>>) grid.getData()).put(o, primaryKeys); row[rowIndex] = o; rowIndex++; } } grid.addRow(row); rowNumber++; } if (rowNumber < 100) { grid.getColumn("#").setWidth(75); } else if (rowNumber < 1000) { grid.getColumn("#").setWidth(95); } else { grid.getColumn("#").setWidth(115); } if (!showRowNumbers) { grid.getColumn("#").setHidden(true); } else { grid.setFrozenColumnCount(1); } return grid; }
From source file:org.vaadin.allaboutgrid.AllAboutGridUI.java
License:Apache License
private void initializeGrid(final Grid grid) { /*/*from w w w.j a va2 s . c o m*/ * Let's just add some data there to get something showing */ // grid.addColumn("Col 1"); // grid.addColumn("Col 2"); // // grid.addRow("Some", "data"); // grid.addRow("Another", "row"); /* * Let's use a full-featured container instead */ BeanItemContainer<Order> orderContainer = createOrderContainer(); grid.setContainerDataSource(orderContainer); /* * Changing the column order and adjusting column headers */ grid.setColumnOrder("id", "customer", "product", "orderAmount", "reservedAmount", "completePercentage", "priority", "customized", "orderTime"); grid.getColumn("orderAmount").setHeaderCaption("Ordered"); grid.getColumn("reservedAmount").setHeaderCaption("Reserved"); grid.getColumn("completePercentage").setHeaderCaption("Complete"); grid.getColumn("customized").setHeaderCaption("Custom"); /* * Removing unwanted columns */ // grid.removeColumn("customer"); // grid.removeColumn("customized"); // grid.removeColumn("priority"); // grid.removeColumn("orderTime"); /* * Adjusting column sizes */ grid.getColumn("id").setMaximumWidth(70); grid.getColumn("customer").setMinimumWidth(200); grid.getColumn("product").setMinimumWidth(200); /* * Keep some columns in view all the time */ grid.getColumn("product").setLastFrozenColumn(); /* * Changing the locale affects how data is presented */ grid.setLocale(Locale.GERMANY); /* * Various ways of tweaking how data is shown */ grid.getColumn("id").setRenderer(new NumberRenderer(idFormat)); grid.getColumn("completePercentage") .setRenderer(new NumberRenderer(NumberFormat.getPercentInstance(grid.getLocale()))); grid.getColumn("completePercentage").setRenderer(new ProgressBarRenderer()); grid.getColumn("customized").setConverter(new BooleanToFontIconConverter()); grid.getColumn("customized").setRenderer(new HtmlRenderer()); grid.setCellStyleGenerator(new CellStyleGenerator() { @Override public String getStyle(CellReference cellReference) { if ("priority".equals(cellReference.getPropertyId())) { Priority priority = (Priority) cellReference.getValue(); return "priority-" + priority.name().toLowerCase(); } else { return null; } } }); /* * Additional header spanned cells */ HeaderRow extraHeader = grid.prependHeaderRow(); extraHeader.join("orderAmount", "reservedAmount").setText("Quantity"); extraHeader.join("priority", "customized").setText("Status"); /* * Footer with various types of content */ FooterRow extraFooter = grid.appendFooterRow(); int totalOrdered = OrderUtil.getTotalOrderAmount(orderContainer); extraFooter.getCell("orderAmount").setText(Integer.toString(totalOrdered)); int totalReserved = OrderUtil.getTotalReservedAmounT(orderContainer); extraFooter.getCell("reservedAmount").setHtml("<b>" + totalReserved + "</b>"); extraFooter.getCell("completePercentage") .setComponent(new ProgressBar(totalReserved / (float) totalOrdered)); /* * Enable editing */ grid.setEditorEnabled(true); grid.setFrozenColumnCount(0); grid.getColumn("id").setEditable(false); grid.getColumn("completePercentage").setEditable(false); grid.getColumn("customized").getEditorField().setCaption(""); grid.getColumn("orderTime").setEditorField(createOrderTimeField()); Field<?> customerField = grid.getColumn("customer").getEditorField(); customerField.setRequired(true); customerField.setRequiredError("Value is required"); /* * Get an event when the users saves in the editor */ grid.getEditorFieldGroup().addCommitHandler(new CommitHandler() { @Override public void preCommit(CommitEvent commitEvent) throws CommitException { // Do nothing } @Override public void postCommit(CommitEvent commitEvent) throws CommitException { Notification.show("Changes saved"); } }); /* * New feature going into Vaadin 7.5: Column reordering */ grid.setColumnReorderingAllowed(true); /* * New feature going into Vaadin 7.5: Row details */ grid.setDetailsGenerator(new DetailsGenerator() { @Override public Component getDetails(RowReference rowReference) { Order order = (Order) rowReference.getItemId(); String detailsMessage = "This is a label with information about the order of " + order.getProduct() + " by " + order.getCustomer() + "."; Button deleteButton = new Button("Delete order", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { Notification.show("Button clicked"); } }); VerticalLayout layout = new VerticalLayout(new Label(detailsMessage), deleteButton); layout.setMargin(true); layout.setSpacing(true); return layout; } }); grid.addItemClickListener(new ItemClickListener() { @Override public void itemClick(ItemClickEvent event) { if (event.isDoubleClick()) { Object itemId = event.getItemId(); grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId)); } } }); grid.setEditorEnabled(false); /* * That's all. Thank you for watching! */ }