/** @return a two-way property of whether {@code items} are a subset of this list. */ public BooleanProperty containsAll(final List<E> items) { final BooleanProperty b = booleanProperty(getName() + "ContainsAll", false); final boolean[] firing = {false}; // conditionally update us when b goes true->false/false->true b.addPropertyChangedHandler( new PropertyChangedHandler<Boolean>() { public void onPropertyChanged(final PropertyChangedEvent<Boolean> event) { if (!firing[0]) { firing[0] = true; if (event.getNewValue()) { for (final E item : items) { if (!get().contains(item)) { add(item); } } } else { removeAll(items); } firing[0] = false; } } }); // conditionally update b when we change addPropertyChangedHandler( new PropertyChangedHandler<List<E>>() { public void onPropertyChanged(final PropertyChangedEvent<List<E>> event) { if (!firing[0]) { firing[0] = true; b.set(get().containsAll(items)); firing[0] = false; } } }); return b; }
/** Tests that trigger is called after the value is changed */ public void testValueChange() { final MyProperties props = new MyProperties(); String path = "test.mondrian.properties.change.value"; BooleanProperty boolProp = new BooleanProperty(props, path, false); assertTrue("Check property value NOT false", !boolProp.get()); // set via the 'set' method final boolean prevBoolean = boolProp.set(true); assertEquals(false, prevBoolean); // now explicitly set the property final Object prevObject = props.setProperty(path, "false"); assertEquals("true", prevObject); String v = props.getProperty(path); assertTrue("Check property value is null", v != null); assertTrue("Check property value is true", (!Boolean.valueOf(v).booleanValue())); final State state = new State(); state.triggerCalled = false; state.triggerValue = null; final Trigger trigger = new Trigger() { public boolean isPersistent() { return false; } public int phase() { return Trigger.PRIMARY_PHASE; } public void execute(Property property, String value) { state.triggerCalled = true; state.triggerValue = value; } }; boolProp.addTrigger(trigger); String falseStr = "false"; props.setProperty(path, falseStr); assertTrue("Check trigger was called", !state.triggerCalled); String trueStr = "true"; props.setProperty(path, trueStr); assertTrue("Check trigger was NOT called", state.triggerCalled); assertTrue("Check trigger value was null", (state.triggerValue != null)); assertTrue("Check trigger value is NOT correct", state.triggerValue.equals(trueStr)); }
/** * Return the default value of the property * * @param p Swagger property object * @return string presentation of the default value of the property */ @Override public String toDefaultValue(Property p) { if (p instanceof StringProperty) { StringProperty dp = (StringProperty) p; if (dp.getDefault() != null) { return "'" + dp.getDefault().toString() + "'"; } } else if (p instanceof BooleanProperty) { BooleanProperty dp = (BooleanProperty) p; if (dp.getDefault() != null) { if (dp.getDefault().toString().equalsIgnoreCase("false")) return "False"; else return "True"; } } else if (p instanceof DateProperty) { // TODO } else if (p instanceof DateTimeProperty) { // TODO } else if (p instanceof DoubleProperty) { DoubleProperty dp = (DoubleProperty) p; if (dp.getDefault() != null) { return dp.getDefault().toString(); } } else if (p instanceof FloatProperty) { FloatProperty dp = (FloatProperty) p; if (dp.getDefault() != null) { return dp.getDefault().toString(); } } else if (p instanceof IntegerProperty) { IntegerProperty dp = (IntegerProperty) p; if (dp.getDefault() != null) { return dp.getDefault().toString(); } } else if (p instanceof LongProperty) { LongProperty dp = (LongProperty) p; if (dp.getDefault() != null) { return dp.getDefault().toString(); } } return null; }
@Override public String toDefaultValue(Property p) { if (p instanceof IntegerProperty) { IntegerProperty dp = (IntegerProperty) p; if (dp.getDefault() != null) { return dp.getDefault().toString(); } } else if (p instanceof LongProperty) { LongProperty dp = (LongProperty) p; if (dp.getDefault() != null) { return dp.getDefault().toString(); } } else if (p instanceof DoubleProperty) { DoubleProperty dp = (DoubleProperty) p; if (dp.getDefault() != null) { return dp.getDefault().toString(); } } else if (p instanceof FloatProperty) { FloatProperty dp = (FloatProperty) p; if (dp.getDefault() != null) { return dp.getDefault().toString(); } } else if (p instanceof BooleanProperty) { BooleanProperty bp = (BooleanProperty) p; if (bp.getDefault() != null) { return bp.getDefault().toString(); } } else if (p instanceof StringProperty) { StringProperty sp = (StringProperty) p; if (sp.getDefault() != null) { return "\"" + escapeText(sp.getDefault()) + "\""; } } return null; }
public boolean isUseThemeManager() { return useThemeManager.getValue(); }
public boolean isAlwaysUseParentTheme() { return alwaysUseParentTheme.getValue(); }
public boolean isDebugMode() { return debugMode.getValue(); }
public boolean isDisableOverscrollEffects() { return disableOverscrollEffects.getValue(); }
public boolean isDisableContextMenu() { return disableContextMenu.getValue(); }
public boolean getStringedNamePreferences() { return stringedNamePreferences.getValue(); }
@Override public String toDefaultValue(Property p) { if (p instanceof ArrayProperty) { final ArrayProperty ap = (ArrayProperty) p; final String pattern; if (fullJavaUtil) { pattern = "new java.util.ArrayList<%s>()"; } else { pattern = "new ArrayList<%s>()"; } return String.format(pattern, getTypeDeclaration(ap.getItems())); } else if (p instanceof MapProperty) { final MapProperty ap = (MapProperty) p; final String pattern; if (fullJavaUtil) { pattern = "new java.util.HashMap<String, %s>()"; } else { pattern = "new HashMap<String, %s>()"; } return String.format(pattern, getTypeDeclaration(ap.getAdditionalProperties())); } else if (p instanceof IntegerProperty) { IntegerProperty dp = (IntegerProperty) p; if (dp.getDefault() != null) { return dp.getDefault().toString(); } return "null"; } else if (p instanceof LongProperty) { LongProperty dp = (LongProperty) p; if (dp.getDefault() != null) { return dp.getDefault().toString() + "l"; } return "null"; } else if (p instanceof DoubleProperty) { DoubleProperty dp = (DoubleProperty) p; if (dp.getDefault() != null) { return dp.getDefault().toString() + "d"; } return "null"; } else if (p instanceof FloatProperty) { FloatProperty dp = (FloatProperty) p; if (dp.getDefault() != null) { return dp.getDefault().toString() + "f"; } return "null"; } else if (p instanceof BooleanProperty) { BooleanProperty bp = (BooleanProperty) p; if (bp.getDefault() != null) { return bp.getDefault().toString(); } return "null"; } else if (p instanceof StringProperty) { StringProperty sp = (StringProperty) p; if (sp.getDefault() != null) { String _default = sp.getDefault(); if (sp.getEnum() == null) { return "\"" + escapeText(_default) + "\""; } else { // convert to enum var name later in postProcessModels return _default; } } return "null"; } return super.toDefaultValue(p); }
/** Checks that triggers are called in the correct order. */ public void testTriggerCallOrder() { final MyProperties props = new MyProperties(); String path = "test.mondrian.properties.call.order"; BooleanProperty boolProp = new BooleanProperty(props, path, false); final State2 state = new State2(); state.callCounter = 0; // now explicitly set the property props.setProperty(path, "false"); String v = props.getProperty(path); assertTrue("Check property value is null", (v != null)); assertTrue("Check property value is true", (!Boolean.valueOf(v).booleanValue())); // primaryOne Trigger primaryOneTrigger = new Trigger() { public boolean isPersistent() { return false; } public int phase() { return Trigger.PRIMARY_PHASE; } public void execute(Property property, String value) { state.primaryOne = state.callCounter++; } }; boolProp.addTrigger(primaryOneTrigger); // secondaryOne Trigger secondaryOneTrigger = new Trigger() { public boolean isPersistent() { return false; } public int phase() { return Trigger.SECONDARY_PHASE; } public void execute(Property property, String value) { state.secondaryOne = state.callCounter++; } }; boolProp.addTrigger(secondaryOneTrigger); // tertiaryOne Trigger tertiaryOneTrigger = new Trigger() { public boolean isPersistent() { return false; } public int phase() { return Trigger.TERTIARY_PHASE; } public void execute(Property property, String value) { state.tertiaryOne = state.callCounter++; } }; boolProp.addTrigger(tertiaryOneTrigger); // tertiaryTwo Trigger tertiaryTwoTrigger = new Trigger() { public boolean isPersistent() { return false; } public int phase() { return Trigger.TERTIARY_PHASE; } public void execute(Property property, String value) { state.tertiaryTwo = state.callCounter++; } }; boolProp.addTrigger(tertiaryTwoTrigger); // secondaryTwo Trigger secondaryTwoTrigger = new Trigger() { public boolean isPersistent() { return false; } public int phase() { return Trigger.SECONDARY_PHASE; } public void execute(Property property, String value) { state.secondaryTwo = state.callCounter++; } }; boolProp.addTrigger(secondaryTwoTrigger); // primaryTwo Trigger primaryTwoTrigger = new Trigger() { public boolean isPersistent() { return false; } public int phase() { return Trigger.PRIMARY_PHASE; } public void execute(Property property, String value) { state.primaryTwo = state.callCounter++; } }; boolProp.addTrigger(primaryTwoTrigger); String falseStr = "false"; props.setProperty(path, falseStr); assertTrue("Check trigger was called", (state.callCounter == 0)); String trueStr = "true"; props.setProperty(path, trueStr); assertTrue("Check trigger was NOT called", (state.callCounter != 0)); assertTrue("Check triggers was NOT called correct number of times", (state.callCounter == 6)); // now make sure that primary are called before secondary which are // before tertiary assertTrue("Check primaryOne > secondaryOne", (state.primaryOne < state.secondaryOne)); assertTrue("Check primaryOne > secondaryTwo", (state.primaryOne < state.secondaryTwo)); assertTrue("Check primaryOne > tertiaryOne", (state.primaryOne < state.tertiaryOne)); assertTrue("Check primaryOne > tertiaryTwo", (state.primaryOne < state.tertiaryTwo)); assertTrue("Check primaryTwo > secondaryOne", (state.primaryTwo < state.secondaryOne)); assertTrue("Check primaryTwo > secondaryTwo", (state.primaryTwo < state.secondaryTwo)); assertTrue("Check primaryTwo > tertiaryOne", (state.primaryTwo < state.tertiaryOne)); assertTrue("Check primaryTwo > tertiaryTwo", (state.primaryTwo < state.tertiaryTwo)); assertTrue("Check secondaryOne > tertiaryOne", (state.secondaryOne < state.tertiaryOne)); assertTrue("Check secondaryOne > tertiaryTwo", (state.secondaryOne < state.tertiaryTwo)); assertTrue("Check secondaryTwo > tertiaryOne", (state.secondaryTwo < state.tertiaryOne)); assertTrue("Check secondaryTwo > tertiaryTwo", (state.secondaryTwo < state.tertiaryTwo)); // remove some of the triggers boolProp.removeTrigger(primaryTwoTrigger); boolProp.removeTrigger(secondaryTwoTrigger); boolProp.removeTrigger(tertiaryTwoTrigger); // reset state.callCounter = 0; state.primaryOne = 0; state.primaryTwo = 0; state.secondaryOne = 0; state.secondaryTwo = 0; state.tertiaryOne = 0; state.tertiaryTwo = 0; props.setProperty(path, falseStr); assertTrue("Check trigger was NOT called", (state.callCounter != 0)); assertTrue("Check triggers was NOT called correct number of times", (state.callCounter == 3)); // now make sure that primary are called before secondary which are // before tertiary assertTrue("Check primaryOne > secondaryOne", (state.primaryOne < state.secondaryOne)); assertTrue("Check primaryOne > tertiaryOne", (state.primaryOne < state.tertiaryOne)); assertTrue("Check secondaryOne > tertiaryOne", (state.secondaryOne < state.tertiaryOne)); }