ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [2/2] incubator-ignite git commit: # IGNITE-32 WIP: Select type conversion in GUI.
Date Tue, 20 Jan 2015 06:16:31 GMT
# IGNITE-32 WIP: Select type conversion in GUI.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/6a8a5aa8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/6a8a5aa8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/6a8a5aa8

Branch: refs/heads/ignite-32
Commit: 6a8a5aa8801b4f67557cd5bdf8cc0d602c97f89f
Parents: 8241ac1
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Tue Jan 20 13:17:02 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Tue Jan 20 13:17:02 2015 +0700

----------------------------------------------------------------------
 .../org/apache/ignite/schema/ui/PojoField.java  | 99 ++++++++++++++++++++
 .../apache/ignite/schema/ui/SchemaLoadApp.java  | 71 ++++++++++++++
 2 files changed, 170 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6a8a5aa8/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/PojoField.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/PojoField.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/PojoField.java
index 9e9e16e..711d95d 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/PojoField.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/PojoField.java
@@ -18,7 +18,11 @@
 package org.apache.ignite.schema.ui;
 
 import javafx.beans.property.*;
+import javafx.collections.*;
 import org.gridgain.grid.cache.query.*;
+import org.gridgain.grid.util.typedef.internal.*;
+
+import java.util.*;
 
 import static java.sql.Types.*;
 
