Search in sources :

Example 36 with TreeItem

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

the class SqlMultiplePane method applySelectScript.

/**
	 * 테이블의 SELECT문을 리턴.
	 *
	 * @param e
	 */
public void applySelectScript(ActionEvent e) {
    TreeItem<K> selectedItem = schemaTree.getSelectionModel().getSelectedItem();
    String tableName = this.getSelectedTreeByTableName(selectedItem);
    SqlTab selectedTab = getSelectedSqlTab();
    TreeItem<K> schemaTreeItem = selectedItem.getParent();
    String schema = schemaTreeItem.getValue().toString();
    Connection connection = connectionSupplier.get();
    try {
        String driver = DbUtil.getDriverNameByConnection(connection);
        String sql = ConfigResourceLoader.getInstance().get(ConfigResourceLoader.SQL_TABLE_COLUMNS_WRAPPER, driver);
        Map<String, Object> map = new HashMap<>(2);
        map.put("databaseName", schema);
        map.put("tableName", tableName);
        sql = ValueUtil.getVelocityToText(sql, map, true);
        List<String> select = DbUtil.select(connection, sql, 10, (RowMapper<String>) (rs, rowNum) -> rs.getString(1));
        redueceAction(select, ",", v -> selectedTab.appendTextSql(String.format("select %s \nfrom %s ", v.substring(0, v.length()), tableName)));
    } catch (Exception e1) {
        LOGGER.error(ValueUtil.toString(e1));
    }
}
Also used : Button(javafx.scene.control.Button) SystemLayoutViewController(com.kyj.fx.voeditor.visual.main.layout.SystemLayoutViewController) CheckComboBox(org.controlsfx.control.CheckComboBox) Connection(java.sql.Connection) DbUtil(com.kyj.fx.voeditor.visual.util.DbUtil) LoggerFactory(org.slf4j.LoggerFactory) NullExpresion(com.kyj.fx.voeditor.visual.util.NullExpresion) ToExcelFileFunction(com.kyj.fx.voeditor.visual.functions.ToExcelFileFunction) Application(javafx.application.Application) TabPane(javafx.scene.control.TabPane) ListChangeListener(javafx.collections.ListChangeListener) EncrypUtil(com.kyj.fx.voeditor.visual.util.EncrypUtil) ContextMenu(javafx.scene.control.ContextMenu) Map(java.util.Map) SQLPaneMotionable(com.kyj.fx.voeditor.visual.component.sql.functions.SQLPaneMotionable) GargoyleExtensionFilters(com.kyj.fx.voeditor.visual.util.GargoyleExtensionFilters) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) VariableMappingView(com.kyj.fx.voeditor.visual.component.popup.VariableMappingView) DockPos(com.kyj.fx.voeditor.visual.component.dock.pane.DockPos) DockPane(com.kyj.fx.voeditor.visual.component.dock.pane.DockPane) TableView(javafx.scene.control.TableView) SystemUtils(org.apache.commons.lang.SystemUtils) HBox(javafx.scene.layout.HBox) Pair(javafx.util.Pair) MenuItem(javafx.scene.control.MenuItem) KeyEvent(javafx.scene.input.KeyEvent) SimpleTextView(com.kyj.fx.voeditor.visual.component.text.SimpleTextView) ConfigResourceLoader(com.kyj.fx.voeditor.visual.momory.ConfigResourceLoader) Collectors(java.util.stream.Collectors) TreeView(javafx.scene.control.TreeView) ISchemaTreeItem(com.kyj.fx.voeditor.visual.component.sql.functions.ISchemaTreeItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) List(java.util.List) ResourceLoader(com.kyj.fx.voeditor.visual.momory.ResourceLoader) SqlTab(com.kyj.fx.voeditor.visual.component.sql.tab.SqlTab) RowMapper(org.springframework.jdbc.core.RowMapper) Optional(java.util.Optional) DateUtil(com.kyj.fx.voeditor.visual.util.DateUtil) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) TableViewSelectionModel(javafx.scene.control.TableView.TableViewSelectionModel) MouseButton(javafx.scene.input.MouseButton) TreeItem(javafx.scene.control.TreeItem) MouseEvent(javafx.scene.input.MouseEvent) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) DockNode(com.kyj.fx.voeditor.visual.component.dock.pane.DockNode) GagoyleTabProxy(com.kyj.fx.voeditor.visual.main.layout.GagoyleTabProxy) DialogUtil(com.kyj.fx.voeditor.visual.util.DialogUtil) Supplier(java.util.function.Supplier) IntegerProperty(javafx.beans.property.IntegerProperty) BigDataDVO(com.kyj.fx.voeditor.visual.framework.BigDataDVO) TableColumn(javafx.scene.control.TableColumn) Tooltip(javafx.scene.control.Tooltip) KeyCode(javafx.scene.input.KeyCode) Color(javafx.scene.paint.Color) Modality(javafx.stage.Modality) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) Iterator(java.util.Iterator) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) StringConverter(javafx.util.StringConverter) SchoolMgrerSpreadSheetView(com.kyj.fx.voeditor.visual.main.layout.SchoolMgrerSpreadSheetView) File(java.io.File) SqlTabPane(com.kyj.fx.voeditor.visual.component.sql.tab.SqlTabPane) Menu(javafx.scene.control.Menu) Consumer(java.util.function.Consumer) KeyCodeCombination(javafx.scene.input.KeyCodeCombination) ActionEvent(javafx.event.ActionEvent) SelectionMode(javafx.scene.control.SelectionMode) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Tab(javafx.scene.control.Tab) ExtensionFilter(javafx.stage.FileChooser.ExtensionFilter) Collections(java.util.Collections) SharedMemory(com.kyj.fx.voeditor.visual.momory.SharedMemory) HashMap(java.util.HashMap) Connection(java.sql.Connection) SqlTab(com.kyj.fx.voeditor.visual.component.sql.tab.SqlTab)

