Repository: incubator-ignite Updated Branches: refs/heads/ignite-32 2238d6fd4 -> 356d3311c
# IGNITE-32 WIP: Implemented custom naming. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/356d3311 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/356d3311 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/356d3311 Branch: refs/heads/ignite-32 Commit: 356d3311c79345a9224791a4bf9e6273a8f7faba Parents: 2238d6f Author: AKuznetsov <akuznet...@gridgain.com> Authored: Fri Jan 9 22:47:05 2015 +0700 Committer: AKuznetsov <akuznet...@gridgain.com> Committed: Fri Jan 9 22:47:05 2015 +0700 ---------------------------------------------------------------------- .../org/apache/ignite/schema/ui/Controls.java | 25 +++- .../org/apache/ignite/schema/ui/GridPaneEx.java | 18 --- .../apache/ignite/schema/ui/NamingDialog.java | 113 +++++++++++++++++- .../apache/ignite/schema/ui/SchemaLoadApp.java | 117 ++++++++++++++----- 4 files changed, 216 insertions(+), 57 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/356d3311/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 99a60b3..864861d 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 @@ -204,10 +204,17 @@ public class Controls { /** * Create text field. * + * @param txt Textual content of this text field. + * @param tip Tooltip text. * @return New {@code TextField} instance. */ - public static TextField textField() { - return new TextField(); + public static TextField textField(String txt, String tip) { + TextField tf = new TextField(); + + tf.setText(txt); + tf.setTooltip(new Tooltip(tip)); + + return tf; } /** @@ -227,6 +234,20 @@ public class Controls { } /** + * Create password field. + * + * @param tip Tooltip text. + * @return New {@code PasswordField} instance. + */ + public static PasswordField passwordField(String tip) { + PasswordField pf = new PasswordField(); + + pf.setTooltip(new Tooltip(tip)); + + return pf; + } + + /** * Create split pane for provided nodes. * * @param node1 First node. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/356d3311/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 6d847ce..c57ce75 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 @@ -28,15 +28,6 @@ public class GridPaneEx extends GridPane { } /** - * Add fixed width column. - * - * @param width Column width. - */ - public void addColumn(double width) { - getColumnConstraints().add(new ColumnConstraints(width)); - } - - /** * Add default column. */ public void addColumn() { @@ -60,15 +51,6 @@ public class GridPaneEx extends GridPane { } /** - * Add fixed height row. - * - * @param height Row height. - */ - public void addRow(double height) { - getRowConstraints().add(new RowConstraints(height)); - } - - /** * Add default row. */ public void addRow() { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/356d3311/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/NamingDialog.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/NamingDialog.java b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/NamingDialog.java index e4269ee..1c94cdf 100644 --- a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/NamingDialog.java +++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/NamingDialog.java @@ -3,6 +3,7 @@ package org.apache.ignite.schema.ui; import javafx.event.*; +import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; @@ -15,12 +16,36 @@ public class NamingDialog extends Stage { /** Owner window. */ private final Stage owner; + /** */ + private final TextField prefixTf; + + /** */ + private final TextField suffixTf; + + /** */ + private final CheckBox regexCh; + + /** */ + private final TextField ptrnTf; + + /** */ + private final TextField replaceTf; + + /** */ + private boolean ok; + /** * Create naming dialog. * * @param owner Owner window. + * @param prefix Prefix. + * @param suffix Suffix. + * @param regex {@code true} if regular expression should be applied to DB names. + * @param ptrn Regular expression pattern. + * @param replace Text to replace. */ - public NamingDialog(Stage owner) { + public NamingDialog(final Stage owner, final String prefix, String suffix, boolean regex, final String ptrn, + final String replace) { this.owner = owner; setTitle("Custom Naming"); @@ -34,18 +59,57 @@ public class NamingDialog extends Stage { pane.addColumn(); pane.addColumn(200, 200, Double.MAX_VALUE, Priority.ALWAYS); - pane.addLabeled("Prefix:", textField()); - pane.addLabeled("Suffix:", textField()); + prefixTf = pane.addLabeled("Prefix:", textField(prefix, "Optional text to add before each DB name")); + + suffixTf = pane.addLabeled("Suffix:", textField(suffix, "Optional text to add after each DB name")); + + regexCh = pane.add(checkBox("Regular expression", + "If selected than DB names will be processed with specified pattern", regex), 2); + + ptrnTf = pane.addLabeled("Pattern:", textField(ptrn, "Regular expression pattern. For example: (.*)-(.*)")); + ptrnTf.setDisable(!regex); + + replaceTf = pane.addLabeled("Replace with:", textField(replace, "Replace text. For example: $1_$2")); + replaceTf.setDisable(!regex); + + regexCh.setOnAction(new EventHandler<ActionEvent>() { + @Override public void handle(ActionEvent evt) { + boolean f = !regexCh.isSelected(); + + ptrnTf.setDisable(f); + replaceTf.setDisable(f); + } + }); pane.add(buttonsPane( button("OK", new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent evt) { - // TODO: CODE: implement. + if (regexCh.isSelected()) { + if (pattern().isEmpty()) { + MessageBox.warningDialog(owner, "Regular expression pattern should not be empty!"); + + ptrnTf.requestFocus(); + + return; + } + + if (replace().isEmpty()) { + MessageBox.warningDialog(owner, "Replace expression should not be empty!"); + + replaceTf.requestFocus(); + + return; + } + } + + ok = true; + + close(); } }), button("Cancel", new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent evt) { - // TODO: CODE: implement. + close(); } })), 2); @@ -53,14 +117,51 @@ public class NamingDialog extends Stage { } /** + * @return Prefix. + */ + public String prefix() { + return prefixTf.getText().trim(); + } + + /** + * @return Suffix. + */ + public String suffix() { + return suffixTf.getText().trim(); + } + + /** + * @return {@code true} if regexp should be applied to DB name. + */ + public boolean regexp() { + return regexCh.isSelected(); + } + + /** + * @return Regex pattern. + */ + public String pattern() { + return ptrnTf.getText().trim(); + } + + /** + * @return Replace text. + */ + public String replace() { + return replaceTf.getText().trim(); + } + + /** * Show modal dialog. */ - public void showDialog() { + public boolean showDialog() { sizeToScene(); setX(owner.getX() + owner.getWidth() / 6); setY(owner.getY() + owner.getHeight() / 4); showAndWait(); + + return ok; } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/356d3311/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 5547fdf..16fe000 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 @@ -32,9 +32,11 @@ import java.util.*; import java.util.List; import java.util.concurrent.*; import java.util.prefs.*; +import java.util.regex.*; import static javafx.embed.swing.SwingFXUtils.*; import static org.apache.ignite.schema.ui.Controls.*; +import static org.apache.ignite.schema.util.SchemaUtils.*; /** * Schema load application. @@ -115,17 +117,29 @@ public class SchemaLoadApp extends Application { /** */ private ProgressIndicator pi; + /** */ + private String prefix; + + /** */ + private String suffix; + + /** */ + private boolean regex; + + /** */ + private String ptrn; + + /** */ + private String replace; + /** Map with types metadata. */ private LinkedHashMap<String, LinkedHashMap<String, GridCacheQueryTypeMetadata>> metas; /** Map with fields descriptors. */ - private Map<String, Map<String, List<Field>>> fields; - - /** Fields collection of currently selected table. */ - private List<Field> curFields; + private Map<String, Map<String, ObservableList<Field>>> fields; /** */ - private final ObservableList<Field> noData = FXCollections.emptyObservableList(); + private static final ObservableList<Field> NO_DATA = FXCollections.emptyObservableList(); /** */ private final Map<String, Driver> drivers = new HashMap<>(); @@ -207,7 +221,7 @@ public class SchemaLoadApp extends Application { LinkedHashMap<String, GridCacheQueryTypeMetadata> tbls = meta.getValue(); - Map<String, List<Field>> tblsFields = U.newHashMap(tbls.size()); + Map<String, ObservableList<Field>> tblsFields = U.newHashMap(tbls.size()); fields.put(schema, tblsFields); @@ -220,13 +234,13 @@ public class SchemaLoadApp extends Application { List<Field> tblFields = new ArrayList<>(keys.size() + vals.size()); - tblsFields.put(type.getTableName(), tblFields); - for (GridCacheQueryTypeDescriptor key : keys) tblFields.add(new Field(true, key)); for (GridCacheQueryTypeDescriptor val : vals) tblFields.add(new Field(false, val)); + + tblsFields.put(type.getTableName(), FXCollections.observableList(tblFields)); } } @@ -241,7 +255,7 @@ public class SchemaLoadApp extends Application { rootItem.getChildren().clear(); - for (Map.Entry<String, Map<String, List<Field>>> schema : fields.entrySet()) { + for (Map.Entry<String, Map<String, ObservableList<Field>>> schema : fields.entrySet()) { CheckBoxTreeItem<String> schemaItem = new CheckBoxTreeItem<>(schema.getKey()); for (String tbl : schema.getValue().keySet()) @@ -338,10 +352,33 @@ public class SchemaLoadApp extends Application { Collection<GridCacheQueryTypeDescriptor> vals = new ArrayList<>(); + boolean customNaming = !dfltNamingCh.isSelected(); + // Fill list with key and value type descriptors. for (Field fld : tblFields) { GridCacheQueryTypeDescriptor desc = fld.descriptor(); + if (customNaming) { + String javaName = toJavaFieldName(desc.getDbName()); + + if (!prefix.isEmpty()) + javaName = prefix + capitalizeFirst(javaName); + + if (!suffix.isEmpty()) + javaName += suffix; + + try { + if (regex) + javaName = javaName.replaceAll(ptrn, replace); + } + catch (PatternSyntaxException e) { + throw new IllegalStateException("Failed to apply regexp [" + ptrn + "] to [" + + javaName + "]", e); + } + + desc.setJavaName(javaName); + } + if (fld.isKey()) { keys.add(desc); @@ -536,14 +573,16 @@ public class SchemaLoadApp extends Application { connPnl.addColumn(100, 100, Double.MAX_VALUE, Priority.ALWAYS); connPnl.addColumn(35, 35, 35, Priority.NEVER); - jdbcDrvJarTf = connPnl.addLabeled("Driver JAR:", textField()); + jdbcDrvJarTf = connPnl.addLabeled("Driver JAR:", textField("", "Path to driver jar")); connPnl.add(button("...", new EventHandler<ActionEvent>() { /** {@inheritDoc} */ @Override public void handle(ActionEvent evt) { FileChooser fc = new FileChooser(); - fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("JDBC Drivers (*.jar)", "*.jar")); + fc.getExtensionFilters().addAll( + new FileChooser.ExtensionFilter("JDBC Drivers (*.jar)", "*.jar"), + new FileChooser.ExtensionFilter("ZIP archives (*.zip)", "*.zip")); File drvJar = fc.showOpenDialog(owner); @@ -552,13 +591,13 @@ public class SchemaLoadApp extends Application { } })); - jdbcDrvClsTf = connPnl.addLabeled("JDBC Driver:", textField(), 2); + jdbcDrvClsTf = connPnl.addLabeled("JDBC Driver:", textField("", "Class name for JDBC driver"), 2); - jdbcUrlTf = connPnl.addLabeled("URL:", textField(), 2); + jdbcUrlTf = connPnl.addLabeled("URL:", textField("", "URL of the database connection string"), 2); - userTf = connPnl.addLabeled("User:", textField(), 2); + userTf = connPnl.addLabeled("User:", textField("", "User name"), 2); - pwdTf = connPnl.addLabeled("Password:", new PasswordField(), 2); + pwdTf = connPnl.addLabeled("Password:", passwordField("User password"), 2); connLayerPnl = stackPane(connPnl); @@ -614,7 +653,6 @@ public class SchemaLoadApp extends Application { ObservableList<Field> items = tbl.getItems(); items.add(selIdx - 1, items.remove(selIdx)); - curFields.add(selIdx - 1, curFields.remove(selIdx)); selMdl.select(selIdx - 1); } @@ -634,7 +672,6 @@ public class SchemaLoadApp extends Application { if (selIdx < items.size() - 1) { items.add(selIdx + 1, items.remove(selIdx)); - curFields.add(selIdx + 1, curFields.remove(selIdx)); selMdl.select(selIdx + 1); } @@ -661,28 +698,23 @@ public class SchemaLoadApp extends Application { @Override public void changed(ObservableValue<? extends TreeItem<String>> val, TreeItem<String> oldItem, TreeItem<String> newItem) { if (newItem != null && newItem.getParent() != null && newItem.isLeaf()) { - curFields = fields.get(newItem.getParent().getValue()).get(newItem.getValue()); - - tbl.setItems(FXCollections.observableArrayList(curFields)); + tbl.setItems(fields.get(newItem.getParent().getValue()).get(newItem.getValue())); tbl.getSelectionModel().select(0); } else { - tbl.setItems(noData); + tbl.setItems(NO_DATA); upBtn.setDisable(true); downBtn.setDisable(true); } - } }); genPnl.add(splitPane(tree, borderPane(null, tbl, null, null, vBox(10, upBtn, downBtn)), 0.6), 3); - pkgTf = genPnl.addLabeled("Package:", textField()); + pkgTf = genPnl.addLabeled("Package:", textField("", "Package that will be used for POJOs generation"), 2); - genPnl.wrap(); - - outFolderTf = genPnl.addLabeled("Output Folder:", textField()); + outFolderTf = genPnl.addLabeled("Output Folder:", textField("", "Output folder for POJOs and XML files")); genPnl.add(button("...", new EventHandler<ActionEvent>() { /** {@inheritDoc} */ @@ -711,9 +743,15 @@ public class SchemaLoadApp extends Application { btnNaming = button("Configure Naming", new EventHandler<ActionEvent>() { /** {@inheritDoc} */ @Override public void handle(ActionEvent evt) { - NamingDialog dlg = new NamingDialog(owner); - - dlg.showDialog(); + NamingDialog dlg = new NamingDialog(owner, prefix, suffix, regex, ptrn, replace); + + if (dlg.showDialog()) { + prefix = dlg.prefix(); + suffix = dlg.suffix(); + regex = dlg.regexp(); + ptrn = dlg.pattern(); + replace = dlg.replace(); + } } }); @@ -724,10 +762,10 @@ public class SchemaLoadApp extends Application { } }); - genPnl.add(hBox(10, false, dfltNamingCh, btnNaming), 3); + genPnl.add(hBox(10, false, dfltNamingCh, btnNaming), 3).setAlignment(Pos.CENTER_LEFT); openFolderCh = genPnl.add(checkBox("Reveal output folder", - "Open output folder in system file manager after generation complete", true)); + "Open output folder in system file manager after generation complete", true), 3); genLayerPnl = stackPane(genPnl); } @@ -800,11 +838,20 @@ public class SchemaLoadApp extends Application { // Restore generation pane settings. outFolderTf.setText(userPrefs.get("out.folder", userHome + "/schema-load/out")); openFolderCh.setSelected(userPrefs.getBoolean("out.folder.open", true)); + pkgTf.setText(userPrefs.get("pojo.package", "org.apache.ignite")); pojoIncludeKeysCh.setSelected(userPrefs.getBoolean("pojo.include", true)); pojoConstructorCh.setSelected(userPrefs.getBoolean("pojo.constructor", false)); + xmlSingleFileCh.setSelected(userPrefs.getBoolean("xml.single", true)); + dfltNamingCh.setSelected(userPrefs.getBoolean("naming.default", true)); + prefix = userPrefs.get("naming.prefix", ""); + suffix = userPrefs.get("naming.suffix", ""); + regex = userPrefs.getBoolean("naming.regex", false); + ptrn = userPrefs.get("naming.pattern", ""); + replace = userPrefs.get("naming.replace", ""); + btnNaming.setDisable(dfltNamingCh.isSelected()); primaryStage.show(); @@ -829,11 +876,19 @@ public class SchemaLoadApp extends Application { // Save generation pane settings. userPrefs.put("out.folder", outFolderTf.getText()); userPrefs.putBoolean("out.folder.open", openFolderCh.isSelected()); + 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()); + userPrefs.put("naming.prefix", prefix); + userPrefs.put("naming.suffix", suffix); + userPrefs.putBoolean("naming.regex", regex); + userPrefs.put("naming.pattern", ptrn); + userPrefs.put("naming.replace", replace); } /**