# IGNITE-32 WIP: Refactoring app + started to add table with columns metadata.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/2b0a2d13 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/2b0a2d13 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/2b0a2d13 Branch: refs/heads/ignite-32 Commit: 2b0a2d1300e6ec8e3570ebe810baa303d1d294d3 Parents: 5e7b9cd Author: AKuznetsov <akuznet...@gridgain.com> Authored: Sun Dec 28 14:24:32 2014 +0700 Committer: AKuznetsov <akuznet...@gridgain.com> Committed: Sun Dec 28 14:24:32 2014 +0700 ---------------------------------------------------------------------- .../apache/ignite/schema/ui/SchemaLoadApp.java | 208 ++++++++++--------- .../apache/ignite/schema/util/SchemaUtils.java | 45 ---- 2 files changed, 107 insertions(+), 146 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2b0a2d13/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 e3d512e..0bffbeb 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 @@ -27,7 +27,7 @@ import java.io.*; import java.sql.*; import java.util.*; -import static org.apache.ignite.schema.util.SchemaUtils.*; +import static org.apache.ignite.schema.ui.Controls.*; /** * Schema load application. @@ -88,92 +88,22 @@ public class SchemaLoadApp extends Application { private LinkedHashMap<String, LinkedHashMap<String, GridCacheQueryTypeMetadata>> schemas; /** - * Create pane with controls to configure connection to database. - */ - private Pane connectPane() { - if (connPnl == null) { - connPnl = new GridPaneEx(DFLT_PADDING); - - connPnl.addColumn(); - connPnl.addColumn(100, 100, Double.MAX_VALUE, Priority.ALWAYS); - - jdbcTf = connPnl.addLabeled("JDBC Driver:", Controls.textField()); - jdbcTf.setText("org.h2.Driver"); - - urlTf = connPnl.addLabeled("URL:", Controls.textField()); - urlTf.setText("jdbc:h2:mem:test"); - - userTf = connPnl.addLabeled("User:", Controls.textField()); - userTf.setText("sa"); - - pwdTf = connPnl.addLabeled("Password:", new PasswordField()); - } - - return connPnl; - } - - /** - * Create pane with controls used to configure XML and code generation. - * - * @return Pane with controls. - */ - private Pane generatePane() { - if (genPnl == null) { - genPnl = new GridPaneEx(DFLT_PADDING); - - genPnl.addColumn(); - genPnl.addColumn(100, 100, Double.MAX_VALUE, Priority.ALWAYS); - genPnl.addColumn(30); - - genPnl.addRow(100, 100, Double.MAX_VALUE, Priority.ALWAYS); - genPnl.addRow(); - genPnl.addRow(); - genPnl.addRow(); - genPnl.addRow(); - - rootItem = new CheckBoxTreeItem<>("Database"); - rootItem.setExpanded(true); - - TreeView<String> tree = new TreeView<>(rootItem); - tree.setCellFactory(CheckBoxTreeCell.<String>forTreeView()); - - genPnl.add(tree, 3); - - pkgTf = genPnl.addLabeled("Package:", Controls.textField()); - pkgTf.setText("org.apache.ignite"); - - genPnl.wrap(); - - outFolderTf = genPnl.addLabeled("Output Folder:", Controls.textField()); - outFolderTf.setText(PATH); - - genPnl.add(Controls.button("...", new EventHandler<ActionEvent>() { - @Override public void handle(ActionEvent evt) { - DirectoryChooser dc = new DirectoryChooser(); - - File folder = dc.showDialog(owner); - - if (folder != null) - outFolderTf.setText(folder.getAbsolutePath()); - } - })); - - pojoConstructorCh = genPnl.add(Controls.checkBox("Generate Constructor For POJO", false), 3); - - xmlSingleFileCh = genPnl.add(Controls.checkBox("Write All Configurations To Single File", true), 3); - } - - return genPnl; - } - - /** * Fill tree with database metadata. */ - private void fill() { + private boolean fill() { rootItem.getChildren().clear(); try { - Class.forName(jdbcTf.getText()); + String driver = jdbcTf.getText(); + + try { + Class.forName(driver); + } + catch (Throwable e) { + MessageBox.errorDialog(owner, "Failed to load JDBC driver: " + e.getMessage()); + + return false; + } try (Connection conn = DriverManager.getConnection(urlTf.getText(), userTf.getText(), pwdTf.getText())) { schemas = DbMetadataParser.parse(conn); @@ -187,9 +117,13 @@ public class SchemaLoadApp extends Application { schemaItem.getChildren().add(new CheckBoxTreeItem<>(tbl)); } } + + return true; } catch (Throwable e) { - MessageBox.showErrorDialog(owner, "Failed to get tables list: " + e.getMessage()); + MessageBox.errorDialog(owner, "Failed to get tables list: " + e.getMessage()); + + return false; } } @@ -223,16 +157,16 @@ public class SchemaLoadApp extends Application { } if (all.isEmpty()) - MessageBox.showInformationDialog(owner, "Warning", "Nothing selected"); + MessageBox.informationDialog(owner, "Nothing selected"); else { if (xmlSingleFileCh.isSelected()) XmlTransformer.transform(pkg, all, new File(outFolder, "all.xml")); - MessageBox.showInformationDialog(owner, "Information", "Generation complete!"); + MessageBox.informationDialog(owner, "Generation complete!"); } } catch (Throwable e) { - MessageBox.showErrorDialog(owner, "Generation failed: " + e.getMessage()); + MessageBox.errorDialog(owner, "Generation failed: " + e.getMessage()); } } @@ -240,7 +174,7 @@ public class SchemaLoadApp extends Application { * @return Header pane with title label. */ private Pane createHeaderPane() { - HBox hb = newHBox(0); + HBox hb = hBox(0); titleLb = new Label(""); titleLb.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20)); @@ -254,19 +188,19 @@ public class SchemaLoadApp extends Application { * @return Panel with control buttons. */ private Pane createButtonsPane() { - prevBtn = Controls.button("Prev", new EventHandler<ActionEvent>() { + prevBtn = button("Prev", new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent evt) { prev(); } }); - nextBtn = Controls.button("Next", new EventHandler<ActionEvent>() { + nextBtn = button("Next", new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent evt) { next(); } }); - HBox hb = newHBox(10); + HBox hb = hBox(10); hb.setAlignment(Pos.BOTTOM_RIGHT); hb.getChildren().addAll(prevBtn, nextBtn); @@ -279,7 +213,7 @@ public class SchemaLoadApp extends Application { private void prev() { titleLb.setText("Connect To Database"); - rootPane.setCenter(connectPane()); + rootPane.setCenter(connPnl); prevBtn.setDisable(true); nextBtn.setText("Next"); @@ -290,14 +224,14 @@ public class SchemaLoadApp extends Application { */ private void next() { if (rootPane.getCenter() == connPnl) { - titleLb.setText("Generate XML And POJOs"); - - rootPane.setCenter(generatePane()); + if (fill()) { + titleLb.setText("Generate XML And POJOs"); - prevBtn.setDisable(false); - nextBtn.setText("Generate"); + rootPane.setCenter(genPnl); - fill(); + prevBtn.setDisable(false); + nextBtn.setText("Generate"); + } } else generate(); @@ -314,8 +248,82 @@ public class SchemaLoadApp extends Application { rootPane = new BorderPane(); + // Connection pane. + connPnl = new GridPaneEx(DFLT_PADDING); + + connPnl.addColumn(); + connPnl.addColumn(100, 100, Double.MAX_VALUE, Priority.ALWAYS); + + jdbcTf = connPnl.addLabeled("JDBC Driver:", textField()); + jdbcTf.setText("org.h2.Driver"); + + urlTf = connPnl.addLabeled("URL:", textField()); + urlTf.setText("jdbc:h2:mem:test"); + + userTf = connPnl.addLabeled("User:", textField()); + userTf.setText("sa"); + + pwdTf = connPnl.addLabeled("Password:", new PasswordField()); + + // Generation pane. + genPnl = new GridPaneEx(DFLT_PADDING); + + genPnl.addColumn(); + genPnl.addColumn(100, 100, Double.MAX_VALUE, Priority.ALWAYS); + genPnl.addColumn(30); + + genPnl.addRow(100, 100, Double.MAX_VALUE, Priority.ALWAYS); + genPnl.addRow(100, 100, 100, Priority.NEVER); + genPnl.addRow(); + genPnl.addRow(); + genPnl.addRow(); + genPnl.addRow(); + + rootItem = new CheckBoxTreeItem<>("Database"); + rootItem.setExpanded(true); + + TreeView<String> tree = new TreeView<>(rootItem); + tree.setCellFactory(CheckBoxTreeCell.<String>forTreeView()); + + genPnl.add(tree, 3); + + TableView<String> tbl = new TableView<>(); + + TableColumn<String, Boolean> keyCol = new TableColumn<>("Key"); + TableColumn<String, String> dbNameCol = new TableColumn<>("Db Name"); + TableColumn<String, String> javaNameCol = new TableColumn<>("Java Name"); + + tbl.getColumns().addAll(keyCol, dbNameCol, javaNameCol); + + tbl.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); + + genPnl.add(tbl, 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>() { + @Override public void handle(ActionEvent evt) { + DirectoryChooser dc = new DirectoryChooser(); + + File folder = dc.showDialog(owner); + + if (folder != null) + outFolderTf.setText(folder.getAbsolutePath()); + } + })); + + pojoConstructorCh = genPnl.add(checkBox("Generate Constructor For POJO", false), 3); + + xmlSingleFileCh = genPnl.add(checkBox("Write All Configurations To Single File", true), 3); + rootPane.setTop(createHeaderPane()); - rootPane.setCenter(connectPane()); + rootPane.setCenter(connPnl); rootPane.setBottom(createButtonsPane()); primaryStage.setScene(new Scene(rootPane)); @@ -323,12 +331,10 @@ public class SchemaLoadApp extends Application { int w = 400; primaryStage.setWidth(w); primaryStage.setMinWidth(w); - primaryStage.setMaxWidth(2 * w); - int h = 400; + int h = 500; primaryStage.setHeight(h); primaryStage.setMinHeight(h); - primaryStage.setMaxHeight(2 * h); prev(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2b0a2d13/modules/schema-load/src/main/java/org/apache/ignite/schema/util/SchemaUtils.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/util/SchemaUtils.java b/modules/schema-load/src/main/java/org/apache/ignite/schema/util/SchemaUtils.java index a4e0d6a..ee1f636 100644 --- a/modules/schema-load/src/main/java/org/apache/ignite/schema/util/SchemaUtils.java +++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/util/SchemaUtils.java @@ -9,17 +9,10 @@ package org.apache.ignite.schema.util; -import javafx.geometry.*; -import javafx.scene.image.*; -import javafx.scene.layout.*; - /** * Utility class with common functions. */ public class SchemaUtils { - /** */ - public static final Insets DFLT_PADDING = new Insets(10, 10, 10, 10); - /** * @param str Source string. * @return String with each word first letters capitalized. @@ -79,43 +72,5 @@ public class SchemaUtils { public static String toJavaFieldName(String name) { return uncapitalizeFirst(toJavaClassName(name)); } - - /** - * Gets image by its filename. - * - * @param imgFileName Image filename. - */ - public static Image image(String imgFileName, int sz) { - return new Image(SchemaUtils.class.getClassLoader() - .getResourceAsStream(String.format("media/%1$s_%2$dx%2$d.png", imgFileName, sz))); - } - - /** - * Create new {@code HBox} with default padding. - * - * @param spacing Amount of horizontal space between each child. - * @return New {@code HBox} instance. - */ - public static HBox newHBox(int spacing) { - HBox hb = new HBox(spacing); - - hb.setPadding(DFLT_PADDING); - - return hb; - } - - /** - * Create new {@code VBox} with default padding. - * - * @param spacing Amount of horizontal space between each child. - * @return New {@code VBox} instance. - */ - public static VBox newVBox(int spacing) { - VBox vb = new VBox(spacing); - - vb.setPadding(DFLT_PADDING); - - return vb; - } }