@@ -44,6 +48,9 @@ public class PojoField {
     /** Field type descriptor. */
     private final GridCacheQueryTypeDescriptor desc;
 
+    /** List of possible java type conversions. */
+    private final ObservableList<String> conversions;
+
     /**
      * @param key {@code true} if this field belongs to primary key.
      * @param desc Field type descriptor.
@@ -55,6 +62,13 @@ public class PojoField {
         javaTypeName = new SimpleStringProperty(desc.getJavaType().getName());
         dbName = new SimpleStringProperty(desc.getDbName());
         dbTypeName = new SimpleStringProperty(jdbcTypeName(desc.getDbType()));
+
+        ObservableList<String> c = conversionsMap.get(desc.getDbType());
+
+        if (c != null)
+            conversions = c;
+        else
+            conversions = FXCollections.singletonObservableList(javaTypeName());
     }
 
     /**
@@ -184,6 +198,13 @@ public class PojoField {
     }
 
     /**
+     * @return POJO field JDBC type in database.
+     */
+    public int dbType() {
+        return desc.getDbType();
+    }
+
+    /**
      * @return Boolean property support for {@code key} property.
      */
     public BooleanProperty keyProperty() {
@@ -217,4 +238,82 @@ public class PojoField {
     public StringProperty dbTypeNameProperty() {
         return dbTypeName;
     }
+
+
+    /** */
+    private static final String BOOL_P = "boolean";
+
+    /** */
+    private static final String BOOL_O = "java.lang.Boolean";
+
+    /** */
+    private static final String BYTE_P = "byte";
+
+    /** */
+    private static final String BYTE_O = "java.lang.Byte";
+
+    /** */
+    private static final String SHORT_P = "short";
+
+    /** */
+    private static final String SHORT_O = "java.lang.Short";
+
+    /** */
+    private static final String INT_P = "int";
+
+    /** */
+    private static final String INT_O = "java.lang.Integer";
+
+    /** */
+    private static final String LONG_P = "long";
+
+    /** */
+    private static final String LONG_O = "java.lang.Long";
+
+    /** */
+    private static final String FLOAT_P = "float";
+
+    /** */
+    private static final String FLOAT_O = "java.lang.Float";
+
+    /** */
+    private static final String DOUBLE_P = "double";
+
+    /** */
+    private static final String DOUBLE_O = "java.lang.Double";
+
+    /** */
+    private static final String BIG_DECIMAL_O = "java.math.BigDecimal";
+
+    /** */
+    private static final Map<Integer, ObservableList<String>> conversionsMap
= U.newHashMap(10);
+
+    static {
+        conversionsMap.put(TINYINT, FXCollections.observableArrayList(BOOL_P, BYTE_P, SHORT_P,
INT_P, LONG_P, FLOAT_P,
+                DOUBLE_P, BOOL_O, BYTE_O, SHORT_O, INT_O, LONG_O, FLOAT_O, DOUBLE_O, BIG_DECIMAL_O));
+
+        conversionsMap.put(SMALLINT, FXCollections.observableArrayList(BOOL_P, SHORT_P, INT_P,
LONG_P, FLOAT_P, DOUBLE_P,
+                BOOL_O, SHORT_O, INT_O, LONG_O, FLOAT_O, DOUBLE_O, BIG_DECIMAL_O));
+
+        conversionsMap.put(INTEGER, FXCollections.observableArrayList(BOOL_P, INT_P, LONG_P,
FLOAT_P, DOUBLE_P,
+                BOOL_O, INT_O, LONG_O, FLOAT_O, DOUBLE_O, BIG_DECIMAL_O));
+
+        conversionsMap.put(BIGINT, FXCollections.observableArrayList(BOOL_P, LONG_P, FLOAT_P,
DOUBLE_P, BOOL_O, LONG_O,
+            FLOAT_O, DOUBLE_O, BIG_DECIMAL_O));
+
+        conversionsMap.put(REAL, FXCollections.observableArrayList(BOOL_P, FLOAT_P, DOUBLE_P,
BOOL_O, FLOAT_O, DOUBLE_O,
+            BIG_DECIMAL_O));
+
+        conversionsMap.put(FLOAT, FXCollections.observableArrayList(BOOL_P, FLOAT_P, DOUBLE_P,
BOOL_O, FLOAT_O, DOUBLE_O,
+            BIG_DECIMAL_O));
+
+        conversionsMap.put(DOUBLE, conversionsMap.get(FLOAT));
+    }
+
+    /**
+     * @return List of possible java type conversions.
+     */
+    public ObservableList<String> conversions() {
+        return conversions;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6a8a5aa8/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
index 2b011ab..9a6175c 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
@@ -663,6 +663,8 @@ public class SchemaLoadApp extends Application {
 
         TableColumn<PojoField, String> javaTypeNameCol = tableColumn("Java Type", "javaTypeName",
             "Field java type in POJO class", 100, 0);
+        javaTypeNameCol.setCellFactory(JavaTypeCell.forTableColumn());
+        javaTypeNameCol.setEditable(true);
 
         final TableView<PojoField> tbl = new TableView<>();
 
@@ -1153,4 +1155,73 @@ public class SchemaLoadApp extends Application {
 
         launch(args);
     }
+
+    /**
+     * Special table cell to select possible java type conversions.
+     */
+    private static class JavaTypeCell extends TableCell<PojoField, String> {
+        /** Combo box. */
+        private final ComboBox<String> comboBox;
+
+        /** Creates a ComboBox cell factory for use in TableColumn controls. */
+        public static Callback<TableColumn<PojoField, String>, TableCell<PojoField,
String>> forTableColumn() {
+            return new Callback<TableColumn<PojoField, String>, TableCell<PojoField,
String>>() {
+                public TableCell<PojoField, String> call(TableColumn<PojoField,
String> col) {
+                    return new JavaTypeCell(col);
+                }
+            };
+        }
+
+        /**
+         * Default constructor.
+         */
+        private JavaTypeCell(final TableColumn<PojoField, String> col) {
+            comboBox = new ComboBox<>(FXCollections.<String>emptyObservableList());
+
+            comboBox.editableProperty().bind(col.editableProperty());
+
+            comboBox.disableProperty().bind(col.editableProperty().not());
+
+            comboBox.setOnShowing(new EventHandler<Event>() {
+                @Override public void handle(Event evt) {
+                    final TableView<PojoField> tblView = getTableView();
+                    tblView.getSelectionModel().select(getTableRow().getIndex());
+
+                    PojoField pojo = tblView.getSelectionModel().getSelectedItem();
+                    if (pojo != null) {
+                        comboBox.setItems(pojo.conversions());
+
+                        comboBox.getSelectionModel().select(pojo.javaTypeName());
+                    }
+
+                    tblView.edit(tblView.getSelectionModel().getSelectedIndex(), col);
+                }
+            });
+
+            comboBox.valueProperty().addListener(new ChangeListener<String>() {
+                @Override public void changed(ObservableValue<? extends String> val,
String oldVal, String newVal) {
+                    if (isEditing())
+                        commitEdit(newVal);
+                }
+            });
+
+            setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
+
+            getStyleClass().add("combo-box-table-cell");
+        }
+
+        /** {@inheritDoc} */
+        @Override public void updateItem(String item, boolean empty) {
+            super.updateItem(item, empty);
+
+            setText(null);
+
+            if(empty)
+                setGraphic(null);
+            else {
+                comboBox.setValue(item);
+                setGraphic(comboBox);
+            }
+        }
+    }
 }


Mime
View raw message