use of javafx.scene.control.MenuItem in project Gargoyle by callakrsos.
the class SVNTreeView method addContextMenus.
/***********************************************************************************/
/***********************************************************************************/
/* 일반API 구현 */
/**
* 컨텍스트 메뉴 등록
*
* @작성자 : KYJ
* @작성일 : 2016. 4. 4.
*/
void addContextMenus() {
menuNew = new Menu("New");
menuAddNewLocation = new MenuItem("Repository Location");
menuDiscardLocation = new MenuItem("Discard Location");
menuReflesh = new MenuItem("Reflesh");
menuCheckout = new MenuItem("Checkout");
menuSvnGraph = new MenuItem("SVN Graph");
menuProperties = new MenuItem("Properties");
menuNew.getItems().add(menuAddNewLocation);
menuAddNewLocation.setOnAction(this::menuAddNewLocationOnAction);
menuDiscardLocation.setOnAction(this::menuDiscardLocationOnAction);
menuCheckout.setOnAction(this::menuCheckoutOnAction);
menuSvnGraph.setOnAction(this::menuSVNGraphOnAction);
menuProperties.setOnAction(this::menuPropertiesOnAction);
contextMenu = new ContextMenu(menuNew, new SeparatorMenuItem(), menuCheckout, new SeparatorMenuItem(), menuSvnGraph, new SeparatorMenuItem(), menuDiscardLocation, menuReflesh, new SeparatorMenuItem(), menuProperties);
// setContextMenu(contextMenu);
setCellFactory(treeItem -> {
TextFieldTreeCell<SVNItem> textFieldTreeCell = new TextFieldTreeCell<>();
textFieldTreeCell.setContextMenu(contextMenu);
return textFieldTreeCell;
});
// 특정 조건에 따른 메뉴 VISIBLE 처리를 정의함.
contextMenu.setOnShown(contextMenuVisibleEvent);
}
use of javafx.scene.control.MenuItem in project Gargoyle by callakrsos.
the class SVNViewer method initialize.
@FXML
public void initialize() {
tvSvnView = new SVNTreeView();
tvSvnView.setOnAction(this::svnTreeViewOnAction);
tvSvnView.setOnKeyPressed(this::svnTreeVoewOnKeyPressed);
tvSvnView.load();
anTreePane.getChildren().set(0, tvSvnView);
AnchorPane.setLeftAnchor(tvSvnView, 0.0);
AnchorPane.setRightAnchor(tvSvnView, 0.0);
AnchorPane.setBottomAnchor(tvSvnView, 0.0);
AnchorPane.setTopAnchor(tvSvnView, 0.0);
colRevision.setCellValueFactory(v -> new SimpleObjectProperty<Long>(v.getValue().getRevision()));
colUser.setCellValueFactory(v -> new SimpleStringProperty(v.getValue().getAuthor()));
colComment.setCellValueFactory(v -> new SimpleStringProperty(v.getValue().getMessage()));
colDate.setCellValueFactory(v -> new SimpleStringProperty(DateUtil.getDateString(v.getValue().getDate().getTime(), "yyyy-MM-dd")));
javaTextAre = new JavaTextArea();
borSource.setCenter(javaTextAre);
lineHist = new LineChart<>(new CategoryAxis(), new CategoryAxis());
borChart.setCenter(lineHist);
tbRevision.getSelectionModel().setCellSelectionEnabled(true);
tbRevision.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
// FxClipboardUtil.installCopyPasteHandler(tbRevision);
// FxTableViewUtil.
FxUtil.installClipboardKeyEvent(tbRevision);
MenuItem menuDiff = new MenuItem("Diff");
menuDiff.setOnAction(this::menuDiffOnAction);
tbRevision.setContextMenu(new ContextMenu(menuDiff));
tvSvnView.svnGraphPropertyProperty().addListener((oba, oldView, newView) -> {
if (newView != null) {
Tab tabSvnGraph = new Tab("SVN Graph", newView);
if (tabPaneSVN.getTabs().size() <= TAB_INDEX_SVN_GRAPH) {
tabPaneSVN.getTabs().add(tabSvnGraph);
} else {
tabPaneSVN.getTabs().add(TAB_INDEX_SVN_GRAPH, tabSvnGraph);
}
}
});
displayLatestRevision();
}
use of javafx.scene.control.MenuItem in project Gargoyle by callakrsos.
the class FxSVNHistoryDataSupplier method createHistoryListView.
public ListView<GargoyleSVNLogEntryPath> createHistoryListView(ObservableList<GargoyleSVNLogEntryPath> list) {
ListView<GargoyleSVNLogEntryPath> listView = new ListView<GargoyleSVNLogEntryPath>(list);
listView.setCellFactory(new Callback<ListView<GargoyleSVNLogEntryPath>, ListCell<GargoyleSVNLogEntryPath>>() {
@Override
public ListCell<GargoyleSVNLogEntryPath> call(ListView<GargoyleSVNLogEntryPath> param) {
ListCell<GargoyleSVNLogEntryPath> listCell = new ListCell<GargoyleSVNLogEntryPath>() {
/* (non-Javadoc)
* @see javafx.scene.control.Cell#updateItem(java.lang.Object, boolean)
*/
@Override
protected void updateItem(GargoyleSVNLogEntryPath item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
} else {
String type = "Modify";
switch(item.getType()) {
case GargoyleSVNLogEntryPath.TYPE_ADDED:
type = "Add";
break;
case GargoyleSVNLogEntryPath.TYPE_MODIFIED:
type = "Modify";
break;
case GargoyleSVNLogEntryPath.TYPE_REPLACED:
type = "Replace";
break;
case GargoyleSVNLogEntryPath.TYPE_DELETED:
type = "Delete";
break;
}
String path = item.getPath();
setText(String.format("Resivion :%d File : %s Date : %s Type : %s ", item.getCopyRevision(), path.substring(path.lastIndexOf("/")), YYYY_MM_DD_HH_MM_SS_PATTERN.format(item.getDate()), type));
}
}
};
return listCell;
}
});
listView.setPrefSize(600, ListView.USE_COMPUTED_SIZE);
listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
listView.addEventHandler(MouseEvent.MOUSE_CLICKED, ev -> {
ContextMenu contextMenu = null;
ObservableList<GargoyleSVNLogEntryPath> selectedItems = listView.getSelectionModel().getSelectedItems();
GargoyleSVNLogEntryPath selectedItem = null;
if (selectedItems != null && !selectedItems.isEmpty()) {
selectedItem = selectedItems.get(0);
}
if (ev.getClickCount() == 2 && ev.getButton() == MouseButton.PRIMARY) {
if (selectedItem != null) {
String path = selectedItem.getPath();
long copyRevision = selectedItem.getCopyRevision();
String rootUrl = getRootUrl();
LOGGER.debug("{}", rootUrl);
LOGGER.debug("Cat Command, Path : {} Revision {}", path, copyRevision);
String content = "";
VBox vBox = new VBox(5);
if (isExists(path)) {
content = cat(path, String.valueOf(copyRevision));
List<SVNLogEntry> log = log(path, String.valueOf(copyRevision), ex -> {
LOGGER.error(ValueUtil.toString(ex));
});
if (ValueUtil.isNotEmpty(log)) {
SVNLogEntry svnLogEntry = log.get(0);
String apply = getManager().fromPrettySVNLogConverter().apply(svnLogEntry);
Label e = new Label(apply);
e.setStyle("-fx-text-fill:black");
vBox.getChildren().add(e);
}
vBox.getChildren().add(createJavaTextArea(content));
} else {
content = "Does not exists. Repository. [Removed]";
Label e = new Label(content);
e.setStyle("-fx-text-fill:black");
vBox.getChildren().add(e);
}
FxUtil.showPopOver(ev.getPickResult().getIntersectedNode(), vBox);
}
ev.consume();
} else if (ev.getClickCount() == 1 && ev.getButton() == MouseButton.SECONDARY) {
ObservableList<MenuItem> menus = FXCollections.observableArrayList();
MenuItem miHist = new MenuItem("History");
miHist.setUserData(selectedItem);
MenuItem miAllHist = new MenuItem("All History");
MenuItem miDiff = new MenuItem("Diff");
miDiff.setDisable(true);
menus.add(miHist);
menus.add(miAllHist);
menus.add(new SeparatorMenuItem());
menus.add(miDiff);
if (selectedItems.size() == 2) {
miDiff.setUserData(selectedItems);
miDiff.setDisable(false);
}
miHist.setOnAction(event -> {
GargoyleSVNLogEntryPath userData = (GargoyleSVNLogEntryPath) miHist.getUserData();
if (userData == null)
return;
FxUtil.showPopOver(ev.getPickResult().getIntersectedNode(), createHistoryListView(userData.getPath()));
});
miAllHist.setOnAction(event -> {
GargoyleSVNLogEntryPath userData = (GargoyleSVNLogEntryPath) miHist.getUserData();
if (userData == null)
return;
String path = userData.getPath();
try {
Collection<SVNLogEntry> allLogs = getManager().getAllLogs(path);
ObservableList<GargoyleSVNLogEntryPath> collect = createStream(allLogs).filter(v -> {
return path.equals(v.getPath());
}).collect(FxCollectors.toObservableList());
FxUtil.showPopOver(ev.getPickResult().getIntersectedNode(), createHistoryListView(collect));
} catch (Exception e) {
LOGGER.error(ValueUtil.toString(e));
}
});
miDiff.setOnAction(event -> {
List<GargoyleSVNLogEntryPath> userData = (List<GargoyleSVNLogEntryPath>) miDiff.getUserData();
if (userData == null && userData.size() != 2)
return;
GargoyleSVNLogEntryPath gargoyleSVNLogEntryPath1 = userData.get(0);
GargoyleSVNLogEntryPath gargoyleSVNLogEntryPath2 = userData.get(1);
try {
String diff = diff(gargoyleSVNLogEntryPath1.getPath(), gargoyleSVNLogEntryPath1.getCopyRevision(), gargoyleSVNLogEntryPath2.getCopyRevision());
TextArea showingNode = new TextArea(diff);
showingNode.setPrefSize(600d, 800d);
FxUtil.showPopOver(ev.getPickResult().getIntersectedNode(), showingNode);
} catch (Exception e) {
e.printStackTrace();
}
});
contextMenu = new ContextMenu(menus.stream().toArray(MenuItem[]::new));
contextMenu.show(ev.getPickResult().getIntersectedNode(), ev.getScreenX(), ev.getScreenY());
}
});
return listView;
}
use of javafx.scene.control.MenuItem in project Gargoyle by callakrsos.
the class ScmCommitComposite method init.
/* (non-Javadoc)
* @see com.kyj.fx.voeditor.visual.component.MasterSlaveChartComposite#init()
*/
@Override
public void init() {
MenuItem miReflesh = new MenuItem("Reflesh");
miReflesh.setOnAction(ex -> {
getLineChartDayOfWeek().getData().clear();
getLineChartDayOfWeekCategory().getCategories().clear();
getBarChartDayOfMonth().getData().clear();
getBarChartDayOfMonthCategory().getCategories().clear();
load();
});
ContextMenu contextMenu = new ContextMenu(miReflesh);
this.addEventFilter(MouseEvent.MOUSE_CLICKED, ev -> {
contextMenu.hide();
if (ev.getButton() == MouseButton.SECONDARY) {
contextMenu.show(FxUtil.getWindow(this), ev.getScreenX(), ev.getScreenY());
}
});
}
use of javafx.scene.control.MenuItem in project Gargoyle by callakrsos.
the class PostgreSqlPane method menuExportMergeScriptOnAction.
/* (non-Javadoc)
* @see com.kyj.fx.voeditor.visual.component.sql.view.SqlPane#menuExportMergeScriptOnAction(javafx.event.ActionEvent)
*/
@Override
public void menuExportMergeScriptOnAction(ActionEvent e) {
// TableView<Map<String, Object>> tbResult = getTbResult();
List<Map<String, Object>> items = getSelectedTabResultItems();
// TreeView<DatabaseItemTree<String>> schemaTree = getSchemaTree();
//
// List<String> schemaList = schemaTree.getRoot().getChildren().stream().map(v -> v.getValue().getName()).collect(Collectors.toList());
//
String defaultSchema = "";
try {
Map<String, Object> findOne = DbUtil.findOne(connectionSupplier.get(), "select current_schema() as currentschema");
if (findOne != null && !findOne.isEmpty()) {
defaultSchema = ValueUtil.decode(findOne.get("currentschema"), "").toString();
}
} catch (Exception e4) {
e4.printStackTrace();
}
//
final String _defaultSchema = defaultSchema;
//
// if (items.isEmpty())
// return;
//
// // TODO :: DBMS에 따라 Merge문 생성 로직 분기 처리 필요.
//
// Optional<Pair<String, String[]>> showInputDialog = 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 -> v.getValue().getName())
// .collect(Collectors.toList());
// });
// txtSchema.setText(_defaultSchema);
//
// //Default TableName
// TreeItem<DatabaseItemTree<String>> selectedItem = getSchemaTree().getSelectionModel().getSelectedItem();
// if (null != selectedItem) {
// DatabaseItemTree<String> value = selectedItem.getValue();
// if (value instanceof TableItemTree) {
// txtTable.setText(value.getName());
// }
// }
//
// 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;
// }
//
// });
Optional<Pair<String, String[]>> showTableInputDialog = showTableInputDialog(v -> v.getName());
showTableInputDialog.ifPresent(op -> {
if (!"OK".equals(op.getKey()))
return;
String[] resultValue = op.getValue();
try {
StringBuilder clip = new StringBuilder();
PostgreTableItemTree dirtyTreeItem = new PostgreTableItemTree();
String schemaName = (resultValue[0] == null || resultValue[0].isEmpty()) ? _defaultSchema : resultValue[0];
String tableName = resultValue[1];
String childrenSQL = dirtyTreeItem.getChildrenSQL(schemaName, tableName);
List<Map<String, Object>> select = DbUtil.select(childrenSQL);
List<String> pkList = new ArrayList<>();
List<String> notPkList = new ArrayList<>();
List<String> columnList = new ArrayList<>();
for (Map<String, Object> map : select) {
String columnName = map.get("column_name").toString();
Object primaryKeyYn = map.get("primary_yn");
columnList.add(columnName);
if ("Y".equals(primaryKeyYn)) {
pkList.add(columnName);
} else {
notPkList.add(columnName);
}
}
String mergePreffix = String.format("with upsert as ( update %s set ", tableName);
String mergeMiddle = " returning * )\n";
String collect = columnList.stream().collect(Collectors.joining(", ", "(", ")"));
String insertPreffix = String.format("insert into %s", tableName);
String insertend = " where not exists (select * from upsert);\n";
List<String> valueList = items.stream().map(v -> {
return ValueUtil.toJSONObject(v);
}).map(v -> {
String updateSetSql = notPkList.stream().map(str -> {
if (str == null)
return null;
else {
JsonElement jsonElement = v.get(str);
if (jsonElement == null) {
return str.concat("=").concat("null");
} else {
String dataValue = jsonElement.toString();
dataValue = dataValue.substring(1, dataValue.length() - 1);
if (dataValue.indexOf("'") >= 0) {
dataValue = StringUtils.replace(dataValue, "'", "''");
}
return str.concat("=").concat("'").concat(dataValue).concat("'");
}
}
}).collect(Collectors.joining(", "));
String updateWhereSql = pkList.stream().map(str -> {
if (str == null)
return null;
else {
if (null == v.get(str))
return null;
String dataValue = v.get(str).toString();
dataValue = dataValue.substring(1, dataValue.length() - 1);
if (dataValue.indexOf("'") >= 0) {
try {
dataValue = StringUtils.replace(dataValue, "'", "''");
} catch (Exception e1) {
e1.printStackTrace();
}
}
return str.concat(" = ").concat("'").concat(dataValue).concat("'");
}
}).filter(str -> str != null).collect(Collectors.joining(" and "));
String insertValueSql = columnList.stream().map(str -> {
if (str == null)
return null;
else {
JsonElement jsonElement = v.get(str);
if (jsonElement == null) {
return "null";
} else {
String dataValue = jsonElement.toString();
dataValue = dataValue.substring(1, dataValue.length() - 1);
if (dataValue.indexOf("'") >= 0) {
dataValue = StringUtils.replace(dataValue, "'", "''");
}
return "'".concat(dataValue).concat("'");
}
}
}).collect(Collectors.joining(", "));
return new StringBuilder().append(mergePreffix).append(updateSetSql).append(" where ").append(updateWhereSql).append(mergeMiddle).append(insertPreffix).append(collect).append(" select ").append(insertValueSql).append(insertend).toString();
}).collect(Collectors.toList());
valueList.forEach(str -> {
clip.append(str);
});
SqlKeywords parent = new SqlKeywords();
{
MenuBar menuBar = new MenuBar();
Menu menuFile = new Menu("File");
MenuItem miSaveAs = new MenuItem("Save As");
miSaveAs.setOnAction(ev -> {
File saveAsFile = DialogUtil.showFileSaveCheckDialog(getScene().getWindow(), chooser -> {
chooser.getExtensionFilters().add(new ExtensionFilter(GargoyleExtensionFilters.SQL_NAME, GargoyleExtensionFilters.SQL));
});
if (saveAsFile != null) {
ThreadUtil.createNewThreadAndRun("Saveas", () -> {
SaveSQLFileFunction function = new SaveSQLFileFunction();
function.apply(saveAsFile, parent.getText());
});
}
});
menuFile.getItems().add(miSaveAs);
menuBar.getMenus().add(menuFile);
parent.setTop(menuBar);
}
parent.setContent(clip.toString());
parent.setWrapText(false);
parent.setPrefSize(1200d, 800d);
FxUtil.createStageAndShow(parent, stage -> {
stage.initOwner(getScene().getWindow());
stage.setTitle(String.format("[Merge Script] Table : %s", tableName));
});
} catch (Exception e2) {
LOGGER.error(ValueUtil.toString(e2));
DialogUtil.showExceptionDailog(e2, "에러발생, 테이블을 잘못 선택하셨을 수 있습니다.");
}
});
}
Aggregations