use of javafx.collections.ObservableList in project jabref by JabRef.
the class GroupTreeController method initialize.
@FXML
public void initialize() {
viewModel = new GroupTreeViewModel(stateManager, dialogService, taskExecutor);
// Set-up groups tree
groupTree.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
// Set-up bindings
Consumer<ObservableList<GroupNodeViewModel>> updateSelectedGroups = (newSelectedGroups) -> newSelectedGroups.forEach(this::selectNode);
Consumer<List<TreeItem<GroupNodeViewModel>>> updateViewModel = (newSelectedGroups) -> {
if (newSelectedGroups == null) {
viewModel.selectedGroupsProperty().clear();
} else {
viewModel.selectedGroupsProperty().setAll(newSelectedGroups.stream().map(TreeItem::getValue).collect(Collectors.toList()));
}
};
BindingsHelper.bindContentBidirectional(groupTree.getSelectionModel().getSelectedItems(), viewModel.selectedGroupsProperty(), updateSelectedGroups, updateViewModel);
viewModel.filterTextProperty().bind(searchField.textProperty());
groupTree.rootProperty().bind(EasyBind.map(viewModel.rootGroupProperty(), group -> new RecursiveTreeItem<>(group, GroupNodeViewModel::getChildren, GroupNodeViewModel::expandedProperty, viewModel.filterPredicateProperty())));
// Icon and group name
mainColumn.setCellValueFactory(cellData -> cellData.getValue().valueProperty());
mainColumn.setCellFactory(new ViewModelTreeTableCellFactory<GroupNodeViewModel, GroupNodeViewModel>().withText(GroupNodeViewModel::getDisplayName).withIcon(GroupNodeViewModel::getIconCode, GroupNodeViewModel::getColor).withTooltip(GroupNodeViewModel::getDescription));
// Number of hits
PseudoClass anySelected = PseudoClass.getPseudoClass("any-selected");
PseudoClass allSelected = PseudoClass.getPseudoClass("all-selected");
numberColumn.setCellFactory(new ViewModelTreeTableCellFactory<GroupNodeViewModel, GroupNodeViewModel>().withGraphic(group -> {
final StackPane node = new StackPane();
node.getStyleClass().setAll("hits");
if (!group.isRoot()) {
BindingsHelper.includePseudoClassWhen(node, anySelected, group.anySelectedEntriesMatchedProperty());
BindingsHelper.includePseudoClassWhen(node, allSelected, group.allSelectedEntriesMatchedProperty());
}
Text text = new Text();
text.textProperty().bind(group.getHits().asString());
text.getStyleClass().setAll("text");
node.getChildren().add(text);
node.setMaxWidth(Control.USE_PREF_SIZE);
return node;
}));
// Arrow indicating expanded status
disclosureNodeColumn.setCellValueFactory(cellData -> cellData.getValue().valueProperty());
disclosureNodeColumn.setCellFactory(new ViewModelTreeTableCellFactory<GroupNodeViewModel, GroupNodeViewModel>().withGraphic(viewModel -> {
final StackPane disclosureNode = new StackPane();
disclosureNode.visibleProperty().bind(viewModel.hasChildrenProperty());
disclosureNode.getStyleClass().setAll("tree-disclosure-node");
final StackPane disclosureNodeArrow = new StackPane();
disclosureNodeArrow.getStyleClass().setAll("arrow");
disclosureNode.getChildren().add(disclosureNodeArrow);
return disclosureNode;
}).withOnMouseClickedEvent(group -> event -> group.toggleExpansion()));
// Set pseudo-classes to indicate if row is root or sub-item ( > 1 deep)
PseudoClass rootPseudoClass = PseudoClass.getPseudoClass("root");
PseudoClass subElementPseudoClass = PseudoClass.getPseudoClass("sub");
// Pseudo-classes for drag and drop
PseudoClass dragOverBottom = PseudoClass.getPseudoClass("dragOver-bottom");
PseudoClass dragOverCenter = PseudoClass.getPseudoClass("dragOver-center");
PseudoClass dragOverTop = PseudoClass.getPseudoClass("dragOver-top");
groupTree.setRowFactory(treeTable -> {
TreeTableRow<GroupNodeViewModel> row = new TreeTableRow<>();
row.treeItemProperty().addListener((ov, oldTreeItem, newTreeItem) -> {
boolean isRoot = newTreeItem == treeTable.getRoot();
row.pseudoClassStateChanged(rootPseudoClass, isRoot);
boolean isFirstLevel = (newTreeItem != null) && (newTreeItem.getParent() == treeTable.getRoot());
row.pseudoClassStateChanged(subElementPseudoClass, !isRoot && !isFirstLevel);
});
row.setDisclosureNode(null);
row.disclosureNodeProperty().addListener((observable, oldValue, newValue) -> row.setDisclosureNode(null));
row.contextMenuProperty().bind(EasyBind.monadic(row.itemProperty()).map(this::createContextMenuForGroup).orElse((ContextMenu) null));
row.setOnDragDetected(event -> {
TreeItem<GroupNodeViewModel> selectedItem = treeTable.getSelectionModel().getSelectedItem();
if ((selectedItem != null) && (selectedItem.getValue() != null)) {
Dragboard dragboard = treeTable.startDragAndDrop(TransferMode.MOVE);
dragboard.setDragView(row.snapshot(null, null));
ClipboardContent content = new ClipboardContent();
content.put(DragAndDropDataFormats.GROUP, selectedItem.getValue().getPath());
dragboard.setContent(content);
event.consume();
}
});
row.setOnDragOver(event -> {
Dragboard dragboard = event.getDragboard();
if ((event.getGestureSource() != row) && row.getItem().acceptableDrop(dragboard)) {
event.acceptTransferModes(TransferMode.MOVE, TransferMode.LINK);
removePseudoClasses(row, dragOverBottom, dragOverCenter, dragOverTop);
switch(getDroppingMouseLocation(row, event)) {
case BOTTOM:
row.pseudoClassStateChanged(dragOverBottom, true);
break;
case CENTER:
row.pseudoClassStateChanged(dragOverCenter, true);
break;
case TOP:
row.pseudoClassStateChanged(dragOverTop, true);
break;
}
}
event.consume();
});
row.setOnDragExited(event -> {
removePseudoClasses(row, dragOverBottom, dragOverCenter, dragOverTop);
});
row.setOnDragDropped(event -> {
Dragboard dragboard = event.getDragboard();
boolean success = false;
if (dragboard.hasContent(DragAndDropDataFormats.GROUP)) {
String pathToSource = (String) dragboard.getContent(DragAndDropDataFormats.GROUP);
Optional<GroupNodeViewModel> source = viewModel.rootGroupProperty().get().getChildByPath(pathToSource);
if (source.isPresent()) {
source.get().draggedOn(row.getItem(), getDroppingMouseLocation(row, event));
success = true;
}
}
if (dragboard.hasContent(DragAndDropDataFormats.ENTRIES)) {
TransferableEntrySelection entrySelection = (TransferableEntrySelection) dragboard.getContent(DragAndDropDataFormats.ENTRIES);
row.getItem().addEntriesToGroup(entrySelection.getSelection());
success = true;
}
event.setDropCompleted(success);
event.consume();
});
return row;
});
// Filter text field
setupClearButtonField(searchField);
}
use of javafx.collections.ObservableList in project Gargoyle by callakrsos.
the class ComponentClassifier method recursive.
/**
*
* @param node
* @return
*/
List<Node> recursive(Node node) {
List<Node> controls = new ArrayList<>();
if (node == null) {
return controls;
}
if (node instanceof Control) {
Control c = (Control) node;
DefaultProperty annotation = c.getClass().getAnnotation(DefaultProperty.class);
if (annotation != null) {
String value = annotation.value();
try {
Object invoke = getMethod(c, value + "Property");
if (ReadOnlyProperty.class.isAssignableFrom(invoke.getClass())) {
ReadOnlyProperty prop = (ReadOnlyProperty) invoke;
Node bean2 = (Node) prop.getBean();
if (bean2 == null) {
return controls;
}
System.out.println("컨트롤 : " + bean2);
controls.add((Control) bean2);
} else {
System.out.println("컨트롤 : " + c);
controls.add(c);
}
} catch (Exception e) {
ObservableList<Node> childrenUnmodifiable = c.getChildrenUnmodifiable();
ObservableList<Node> collect = childrenUnmodifiable.stream().flatMap(new Function<Node, Stream<Node>>() {
@Override
public Stream<Node> apply(Node t) {
return recursive(t).stream();
}
}).collect(FXCollections::observableArrayList, (collections, item) -> collections.add(item), (collections, item) -> collections.addAll(item));
controls.addAll(collect);
}
} else /*
* if (node instanceof ScrollPane || node instanceof TabPane) { //
* scrollpane, TabPane은 컨트롤요소에 추가하지않음. // controls.add(c);
* ObservableList<Control> recursive = recursive(((ScrollPane)
* node).getContent()); controls.addAll(recursive); }
*/
{
controls.add(c);
ObservableList<Node> childrenUnmodifiable = c.getChildrenUnmodifiable();
ObservableList<Node> collect = childrenUnmodifiable.stream().flatMap(new Function<Node, Stream<Node>>() {
@Override
public Stream<Node> apply(Node t) {
return recursive(t).stream();
}
}).collect(FXCollections::observableArrayList, (collections, item) -> collections.add(item), (collections, item) -> collections.addAll(item));
controls.addAll(collect);
/* 개선 */
// childrenUnmodifiable.forEach(n -> {
// ObservableList<Node> recursive = recursive(n);
// controls.addAll(recursive);
// });
}
return controls;
} else if (node instanceof Parent) {
Parent p = (Parent) node;
// ObservableList<Node> collect =
// childrenUnmodifiable.stream().map(n->this).collect(FXCollections::observableArrayList,
// (collections, item) -> collections.add(item), (collections, item)
// -> collections.addAll(item));
// controls.addAll(collect);
ObservableList<Node> childrenUnmodifiable = p.getChildrenUnmodifiable();
// childrenUnmodifiable.forEach(n -> {
// ObservableList<Node> recursive = recursive(n);
// controls.addAll(recursive);
// });
ObservableList<Node> collect = childrenUnmodifiable.stream().flatMap(new Function<Node, Stream<Node>>() {
@Override
public Stream<Node> apply(Node t) {
return recursive(t).stream();
}
}).collect(FXCollections::observableArrayList, (collections, item) -> collections.add(item), (collections, item) -> collections.addAll(item));
controls.addAll(collect);
} else {
System.err.println("her.! : " + node);
}
return controls;
}
use of javafx.collections.ObservableList in project Gargoyle by callakrsos.
the class ComponentClassifier method start.
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(SystemLayoutViewController.class.getResource("VoEditorView.fxml"));
try {
Node node = loader.load();
// {
//
// ObservableList<Node> recursive = recursive(node);
// print(recursive);
//
// }
// {
// Group group = new Group();
//
// // Text는 Shape클래스의 하위클래스
// group.getChildren().add(new Text());
// group.getChildren().add(new Button());
// group.getChildren().add(new Button());
// group.getChildren().add(new Label());
// ObservableList<Node> recursive = recursive(group);
// print(recursive);
//
// }
// {
// ScrollPane scrollPane = new ScrollPane();
// ScrollPane scrollPane2 = new ScrollPane();
// scrollPane2.setContent(new TextArea());
// scrollPane.setContent(new BorderPane(scrollPane2));
// ObservableList<Node> recursive = recursive(scrollPane);
// print(recursive);
// }
{
BorderPane borderPane = new BorderPane();
ScrollPane scrollPane2 = new ScrollPane();
scrollPane2.setContent(new TextArea());
borderPane.setTop(new HBox(new Button(), new Button(), new HTMLEditor()));
borderPane.setCenter(new BorderPane(scrollPane2));
FxControlTreeView tv = new FxControlTreeView(borderPane);
tv.setOnMouseClicked(event -> {
System.out.println(tv.getSelectionModel().getSelectedItem());
});
Scene scene = new Scene(tv);
primaryStage.setScene(scene);
primaryStage.show();
// List<Node> recursive = recursive(borderPane);
// print(recursive);
}
//
// Scene scene = new Scene((Parent) node);
// primaryStage.setScene(scene);
// primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
use of javafx.collections.ObservableList in project Gargoyle by callakrsos.
the class GargoyleSpreadSheetExam method start.
/* (non-Javadoc)
* @see javafx.application.Application#start(javafx.stage.Stage)
*/
@Override
public void start(Stage primaryStage) throws Exception {
GridBase gridBase = new GridBase(100, 100);
List<ObservableList<SpreadsheetCell>> rows = FXCollections.observableArrayList();
for (int row = 0; row < gridBase.getRowCount(); ++row) {
ObservableList<SpreadsheetCell> currentRow = FXCollections.observableArrayList();
for (int column = 0; column < gridBase.getColumnCount(); ++column) {
SpreadsheetCell createCell = SpreadsheetCellType.STRING.createCell(row, column, 1, 1, "");
currentRow.add(createCell);
}
rows.add(currentRow);
}
gridBase.setRows(rows);
ExcelTemplateControl excelTemplateControl = new ExcelTemplateControl();
primaryStage.setScene(new Scene(new GagoyleSpreadSheetView(gridBase)));
primaryStage.show();
}
use of javafx.collections.ObservableList 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;
}
Aggregations