Example 37 with TreeItem

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

the class SqlPane method showTableInputDialog.

public Optional<Pair<String, String[]>> showTableInputDialog(Function<K, String> stringConverter) {
    final List<String> schemaList = getSchemaTree().getRoot().getChildren().stream().map(v -> {
        return stringConverter.apply(v.getValue());
    }).collect(Collectors.toList());
    String defaultSchema = "";
    try (Connection con = connectionSupplier.get()) {
        //
        //			String catalog = con.getCatalog();
        //			String schema = con.getSchema();
        //			ResultSet schemas = con.getMetaData().getCatalogs();
        //			if (schemas.next()) {
        //				String string = schemas.getString(1);
        //				System.out.println(string);
        //			}
        Map<String, Object> findOne = DbUtil.findOne(con, "select current_schema() as currentschema");
        if (findOne != null && !findOne.isEmpty()) {
            defaultSchema = ValueUtil.decode(findOne.get("currentschema"), "").toString();
        }
    } catch (Exception e4) {
        LOGGER.error(ValueUtil.toString(e4));
    }
    final String _defaultSchema = defaultSchema;
    if (tbResult.getItems().isEmpty())
        return Optional.empty();
    return DialogUtil.showInputCustomDialog(tbResult.getScene().getWindow(), "table Name", "테이블명을 입력하세요.", new CustomInputDialogAction<GridPane, String[]>() {

        TextField txtSchema;

        TextField txtTable;

        @Override
        public GridPane getNode() {
            GridPane gridPane = new GridPane();
            txtSchema = new TextField();
            txtTable = new TextField();
            FxUtil.installAutoTextFieldBinding(txtSchema, () -> {
                return schemaList;
            });
            FxUtil.installAutoTextFieldBinding(txtTable, () -> {
                return searchPattern(txtSchema.getText(), txtTable.getText()).stream().map(v -> stringConverter.apply(v.getValue())).collect(Collectors.toList());
            });
            txtSchema.setText(_defaultSchema);
            // Default TableName
            TreeItem<K> selectedItem = getSchemaTree().getSelectionModel().getSelectedItem();
            if (null != selectedItem) {
                K value = selectedItem.getValue();
                if (value instanceof TableItemTree) {
                    txtTable.setText(stringConverter.apply(value));
                }
            }
            Label label = new Label("Schema : ");
            Label label2 = new Label("Table : ");
            gridPane.add(label, 0, 0);
            gridPane.add(label2, 1, 0);
            gridPane.add(txtSchema, 0, 1);
            gridPane.add(txtTable, 1, 1);
            return gridPane;
        }

        @Override
        public String[] okClickValue() {
            String schema = txtSchema.getText().trim();
            String table = txtTable.getText().trim();
            String[] okValue = new String[2];
            okValue[0] = schema;
            okValue[1] = table;
            return okValue;
        }

        @Override
        public String[] cancelClickValue() {
            return null;
        }
    });
}
Also used : SystemLayoutViewController(com.kyj.fx.voeditor.visual.main.layout.SystemLayoutViewController) Arrays(java.util.Arrays) CheckComboBox(org.controlsfx.control.CheckComboBox) Application(javafx.application.Application) TabPane(javafx.scene.control.TabPane) ListChangeListener(javafx.collections.ListChangeListener) MacroControl(com.kyj.fx.voeditor.visual.component.macro.MacroControl) Map(java.util.Map) SQLPaneMotionable(com.kyj.fx.voeditor.visual.component.sql.functions.SQLPaneMotionable) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) VariableMappingView(com.kyj.fx.voeditor.visual.component.popup.VariableMappingView) DockPane(com.kyj.fx.voeditor.visual.component.dock.pane.DockPane) SystemUtils(org.apache.commons.lang.SystemUtils) Strings(com.sun.btrace.BTraceUtils.Strings) ColumnExpression(com.kyj.fx.voeditor.visual.component.grid.EditableTableView.ColumnExpression) SplitPane(javafx.scene.control.SplitPane) Pair(javafx.util.Pair) EditableTableViewComposite(com.kyj.fx.voeditor.visual.component.grid.EditableTableViewComposite) KeyEvent(javafx.scene.input.KeyEvent) ValueExpression(com.kyj.fx.voeditor.visual.component.grid.EditableTableView.ValueExpression) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) ResourceLoader(com.kyj.fx.voeditor.visual.momory.ResourceLoader) CustomInputDialogAction(com.kyj.fx.voeditor.visual.util.DialogUtil.CustomInputDialogAction) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) TitledBorderPane(com.kyj.fx.voeditor.visual.component.TitledBorderPane) TableViewSelectionModel(javafx.scene.control.TableView.TableViewSelectionModel) MouseButton(javafx.scene.input.MouseButton) ASTSqlCodeAreaHelper(com.kyj.fx.voeditor.visual.component.text.ASTSqlCodeAreaHelper) TreeItem(javafx.scene.control.TreeItem) FXCollections(javafx.collections.FXCollections) GagoyleTabProxy(com.kyj.fx.voeditor.visual.main.layout.GagoyleTabProxy) DialogUtil(com.kyj.fx.voeditor.visual.util.DialogUtil) Supplier(java.util.function.Supplier) IntegerProperty(javafx.beans.property.IntegerProperty) ArrayList(java.util.ArrayList) TableItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.TableItemTree) Color(javafx.scene.paint.Color) Node(javafx.scene.Node) TableOpenResourceView(com.kyj.fx.voeditor.visual.component.popup.TableOpenResourceView) StringConverter(javafx.util.StringConverter) SchoolMgrerSpreadSheetView(com.kyj.fx.voeditor.visual.main.layout.SchoolMgrerSpreadSheetView) GridPane(jfxtras.scene.layout.GridPane) File(java.io.File) SqlTabPane(com.kyj.fx.voeditor.visual.component.sql.tab.SqlTabPane) Menu(javafx.scene.control.Menu) KeyCodeCombination(javafx.scene.input.KeyCodeCombination) SelectionMode(javafx.scene.control.SelectionMode) TreeMap(java.util.TreeMap) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Tab(javafx.scene.control.Tab) ResultDialog(com.kyj.fx.voeditor.visual.component.ResultDialog) Button(javafx.scene.control.Button) Connection(java.sql.Connection) DbUtil(com.kyj.fx.voeditor.visual.util.DbUtil) LoggerFactory(org.slf4j.LoggerFactory) ToExcelFileFunction(com.kyj.fx.voeditor.visual.functions.ToExcelFileFunction) EncrypUtil(com.kyj.fx.voeditor.visual.util.EncrypUtil) ContextMenu(javafx.scene.control.ContextMenu) WindowEvent(javafx.stage.WindowEvent) TableView(javafx.scene.control.TableView) SqlKeywords(com.kyj.fx.voeditor.visual.component.text.SqlKeywords) Orientation(javafx.geometry.Orientation) HBox(javafx.scene.layout.HBox) TextField(javafx.scene.control.TextField) Main(com.kyj.fx.voeditor.visual.main.Main) MenuItem(javafx.scene.control.MenuItem) SimpleTextView(com.kyj.fx.voeditor.visual.component.text.SimpleTextView) ConfigResourceLoader(com.kyj.fx.voeditor.visual.momory.ConfigResourceLoader) Collectors(java.util.stream.Collectors) TreeView(javafx.scene.control.TreeView) ISchemaTreeItem(com.kyj.fx.voeditor.visual.component.sql.functions.ISchemaTreeItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) List(java.util.List) SqlTab(com.kyj.fx.voeditor.visual.component.sql.tab.SqlTab) Entry(java.util.Map.Entry) RowMapper(org.springframework.jdbc.core.RowMapper) Optional(java.util.Optional) DateUtil(com.kyj.fx.voeditor.visual.util.DateUtil) MouseEvent(javafx.scene.input.MouseEvent) HashMap(java.util.HashMap) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) Function(java.util.function.Function) BigDataDVO(com.kyj.fx.voeditor.visual.framework.BigDataDVO) TableColumn(javafx.scene.control.TableColumn) Insets(javafx.geometry.Insets) FxCollectors(com.kyj.fx.voeditor.visual.util.FxCollectors) Tooltip(javafx.scene.control.Tooltip) KeyCode(javafx.scene.input.KeyCode) ObjectProperty(javafx.beans.property.ObjectProperty) Modality(javafx.stage.Modality) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) Iterator(java.util.Iterator) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) Consumer(java.util.function.Consumer) ActionEvent(javafx.event.ActionEvent) Stage(javafx.stage.Stage) ExtensionFilter(javafx.stage.FileChooser.ExtensionFilter) Collections(java.util.Collections) SharedMemory(com.kyj.fx.voeditor.visual.momory.SharedMemory) TableItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.TableItemTree) GridPane(jfxtras.scene.layout.GridPane) TreeItem(javafx.scene.control.TreeItem) ISchemaTreeItem(com.kyj.fx.voeditor.visual.component.sql.functions.ISchemaTreeItem) Connection(java.sql.Connection) Label(javafx.scene.control.Label) TextField(javafx.scene.control.TextField)

