Search in sources :

Example 6 with TreeItem

use of javafx.scene.control.TreeItem in project Gargoyle by callakrsos.

the class H2TableItemTree method applyChildren.

//	private static final int GETPRIMARY_KEY_SEQ = 5;
//	private static final int GETPRIMARY_PRIMARYKEY_NAME = 6;
@Override
public ObservableList<TreeItem<DatabaseItemTree<String>>> applyChildren(Connection con, String... args) throws Exception {
    DatabaseMetaData metaData = con.getMetaData();
    ResultSet tables = metaData.getColumns(null, args[0], args[1], "%");
    Set<String> primaryKeySet = toSet(metaData.getPrimaryKeys(null, args[0], args[1]), COLUMN_NAME);
    ObservableList<TreeItem<DatabaseItemTree<String>>> observableArrayList = FXCollections.observableArrayList();
    while (tables.next()) {
        /* 
			 * references 
			 * http://docs.oracle.com/javase/6/docs/api/java/sql/ DatabaseMetaData.html#getTables%28java.lang.String,%20java.lang. String,%20java.lang.String,%20java.lang.String%5b%5d%29 
			 */
        String columnName = tables.getString(COLUMN_NAME);
        SqliteColumnItemTree coumnItem = new SqliteColumnItemTree(this, columnName);
        coumnItem.setPrimaryKey(primaryKeySet.contains(columnName));
        TreeItem<DatabaseItemTree<String>> treeItem = new TreeItem<>(coumnItem);
        observableArrayList.add(treeItem);
    }
    return observableArrayList;
}
Also used : TreeItem(javafx.scene.control.TreeItem) ResultSet(java.sql.ResultSet) SqliteColumnItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.sqlite.SqliteColumnItemTree) DatabaseItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.DatabaseItemTree) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 7 with TreeItem

use of javafx.scene.control.TreeItem in project Gargoyle by callakrsos.

the class SchemaItemTree method read.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.DatabaseItemTree
	 * #read()
	 */
@Override
public void read() throws Exception {
    String childrenSQL = getChildrenSQL(getName());
    // Connection connection = getConnection();
    // try {
    // if (childrenSQL != null && !childrenSQL.isEmpty()) {
    // List<Map<String, Object>> select = DbUtil.select(connection,
    // childrenSQL);
    // childrens = applyChildren(select);
    //
    // if (childrens == null)
    // childrens = FXCollections.observableArrayList();
    // }
    // } finally {
    // connection.close();
    // }
    Connection connection = getConnection();
    if (connection == null)
        throw new GargoyleConnectionFailException("connect fail...");
    try {
        if (childrenSQL != null && !childrenSQL.isEmpty()) {
            List<Map<String, Object>> select = DbUtil.select(connection, childrenSQL);
            childrens.addAll(applyChildren(select));
        }
        //			if (childrens == null)
        //				childrens = FXCollections.observableArrayList();
        // SQL로 불가능한 처리는 Connection을 받아 처리하도록한다.
        ObservableList<TreeItem<DatabaseItemTree<T>>> second = applyChildren(connection, getName());
        if (second != null)
            childrens.addAll(second);
    } finally {
        if (connection != null)
            connection.close();
    }
}
Also used : TreeItem(javafx.scene.control.TreeItem) Connection(java.sql.Connection) Map(java.util.Map) GargoyleConnectionFailException(com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException)

Example 8 with TreeItem

use of javafx.scene.control.TreeItem in project Gargoyle by callakrsos.

the class FxControlsTreeItem method createNode.

/**
	 * 파일 트리를 생성하기 위한 노드를 반환한다.
	 *
	 * @Date 2015. 10. 14.
	 * @param f
	 * @return
	 * @User KYJ
	 */
public TreeItem<Node> createNode(final Node f) {
    TreeItem<Node> treeItem = new TreeItem<Node>(f) {

        private boolean isLeaf;

        private boolean isFirstTimeChildren = true;

        private boolean isFirstTimeLeaf = true;

        @Override
        public ObservableList<TreeItem<Node>> getChildren() {
            if (isFirstTimeChildren) {
                isFirstTimeChildren = false;
                super.getChildren().setAll(buildChildren(this));
            }
            return super.getChildren();
        }

        @Override
        public boolean isLeaf() {
            if (isFirstTimeLeaf) {
                isFirstTimeLeaf = false;
                Node f = getValue();
                if (f == null) {
                    isLeaf = true;
                } else if (f instanceof Control) {
                    isLeaf = ((Control) f).getChildrenUnmodifiable().isEmpty();
                } else if (f instanceof Parent) {
                    isLeaf = ((Parent) f).getChildrenUnmodifiable().isEmpty();
                } else if (f instanceof Shape)
                    isLeaf = true;
                else
                    isLeaf = false;
            }
            return isLeaf;
        }

        private ObservableList<TreeItem<Node>> buildChildren(TreeItem<Node> treeItem) {
            Node f = treeItem.getValue();
            if (f == null) {
                return FXCollections.emptyObservableList();
            }
            treeItem.setGraphic(new HBox(/* new CheckBox(), */
            getImage(getName(f))));
            List<Node> childrens = getChildrens(f);
            if (childrens == null || childrens.isEmpty()) {
                return FXCollections.emptyObservableList();
            } else {
                ObservableList<TreeItem<Node>> children = FXCollections.observableArrayList();
                for (Node child : childrens) {
                    children.add(createNode(child));
                }
                return children;
            }
        }
    };
    treeItem.setGraphic(new HBox(/* new CheckBox(), */
    getImage(getName(f))));
    return treeItem;
}
Also used : Control(javafx.scene.control.Control) HBox(javafx.scene.layout.HBox) Shape(javafx.scene.shape.Shape) TreeItem(javafx.scene.control.TreeItem) Parent(javafx.scene.Parent) Node(javafx.scene.Node)

