Java 类javafx.scene.control.MultipleSelectionModel 实例源码

项目:marathonv5    文件:RFXTreeViewTest.java   
@Test public void getTextForMultipleSelection() {
    @SuppressWarnings("rawtypes")
    TreeView treeView = (TreeView) getPrimaryStage().getScene().getRoot().lookup(".tree-view");
    LoggingRecorder lr = new LoggingRecorder();
    List<String> text = new ArrayList<>();
    Platform.runLater(new Runnable() {
        @Override public void run() {
            RFXTreeView rTreeView = new RFXTreeView(treeView, null, null, lr);
            @SuppressWarnings("rawtypes")
            MultipleSelectionModel selectionModel = treeView.getSelectionModel();
            selectionModel.setSelectionMode(SelectionMode.MULTIPLE);
            selectionModel.selectIndices(2, 3);
            rTreeView.focusLost(new RFXTreeView(null, null, null, null));
            text.add(rTreeView.getAttribute("text"));
        }
    });
    new Wait("Waiting for tree text.") {
        @Override public boolean until() {
            return text.size() > 0;
        }
    };
    AssertJUnit.assertEquals("[\"/Root node/Child Node 2\",\"/Root node/Child Node 3\"]", text.get(0));
}
项目:marathonv5    文件:RFXListViewTest.java   
@Test public void getTextForMultipleSelection() {
    ListView<?> listView = (ListView<?>) getPrimaryStage().getScene().getRoot().lookup(".list-view");
    LoggingRecorder lr = new LoggingRecorder();
    List<String> text = new ArrayList<>();
    Platform.runLater(new Runnable() {
        @Override public void run() {
            MultipleSelectionModel<?> selectionModel = listView.getSelectionModel();
            selectionModel.setSelectionMode(SelectionMode.MULTIPLE);
            selectionModel.selectIndices(2, 8);
            RFXListView rfxListView = new RFXListView(listView, null, null, lr);
            rfxListView.focusLost(new RFXListView(null, null, null, lr));
            text.add(rfxListView.getAttribute("text"));
        }
    });
    new Wait("Waiting for list text.") {
        @Override public boolean until() {
            return text.size() > 0;
        }
    };
    AssertJUnit.assertEquals("[\"Long Row 3\",\"Row 9\"]", text.get(0));
}
项目:marathonv5    文件:RFXListViewTest.java   
@Test public void selectMultipleItemSelection() {
    ListView<?> listView = (ListView<?>) getPrimaryStage().getScene().getRoot().lookup(".list-view");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(new Runnable() {
        @Override public void run() {
            MultipleSelectionModel<?> selectionModel = listView.getSelectionModel();
            selectionModel.setSelectionMode(SelectionMode.MULTIPLE);
            selectionModel.selectIndices(2, 6);
            RFXListView rfxListView = new RFXListView(listView, null, null, lr);
            rfxListView.focusLost(new RFXListView(null, null, null, lr));
        }
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("[\"Long Row 3\",\"Row 7\"]", recording.getParameters()[0]);
}
项目:jmonkeybuilder    文件:VirtualAssetEditorDialog.java   
@Override
@FXThread
protected @NotNull ObservableBooleanValue buildAdditionalDisableCondition() {

    final VirtualResourceTree<C> resourceTree = getResourceTree();
    final MultipleSelectionModel<TreeItem<VirtualResourceElement<?>>> selectionModel = resourceTree.getSelectionModel();
    final ReadOnlyObjectProperty<TreeItem<VirtualResourceElement<?>>> selectedItemProperty = selectionModel.selectedItemProperty();

    final Class<C> type = getObjectsType();
    final BooleanBinding typeCondition = new BooleanBinding() {

        @Override
        protected boolean computeValue() {
            final TreeItem<VirtualResourceElement<?>> treeItem = selectedItemProperty.get();
            return treeItem == null || !type.isInstance(treeItem.getValue().getObject());
        }

        @Override
        public Boolean getValue() {
            return computeValue();
        }
    };

    return Bindings.or(selectedItemProperty.isNull(), typeCondition);
}
项目:jmonkeybuilder    文件:VirtualAssetEditorDialog.java   
@Override
@FXThread
protected void processOk() {
    super.processOk();

    final VirtualResourceTree<C> resourceTree = getResourceTree();
    final MultipleSelectionModel<TreeItem<VirtualResourceElement<?>>> selectionModel = resourceTree.getSelectionModel();
    final TreeItem<VirtualResourceElement<?>> selectedItem = selectionModel.getSelectedItem();

    if (selectedItem == null) {
        hide();
        return;
    }

    final VirtualResourceElement<?> element = selectedItem.getValue();
    final Object object = element.getObject();
    final Class<C> type = getObjectsType();

    if (type.isInstance(object)) {
        getConsumer().accept(type.cast(object));
    }
}
项目:jmonkeybuilder    文件:AssetEditorDialog.java   
@Override
@FXThread
protected void processOk() {
    super.processOk();

    final ResourceTree resourceTree = getResourceTree();
    final MultipleSelectionModel<TreeItem<ResourceElement>> selectionModel = resourceTree.getSelectionModel();
    final TreeItem<ResourceElement> selectedItem = selectionModel.getSelectedItem();

    if (selectedItem == null) {
        hide();
        return;
    }

    processOpen(selectedItem.getValue());
}
项目:jmonkeybuilder    文件:AppStateList.java   
/**
 * Fill a list of app states.
 *
 * @param sceneNode the scene node
 */
public void fill(@NotNull final SceneNode sceneNode) {

    final ListView<EditableSceneAppState> listView = getListView();
    final MultipleSelectionModel<EditableSceneAppState> selectionModel = listView.getSelectionModel();
    final EditableSceneAppState selected = selectionModel.getSelectedItem();

    final ObservableList<EditableSceneAppState> items = listView.getItems();
    items.clear();

    final List<SceneAppState> appStates = sceneNode.getAppStates();
    appStates.stream().filter(EditableSceneAppState.class::isInstance)
            .map(EditableSceneAppState.class::cast)
            .forEach(items::add);

    if (selected != null && appStates.contains(selected)) {
        selectionModel.select(selected);
    }
}
项目:jmonkeybuilder    文件:FilterList.java   
/**
 * Fill a list of filters.
 *
 * @param sceneNode the scene node
 */
public void fill(@NotNull final SceneNode sceneNode) {

    final MultipleSelectionModel<EditableSceneFilter> selectionModel = listView.getSelectionModel();
    final EditableSceneFilter selected = selectionModel.getSelectedItem();

    final ObservableList<EditableSceneFilter> items = listView.getItems();
    items.clear();

    final List<SceneFilter> filters = sceneNode.getFilters();
    filters.stream().filter(EditableSceneFilter.class::isInstance)
            .map(EditableSceneFilter.class::cast)
            .forEach(items::add);

    if (selected != null && filters.contains(selected)) {
        selectionModel.select(selected);
    }
}
项目:openjfx-8u-dev-tests    文件:TreeViewCommonFunctionality.java   
protected static HashSet<Point> getSelected(final Wrap<? extends Control> testedControl) {

        return new GetAction<HashSet<Point>>() {
            @Override
            public void run(Object... parameters) throws Exception {
                HashSet<Point> selected = new HashSet<Point>();
                final Control control = testedControl.getControl();
                MultipleSelectionModel model;
                if (control instanceof TreeView) {
                    model = ((TreeView) control).getSelectionModel();
                } else {
                    model = ((TreeTableView) control).getSelectionModel();
                }
                for (Object obj : model.getSelectedIndices()) {
                    Integer pos = (Integer) obj;
                    selected.add(new Point(-1, pos));
                }
                setResult(selected);
            }
        }.dispatch(Root.ROOT.getEnvironment());
    }
项目:org.csstudio.display.builder    文件:AddAnnotationDialog.java   
private boolean checkInput()
{
    if (traces.isEmpty())
    {
        new Alert(AlertType.INFORMATION, Messages.AddAnnotation_NoTraces).showAndWait();
        return false;
    }
    final MultipleSelectionModel<Trace<XTYPE>> seletion = trace_list.getSelectionModel();
    final Trace<XTYPE> item = seletion.isEmpty() ? traces.get(0) : seletion.getSelectedItem();
    final String content = text.getText().trim();
    if (content.isEmpty())
    {
        new Alert(AlertType.WARNING, Messages.AddAnnotation_NoContent).showAndWait();
        return false;
    }
    plot.addAnnotation(item, content);
    return true;
}
项目:org.csstudio.display.builder    文件:WidgetTree.java   
/** Called by selection handler when selected widgets have changed, or on new model
 *  @param widgets Widgets to select in tree
 */
public void setSelectedWidgets(final List<Widget> widgets)
{
    if (! active.compareAndSet(false, true))
        return;
    try
    {
        final MultipleSelectionModel<TreeItem<WidgetOrTab>> selection = tree_view.getSelectionModel();
        selection.clearSelection();
        for (Widget widget : widgets)
            selection.select(widget2tree.get(widget));
    }
    finally
    {
        active.set(false);
    }
}
项目:mlo-gui    文件:MloInfoViewController.java   
@Override
public void initialize(URL url, ResourceBundle rb) {
    LOG.info("Start initializing");

    headerLabel.setText(ClientConfigConstants.APP_NAME);
    copyrightLabel.setText(ClientConfigConstants.APP_COPYRIGHT);

    MultipleSelectionModel<String>  model = sliceListView.getSelectionModel();
    ObservableList<String> selectedItems = model.getSelectedItems();
    selectedItems.addListener(new ListChangeListener<String>() {
        @Override
        public void onChanged(Change<? extends String> change) {
            selectSliceName = change.getList().get(0);

            doReadSliceTask(MloClient.getInstance());
        }
    });

    scrollPane.setContent(sliceFlowsDispVBox);

    setUpView();

    LOG.info("End initializing");
}
项目:auto-web-auth    文件:SummaryPresenter.java   
@Override
public void initialize(URL location, ResourceBundle resources)
{
   loadRegistrations();

   this.registrationList.selectionModelProperty().addListener(
         new ChangeListener<MultipleSelectionModel<Registration>>()
         {
            @Override
            public void changed(
                  ObservableValue<? extends MultipleSelectionModel<Registration>> observable,
                  MultipleSelectionModel<Registration> oldValue,
                  MultipleSelectionModel<Registration> newValue)
            {
               if (registrationList.getItems().size() == 0)
               {
                  btModifyRegistration.setDisable(true);
               }
               else
               {
                  btModifyRegistration.setDisable(false);
               }

            }
         });
}
项目:marathonv5    文件:UpDownHandler.java   
@Override public void handle(ActionEvent event) {
    MultipleSelectionModel<ClassPathElement> selectionModel = classPathListView.getSelectionModel();
    ObservableList<ClassPathElement> items = classPathListView.getItems();
    int selectedIndex = selectionModel.getSelectedIndex();
    ClassPathElement selectedItem = selectionModel.getSelectedItem();
    items.remove(selectedItem);
    if (shouldMoveUp) {
        items.add(selectedIndex - 1, selectedItem);
    } else {
        items.add(selectedIndex + 1, selectedItem);
    }
    selectionModel.clearAndSelect(items.indexOf(selectedItem));
}
项目:marathonv5    文件:HistoryUpDownHandler.java   
@Override public void handle(ActionEvent event) {
    MultipleSelectionModel<JSONObject> selectionModel = historyView.getSelectionModel();
    ObservableList<JSONObject> items = historyView.getItems();
    int selectedIndex = selectionModel.getSelectedIndex();
    JSONObject selectedItem = selectionModel.getSelectedItem();
    items.remove(selectedItem);
    if (shouldMoveUp) {
        items.add(selectedIndex - 1, selectedItem);
    } else {
        items.add(selectedIndex + 1, selectedItem);
    }
    selectionModel.select(selectedItem);
    TestRunnerHistory.getInstance().rewrite("favourites", items);
}
项目:marathonv5    文件:ListLayout.java   
private VBox createListView() {
    listViewBox = new VBox(5);
    classPathListView = new ListView<ClassPathElement>(classPathListItems);
    classPathListView.setPrefHeight(Node.BASELINE_OFFSET_SAME_AS_HEIGHT);
    classPathListView.setId("ClassPathList");
    classPathListView.setCellFactory((e) -> {
        ClassPathCell classPathCell = new ClassPathCell();
        classPathCell.setId("ClassPathCell");
        return classPathCell;
    });

    if (!isSingleSelection()) {
        classPathListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    }
    classPathListView.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
        MultipleSelectionModel<ClassPathElement> selectionModel = classPathListView.getSelectionModel();
        int itemCount = classPathListItems.size();
        int selectedIndex = selectionModel.getSelectedIndex();
        setButtonState(deleteButton, selectedIndex != -1);
        boolean enable = selectedIndex != 0 && selectedIndex != -1 && itemCount > 1;
        setButtonState(upButton, enable);
        enable = selectedIndex != itemCount - 1 && selectedIndex != -1 && itemCount > 1;
        setButtonState(downButton, enable);
    });
    listViewBox.getChildren().add(classPathListView);
    HBox.setHgrow(listViewBox, Priority.ALWAYS);
    VBox.setVgrow(classPathListView, Priority.ALWAYS);
    return listViewBox;
}
项目:jmonkeybuilder    文件:AssetEditorDialog.java   
@Override
@FXThread
protected @NotNull ObservableBooleanValue buildAdditionalDisableCondition() {
    final ResourceTree resourceTree = getResourceTree();
    final MultipleSelectionModel<TreeItem<ResourceElement>> selectionModel = resourceTree.getSelectionModel();
    final ReadOnlyObjectProperty<TreeItem<ResourceElement>> selectedItemProperty = selectionModel.selectedItemProperty();
    return selectedItemProperty.isNull();
}
项目:jmonkeybuilder    文件:AppStateList.java   
/**
 * Create components of this component.
 */
