ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject incubator-ignite git commit: # IGNITE-32 WIP: Reworking tree to pseudo tree-table.
Date Thu, 22 Jan 2015 18:54:55 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-32 a163f5b50 -> cea0b0864


# IGNITE-32 WIP: Reworking tree to pseudo tree-table.


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

Branch: refs/heads/ignite-32
Commit: cea0b0864931ca4d44844c8da4233a68c1a3d2c9
Parents: a163f5b
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Fri Jan 23 01:54:50 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Fri Jan 23 01:54:50 2015 +0700

----------------------------------------------------------------------
 .../schema-load/src/main/java/media/style.css   |   8 ++
 .../org/apache/ignite/schema/ui/Controls.java   | 130 +++++++++++--------
 .../apache/ignite/schema/ui/SchemaLoadApp.java  | 122 +++++++++++++++--
 3 files changed, 198 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cea0b086/modules/schema-load/src/main/java/media/style.css
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/media/style.css b/modules/schema-load/src/main/java/media/style.css
index 99f3d68..35ab834 100644
--- a/modules/schema-load/src/main/java/media/style.css
+++ b/modules/schema-load/src/main/java/media/style.css
@@ -35,6 +35,14 @@
     -fx-focus-color: gray;
 }
 
+.table-row-cell:empty {
+    -fx-background-color: white;
+}
+
+.table-row-cell:empty .table-cell {
+    -fx-border-width: 0px;
+}
+
 .tooltip {
     -fx-background-radius: 0 0 0 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cea0b086/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/Controls.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/Controls.java b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/Controls.java
index ae006ac..6bed394 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/Controls.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/Controls.java
@@ -375,19 +375,35 @@ public class Controls {
         return col;
     }
 
+    /**
+     * Create editable boolean table column.
+     *
+     * @param colName Column name to display.
+     * @param propName Property name column is bound to.
+     * @param tip Column tooltip text.
+     * @return New {@code TableColumn} instance.
+     */
     public static <S> TableColumn<S, Boolean> booleanColumn(String colName, String
propName, String tip) {
         TableColumn<S, Boolean> col = tableColumn(colName, propName, tip, 70, 70, true);
 
-        col.setCellFactory(CheckBoxTableCellEx.<S>forTableColumn());
+        col.setCellFactory(CheckBoxTableCellEx.<S>cellFactory());
 
         return col;
 
     }
 
+    /**
+     * Create editable text table column.
+     *
+     * @param colName Column name to display.
+     * @param propName Property name column is bound to.
+     * @param tip Column tooltip text.
+     * @return New {@code TableColumn} instance.
+     */
     public static <S> TableColumn<S, String> textColumn(String colName, String
propName, String tip) {
         TableColumn<S, String> col = tableColumn(colName, propName, tip, 100, 0, true);
 
-        col.setCellFactory(TextFieldTableCellEx.<S>forTableColumn());
+        col.setCellFactory(TextFieldTableCellEx.<S>cellFactory());
 
         return col;
     }
@@ -466,9 +482,10 @@ public class Controls {
      */
     private static class CheckBoxTableCellEx<S> extends CheckBoxTableCell<S, Boolean>
{
         /** Creates a ComboBox cell factory for use in TableColumn controls. */
-        public static <S> Callback<TableColumn<S, Boolean>, TableCell<S,
Boolean>> forTableColumn() {
+        public static <S> Callback<TableColumn<S, Boolean>, TableCell<S,
Boolean>> cellFactory() {
             return new Callback<TableColumn<S, Boolean>, TableCell<S, Boolean>>()
{
-                public TableCell<S, Boolean> call(TableColumn<S, Boolean> col)
{
+                /** {@inheritDoc} */
+                @Override public TableCell<S, Boolean> call(TableColumn<S, Boolean>
col) {
                     return new CheckBoxTableCellEx<>();
                 }
             };
@@ -478,77 +495,86 @@ public class Controls {
          * Default constructor.
          */
         private CheckBoxTableCellEx() {
-            super();
-
             setAlignment(Pos.CENTER);
         }
     }
 
-    private static class TextFieldTableCellEx<S> extends TableCell<S, String>
{
-        /** Text field. */
-        private final TextField textField;
-
-        public static <S> Callback<TableColumn<S, String>, TableCell<S,
String>> forTableColumn() {
+    /**
+     * Special table text field cell that commit its content on focus lost.
+     */
+    private static class TextFieldTableCellEx<S> extends TextFieldTableCell<S, String>
{
+        /** */
+        private boolean cancelling;
+        /** */
+        private boolean hardCancel;
+        /** */
+        private String curTxt = "";
+
+        /** Create cell factory. */
+        public static <S> Callback<TableColumn<S, String>, TableCell<S,
String>> cellFactory() {
             return new Callback<TableColumn<S, String>, TableCell<S, String>>()
{
+                /** {@inheritDoc} */
                 @Override public TableCell<S, String> call(TableColumn<S, String>
col) {
                     return new TextFieldTableCellEx<>();
                 }
             };
         }
 
-        private TextFieldTableCellEx() {
-            textField = new TextField();
-
-            textField.setOnKeyReleased(new EventHandler<KeyEvent>() {
-                /** {@inheritDoc} */
-                @Override public void handle(KeyEvent evt) {
-                    if (KeyCode.ENTER == evt.getCode())
-                        commitEdit(textField.getText());
-                    else if (KeyCode.ESCAPE == evt.getCode())
-                        cancelEdit();
-                }
-            });
-
-            textField.focusedProperty().addListener(new ChangeListener<Boolean>() {
-                /** {@inheritDoc} */
-                @Override public void changed(ObservableValue<? extends Boolean> observable,
Boolean oldVal,
-                    Boolean newVal) {
-                    if (!newVal)
-                        commitEdit(textField.getText());
-                }
-            });
-
-            getStyleClass().add("text-field-table-cell");
-        }
-
         /** {@inheritDoc} */
         @Override public void startEdit() {
             super.startEdit();
 
-            setText(null);
-            setGraphic(textField);
+            Node g = getGraphic();
+
+            if (g != null) {
+                final TextField tf = (TextField)g;
+
+                tf.textProperty().addListener(new ChangeListener<String>() {
+                    @Override public void changed(ObservableValue<? extends String>
val, String oldVal, String newVal) {
+                        curTxt = newVal;
+                    }
+                });
+
+                tf.setOnKeyReleased(new EventHandler<KeyEvent>() {
+                    /** {@inheritDoc} */
+                    @Override public void handle(KeyEvent evt) {
+                        if (KeyCode.ENTER == evt.getCode())
+                            cancelEdit();
+                        else if (KeyCode.ESCAPE == evt.getCode()) {
+                            hardCancel = true;
+
+                            cancelEdit();
+                        }
+                    }
+                });
+            }
         }
 
         /** {@inheritDoc} */
         @Override public void cancelEdit() {
-            super.cancelEdit();
-
-            setText(getItem());
-
-            setGraphic(null);
+            if (!cancelling) {
+                try {
+                    cancelling = true;
+
+                    if (hardCancel || curTxt.trim().isEmpty())
+                        super.cancelEdit();
+                    else
+                        commitEdit(curTxt);
+                }
+                finally {
+                    cancelling = false;
+                }
+            }
+            else
+                super.cancelEdit();
         }
 
         /** {@inheritDoc} */
-        @Override public void updateItem(String item, boolean empty) {
-            super.updateItem(item, empty);
-
-            setGraphic(null);
+        @Override public void commitEdit(String s) {
+            super.commitEdit(s);
 
-            if (!empty) {
-                setText(item);
-
-                textField.setText(item);
-            }
+            hardCancel = false;
+            curTxt = "";
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cea0b086/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 146c07e..34331df 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
@@ -631,18 +631,18 @@ public class SchemaLoadApp extends Application {
         genPnl.addRow(100, 100, Double.MAX_VALUE, Priority.ALWAYS);
         genPnl.addRows(7);
 
-        TableColumn<SchemaItem, Boolean> useCol = booleanColumn("Use", "use",
-            "If checked then this field will be part of key object");
-
-        TableColumn<SchemaItem, String> schemaCol = tableColumn("Schema", "schema",
"Schema name in database");
+        TableColumn<SchemaItem, Boolean> useCol = customColumn("Use", "use",
+            "If checked then this field will be part of key object", SchemaCell.cellFactory());
 
-        TableColumn<SchemaItem, String> tblCol = tableColumn("Table", "table", "Table
name in database");
+//        TableColumn<SchemaItem, String> schemaCol = tableColumn("Schema", "schema",
"Schema name in database");
+//
+//        TableColumn<SchemaItem, String> tblCol = tableColumn("Table", "table", "Table
name in database");
 
         TableColumn<SchemaItem, String> keyClsCol = textColumn("Key Class", "keyClass",
"Key class name");
 
         TableColumn<SchemaItem, String> valClsCol = textColumn("Value Class", "valueClass",
"Value class name");
 
-        schemesTbl = tableView("Tables not found in database", useCol, schemaCol, tblCol,
keyClsCol, valClsCol);
+        schemesTbl = tableView("Tables not found in database", useCol, /* schemaCol, tblCol,
*/ keyClsCol, valClsCol);
 
         TableColumn<PojoField, Boolean> keyCol = booleanColumn("Key", "key",
             "If checked then this field will be part of key object");
@@ -654,7 +654,7 @@ public class SchemaLoadApp extends Application {
         TableColumn<PojoField, String> javaNameCol = textColumn("Ignite Name", "javaName",
"Field name in POJO class");
 
         TableColumn<PojoField, String> javaTypeNameCol = customColumn("Java Type",
"javaTypeName",
-            "Field java type in POJO class", JavaTypeCell.forTableColumn());
+            "Field java type in POJO class", JavaTypeCell.cellFactory());
 
         final TableView<PojoField> fieldsTbl = tableView("Select table to see table
columns",
             keyCol, dbNameCol, dbTypeNameCol, javaNameCol, javaTypeNameCol);
@@ -983,7 +983,15 @@ public class SchemaLoadApp extends Application {
 
         rootPane = borderPane(createHeaderPane(), createConnectionPane(), createButtonsPane(),
null, null);
 
-        primaryStage.setScene(scene(rootPane));
+        Scene scene = scene(rootPane);
+
+//        scene.focusOwnerProperty().addListener(new ChangeListener<Node>() {
+//            @Override public void changed(ObservableValue<? extends Node> value,
Node node, Node t1) {
+//                System.out.println(String.valueOf(value));
+//            }
+//        });
+
+        primaryStage.setScene(scene);
 
         primaryStage.setWidth(600);
         primaryStage.setMinWidth(600);
@@ -1857,9 +1865,10 @@ public class SchemaLoadApp extends Application {
         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() {
+        public static Callback<TableColumn<PojoField, String>, TableCell<PojoField,
String>> cellFactory() {
             return new Callback<TableColumn<PojoField, String>, TableCell<PojoField,
String>>() {
-                public TableCell<PojoField, String> call(TableColumn<PojoField,
String> col) {
+                /** {@inheritDoc} */
+                @Override public TableCell<PojoField, String> call(TableColumn<PojoField,
String> col) {
                     return new JavaTypeCell();
                 }
             };
@@ -1872,6 +1881,7 @@ public class SchemaLoadApp extends Application {
             comboBox = new ComboBox<>(FXCollections.<String>emptyObservableList());
 
             comboBox.valueProperty().addListener(new ChangeListener<String>() {
+                /** {@inheritDoc} */
                 @Override public void changed(ObservableValue<? extends String> val,
String oldVal, String newVal) {
                     if (isEditing())
                         commitEdit(newVal);
@@ -1921,4 +1931,96 @@ public class SchemaLoadApp extends Application {
             }
         }
     }
+
+    /**
+     * Special table cell to select schema or table.
+     */
+    private static class SchemaCell extends TableCell<SchemaItem, Boolean> {
+        private final Pane schemaPnl;
+
+        private final Pane tblPnl;
+
+        /** Combo box. */
+        private final CheckBox ch;
+
+        /** Creates a ComboBox cell factory for use in TableColumn controls. */
+        public static Callback<TableColumn<SchemaItem, Boolean>, TableCell<SchemaItem,
Boolean>> cellFactory() {
+            return new Callback<TableColumn<SchemaItem, Boolean>, TableCell<SchemaItem,
Boolean>>() {
+                /** {@inheritDoc} */
+                @Override public TableCell<SchemaItem, Boolean> call(TableColumn<SchemaItem,
Boolean> col) {
+                    return new SchemaCell();
+                }
+            };
+        }
+
+        /**
+         * Default constructor.
+         */
+        private SchemaCell() {
+            ch = new CheckBox();
+
+            ch.setOnAction(new EventHandler<ActionEvent>() {
+                @Override public void handle(ActionEvent event) {
+//                    int idx = getIndex();
+
+                    getTableView().getSelectionModel().select(getIndex());
+
+//                    TableRow row = getTableRow();
+//
+//                    if (row != null)
+//                        row.getTableView().getSelectionModel().select(row.getIndex()+1);
+                }
+            });
+
+            schemaPnl = new HBox();
+            schemaPnl.setPadding(new Insets(0, 0, 0, 5));
+
+            tblPnl = new HBox();
+            tblPnl.setPadding(new Insets(0, 0, 0, 15));
+
+            tblPnl.getChildren().add(ch);
+
+            setGraphic(tblPnl);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void startEdit() {
+            super.startEdit();
+        }
+
+        private void setGraphic(String text, Pane pnl) {
+            if (!text.isEmpty()) {
+                ch.setText(text);
+
+                pnl.getChildren().add(ch);
+
+                setGraphic(pnl);
+            }
+        }
+
+        /** {@inheritDoc} */
+        @Override public void updateItem(Boolean item, boolean empty) {
+            super.updateItem(item, empty);
+
+            setGraphic(null);
+
+            if (!empty) {
+                TableRow row = getTableRow();
+
+                if (row != null) {
+                    SchemaItem schema = (SchemaItem)row.getItem();
+
+                    if (schema != null) {
+                        ch.setSelected(item);
+
+                        schemaPnl.getChildren().clear();
+                        tblPnl.getChildren().clear();
+
+                        setGraphic(schema.schemaProperty().get(), schemaPnl);
+                        setGraphic(schema.tableProperty().get(), tblPnl);
+                    }
+                }
+            }
+        }
+    }
 }


Mime
View raw message