Example 9 with TreeItem

use of javafx.scene.control.TreeItem in project Challenger4SysAdmins by fvarrui.

the class TreeItemFactory method createChallengeTreeItem.

/**
 * @param challenge un chellenge
 * @return un item
 */
public static TreeItem<Object> createChallengeTreeItem(Challenge challenge) {
    TreeItem<Object> challengeItem = new TreeItem<Object>();
    challengeItem.setExpanded(true);
    challengeItem.setValue(challenge);
    for (Goal goal : challenge.getGoals()) {
        challengeItem.getChildren().add(createGoalTreeItem(goal));
    }
    challenge.goalsProperty().addListener(new ListChangeListener<Goal>() {

        public void onChanged(Change<? extends Goal> c) {
            while (c.next()) {
                c.getAddedSubList().stream().forEach(g -> challengeItem.getChildren().add(createGoalTreeItem(g)));
                c.getRemoved().stream().forEach(g -> {
                    TreeItem<Object> item = challengeItem.getChildren().stream().filter(i -> i.getValue().equals(g)).findFirst().get();
                    challengeItem.getChildren().remove(item);
                });
            }
        }
    });
    return challengeItem;
}
Also used : TestGroup(fvarrui.sysadmin.challenger.test.TestGroup) Challenge(fvarrui.sysadmin.challenger.Challenge) Test(fvarrui.sysadmin.challenger.test.Test) Goal(fvarrui.sysadmin.challenger.Goal) ListChangeListener(javafx.collections.ListChangeListener) TreeItem(javafx.scene.control.TreeItem) CommandTest(fvarrui.sysadmin.challenger.test.CommandTest) Command(fvarrui.sysadmin.challenger.command.Command) Goal(fvarrui.sysadmin.challenger.Goal) TreeItem(javafx.scene.control.TreeItem)

Example 10 with TreeItem

use of javafx.scene.control.TreeItem in project Challenger4SysAdmins by fvarrui.

the class TreeItemFactory method createTestTreeItem.

/**
 * @param test un test
 * @return un item de tipo test
 */
public static TreeItem<Object> createTestTreeItem(Test test) {
    TreeItem<Object> testItem = new TreeItem<Object>();
    testItem.setExpanded(true);
    testItem.setValue(test);
    if (test instanceof TestGroup) {
        TestGroup ct = (TestGroup) test;
        for (Test t : ct.getTests()) {
            testItem.getChildren().add(createTestTreeItem(t));
        }
        ct.testsProperty().addListener(new ListChangeListener<Test>() {

            public void onChanged(Change<? extends Test> c) {
                while (c.next()) {
                    c.getAddedSubList().stream().forEach(g -> testItem.getChildren().add(createTestTreeItem(g)));
                    c.getRemoved().stream().forEach(g -> {
                        TreeItem<Object> item = testItem.getChildren().stream().filter(i -> i.getValue().equals(g)).findFirst().get();
                        testItem.getChildren().remove(item);
                    });
                }
            }
        });
    } else if (test instanceof CommandTest) {
        CommandTest ct = (CommandTest) test;
        if (ct.getCommand() != null) {
            testItem.getChildren().add(createCommandTreeItem(ct.getCommand()));
        }
        ct.commandProperty().addListener((o, ov, nv) -> {
            if (nv != null) {
                testItem.getChildren().add(createCommandTreeItem(ct.getCommand()));
            } else {
                testItem.getChildren().clear();
            }
        });
    }
    return testItem;
}
Also used : TestGroup(fvarrui.sysadmin.challenger.test.TestGroup) Challenge(fvarrui.sysadmin.challenger.Challenge) Test(fvarrui.sysadmin.challenger.test.Test) Goal(fvarrui.sysadmin.challenger.Goal) ListChangeListener(javafx.collections.ListChangeListener) TreeItem(javafx.scene.control.TreeItem) CommandTest(fvarrui.sysadmin.challenger.test.CommandTest) Command(fvarrui.sysadmin.challenger.command.Command) TreeItem(javafx.scene.control.TreeItem) Test(fvarrui.sysadmin.challenger.test.Test) CommandTest(fvarrui.sysadmin.challenger.test.CommandTest) TestGroup(fvarrui.sysadmin.challenger.test.TestGroup) CommandTest(fvarrui.sysadmin.challenger.test.CommandTest)

Aggregations

TreeItem (javafx.scene.control.TreeItem)76 File (java.io.File)15 TreeView (javafx.scene.control.TreeView)11 ArrayList (java.util.ArrayList)10 List (java.util.List)10 ObjectProperty (javafx.beans.property.ObjectProperty)9 MenuItem (javafx.scene.control.MenuItem)9 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 ValueUtil (com.kyj.fx.voeditor.visual.util.ValueUtil)7 IOException (java.io.IOException)7 FXCollections (javafx.collections.FXCollections)7 ListChangeListener (javafx.collections.ListChangeListener)7 ObservableList (javafx.collections.ObservableList)7 ActionEvent (javafx.event.ActionEvent)7 ContextMenu (javafx.scene.control.ContextMenu)7 FxUtil (com.kyj.fx.voeditor.visual.util.FxUtil)6 FXML (javafx.fxml.FXML)6 Button (javafx.scene.control.Button)6