private void createComponents() {

    listView = new ListView<>();
    listView.setCellFactory(param -> new AppStateListCell(this));
    listView.setEditable(false);
    listView.setFocusTraversable(true);
    listView.prefHeightProperty().bind(heightProperty());
    listView.prefWidthProperty().bind(widthProperty());
    listView.setFixedCellSize(FXConstants.LIST_CELL_HEIGHT);

    final MultipleSelectionModel<EditableSceneAppState> selectionModel = listView.getSelectionModel();
    selectionModel.selectedItemProperty().addListener((observable, oldValue, newValue) ->
            selectHandler.accept(newValue));

    final Button addButton = new Button();
    addButton.setGraphic(new ImageView(Icons.ADD_12));
    addButton.setOnAction(event -> addAppState());

    final Button removeButton = new Button();
    removeButton.setGraphic(new ImageView(Icons.REMOVE_12));
    removeButton.setOnAction(event -> removeAppState());
    removeButton.disableProperty().bind(selectionModel.selectedItemProperty().isNull());

    final HBox buttonContainer = new HBox(addButton, removeButton);

    FXUtils.addToPane(listView, this);
    FXUtils.addToPane(buttonContainer, this);

    FXUtils.addClassTo(buttonContainer, CSSClasses.DEF_HBOX);
    FXUtils.addClassTo(addButton, CSSClasses.BUTTON_WITHOUT_RIGHT_BORDER);
    FXUtils.addClassTo(removeButton, CSSClasses.BUTTON_WITHOUT_LEFT_BORDER);
    FXUtils.addClassTo(listView, CSSClasses.TRANSPARENT_LIST_VIEW);

    DynamicIconSupport.addSupport(addButton, removeButton);
}
项目:jmonkeybuilder    文件:AppStateList.java   
/**
 * Handle removing an old app state.
 */
