List of usage examples for com.vaadin.ui Grid getColumn
public Column<T, ?> getColumn(String columnId)
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 ww . j a v a 2 s . com*/ 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.eclipse.hawkbit.ui.distributions.smtable.SwMetadataPopupLayout.java
License:Open Source License
@Override protected Grid createMetadataGrid() { final Grid metadataGrid = super.createMetadataGrid(); metadataGrid.getContainerDataSource().addContainerProperty(TARGET_VISIBLE, Boolean.class, Boolean.FALSE); metadataGrid.getColumn(TARGET_VISIBLE).setHeaderCaption(i18n.getMessage("metadata.targetvisible")); metadataGrid.getColumn(TARGET_VISIBLE).setHidden(true); return metadataGrid; }
From source file:org.jumpmind.metl.ui.views.manage.ExecutionRunPanel.java
License:Open Source License
protected void logTableCellClicked(Grid logTable, ItemClickEvent event) { if (event.isDoubleClick()) { Object object = event.getPropertyId(); if (!object.toString().equals("")) { Object prop = event.getPropertyId(); String header = logTable.getColumn(prop).getHeaderCaption(); Property<?> p = event.getItem().getItemProperty(prop); if (p != null) { String data = String.valueOf(p.getValue()); new ReadOnlyTextAreaDialog(header, data, false).showAtSize(.5); }/* w w w . ja v a 2 s.c o m*/ } } }
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 ww w . j a va2s .c o 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 . ja v a2 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! */ }