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));
}
}
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;
}
});
}
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;
}
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;
}
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();
}
}
Aggregations