private void removeAppState() {

    final MultipleSelectionModel<EditableSceneAppState> selectionModel = getListView().getSelectionModel();
    final EditableSceneAppState appState = selectionModel.getSelectedItem();
    final SceneNode sceneNode = changeConsumer.getCurrentModel();

    changeConsumer.execute(new RemoveAppStateOperation(appState, sceneNode));
}
项目:jmonkeybuilder    文件:FilterList.java   
/**
 * Create components of this component.
 */
private void createComponents() {

    listView = new ListView<>();
    listView.setCellFactory(param -> new FilterListCell(this));
    listView.setEditable(false);
    listView.setFocusTraversable(true);
    listView.prefHeightProperty().bind(heightProperty());
    listView.prefWidthProperty().bind(widthProperty());
    listView.setFixedCellSize(FXConstants.LIST_CELL_HEIGHT);

    final MultipleSelectionModel<EditableSceneFilter> selectionModel = listView.getSelectionModel();
    selectionModel.selectedItemProperty().addListener((observable, oldValue, newValue) ->
            selectHandler.accept(newValue));

    final Button addButton = new Button();
    addButton.setGraphic(new ImageView(Icons.ADD_12));
    addButton.setOnAction(event -> addFilter());

    final Button removeButton = new Button();
    removeButton.setGraphic(new ImageView(Icons.REMOVE_12));
    removeButton.setOnAction(event -> removeFilter());
    removeButton.disableProperty().bind(selectionModel.selectedItemProperty().isNull());

    final HBox buttonContainer = new HBox(addButton, removeButton);

    FXUtils.addToPane(listView, this);
    FXUtils.addToPane(buttonContainer, this);

    FXUtils.addClassTo(buttonContainer, CSSClasses.DEF_HBOX);
    FXUtils.addClassTo(addButton, CSSClasses.BUTTON_WITHOUT_RIGHT_BORDER);
    FXUtils.addClassTo(removeButton, CSSClasses.BUTTON_WITHOUT_LEFT_BORDER);
    FXUtils.addClassTo(listView, CSSClasses.TRANSPARENT_LIST_VIEW);

    DynamicIconSupport.addSupport(addButton, removeButton);
}
项目:jmonkeybuilder    文件:FilterList.java   
/**
 * Handle removing an old filter.
 */
