Search in sources :

Example 36 with ObservableList

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);
}
Also used : PseudoClass(javafx.css.PseudoClass) TreeItem(javafx.scene.control.TreeItem) Control(javafx.scene.control.Control) BindingsHelper(org.jabref.gui.util.BindingsHelper) DialogService(org.jabref.gui.DialogService) StackPane(javafx.scene.layout.StackPane) DragEvent(javafx.scene.input.DragEvent) TreeTableRow(javafx.scene.control.TreeTableRow) TransferMode(javafx.scene.input.TransferMode) Inject(javax.inject.Inject) TextFields(org.controlsfx.control.textfield.TextFields) TreeTableView(javafx.scene.control.TreeTableView) Dragboard(javafx.scene.input.Dragboard) ContextMenu(javafx.scene.control.ContextMenu) Localization(org.jabref.logic.l10n.Localization) Method(java.lang.reflect.Method) RecursiveTreeItem(org.jabref.gui.util.RecursiveTreeItem) ObjectProperty(javafx.beans.property.ObjectProperty) TextField(javafx.scene.control.TextField) MenuItem(javafx.scene.control.MenuItem) AbstractController(org.jabref.gui.AbstractController) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) Consumer(java.util.function.Consumer) FXML(javafx.fxml.FXML) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) Text(javafx.scene.text.Text) TreeTableColumn(javafx.scene.control.TreeTableColumn) TaskExecutor(org.jabref.gui.util.TaskExecutor) List(java.util.List) ActionEvent(javafx.event.ActionEvent) StateManager(org.jabref.gui.StateManager) SelectionMode(javafx.scene.control.SelectionMode) DragAndDropDataFormats(org.jabref.gui.DragAndDropDataFormats) EasyBind(org.fxmisc.easybind.EasyBind) ViewModelTreeTableCellFactory(org.jabref.gui.util.ViewModelTreeTableCellFactory) Optional(java.util.Optional) Log(org.apache.commons.logging.Log) ObservableList(javafx.collections.ObservableList) ClipboardContent(javafx.scene.input.ClipboardContent) LogFactory(org.apache.commons.logging.LogFactory) CustomTextField(org.controlsfx.control.textfield.CustomTextField) PseudoClass(javafx.css.PseudoClass) ViewModelTreeTableCellFactory(org.jabref.gui.util.ViewModelTreeTableCellFactory) ClipboardContent(javafx.scene.input.ClipboardContent) Text(javafx.scene.text.Text) ContextMenu(javafx.scene.control.ContextMenu) RecursiveTreeItem(org.jabref.gui.util.RecursiveTreeItem) ObservableList(javafx.collections.ObservableList) List(java.util.List) ObservableList(javafx.collections.ObservableList) TreeTableRow(javafx.scene.control.TreeTableRow) StackPane(javafx.scene.layout.StackPane) Dragboard(javafx.scene.input.Dragboard) FXML(javafx.fxml.FXML)

Example 37 with ObservableList

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;
}
Also used : Button(javafx.scene.control.Button) SystemLayoutViewController(com.kyj.fx.voeditor.visual.main.layout.SystemLayoutViewController) Scene(javafx.scene.Scene) TextArea(javafx.scene.control.TextArea) Control(javafx.scene.control.Control) FXCollections(javafx.collections.FXCollections) Skin(javafx.scene.control.Skin) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Application(javafx.application.Application) Parent(javafx.scene.Parent) ScrollPane(javafx.scene.control.ScrollPane) FXMLLoader(javafx.fxml.FXMLLoader) ReadOnlyProperty(javafx.beans.property.ReadOnlyProperty) Method(java.lang.reflect.Method) HBox(javafx.scene.layout.HBox) Node(javafx.scene.Node) IOException(java.io.IOException) List(java.util.List) Stream(java.util.stream.Stream) Stage(javafx.stage.Stage) FxControlTreeView(com.kyj.fx.voeditor.visual.component.FxControlTreeView) DefaultProperty(javafx.beans.DefaultProperty) HTMLEditor(javafx.scene.web.HTMLEditor) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) ReadOnlyProperty(javafx.beans.property.ReadOnlyProperty) Parent(javafx.scene.Parent) Node(javafx.scene.Node) ArrayList(java.util.ArrayList) FXCollections(javafx.collections.FXCollections) DefaultProperty(javafx.beans.DefaultProperty) IOException(java.io.IOException) Function(java.util.function.Function) Control(javafx.scene.control.Control) ObservableList(javafx.collections.ObservableList) Stream(java.util.stream.Stream)

