@Override public void run() { JsonElement element = parser.parse(line); DynamicModelObject object = DynamicModelUtils.getObjectByAdress( element.getAsJsonObject().get("@src").getAsString(), model); String propertyName = element.getAsJsonObject().get("@prop").getAsString(); JsonElement nv = element.getAsJsonObject().get("@nv"); JsonElement ov = element.getAsJsonObject().get("@ov"); Object value = null; boolean isList = object.getCollection().getAsListProperties().contains(propertyName); if (nv != null) { String raw = nv.getAsString(); if (OBJECT_ADDRESS_PATTERN.matcher(raw).matches()) { value = DynamicModelUtils.getObjectByAdress(nv.getAsString(), model); } else if (DOUBLE_VALUE_PATTERN.matcher(raw).matches()) { value = nv.getAsDouble(); } else if (INTEGER_VALUE_PATTERN.matcher(raw).matches()) { value = nv.getAsInt(); } else if (BOOLEAN_VALUE_PATTERN.matcher(raw).matches()) { value = nv.getAsBoolean(); } else { value = raw; } } else if (ov != null) { // is a deletion value = null; if (isList) { value = model.getObject(ov.getAsString()); } } if (!isList) { Property<Object> prop = (Property<Object>) object.getProperties().get(propertyName); if (prop != null) { if (prop.getValue() != null && (value == null || prop.getValue().getClass().isAssignableFrom(value.getClass()))) { prop.setValue(value); } else { SettlersApplication.NET.warning( "Received invalid property update - types don't match."); } } else { if (value == null) { return; } ((Property<Object>) object.getProperty(propertyName, value.getClass())).setValue(value); } } else { ListProperty<DynamicModelObject> list = (ListProperty<DynamicModelObject>) object.getProperty(propertyName, List.class); if (nv != null) { list.add((DynamicModelObject) value); } else if (ov != null) { list.remove(value); } } }
public static void print(String msg, ListProperty<String> lp1, ListProperty<String> lp2) { System.out.println(msg); System.out.println( "lp1: " + lp1.get() + ", lp2: " + lp2.get() + ", lp1.get() == lp2.get(): " + (lp1.get() == lp2.get())); System.out.println("---------------------------"); }
public static void main(String[] args) { ListProperty<String> lp1 = new SimpleListProperty<>(FXCollections.observableArrayList()); ListProperty<String> lp2 = new SimpleListProperty<>(FXCollections.observableArrayList()); lp1.bind(lp2); print("Before addAll():", lp1, lp2); lp1.addAll("One", "Two"); print("After addAll():", lp1, lp2); // Change the reference of the ObservableList in lp2 lp2.set(FXCollections.observableArrayList("1", "2")); print("After lp2.set():", lp1, lp2); // Cannot do the following as lp1 is a bound property // lp1.set(FXCollections.observableArrayList("1", "2")); // Unbind lp1 lp1.unbind(); print("After unbind():", lp1, lp2); // Bind lp1 and lp2 bidirectionally lp1.bindBidirectional(lp2); print("After bindBidirectional():", lp1, lp2); lp1.set(FXCollections.observableArrayList("X", "Y")); print("After lp1.set():", lp1, lp2); }
private RegisterStage(@NotNull final Account account) { super(StageStyle.DECORATED); accountProperty.setValue(account); final String formResource; if (account.isLocked()) { if (account.memberOf(AccountGroup.INVEST)) { formResource = "LockedInvestmentRegisterPane.fxml"; } else { formResource = "LockedBasicRegisterPane.fxml"; } } else { if (account.memberOf(AccountGroup.INVEST)) { formResource = "InvestmentRegisterPane.fxml"; } else { formResource = "BasicRegisterPane.fxml"; } } controller = FXMLUtils.loadFXML( scene -> setScene(new Scene((Parent) scene)), formResource, ResourceUtils.getBundle()); getScene().getStylesheets().addAll(MainApplication.DEFAULT_CSS); double minWidth = Double.MAX_VALUE; double minHeight = Double.MAX_VALUE; for (final Screen screen : Screen.getScreens()) { minWidth = Math.min(minWidth, screen.getVisualBounds().getWidth()); minHeight = Math.min(minHeight, screen.getVisualBounds().getHeight()); } setWidth(minWidth * SCALE_FACTOR); setHeight(minHeight * SCALE_FACTOR); // Push the account to the controller at the end of the application thread Platform.runLater(() -> controller.accountProperty().setValue(account)); updateTitle(account); StageUtils.addBoundsListener(this, account.getUuid()); registerStageListProperty.get().add(this); setOnHidden(event -> registerStageListProperty.get().remove(RegisterStage.this)); }
public Stack(final List<T> list) { if (list == null) { throw new IllegalArgumentException("Cannot create stack from list: argument is null."); } elementsProperty.set(FXCollections.observableList(list)); }
public Stack(final Stack<T> otherStack) { if (otherStack == null) { throw new IllegalArgumentException("Cannot create stack from stack: argument is null."); } elementsProperty.set(FXCollections.observableList(otherStack.toList())); }
public AgentInfo(String field, String value) { this.field = field; this.value = value; this.active = true; color = Configuration.getInstance().getColor(getName()); inventory.addListener( (Observable o) -> { if (inventory.get() != null) { filteredInventory = new FilteredList<Inventory>(inventory.get()); filteredInventory.addListener( (Observable e) -> { addToChart(this); }); filteredInventory.predicateProperty().bind(_currentNuclideFilterProperty); } }); }
public boolean validate() { long notErrors = 0; for (Validator validator : validators) { if (validator.validate()) { notErrors++; } } return notErrors == validators.size(); }
/** Sanity: quick check that using a ListProperty as source doesn't interfere. */ @Test public void testItemsIsListProperty() { ObjectProperty<ObservableList<String>> itemsProperty = new SimpleObjectProperty(items); ListProperty<String> listItems = new SimpleListProperty<>(); listItems.bind(itemsProperty); IndicesBase indicesList = new IndicesList(listItems); ListChangeReport report = new ListChangeReport(indicesList); int[] indices = new int[] {3, 5, 1}; indicesList.addIndices(indices); report.clear(); // new PrintingListChangeListener("SetAll Same size", indicesList); ObservableList<String> other = createObservableList(true); // make it not equal other.set(0, "otherItem"); items.setAll(other); assertEquals("all cleared", 0, indicesList.size()); assertEquals(1, report.getEventCount()); assertTrue( "expected single removed, but was " + report.getLastChange(), wasSingleRemoved(report.getLastChange())); }
private List<T> elements() { return elementsProperty.get(); }
public void removeListener(final ListChangeListener<T> listener) { elementsProperty.removeListener(listener); }
public void addListener(final ListChangeListener<T> listener) { elementsProperty.addListener(listener); }
public Stack() { elementsProperty.set(FXCollections.observableList(new ArrayList<>())); }
public TeamViewModel() { createValidators(); ListProperty<Person> peopleInOrganisation = new SimpleListProperty<>(); peopleInOrganisation.bind( Bindings.createObjectBinding( () -> { if (organisationProperty().get() != null) { return organisationProperty().get().getPeople(); } else { return FXCollections.observableArrayList(); } }, organisationProperty())); ListProperty<Team> teamsInOrganisation = new SimpleListProperty<>(); teamsInOrganisation.bind( Bindings.createObjectBinding( () -> { if (organisationProperty().get() != null) { return organisationProperty().get().getTeams(); } else { return FXCollections.observableArrayList(); } }, organisationProperty())); ListProperty<Person> peopleInTeams = new SimpleListProperty<>(); peopleInTeams.bind( Bindings.createObjectBinding( () -> { return teamsInOrganisation .stream() .flatMap(team -> team.observableTeamMembers().stream()) // TODO listen .collect(GoatCollectors.toObservableList()); }, teamsInOrganisation)); eligibleTeamMembers = new SimpleListProperty<>(); eligibleTeamMembers.bind( Bindings.createObjectBinding( () -> { return peopleInOrganisation .stream() .filter( person -> !peopleInTeams.contains(person) // no team in model || person.getTeam() == modelWrapper.get()) // this team in model .collect(GoatCollectors.toObservableList()); }, peopleInOrganisation, peopleInTeams)); eligibleDevs = new SimpleListProperty<>(); eligibleDevs.bind( Bindings.createObjectBinding( () -> { return teamMembersProperty() .get() .stream() // is in team .filter( person -> !person.equals(productOwnerProperty().get()) // not PO && !person.equals(scrumMasterProperty().get())) // not SM .collect(GoatCollectors.toObservableList()); }, teamMembersProperty(), productOwnerProperty(), scrumMasterProperty())); teamMembersProperty() .addListener( (ListChangeListener.Change<? extends Person> change) -> { change.next(); List<? extends Person> removed = change.getRemoved(); devTeamProperty().removeAll(removed); if (removed.contains(productOwnerProperty().get())) { productOwnerProperty().set(null); } if (removed.contains(scrumMasterProperty().get())) { scrumMasterProperty().set(null); } }); }
public boolean addValidator(Validator validator) { return validators.add(validator); }