private void removeFilter() {

    final MultipleSelectionModel<EditableSceneFilter> selectionModel = listView.getSelectionModel();
    final EditableSceneFilter filter = selectionModel.getSelectedItem();
    final SceneNode sceneNode = changeConsumer.getCurrentModel();

    changeConsumer.execute(new RemoveSceneFilterOperation(filter, sceneNode));
}
项目:livestreamer_twitch_gui    文件:ChannelList.java   
private void setupChannelList() {
    final MultipleSelectionModel<IChannel> selectionModel = this.channelListView.getSelectionModel();
    selectionModel.setSelectionMode(SelectionMode.SINGLE);
    this.selectedChannelProperty.bind(selectionModel.selectedItemProperty());
    this.channelListView.itemsProperty().bind(this.channelListProperty);
    this.channelListView.setCellFactory(listView -> new ChannelCell());
}
项目:CalendarFX    文件:Util.java   
public static <T> MultipleSelectionModel<T> createEmptySelectionModel() {
    return new EmptySelectionModel<>();
}
项目:ExtremeGuiMakeover    文件:MovieViewSkin.java   
private void addTableAndListView() {
    FilteredList<Movie> filteredList = new FilteredList<>(database.getMovies());
    filteredList.predicateProperty().bind(getSkinnable().filterPredicateProperty());

    SortedList<Movie> tableViewSortedList = new SortedList<>(filteredList);
    TableView<Movie> tableView = new MovieTableView();
    tableViewSortedList.comparatorProperty().bind(tableView.comparatorProperty());
    tableView.setItems(tableViewSortedList);
    TableViewSelectionModel<Movie> tableViewSelectionModel = tableView.getSelectionModel();
    tableViewSelectionModel.selectedItemProperty().addListener(it -> getSkinnable().setSelectedMovie(tableViewSelectionModel.getSelectedItem()));

    PrettyListView<Movie> listView = new PrettyListView<>();
    listView.setItems(filteredList);
    MultipleSelectionModel<Movie> listViewSelectionModel = listView.getSelectionModel();
    listViewSelectionModel.selectedItemProperty().addListener(it -> getSkinnable().setSelectedMovie(listViewSelectionModel.getSelectedItem()));

    listView.setOnMouseClicked(evt -> {
        if (evt.getButton() == MouseButton.PRIMARY && evt.getClickCount() == 2) {
            showTrailer();
        }
    });

    getSkinnable().useListViewCellFactoryProperty().addListener(it -> {
        if (getSkinnable().isUseListViewCellFactory()) {
            listView.setCellFactory(view -> new MovieCell(getSkinnable()));
        } else {
            listView.setCellFactory(view -> new ListCell<Movie>() {
                @Override
                protected void updateItem(Movie item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null) {
                        setText(item.toString());
                    }
                }
            });
        }
    });

    getSkinnable().selectedMovieProperty().addListener(it -> {
        tableViewSelectionModel.select(getSkinnable().getSelectedMovie());
        listViewSelectionModel.select(getSkinnable().getSelectedMovie());
    });

    FlipPanel flipPanel = new FlipPanel();

    flipPanel.setFlipDirection(Orientation.HORIZONTAL);
    flipPanel.getFront().getChildren().add(tableView);
    flipPanel.getBack().getChildren().add(listView);

    getSkinnable().useListViewProperty().addListener(it -> {
        if (getSkinnable().isUseListView()) {
            flipPanel.flipToBack();
            if (getSkinnable().isUseListViewCellFactory()) {
                listView.setCellFactory(view -> new MovieCell(getSkinnable()));
            }
        } else {
            flipPanel.flipToFront();
        }
    });

    GridPane.setVgrow(flipPanel, Priority.ALWAYS);
    container.add(flipPanel, 1, 2);
}
项目:jmonkeybuilder    文件:AppStateList.java   
/**
 * Clear selection.
 */
