List of usage examples for com.vaadin.ui Grid addColumn
private void addColumn(String identifier, Column<T, ?> column)
From source file:com.yoncabt.ebr.ui.ReportStatusWindow.java
private Grid makeGrid() { Grid ret = new Grid(); ret.setId("reportsGrid"); ret.addColumn("uuid", String.class); ret.addColumn("data source", String.class); ret.addColumn("report", String.class); ret.addColumn("ext", String.class); ret.addColumn("started", String.class); ret.addColumn("ended", String.class); ret.addColumn("iptal", String.class) .setRenderer(new ButtonRenderer((ClickableRenderer.RendererClickEvent e) -> { String uuid = (String) grid.getContainerDataSource().getItem(e.getItemId()) .getItemProperty("uuid").getValue(); reportWS.cancel(uuid);/*from w w w . ja va2 s .c o m*/ Notification.show(uuid + " durduruldu"); })); ret.addColumn("gster", String.class) .setRenderer(new ButtonRenderer((ClickableRenderer.RendererClickEvent e) -> { String uuid = (String) grid.getContainerDataSource().getItem(e.getItemId()) .getItemProperty("uuid").getValue(); if (reportWS.status(uuid) == Status.FINISH) { Page.getCurrent().open("/ebr/ws/1.0/output/" + uuid, "_new", false); } else { Notification.show("Bitmi bir rapor yok"); } })); ret.addColumn("durum", String.class); ret.addColumn("exception", String.class); ret.setSizeFull(); return ret; }
From source file:org.jumpmind.metl.ui.views.design.ManageProjectsPanel.java
License:Open Source License
protected Component buildVersionGrid(Project project) { context.getConfigurationService().refresh(project); List<ProjectVersion> versions = project.getProjectVersions(); BeanItemContainer<ProjectVersion> versionGridContainer = new BeanItemContainer<>(ProjectVersion.class); Grid versionGrid = new Grid(); VerticalLayout layout = new VerticalLayout(); layout.setWidth(100, Unit.PERCENTAGE); layout.setMargin(true);//w ww .j a v a2 s.c o m layout.setSpacing(true); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); Button openButton = new Button("Open", (event) -> { Collection<Object> selected = versionGrid.getSelectedRows(); for (Object object : selected) { projectNavigator.addProjectVersion(((ProjectVersion) object)); } }); buttons.addComponent(openButton); Button newButton = new Button("New Version", (event) -> newVersion(versionGrid)); buttons.addComponent(newButton); Button editButton = new Button("Edit Version", (event) -> edit(versionGrid)); buttons.addComponent(editButton); Button removeButton = new Button("Remove Version", (event) -> removeVersion(versionGrid)); buttons.addComponent(removeButton); openButton.setEnabled(false); newButton.setEnabled(false); removeButton.setEnabled(false); editButton.setEnabled(false); layout.addComponent(buttons); versionGrid.setWidth(100, Unit.PERCENTAGE); versionGrid.setHeight(3 + (versions.size() * ROW_EM), Unit.EM); versionGrid.setEditorEnabled(true); versionGrid.setSelectionMode(SelectionMode.MULTI); versionGrid.addColumn("versionLabel", String.class).setHeaderCaption("Version").setExpandRatio(2); versionGrid.addColumn("description", String.class).setHeaderCaption("Description").setExpandRatio(1); versionGrid.addColumn("readOnly", Boolean.class).setHeaderCaption("Read Only").setMaximumWidth(100) .setRenderer(new HtmlRenderer(), new StringToBooleanConverter() { private static final long serialVersionUID = 1L; protected String getTrueString() { return FontAwesome.CHECK.getHtml(); }; protected String getFalseString() { return ""; }; }); versionGrid.addColumn("createTime", Date.class).setHeaderCaption("Create Time").setWidth(185) .setMaximumWidth(200).setRenderer(new DateRenderer(UiConstants.DATETIME_FORMAT)).setEditable(false); versionGrid.setContainerDataSource(versionGridContainer); versionGrid.setEditorFieldFactory(new FieldFactory()); versionGrid.getEditorFieldGroup().addCommitHandler(new FieldGroup.CommitHandler() { private static final long serialVersionUID = 1L; @Override public void preCommit(CommitEvent commitEvent) throws CommitException { } @Override public void postCommit(CommitEvent commitEvent) throws CommitException { ProjectVersion item = (ProjectVersion) versionGrid.getEditedItemId(); IConfigurationService configurationService = context.getConfigurationService(); configurationService.save(item); projectGrid.markAsDirty(); } }); versionGrid.addSelectionListener((event) -> { int numberSelected = versionGrid.getSelectedRows().size(); boolean currentlyEditing = projectGrid.getEditedItemId() != null; boolean selected = numberSelected > 0 && !currentlyEditing; openButton.setEnabled(selected); newButton.setEnabled(selected); removeButton.setEnabled(selected); editButton.setEnabled(selected); }); versionGrid.addItemClickListener(new GridClickListener(versionGrid)); layout.addComponent(versionGrid); layout.setExpandRatio(versionGrid, 1); layout.addComponent(new Label(" ")); versionGridContainer.addAll(versions); versionGrid.sort("versionLabel", SortDirection.DESCENDING); return layout; }
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 ww. ja va 2 s . 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; }