diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/AbbreviatorConverter.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/AbbreviatorConverter.java deleted file mode 100644 index ab06341995..0000000000 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/AbbreviatorConverter.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.jumpmind.vaadin.ui.common; - -import java.util.Locale; - -import org.apache.commons.lang.StringUtils; - -import com.vaadin.v7.data.util.converter.Converter; - -public class AbbreviatorConverter implements Converter { - - private static final long serialVersionUID = 1L; - - private int maxWidth; - - public AbbreviatorConverter(int maxWidth) { - this.maxWidth = maxWidth; - } - - @Override - public String convertToModel(String value, Class targetType, Locale locale) - throws com.vaadin.v7.data.util.converter.Converter.ConversionException { - return value; - } - - @Override - public String convertToPresentation(String value, Class targetType, Locale locale) - throws com.vaadin.v7.data.util.converter.Converter.ConversionException { - return StringUtils.abbreviate(value, maxWidth); - } - - @Override - public Class getModelType() { - return String.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - -} diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/AbstractSpringUI.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/AbstractSpringUI.java deleted file mode 100644 index 9614f3ab5d..0000000000 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/AbstractSpringUI.java +++ /dev/null @@ -1,127 +0,0 @@ -/** - * Licensed to JumpMind Inc under one or more contributor - * license agreements. See the NOTICE file distributed - * with this work for additional information regarding - * copyright ownership. JumpMind Inc licenses this file - * to you under the GNU General Public License, version 3.0 (GPLv3) - * (the "License"); you may not use this file except in compliance - * with the License. - * - * You should have received a copy of the GNU General Public License, - * version 3.0 (GPLv3) along with this library; if not, see - * . - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jumpmind.vaadin.ui.common; - -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.Date; -import java.util.Locale; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.context.support.WebApplicationContextUtils; - -import com.vaadin.v7.data.util.converter.Converter; -import com.vaadin.v7.data.util.converter.DefaultConverterFactory; -import com.vaadin.v7.data.util.converter.StringToBigDecimalConverter; -import com.vaadin.v7.data.util.converter.StringToBooleanConverter; -import com.vaadin.v7.data.util.converter.StringToDateConverter; -import com.vaadin.v7.data.util.converter.StringToDoubleConverter; -import com.vaadin.v7.data.util.converter.StringToFloatConverter; -import com.vaadin.v7.data.util.converter.StringToIntegerConverter; -import com.vaadin.v7.data.util.converter.StringToLongConverter; -import com.vaadin.server.DefaultErrorHandler; -import com.vaadin.server.Responsive; -import com.vaadin.server.VaadinRequest; -import com.vaadin.server.VaadinServlet; -import com.vaadin.server.VaadinSession; -import com.vaadin.ui.UI; - -abstract public class AbstractSpringUI extends UI { - - private static final long serialVersionUID = 1L; - - private final Logger log = LoggerFactory.getLogger(getClass()); - - @Override - protected void init(VaadinRequest request) { - setErrorHandler(new DefaultErrorHandler() { - - private static final long serialVersionUID = 1L; - - @Override - public void error(com.vaadin.server.ErrorEvent event) { - Throwable ex = event.getThrowable(); - CommonUiUtils.notify(ex); - if (ex != null) { - log.error(ex.getMessage(), ex); - } else { - log.error("An unexpected error occurred"); - } - } - }); - - VaadinSession.getCurrent().setConverterFactory(new DefaultConverterFactory() { - private static final long serialVersionUID = 1L; - - @Override - protected Converter createDateConverter(Class sourceType) { - return super.createDateConverter(sourceType); - } - - protected Converter createStringConverter(Class sourceType) { - if (Double.class.isAssignableFrom(sourceType)) { - return new StringToDoubleConverter(); - } else if (Float.class.isAssignableFrom(sourceType)) { - return new StringToFloatConverter(); - } else if (Integer.class.isAssignableFrom(sourceType)) { - return new StringToIntegerConverter() { - private static final long serialVersionUID = 1L; - @Override - protected NumberFormat getFormat(Locale locale) { - NumberFormat format = super.getFormat(locale); - format.setGroupingUsed(false); - return format; - } - }; - } else if (Long.class.isAssignableFrom(sourceType)) { - return new StringToLongConverter() { - private static final long serialVersionUID = 1L; - @Override - protected NumberFormat getFormat(Locale locale) { - NumberFormat format = super.getFormat(locale); - format.setGroupingUsed(false); - return format; - } - }; - } else if (BigDecimal.class.isAssignableFrom(sourceType)) { - return new StringToBigDecimalConverter(); - } else if (Boolean.class.isAssignableFrom(sourceType)) { - return new StringToBooleanConverter(); - } else if (Date.class.isAssignableFrom(sourceType)) { - return new StringToDateConverter(); - } else { - return null; - } - } - - - }); - - Responsive.makeResponsive(this); - } - - public WebApplicationContext getWebApplicationContext() { - return WebApplicationContextUtils.getRequiredWebApplicationContext(VaadinServlet - .getCurrent().getServletContext()); - } -} diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/CommonUiUtils.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/CommonUiUtils.java index f334182932..b4ea27c4cf 100644 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/CommonUiUtils.java +++ b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/CommonUiUtils.java @@ -36,7 +36,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Locale; +import java.util.Map; import java.util.Set; import javax.servlet.ServletContext; @@ -49,28 +49,18 @@ import org.slf4j.LoggerFactory; import org.vaadin.aceeditor.AceEditor; -import com.vaadin.v7.data.Container; -import com.vaadin.v7.data.Property; -import com.vaadin.v7.data.util.converter.Converter; -import com.vaadin.v7.data.util.converter.StringToBigDecimalConverter; -import com.vaadin.v7.data.util.converter.StringToLongConverter; import com.vaadin.server.Page; import com.vaadin.server.Sizeable.Unit; import com.vaadin.server.VaadinServlet; import com.vaadin.shared.Position; -import com.vaadin.v7.ui.AbstractSelect; -import com.vaadin.v7.ui.AbstractTextField.TextChangeEventMode; import com.vaadin.ui.Button; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.Column; -import com.vaadin.v7.ui.Grid.SelectionMode; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.Column; +import com.vaadin.ui.Grid.SelectionMode; import com.vaadin.ui.Label; -import com.vaadin.v7.ui.NativeSelect; import com.vaadin.ui.Notification; import com.vaadin.ui.Notification.Type; import com.vaadin.ui.TabSheet; -import com.vaadin.v7.ui.Table; -import com.vaadin.v7.ui.Table.CellStyleGenerator; import com.vaadin.ui.themes.ValoTheme; public final class CommonUiUtils { @@ -112,42 +102,6 @@ public static Button createPrimaryButton(String name, Button.ClickListener liste return button; } - public static Table createTable() { - Table table = new Table() { - - private static final long serialVersionUID = 1L; - - @Override - protected String formatPropertyValue(Object rowId, Object colId, Property property) { - if (property.getValue() != null) { - if (property.getType() == Date.class) { - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss aaa"); - return df.format((Date) property.getValue()); - } else if (Number.class.isAssignableFrom(property.getType())) { - return property.getValue().toString(); - } - } - return super.formatPropertyValue(rowId, colId, property); - } - - }; - - table.setCellStyleGenerator(new CellStyleGenerator() { - - private static final long serialVersionUID = 1L; - - @Override - public String getStyle(Table source, Object itemId, Object propertyId) { - if (propertyId != null && propertyId.equals("#")) { - return "rowheader"; - } - return null; - } - }); - - return table; - } - public static AceEditor createAceEditor() { AceEditor editor = new AceEditor(); editor.setSizeFull(); @@ -229,319 +183,134 @@ public static Object getObject(ResultSet rs, int i) throws SQLException { return obj; } - public static Table putResultsInTable(final ResultSet rs, int maxResultSize, final boolean showRowNumbers, String... excludeValues) - throws SQLException { - try { - final Table table = createTable(); - table.setImmediate(true); - table.setSortEnabled(true); - table.setSelectable(true); - table.setMultiSelect(true); - table.setColumnReorderingAllowed(true); - table.setColumnReorderingAllowed(true); - table.setColumnCollapsingAllowed(true); - - if(rs != null) { - final ResultSetMetaData meta = rs.getMetaData(); - int columnCount = meta.getColumnCount(); - table.addContainerProperty("#", Integer.class, null); - Set columnNames = new HashSet(); - Set skipColumnIndexes = new HashSet(); - 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)) { + public static String[] getHeaderCaptions(Grid grid) { + List headers = new ArrayList(); + for (Column column : grid.getColumns()) { + headers.add(column.getCaption()); + } + return headers.toArray(new String[headers.size()]); + } - int index = 1; - while (columnNames.contains(columnName)) { - columnName = realColumnName + "_" + index++; + public static Grid> putResultsInGrid(final ResultSet rs, int maxResultSize, final boolean showRowNumbers, + String... excludeValues) throws SQLException { + final Grid> grid = new Grid>(); + grid.setSelectionMode(SelectionMode.MULTI); + grid.setColumnReorderingAllowed(true); + grid.addItemClickListener(event -> { + grid.deselectAll(); + grid.select(event.getItem()); + }); + + List> outerList = new ArrayList>(); + if (rs != null) { + final int[] rowCounter = {0}; + final Map, Integer> rowNumberMap = new HashMap, Integer>(); + grid.addColumn(row -> { + if (!rowNumberMap.containsKey(row)) { + rowCounter[0]++; + rowNumberMap.put(row, rowCounter[0]); + } + return rowNumberMap.get(row); + }).setCaption("#").setId("#").setHidden(!showRowNumbers).setStyleGenerator(row -> { + if (!grid.getSelectedItems().contains(row)) { + return "rowheader"; + } + return null; + }); + + final ResultSetMetaData meta = rs.getMetaData(); + int totalColumns = meta.getColumnCount(); + Set skipColumnIndexes = new HashSet(); + Set columnNames = new HashSet(); + int[] types = new int[totalColumns]; + final int[] columnCounter = {1}; + while (columnCounter[0] <= totalColumns) { + String realColumnName = meta.getColumnName(columnCounter[0]); + String columnName = realColumnName; + if (!Arrays.asList(excludeValues).contains(columnName)) { + int index = 1; + while (columnNames.contains(columnName)) { + columnName = realColumnName + "_" + index++; + } + columnNames.add(columnName); + + Integer colNum = new Integer(columnCounter[0] - 1 - skipColumnIndexes.size()); + grid.addColumn(row -> row.get(colNum)).setCaption(columnName).setHidable(true) + .setStyleGenerator(row -> { + if (row.get(colNum) == null) { + return "italics"; } - columnNames.add(columnName); - - Class typeClass = Object.class; - int type = meta.getColumnType(i); - types[i - 1] = type; + return null; + }); + + types[columnCounter[0] - 1] = meta.getColumnType(columnCounter[0]); + } else { + skipColumnIndexes.add(columnCounter[0] - 1); + } + columnCounter[0]++; + } + + for (int rowNumber = 1; rs.next() && rowNumber <= maxResultSize; rowNumber++) { + List innerList = new ArrayList(); + + for (int i = 0; i < totalColumns; 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.NUMERIC: case Types.REAL: + case Types.NUMERIC: case Types.DECIMAL: - typeClass = BigDecimal.class; + if (o == null) { + o = new BigDecimal(-1); + } + if (!(o instanceof BigDecimal)) { + o = new BigDecimal(castToNumber(o.toString())); + } break; case Types.TINYINT: case Types.SMALLINT: case Types.BIGINT: case Types.INTEGER: - typeClass = Long.class; + if (o == null) { + o = new Long(-1); + } + + if (!(o instanceof Long)) { + o = new Long(castToNumber(o.toString())); + } break; - case Types.VARCHAR: - case Types.CHAR: - case Types.NVARCHAR: - case Types.NCHAR: - case Types.CLOB: - typeClass = String.class; default: break; } - table.addContainerProperty(i, typeClass, null); - table.setColumnHeader(i, columnName); - } 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 = new BigDecimal(-1); - } - if (!(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 = new Long(-1); - } - - if (!(o instanceof Long)) { - o = new Long(castToNumber(o.toString())); - } - break; - default: - break; - } - row[rowIndex] = o == null ? NULL_TEXT : o; - rowIndex++; - } + + innerList.add(o == null ? NULL_TEXT : o); } - table.addItem(row, rowNumber); - rowNumber++; } - + + outerList.add(innerList); + if (rowNumber < 100) { - table.setColumnWidth("#", 18); + grid.getColumn("#").setWidth(75); } else if (rowNumber < 1000) { - table.setColumnWidth("#", 25); - } else { - table.setColumnWidth("#", 30); - } - - if (!showRowNumbers) { - table.setColumnCollapsed("#", true); - } - } else { - Object[] row = new Object[1]; - row[0] = "Metadata unavailable"; - table.addContainerProperty(1, String.class, null); - table.setColumnHeader(1, "Status"); - table.addItem(row, 1); - } - - return table; - } finally { - JdbcSqlTemplate.close(rs); - } - } - - public static String[] getHeaderCaptions(Grid grid) { - List headers = new ArrayList(); - List columns = grid.getColumns(); - for (Column column : columns) { - headers.add(column.getHeaderCaption()); - } - return headers.toArray(new String[headers.size()]); - } - - public static Grid putResultsInGrid(final ResultSet rs, org.jumpmind.db.model.Table resultTable, int maxResultSize, final boolean showRowNumbers, String... excludeValues) - throws SQLException { - - final Grid grid = new Grid(); - grid.setSelectionMode(SelectionMode.MULTI); - grid.setColumnReorderingAllowed(true); - grid.setData(new HashMap>()); - - final ResultSetMetaData meta = rs.getMetaData(); - int columnCount = meta.getColumnCount(); - grid.addColumn("#", Integer.class).setHeaderCaption("#").setHidable(true); - Set columnNames = new HashSet(); - Set skipColumnIndexes = new HashSet(); - 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 targetType, Locale locale) - throws com.vaadin.v7.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 targetType, Locale locale) - throws com.vaadin.v7.data.util.converter.Converter.ConversionException { - if (value == null) { - return NULL_TEXT; - } else { - return value.toString(); - } - } - }); + grid.getColumn("#").setWidth(95); } else { - column.setConverter(new Converter() { - private static final long serialVersionUID = 1L; - - @Override - public Object convertToModel(String value, Class targetType, Locale locale) - throws com.vaadin.v7.data.util.converter.Converter.ConversionException { - return null; - } - - @Override - public String convertToPresentation(Object value, Class targetType, Locale locale) - throws com.vaadin.v7.data.util.converter.Converter.ConversionException { - if (value == null) { - return NULL_TEXT; - } else { - return value.toString(); - } - } - - @Override - public Class getModelType() { - return Object.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - - }); + grid.getColumn("#").setWidth(115); } - } 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; - } - row[rowIndex] = o; - rowIndex++; + if (showRowNumbers) { + grid.setFrozenColumnCount(1); } } - grid.addRow(row); - rowNumber++; - } - - if (rowNumber < 100) { - grid.getColumn("#").setWidth(75); - } else if (rowNumber < 1000) { - grid.getColumn("#").setWidth(95); } else { - grid.getColumn("#").setWidth(115); + grid.addColumn(row -> row.get(0)).setCaption("Status"); + List innerList = new ArrayList(); + innerList.add("Metadata unavailable"); + outerList.add(innerList); } - - if (!showRowNumbers) { - grid.getColumn("#").setHidden(true); - } else { - grid.setFrozenColumnCount(1); - } - - - + grid.setItems(outerList); return grid; } @@ -583,12 +352,6 @@ public static String formatDateTime(Date dateTime) { } } - public static void addItems(List items, Container container) { - for (Object item : items) { - container.addItem(item); - } - } - public static String getJdbcTypeValue(String type) { String value = null; if (type.equalsIgnoreCase("CHAR")) { @@ -660,17 +423,4 @@ public static Label createSeparator() { separator.setWidthUndefined(); return separator; } - - public static AbstractSelect createComboBox() { - return createComboBox(null); - } - - public static AbstractSelect createComboBox(String name) { - NativeSelect cb = name == null ? new NativeSelect() : new NativeSelect(name); - cb.setImmediate(true); - cb.setWidth(16, Unit.EM); - cb.setHeight(2.15f, Unit.EM); - cb.setNullSelectionAllowed(false); - return cb; - } } diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/DateColumnFormatter.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/DateColumnFormatter.java deleted file mode 100644 index cac41a9b3e..0000000000 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/DateColumnFormatter.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Licensed to JumpMind Inc under one or more contributor - * license agreements. See the NOTICE file distributed - * with this work for additional information regarding - * copyright ownership. JumpMind Inc licenses this file - * to you under the GNU General Public License, version 3.0 (GPLv3) - * (the "License"); you may not use this file except in compliance - * with the License. - * - * You should have received a copy of the GNU General Public License, - * version 3.0 (GPLv3) along with this library; if not, see - * . - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jumpmind.vaadin.ui.common; - -import java.util.Date; - -import com.vaadin.v7.data.Property; -import com.vaadin.ui.Component; -import com.vaadin.ui.Label; -import com.vaadin.v7.ui.Table; - -public class DateColumnFormatter implements Table.ColumnGenerator { - - private static final long serialVersionUID = 1L; - - public Component generateCell(Table source, Object itemId, Object columnId) { - Property prop = source.getItem(itemId).getItemProperty(columnId); - if (prop.getType().equals(Date.class)) { - return new Label(CommonUiUtils.formatDateTime((Date) prop.getValue())); - } - return null; - } - -} diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/DurationConverter.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/DurationConverter.java deleted file mode 100644 index b85d3fe536..0000000000 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/DurationConverter.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.jumpmind.vaadin.ui.common; - -import java.util.Locale; - -import com.vaadin.v7.data.util.converter.StringToLongConverter; - -public class DurationConverter extends StringToLongConverter { - - private static final long serialVersionUID = 1L; - - public DurationConverter() { - } - - @Override - public String convertToPresentation(Long value, Class targetType, Locale locale) - throws com.vaadin.v7.data.util.converter.Converter.ConversionException { - return value != null ? CommonUiUtils.formatDuration(value) : ""; - } -} diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/DurationFormatter.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/DurationFormatter.java deleted file mode 100644 index ca9282b30d..0000000000 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/DurationFormatter.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Licensed to JumpMind Inc under one or more contributor - * license agreements. See the NOTICE file distributed - * with this work for additional information regarding - * copyright ownership. JumpMind Inc licenses this file - * to you under the GNU General Public License, version 3.0 (GPLv3) - * (the "License"); you may not use this file except in compliance - * with the License. - * - * You should have received a copy of the GNU General Public License, - * version 3.0 (GPLv3) along with this library; if not, see - * . - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jumpmind.vaadin.ui.common; - -import com.vaadin.v7.data.Property; -import com.vaadin.ui.Component; -import com.vaadin.ui.Label; -import com.vaadin.v7.ui.Table; - -public class DurationFormatter implements Table.ColumnGenerator { - - private static final long serialVersionUID = 1L; - - public Component generateCell(Table source, Object itemId, Object columnId) { - Property prop = source.getItem(itemId).getItemProperty(columnId); - if (prop.getType().equals(Long.class)) { - return new Label(CommonUiUtils.formatDuration((Long)prop.getValue())); - } - return null; - } -} diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/Grid7DataProvider.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/Grid7DataProvider.java deleted file mode 100644 index 0dd589f47c..0000000000 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/Grid7DataProvider.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.jumpmind.vaadin.ui.common; - -import java.util.Collection; -import java.util.List; - -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.Column; - -public class Grid7DataProvider implements IDataProvider { - - private Grid grid; - - public Grid7DataProvider(Grid grid) { - this.grid = grid; - } - - @Override - public Collection getRowItems() { - return grid.getContainerDataSource().getItemIds(); - } - - @Override - public List getColumns() { - return grid.getColumns(); - } - - @Override - public Object getCellValue(Object item, Object column) { - if(column instanceof Column) { - Object propId = ((Column)column).getPropertyId(); - return grid.getContainerDataSource().getContainerProperty(item, propId).getValue(); - } - return null; - } - - @Override - public boolean isHeaderVisible() { - return grid.isHeaderVisible(); - } - - @Override - public String getHeaderValue(Object column) { - Object propId = ((Column)column).getPropertyId(); - return grid.getDefaultHeaderRow().getCell(propId).getText(); - } - -} \ No newline at end of file diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/ImmediateUpdatePasswordField.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/ImmediateUpdatePasswordField.java deleted file mode 100644 index c57c480c3b..0000000000 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/ImmediateUpdatePasswordField.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Licensed to JumpMind Inc under one or more contributor - * license agreements. See the NOTICE file distributed - * with this work for additional information regarding - * copyright ownership. JumpMind Inc licenses this file - * to you under the GNU General Public License, version 3.0 (GPLv3) - * (the "License"); you may not use this file except in compliance - * with the License. - * - * You should have received a copy of the GNU General Public License, - * version 3.0 (GPLv3) along with this library; if not, see - * . - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jumpmind.vaadin.ui.common; - -import com.vaadin.v7.event.FieldEvents.TextChangeEvent; -import com.vaadin.v7.event.FieldEvents.TextChangeListener; -import com.vaadin.v7.ui.PasswordField; - -public abstract class ImmediateUpdatePasswordField extends PasswordField { - - private static final long serialVersionUID = 1L; - - boolean initialized = false; - - public ImmediateUpdatePasswordField(String caption) { - super(caption); - setImmediate(true); - setNullRepresentation(""); - setTextChangeEventMode(TextChangeEventMode.LAZY); - setTextChangeTimeout(200); - addTextChangeListener(new TextChangeListener() { - private static final long serialVersionUID = 1L; - - @Override - public void textChange(TextChangeEvent event) { - save(event.getText()); - } - }); - } - - abstract protected void save(String text); -} diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/ImmediateUpdateTextArea.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/ImmediateUpdateTextArea.java deleted file mode 100644 index 9199e7b26e..0000000000 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/ImmediateUpdateTextArea.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Licensed to JumpMind Inc under one or more contributor - * license agreements. See the NOTICE file distributed - * with this work for additional information regarding - * copyright ownership. JumpMind Inc licenses this file - * to you under the GNU General Public License, version 3.0 (GPLv3) - * (the "License"); you may not use this file except in compliance - * with the License. - * - * You should have received a copy of the GNU General Public License, - * version 3.0 (GPLv3) along with this library; if not, see - * . - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jumpmind.vaadin.ui.common; - -import org.apache.commons.lang.StringUtils; - -import com.vaadin.v7.event.FieldEvents.TextChangeEvent; -import com.vaadin.v7.event.FieldEvents.TextChangeListener; -import com.vaadin.v7.ui.TextArea; - -public abstract class ImmediateUpdateTextArea extends TextArea { - - private static final long serialVersionUID = 1L; - - String startValue; - - boolean initialized = false; - - public ImmediateUpdateTextArea(String caption) { - super(caption); - setImmediate(true); - setNullRepresentation(""); - setTextChangeEventMode(TextChangeEventMode.LAZY); - setTextChangeTimeout(200); - addTextChangeListener(new TextChangeListener() { - private static final long serialVersionUID = 1L; - @Override - public void textChange(TextChangeEvent event) { - if (!StringUtils.equals(startValue, event.getText())) { - save(event.getText()); - } - } - }); - } - - abstract protected void save(String text); - -} diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/ImmediateUpdateTextField.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/ImmediateUpdateTextField.java deleted file mode 100644 index 8b998d11c0..0000000000 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/ImmediateUpdateTextField.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Licensed to JumpMind Inc under one or more contributor - * license agreements. See the NOTICE file distributed - * with this work for additional information regarding - * copyright ownership. JumpMind Inc licenses this file - * to you under the GNU General Public License, version 3.0 (GPLv3) - * (the "License"); you may not use this file except in compliance - * with the License. - * - * You should have received a copy of the GNU General Public License, - * version 3.0 (GPLv3) along with this library; if not, see - * . - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jumpmind.vaadin.ui.common; - -import com.vaadin.v7.event.FieldEvents.TextChangeEvent; -import com.vaadin.v7.event.FieldEvents.TextChangeListener; -import com.vaadin.v7.ui.TextField; - -public abstract class ImmediateUpdateTextField extends TextField { - - private static final long serialVersionUID = 1L; - - boolean initialized = false; - - public ImmediateUpdateTextField(String caption) { - super(caption); - setImmediate(true); - setNullRepresentation(""); - setTextChangeEventMode(TextChangeEventMode.LAZY); - setTextChangeTimeout(200); - addTextChangeListener(new TextChangeListener() { - private static final long serialVersionUID = 1L; - @Override - public void textChange(TextChangeEvent event) { - save(event.getText()); - } - }); - } - - protected abstract void save(String text); -} diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/MultiSelectTable.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/MultiSelectTable.java deleted file mode 100644 index becb90aa67..0000000000 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/MultiSelectTable.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Licensed to JumpMind Inc under one or more contributor - * license agreements. See the NOTICE file distributed - * with this work for additional information regarding - * copyright ownership. JumpMind Inc licenses this file - * to you under the GNU General Public License, version 3.0 (GPLv3) - * (the "License"); you may not use this file except in compliance - * with the License. - * - * You should have received a copy of the GNU General Public License, - * version 3.0 (GPLv3) along with this library; if not, see - * . - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jumpmind.vaadin.ui.common; - -import java.util.Set; - -import com.vaadin.v7.event.ItemClickEvent; -import com.vaadin.v7.event.ItemClickEvent.ItemClickListener; -import com.vaadin.shared.MouseEventDetails.MouseButton; -import com.vaadin.v7.ui.Table; - -public class MultiSelectTable extends Table { - - private static final long serialVersionUID = 1L; - - private Set lastSelected; - - public MultiSelectTable() { - setMultiSelect(true); - setSelectable(true); - - addValueChangeListener(new ValueChangeListener() { - private static final long serialVersionUID = 1L; - @SuppressWarnings("unchecked") - @Override - public void valueChange(com.vaadin.v7.data.Property.ValueChangeEvent event) { - lastSelected = (Set) getValue(); - } - }); - - addItemClickListener(new ItemClickListener() { - - private static final long serialVersionUID = 1L; - - @Override - public void itemClick(ItemClickEvent event) { - if (event.getButton() == MouseButton.LEFT) { - if (lastSelected != null && lastSelected.contains(event.getItemId())) { - unselect(event.getItemId()); - } - } - } - }); - } - - @SuppressWarnings("unchecked") - public Set getSelected() { - return (Set)getValue(); - } -} diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/NotifyDialog.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/NotifyDialog.java index c9f2e41f43..4bd9d79cb3 100644 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/NotifyDialog.java +++ b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/NotifyDialog.java @@ -24,14 +24,14 @@ import org.apache.commons.lang.exception.ExceptionUtils; -import com.vaadin.server.FontAwesome; +import com.vaadin.icons.VaadinIcons; import com.vaadin.shared.ui.MarginInfo; -import com.vaadin.v7.shared.ui.label.ContentMode; +import com.vaadin.shared.ui.ContentMode; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.HorizontalLayout; -import com.vaadin.v7.ui.Label; +import com.vaadin.ui.Label; import com.vaadin.ui.Notification.Type; import com.vaadin.ui.UI; @@ -59,7 +59,7 @@ public NotifyDialog(String caption, String text, final Throwable ex, Type type) text = isNotBlank(text) ? text : (ex != null ? ex.getMessage() : ""); if (type == Type.ERROR_MESSAGE) { - setIcon(FontAwesome.BAN); + setIcon(VaadinIcons.BAN); } final String message = text; diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/PromptDialog.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/PromptDialog.java index 8d012277e3..ebb330a2b1 100644 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/PromptDialog.java +++ b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/PromptDialog.java @@ -30,7 +30,7 @@ import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; -import com.vaadin.v7.ui.TextField; +import com.vaadin.ui.TextField; import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; @@ -63,10 +63,9 @@ public PromptDialog(String caption, String text, String defaultValue, final TextField field = new TextField(); field.setWidth(100, Unit.PERCENTAGE); - field.setNullRepresentation(""); field.setValue(defaultValue); if (defaultValue != null) { - field.setSelectionRange(0, defaultValue.length()); + field.setSelection(0, defaultValue.length()); } layout.addComponent(field); diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/ReadOnlyTextAreaDialog.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/ReadOnlyTextAreaDialog.java index 2069aca1d5..af677ab621 100644 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/ReadOnlyTextAreaDialog.java +++ b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/ReadOnlyTextAreaDialog.java @@ -31,6 +31,8 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; import javax.sql.DataSource; @@ -45,24 +47,19 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.vaadin.v7.data.Property.ValueChangeEvent; -import com.vaadin.v7.data.Property.ValueChangeListener; -import com.vaadin.v7.event.FieldEvents.TextChangeEvent; -import com.vaadin.v7.event.FieldEvents.TextChangeListener; import com.vaadin.server.FileDownloader; import com.vaadin.server.Resource; import com.vaadin.server.StreamResource; import com.vaadin.server.StreamResource.StreamSource; -import com.vaadin.v7.ui.AbstractSelect; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; -import com.vaadin.v7.ui.ComboBox; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; +import com.vaadin.ui.NativeSelect; import com.vaadin.ui.Notification.Type; -import com.vaadin.v7.ui.TextArea; +import com.vaadin.ui.TextArea; import com.vaadin.ui.Upload; import com.vaadin.ui.Upload.Receiver; import com.vaadin.ui.Upload.SucceededEvent; @@ -78,7 +75,7 @@ public class ReadOnlyTextAreaDialog extends ResizableWindow { VerticalLayout wrapper; protected HorizontalLayout buttonLayout; protected TextArea textField; - protected AbstractSelect displayBox; + protected NativeSelect displayBox; protected Button downloadButton; protected Table table; protected Column column; @@ -102,7 +99,7 @@ public ReadOnlyTextAreaDialog(final String title, final String value, Table tabl wrapper.setSizeFull(); textField = new TextArea(); textField.setSizeFull(); - textField.setWordwrap(false); + textField.setWordWrap(false); wrapper.addComponent(textField); addComponent(wrapper, 1); @@ -113,21 +110,14 @@ public ReadOnlyTextAreaDialog(final String title, final String value, Table tabl addComponent(buttonLayout); if (value != null && isEncodedInHex) { - displayBox = new ComboBox("Display As"); - displayBox.addItem("Hex"); - displayBox.addItem("Text"); - displayBox.addItem("Decimal"); - displayBox.setNullSelectionAllowed(false); - displayBox.select("Hex"); - displayBox.addValueChangeListener(new ValueChangeListener() { - - private static final long serialVersionUID = 1L; - - @Override - public void valueChange(ValueChangeEvent event) { - updateTextField((String) displayBox.getValue(), value); - } - }); + List displayList = new ArrayList(); + displayList.add("Hex"); + displayList.add("Text"); + displayList.add("Decimal"); + displayBox = new NativeSelect("Display As", displayList); + displayBox.setEmptySelectionAllowed(false); + displayBox.setSelectedItem("Hex"); + displayBox.addValueChangeListener(event -> updateTextField((String) displayBox.getValue(), value)); buttonLayout.addComponent(displayBox); } @@ -145,17 +135,11 @@ public void valueChange(ValueChangeEvent event) { buttonLayout.setComponentAlignment(closeButton, Alignment.BOTTOM_RIGHT); textField.setValue(value); - textField.addTextChangeListener(new TextChangeListener() { - - private static final long serialVersionUID = 1L; - - @Override - public void textChange(TextChangeEvent event) { - if (displayBox != null) { - updateTextField((String) displayBox.getValue(), value); - } else { - textField.setValue(value); - } + textField.addValueChangeListener(event -> { + if (displayBox != null) { + updateTextField((String) displayBox.getValue(), value); + } else { + textField.setValue(value); } }); } diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/AbstractMetaDataTableCreator.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/AbstractMetaDataGridCreator.java similarity index 81% rename from symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/AbstractMetaDataTableCreator.java rename to symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/AbstractMetaDataGridCreator.java index 471ba680f7..097bdc4209 100644 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/AbstractMetaDataTableCreator.java +++ b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/AbstractMetaDataGridCreator.java @@ -26,6 +26,7 @@ import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.List; import org.jumpmind.db.sql.IConnectionCallback; import org.jumpmind.db.sql.JdbcSqlTemplate; @@ -34,9 +35,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.vaadin.v7.ui.Table; +import com.vaadin.ui.Grid; -abstract public class AbstractMetaDataTableCreator { +abstract public class AbstractMetaDataGridCreator { final Logger log = LoggerFactory.getLogger(getClass()); @@ -52,31 +53,31 @@ abstract public class AbstractMetaDataTableCreator { "TABLE_CATALOG", "TABLE_SCHEMA", "PKTABLE_NAME", "PKTABLE_CATALOG", "PKTABLE_SCHEMA", "TABLE_CAT", "TABLE_SCHEM" }; - public AbstractMetaDataTableCreator(JdbcSqlTemplate sqlTemplate, org.jumpmind.db.model.Table table, + public AbstractMetaDataGridCreator(JdbcSqlTemplate sqlTemplate, org.jumpmind.db.model.Table table, Settings settings) { this.sqlTemplate = sqlTemplate; this.table = table; this.settings = settings; } - public Table create() { - return sqlTemplate.execute(new IConnectionCallback() { + public Grid> create() { + return sqlTemplate.execute(new IConnectionCallback>>() { - public com.vaadin.v7.ui.Table execute(Connection con) throws SQLException { + public Grid> execute(Connection con) throws SQLException { TypedProperties properties = settings.getProperties(); ResultSet rs = null; - Table t = null; + Grid> g = null; try { DatabaseMetaData metadata = con.getMetaData(); rs = getMetaDataResultSet(metadata); - t = CommonUiUtils.putResultsInTable(rs, Integer.MAX_VALUE, + g = CommonUiUtils.putResultsInGrid(rs, Integer.MAX_VALUE, properties.is(SQL_EXPLORER_SHOW_ROW_NUMBERS), getColumnsToExclude()); - t.setSizeFull(); - return t; + g.setSizeFull(); + return g; } catch (Exception ex) { log.info("Failed to retrieve meta data. It might be that this driver doesn't support it. Turn on debug logging to see the resulting stacktrace"); log.debug("", ex); - return CommonUiUtils.createTable(); + return new Grid>(); } finally { JdbcSqlTemplate.close(rs); } diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/ColumnMetaDataTableCreator.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/ColumnMetaDataTableCreator.java index 0bc957e361..66df8a6003 100644 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/ColumnMetaDataTableCreator.java +++ b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/ColumnMetaDataTableCreator.java @@ -27,7 +27,7 @@ import org.jumpmind.db.model.Table; import org.jumpmind.db.sql.JdbcSqlTemplate; -public class ColumnMetaDataTableCreator extends AbstractMetaDataTableCreator { +public class ColumnMetaDataTableCreator extends AbstractMetaDataGridCreator { public ColumnMetaDataTableCreator(JdbcSqlTemplate sqlTemplate, Table table, Settings settings) { super(sqlTemplate, table, settings); diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/DatabaseInfoPanel.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/DatabaseInfoPanel.java index cffbdb228a..4342ec3c90 100644 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/DatabaseInfoPanel.java +++ b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/DatabaseInfoPanel.java @@ -18,12 +18,13 @@ import com.vaadin.ui.AbstractLayout; import com.vaadin.ui.Component; +import com.vaadin.ui.Grid; import com.vaadin.ui.TabSheet; import com.vaadin.ui.TabSheet.SelectedTabChangeEvent; import com.vaadin.ui.TabSheet.SelectedTabChangeListener; import com.vaadin.ui.TabSheet.Tab; import com.vaadin.ui.VerticalLayout; -import com.vaadin.v7.ui.Table; +import com.vaadin.ui.Grid.SelectionMode; public class DatabaseInfoPanel extends VerticalLayout implements IInfoPanel { @@ -62,8 +63,8 @@ public void selectedTabChange(SelectedTabChangeEvent event) { c = ((DataSource) db.getPlatform().getDataSource()).getConnection(); DatabaseMetaData metaData = c.getMetaData(); - tabSheet.addTab(createTabData(createTableWithReflection(DatabaseMetaData.class, metaData)), "Meta Data"); - tabSheet.addTab(createTabData(createTableWithReflection(Connection.class, c)), "Connection"); + tabSheet.addTab(createTabData(createGridWithReflection(DatabaseMetaData.class, metaData)), "Meta Data"); + tabSheet.addTab(createTabData(createGridWithReflection(Connection.class, c)), "Connection"); try{ ResultSet rs = null; @@ -72,7 +73,7 @@ public void selectedTabChange(SelectedTabChangeEvent event) { } catch(SQLException e) { log.debug("Could not create Client Info Properties tab", e.getMessage()); } - Table clientInfoProperties = CommonUiUtils.putResultsInTable(rs, Integer.MAX_VALUE, false); + Grid> clientInfoProperties = CommonUiUtils.putResultsInGrid(rs, Integer.MAX_VALUE, false); clientInfoProperties.setSizeFull(); tabSheet.addTab(createTabData(clientInfoProperties), "Client Info Properties"); } catch (AbstractMethodError e) { @@ -80,7 +81,7 @@ public void selectedTabChange(SelectedTabChangeEvent event) { } try { - Table catalogs = CommonUiUtils.putResultsInTable(metaData.getCatalogs(), Integer.MAX_VALUE, false); + Grid> catalogs = CommonUiUtils.putResultsInGrid(metaData.getCatalogs(), Integer.MAX_VALUE, false); catalogs.setSizeFull(); tabSheet.addTab(createTabData(catalogs), "Catalogs"); } catch (AbstractMethodError e) { @@ -88,11 +89,11 @@ public void selectedTabChange(SelectedTabChangeEvent event) { } try { - Table schemas; + Grid> schemas; try { - schemas = CommonUiUtils.putResultsInTable(metaData.getSchemas(), Integer.MAX_VALUE, false); + schemas = CommonUiUtils.putResultsInGrid(metaData.getSchemas(), Integer.MAX_VALUE, false); } catch (SQLException e) { - schemas = CommonUiUtils.putResultsInTable(metaData.getSchemas("", null), Integer.MAX_VALUE, false); + schemas = CommonUiUtils.putResultsInGrid(metaData.getSchemas("", null), Integer.MAX_VALUE, false); } schemas.setSizeFull(); tabSheet.addTab(createTabData(schemas), "Schemas"); @@ -101,7 +102,7 @@ public void selectedTabChange(SelectedTabChangeEvent event) { } try { - Table tableTypes = CommonUiUtils.putResultsInTable(metaData.getTableTypes(), Integer.MAX_VALUE, false); + Grid> tableTypes = CommonUiUtils.putResultsInGrid(metaData.getTableTypes(), Integer.MAX_VALUE, false); tableTypes.setSizeFull(); tabSheet.addTab(createTabData(tableTypes), "Table Types"); } catch (AbstractMethodError e) { @@ -109,7 +110,7 @@ public void selectedTabChange(SelectedTabChangeEvent event) { } try { - Table dataTypes = CommonUiUtils.putResultsInTable(metaData.getTypeInfo(), Integer.MAX_VALUE, false); + Grid> dataTypes = CommonUiUtils.putResultsInGrid(metaData.getTypeInfo(), Integer.MAX_VALUE, false); dataTypes.setSizeFull(); tabSheet.addTab(createTabData(dataTypes), "Data Types"); } catch (AbstractMethodError e) { @@ -117,31 +118,31 @@ public void selectedTabChange(SelectedTabChangeEvent event) { } try { - tabSheet.addTab(createTabData(createTableFromString(metaData.getNumericFunctions(), "Numeric Functions")), "Numeric Functions"); + tabSheet.addTab(createTabData(createGridFromString(metaData.getNumericFunctions(), "Numeric Functions")), "Numeric Functions"); } catch (AbstractMethodError e) { log.debug("Could not create Numeric Functions tab", e); } try { - tabSheet.addTab(createTabData(createTableFromString(metaData.getStringFunctions(), "String Functions")), "String Functions"); + tabSheet.addTab(createTabData(createGridFromString(metaData.getStringFunctions(), "String Functions")), "String Functions"); } catch (AbstractMethodError e) { log.debug("Could not create String Functions tab", e); } try { - tabSheet.addTab(createTabData(createTableFromString(metaData.getSystemFunctions(), "System Functions")), "System Functions"); + tabSheet.addTab(createTabData(createGridFromString(metaData.getSystemFunctions(), "System Functions")), "System Functions"); } catch (AbstractMethodError e) { log.debug("Could not create System Functions tab", e); } try { - tabSheet.addTab(createTabData(createTableFromString(metaData.getTimeDateFunctions(), "Date/Time Functions")), "Date/Time Functions"); + tabSheet.addTab(createTabData(createGridFromString(metaData.getTimeDateFunctions(), "Date/Time Functions")), "Date/Time Functions"); } catch (AbstractMethodError e) { log.debug("Could not create Date/Time Functions tab", e); } try { - tabSheet.addTab(createTabData(createTableFromString(metaData.getSQLKeywords(), "Keywords")), "Keywords"); + tabSheet.addTab(createTabData(createGridFromString(metaData.getSQLKeywords(), "Keywords")), "Keywords"); } catch (AbstractMethodError e) { log.debug("Could not create Keywords tab", e); } @@ -162,45 +163,46 @@ public void selectedTabChange(SelectedTabChangeEvent event) { } } - public AbstractLayout createTabData(Table table) { + public AbstractLayout createTabData(Grid grid) { VerticalLayout layout = new VerticalLayout(); layout.setMargin(false); layout.setSizeFull(); - layout.addComponent(table); - layout.setExpandRatio(table, 1); + layout.addComponent(grid); + layout.setExpandRatio(grid, 1); return layout; } - private Table createTableWithReflection(Class reflectionClass, Object instance) { - Table table = CommonUiUtils.createTable(); - table.setSizeFull(); - table.setSortEnabled(true); - table.setSelectable(true); - table.setMultiSelect(true); + private Grid> createGridWithReflection(Class reflectionClass, Object instance) { + Grid> grid = new Grid>(); + grid.setSelectionMode(SelectionMode.MULTI); + grid.setSizeFull(); + grid.addItemClickListener(event -> { + grid.deselectAll(); + grid.select(event.getItem()); + }); - table.addContainerProperty(1, String.class, null); - table.setColumnHeader(1, "Property"); - table.setColumnWidth(1, 400); - table.addContainerProperty(2, Object.class, null); - table.setColumnHeader(2, "Value"); + grid.addColumn(row -> row.get(0)).setCaption("Property").setWidth(400); + grid.addColumn(row -> row.get(1)).setCaption("Value"); + List> outerList = new ArrayList>(); Method[] methods = reflectionClass.getMethods(); - int rowNumber = 1; for (Method method : methods) { if ((method.getReturnType().equals(Integer.TYPE) || method.getReturnType().equals(String.class) || method.getReturnType().equals(Boolean.TYPE)) && method.getParameterTypes().length == 0) { try { + List innerList = new ArrayList(); Object value = method.invoke(instance); - Object[] row = new Object[] {cleanMethodName(method.getName()), value}; - table.addItem(row, rowNumber); - rowNumber++; + innerList.add(cleanMethodName(method.getName())); + innerList.add(value); + outerList.add(innerList); } catch (Exception e) { log.debug("Could not invoke method "+method.getName(), e); } } } + grid.setItems(outerList); - return table; + return grid; } private String cleanMethodName(String methodName) { @@ -223,13 +225,17 @@ private String cleanMethodName(String methodName) { return methodName; } - - private Table createTableFromString(String data, String columnName) { - Table table = CommonUiUtils.createTable(); - table.setSizeFull(); - table.setSortEnabled(true); - table.setSelectable(true); - table.setMultiSelect(true); + + private Grid createGridFromString(String data, String columnName) { + Grid grid = new Grid(); + grid.setSelectionMode(SelectionMode.MULTI); + grid.setSizeFull(); + grid.addItemClickListener(event -> { + grid.deselectAll(); + grid.select(event.getItem()); + }); + + grid.addColumn(row -> row).setCaption(columnName); List values = new ArrayList(); int lastComma = 0; @@ -239,16 +245,11 @@ private Table createTableFromString(String data, String columnName) { lastComma = i + 1; } } + grid.setItems(values); - table.addContainerProperty(1, String.class, null); - table.setColumnHeader(1, columnName); - for (int i=0; i) { + Grid table = (Grid) target; TabularResultLayout layout = (TabularResultLayout) table.getParent(); reExecute(layout.getSql()); } else if (target instanceof AceEditor) { @@ -329,8 +329,8 @@ protected ShortcutListener createExecuteSqlScriptShortcutListener(){ @Override public void handleAction(Object sender, Object target){ - if (target instanceof Table) { - Table table = (Table) target; + if (target instanceof Grid) { + Grid table = (Grid) target; TabularResultLayout layout = (TabularResultLayout) table.getParent(); reExecute(layout.getSql()); }else if (target instanceof AceEditor){ diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/TableInfoPanel.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/TableInfoPanel.java index a5b6757c95..c126d42597 100644 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/TableInfoPanel.java +++ b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/TableInfoPanel.java @@ -40,13 +40,13 @@ import com.vaadin.icons.VaadinIcons; import com.vaadin.ui.AbstractLayout; import com.vaadin.ui.Component; +import com.vaadin.ui.Grid; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.ProgressBar; import com.vaadin.ui.TabSheet; import com.vaadin.ui.TabSheet.SelectedTabChangeEvent; import com.vaadin.ui.TabSheet.SelectedTabChangeListener; import com.vaadin.ui.TabSheet.Tab; -import com.vaadin.v7.ui.Table; import com.vaadin.ui.VerticalLayout; public class TableInfoPanel extends VerticalLayout implements IInfoPanel { @@ -85,7 +85,7 @@ public void selectedTabChange(SelectedTabChangeEvent event) { AbstractLayout layout = (AbstractLayout) tabSheet.getSelectedTab(); if (selectedCaption.equals("Data") && layout.getData() != null && layout.getData().equals(true)) { refreshData(table, user, db, settings, false); - } else if (layout.getData() != null && layout.getData() instanceof AbstractMetaDataTableCreator) { + } else if (layout.getData() != null && layout.getData() instanceof AbstractMetaDataGridCreator) { populate((VerticalLayout) layout); } } else if (tabSheet.getSelectedTab() instanceof AceEditor && @@ -198,7 +198,7 @@ public void run() { } - protected AbstractLayout create(AbstractMetaDataTableCreator creator) { + protected AbstractLayout create(AbstractMetaDataGridCreator creator) { VerticalLayout layout = new VerticalLayout(); layout.setMargin(false); layout.setSizeFull(); @@ -207,10 +207,10 @@ protected AbstractLayout create(AbstractMetaDataTableCreator creator) { } protected void populate(VerticalLayout layout) { - AbstractMetaDataTableCreator creator = (AbstractMetaDataTableCreator) layout.getData(); - Table table = creator.create(); - layout.addComponent(table); - layout.setExpandRatio(table, 1); + AbstractMetaDataGridCreator creator = (AbstractMetaDataGridCreator) layout.getData(); + Grid> grid = creator.create(); + layout.addComponent(grid); + layout.setExpandRatio(grid, 1); layout.setData(null); } diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/TabularResultLayout.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/TabularResultLayout.java index 0cbfdc5d4b..bbfa3bd5e0 100644 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/TabularResultLayout.java +++ b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/TabularResultLayout.java @@ -25,21 +25,13 @@ import static org.jumpmind.vaadin.ui.sqlexplorer.Settings.SQL_EXPLORER_MAX_RESULTS; import static org.jumpmind.vaadin.ui.sqlexplorer.Settings.SQL_EXPLORER_SHOW_ROW_NUMBERS; -import java.sql.Date; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.sql.Time; -import java.sql.Timestamp; -import java.sql.Types; -import java.text.NumberFormat; import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.Set; import javax.sql.DataSource; @@ -50,55 +42,33 @@ import org.jumpmind.db.model.Table; import org.jumpmind.db.platform.DatabaseInfo; import org.jumpmind.db.platform.IDdlReader; -import org.jumpmind.db.sql.SqlException; import org.jumpmind.properties.TypedProperties; import org.jumpmind.util.FormatUtils; import org.jumpmind.vaadin.ui.common.CommonUiUtils; import org.jumpmind.vaadin.ui.common.CsvExport; -import org.jumpmind.vaadin.ui.common.Grid7DataProvider; +import org.jumpmind.vaadin.ui.common.GridDataProvider; import org.jumpmind.vaadin.ui.common.IDataProvider; -import org.jumpmind.vaadin.ui.common.NotifyDialog; import org.jumpmind.vaadin.ui.common.ReadOnlyTextAreaDialog; import org.jumpmind.vaadin.ui.sqlexplorer.SqlRunner.ISqlRunnerListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.vaadin.contextmenu.ContextMenu; +import com.vaadin.data.provider.Query; import com.vaadin.icons.VaadinIcons; import com.vaadin.shared.MouseEventDetails.MouseButton; import com.vaadin.shared.ui.MarginInfo; import com.vaadin.ui.Alignment; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.Component; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.MenuBar; import com.vaadin.ui.MenuBar.Command; import com.vaadin.ui.MenuBar.MenuItem; import com.vaadin.ui.Notification; -import com.vaadin.ui.Notification.Type; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.themes.ValoTheme; -import com.vaadin.v7.data.Item; -import com.vaadin.v7.data.Property; -import com.vaadin.v7.data.Validator; -import com.vaadin.v7.data.fieldgroup.FieldGroup.CommitEvent; -import com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException; -import com.vaadin.v7.data.fieldgroup.FieldGroup.CommitHandler; -import com.vaadin.v7.data.util.converter.Converter; -import com.vaadin.v7.data.util.converter.StringToBigDecimalConverter; -import com.vaadin.v7.data.util.converter.StringToBooleanConverter; -import com.vaadin.v7.data.util.converter.StringToLongConverter; -import com.vaadin.v7.event.ItemClickEvent; -import com.vaadin.v7.event.ItemClickEvent.ItemClickListener; import com.vaadin.shared.ui.ContentMode; -import com.vaadin.v7.ui.CustomField; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.CellReference; -import com.vaadin.v7.ui.Grid.CellStyleGenerator; +import com.vaadin.ui.Grid; import com.vaadin.ui.Label; -import com.vaadin.v7.ui.TextField; public class TabularResultLayout extends VerticalLayout { @@ -124,7 +94,7 @@ public class TabularResultLayout extends VerticalLayout { String schemaName; - Grid grid; + Grid> grid; org.jumpmind.db.model.Table resultTable; @@ -188,23 +158,6 @@ protected void createTabularResultLayout() { grid = putResultsInGrid(settings.getProperties().getInt(SQL_EXPLORER_MAX_RESULTS)); grid.setSizeFull(); - initGridEditing(); - - grid.setCellStyleGenerator(new CellStyleGenerator() { - private static final long serialVersionUID = 1L; - - @Override - public String getStyle(CellReference cell) { - if (cell.getPropertyId().equals("#") && !grid.getSelectedRows().contains(cell.getItemId())) { - return "rowheader"; - } - if (cell.getValue() == null) { - return "italics"; - } - return null; - } - }); - ContextMenu menu = new ContextMenu(grid, true); menu.addItem(ACTION_SELECT, new MenuBar.Command() { @@ -248,39 +201,35 @@ public void menuSelected(MenuItem selectedItem) { buildFollowToMenu(); } - grid.addItemClickListener(new ItemClickListener() { - - private static final long serialVersionUID = 1L; - - @Override - public void itemClick(ItemClickEvent event) { - MouseButton button = event.getButton(); - if (button == MouseButton.LEFT) { - Object object = event.getPropertyId(); - if (object != null && !object.toString().equals("")) { - if (event.isDoubleClick() && !grid.isEditorEnabled()) { - Object prop = event.getPropertyId(); - String header = grid.getColumn(prop).getHeaderCaption(); - Property p = event.getItem().getItemProperty(prop); - if (p != null) { - String data = String.valueOf(p.getValue()); - boolean binary = resultTable != null ? resultTable.getColumnWithName(header).isOfBinaryType() : false; - if (binary) { - ReadOnlyTextAreaDialog.show(header, data.toUpperCase(), binary); - } else { - ReadOnlyTextAreaDialog.show(header, data, binary); - } - } + grid.addItemClickListener(event -> { + MouseButton button = event.getMouseEventDetails().getButton(); + if (button == MouseButton.LEFT) { + if (event.getMouseEventDetails().isDoubleClick()) { + String header = event.getColumn().getCaption(); + List, ?>> colList = grid.getColumns(); + Object o = null; + for (int i = 1; i < colList.size(); i++) { + if (colList.get(i).getCaption().equals(header)) { + o = event.getItem().get(i - 1); + break; + } + } + if (o != null) { + String data = String.valueOf(o); + boolean binary = resultTable != null ? resultTable.getColumnWithName(header).isOfBinaryType() : false; + if (binary) { + ReadOnlyTextAreaDialog.show(header, data.toUpperCase(), binary); } else { - Object row = event.getItemId(); - if (!grid.getSelectedRows().contains(row)) { - grid.deselectAll(); - grid.select(row); - } else { - grid.deselect(row); - } + ReadOnlyTextAreaDialog.show(header, data, binary); } } + } else { + if (!grid.getSelectedItems().contains(event.getItem())) { + grid.deselectAll(); + grid.select(event.getItem()); + } else { + grid.deselect(event.getItem()); + } } } }); @@ -288,7 +237,7 @@ public void itemClick(ItemClickEvent event) { this.addComponent(grid); this.setExpandRatio(grid, 1); - int count = (grid.getContainerDataSource().getItemIds().size()); + long count = (grid.getDataProvider().fetch(new Query<>()).count()); int maxResultsSize = settings.getProperties().getInt(SQL_EXPLORER_MAX_RESULTS); if (count >= maxResultsSize) { resultLabel.setValue("Limited to " + maxResultsSize + " rows;"); @@ -340,7 +289,7 @@ public void menuSelected(MenuBar.MenuItem selectedItem) { @Override public void menuSelected(MenuBar.MenuItem selectedItem) { - IDataProvider target = new Grid7DataProvider(grid); + IDataProvider target = new GridDataProvider(grid); CsvExport csvExport = null; if (target instanceof IDataProvider) { csvExport = new CsvExport((IDataProvider) target); @@ -394,17 +343,14 @@ protected void handleAction(String action) { final String schemaSeparator = dbInfo.getSchemaSeparator(); String[] columnHeaders = CommonUiUtils.getHeaderCaptions(grid); - Collection selectedRowsSet = grid.getSelectedRows(); - Iterator setIterator = selectedRowsSet.iterator(); + Set> selectedRowsSet = grid.getSelectedItems(); + Iterator> setIterator = selectedRowsSet.iterator(); while (setIterator.hasNext()) { List typeValueList = new ArrayList(); - int row = (Integer) setIterator.next(); - Item item = grid.getContainerDataSource().getItem(row); - Iterator iterator = item.getItemPropertyIds().iterator(); - iterator.next(); + List item = setIterator.next(); for (int i = 1; i < columnHeaders.length; i++) { - Object typeValue = item.getItemProperty(iterator.next()).getValue(); + Object typeValue = item.get(i - 1); if (typeValue instanceof String) { if ("".equals(typeValue) || "".equals(typeValue)) { typeValue = "null"; @@ -580,7 +526,7 @@ public void menuSelected(MenuItem selectedItem) { } protected void followTo(ForeignKey foreignKey) { - Collection selectedRows = grid.getSelectedRows(); + Set> selectedRows = grid.getSelectedItems(); if (selectedRows.size() > 0) { log.info("Following foreign key to " + foreignKey.getForeignTableName()); @@ -609,11 +555,16 @@ protected void followTo(ForeignKey foreignKey) { try { PreparedStatement ps = ((DataSource) db.getPlatform().getDataSource()).getConnection().prepareStatement(sql); int i = 1; - for (Object row : selectedRows) { + for (List row : selectedRows) { for (Reference ref : references) { - Object targetObject = grid.getContainerDataSource().getItem(row).getItemProperty(ref.getLocalColumnName()).getValue(); + int colNum = 0; + for (Grid.Column, ?> col : grid.getColumns()) { + if (col.getCaption().equals(ref.getLocalColumnName())) { + break; + } + } int targetType = ref.getForeignColumn().getMappedTypeCode(); - ps.setObject(i, targetObject, targetType); + ps.setObject(i, row.get(colNum - 1), targetType); i++; } } @@ -657,7 +608,7 @@ protected String createFollowSql(Table foreignTable, Reference[] references, int return sql.toString(); } - protected Grid putResultsInGrid(int maxResultSize) throws SQLException { + protected Grid> putResultsInGrid(int maxResultSize) throws SQLException { String parsedSql = sql; String first = ""; String second = ""; @@ -751,7 +702,7 @@ protected Grid putResultsInGrid(int maxResultSize) throws SQLException { } TypedProperties properties = settings.getProperties(); - return CommonUiUtils.putResultsInGrid(rs, resultTable, properties.getInt(SQL_EXPLORER_MAX_RESULTS), + return CommonUiUtils.putResultsInGrid(rs, properties.getInt(SQL_EXPLORER_MAX_RESULTS), properties.is(SQL_EXPLORER_SHOW_ROW_NUMBERS), getColumnsToExclude()); } @@ -759,359 +710,4 @@ protected Grid putResultsInGrid(int maxResultSize) throws SQLException { protected String[] getColumnsToExclude() { return new String[0]; } - - private void initGridEditing() { - if (resultTable != null) { - grid.setEditorEnabled(true); - List columns = grid.getColumns(); - List primaryKeyEditors = new ArrayList(); - for (com.vaadin.v7.ui.Grid.Column gridColumn : columns) { - String header = gridColumn.getHeaderCaption(); - Column tableColumn = resultTable.getColumnWithName(header); - if (columns.get(0).equals(gridColumn) || (tableColumn != null && tableColumn.isAutoIncrement() - && !db.getPlatform().getDatabaseInfo().isAutoIncrementUpdateAllowed())) { - gridColumn.setEditable(false); - } else if (tableColumn != null && db.getPlatform().isLob(tableColumn.getMappedTypeCode())) { - gridColumn.setEditorField(new LobEditorField(header)); - } else if (tableColumn != null) { - setEditor(gridColumn, tableColumn, primaryKeyEditors); - } - } - - for (TextField editor : primaryKeyEditors) { - editor.addValidator(new PrimaryKeyValidator(primaryKeyEditors)); - } - - initCommit(); - } else { - log.info("Table editing disabled."); - } - } - - private void setEditor(Grid.Column gridColumn, Column tableColumn, List primaryKeyEditors) { - TextField editor = new TextField(); - int typeCode = tableColumn.getMappedTypeCode(); - - switch (typeCode) { - case Types.DATE: - editor.setConverter(new ObjectConverter(Date.class, typeCode)); - break; - case Types.TIME: - editor.setConverter(new ObjectConverter(Time.class, typeCode)); - break; - case Types.TIMESTAMP: - editor.setConverter(new ObjectConverter(Timestamp.class, typeCode)); - break; - case Types.BIT: - editor.setConverter(new StringToBooleanConverter()); - break; - case Types.TINYINT: - case Types.SMALLINT: - case Types.BIGINT: - case Types.INTEGER: - editor.setConverter(new StringToLongConverter() { - private static final long serialVersionUID = 1L; - - public NumberFormat getFormat(Locale locale) { - NumberFormat format = super.getFormat(locale); - format.setGroupingUsed(false); - return format; - } - }); - break; - case Types.FLOAT: - case Types.DOUBLE: - case Types.REAL: - case Types.NUMERIC: - case Types.DECIMAL: - editor.setConverter(new StringToBigDecimalConverter() { - private static final long serialVersionUID = 1L; - - public NumberFormat getFormat(Locale locale) { - NumberFormat format = super.getFormat(locale); - format.setGroupingUsed(false); - return format; - } - }); - break; - default: - break; - } - - editor.addValidator(new TableChangeValidator(editor, tableColumn)); - - editor.setNullRepresentation(""); - if (!tableColumn.isRequired()) { - editor.setNullSettingAllowed(true); - } - - if (tableColumn.isPrimaryKey()) { - primaryKeyEditors.add(editor); - } - - gridColumn.setEditorField(editor); - } - - private void initCommit() { - grid.getEditorFieldGroup().addCommitHandler(new CommitHandler() { - - private static final long serialVersionUID = 1L; - - Map unchangedValues; - Object[] params; - int[] types; - - @Override - public void preCommit(CommitEvent commitEvent) throws CommitException { - Item row = commitEvent.getFieldBinder().getItemDataSource(); - unchangedValues = new HashMap(); - params = new Object[resultTable.getPrimaryKeyColumnCount() + 1]; - types = new int[params.length]; - int paramCount = 1; - for (Object id : row.getItemPropertyIds()) { - unchangedValues.put(id, row.getItemProperty(id).getValue()); - if (resultTable.getPrimaryKeyColumnIndex(id.toString()) >= 0) { - params[paramCount] = commitEvent.getFieldBinder().getItemDataSource().getItemProperty(id).getValue(); - types[paramCount] = resultTable.getColumnWithName(id.toString()).getMappedTypeCode(); - paramCount++; - } - } - } - - @Override - public void postCommit(CommitEvent commitEvent) throws CommitException { - Item row = commitEvent.getFieldBinder().getItemDataSource(); - for (Object id : row.getItemPropertyIds()) { - if (grid.getColumn(id).isEditable() - && !db.getPlatform().isLob(resultTable.getColumnWithName(id.toString()).getMappedTypeCode())) { - String sql = buildUpdate(resultTable, id.toString(), resultTable.getPrimaryKeyColumnNames()); - params[0] = row.getItemProperty(id).getValue(); - if ((params[0] == null && unchangedValues.get(id) == null) - || (params[0] != null && params[0].equals(unchangedValues.get(id)))) { - continue; - } - types[0] = resultTable.getColumnWithName(id.toString()).getMappedTypeCode(); - for (int i = 0; i < types.length; i++) { - if (types[i] == Types.DATE && db.getPlatform().getDdlBuilder().getDatabaseInfo().isDateOverridesToTimestamp()) { - types[i] = Types.TIMESTAMP; - } - } - try { - db.getPlatform().getSqlTemplate().update(sql, params, types); - } catch (SqlException e) { - NotifyDialog.show("Error", - "The table could not be updated.
" - + "Cause: the sql update statement failed to execute.

" - + "To view the Stack Trace, click \"Details\".", - e, Type.ERROR_MESSAGE); - } - } - } - listener.reExecute(sql); - } - }); - } - - protected Object[] getPrimaryKeys() { - String[] columnNames = resultTable.getPrimaryKeyColumnNames(); - Object[] pks = new Object[columnNames.length]; - Item row = grid.getContainerDataSource().getItem(grid.getEditedItemId()); - int index = 0; - for (String columnName : columnNames) { - Property p = row.getItemProperty(columnName); - if (p != null) { - pks[index++] = p.getValue(); - } else { - return null; - } - } - return pks; - } - - protected String buildUpdate(Table table, String columnName, String[] pkColumnNames) { - StringBuilder sql = new StringBuilder("update "); - DatabaseInfo dbInfo = db.getPlatform().getDatabaseInfo(); - String quote = db.getPlatform().getDdlBuilder().isDelimitedIdentifierModeOn() ? dbInfo.getDelimiterToken() : ""; - sql.append(table.getQualifiedTableName(quote, dbInfo.getCatalogSeparator(), dbInfo.getSchemaSeparator())); - sql.append(" set "); - sql.append(quote); - sql.append(columnName); - sql.append(quote); - sql.append("=? where "); - for (String col : pkColumnNames) { - sql.append(quote); - sql.append(col); - sql.append(quote); - sql.append("=? and "); - } - sql.delete(sql.length() - 5, sql.length()); - return sql.toString(); - } - - class LobEditorField extends CustomField { - - private static final long serialVersionUID = 1L; - - String header; - - LobEditorField(String header) { - super(); - this.header = header; - } - - @Override - protected Component initContent() { - final Button button = new Button("..."); - button.addClickListener(new ClickListener() { - - private static final long serialVersionUID = 1L; - - public void buttonClick(ClickEvent event) { - Property p = grid.getContainerDataSource().getItem(grid.getEditedItemId()).getItemProperty(header); - if (p != null) { - String data = p.getValue() == null ? null : String.valueOf(p.getValue()); - boolean binary = resultTable != null ? resultTable.getColumnWithName(header).isOfBinaryType() : false; - if (binary) { - ReadOnlyTextAreaDialog.show(header, data == null ? null : data.toUpperCase(), resultTable, getPrimaryKeys(), - db.getPlatform(), binary, true); - } else { - ReadOnlyTextAreaDialog.show(header, data, resultTable, getPrimaryKeys(), db.getPlatform(), binary, true); - } - } - } - }); - return button; - } - - @Override - public Class getType() { - return String.class; - } - - } - - class ObjectConverter implements Converter { - - private static final long serialVersionUID = 1L; - - Class modelType; - int typeCode; - - ObjectConverter(Class modelType, int typeCode) { - super(); - this.modelType = modelType; - this.typeCode = typeCode; - } - - @Override - public Object convertToModel(String value, Class targetType, Locale locale) - throws com.vaadin.v7.data.util.converter.Converter.ConversionException { - if (value == null || value.isEmpty() || value.equals("")) { - return null; - } - - if (java.util.Date.class.isAssignableFrom(modelType)) { - try { - return modelType.cast(db.getPlatform().parseDate(typeCode, value, false)); - } catch (Exception e) { - return value; - } - } - - return value.toString(); - } - - @Override - public String convertToPresentation(Object value, Class targetType, Locale locale) - throws com.vaadin.v7.data.util.converter.Converter.ConversionException { - if (value == null || value.equals("") || value.equals("")) - return ""; - return String.valueOf(value); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - public Class getModelType() { - if (typeCode == Types.DATE && db.getPlatform().getDdlBuilder().getDatabaseInfo().isDateOverridesToTimestamp()) { - modelType = Timestamp.class; - } - return modelType; - } - - @Override - public Class getPresentationType() { - return String.class; - } - } - - class TableChangeValidator implements Validator { - - private static final long serialVersionUID = 1L; - - TextField editor; - Column col; - - TableChangeValidator(TextField editor, Column col) { - super(); - this.editor = editor; - this.col = col; - } - - @Override - public void validate(Object value) throws InvalidValueException { - if (value == null || value.toString().isEmpty()) { - if (col.isRequired()) { - throw new EmptyValueException("Value cannot be null"); - } - } else if (editor.getConverter() instanceof ObjectConverter) { - int typeCode = col.getMappedTypeCode(); - if (typeCode == Types.DATE || typeCode == Types.TIME || typeCode == Types.TIMESTAMP) { - try { - db.getPlatform().parseDate(typeCode, String.valueOf(value), false); - } catch (Exception e) { - throw new InvalidValueException(col.getMappedType() + " format not valid"); - } - } - } - } - } - - class PrimaryKeyValidator implements Validator { - - private static final long serialVersionUID = 1L; - - List editors; - - PrimaryKeyValidator(List editors) { - super(); - this.editors = editors; - } - - public void validate(Object value) throws InvalidValueException { - String[] pkColumns = resultTable.getPrimaryKeyColumnNames(); - if (editors.size() != pkColumns.length) { - throw new IllegalArgumentException(); - } - Object[] newValues = new Object[pkColumns.length]; - for (int i = 0; i < editors.size(); i++) { - TextField editor = editors.get(i); - if (editor.getConverter() != null) { - newValues[i] = editor.getConverter().convertToModel(editor.getValue(), editor.getConverter().getModelType(), - editor.getLocale()); - } else { - newValues[i] = editor.getValue(); - } - } - allColumns: for (Object row : grid.getContainerDataSource().getItemIds()) { - if (!row.equals(grid.getEditedItemId())) { - for (int i = 0; i < pkColumns.length; i++) { - if (!grid.getContainerDataSource().getItem(row).getItemProperty(pkColumns[i]).getValue().equals(newValues[i])) { - continue allColumns; - } - } - throw new InvalidValueException("Cannot use repeated primary keys"); - } - } - } - } }