public void clearSelection() {
    final MultipleSelectionModel<EditableSceneAppState> selectionModel = getListView().getSelectionModel();
    selectionModel.select(null);
}
项目:jmonkeybuilder    文件:FilterList.java   
/**
 * Clear selection.
 */
public void clearSelection() {
    final MultipleSelectionModel<EditableSceneFilter> selectionModel = listView.getSelectionModel();
    selectionModel.select(null);
}
项目:Gargoyle    文件:RaxStructureTreeViewWrapper.java   
public MultipleSelectionModel<TreeItem<RaxItem>> getSelectionModel() {
    return raxTreeView.getSelectionModel();
}
项目:factoryfx    文件:ContentAssistPopupSkin.java   
public void selectItem(String item) {
    suggestionList.scrollTo(item);
    MultipleSelectionModel<String> selectionModel = suggestionList.getSelectionModel();
    selectionModel.clearSelection();
    selectionModel.select(item);
}
项目:qupath    文件:PathObjectHierarchyView.java   
private void synchronizeSelectionModelToTree(final ListChangeListener.Change<? extends TreeItem<PathObject>> change) {
    if (synchronizingTreeToModel)
        return;
    boolean ownsChanges = !synchronizingModelToTree;
    try {
        synchronizingModelToTree = true;
        PathObjectSelectionModel model = getHierarchySelectionModel();
        if (model == null) {
            return;
        }

        // Check - was anything removed?
        boolean removed = false;
        while (change.next())
            removed = removed | change.wasRemoved();

        MultipleSelectionModel<TreeItem<PathObject>> treeModel = treeView.getSelectionModel();
        List<TreeItem<PathObject>> selectedItems = treeModel.getSelectedItems();
        // If we just have no selected items, and something was removed, then clear the selection
        if (selectedItems.isEmpty() && removed) {
            model.clearSelection();
            return;             
        }
        // If we just have one selected item, and also items were removed from the selection, then only select the one item we have
        if (selectedItems.size() == 1 && removed) {
            model.setSelectedObject(selectedItems.get(0).getValue(), false);
            return;
        }
        // If we have multiple selected items, we need to ensure that everything in the tree matches with everything in the selection model
        Set<PathObject> currentSelections = model.getSelectedObjects();
        Set<PathObject> toDeselect = new HashSet<>();
        Set<PathObject> toSelect = new HashSet<>();
        int n = treeView.getExpandedItemCount();
        for (int i = 0; i < n; i++) {
            PathObject temp = treeView.getTreeItem(i).getValue();
            if (treeModel.isSelected(i)) {
                if (!currentSelections.contains(temp))
                    toSelect.add(temp);
            } else {
                if (currentSelections.contains(temp))
                    toDeselect.add(temp);
            }
        }
        model.deselectObjects(toDeselect);
        model.selectObjects(toSelect);

        // Ensure that we have the main selected object
        TreeItem<PathObject> mainSelection = treeView.getFocusModel().getFocusedItem();
        if (mainSelection != null && model.isSelected(mainSelection.getValue()))
            model.setSelectedObject(mainSelection.getValue(), true);

    } finally {
        if (ownsChanges)
            synchronizingModelToTree = false;
    }
}
项目:qupath    文件:PathObjectHierarchyView.java   
private void synchronizeTreeToSelectionModel() {
    if (synchronizingModelToTree)
        return;
    boolean ownsChanges = !synchronizingTreeToModel;
    try {
        synchronizingTreeToModel = true;

        PathObjectSelectionModel model = getHierarchySelectionModel();
        MultipleSelectionModel<TreeItem<PathObject>> treeModel = treeView.getSelectionModel();
        if (model == null || model.noSelection()) {
            treeModel.clearSelection();
            return;
        }

        if (model.singleSelection()) {
            selectSingleObject(model.getSelectedObject());
            return;
        }

        // Loop through all possible selections, and select them if they should be selected (and not if they shouldn't)
        int n = treeView.getExpandedItemCount();
        PathObject mainSelectedObject = model.getSelectedObject();
        int mainObjectInd = -1;

        for (int i = 0; i < n; i++) {
            TreeItem<PathObject> item = treeView.getTreeItem(i);
            if (item == null) {
                treeModel.clearSelection(i);
                continue;
            }
            PathObject temp = item.getValue();
            if (temp == mainSelectedObject)
                mainObjectInd = i;
            if (model.isSelected(temp)) {
                // Only select if necessary, or if this is the main selected object
                if (!treeModel.isSelected(i))
                    treeModel.select(i);
            }
            else
                treeModel.clearSelection(i);
        }
        // Ensure that the main object is focused & its node expanded
        if (mainObjectInd >= 0) {
            treeModel.select(mainObjectInd);
            treeView.scrollTo(mainObjectInd);
        }


    } finally {
        if (ownsChanges)
            synchronizingTreeToModel = false;
    }
}
项目:qupath    文件:PathAnnotationPanel.java   
@Override
    public void selectedPathObjectChanged(final PathObject pathObjectSelected, final PathObject previousObject) {
        if (!Platform.isFxApplicationThread()) {
            Platform.runLater(() -> selectedPathObjectChanged(pathObjectSelected, previousObject));
            return;
        }

        changingSelection = true;
//      tableModel.setPathObject(pathObjectSelected);

        // TODO: Find a more robust way to do this - the check for the creation of a new object is rather hack-ish
        if (pathObjectSelected != null && pathObjectSelected.getParent() == null && !pathObjectSelected.isRootObject() && pathObjectSelected.getPathClass() == null && PathPrefs.getAutoSetAnnotationClass()) {
            PathClass pathClass = getSelectedPathClass();
            if (pathClass != null)
                pathObjectSelected.setPathClass(pathClass);
        }

        // Determine the objects to select
        MultipleSelectionModel<PathObject> model = listAnnotations.getSelectionModel();
        List<PathObject> selected = new ArrayList<>();
        for (PathObject pathObject : hierarchy.getSelectionModel().getSelectedObjects()) {
            if (pathObject == null)
                logger.warn("Selected object is null!");
            else if (pathObject.isAnnotation())
                selected.add(pathObject);
        }
        if (selected.isEmpty()) {
            model.clearSelection();
            changingSelection = false;
            return;
        }
        // Check if we're making changes
        List<PathObject> currentlySelected = model.getSelectedItems();
        if (selected.size() == currentlySelected.size() && (hierarchy.getSelectionModel().getSelectedObjects().containsAll(currentlySelected))) {
            changingSelection = false;
            listAnnotations.refresh();
            return;
        }

//      System.err.println("Setting " + currentlySelected + " to " + selected);
        int[] inds = new int[selected.size()];
        int i = 0;
        model.clearSelection();
        boolean firstInd = true;
        for (PathObject temp : selected) {
            int idx = listAnnotations.getItems().indexOf(temp);
            if (idx >= 0 && firstInd) {
                Arrays.fill(inds, idx);
                firstInd = false;
            }
            inds[i] = idx;
            i++;
        }

        if (inds.length == 1 && hierarchy.getSelectionModel().getSelectedObject() instanceof PathAnnotationObject)
            listAnnotations.scrollTo(hierarchy.getSelectionModel().getSelectedObject());

        if (firstInd) {
            changingSelection = false;
            return;
        }
        model.selectIndices(inds[0], inds);

        changingSelection = false;
    }
