ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yzhda...@apache.org
Subject [6/7] incubator-ignite git commit: # IGNITE-32 Save presets.
Date Sat, 07 Feb 2015 22:01:17 GMT
# IGNITE-32 Save presets.


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

Branch: refs/heads/ignite-96
Commit: 74356907f1b055ca29e5d9efeaea7193668025b9
Parents: af83714
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Sun Feb 8 00:59:40 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Sun Feb 8 00:59:40 2015 +0700

----------------------------------------------------------------------
 .../apache/ignite/schema/ui/SchemaLoadApp.java  | 140 +++++++++++--------
 1 file changed, 85 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/74356907/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 d03d252..cd34a10 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
@@ -47,33 +47,15 @@ import static org.apache.ignite.schema.ui.Controls.*;
  */
 @SuppressWarnings("UnnecessaryFullyQualifiedName")
 public class SchemaLoadApp extends Application {
-    /** Default presets for most popular databases. */
-    private enum Preset {
-        /** Preset for H2. */
-        H2("H2 Database", "h2.jar", "org.h2.Driver", "jdbc:h2:[database]", "sa"),
+    /** Presets for database settings. */
+    private static class Preset {
+        /** Name in preferences. */
+        private String pref;
 
-        /** Preset for DB2. */
-        DB2("DB2", "db2jcc4.jar", "com.ibm.db2.jcc.DB2Driver", "jdbc:db2://[host]:[port]/[database]",
"db2admin"),
+        /** RDBMS name to show on screen. */
+        private String name;
 
-        /** Preset for Oracle. */
-        ORACLE("Oracle", "ojdbc6.jar", "oracle.jdbc.OracleDriver", "jdbc:oracle:thin:@[host]:[port]:[database]",
"system"),
-
-        /** Preset for MySql. */
-        MY_SQL("MySQL", "mysql-connector-java-5-bin.jar", "com.mysql.jdbc.Driver", "jdbc:mysql://[host]:[port]/[database]",
"root"),
-
-        /** Preset for MsSql. */
-        MS_SQL("Microsoft SQL Server", "sqljdbc41.jar", "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"jdbc:sqlserver://[host]:[port][;databaseName=database]", "sa"),
-
-        /** Preset for PostgreSQL. */
-        POSTGRE_SQL("PostgreSQL", "postgresql-9.3.jdbc4.jar", "org.postgresql.Driver", "jdbc:postgresql://[host]:[port]/[database]",
"sa"),
-
-        /** Preset for custom server. */
-        CUSTOM("Custom server...", "custom-jdbc.jar", "org.custom.Driver", "jdbc:custom",
"sa");
-
-        /** RDBMS name. */
-        private final String name;
-
-        /** JDBC driver jar name. */
+        /** Path to JDBC driver jar. */
         private String jar;
 
         /** JDBC driver class name. */
@@ -86,15 +68,17 @@ public class SchemaLoadApp extends Application {
         private String user;
 
         /**
-         * Enum constructor.
+         * Preset constructor.
          *
-         * @param name RDBMS name.
-         * @param jar JDBC driver jar name.
+         * @param pref Name in preferences.
+         * @param name RDBMS name to show on screen.
+         * @param jar Path to JDBC driver jar..
          * @param drv JDBC driver class name.
          * @param url JDBC URL.
          * @param user User name.
          */
-        Preset(String name, String jar, String drv, String url, String user) {
+        Preset(String pref, String name, String jar, String drv, String url, String user)
{
+            this.pref = pref;
             this.name = name;
             this.jar = jar;
             this.drv = drv;
@@ -108,9 +92,6 @@ public class SchemaLoadApp extends Application {
         }
     }
 
-    /** Databases presets. */
-    private static Preset[] PRESETS = Preset.values();
-
     /** */
     private Stage owner;
 
@@ -141,6 +122,22 @@ public class SchemaLoadApp extends Application {
     /** */
     private ComboBox<Preset> rdbmsCb;
 
+    /** Default presets for popular databases. */
+    private final Preset[] presets = {
+        new Preset("h2", "H2 Database", "h2.jar", "org.h2.Driver", "jdbc:h2:[database]",
"sa"),
+        new Preset("db2", "DB2", "db2jcc4.jar", "com.ibm.db2.jcc.DB2Driver", "jdbc:db2://[host]:[port]/[database]",
+            "db2admin"),
+        new Preset("oracle", "Oracle", "ojdbc6.jar", "oracle.jdbc.OracleDriver",
+            "jdbc:oracle:thin:@[host]:[port]:[database]", "system"),
+        new Preset("mysql", "MySQL", "mysql-connector-java-5-bin.jar", "com.mysql.jdbc.Driver",
+            "jdbc:mysql://[host]:[port]/[database]", "root"),
+        new Preset("mssql", "Microsoft SQL Server", "sqljdbc41.jar", "com.microsoft.sqlserver.jdbc.SQLServerDriver",
+            "jdbc:sqlserver://[host]:[port][;databaseName=database]", "sa"),
+        new Preset("posgresql", "PostgreSQL", "postgresql-9.3.jdbc4.jar", "org.postgresql.Driver",
+            "jdbc:postgresql://[host]:[port]/[database]", "sa"),
+        new Preset("custom", "Custom server...", "custom-jdbc.jar", "org.custom.Driver",
"jdbc:custom", "sa")
+    };
+
     /** */
     private TextField jdbcDrvJarTf;
 
@@ -649,13 +646,13 @@ public class SchemaLoadApp extends Application {
         presetPnl.addColumn(100, 100, Double.MAX_VALUE, Priority.ALWAYS);
         presetPnl.addColumn();
 
+        rdbmsCb = presetPnl.add(comboBox("Select database server to get predefined settings",
presets));
 
-
-        rdbmsCb = presetPnl.add(comboBox("Select database server to get predefined settings",
PRESETS));
-
-        presetPnl.add(button("Save preset", "", new EventHandler<ActionEvent>() {
+        presetPnl.add(button("Save preset", "Save current settings in preferences", new EventHandler<ActionEvent>()
{
             @Override public void handle(ActionEvent evt) {
-                // TODO: CODE: implement.
+                Preset preset = rdbmsCb.getSelectionModel().getSelectedItem();
+
+                savePreset(preset);
             }
         }));
 
@@ -1148,14 +1145,24 @@ public class SchemaLoadApp extends Application {
 
         prev();
 
-        Preferences userPrefs = Preferences.userNodeForPackage(getClass());
+        Preferences prefs = Preferences.userNodeForPackage(getClass());
+
+        // Restore presets.
+        for (Preset preset : presets) {
+            String key = "presets." + preset.pref + ".";
+
+            preset.jar = prefs.get(key + "jar", preset.jar);
+            preset.drv = prefs.get(key + "drv", preset.drv);
+            preset.url = prefs.get(key + "url", preset.url);
+            preset.user = prefs.get(key + "user", preset.user);
+        }
 
         // Restore window pos and size.
-        if (userPrefs.get("window.x", null) != null) {
-            double x = userPrefs.getDouble("window.x", 100);
-            double y = userPrefs.getDouble("window.y", 100);
-            double w = userPrefs.getDouble("window.width", 650);
-            double h = userPrefs.getDouble("window.height", 650);
+        if (prefs.get("window.x", null) != null) {
+            double x = prefs.getDouble("window.x", 100);
+            double y = prefs.getDouble("window.y", 100);
+            double w = prefs.getDouble("window.width", 650);
+            double h = prefs.getDouble("window.height", 650);
 
             // Ensure that window fit any available screen.
             if (!Screen.getScreensForRectangle(x, y, w, h).isEmpty()) {
@@ -1175,27 +1182,50 @@ public class SchemaLoadApp extends Application {
         String userHome = System.getProperty("user.home").replace('\\', '/');
 
         // Restore connection pane settings.
-        rdbmsCb.getSelectionModel().select(userPrefs.getInt("jdbc.db.preset", 0));
-        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:" + userHome + "/ignite-schema-load/db"));
-        userTf.setText(userPrefs.get("jdbc.user", "sa"));
+        rdbmsCb.getSelectionModel().select(prefs.getInt("jdbc.db.preset", 0));
+        jdbcDrvJarTf.setText(prefs.get("jdbc.driver.jar", "h2.jar"));
+        jdbcDrvClsTf.setText(prefs.get("jdbc.driver.class", "org.h2.Driver"));
+        jdbcUrlTf.setText(prefs.get("jdbc.url", "jdbc:h2:" + userHome + "/ignite-schema-load/db"));
+        userTf.setText(prefs.get("jdbc.user", "sa"));
 
         // Restore generation pane settings.
-        outFolderTf.setText(userPrefs.get("out.folder", userHome + "/ignite-schema-load/out"));
+        outFolderTf.setText(prefs.get("out.folder", userHome + "/ignite-schema-load/out"));
 
-        pkgTf.setText(userPrefs.get("pojo.package", "org.apache.ignite"));
-        pojoIncludeKeysCh.setSelected(userPrefs.getBoolean("pojo.include", true));
-        pojoConstructorCh.setSelected(userPrefs.getBoolean("pojo.constructor", false));
+        pkgTf.setText(prefs.get("pojo.package", "org.apache.ignite"));
+        pojoIncludeKeysCh.setSelected(prefs.getBoolean("pojo.include", true));
+        pojoConstructorCh.setSelected(prefs.getBoolean("pojo.constructor", false));
 
-        xmlSingleFileCh.setSelected(userPrefs.getBoolean("xml.single", true));
+        xmlSingleFileCh.setSelected(prefs.getBoolean("xml.single", true));
 
-        regexTf.setText(userPrefs.get("naming.pattern", "(\\w+)"));
-        replaceTf.setText(userPrefs.get("naming.replace", "$1_SomeText"));
+        regexTf.setText(prefs.get("naming.pattern", "(\\w+)"));
+        replaceTf.setText(prefs.get("naming.replace", "$1_SomeText"));
 
         primaryStage.show();
     }
 
+    /**
+     * Save preset.
+     *
+     * @param preset Preset to save.
+     */
+    private void savePreset(Preset preset) {
+        Preferences prefs = Preferences.userNodeForPackage(getClass());
+
+        String key = "presets." + preset.pref + ".";
+
+        preset.jar = jdbcDrvJarTf.getText();
+        prefs.put(key + "jar", preset.jar);
+
+        preset.drv = jdbcDrvClsTf.getText();
+        prefs.put(key + "drv", preset.drv);
+
+        preset.url = jdbcUrlTf.getText();
+        prefs.put(key + "url", preset.url);
+
+        preset.user = userTf.getText();
+        prefs.put(key + "user", preset.user);
+    }
+
     /** {@inheritDoc} */
     @Override public void stop() throws Exception {
         Preferences userPrefs = Preferences.userNodeForPackage(getClass());


Mime
View raw message