/** * Returns the default value for the package name * * @param injector the injector, in case an implementing class needs it * @return the default package name */ default ObservableStringValue defaultPackageNameProperty(Injector injector) { final TranslatorSupport<?> support = new TranslatorSupport<>(injector, this); if (this instanceof ProjectProperty) { final ProjectProperty project = (ProjectProperty) this; return createStringBinding( support::defaultPackageName, project.nameProperty(), project.companyNameProperty() ); } else if (this instanceof HasAliasProperty) { final HasAliasProperty alias = (HasAliasProperty) this; return createStringBinding(support::defaultPackageName, alias.aliasProperty()); } else { return createStringBinding(support::defaultPackageName, nameProperty()); } }
private void updateInfoPane(Theme selectedTheme) { view.themeNameLabel.textProperty().bind(selectedTheme.getLocalizedName()); view.themeDescriptionLabel.textProperty().bind(selectedTheme.getDescription()); view.themeAuthorsLabel.textProperty().bind(new StringBinding() { ObservableValue<ObservableStringValue[]> authorsBinding = selectedTheme.getAuthors(); { bind(authorsBinding); } @Override protected String computeValue() { return Stream .of(authorsBinding.getValue()) .map(ObservableStringValue::get) .collect(joining(", ")); } }); }
@Override default ObservableStringValue getLocalizedName() { return new StringBinding() { StringProperty aliasProperty = aliasProperty(); { bind(aliasProperty); } @Override protected String computeValue() { String alias = aliasProperty.get(); if (alias == null) { return getVersionNumber(); } return alias; } }; }
/** * Returns a new observable string which contains either the contents of ifTrue, or ifFalse, depending on the condition * @param condition * @param ifTrue * @param ifFalse * @return */ public static ObservableStringValue decision(ObservableBooleanValue condition, ObservableStringValue ifTrue, ObservableStringValue ifFalse) { StringProperty ret = new SimpleStringProperty(); condition.addListener((obs, ov, nv) -> { ret.set(nv ? ifTrue.get() : ifFalse.get()); }); ifTrue.addListener((obs, ov, nv) -> { if (condition.get()) { ret.set(nv); } }); ifFalse.addListener((obs, ov, nv) -> { if (!condition.get()) { ret.set(nv); } }); ret.set(condition.get() ? ifTrue.get() : ifFalse.get()); return ret; }
@Test public void testObservableStringValue(){ ObservableStringValue actual = new SimpleStringProperty("test"); assertThat(actual).hasValue("test"); assertThat(actual).hasSameValue(actual); }
@Test public void should_fail_if_expected_value_is_null(){ try{ ObservableStringValue actual = new SimpleStringProperty("test123"); new ObservableStringValueAssertions(actual).contains(null); fail("Should throw an AssertionError"); }catch(AssertionError error){ assertThat(error).hasMessageContaining("expected value may not be null"); } }
@Override public ObservableStringValue getLocalizedName() { if (isCurrentMcdir()) { return I18N.localize("org.to2mbn.lolixl.mcdir.default.name"); } return FxConstants.string(location.toString()); }
private void bindManagementTile() { Tile tile = new ItemTile(new DisplayableItem() { @Override public ObservableStringValue getLocalizedName() { return FxConstants.string("..."); } }); Panel panel = panelDisplayService.newPanel(); panel.bindButton(tile); panel.bindItem(this); panel.contentProperty().set(view.rootContainer); homeContentPresenter.setManagementTile(tile); }
public ObservableStringValue getProperty(final String columnName) { return Bindings.createStringBinding(() -> { String value = metadataMap.get(columnName); if (value == null) return ""; return value; }); }
private static void setTextFieldBehaviour(TextInputControl text, boolean useDefaultValue, ObservableStringValue defaultValue, StringProperty customValue) { if (useDefaultValue) { customValue.unbind(); text.textProperty().bind(defaultValue); } else { text.textProperty().unbind(); text.setText(customValue.get()); customValue.bind(text.textProperty()); } }
/** * @deprecated Use {@link #setupErrorMarker(Control, StackPane, ValidBooleanBinding)} instead */ public static Node setupErrorMarker(Control initialControl, StackPane stackPane, ObservableStringValue reasonWhyControlInvalid) { ValidBooleanBinding binding = new ValidBooleanBinding() { { bind(reasonWhyControlInvalid); } @Override protected boolean computeValue() { if (StringUtils.isNotBlank(reasonWhyControlInvalid.get())) { setInvalidReason(reasonWhyControlInvalid.get()); return false; } else { clearInvalidReason(); return true; } } }; return setupErrorMarker(initialControl, stackPane, binding); }
@Test public void should_fail_if_expected_value_is_null(){ try{ ObservableStringValue actual = new SimpleStringProperty("test"); new ObservableStringValueAssertions(actual).hasValue(null); fail("Should throw an AssertionError"); }catch(AssertionError error){ assertThat(error).hasMessageContaining("expected value may not be null"); } }
@Test public void should_fail_if_actual_has_wrong_value(){ try{ ObservableStringValue actual = new SimpleStringProperty("test"); new ObservableStringValueAssertions(actual).hasValue("testest"); fail("Should throw an AssertionError"); }catch(AssertionError error){ assertThat(error).hasMessageContaining("<testest> but was <test>"); } }
@Test public void should_fail_if_actual_has_value_of_null(){ try{ ObservableStringValue actual = new SimpleStringProperty(); new ObservableStringValueAssertions(actual).hasValue("test"); fail("Should throw an AssertionError"); }catch(AssertionError error){ assertThat(error).hasMessageContaining("<test> but was <null>"); } }
@Test public void should_fail_if_actual_does_not_contain_expected_text(){ try{ ObservableStringValue actual = new SimpleStringProperty("test123"); new ObservableStringValueAssertions(actual).contains("st21"); fail("Should throw an AssertionError"); }catch(AssertionError error){ assertThat(error); } }
/** * @deprecated Use {@link Val#suspendable(javafx.beans.value.ObservableValue)}. */ @Deprecated public static StringBinding wrap(ObservableStringValue source) { return new StringBinding() { { bind(source); } @Override protected String computeValue() { return source.get(); } }; }
public StringBinding selectString(Function<S, ? extends ObservableStringValue> childPropertyAccessor) { return selectString(childPropertyAccessor, ""); }
public StringBinding selectString(Function<S, ? extends ObservableStringValue> childPropertyAccessor, String defaultValue) { return new StringBindingAdapter(new ChainBinding<>(rootProperty, childPropertyAccessor), defaultValue); }
public static ObservableStringValue localize(String key, Object... arguments) { return new LocalizedStringValue(getLocalizationService(), key, arguments); }
public static ObservableStringValue string(String constant) { return new StringConstant(constant); }
default ObservableValue<ObservableStringValue[]> getAuthors() { return null; }
default ObservableStringValue getDescription() { return null; }
@Override public ObservableStringValue getLocalizedName() { return I18N.localize("org.to2mbn.lolixl.ui.impl.tiles.management.title"); }
@Override public ObservableStringValue getLocalizedName() { return I18N.localize("org.to2mbn.lolixl.ui.download_center.title"); }
@Override public ObservableStringValue getLocalizedName() { return I18N.localize("org.to2mbn.lolixl.ui.impl.settings.title"); }
@Override public ObservableStringValue getLocalizedName() { return I18N.localize("org.to2mbn.lolixl.ui.theme.background.default.name"); }
@Override public ObservableStringValue getLocalizedName() { return I18N.localize("org.to2mbn.lolixl.ui.theme.default.name"); }
@Override public ObservableValue<ObservableStringValue[]> getAuthors() { return FxConstants.object(new ObservableStringValue[] { I18N.localize("org.to2mbn.lolixl.ui.theme.default.author.lolixlgroup") }); }
@Override public ObservableStringValue getDescription() { return I18N.localize("org.to2mbn.lolixl.ui.theme.default.description"); }
public VersionTag(String id, int ranking, List<String> cssClasses, ObservableStringValue displayName) { this.id = Objects.requireNonNull(id); this.ranking = ranking; this.cssClasses = Objects.requireNonNull(cssClasses); this.displayName = Objects.requireNonNull(displayName); }
public ObservableStringValue getDisplayName() { return displayName; }
default ObservableStringValue getEmail() { return null; }
@Override default ObservableStringValue getLocalizedName() { return getUsername(); }
@Override public ObservableStringValue getLocalizedName() { return I18N.localize("org.to2mbn.lolixl.auth.offline.name"); }
@Override public ObservableStringValue getUsername() { return username; }
@Override public ObservableStringValue getUsername() { return usernameView; }
@Override public ObservableStringValue getEmail() { return emailProperty; }
public ObservableStringValue getNameBinding() { return Bindings.createStringBinding(() -> entry.getImageName()); }
public ObservableStringValue speedLabel() { return speedLabel; }
/** * @deprecated Use {@link #setupErrorMarker(Control, StackPane, ValidBooleanBinding)} instead */ public static Node setupErrorMarker(Control initialControl, ObservableStringValue reasonWhyControlInvalid) { return setupErrorMarker(initialControl, new StackPane(), reasonWhyControlInvalid); }