List of usage examples for javafx.collections ListChangeListener ListChangeListener
ListChangeListener
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<String>(); ObservableList<String> observableList = FXCollections.observableList(list); observableList.addListener(new ListChangeListener() { @Override/*from w ww .jav a 2 s. co m*/ public void onChanged(ListChangeListener.Change change) { System.out.println("change!"); } }); observableList.add("item one"); list.add("item two"); System.out.println("Size: " + observableList.size()); }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<String>(); ObservableList<String> observableList = FXCollections.observableList(list); observableList.addListener(new ListChangeListener() { @Override/*from w w w . ja va 2 s.c om*/ public void onChanged(ListChangeListener.Change change) { System.out.println("Detected a change! "); while (change.next()) { System.out.println("Was added? " + change.wasAdded()); System.out.println("Was removed? " + change.wasRemoved()); System.out.println("Was replaced? " + change.wasReplaced()); System.out.println("Was permutated? " + change.wasPermutated()); } } }); observableList.add("item one"); list.add("item two"); System.out.println("Size: " + observableList.size()); }
From source file:Main.java
@Override public void start(final Stage stage) { stage.setWidth(400);// w w w . java 2s . co m stage.setHeight(500); Scene scene = new Scene(new Group()); final WebView browser = new WebView(); final WebEngine webEngine = browser.getEngine(); ScrollPane scrollPane = new ScrollPane(); scrollPane.setContent(browser); browser.getEngine().setOnAlert((WebEvent<String> wEvent) -> { System.out.println("Alert Event - Message: " + wEvent.getData()); }); webEngine.load("http://java2s.com"); final WebHistory history = webEngine.getHistory(); history.getEntries().addListener(new ListChangeListener<WebHistory.Entry>() { @Override public void onChanged(Change<? extends Entry> c) { c.next(); for (Entry e : c.getRemoved()) { System.out.println(e.getUrl()); } for (Entry e : c.getAddedSubList()) { System.out.println(e.getUrl()); } } }); history.go(0); scene.setRoot(scrollPane); stage.setScene(scene); stage.show(); }
From source file:gov.va.isaac.gui.listview.operations.ParentRetire.java
@Override public void init(ObservableList<SimpleDisplayConcept> conceptList) { super.init(conceptList); root_.add(new Label("Retire as parent"), 0, 0); retireAsParent_.setPromptText("-Populate the Concepts List-"); Node n = ErrorMarkerUtils.setupErrorMarker(retireAsParent_, replaceOptionsInvalidString_); root_.add(n, 1, 0);/*from ww w.ja v a 2 s .co m*/ ComboBoxSetupTool.setupComboBox(retireAsParent_); // TODO populate retireAsParentCombo retireAsParent_.setMaxWidth(Double.MAX_VALUE); GridPane.setHgrow(n, Priority.ALWAYS); FxUtils.preventColCollapse(root_, 0); retireAsParent_.getItems().addListener(new ListChangeListener<SimpleDisplayConcept>() { @Override public void onChanged(javafx.collections.ListChangeListener.Change<? extends SimpleDisplayConcept> c) { if (retireAsParent_.getItems().size() > 0) { replaceOptionsInvalidString_.set(null); if (retireAsParent_.getSelectionModel().getSelectedItem() == null) { retireAsParent_.getSelectionModel().selectFirst(); } } else { replaceOptionsInvalidString_.set("A concept must be selected from this drop down"); retireAsParent_.getSelectionModel().clearSelection(); retireAsParent_.setValue(null); retireAsParent_.setPromptText("-Populate the Concepts List-"); } } }); allValid_ = new BooleanBinding() { { super.bind(replaceOptionsInvalidString_); } @Override protected boolean computeValue() { return StringUtils.isBlank(replaceOptionsInvalidString_.get()); } }; }
From source file:gov.va.isaac.gui.listview.operations.ParentReplace.java
private void initActionListeners() { replaceOptions_.getItems().addListener(new ListChangeListener<SimpleDisplayConcept>() { @Override/*from w ww. j a v a 2 s. c om*/ public void onChanged(ListChangeListener.Change<? extends SimpleDisplayConcept> c) { if (replaceOptions_.getItems().size() > 0) { replaceOptionsInvalidString_.set(null); if (replaceOptions_.getSelectionModel().getSelectedItem() == null) { replaceOptions_.getSelectionModel().selectFirst(); } } else { replaceOptionsInvalidString_.set("A concept must be selected from this drop down"); replaceOptions_.getSelectionModel().clearSelection(); replaceOptions_.setValue(null); replaceOptions_.setPromptText("-Populate the Concepts List-"); } } }); operationIsReady_ = new BooleanBinding() { { super.bind(replaceOptionsInvalidString_, withConcept_.isValid()); } @Override protected boolean computeValue() { if (StringUtils.isBlank(replaceOptionsInvalidString_.get()) && withConcept_.isValid().get()) { return true; } return false; } }; }
From source file:ch.unibas.fittingwizard.presentation.MoleculeListPage.java
private void setupMoleculesTable() { moleculesTable.getItems().addListener(new ListChangeListener<Molecule>() { @Override/* w w w . ja va 2 s . co m*/ public void onChanged(Change<? extends Molecule> change) { boolean hasMolecules = change.getList().size() > 0; fittingParameterButton.setDisable(!hasMolecules); } }); moleculesTable.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Molecule>() { @Override public void changed(ObservableValue observableValue, Molecule o, Molecule o2) { selectedMolecule = o2; displayButton.setDisable(selectedMolecule == null); editButton.setDisable(selectedMolecule == null); removeButton.setDisable(selectedMolecule == null); } }); nameColumn.setCellValueFactory(new PropertyValueFactory<Molecule, String>("description")); }
From source file:com.properned.application.ManageLocaleController.java
public void initializeList() { logger.info("Initialize locale list"); list = FXCollections.observableArrayList(multiLanguageProperties.getMapPropertiesByLocale().keySet()); SortedList<Locale> sortedList = new SortedList<>(list, new Comparator<Locale>() { @Override// w w w . j a v a2 s . c o m public int compare(Locale o1, Locale o2) { return o1.toString().compareTo(o2.toString()); } }); localeList.setItems(sortedList); localeList.setCellFactory(c -> new LocaleListCell(multiLanguageProperties, this)); list.addListener(new ListChangeListener<Locale>() { @Override public void onChanged(Change<? extends Locale> c) { if (c.next()) { if (c.wasAdded()) { List<? extends Locale> addedSubList = c.getAddedSubList(); for (Locale locale : addedSubList) { try { MultiLanguageProperties.getInstance().addLocale(locale); } catch (IOException e) { Properned.getInstance().showError( MessageReader.getInstance().getMessage("manageLocale.error.errorAddLocale"), e); } } } } } }); }
From source file:gov.va.isaac.gui.ConceptNode.java
/** * descriptionReader is optional//from www. ja va2 s.c o m */ public ConceptNode(ConceptVersionBI initialConcept, boolean flagAsInvalidWhenBlank, ObservableList<SimpleDisplayConcept> dropDownOptions, Function<ConceptVersionBI, String> descriptionReader) { c_ = initialConcept; //We can't simply use the ObservableList from the CommonlyUsedConcepts, because it infinite loops - there doesn't seem to be a way //to change the items in the drop down without changing the selection. So, we have this hack instead. listChangeListener_ = new ListChangeListener<SimpleDisplayConcept>() { @Override public void onChanged(Change<? extends SimpleDisplayConcept> c) { //TODO I still have an infinite loop here. Find and fix. logger.debug("updating concept dropdown"); disableChangeListener_ = true; SimpleDisplayConcept temp = cb_.getValue(); cb_.setItems(FXCollections.observableArrayList(dropDownOptions_)); cb_.setValue(temp); cb_.getSelectionModel().select(temp); disableChangeListener_ = false; } }; descriptionReader_ = (descriptionReader == null ? (conceptVersion) -> { return conceptVersion == null ? "" : OTFUtility.getDescription(conceptVersion); } : descriptionReader); dropDownOptions_ = dropDownOptions == null ? AppContext.getService(CommonlyUsedConcepts.class).getObservableConcepts() : dropDownOptions; dropDownOptions_.addListener(new WeakListChangeListener<SimpleDisplayConcept>(listChangeListener_)); conceptBinding_ = new ObjectBinding<ConceptVersionBI>() { @Override protected ConceptVersionBI computeValue() { return c_; } }; flagAsInvalidWhenBlank_ = flagAsInvalidWhenBlank; cb_ = new ComboBox<>(); cb_.setConverter(new StringConverter<SimpleDisplayConcept>() { @Override public String toString(SimpleDisplayConcept object) { return object == null ? "" : object.getDescription(); } @Override public SimpleDisplayConcept fromString(String string) { return new SimpleDisplayConcept(string, 0); } }); cb_.setValue(new SimpleDisplayConcept("", 0)); cb_.setEditable(true); cb_.setMaxWidth(Double.MAX_VALUE); cb_.setPrefWidth(ComboBox.USE_COMPUTED_SIZE); cb_.setMinWidth(200.0); cb_.setPromptText("Type, drop or select a concept"); cb_.setItems(FXCollections.observableArrayList(dropDownOptions_)); cb_.setVisibleRowCount(11); cm_ = new ContextMenu(); MenuItem copyText = new MenuItem("Copy Description"); copyText.setGraphic(Images.COPY.createImageView()); copyText.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { CustomClipboard.set(cb_.getEditor().getText()); } }); cm_.getItems().add(copyText); CommonMenusNIdProvider nidProvider = new CommonMenusNIdProvider() { @Override public Set<Integer> getNIds() { Set<Integer> nids = new HashSet<>(); if (c_ != null) { nids.add(c_.getNid()); } return nids; } }; CommonMenuBuilderI menuBuilder = CommonMenus.CommonMenuBuilder.newInstance(); menuBuilder.setInvisibleWhenFalse(isValid); CommonMenus.addCommonMenus(cm_, menuBuilder, nidProvider); cb_.getEditor().setContextMenu(cm_); updateGUI(); new LookAheadConceptPopup(cb_); if (cb_.getValue().getNid() == 0) { if (flagAsInvalidWhenBlank_) { isValid.setInvalid("Concept Required"); } } else { isValid.setValid(); } cb_.valueProperty().addListener(new ChangeListener<SimpleDisplayConcept>() { @Override public void changed(ObservableValue<? extends SimpleDisplayConcept> observable, SimpleDisplayConcept oldValue, SimpleDisplayConcept newValue) { if (newValue == null) { logger.debug("Combo Value Changed - null entry"); } else { logger.debug("Combo Value Changed: {} {}", newValue.getDescription(), newValue.getNid()); } if (disableChangeListener_) { logger.debug("change listener disabled"); return; } if (newValue == null) { //This can happen if someone calls clearSelection() - it passes in a null. cb_.setValue(new SimpleDisplayConcept("", 0)); return; } else { if (newValue.shouldIgnoreChange()) { logger.debug("One time change ignore"); return; } //Whenever the focus leaves the combo box editor, a new combo box is generated. But, the new box will have 0 for an id. detect and ignore if (oldValue != null && oldValue.getDescription().equals(newValue.getDescription()) && newValue.getNid() == 0) { logger.debug("Not a real change, ignore"); newValue.setNid(oldValue.getNid()); return; } lookup(); } } }); AppContext.getService(DragRegistry.class).setupDragAndDrop(cb_, new SingleConceptIdProvider() { @Override public String getConceptId() { return cb_.getValue().getNid() + ""; } }, true); pi_ = new ProgressIndicator(ProgressIndicator.INDETERMINATE_PROGRESS); pi_.visibleProperty().bind(isLookupInProgress_); pi_.setPrefHeight(16.0); pi_.setPrefWidth(16.0); pi_.setMaxWidth(16.0); pi_.setMaxHeight(16.0); lookupFailImage_ = Images.EXCLAMATION.createImageView(); lookupFailImage_.visibleProperty().bind(isValid.not().and(isLookupInProgress_.not())); Tooltip t = new Tooltip(); t.textProperty().bind(isValid.getReasonWhyInvalid()); Tooltip.install(lookupFailImage_, t); StackPane sp = new StackPane(); sp.setMaxWidth(Double.MAX_VALUE); sp.getChildren().add(cb_); sp.getChildren().add(lookupFailImage_); sp.getChildren().add(pi_); StackPane.setAlignment(cb_, Pos.CENTER_LEFT); StackPane.setAlignment(lookupFailImage_, Pos.CENTER_RIGHT); StackPane.setMargin(lookupFailImage_, new Insets(0.0, 30.0, 0.0, 0.0)); StackPane.setAlignment(pi_, Pos.CENTER_RIGHT); StackPane.setMargin(pi_, new Insets(0.0, 30.0, 0.0, 0.0)); hbox_ = new HBox(); hbox_.setSpacing(5.0); hbox_.setAlignment(Pos.CENTER_LEFT); hbox_.getChildren().add(sp); HBox.setHgrow(sp, Priority.SOMETIMES); }
From source file:com.panemu.tiwulfx.table.TableControl.java
public TableControl(Class<R> recordClass) { this.recordClass = recordClass; initControls();/*from w w w .j a va2 s . co m*/ tblView.getSortOrder().addListener(new ListChangeListener<TableColumn<R, ?>>() { @Override public void onChanged(ListChangeListener.Change<? extends TableColumn<R, ?>> change) { reload(); } }); btnAdd.disableProperty().bind(mode.isEqualTo(Mode.EDIT)); btnEdit.disableProperty().bind(mode.isNotEqualTo(Mode.READ)); btnSave.disableProperty().bind(mode.isEqualTo(Mode.READ)); btnDelete.disableProperty().bind(new BooleanBinding() { { super.bind(mode, tblView.getSelectionModel().selectedItemProperty(), lstChangedRow); } @Override protected boolean computeValue() { if ((mode.get() == Mode.INSERT && lstChangedRow.size() < 2) || tblView.getSelectionModel().selectedItemProperty().get() == null || mode.get() == Mode.EDIT) { return true; } return false; } }); tblView.editableProperty().bind(mode.isNotEqualTo(Mode.READ)); tblView.getSelectionModel().cellSelectionEnabledProperty().bind(tblView.editableProperty()); mode.addListener(new ChangeListener<Mode>() { @Override public void changed(ObservableValue<? extends Mode> ov, Mode t, Mode t1) { if (t1 == Mode.READ) { directEdit = false; } } }); tblView.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) { lblRowIndex .setText(TiwulFXUtil.getLiteral("row.param", (page * maxResult.get() + t1.intValue() + 1))); } }); tblView.getFocusModel().focusedCellProperty().addListener(new ChangeListener<TablePosition>() { @Override public void changed(ObservableValue<? extends TablePosition> observable, TablePosition oldValue, TablePosition newValue) { if (tblView.isEditable() && directEdit && agileEditing.get()) { tblView.edit(newValue.getRow(), newValue.getTableColumn()); } } }); tblView.setOnKeyPressed(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { if (event.getCode() == KeyCode.ESCAPE) { directEdit = false; } else if (event.getCode() == KeyCode.ENTER && mode.get() == Mode.READ) { getController().doubleClick(getSelectionModel().getSelectedItem()); } } }); /** * Define policy for TAB key press */ tblView.addEventFilter(KeyEvent.KEY_PRESSED, tableKeyListener); /** * In INSERT mode, only inserted row that is focusable */ tblView.getFocusModel().focusedCellProperty().addListener(tableFocusListener); tblView.setOnMouseReleased(tableRightClickListener); if (Platform.isFxApplicationThread()) { cm = new ContextMenu(); cm.setAutoHide(true); setToolTips(); /** * create custom row factory that can intercept double click on grid row */ tblView.setRowFactory(new Callback<TableView<R>, TableRow<R>>() { @Override public TableRow<R> call(TableView<R> param) { return new TableRowControl(TableControl.this); } }); } columns.addListener(new ListChangeListener<TableColumn<R, ?>>() { @Override public void onChanged(ListChangeListener.Change<? extends TableColumn<R, ?>> change) { while (change.next()) { if (change.wasAdded()) { for (TableColumn<R, ?> column : change.getAddedSubList()) { initColumn(column); } } lastColumnIndex = getLeafColumns().size() - 1; } } }); attachWindowVisibilityListener(); }
From source file:caillou.company.clonemanager.gui.customComponent.results.ResultController.java
private void handleRowColor() { resultViewId.getSortOrder().addListener(new ListChangeListener<TableColumn<GUIApplicationFile, ?>>() { @Override// w w w . jav a 2 s . co m public void onChanged(ListChangeListener.Change<? extends TableColumn<GUIApplicationFile, ?>> c) { if (resultViewId.getSortOrder().size() > 0) { TableColumn<GUIApplicationFile, ?> tableColumn = resultViewId.getSortOrder().get(0); if (tableColumn.getId() != null && tableColumn.getId().equals("md5PrintId")) { myRowFactory.setHigthLigthMode(true); } else { myRowFactory.setHigthLigthMode(false); } } } }); }