Example 38 with ObservableList

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();
    }
}
Also used : Button(javafx.scene.control.Button) SystemLayoutViewController(com.kyj.fx.voeditor.visual.main.layout.SystemLayoutViewController) Scene(javafx.scene.Scene) TextArea(javafx.scene.control.TextArea) Control(javafx.scene.control.Control) FXCollections(javafx.collections.FXCollections) Skin(javafx.scene.control.Skin) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Application(javafx.application.Application) Parent(javafx.scene.Parent) ScrollPane(javafx.scene.control.ScrollPane) FXMLLoader(javafx.fxml.FXMLLoader) ReadOnlyProperty(javafx.beans.property.ReadOnlyProperty) Method(java.lang.reflect.Method) HBox(javafx.scene.layout.HBox) Node(javafx.scene.Node) IOException(java.io.IOException) List(java.util.List) Stream(java.util.stream.Stream) Stage(javafx.stage.Stage) FxControlTreeView(com.kyj.fx.voeditor.visual.component.FxControlTreeView) DefaultProperty(javafx.beans.DefaultProperty) HTMLEditor(javafx.scene.web.HTMLEditor) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) SystemLayoutViewController(com.kyj.fx.voeditor.visual.main.layout.SystemLayoutViewController) BorderPane(javafx.scene.layout.BorderPane) HBox(javafx.scene.layout.HBox) TextArea(javafx.scene.control.TextArea) Node(javafx.scene.Node) IOException(java.io.IOException) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) FxControlTreeView(com.kyj.fx.voeditor.visual.component.FxControlTreeView) Button(javafx.scene.control.Button) ScrollPane(javafx.scene.control.ScrollPane) HTMLEditor(javafx.scene.web.HTMLEditor)

Example 39 with ObservableList

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();
}
Also used : GridBase(org.controlsfx.control.spreadsheet.GridBase) SpreadsheetCell(org.controlsfx.control.spreadsheet.SpreadsheetCell) ExcelTemplateControl(com.kyj.fx.voeditor.visual.component.spreadsheets.ExcelTemplateControl) ObservableList(javafx.collections.ObservableList) GagoyleSpreadSheetView(com.kyj.fx.voeditor.visual.component.spreadsheets.GagoyleSpreadSheetView) Scene(javafx.scene.Scene)

Example 40 with ObservableList

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;
}
Also used : Arrays(java.util.Arrays) MouseButton(javafx.scene.input.MouseButton) ListView(javafx.scene.control.ListView) TextArea(javafx.scene.control.TextArea) ListCell(javafx.scene.control.ListCell) MouseEvent(javafx.scene.input.MouseEvent) LoggerFactory(org.slf4j.LoggerFactory) JavaTextArea(com.kyj.fx.voeditor.visual.component.text.JavaTextArea) FXCollections(javafx.collections.FXCollections) JavaSVNManager(com.kyj.scm.manager.svn.java.JavaSVNManager) VBox(javafx.scene.layout.VBox) ContextMenu(javafx.scene.control.ContextMenu) Map(java.util.Map) FxCollectors(com.kyj.fx.voeditor.visual.util.FxCollectors) Callback(javafx.util.Callback) SVNLogEntryPath(org.tmatesoft.svn.core.SVNLogEntryPath) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) MenuItem(javafx.scene.control.MenuItem) Collection(java.util.Collection) SVNNodeKind(org.tmatesoft.svn.core.SVNNodeKind) Node(javafx.scene.Node) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) Collectors(java.util.stream.Collectors) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) List(java.util.List) SelectionMode(javafx.scene.control.SelectionMode) SVNLogEntry(org.tmatesoft.svn.core.SVNLogEntry) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) DateUtil(com.kyj.fx.voeditor.visual.util.DateUtil) ObservableList(javafx.collections.ObservableList) SVNLogEntry(org.tmatesoft.svn.core.SVNLogEntry) TextArea(javafx.scene.control.TextArea) JavaTextArea(com.kyj.fx.voeditor.visual.component.text.JavaTextArea) ListCell(javafx.scene.control.ListCell) Label(javafx.scene.control.Label) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) ListView(javafx.scene.control.ListView) ObservableList(javafx.collections.ObservableList) Collection(java.util.Collection) List(java.util.List) ObservableList(javafx.collections.ObservableList) VBox(javafx.scene.layout.VBox)

Aggregations

ObservableList (javafx.collections.ObservableList)77 List (java.util.List)46 ArrayList (java.util.ArrayList)31 Collectors (java.util.stream.Collectors)29 Map (java.util.Map)28 FXCollections (javafx.collections.FXCollections)28 HashMap (java.util.HashMap)21 Node (javafx.scene.Node)20 TableColumn (javafx.scene.control.TableColumn)20 Label (javafx.scene.control.Label)18 Optional (java.util.Optional)17 ActionEvent (javafx.event.ActionEvent)16 FXML (javafx.fxml.FXML)16 TableView (javafx.scene.control.TableView)16 MouseEvent (javafx.scene.input.MouseEvent)16 Logger (org.slf4j.Logger)16 LoggerFactory (org.slf4j.LoggerFactory)16 Button (javafx.scene.control.Button)15 BorderPane (javafx.scene.layout.BorderPane)15 File (java.io.File)14