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: Implemented save and restore preferences. Implemented check for empty keys/values.
Date Wed, 07 Jan 2015 14:56:28 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-32 232c70d10 -> 711dc4a9e


# IGNITE-32 WIP: Implemented save and restore preferences. Implemented check for empty keys/values.


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

Branch: refs/heads/ignite-32
Commit: 711dc4a9e3a582ff81b3db746dc5472633217b01
Parents: 232c70d
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Wed Jan 7 21:56:28 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Wed Jan 7 21:56:28 2015 +0700

----------------------------------------------------------------------
 .../ignite/schema/pojo/PojoCodeGenerator.java   |   2 +-
 .../apache/ignite/schema/ui/SchemaLoadApp.java  | 227 +++++++++++++------
 2 files changed, 160 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/711dc4a9/modules/schema-load/src/main/java/org/apache/ignite/schema/pojo/PojoCodeGenerator.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/pojo/PojoCodeGenerator.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/pojo/PojoCodeGenerator.java
index 3376006..e1b20bb 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/pojo/PojoCodeGenerator.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/pojo/PojoCodeGenerator.java
@@ -72,7 +72,7 @@ public class PojoCodeGenerator {
     private static void generateCode(String pkg, String type, Collection<GridCacheQueryTypeDescriptor>
descs,
         File pkgFolder, boolean constructor) throws IOException {
         if (descs.isEmpty())
-            return; // TODO IGNITE-32 UI should pass non metadata.
+            throw new IllegalStateException("List of type descriptors is empty.");
 
         Collection<String> src = new ArrayList<>(256);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/711dc4a9/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 148cfb3..9cf3dca 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
@@ -19,13 +19,13 @@ import org.apache.ignite.schema.db.*;
 import org.apache.ignite.schema.pojo.*;
 import org.apache.ignite.schema.xml.*;
 import org.gridgain.grid.cache.query.*;
-import org.gridgain.grid.util.typedef.*;
 import org.gridgain.grid.util.typedef.internal.*;
 
 import java.io.*;
 import java.net.*;
 import java.sql.*;
 import java.util.*;
+import java.util.prefs.*;
 
 import static javafx.embed.swing.SwingFXUtils.*;
 import static org.apache.ignite.schema.ui.Controls.*;
@@ -109,6 +109,13 @@ public class SchemaLoadApp extends Application {
         }
 
         /**
+         * @return Type descriptor.
+         */
+        public GridCacheQueryTypeDescriptor descriptor() {
+            return desc;
+        }
+
+        /**
          * @return Boolean property support for {@code key} property.
          */
         public BooleanProperty keyProperty() {
@@ -130,9 +137,6 @@ public class SchemaLoadApp extends Application {
         }
     }
 
-    /** TODO: IGNITE 32 remove before release */
-    private static final String PATH = "C:/Temp/ignite";
-
     /** */
     private Stage owner;
 
@@ -149,13 +153,13 @@ public class SchemaLoadApp extends Application {
     private Button nextBtn;
 
     /** */
-    private TextField jdbcTf;
+    private TextField jdbcDrvJarTf;
 
     /** */
-    private TextField drvTf;
+    private TextField jdbcDrvClsTf;
 
     /** */
-    private TextField urlTf;
+    private TextField jdbcUrlTf;
 
     /** */
     private TextField userTf;
@@ -167,16 +171,16 @@ public class SchemaLoadApp extends Application {
     private GridPaneEx connPnl;
 
     /** */
-    private CheckBoxTreeItem<String> rootItem;
+    private TreeView<String> tree;
 
     /** */
-    private TableView<Field> tbl;
+    private CheckBoxTreeItem<String> rootItem;
 
     /** */
-    private TextField pkgTf;
+    private TextField outFolderTf;
 
     /** */
-    private TextField outFolderTf;
+    private TextField pkgTf;
 
     /** */
     private CheckBox pojoConstructorCh;
@@ -188,12 +192,18 @@ public class SchemaLoadApp extends Application {
     private CheckBox xmlSingleFileCh;
 
     /** */
-    private GridPaneEx genPnl;
+    private CheckBox dfltNamingCh;
 
     /** */
-    private LinkedHashMap<String, LinkedHashMap<String, GridCacheQueryTypeMetadata>>
metas;
+    private Button btnNaming;
 
     /** */
+    private GridPaneEx genPnl;
+
+    /** Map with types metadata. */
+    private LinkedHashMap<String, LinkedHashMap<String, GridCacheQueryTypeMetadata>>
metas;
+
+    /** Map with fields descriptors. */
     private Map<String, Map<String, Collection<Field>>> fields;
 
     /** */
@@ -276,17 +286,54 @@ public class SchemaLoadApp extends Application {
             boolean constructor = pojoConstructorCh.isSelected();
             boolean include = pojoIncludeKeysCh.isSelected();
 
+            // Generate POJO and XML.
             for (TreeItem<String> schemeItem : rootItem.getChildren()) {
                 for (TreeItem<String> tblItem : schemeItem.getChildren()) {
                     if (((CheckBoxTreeItem)tblItem).isSelected()) {
-                        GridCacheQueryTypeMetadata meta = metas.get(schemeItem.getValue()).get(tblItem.getValue());
+                        String scheme = schemeItem.getValue();
+                        String tbl = tblItem.getValue();
+
+                        GridCacheQueryTypeMetadata meta = metas.get(scheme).get(tbl);
+
+                        Collection<Field> tblFields = fields.get(scheme).get(tbl);
 
-                        if (include) {
-                            meta = new GridCacheQueryTypeMetadata(meta);
+                        // Create a copy of metadata for modifications before processing.
+                        meta = new GridCacheQueryTypeMetadata(meta);
 
-                            meta.setValueDescriptors(F.concat(false, meta.getKeyDescriptors(),
meta.getValueDescriptors()));
+                        Collection<GridCacheQueryTypeDescriptor> keys = new ArrayList<>();
+
+                        Collection<GridCacheQueryTypeDescriptor> vals = new ArrayList<>();
+
+                        // Fill list with key and value type descriptors.
+                        for (Field fld : tblFields) {
+                            GridCacheQueryTypeDescriptor desc = fld.descriptor();
+
+                            if (fld.isKey()) {
+                                keys.add(desc);
+
+                                if (include)
+                                    vals.add(desc);
+                            }
+                            else
+                                vals.add(desc);
+                        }
+
+                        if (keys.isEmpty()) {
+                            tree.getSelectionModel().select(tblItem);
+
+                            throw new IllegalStateException("No key fields specified for
type: " + tbl);
+                        }
+
+                        if (vals.isEmpty()) {
+                            tree.getSelectionModel().select(tblItem);
+
+                            throw new IllegalStateException("No value fields specified for
type: " + tbl);
                         }
 
+                        meta.setKeyDescriptors(keys);
+
+                        meta.setValueDescriptors(vals);
+
                         all.add(meta);
 
                         XmlTransformer.transform(pkg, meta, new File(destFolder, meta.getType()
+ ".xml"));
@@ -386,17 +433,17 @@ public class SchemaLoadApp extends Application {
      * @throws SQLException if connection failed.
      */
     private Connection connect() throws SQLException {
-        String drvCls = jdbcTf.getText();
+        String drvCls = jdbcDrvClsTf.getText();
 
         Driver drv = drivers.get(drvCls);
 
         if (drv == null) {
-            String path = drvTf.getText().trim();
+            String path = jdbcDrvJarTf.getText().trim();
 
             if (path.isEmpty())
                 throw new IllegalStateException("Driver jar file name is not specified");
 
-            File drvJar = new File(drvTf.getText());
+            File drvJar = new File(jdbcDrvJarTf.getText());
 
             if (!drvJar.exists())
                 throw new IllegalStateException("Driver jar file is not found");
@@ -427,7 +474,7 @@ public class SchemaLoadApp extends Application {
         if (!pwd.isEmpty())
             info.put("password", pwd);
 
-        return drv.connect(urlTf.getText(), info);
+        return drv.connect(jdbcUrlTf.getText(), info);
     }
 
     /**
@@ -440,8 +487,7 @@ public class SchemaLoadApp extends Application {
         connPnl.addColumn(100, 100, Double.MAX_VALUE, Priority.ALWAYS);
         connPnl.addColumn(35, 35, 35, Priority.NEVER);
 
-        drvTf = connPnl.addLabeled("Driver JAR:", textField());
-        drvTf.setText("C:/GridGain/h2/bin/h2-1.3.176.jar");
+        jdbcDrvJarTf = connPnl.addLabeled("Driver JAR:", textField());
 
         connPnl.add(button("...", new EventHandler<ActionEvent>() {
             /** {@inheritDoc} */
@@ -453,18 +499,15 @@ public class SchemaLoadApp extends Application {
                 File drvJar = fc.showOpenDialog(owner);
 
                 if (drvJar != null)
-                    drvTf.setText(drvJar.getAbsolutePath());
+                    jdbcDrvJarTf.setText(drvJar.getAbsolutePath());
             }
         }));
 
-        jdbcTf = connPnl.addLabeled("JDBC Driver:", textField(), 2);
-        jdbcTf.setText("org.h2.Driver");
+        jdbcDrvClsTf = connPnl.addLabeled("JDBC Driver:", textField(), 2);
 
-        urlTf = connPnl.addLabeled("URL:", textField(), 2);
-        urlTf.setText("jdbc:h2:c:/Temp/test");
+        jdbcUrlTf = connPnl.addLabeled("URL:", textField(), 2);
 
         userTf = connPnl.addLabeled("User:", textField(), 2);
-        userTf.setText("sa");
 
         pwdTf = connPnl.addLabeled("Password:", new PasswordField(), 2);
     }
@@ -482,21 +525,6 @@ public class SchemaLoadApp extends Application {
         genPnl.addRow(100, 100, Double.MAX_VALUE, Priority.ALWAYS);
         genPnl.addRows(6);
 
-        rootItem = new CheckBoxTreeItem<>("Database");
-        rootItem.setExpanded(true);
-
-        TreeView<String> tree = new TreeView<>(rootItem);
-
-        tree.setCellFactory(CheckBoxTreeCell.<String>forTreeView());
-
-        tree.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TreeItem<String>>()
{
-            /** {@inheritDoc} */
-            @Override public void changed(ObservableValue<? extends TreeItem<String>>
val, TreeItem<String> oldItem,
-                TreeItem<String> newItem) {
-                onTreeSelectionChanged(newItem);
-            }
-        });
-
         TableColumn<Field, Boolean> keyCol = tableColumn("Key", "key", 70, 70);
 
         keyCol.setCellFactory(new Callback<TableColumn<Field, Boolean>, TableCell<Field,
Boolean>>() {
@@ -516,21 +544,39 @@ public class SchemaLoadApp extends Application {
 
         TableColumn<Field, String> javaNameCol = tableColumn("Ignite Name", "javaName",
0, 0);
 
-        tbl = new TableView<>();
+        final TableView<Field> tbl = new TableView<>();
 
         tbl.getColumns().addAll(keyCol, dbNameCol, javaNameCol);
         tbl.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
         tbl.setEditable(true);
 
+        rootItem = new CheckBoxTreeItem<>("Database");
+        rootItem.setExpanded(true);
+
+        tree = new TreeView<>(rootItem);
+
+        tree.setCellFactory(CheckBoxTreeCell.<String>forTreeView());
+
+        tree.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TreeItem<String>>()
{
+            /** {@inheritDoc} */
+            @Override public void changed(ObservableValue<? extends TreeItem<String>>
val, TreeItem<String> oldItem,
+                TreeItem<String> newItem) {
+                if (newItem != null && newItem.getParent() != null && newItem.isLeaf())
+                    tbl.setItems(FXCollections.observableArrayList(
+                        fields.get(newItem.getParent().getValue()).get(newItem.getValue())));
+                else
+                    tbl.setItems(noData);
+
+            }
+        });
+
         genPnl.add(splitPane(tree, tbl, 0.6), 3);
 
         pkgTf = genPnl.addLabeled("Package:", textField());
-        pkgTf.setText("org.apache.ignite");
 
         genPnl.wrap();
 
         outFolderTf = genPnl.addLabeled("Output Folder:", textField());
-        outFolderTf.setText(PATH);
 
         genPnl.add(button("...", new EventHandler<ActionEvent>() {
             /** {@inheritDoc} */
@@ -553,10 +599,10 @@ public class SchemaLoadApp extends Application {
         xmlSingleFileCh = genPnl.add(checkBox("Write all configurations to a single file",
             "If selected then all configurations will be saved into the file 'ignite.xml'",
true), 3);
 
-        final CheckBox dfltNamingCh = checkBox("Default naming conversions",
+        dfltNamingCh = checkBox("Default naming conversions",
             "If selected then DB names will be converted to default java names", true);
 
-        final Button btnNaming = button("Configure Naming", new EventHandler<ActionEvent>()
{
+        btnNaming = button("Configure Naming", new EventHandler<ActionEvent>() {
             /** {@inheritDoc} */
             @Override public void handle(ActionEvent evt) {
                 MessageBox.informationDialog(owner, "TODO: implement.");
@@ -575,19 +621,6 @@ public class SchemaLoadApp extends Application {
         genPnl.add(hBox(10, false, dfltNamingCh, btnNaming), 3);
     }
 
-    /**
-     * Action on tree selection changed.
-     *
-     * @param item Selected tree item.
-     */
-    private void onTreeSelectionChanged(TreeItem<String> item) {
-        if (item != null && item.getParent() != null && item.isLeaf())
-            tbl.setItems(FXCollections.observableArrayList(
-                fields.get(item.getParent().getValue()).get(item.getValue())));
-        else
-            tbl.setItems(noData);
-    }
-
     /** {@inheritDoc} */
     @Override public void start(Stage primaryStage) {
         System.setProperty("prism.lcdtext", "false");
@@ -633,19 +666,77 @@ public class SchemaLoadApp extends Application {
 
         primaryStage.setScene(scene);
 
-        int w = 400;
-        primaryStage.setWidth(w);
-        primaryStage.setMinWidth(w);
+        primaryStage.setWidth(400);
+        primaryStage.setMinWidth(400);
 
-        int h = 600;
-        primaryStage.setHeight(h);
-        primaryStage.setMinHeight(h);
+        primaryStage.setHeight(600);
+        primaryStage.setMinHeight(600);
 
         prev();
 
+        Preferences userPrefs = Preferences.userNodeForPackage(getClass());
+
+        // Restore window pos and size.
+        double x = userPrefs.getDouble("window.x", 100);
+        double y = userPrefs.getDouble("window.y", 100);
+        double w = userPrefs.getDouble("window.width", 400);
+        double h = userPrefs.getDouble("window.height", 600);
+
+        // Ensure that window fit any available screen.
+        if (!Screen.getScreensForRectangle(x, y, w, h).isEmpty()) {
+            if (x > 0)
+                primaryStage.setX(x);
+
+            if (y > 0)
+                primaryStage.setY(y);
+
+            primaryStage.setWidth(w);
+            primaryStage.setHeight(h);
+        }
+
+        // Restore connection pane settings.
+        jdbcDrvJarTf.setText(userPrefs.get("jdbc.driver.jar", "h2.jar"));
+        jdbcDrvClsTf.setText(userPrefs.get("jdbc.driver.class", "org.h2.Driver"));
+        jdbcUrlTf.setText(userPrefs.get("jdbc.url", "jdbc:h2:~/test"));
+        userTf.setText(userPrefs.get("jdbc.user", "sa"));
+
+        // Restore generation pane settings.
+        outFolderTf.setText(userPrefs.get("out.folder", "~/temp"));
+        pkgTf.setText(userPrefs.get("pojo.package", "org.apache.ignite"));
+        pojoIncludeKeysCh.setSelected(userPrefs.getBoolean("pojo.include", false));
+        pojoConstructorCh.setSelected(userPrefs.getBoolean("pojo.constructor", false));
+        xmlSingleFileCh.setSelected(userPrefs.getBoolean("xml.single", true));
+        dfltNamingCh.setSelected(userPrefs.getBoolean("naming.default", true));
+        btnNaming.setDisable(dfltNamingCh.isSelected());
+
         primaryStage.show();
     }
 
+    /** {@inheritDoc} */
+    @Override public void stop() throws Exception {
+        Preferences userPrefs = Preferences.userNodeForPackage(getClass());
+
+        // Save window pos and size.
+        userPrefs.putDouble("window.x", owner.getX());
+        userPrefs.putDouble("window.y", owner.getY());
+        userPrefs.putDouble("window.width", owner.getWidth());
+        userPrefs.putDouble("window.height", owner.getHeight());
+
+        // Save connection pane settings.
+        userPrefs.put("jdbc.driver.jar", jdbcDrvJarTf.getText());
+        userPrefs.put("jdbc.driver.class", jdbcDrvClsTf.getText());
+        userPrefs.put("jdbc.url", jdbcUrlTf.getText());
+        userPrefs.put("jdbc.user", userTf.getText());
+
+        // Save generation pane settings.
+        userPrefs.put("out.folder", outFolderTf.getText());
+        userPrefs.put("pojo.package", pkgTf.getText());
+        userPrefs.putBoolean("pojo.include", pojoIncludeKeysCh.isSelected());
+        userPrefs.putBoolean("pojo.constructor", pojoConstructorCh.isSelected());
+        userPrefs.putBoolean("xml.single", xmlSingleFileCh.isSelected());
+        userPrefs.putBoolean("naming.default", dfltNamingCh.isSelected());
+    }
+
     /**
      * Schema load utility launcher.
      *


Mime
View raw message