项目:epubfx    文件:EditingTreeCellBehavior.java   
/***************************************************************************
 *                                                                         *
 * Private implementation                                                  *
 *                                                                         *
 **************************************************************************/

@Override
protected MultipleSelectionModel<TreeItem<T>> getSelectionModel() {
    return getCellContainer().getSelectionModel();
}
项目:javafx-demos    文件:AutoCompleteTextAreaDemo.java   
public MultipleSelectionModel<ItemType> getAvailableItemsSelectionModel()
{
    return availableList.getSelectionModel();
}
项目:javafx-demos    文件:TokenInputSearchControl.java   
public MultipleSelectionModel<ItemType> getAvailableItemsSelectionModel() {
    return availableList.getSelectionModel();
}
项目:javafx-demos    文件:TokenInputSearchFlowControl.java   
public MultipleSelectionModel<ItemType> getAvailableItemsSelectionModel() {
    return availableList.getSelectionModel();
}
项目:javafx-demos    文件:AutoCompleteList.java   
public MultipleSelectionModel<ItemType> getAvailableItemsSelectionModel()
{
    return availableList.getSelectionModel();
}
项目:javafx-demos    文件:EMRComboBox.java   
public MultipleSelectionModel<ItemType> getSelectionModel()
{
    return popupList.getSelectionModel();
}
项目:Gargoyle    文件:SystemLayoutViewController.java   
/********************************
 * 작성일 : 2016. 7. 14. 작성자 : KYJ
 *
 * 트리에 선택된 모델 리턴.
 *
 * @return
 ********************************/
public final MultipleSelectionModel<TreeItem<JavaProjectFileWrapper>> getTreeProjectFileSelectionModel() {
    return treeProjectFile.getSelectionModel();
}
项目:jutility-javafx    文件:ListViewWrapper.java   
/**
 * The SelectionModel provides the API through which it is possible to
 * select single or multiple items within a ListView, as well as inspect
 * which items have been selected by the user. Note that it has a generic
 * type that must match the type of the ListView itself.
 * 
 * @return the selection model property.
 */
public final ObjectProperty<MultipleSelectionModel<T>> selectionModelProperty() {

    return this.getWrappedControl().selectionModelProperty();
}
项目:jutility-javafx    文件:ListViewWrapper.java   
/**
 * Sets the MultipleSelectionModel to be used in the ListView. Despite a
 * ListView requiring a MultipleSelectionModel, it is possible to configure
 * it to only allow single selection (see
 * MultipleSelectionModel.setSelectionMode
 * (javafx.scene.control.SelectionMode) for more information).
 * 
 * @param value
 *            the selection model.
 */
public final void setSelectionModel(MultipleSelectionModel<T> value) {

    this.getWrappedControl().setSelectionModel(value);
}