You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2017/04/06 16:07:56 UTC
[5/7] ignite git commit: IGNITE-4349 Removed Schema import utility.
http://git-wip-us.apache.org/repos/asf/ignite/blob/137aefbe/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
deleted file mode 100644
index df54e04..0000000
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
+++ /dev/null
@@ -1,446 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.schema.generator;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import org.apache.ignite.cache.QueryEntity;
-import org.apache.ignite.cache.QueryIndex;
-import org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory;
-import org.apache.ignite.cache.store.jdbc.JdbcType;
-import org.apache.ignite.cache.store.jdbc.JdbcTypeField;
-import org.apache.ignite.internal.util.typedef.T2;
-import org.apache.ignite.schema.model.PojoDescriptor;
-import org.apache.ignite.schema.model.PojoField;
-import org.apache.ignite.schema.ui.ConfirmCallable;
-import org.apache.ignite.schema.ui.MessageBox;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-import static org.apache.ignite.schema.ui.MessageBox.Result.CANCEL;
-import static org.apache.ignite.schema.ui.MessageBox.Result.NO;
-import static org.apache.ignite.schema.ui.MessageBox.Result.NO_TO_ALL;
-
-/**
- * Generator of XML files for type metadata.
- */
-public class XmlGenerator {
- /**
- * Add comment with license and generation date.
- *
- * @param doc XML document.
- */
- private static void addComment(Document doc) {
- doc.appendChild(doc.createComment("\n" +
- " Licensed to the Apache Software Foundation (ASF) under one or more\n" +
- " contributor license agreements. See the NOTICE file distributed with\n" +
- " this work for additional information regarding copyright ownership.\n" +
- " The ASF licenses this file to You under the Apache License, Version 2.0\n" +
- " (the \"License\"); you may not use this file except in compliance with\n" +
- " the License. You may obtain a copy of the License at\n\n" +
- " http://www.apache.org/licenses/LICENSE-2.0\n\n" +
- " Unless required by applicable law or agreed to in writing, software\n" +
- " distributed under the License is distributed on an \"AS IS\" BASIS,\n" +
- " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +
- " See the License for the specific language governing permissions and\n" +
- " limitations under the License.\n"));
-
- doc.appendChild(doc.createComment("\n XML generated by Apache Ignite Schema Import utility: " +
- new SimpleDateFormat("MM/dd/yyyy").format(new Date()) + "\n"));
- }
-
- /**
- * Add bean to XML document.
- *
- * @param doc XML document.
- * @param parent Parent XML node.
- * @param cls Bean class.
- */
- private static Element addBean(Document doc, Node parent, Class<?> cls) {
- Element elem = doc.createElement("bean");
-
- elem.setAttribute("class", cls.getName());
-
- parent.appendChild(elem);
-
- return elem;
- }
-
- /**
- * Add element to XML document.
- *
- * @param doc XML document.
- * @param parent Parent XML node.
- * @param tagName XML tag name.
- * @param attr1 Name for first attr.
- * @param val1 Value for first attribute.
- * @param attr2 Name for second attr.
- * @param val2 Value for second attribute.
- */
- private static Element addElement(Document doc, Node parent, String tagName,
- String attr1, String val1, String attr2, String val2) {
- Element elem = doc.createElement(tagName);
-
- if (attr1 != null)
- elem.setAttribute(attr1, val1);
-
- if (attr2 != null)
- elem.setAttribute(attr2, val2);
-
- parent.appendChild(elem);
-
- return elem;
- }
-
- /**
- * Add element to XML document.
- *
- * @param doc XML document.
- * @param parent Parent XML node.
- * @param tagName XML tag name.
- */
- private static Element addElement(Document doc, Node parent, String tagName) {
- return addElement(doc, parent, tagName, null, null, null, null);
- }
-
- /**
- * Add element to XML document.
- *
- * @param doc XML document.
- * @param parent Parent XML node.
- * @param tagName XML tag name.
- */
- private static Element addElement(Document doc, Node parent, String tagName, String attrName, String attrVal) {
- return addElement(doc, parent, tagName, attrName, attrVal, null, null);
- }
-
- /**
- * Add "property" element to XML document.
- *
- * @param doc XML document.
- * @param parent Parent XML node.
- * @param name Value for "name" attribute
- * @param val Value for "value" attribute
- */
- private static Element addProperty(Document doc, Node parent, String name, String val) {
- String valAttr = val != null ? "value" : null;
-
- return addElement(doc, parent, "property", "name", name, valAttr, val);
- }
-
- /**
- * Add type descriptors to XML document.
- *
- * @param doc XML document.
- * @param parent Parent XML node.
- * @param name Property name.
- * @param fields Collection of POJO fields.
- */
- private static void addJdbcFields(Document doc, Node parent, String name, Collection<PojoField> fields) {
- if (!fields.isEmpty()) {
- Element prop = addProperty(doc, parent, name, null);
-
- Element list = addElement(doc, prop, "list");
-
- for (PojoField field : fields) {
- Element item = addBean(doc, list, JdbcTypeField.class);
-
- Element dbType = addProperty(doc, item, "databaseFieldType", null);
- addElement(doc, dbType, "util:constant", "static-field", "java.sql.Types." + field.dbTypeName());
- addProperty(doc, item, "databaseFieldName", field.dbName());
- addProperty(doc, item, "javaFieldType", field.javaTypeName());
- addProperty(doc, item, "javaFieldName", field.javaName());
- }
- }
- }
-
- /**
- * Add query fields to xml document.
- *
- * @param doc XML document.
- * @param parent Parent XML node.
- * @param fields Map with fields.
- */
- private static void addQueryFields(Document doc, Node parent, Collection<PojoField> fields) {
- if (!fields.isEmpty()) {
- Element prop = addProperty(doc, parent, "fields", null);
-
- Element map = addElement(doc, prop, "util:map", "map-class", "java.util.LinkedHashMap");
-
- for (PojoField field : fields)
- addElement(doc, map, "entry", "key", field.javaName(), "value",
- GeneratorUtils.boxPrimitiveType(field.javaTypeName()));
- }
- }
-
- /**
- * Add query field aliases to xml document.
- *
- * @param doc XML document.
- * @param parent Parent XML node.
- * @param fields Map with fields.
- */
- private static void addQueryFieldAliases(Document doc, Node parent, Collection<PojoField> fields) {
- Collection<PojoField> aliases = new ArrayList<>();
-
- for (PojoField field : fields) {
- if (!field.javaName().equalsIgnoreCase(field.dbName()))
- aliases.add(field);
- }
-
- if (!aliases.isEmpty()) {
- Element prop = addProperty(doc, parent, "aliases", null);
-
- Element map = addElement(doc, prop, "map");
-
- for (PojoField alias : aliases)
- addElement(doc, map, "entry", "key", alias.javaName(), "value", alias.dbName());
- }
- }
-
- /**
- * Add indexes to xml document.
- *
- * @param doc XML document.
- * @param parent Parent XML node.
- * @param idxs Indexes.
- */
- private static void addQueryIndexes(Document doc, Node parent, Collection<PojoField> fields,
- Collection<QueryIndex> idxs) {
- if (!idxs.isEmpty()) {
- boolean firstIdx = true;
-
- Element list = null;
-
- for (QueryIndex idx : idxs) {
- Set<Map.Entry<String, Boolean>> dbIdxFlds = idx.getFields().entrySet();
-
- int sz = dbIdxFlds.size();
-
- List<T2<String, Boolean>> idxFlds = new ArrayList<>(sz);
-
- for (Map.Entry<String, Boolean> idxFld : dbIdxFlds) {
- PojoField field = GeneratorUtils.findFieldByName(fields, idxFld.getKey());
-
- if (field != null)
- idxFlds.add(new T2<>(field.javaName(), idxFld.getValue()));
- else
- break;
- }
-
- // Only if all fields present, add index description.
- if (idxFlds.size() == sz) {
- if (firstIdx) {
- Element prop = addProperty(doc, parent, "indexes", null);
-
- list = addElement(doc, prop, "list");
-
- firstIdx = false;
- }
-
- Element idxBean = addBean(doc, list, QueryIndex.class);
-
- addProperty(doc, idxBean, "name", idx.getName());
-
- Element idxType = addProperty(doc, idxBean, "indexType", null);
- addElement(doc, idxType, "util:constant", "static-field", "org.apache.ignite.cache.QueryIndexType." + idx.getIndexType());
-
- Element flds = addProperty(doc, idxBean, "fields", null);
-
- Element fldsMap = addElement(doc, flds, "map");
-
- for (T2<String, Boolean> fld : idxFlds)
- addElement(doc, fldsMap, "entry", "key", fld.getKey(), "value", fld.getValue().toString());
- }
- }
- }
- }
-
- /**
- * Add element with JDBC POJO store factory to XML document.
- *
- * @param doc XML document.
- * @param parent Parent XML node.
- * @param pkg Package fo types.
- * @param pojo POJO descriptor.
- */
- private static void addJdbcPojoStoreFactory(Document doc, Node parent, String pkg, PojoDescriptor pojo,
- boolean includeKeys) {
- Element bean = addBean(doc, parent, JdbcType.class);
-
- addProperty(doc, bean, "databaseSchema", pojo.schema());
-
- addProperty(doc, bean, "databaseTable", pojo.table());
-
- addProperty(doc, bean, "keyType", pkg + "." + pojo.keyClassName());
-
- addProperty(doc, bean, "valueType", pkg + "." + pojo.valueClassName());
-
- addJdbcFields(doc, bean, "keyFields", pojo.keyFields());
-
- addJdbcFields(doc, bean, "valueFields", pojo.valueFields(includeKeys));
- }
-
- /**
- * Add element with query entity to XML document.
- *
- * @param doc XML document.
- * @param parent Parent XML node.
- * @param pkg Package fo types.
- * @param pojo POJO descriptor.
- * @param generateAliases {@code true} if aliases should be generated for query fields.
- */
- private static void addQueryEntity(Document doc, Node parent, String pkg, PojoDescriptor pojo, boolean generateAliases) {
- Element bean = addBean(doc, parent, QueryEntity.class);
-
- addProperty(doc, bean, "keyType", pkg + "." + pojo.keyClassName());
-
- addProperty(doc, bean, "valueType", pkg + "." + pojo.valueClassName());
-
- Collection<PojoField> fields = pojo.valueFields(true);
-
- addQueryFields(doc, bean, fields);
-
- if (generateAliases)
- addQueryFieldAliases(doc, bean, fields);
-
- addQueryIndexes(doc, bean, fields, pojo.indexes());
- }
-
- /**
- * Transform metadata into xml.
- *
- * @param pkg Package fo types.
- * @param pojo POJO descriptor.
- * @param includeKeys {@code true} if key fields should be included into value class.
- * @param generateAliases {@code true} if aliases should be generated for query fields.
- * @param out File to output result.
- * @param askOverwrite Callback to ask user to confirm file overwrite.
- */
- public static void generate(String pkg, PojoDescriptor pojo, boolean includeKeys, boolean generateAliases, File out,
- ConfirmCallable askOverwrite) {
- generate(pkg, Collections.singleton(pojo), includeKeys, generateAliases, out, askOverwrite);
- }
-
- /**
- * Transform metadata into xml.
- *
- * @param pkg Package fo types.
- * @param pojos POJO descriptors.
- * @param includeKeys {@code true} if key fields should be included into value class.
- * @param generateAliases {@code true} if aliases should be generated for query fields.
- * @param out File to output result.
- * @param askOverwrite Callback to ask user to confirm file overwrite.
- */
- public static void generate(String pkg, Collection<PojoDescriptor> pojos, boolean includeKeys,
- boolean generateAliases, File out, ConfirmCallable askOverwrite) {
-
- File outFolder = out.getParentFile();
-
- if (outFolder == null)
- throw new IllegalStateException("Invalid output file: " + out);
-
- if (!outFolder.exists() && !outFolder.mkdirs())
- throw new IllegalStateException("Failed to create output folder for XML file: " + outFolder);
-
- try {
- if (out.exists()) {
- MessageBox.Result choice = askOverwrite.confirm(out.getName());
-
- if (CANCEL == choice)
- throw new IllegalStateException("XML generation was canceled!");
-
- if (NO == choice || NO_TO_ALL == choice)
- return;
- }
-
- DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
-
- DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
-
- Document doc = docBuilder.newDocument();
- doc.setXmlStandalone(true);
-
- addComment(doc);
-
- Element beans = addElement(doc, doc, "beans");
- beans.setAttribute("xmlns", "http://www.springframework.org/schema/beans");
- beans.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
- beans.setAttribute("xmlns:util", "http://www.springframework.org/schema/util");
- beans.setAttribute("xsi:schemaLocation",
- "http://www.springframework.org/schema/beans " +
- "http://www.springframework.org/schema/beans/spring-beans.xsd " +
- "http://www.springframework.org/schema/util " +
- "http://www.springframework.org/schema/util/spring-util.xsd");
-
- Element factoryBean = addBean(doc, beans, CacheJdbcPojoStoreFactory.class);
- Element typesElem = addProperty(doc, factoryBean, "types", null);
- Element typesItemsElem = addElement(doc, typesElem, "list");
-
- for (PojoDescriptor pojo : pojos)
- addJdbcPojoStoreFactory(doc, typesItemsElem, pkg, pojo, includeKeys);
-
- for (PojoDescriptor pojo : pojos)
- addQueryEntity(doc, beans, pkg, pojo, generateAliases);
-
- TransformerFactory transformerFactory = TransformerFactory.newInstance();
-
- Transformer transformer = transformerFactory.newTransformer();
-
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream(65536);
-
- transformer.transform(new DOMSource(doc), new StreamResult(baos));
-
- // Custom pretty-print of generated XML.
- Files.write(out.toPath(), baos.toString()
- .replaceAll("><", ">\n<")
- .replaceFirst("<!--", "\n<!--")
- .replaceFirst("-->", "-->\n")
- .replaceAll("\" xmlns", "\"\n xmlns")
- .replaceAll("\" xsi", "\"\n xsi")
- .replaceAll(" http://www.springframework", "\n http://www.springframework")
- .getBytes());
- }
- catch (ParserConfigurationException | TransformerException | IOException e) {
- throw new IllegalStateException(e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/137aefbe/modules/schema-import/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java
deleted file mode 100644
index 4f696d6..0000000
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java
+++ /dev/null
@@ -1,497 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.schema.model;
-
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import javafx.beans.property.BooleanProperty;
-import javafx.beans.property.SimpleBooleanProperty;
-import javafx.beans.property.SimpleStringProperty;
-import javafx.beans.property.StringProperty;
-import javafx.beans.value.ChangeListener;
-import javafx.beans.value.ObservableValue;
-import javafx.collections.FXCollections;
-import javafx.collections.ObservableList;
-import org.apache.ignite.cache.QueryIndex;
-import org.apache.ignite.schema.parser.DbColumn;
-import org.apache.ignite.schema.parser.DbTable;
-
-import static java.sql.Types.BIGINT;
-import static java.sql.Types.BIT;
-import static java.sql.Types.BOOLEAN;
-import static java.sql.Types.CHAR;
-import static java.sql.Types.CLOB;
-import static java.sql.Types.DATE;
-import static java.sql.Types.DECIMAL;
-import static java.sql.Types.DOUBLE;
-import static java.sql.Types.FLOAT;
-import static java.sql.Types.INTEGER;
-import static java.sql.Types.LONGNVARCHAR;
-import static java.sql.Types.LONGVARCHAR;
-import static java.sql.Types.NCHAR;
-import static java.sql.Types.NCLOB;
-import static java.sql.Types.NUMERIC;
-import static java.sql.Types.NVARCHAR;
-import static java.sql.Types.REAL;
-import static java.sql.Types.SMALLINT;
-import static java.sql.Types.SQLXML;
-import static java.sql.Types.TIME;
-import static java.sql.Types.TIMESTAMP;
-import static java.sql.Types.TINYINT;
-import static java.sql.Types.VARCHAR;
-
-/**
- * Descriptor for java type.
- */
-public class PojoDescriptor {
- /** Database table. */
- private final DbTable tbl;
-
- /** Selected property. */
- private final BooleanProperty useProp;
-
- /** Previous name for key class. */
- private final String keyClsNamePrev;
-
- /** Key class name to show on screen. */
- private final StringProperty keyClsNameProp;
-
- /** Previous name for value class. */
- private final String valClsNamePrev;
-
- /** Value class name to show on screen. */
- private final StringProperty valClsNameProp;
-
- /** Parent item (schema name). */
- private final PojoDescriptor parent;
-
- /** Children items (tables names). */
- private Collection<PojoDescriptor> children = Collections.emptyList();
-
- /** Indeterminate state of parent. */
- private final BooleanProperty indeterminateProp = new SimpleBooleanProperty(false);
-
- /** Full database name: schema + table. */
- private final String fullDbName;
-
- /** Java class fields. */
- private final ObservableList<PojoField> fields;
-
- /**
- * Constructor of POJO descriptor.
- *
- * @param prn Parent descriptor.
- * @param tbl Database table Tab;e.
- */
- public PojoDescriptor(PojoDescriptor prn, DbTable tbl) {
- parent = prn;
-
- this.tbl = tbl;
-
- fullDbName = tbl.schema() + "." + tbl.table();
-
- valClsNamePrev = toJavaClassName(tbl.table());
- valClsNameProp = new SimpleStringProperty(valClsNamePrev);
-
- keyClsNamePrev = valClsNamePrev.isEmpty() ? "" : valClsNamePrev + "Key";
- keyClsNameProp = new SimpleStringProperty(keyClsNamePrev);
-
- Collection<DbColumn> cols = tbl.columns();
-
- List<PojoField> flds = new ArrayList<>(cols.size());
-
- for (DbColumn col : cols) {
- String colName = col.name();
-
- PojoField fld = new PojoField(colName, col.type(),
- toJavaFieldName(colName), toJavaType(col).getName(),
- col.key(), col.nullable());
-
- fld.owner(this);
-
- flds.add(fld);
- }
-
- fields = FXCollections.observableList(flds);
-
- boolean isTbl = parent != null;
-
- boolean hasKeys = !isTbl || !keyFields().isEmpty();
-
- useProp = new SimpleBooleanProperty(hasKeys);
-
- if (isTbl && !hasKeys && !parent.indeterminateProp.get())
- parent.indeterminateProp.set(true);
-
- useProp.addListener(new ChangeListener<Boolean>() {
- @Override public void changed(ObservableValue<? extends Boolean> val, Boolean oldVal, Boolean newVal) {
- for (PojoDescriptor child : children)
- child.useProp.set(newVal);
-
- if (parent != null && !parent.children.isEmpty()) {
- Iterator<PojoDescriptor> it = parent.children.iterator();
-
- boolean parentIndeterminate = false;
- boolean first = it.next().useProp.get();
-
- while (it.hasNext()) {
- if (it.next().useProp.get() != first) {
- parentIndeterminate = true;
-
- break;
- }
- }
-
- parent.indeterminateProp.set(parentIndeterminate);
-
- if (!parentIndeterminate)
- parent.useProp.set(first);
- }
- }
- });
- }
-
- /**
- * @return Parent descriptor.
- */
- public PojoDescriptor parent() {
- return parent;
- }
-
- /**
- * @return Full database name: schema + table.
- */
- public String fullDbName() {
- return fullDbName;
- }
-
- /**
- * @return {@code true} if POJO descriptor is a table descriptor and checked in GUI.
- */
- public boolean checked() {
- return parent != null && useProp.get();
- }
-
- /**
- * @return Boolean property support for {@code use} property.
- */
- public BooleanProperty useProperty() {
- return useProp;
- }
-
- /**
- * @return Boolean property support for parent {@code indeterminate} property.
- */
- public BooleanProperty indeterminate() {
- return indeterminateProp;
- }
-
- /**
- * @return Key class name.
- */
- public String keyClassName() {
- return keyClsNameProp.get();
- }
-
- /**
- * @param name New key class name.
- */
- public void keyClassName(String name) {
- keyClsNameProp.set(name);
- }
-
- /**
- * @return Value class name.
- */
- public String valueClassName() {
- return valClsNameProp.get();
- }
-
- /**
- * @param name New value class name.
- */
- public void valueClassName(String name) {
- valClsNameProp.set(name);
- }
-
- /**
- * @return {@code true} if at least one field checked as "used".
- */
- public boolean hasFields() {
- for (PojoField field : fields)
- if (field.use())
- return true;
-
- return false;
- }
-
- /**
- * @return {@code true} if at least one field checked as "used" and checked as "key".
- */
- public boolean hasKeyFields() {
- for (PojoField field : fields)
- if (field.use() && field.key())
- return true;
-
- return false;
- }
-
- /**
- * @param includeKeys {@code true} if key fields should be included into value class.
- * @return {@code true} if at least one field checked as "used" and not checked as "key".
- */
- public boolean hasValueFields(boolean includeKeys) {
- if (includeKeys)
- return hasKeyFields();
-
- for (PojoField field : fields)
- if (field.use() && !field.key())
- return true;
-
- return false;
- }
-
- /**
- * @return Collection of key fields.
- */
- public Collection<PojoField> keyFields() {
- Collection<PojoField> keys = new ArrayList<>();
-
- for (PojoField field : fields)
- if (field.use() && field.key() )
- keys.add(field);
-
- return keys;
- }
-
- /**
- * @param includeKeys {@code true} if key fields should be included into value class.
- * @return Collection of value fields.
- */
- public Collection<PojoField> valueFields(boolean includeKeys) {
- Collection<PojoField> vals = new ArrayList<>();
-
- for (PojoField field : fields)
- if (field.use() && (includeKeys || !field.key()))
- vals.add(field);
-
- return vals;
- }
-
- /**
- * Gets indexes indexes.
- *
- * @return Collection with indexes.
- */
- public Collection<QueryIndex> indexes() {
- return tbl.indexes();
- }
-
- /**
- * @return Key class name property.
- */
- public StringProperty keyClassNameProperty() {
- return keyClsNameProp;
- }
-
- /**
- * @return Value class name property.
- */
- public StringProperty valueClassNameProperty() {
- return valClsNameProp;
- }
-
- /**
- * @return Schema name.
- */
- public String schema() {
- return tbl.schema();
- }
-
- /**
- * @return Table name.
- */
- public String table() {
- return tbl.table();
- }
-
- /**
- * Sets children items.
- *
- * @param children Items to set.
- */
- public void children(Collection<PojoDescriptor> children) {
- this.children = children;
- }
-
- /**
- * @return {@code true} if descriptor was changed by user via GUI.
- */
- public boolean changed() {
- if (!keyClsNameProp.get().equals(keyClsNamePrev) || !valClsNameProp.get().equals(valClsNamePrev))
- return true;
-
- for (PojoField field : fields)
- if (field.changed())
- return true;
-
- return false;
- }
-
- /**
- * Revert changes to key class name made by user.
- */
- public void revertKeyClassName() {
- keyClsNameProp.set(keyClsNamePrev);
- }
-
- /**
- * Revert changes to value class name made by user.
- */
- public void revertValueClassName() {
- valClsNameProp.set(valClsNamePrev);
- }
-
- /**
- * Revert changes to java names made by user.
- */
- public void revertJavaNames() {
- for (PojoField field : fields)
- field.resetJavaName();
- }
-
- /**
- * @return Java class fields.
- */
- public ObservableList<PojoField> fields() {
- return fields;
- }
-
- /**
- * @param name Source name.
- * @return String converted to java class name notation.
- */
- private static String toJavaClassName(String name) {
- int len = name.length();
-
- StringBuilder buf = new StringBuilder(len);
-
- boolean capitalizeNext = true;
-
- for (int i = 0; i < len; i++) {
- char ch = name.charAt(i);
-
- if (Character.isWhitespace(ch) || '_' == ch)
- capitalizeNext = true;
- else if (capitalizeNext) {
- buf.append(Character.toUpperCase(ch));
-
- capitalizeNext = false;
- }
- else
- buf.append(Character.toLowerCase(ch));
- }
-
- return buf.toString();
- }
-
- /**
- * @param name Source name.
- * @return String converted to java field name notation.
- */
- private static String toJavaFieldName(String name) {
- String javaName = toJavaClassName(name);
-
- return Character.toLowerCase(javaName.charAt(0)) + javaName.substring(1);
- }
-
- /**
- * Convert JDBC data type to java type.
- *
- * @param col Database column descriptor.
- * @return Java data type.
- */
- private static Class<?> toJavaType(DbColumn col) {
- boolean nullable = col.nullable();
- boolean unsigned = col.unsigned();
-
- switch (col.type()) {
- case BIT:
- case BOOLEAN:
- return nullable ? Boolean.class : boolean.class;
-
- case TINYINT:
- return unsigned
- ? (nullable ? Short.class : short.class)
- : (nullable ? Byte.class : byte.class);
-
- case SMALLINT:
- return unsigned
- ? (nullable ? Integer.class : int.class)
- : (nullable ? Short.class : short.class);
-
- case INTEGER:
- return unsigned
- ? (nullable ? Long.class : long.class)
- : (nullable ? Integer.class : int.class);
-
- case BIGINT:
- return nullable ? Long.class : long.class;
-
- case REAL:
- return nullable ? Float.class : float.class;
-
- case FLOAT:
- case DOUBLE:
- return nullable ? Double.class : double.class;
-
- case NUMERIC:
- case DECIMAL:
- return BigDecimal.class;
-
- case CHAR:
- case VARCHAR:
- case LONGVARCHAR:
- case NCHAR:
- case NVARCHAR:
- case LONGNVARCHAR:
- case CLOB:
- case NCLOB:
- case SQLXML:
- return String.class;
-
- case DATE:
- return java.sql.Date.class;
-
- case TIME:
- return java.sql.Time.class;
-
- case TIMESTAMP:
- return java.sql.Timestamp.class;
-
- // BINARY, VARBINARY, LONGVARBINARY, ARRAY, BLOB, NULL, DATALINK
- // OTHER, JAVA_OBJECT, DISTINCT, STRUCT, REF, ROWID
- default:
- return Object.class;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/137aefbe/modules/schema-import/src/main/java/org/apache/ignite/schema/model/PojoField.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/model/PojoField.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/model/PojoField.java
deleted file mode 100644
index 3ee2f8c..0000000
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/model/PojoField.java
+++ /dev/null
@@ -1,461 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.schema.model;
-
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.List;
-import javafx.beans.property.BooleanProperty;
-import javafx.beans.property.SimpleBooleanProperty;
-import javafx.beans.property.SimpleStringProperty;
-import javafx.beans.property.StringProperty;
-import javafx.beans.value.ChangeListener;
-import javafx.beans.value.ObservableValue;
-import javafx.collections.FXCollections;
-import javafx.collections.ObservableList;
-
-import static java.sql.Types.ARRAY;
-import static java.sql.Types.BIGINT;
-import static java.sql.Types.BINARY;
-import static java.sql.Types.BIT;
-import static java.sql.Types.BLOB;
-import static java.sql.Types.BOOLEAN;
-import static java.sql.Types.CHAR;
-import static java.sql.Types.CLOB;
-import static java.sql.Types.DATALINK;
-import static java.sql.Types.DATE;
-import static java.sql.Types.DECIMAL;
-import static java.sql.Types.DISTINCT;
-import static java.sql.Types.DOUBLE;
-import static java.sql.Types.FLOAT;
-import static java.sql.Types.INTEGER;
-import static java.sql.Types.JAVA_OBJECT;
-import static java.sql.Types.LONGNVARCHAR;
-import static java.sql.Types.LONGVARBINARY;
-import static java.sql.Types.LONGVARCHAR;
-import static java.sql.Types.NCHAR;
-import static java.sql.Types.NCLOB;
-import static java.sql.Types.NULL;
-import static java.sql.Types.NUMERIC;
-import static java.sql.Types.NVARCHAR;
-import static java.sql.Types.OTHER;
-import static java.sql.Types.REAL;
-import static java.sql.Types.REF;
-import static java.sql.Types.ROWID;
-import static java.sql.Types.SMALLINT;
-import static java.sql.Types.SQLXML;
-import static java.sql.Types.STRUCT;
-import static java.sql.Types.TIME;
-import static java.sql.Types.TIMESTAMP;
-import static java.sql.Types.TINYINT;
-import static java.sql.Types.VARBINARY;
-import static java.sql.Types.VARCHAR;
-
-/**
- * Field descriptor with properties for JavaFX GUI bindings.
- */
-public class PojoField {
- /** If this field should be used for code generation. */
- private final BooleanProperty useProp;
-
- /** If this field belongs to primary key. */
- private final BooleanProperty keyProp;
-
- /** If this field is an affinity key. */
- private final BooleanProperty akProp;
-
- /** If this field initially belongs to primary key. */
- private final boolean keyPrev;
-
- /** Field name in database. */
- private final StringProperty dbNameProp;
-
- /** Field type in database. */
- private final StringProperty dbTypeNameProp;
-
- /** Field name in POJO. */
- private final StringProperty javaNameProp;
-
- /** Initial field name in POJO. */
- private final String javaNamePrev;
-
- /** Field type in POJO. */
- private final StringProperty javaTypeNameProp;
-
- /** Initial field type in POJO. */
- private final String javaTypeNamePrev;
-
- /** Is {@code NULL} allowed for field in database. */
- private final boolean nullable;
-
- /** List of possible java type conversions. */
- private final ObservableList<String> conversions;
-
- /** Field owner. */
- private PojoDescriptor owner;
-
- /**
- * @param clss List of classes to get class names.
- * @return List of classes names to show in UI for manual select.
- */
- private static List<String> classNames(Class<?>... clss) {
- List<String> names = new ArrayList<>(clss.length);
-
- for (Class<?> cls : clss)
- names.add(cls.getName());
-
- return names;
- }
-
- /** Null number conversions. */
- private static final ObservableList<String> NULL_NUM_CONVERSIONS = FXCollections.observableArrayList();
-
- /** Not null number conversions. */
- private static final ObservableList<String> NOT_NULL_NUM_CONVERSIONS = FXCollections.observableArrayList();
-
- /** Primitive types. */
- private static final List<String> PRIMITIVES = classNames(boolean.class, byte.class, short.class,
- int.class, long.class, float.class, double.class);
-
- /** Object types. */
- private static final List<String> OBJECTS = classNames(Boolean.class, Byte.class, Short.class, Integer.class,
- Long.class, Float.class, Double.class, BigDecimal.class);
-
- static {
- NOT_NULL_NUM_CONVERSIONS.addAll(PRIMITIVES);
- NOT_NULL_NUM_CONVERSIONS.addAll(OBJECTS);
-
- NULL_NUM_CONVERSIONS.addAll(OBJECTS);
- }
-
- /**
- * @param dbType Database type.
- * @param nullable Nullable.
- * @param dflt Default.
- * @return List of possible type conversions.
- */
- private static ObservableList<String> conversions(int dbType, boolean nullable, String dflt) {
- switch (dbType) {
- case TINYINT:
- case SMALLINT:
- case INTEGER:
- case BIGINT:
- case REAL:
- case FLOAT:
- case DOUBLE:
- return nullable ? NULL_NUM_CONVERSIONS : NOT_NULL_NUM_CONVERSIONS;
-
- default:
- return FXCollections.singletonObservableList(dflt);
- }
- }
-
- /**
- * @param dbName Field name in database.
- * @param dbType Field JDBC type in database.
- * @param javaName Field name in POJO.
- * @param javaTypeName Field type in POJO.
- * @param key {@code true} if this field belongs to primary key.
- * @param nullable {@code true} if {@code NULL} allowed for field in database.
- */
- public PojoField(String dbName, int dbType, String javaName, String javaTypeName, boolean key, boolean nullable) {
- dbNameProp = new SimpleStringProperty(dbName);
-
- dbTypeNameProp = new SimpleStringProperty(jdbcTypeName(dbType));
-
- javaNamePrev = javaName;
-
- javaNameProp = new SimpleStringProperty(javaNamePrev);
-
- javaTypeNamePrev = javaTypeName;
-
- javaTypeNameProp = new SimpleStringProperty(javaTypeNamePrev);
-
- useProp = new SimpleBooleanProperty(true);
-
- keyPrev = key;
-
- keyProp = new SimpleBooleanProperty(keyPrev);
-
- this.nullable = nullable;
-
- akProp = new SimpleBooleanProperty(false);
-
- conversions = conversions(dbType, nullable, javaNamePrev);
-
- keyProp.addListener(new ChangeListener<Boolean>() {
- @Override public void changed(ObservableValue<? extends Boolean> val, Boolean oldVal, Boolean newVal) {
- if (newVal) {
- if (!use())
- useProp.set(true);
- }
- else
- akProp.set(false);
- }
- });
-
- akProp.addListener(new ChangeListener<Boolean>() {
- @Override public void changed(ObservableValue<? extends Boolean> val, Boolean oldVal, Boolean newVal) {
- if (newVal && owner != null) {
- keyProperty().set(true);
-
- for (PojoField field : owner.fields())
- if (field != PojoField.this && field.affinityKey())
- field.akProp.set(false);
- }
- }
- });
- }
-
- /**
- * @param jdbcType String name for JDBC type.
- * @return String name for JDBC type.
- */
- private static String jdbcTypeName(int jdbcType) {
- switch (jdbcType) {
- case BIT:
- return "BIT";
- case TINYINT:
- return "TINYINT";
- case SMALLINT:
- return "SMALLINT";
- case INTEGER:
- return "INTEGER";
- case BIGINT:
- return "BIGINT";
- case FLOAT:
- return "FLOAT";
- case REAL:
- return "REAL";
- case DOUBLE:
- return "DOUBLE";
- case NUMERIC:
- return "NUMERIC";
- case DECIMAL:
- return "DECIMAL";
- case CHAR:
- return "CHAR";
- case VARCHAR:
- return "VARCHAR";
- case LONGVARCHAR:
- return "LONGVARCHAR";
- case DATE:
- return "DATE";
- case TIME:
- return "TIME";
- case TIMESTAMP:
- return "TIMESTAMP";
- case BINARY:
- return "BINARY";
- case VARBINARY:
- return "VARBINARY";
- case LONGVARBINARY:
- return "LONGVARBINARY";
- case NULL:
- return "NULL";
- case OTHER:
- return "OTHER";
- case JAVA_OBJECT:
- return "JAVA_OBJECT";
- case DISTINCT:
- return "DISTINCT";
- case STRUCT:
- return "STRUCT";
- case ARRAY:
- return "ARRAY";
- case BLOB:
- return "BLOB";
- case CLOB:
- return "CLOB";
- case REF:
- return "REF";
- case DATALINK:
- return "DATALINK";
- case BOOLEAN:
- return "BOOLEAN";
- case ROWID:
- return "ROWID";
- case NCHAR:
- return "NCHAR";
- case NVARCHAR:
- return "NVARCHAR";
- case LONGNVARCHAR:
- return "LONGNVARCHAR";
- case NCLOB:
- return "NCLOB";
- case SQLXML:
- return "SQLXML";
- default:
- return "Unknown";
- }
- }
-
- /**
- * Revert changes to java names made by user.
- */
- public void resetJavaName() {
- javaNameProp.set(javaNamePrev);
- }
-
- /**
- * @param owner New field owner.
- */
- public void owner(PojoDescriptor owner) {
- this.owner = owner;
- }
-
- /**
- * @return {@code true} if filed should be used for code generation.
- */
- public boolean use() {
- return useProp.get();
- }
-
- /**
- * @return {@code true} if this field belongs to primary key.
- */
- public boolean key() {
- return keyProp.get();
- }
-
- /**
- * @param pk {@code true} if this field belongs to primary key.
- */
- public void key(boolean pk) {
- keyProp.set(pk);
- }
-
- /**
- * @return {@code true} if this field is an affinity key.
- */
- public boolean affinityKey() {
- return akProp.get();
- }
-
- /**
- * @return POJO field java name.
- */
- public String javaName() {
- return javaNameProp.get();
- }
-
- /**
- * @param name New POJO field java name.
- */
- public void javaName(String name) {
- javaNameProp.set(name);
- }
-
- /**
- * @return POJO field java type name.
- */
- public String javaTypeName() {
- return javaTypeNameProp.get();
- }
-
- /**
- * @return Field name in database.
- */
- public String dbName() {
- return dbNameProp.get();
- }
-
- /**
- * @return POJO field JDBC type name in database.
- */
- public String dbTypeName() {
- return dbTypeNameProp.get();
- }
-
- /**
- * @return Is NULL allowed for field in database.
- */
- public boolean nullable() {
- return nullable;
- }
-
- /**
- * @return List of possible java type conversions.
- */
- public ObservableList<String> conversions() {
- return conversions;
- }
-
- /**
- * @return {@code true} if type of field is primitive type.
- */
- public boolean primitive() {
- return PRIMITIVES.contains(javaTypeName());
- }
-
- /**
- * @return {@code true} if field was changed by user.
- */
- public boolean changed() {
- return keyPrev != key() || !javaNamePrev.equals(javaName()) || !javaTypeNamePrev.equals(javaTypeName());
- }
-
- /**
- * @return Boolean property support for {@code use} property.
- */
- public BooleanProperty useProperty() {
- return useProp;
- }
-
- /**
- * @return Boolean property support for {@code key} property.
- */
- public BooleanProperty keyProperty() {
- return keyProp;
- }
-
- /**
- * @return Boolean property support for {@code affinityKey} property.
- */
- public BooleanProperty affinityKeyProperty() {
- return akProp;
- }
-
- /**
- * @return String property support for {@code javaName} property.
- */
- public StringProperty javaNameProperty() {
- return javaNameProp;
- }
-
- /**
- * @return String property support for {@code javaTypeName} property.
- */
- public StringProperty javaTypeNameProperty() {
- return javaTypeNameProp;
- }
-
- /**
- * @return String property support for {@code dbName} property.
- */
- public StringProperty dbNameProperty() {
- return dbNameProp;
- }
-
- /**
- * @return String property support for {@code dbName} property.
- */
- public StringProperty dbTypeNameProperty() {
- return dbTypeNameProp;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/137aefbe/modules/schema-import/src/main/java/org/apache/ignite/schema/model/SchemaDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/model/SchemaDescriptor.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/model/SchemaDescriptor.java
deleted file mode 100644
index 7de2247..0000000
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/model/SchemaDescriptor.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.schema.model;
-
-import javafx.beans.property.BooleanProperty;
-import javafx.beans.property.SimpleBooleanProperty;
-
-/**
- * Descriptor for schema.
- */
-public class SchemaDescriptor {
- /** Schema name */
- private final String schema;
-
- /** State of schema selection. */
- private final BooleanProperty selected;
-
- /**
- * Constructor of schema descriptor.
- *
- * @param schema Schema.
- * @param selected Selection state.
- */
- public SchemaDescriptor(String schema, boolean selected) {
- this.schema = schema;
- this.selected = new SimpleBooleanProperty(selected);
- }
-
- /**
- * @return Schema name.
- */
- public String schema() {
- return schema;
- }
-
- /**
- * @return Boolean property support for {@code selected} property.
- */
- public BooleanProperty selected() {
- return selected;
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return schema;
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/137aefbe/modules/schema-import/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java
deleted file mode 100644
index 6d87ed5..0000000
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.schema.parser;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import javafx.collections.FXCollections;
-import javafx.collections.ObservableList;
-import org.apache.ignite.cache.QueryIndex;
-import org.apache.ignite.schema.model.PojoDescriptor;
-import org.apache.ignite.schema.model.SchemaDescriptor;
-
-/**
- * Database metadata parser.
- */
-public class DatabaseMetadataParser {
- /**
- * Get list of schemas from database.
- *
- * @param conn Connection to database.
- * @return List of schema descriptors.
- * @throws SQLException If schemas loading failed.
- */
- public static ObservableList<SchemaDescriptor> schemas(Connection conn) throws SQLException {
- Collection<String> dbSchemas = DbMetadataReader.getInstance().schemas(conn);
-
- List<SchemaDescriptor> uiSchemas = new ArrayList<>(dbSchemas.size());
-
- for (String schema : dbSchemas)
- uiSchemas.add(new SchemaDescriptor(schema, false));
-
- return FXCollections.observableList(uiSchemas);
- }
-
- /**
- * Parse database metadata.
- *
- * @param conn Connection to database.
- * @param schemas Collection of schema names to process.
- * @param tblsOnly If {@code true} then process tables only else process tables and views.
- * @return Collection of POJO descriptors.
- * @throws SQLException If parsing failed.
- */
- public static ObservableList<PojoDescriptor> parse(Connection conn, List<String> schemas, boolean tblsOnly)
- throws SQLException {
- Map<String, PojoDescriptor> parents = new HashMap<>();
-
- Map<String, Collection<PojoDescriptor>> childrens = new HashMap<>();
-
- for (DbTable tbl : DbMetadataReader.getInstance().metadata(conn, schemas, tblsOnly)) {
- String schema = tbl.schema();
-
- PojoDescriptor parent = parents.get(schema);
- Collection<PojoDescriptor> children = childrens.get(schema);
-
- if (parent == null) {
- parent = new PojoDescriptor(null, new DbTable(schema, "", Collections.<DbColumn>emptyList(),
- Collections.<QueryIndex>emptyList()));
-
- children = new ArrayList<>();
-
- parents.put(schema, parent);
- childrens.put(schema, children);
- }
-
- children.add(new PojoDescriptor(parent, tbl));
- }
-
- List<PojoDescriptor> res = new ArrayList<>();
-
- for (Map.Entry<String, PojoDescriptor> item : parents.entrySet()) {
- String schema = item.getKey();
- PojoDescriptor parent = item.getValue();
-
- Collection<PojoDescriptor> children = childrens.get(schema);
-
- if (!children.isEmpty()) {
- parent.children(children);
-
- res.add(parent); // Add schema description.
- res.addAll(children); // Add tables in schema.
- }
- }
-
- Collections.sort(res, new Comparator<PojoDescriptor>() {
- @Override public int compare(PojoDescriptor o1, PojoDescriptor o2) {
- return o1.fullDbName().compareTo(o2.fullDbName());
- }
- });
-
- return FXCollections.observableList(res);
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/137aefbe/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/ConfirmCallable.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/ConfirmCallable.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/ConfirmCallable.java
deleted file mode 100644
index b23ff11..0000000
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/ConfirmCallable.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.schema.ui;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.FutureTask;
-import javafx.application.Platform;
-import javafx.stage.Stage;
-
-import static org.apache.ignite.schema.ui.MessageBox.Result.NO;
-import static org.apache.ignite.schema.ui.MessageBox.Result.NO_TO_ALL;
-import static org.apache.ignite.schema.ui.MessageBox.Result.YES_TO_ALL;
-
-/**
- * Callable to ask user for confirmation from non EDT thread.
- */
-public class ConfirmCallable implements Callable<MessageBox.Result> {
- /** Owner window. */
- private final Stage owner;
-
- /** Message template. */
- private final String template;
-
- /** Message to show in confirmation dialog. */
- private String msg;
-
- /** User choice. */
- private MessageBox.Result choice = NO;
-
- /**
- * @param owner Owner window.
- * @param template Message template.
- */
- public ConfirmCallable(Stage owner, String template) {
- this.owner = owner;
- this.template = template;
- }
-
- /** {@inheritDoc} */
- @Override public MessageBox.Result call() throws Exception {
- choice = MessageBox.applyToAllChoiceDialog(owner, String.format(template, msg));
-
- return choice;
- }
-
- /**
- * Execute confirmation in EDT thread.
- *
- * @return Confirm result.
- */
- public MessageBox.Result confirm(String msg) {
- this.msg = msg;
-
- if (choice == YES_TO_ALL || choice == NO_TO_ALL)
- return choice;
-
- FutureTask<MessageBox.Result> fut = new FutureTask<>(this);
-
- Platform.runLater(fut);
-
- try {
- return fut.get();
- }
- catch (Exception ignored) {
- return NO;
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/137aefbe/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/Controls.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/Controls.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/Controls.java
deleted file mode 100644
index 934a4c8..0000000
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/Controls.java
+++ /dev/null
@@ -1,697 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.schema.ui;
-
-import com.sun.javafx.scene.control.skin.VirtualFlow;
-import javafx.application.Platform;
-import javafx.beans.value.ChangeListener;
-import javafx.beans.value.ObservableValue;
-import javafx.collections.FXCollections;
-import javafx.event.ActionEvent;
-import javafx.event.EventHandler;
-import javafx.geometry.Insets;
-import javafx.geometry.Orientation;
-import javafx.geometry.Pos;
-import javafx.scene.Node;
-import javafx.scene.Parent;
-import javafx.scene.Scene;
-import javafx.scene.control.Button;
-import javafx.scene.control.CheckBox;
-import javafx.scene.control.ComboBox;
-import javafx.scene.control.Control;
-import javafx.scene.control.Label;
-import javafx.scene.control.ListView;
-import javafx.scene.control.PasswordField;
-import javafx.scene.control.ProgressIndicator;
-import javafx.scene.control.SelectionMode;
-import javafx.scene.control.SplitPane;
-import javafx.scene.control.TableCell;
-import javafx.scene.control.TableColumn;
-import javafx.scene.control.TableView;
-import javafx.scene.control.TextField;
-import javafx.scene.control.TitledPane;
-import javafx.scene.control.Tooltip;
-import javafx.scene.control.cell.CheckBoxListCell;
-import javafx.scene.control.cell.CheckBoxTableCell;
-import javafx.scene.control.cell.PropertyValueFactory;
-import javafx.scene.control.cell.TextFieldTableCell;
-import javafx.scene.image.Image;
-import javafx.scene.image.ImageView;
-import javafx.scene.input.KeyCode;
-import javafx.scene.input.KeyEvent;
-import javafx.scene.layout.BorderPane;
-import javafx.scene.layout.HBox;
-import javafx.scene.layout.Pane;
-import javafx.scene.layout.StackPane;
-import javafx.scene.layout.VBox;
-import javafx.scene.text.Font;
-import javafx.scene.text.Text;
-import javafx.util.Callback;
-import javafx.util.converter.DefaultStringConverter;
-
-/**
- * Utility class to create controls.
- */
-public class Controls {
- /** */
- public static final Insets DFLT_PADDING = new Insets(10, 10, 10, 10);
-
- /**
- * Create scene with predefined style.
- *
- * @param root The root node of the scene graph.
- * @return New {@code Scene} instance.
- */
- public static Scene scene(Parent root) {
- Scene scene = new Scene(root);
-
- scene.getStylesheets().add("media/style.css");
-
- return scene;
- }
-
- /**
- * Create grid pane with default padding.
- *
- * @param top Top padding
- * @param right Right padding.
- * @param bottom Bottom padding.
- * @param left Left padding.
- * @return New {@code GridPaneEx} instance.
- */
- public static GridPaneEx paneEx(double top, double right, double bottom, double left) {
- GridPaneEx paneEx = new GridPaneEx();
-
- paneEx.setPadding(new Insets(top, right, bottom, left));
-
- return paneEx;
- }
-
- /**
- * Create new {@code HBox} with default padding.
- *
- * @param spacing Amount of horizontal space between each child.
- * @param dfltPadding If {@code true} than set default padding for pane.
- * @return New {@code HBox} instance.
- */
- public static HBox hBox(int spacing, boolean dfltPadding) {
- HBox hb = new HBox(spacing);
-
- if (dfltPadding)
- hb.setPadding(DFLT_PADDING);
-
- return hb;
- }
-
- /**
- * Create new {@code HBox} with default padding and add controls.
- *
- * @param spacing Amount of horizontal space between each child.
- * @param dfltPadding If {@code true} than set default padding for pane.
- * @param controls Controls to add.
- * @return New {@code HBox} instance.
- */
- public static HBox hBox(int spacing, boolean dfltPadding, Node... controls) {
- HBox hb = hBox(spacing, dfltPadding);
-
- hb.getChildren().addAll(controls);
-
- 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 vBox(int spacing) {
- VBox vb = new VBox(spacing);
-
- vb.setPadding(DFLT_PADDING);
-
- return vb;
- }
-
- /**
- * Create new {@code VBox} with default padding and add controls.
- *
- * @param spacing Amount of horizontal space between each child.
- * @param controls Controls to add.
- * @return New {@code VBox} instance.
- */
- public static VBox vBox(int spacing, Node... controls) {
- VBox vb = vBox(spacing);
-
- vb.getChildren().addAll(controls);
-
- return vb;
- }
-
- /**
- * Create stack pane.
- *
- * @param controls Controls to add.
- * @return New {@code StackPane} instance.
- */
- public static StackPane stackPane(Node... controls) {
- StackPane sp = new StackPane();
-
- sp.getChildren().addAll(controls);
-
- return sp;
- }
-
- /**
- * Create border pane.
- *
- * @param top Optional top control.
- * @param center Optional center control.
- * @param bottom Optional bottom control.
- * @param left Optional left control.
- * @param right Optional right control.
- * @return New {@code BorderPane} instance.
- */
- public static BorderPane borderPane(Node top, Node center, Node bottom, Node left, Node right) {
- BorderPane bp = new BorderPane();
-
- bp.setTop(top);
- bp.setCenter(center);
- bp.setBottom(bottom);
- bp.setLeft(left);
- bp.setRight(right);
-
- return bp;
- }
-
- /**
- * Sets control tooltip if needed.
- *
- * @param ctrl Target control.
- * @param tip Tooltip text.
- * @return Control itself for method chaining.
- */
- public static <T extends Control> T tooltip(T ctrl, String tip) {
- if (!tip.isEmpty())
- ctrl.setTooltip(new Tooltip(tip));
-
- return ctrl;
- }
-
- /**
- * Create label.
- *
- * @param text Label text.
- * @return New {@code Label} instance.
- */
- public static Label label(String text) {
- return new Label(text);
- }
-
- /**
- * Create button with text only.
- *
- * @param text Button text.
- * @param tip Tooltip text.
- * @param onAct Button action.
- * @return New {@code Button} instance.
- */
- public static Button button(String text, String tip, EventHandler<ActionEvent> onAct) {
- Button btn = new Button(text);
-
- btn.setOnAction(onAct);
-
- tooltip(btn, tip);
-
- return btn;
- }
-
- /**
- * Create button with icon only.
- *
- * @param icon Button icon.
- * @param tip Tooltip text.
- * @param onAct Button action.
- * @return New {@code Button} instance.
- */
- public static Button button(ImageView icon, String tip, EventHandler<ActionEvent> onAct) {
- Button btn = new Button();
-
- btn.setGraphic(icon);
- btn.setOnAction(onAct);
-
- tooltip(btn, tip);
-
- return btn;
- }
-
- /**
- * Create pane with buttons.
- *
- * @param alignment Alignment of buttons.
- * @param dfltPadding If {@code true} than set default padding for pane.
- * @param btns Buttons that will be added to pane.
- * @return New {@code HBox} instance with buttons.
- */
- public static Pane buttonsPane(Pos alignment, boolean dfltPadding, Button... btns) {
- HBox hb = hBox(10, dfltPadding, btns);
-
- hb.setAlignment(alignment);
-
- return hb;
- }
-
- /**
- * Create checkbox.
- *
- * @param text Checkbox text.
- * @param tip Tooltip tex.
- * @param sel Checkbox selected state.
- * @return New {@code Checkbox} instance.
- */
- public static CheckBox checkBox(String text, String tip, boolean sel) {
- CheckBox ch = new CheckBox(text);
-
- ch.setSelected(sel);
-
- tooltip(ch, tip);
-
- return ch;
- }
-
- /**
- * Create text field.
- *
- * @param tip Tooltip text.
- * @return New {@code TextField} instance.
- */
- public static TextField textField(String tip) {
- TextField tf = new TextField();
-
- tooltip(tf, tip);
-
- return tf;
- }
-
- /**
- * Create static text.
- *
- * @param text Text to show.
- * @param wrap Text wrapping width.
- * @return New {@code Text} instance.
- */
- public static Text text(String text, int wrap) {
- Text t = new Text(text);
-
- t.setFont(new Font(14));
-
- if (wrap > 0)
- t.setWrappingWidth(wrap);
-
- return t;
- }
-
- /**
- * Create password field.
- *
- * @param tip Tooltip text.
- * @return New {@code PasswordField} instance.
- */
- public static PasswordField passwordField(String tip) {
- PasswordField pf = new PasswordField();
-
- tooltip(pf, tip);
-
- return pf;
- }
-
- /**
- * Create combo box.
- *
- * @param tip Tooltip text.
- * @param items Combo box items.
- * @return New {@code ComboBox} instance.
- */
- public static <T> ComboBox<T> comboBox(String tip, T... items) {
- ComboBox<T> cb = new ComboBox<>(FXCollections.observableArrayList(items));
-
- cb.setMaxWidth(Double.MAX_VALUE);
- cb.getSelectionModel().select(0);
-
- tooltip(cb, tip);
-
- return cb;
- }
-
- /**
- * Create split pane for provided nodes.
- *
- * @param node1 First node.
- * @param node2 Second node.
- * @param pos Initial divider position.
- * @return New {@code SplitPane} instance.
- */
- public static SplitPane splitPane(Node node1, Node node2, double pos) {
- SplitPane sp = new SplitPane();
-
- sp.setOrientation(Orientation.VERTICAL);
- sp.getItems().addAll(node1, node2);
- sp.setDividerPosition(0, pos);
-
- return sp;
- }
-
- /**
- * Create titled pane.
- *
- * @param title Title.
- * @param node Node.
- * @param collapsible Collapsible flag.
- * @return New {@code TitledPane} instance.
- */
- public static TitledPane titledPane(String title, Node node, boolean collapsible) {
- TitledPane tp = new TitledPane(title, node);
-
- tp.setCollapsible(collapsible);
- tp.setExpanded(false);
-
- return tp;
- }
-
- /**
- * Create list view.
- *
- * @param tip Tooltip text.
- * @param cb Callback function for list view cell data binding.
- * @param <T> Type of showed by viewer element.
- * @return New {@code ListView} instance.
- */
- public static <T> ListView<T> list(String tip, Callback<T, ObservableValue<Boolean>> cb) {
- ListView lst = new ListView<>();
-
- lst.setCellFactory(CheckBoxListCell.forListView(cb));
-
- lst.setMinHeight(70);
- lst.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
-
- tooltip(lst, tip);
-
- return lst;
- }
-
- /**
- * Create table column.
- *
- * @param colName Column name to display.
- * @param propName Property name column is bound to.
- * @param tip Column tooltip text.
- * @param minWidth The minimum width column is permitted to be resized to.
- * @param maxWidth The maximum width column is permitted to be resized to.
- * @param editable {@code true} if column is editable.
- * @return New {@code TableColumn} instance.
- */
- private static <S, T> TableColumn<S, T> tableColumn(String colName, String propName, String tip,
- int minWidth, int maxWidth, boolean editable) {
- TableColumn<S, T> col = new TableColumn<>();
-
- col.setGraphic(tooltip(new Label(colName), tip));
-
- col.setSortable(false);
-
- if (minWidth > 0)
- col.setMinWidth(minWidth);
-
- if (maxWidth > 0)
- col.setMaxWidth(maxWidth);
-
- col.setCellValueFactory(new PropertyValueFactory<S, T>(propName));
-
- col.setEditable(editable);
-
- return col;
- }
-
- /**
- * Create table column.
- *
- * @param colName Column name to display.
- * @param propName Property name column is bound to.
- * @param tip Column tooltip text.
- * @return New {@code TableColumn} instance.
- */
- public static <S, T> TableColumn<S, T> tableColumn(String colName, String propName, String tip) {
- return tableColumn(colName, propName, tip, 100, 0, false);
- }
-
- /**
- * Create table column.
- *
- * @param colName Column name to display.
- * @param propName Property name column is bound to.
- * @param tip Column tooltip text.
- * @param cellFactory Custom cell factory.
- * @return New {@code TableColumn} instance.
- */
- public static <S, T> TableColumn<S, T> customColumn(String colName, String propName, String tip,
- Callback<TableColumn<S, T>, TableCell<S, T>> cellFactory) {
- TableColumn<S, T> col = tableColumn(colName, propName, tip, 100, 0, true);
-
- col.setCellFactory(cellFactory);
-
- return col;
- }
-
- /**
- * Create editable boolean table column.
- *
- * @param colName Column name to display.
- * @param propName Property name column is bound to.
- * @param tip Column tooltip text.
- * @return New {@code TableColumn} instance.
- */
- public static <S> TableColumn<S, Boolean> booleanColumn(String colName, String propName, String tip) {
- TableColumn<S, Boolean> col = tableColumn(colName, propName, tip, 50, 50, true);
-
- col.setCellFactory(CheckBoxTableCellEx.<S>cellFactory());
-
- return col;
-
- }
-
- /**
- * Create editable text table column.
- *
- * @param colName Column name to display.
- * @param propName Property name column is bound to.
- * @param tip Column tooltip text.
- * @return New {@code TableColumn} instance.
- */
- public static <S> TableColumn<S, String> textColumn(String colName, String propName, String tip,
- TextColumnValidator<S> validator) {
- TableColumn<S, String> col = tableColumn(colName, propName, tip, 100, 0, true);
-
- col.setCellFactory(TextFieldTableCellEx.cellFactory(validator));
-
- return col;
- }
-
- /**
- * Create table view.
- *
- * @param placeholder Text to show if table model is empty.
- * @param cols Columns to add.
- * @return New {@code TableView} instance.
- */
- public static <S> TableView<S> tableView(String placeholder, TableColumn<S, ?>... cols) {
- TableView<S> tbl = new TableView<>();
-
- tbl.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
- tbl.setEditable(true);
- tbl.setMinHeight(70);
- tbl.setPlaceholder(text(placeholder, 0));
-
- tbl.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
-
- tbl.getColumns().addAll(cols);
-
- return tbl;
- }
-
- /**
- * Create progress indicator.
- *
- * @param sz Indicator diameter.
- * @return New {@code ProgressIndicator} instance.
- */
- public static ProgressIndicator progressIndicator(int sz) {
- ProgressIndicator pi = new ProgressIndicator();
-
- pi.setMaxWidth(sz);
- pi.setMaxHeight(sz);
-
- return pi;
- }
-
- /**
- * Create image view.
- *
- * @param imgFileName Image filename.
- * @return New {@code ImageView} instance.
- */
- public static ImageView imageView(String imgFileName, int sz) {
- return new ImageView(image(imgFileName, sz));
- }
-
- /**
- * Gets image by its filename.
- *
- * @param imgFileName Image filename.
- * @return Loaded image.
- */
- public static Image image(String imgFileName, int sz) {
- return new Image(Controls.class.getClassLoader()
- .getResourceAsStream(String.format("media/%1$s_%2$dx%2$d.png", imgFileName, sz)));
- }
-
- /**
- * Customized checkbox.
- */
- private static class CheckBoxTableCellEx<S> extends CheckBoxTableCell<S, Boolean> {
- /** Creates a ComboBox cell factory for use in TableColumn controls. */
- public static <S> Callback<TableColumn<S, Boolean>, TableCell<S, Boolean>> cellFactory() {
- return new Callback<TableColumn<S, Boolean>, TableCell<S, Boolean>>() {
- @Override public TableCell<S, Boolean> call(TableColumn<S, Boolean> col) {
- return new CheckBoxTableCellEx<>();
- }
- };
- }
-
- /**
- * Default constructor.
- */
- private CheckBoxTableCellEx() {
- setAlignment(Pos.CENTER);
- }
- }
-
- /**
- * Special table text field cell that commit its content on focus lost.
- */
- private static class TextFieldTableCellEx<S> extends TextFieldTableCell<S, String> {
- /** */
- private final TextColumnValidator<S> validator;
- /** */
- private String curTxt = "";
-
- /** Row value. */
- private S rowVal;
-
- /** Create cell factory. */
- public static <S> Callback<TableColumn<S, String>, TableCell<S, String>>
- cellFactory(final TextColumnValidator<S> validator) {
- return new Callback<TableColumn<S, String>, TableCell<S, String>>() {
- @Override public TableCell<S, String> call(TableColumn<S, String> col) {
- return new TextFieldTableCellEx<>(validator);
- }
- };
- }
-
- /**
- * Text field cell constructor.
- *
- * @param validator Input text validator.
- */
- private TextFieldTableCellEx(TextColumnValidator<S> validator) {
- super(new DefaultStringConverter());
-
- this.validator = validator;
- }
-
- /** {@inheritDoc} */
- @Override public void startEdit() {
- String item = getItem();
-
- if (item == null || item.isEmpty())
- return;
-
- super.startEdit();
-
- rowVal = getTableView().getSelectionModel().getSelectedItem();
-
- Node g = getGraphic();
-
- if (g != null) {
- final TextField tf = (TextField)g;
-
- curTxt = tf.getText();
-
- tf.textProperty().addListener(new ChangeListener<String>() {
- @Override public void changed(ObservableValue<? extends String> val, String oldVal, String newVal) {
- curTxt = newVal;
- }
- });
-
- tf.setOnKeyPressed(new EventHandler<KeyEvent>() {
- @Override public void handle(KeyEvent evt) {
- if (KeyCode.ENTER == evt.getCode() || KeyCode.ESCAPE == evt.getCode())
- cancelEdit();
- }
- });
-
- tf.setOnKeyReleased(new EventHandler<KeyEvent>() {
- @Override public void handle(KeyEvent evt) {
- // No-op to overwrite JavaFX implementation.
- }
- });
-
- // Special hack for editable TextFieldTableCell.
- // Cancel edit when focus lost from text field, but do not cancel if focus lost to VirtualFlow.
- tf.focusedProperty().addListener(new ChangeListener<Boolean>() {
- @Override public void changed(ObservableValue<? extends Boolean> val, Boolean oldVal, Boolean newVal) {
- Node fo = getScene().getFocusOwner();
-
- if (!newVal) {
- if (fo instanceof VirtualFlow) {
- if (fo.getParent().getParent() != getTableView())
- cancelEdit();
- }
- else
- cancelEdit();
- }
- }
- });
-
- Platform.runLater(new Runnable() {
- @Override public void run() {
- tf.requestFocus();
- }
- });
- }
- }
-
- /** {@inheritDoc} */
- @Override public void cancelEdit() {
- boolean editing = isEditing();
-
- super.cancelEdit();
-
- if (editing && validator.valid(rowVal, curTxt))
- updateItem(curTxt, false);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/137aefbe/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/GridPaneEx.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/GridPaneEx.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/GridPaneEx.java
deleted file mode 100644
index 292a7a0..0000000
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/GridPaneEx.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.schema.ui;
-
-import javafx.geometry.Pos;
-import javafx.scene.Node;
-import javafx.scene.control.Label;
-import javafx.scene.layout.ColumnConstraints;
-import javafx.scene.layout.GridPane;
-import javafx.scene.layout.Priority;
-import javafx.scene.layout.RowConstraints;
-
-/**
- * Utility extension of {@code GridPane}.
- */
-public class GridPaneEx extends GridPane {
- /** Current column. */
- private int col;
-
- /** Current row. */
- private int row;
-
- /**
- * Create pane.
- */
- public GridPaneEx() {
- setAlignment(Pos.TOP_LEFT);
- setHgap(5);
- setVgap(10);
- }
-
- /**
- * Add default column.
- */
- public void addColumn() {
- getColumnConstraints().add(new ColumnConstraints());
- }
-
- /**
- * Add column with constraints and horizontal grow priority for the column.
- *
- * @param min Column minimum size.
- * @param pref Column preferred size.
- * @param max Column max size.
- * @param hgrow Column horizontal grow priority.
- */
- public void addColumn(double min, double pref, double max, Priority hgrow) {
- ColumnConstraints cc = new ColumnConstraints(min, pref, max);
-
- cc.setHgrow(hgrow);
-
- getColumnConstraints().add(cc);
- }
-
- /**
- * Add default row.
- */
- public void addRow() {
- getRowConstraints().add(new RowConstraints());
- }
-
- /**
- * Add default rows.
- *
- * @param n Number of rows to add.
- */
- public void addRows(int n) {
- for (int i = 0; i < n; i++)
- addRow();
- }
-
- /**
- * Add row with constraints and vertical grow priority for the row.
- *
- * @param min Row minimum size.
- * @param pref Row preferred size.
- * @param max Row max size.
- * @param vgrow Row vertical grow priority.
- */
- public void addRow(double min, double pref, double max, Priority vgrow) {
- RowConstraints rc = new RowConstraints(min, pref, max);
-
- rc.setVgrow(vgrow);
-
- getRowConstraints().add(rc);
- }
-
- /**
- * Wrap to next row.
- */
- public void wrap() {
- col = 0;
-
- row++;
- }
-
- /**
- * Skip columns.
- *
- * @param span How many columns should be skipped.
- */
- public void skip(int span) {
- add(new Label(""), span);
- }
-
- /**
- * Move to next column.
- */
- private void nextCol(int span) {
- col += span;
-
- if (col >= getColumnConstraints().size())
- wrap();
- }
-
- /**
- * Add control to grid pane.
- *
- * @param ctrl Control to add.
- * @param span How many columns control should take.
- * @return Added control.
- */
- public <T extends Node> T add(T ctrl, int span) {
- add(ctrl, col, row, span, 1);
-
- nextCol(span);
-
- return ctrl;
- }
-
- /**
- * Add control to grid pane.
- *
- * @param ctrl Control to add.
- * @return Added control.
- */
- public <T extends Node> T add(T ctrl) {
- return add(ctrl, 1);
- }
-
- /**
- * Add control with label.
- *
- * @param text Label text.
- * @param ctrl Control to add.
- * @param span How many columns control should take.
- * @return Added control.
- */
- public <T extends Node> T addLabeled(String text, T ctrl, int span) {
- add(new Label(text));
-
- return add(ctrl, span);
- }
-
- /**
- * Add control with label.
- *
- * @param text Label text.
- * @param ctrl Control to add.
- * @return Added control.
- */
- public <T extends Node> T addLabeled(String text, T ctrl) {
- return addLabeled(text, ctrl, 1);
- }
-}
\ No newline at end of file