Repository: incubator-ignite Updated Branches: refs/heads/ignite-32 4b46f29ac -> d055526d2
# IGNITE-32 WIP: UI: two steps wizard instead of four steps. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/7d05f7d2 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/7d05f7d2 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/7d05f7d2 Branch: refs/heads/ignite-32 Commit: 7d05f7d240793c4b5fedacb158c86bc62fa87aa2 Parents: 4b46f29 Author: AKuznetsov <akuznet...@gridgain.com> Authored: Thu Dec 25 14:47:07 2014 +0700 Committer: AKuznetsov <akuznet...@gridgain.com> Committed: Thu Dec 25 14:47:07 2014 +0700 ---------------------------------------------------------------------- .../org/apache/ignite/schema/ui/GridPaneEx.java | 21 +- .../apache/ignite/schema/ui/SchemaLoadApp.java | 348 ++++++------------- 2 files changed, 129 insertions(+), 240 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7d05f7d2/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/GridPaneEx.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/GridPaneEx.java b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/GridPaneEx.java index aa400d7..4aa8769 100644 --- a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/GridPaneEx.java +++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/GridPaneEx.java @@ -9,6 +9,7 @@ package org.apache.ignite.schema.ui; +import javafx.collections.*; import javafx.geometry.*; import javafx.scene.*; import javafx.scene.control.*; @@ -33,16 +34,30 @@ public class GridPaneEx extends GridPane { * * @param cols Array of column percentages. */ - public void addPercentColumns(double ... cols) { + public void addPercentColumns(double... cols) { + ObservableList<ColumnConstraints> ccs = getColumnConstraints(); + for (double col : cols) { - ColumnConstraints cc = new ColumnConstraints(); + ColumnConstraints cc = new ColumnConstraints(2); cc.setPercentWidth(col); - getColumnConstraints().add(cc); + ccs.add(cc); } } /** + * Add percent columns. + * + * @param cols Array of column percentages. + */ + public void addColumns(double... cols) { + ObservableList<ColumnConstraints> ccs = getColumnConstraints(); + + for (double col : cols) + ccs.add(new ColumnConstraints(col)); + } + + /** * Add label to grid pane. * * @param text Label text. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7d05f7d2/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 7a4fcfa..553db4f 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 @@ -37,6 +37,10 @@ import static org.apache.ignite.schema.util.SchemaUtils.*; */ public class SchemaLoadApp extends Application { private static final String PATH = "C:/Temp/ignite"; + + /** */ + private Stage owner; + /** */ private int step; @@ -53,185 +57,115 @@ public class SchemaLoadApp extends Application { private Button nextBtn; /** */ - private WizardPage[] pages; + private TextField jdbcTf; /** */ - private WizardPage0 page0; + private TextField urlTf; /** */ - private WizardPage1 page1; + private TextField userTf; /** */ - private WizardPage2 page2; + private PasswordField pwdTf; /** */ - private WizardPage3 page3; + private Collection<IgniteBiTuple<String, Collection<String>>> tables = Collections.emptyList(); + /** */ + private GridPaneEx connPnl; - /** - * Base class for wizard pages. - */ - private abstract static class WizardPage { - /** */ - protected Pane contentPane; - - /** */ - protected final Stage owner; - - /** */ - protected final String title; - - /** - * @param owner Owner window. - * @param title Page title. - */ - protected WizardPage(Stage owner, String title) { - this.owner = owner; - this.title = title; - } + /** */ + private TreeView<String> tree; - /** - * Create wizard pane content. - * - * @return New pane instance with controls. - */ - protected abstract Pane createContent(); - - /** - * @return Wizard page with controls. - */ - protected Pane content() { - if (contentPane == null) - contentPane = createContent(); - - return contentPane; - } + /** */ + private CheckBoxTreeItem<String> rootItem; - /** - * @return {@code true} if wizard page complete. - */ - public boolean complete() { - return true; - } - } + /** */ + private TextField packageTf; + + /** */ + private GridPaneEx genPnl; /** - * Wizard page for selecting DB settings. + * Create pane with controls to configure connection to database. */ - private static class WizardPage0 extends WizardPage { - private TextField jdbcTf; - - private TextField urlTf; - - private TextField userTf; - - private PasswordField pwdTf; - - private Collection<IgniteBiTuple<String, Collection<String>>> tables = Collections.emptyList(); - - /** - * Create page. - */ - private WizardPage0(Stage owner) { - super(owner, "Choose Database"); - } + private Pane connectPane() { + if (connPnl == null) { - /** {@inheritDoc} */ - @Override protected Pane createContent() { - GridPaneEx gp = new GridPaneEx(DFLT_PADDING); + connPnl = new GridPaneEx(DFLT_PADDING); - gp.addPercentColumns(30, 70); + connPnl.addPercentColumns(30, 70); -// gp.addLabel("Alias:", 0, 0); -// -// ObservableList<String> options = FXCollections.observableArrayList("My Settings"); -// ComboBox<String> aliasCb = new ComboBox<>(options); -// aliasCb.setPromptText("Schema load settings"); -// aliasCb.setEditable(true); -// aliasCb.setMaxWidth(Double.MAX_VALUE); -// -// gp.add(aliasCb, 1, 0); + // gp.addLabel("Alias:", 0, 0); + // + // ObservableList<String> options = FXCollections.observableArrayList("My Settings"); + // ComboBox<String> aliasCb = new ComboBox<>(options); + // aliasCb.setPromptText("Schema load settings"); + // aliasCb.setEditable(true); + // aliasCb.setMaxWidth(Double.MAX_VALUE); + // + // gp.add(aliasCb, 1, 0); - jdbcTf = gp.addTextField("JDBC Driver:", 0, 2); + jdbcTf = connPnl.addTextField("JDBC Driver:", 0, 2); jdbcTf.setText("org.h2.Driver"); - urlTf = gp.addTextField("URL:", 0, 3); + urlTf = connPnl.addTextField("URL:", 0, 3); urlTf.setText("jdbc:h2:mem:test"); - userTf = gp.addTextField("User:", 0, 4); + userTf = connPnl.addTextField("User:", 0, 4); userTf.setText("sa"); - pwdTf = gp.addLabeled("Password:", new PasswordField(), 0, 5); - - return gp; + pwdTf = connPnl.addLabeled("Password:", new PasswordField(), 0, 5); } - private boolean changed() { - return true; - } - - - public Collection<IgniteBiTuple<String, Collection<String>>> tables() { - if (changed()) { - try { - Class.forName(jdbcTf.getText()); + return connPnl; + } - Connection conn = DriverManager.getConnection(urlTf.getText(), userTf.getText(), pwdTf.getText()); + private Collection<IgniteBiTuple<String, Collection<String>>> tables() { + try { + Class.forName(jdbcTf.getText()); - DatabaseMetaData meta = conn.getMetaData(); + Connection conn = DriverManager.getConnection(urlTf.getText(), userTf.getText(), pwdTf.getText()); - try (ResultSet schemas = meta.getSchemas()) { - tables = new ArrayList<>(); + DatabaseMetaData meta = conn.getMetaData(); - while(schemas.next()) { - String schema = schemas.getString(1); + try (ResultSet schemas = meta.getSchemas()) { + tables = new ArrayList<>(); - String cat = schemas.getString(2); + while (schemas.next()) { + String schema = schemas.getString(1); - try(ResultSet tbls = meta.getTables(cat, schema, "%", null)) { - Collection<String> items = new ArrayList<>(); + String cat = schemas.getString(2); - while (tbls.next()) { - String tbl = tbls.getString(3); + try (ResultSet tbls = meta.getTables(cat, schema, "%", null)) { + Collection<String> items = new ArrayList<>(); - System.out.println(tbl); + while (tbls.next()) { + String tbl = tbls.getString(3); - items.add(tbl); - } + System.out.println(tbl); - if (!items.isEmpty()) - tables.add(new IgniteBiTuple<>(schema, items)); - } + items.add(tbl); } + + if (!items.isEmpty()) + tables.add(new IgniteBiTuple<>(schema, items)); } } - catch(Throwable e) { - MessageBox.showErrorDialog(owner, "Failed to get tables list: " + e.getMessage()); - } } - - return tables; } - } + catch (Throwable e) { + MessageBox.showErrorDialog(owner, "Failed to get tables list: " + e.getMessage()); + } - /** - * Wizard page for selecting tables to import. - */ - private static class WizardPage1 extends WizardPage { - private TreeView<String> tree; + return tables; + } - private CheckBoxTreeItem<String> rootItem; + private Pane generatePane() { + if (genPnl == null) { + genPnl = new GridPaneEx(DFLT_PADDING); - /** - * Create page. - */ - private WizardPage1(Stage owner) { - super(owner, "Select tables"); - } - - /** {@inheritDoc} */ - @Override protected Pane createContent() { - GridPaneEx gp = new GridPaneEx(DFLT_PADDING); + genPnl.addPercentColumns(30, 60, 10); rootItem = new CheckBoxTreeItem<>("Database"); rootItem.setExpanded(true); @@ -239,72 +173,12 @@ public class SchemaLoadApp extends Application { tree = new TreeView<>(rootItem); tree.setCellFactory(CheckBoxTreeCell.<String>forTreeView()); - gp.add(tree, 0, 0); - - return gp; - } - - public void fill(Collection<IgniteBiTuple<String, Collection<String>>> tables) { - rootItem.getChildren().clear(); - - for (IgniteBiTuple<String, Collection<String>> schema : tables) { - CheckBoxTreeItem<String> schemaItem = new CheckBoxTreeItem<>(schema.getKey()); - rootItem.getChildren().add(schemaItem); - - for(String table : schema.getValue()) - schemaItem.getChildren().add(new CheckBoxTreeItem<>(table)); - } - - tree.setRoot(rootItem); - } - } - - /** - * Wizard page for configure generation settings. - */ - private static class WizardPage2 extends WizardPage { - private TextField packageTf; - - /** - * Create page. - */ - private WizardPage2(Stage owner) { - super(owner, "Import Database Schema"); - } - - /** {@inheritDoc} */ - @Override protected Pane createContent() { - GridPaneEx gp = new GridPaneEx(DFLT_PADDING); + genPnl.add(tree, 0, 0, 3, 2); - gp.addPercentColumns(30, 70); - - packageTf = gp.addTextField("Package:", 0, 0); + packageTf = genPnl.addTextField("Package:", 0, 3); packageTf.setText("org.apache.ignite"); - return gp; - } - - public String getPackage() { - return packageTf.getText(); - } - } - - /** - * Final wizard page with selecting output folder. - */ - private static class WizardPage3 extends WizardPage { - /** - * Create page. - */ - private WizardPage3(Stage owner) { - super(owner, "Generate"); - } - - /** {@inheritDoc} */ - @Override protected Pane createContent() { - GridPaneEx gp = new GridPaneEx(DFLT_PADDING); - - final TextField outFolderTf = gp.addTextField("Output folder:", 0, 0); + final TextField outFolderTf = genPnl.addTextField("Output folder:", 0, 4); outFolderTf.setText(PATH); Button btnFolder = new Button("..."); @@ -325,20 +199,20 @@ public class SchemaLoadApp extends Application { } }); - gp.add(btnFolder, 2, 0); + genPnl.add(btnFolder, 2, 4); Button btnGenerate = new Button("Generate"); btnGenerate.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent evt) { try { - try(Connection conn = DriverManager.getConnection("jdbc:h2:mem:test", "sa", "")) { + try (Connection conn = DriverManager.getConnection("jdbc:h2:mem:test", "sa", "")) { DbMetadataParser parser = new DbMetadataParser(conn); ResultSet schemas = parser.schemas(); Collection<GridCacheQueryTypeMetadata> all = new ArrayList<>(30); - while(schemas.next()) { + while (schemas.next()) { String schema = schemas.getString(1); if (!"PUBLIC".equalsIgnoreCase(schema)) @@ -354,7 +228,7 @@ public class SchemaLoadApp extends Application { PojoCodeGenerator codeGen = new PojoCodeGenerator(); - while(tbls.next()) { + while (tbls.next()) { String tbl = tbls.getString(3); System.out.println(" Table:" + tbl); @@ -367,9 +241,9 @@ public class SchemaLoadApp extends Application { Result res = new StreamResult(new File(destFolder, tbl + ".xml")); - transformer.transform(meta, res); + transformer.transform(packageTf.getText(), meta, res); - codeGen.generate(meta, outFolderTf.getText(), "org.apache.ignite"); + codeGen.generate(meta, outFolderTf.getText(), packageTf.getText()); } } @@ -377,12 +251,12 @@ public class SchemaLoadApp extends Application { Result res = new StreamResult(new File(outFolderTf.getText(), "all.xml")); - transformer.transform(all, res); + transformer.transform(packageTf.getText(), all, res); conn.close(); } } - catch(Throwable e) { + catch (Throwable e) { MessageBox.showErrorDialog(owner, "Generation failed: " + e.getMessage()); } @@ -390,10 +264,24 @@ public class SchemaLoadApp extends Application { } }); - gp.add(btnGenerate, 0, 1); + genPnl.add(btnGenerate, 0, 5); + } + + return genPnl; + } - return gp; + private void fill(Collection<IgniteBiTuple<String, Collection<String>>> tables) { + rootItem.getChildren().clear(); + + for (IgniteBiTuple<String, Collection<String>> schema : tables) { + CheckBoxTreeItem<String> schemaItem = new CheckBoxTreeItem<>(schema.getKey()); + rootItem.getChildren().add(schemaItem); + + for (String table : schema.getValue()) + schemaItem.getChildren().add(new CheckBoxTreeItem<>(table)); } + + tree.setRoot(rootItem); } /** @@ -441,51 +329,38 @@ public class SchemaLoadApp extends Application { * @param next If {@code true} then go to next page otherwise go to previous page. */ private void go(boolean next) { - if (next) { - if (step < pages.length) - step++; - } else if (step > 0) - step--; - - WizardPage page = pages[step]; - - rootPane.setCenter(page.createContent()); + Pane pane = next ? generatePane() : connectPane(); - titleLb.setText(page.title); + rootPane.setCenter(pane); - prevBtn.setDisable(step == 0); - nextBtn.setDisable(step == pages.length - 1); + titleLb.setText(next ? "Generate XML And POJOs" : "Connect To Database"); - if (step == 1) - page1.fill(page0.tables()); + prevBtn.setDisable(!next); + nextBtn.setDisable(next); } /** {@inheritDoc} */ @Override public void start(Stage primaryStage) { + owner = primaryStage; + primaryStage.setTitle("Schema Load"); primaryStage.getIcons() .addAll(image("branch", 16), image("branch", 32), image("branch", 48), image("branch", 128)); - page0 = new WizardPage0(primaryStage); - page1 = new WizardPage1(primaryStage); - page2 = new WizardPage2(primaryStage); - page3 = new WizardPage3(primaryStage); - - pages = new WizardPage[]{page0, page1, page2, page3}; - rootPane = new BorderPane(); rootPane.setTop(createHeaderPane()); + rootPane.setCenter(connectPane()); rootPane.setBottom(createButtonsPane()); - primaryStage.setMinWidth(300); - primaryStage.setMinHeight(310); + primaryStage.setMinWidth(400); + primaryStage.setMinHeight(500); - primaryStage.setMaxWidth(600); - primaryStage.setMaxHeight(500); + primaryStage.setMaxWidth(700); + primaryStage.setMaxHeight(700); - primaryStage.setScene(new Scene(rootPane, 300, 310)); + primaryStage.setScene(new Scene(rootPane, 400, 500)); primaryStage.show(); go(false); @@ -498,8 +373,8 @@ public class SchemaLoadApp extends Application { try { Class.forName("org.h2.Driver"); - try(Connection conn = DriverManager.getConnection("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "sa", "")) { - try(Statement stmt = conn.createStatement()) { + try (Connection conn = DriverManager.getConnection("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "sa", "")) { + try (Statement stmt = conn.createStatement()) { stmt.executeUpdate("CREATE TABLE IF NOT EXISTS Organization (id integer primary key, name varchar(50), city varchar(50))"); stmt.executeUpdate("CREATE TABLE IF NOT EXISTS Person (id integer primary key, org_id integer, name varchar(50))"); @@ -525,12 +400,11 @@ public class SchemaLoadApp extends Application { } } } - catch(Throwable e) { + catch (Throwable e) { e.printStackTrace(); } } - /** * Schema load utility launcher. *