Example 38 with TreeItem

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

the class SqliteTableItemTree method applyChildren.

/**
	 * 커넥션으로부터 스키마 정보 출력
	 */
@Override
public ObservableList<TreeItem<DatabaseItemTree<String>>> applyChildren(Connection con, String... args) throws Exception {
    DatabaseMetaData metaData = con.getMetaData();
    ResultSet tables = metaData.getColumns(null, null, args[1], "%");
    Set<String> primaryKeySet = toSet(metaData.getPrimaryKeys(null, null, 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) DatabaseItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.DatabaseItemTree) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 39 with TreeItem

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

the class DatabaseTreeNode method createNode.

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

        private boolean isLeaf;

        private boolean isFirstTimeChildren = true;

        private boolean isFirstTimeLeaf = true;

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

        @Override
        public boolean isLeaf() {
            if (isFirstTimeLeaf) {
                isFirstTimeLeaf = false;
                DatabaseItemTree<String> f = getValue();
                isLeaf = (f instanceof ColumnItemTree);
            }
            return isLeaf;
        }

        private ObservableList<TreeItem<DatabaseItemTree<String>>> buildChildren(TreeItem<DatabaseItemTree<String>> treeItem) {
            DatabaseItemTree<String> f = treeItem.getValue();
            // if (treeItem.getChildren().isEmpty()) {
            if (f == null) {
                return FXCollections.emptyObservableList();
            } else {
                try {
                    f.read();
                } catch (GargoyleConnectionFailException e) {
                    LOGGER.error(ValueUtil.toString(e));
                    DialogUtil.showExceptionDailog(e);
                } catch (Exception e) {
                    LOGGER.error(ValueUtil.toString(e));
                    return FXCollections.emptyObservableList();
                }
            }
            if (f == null) {
                return FXCollections.emptyObservableList();
            }
            if (f instanceof ColumnItemTree) {
                return FXCollections.emptyObservableList();
            }
            ObservableList<TreeItem<DatabaseItemTree<String>>> files = f.getChildrens();
            if (files != null) {
                ObservableList<TreeItem<DatabaseItemTree<String>>> children = FXCollections.observableArrayList();
                for (TreeItem<DatabaseItemTree<String>> childFile : files) {
                    DatabaseItemTree<String> value = childFile.getValue();
                    TreeItem<DatabaseItemTree<String>> createNode = createNode(value);
                    children.add(createNode);
                }
                return children;
            }
            return FXCollections.emptyObservableList();
        }
    };
    Node imageNode = getGraphics(f);
    treeItem.setGraphic(imageNode);
    return treeItem;
}
Also used : TreeItem(javafx.scene.control.TreeItem) Node(javafx.scene.Node) DatabaseItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.DatabaseItemTree) ColumnItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.ColumnItemTree) GargoyleConnectionFailException(com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException) GargoyleConnectionFailException(com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException)

Example 40 with TreeItem

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

the class DatabaseItemTree method read.

public void read() throws Exception {
    String childrenSQL = getChildrenSQL("");
    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);
        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)

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