-/*******************************************************************************\r
- * Copyright (c) 2007, 2012 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.browsing.ui.swt;\r
-\r
-import java.util.Map;\r
-import java.util.Set;\r
-import java.util.TreeMap;\r
-import java.util.TreeSet;\r
-\r
-import org.simantics.browsing.ui.BuiltinKeys;\r
-import org.simantics.browsing.ui.NodeContext;\r
-import org.simantics.browsing.ui.NodeContext.PrimitiveQueryKey;\r
-import org.simantics.browsing.ui.PrimitiveQueryUpdater;\r
-import org.simantics.browsing.ui.common.property.IProperty;\r
-import org.simantics.browsing.ui.common.property.PropertyComparable;\r
-import org.simantics.browsing.ui.common.property.PropertyComparator;\r
-import org.simantics.utils.strings.EString;\r
-import org.simantics.utils.ui.AdaptionUtils;\r
-\r
-/**\r
- * A custom processor implementation for the {@link BuiltinKeys#IS_EXPANDED}\r
- * primitive query that specially handles all {@link NodeContext}s that contain\r
- * {@link PropertyComparable} inputs.\r
- * \r
- * <p>\r
- * This class is needed because default values for properties are generally\r
- * asserted and adding instance properties for subjects with default values\r
- * causes the data contained by IProperty instances to change. For this reason\r
- * {@link PropertyComparable} contains two methods:\r
- * {@link IProperty#propertyHashCode()} and\r
- * {@link PropertyComparable#propertyEquals(Object)} for comparing whether\r
- * two {@link PropertyComparable} instances represent the same property of the\r
- * same subject, regardless of the property value. This allows the UI to\r
- * correctly expand tree nodes for record-type and array-valued properties when\r
- * the value changes from asserted to direct or vice versa.\r
- * \r
- * @author Tuukka Lehtonen\r
- * \r
- * @see BuiltinKeys#IS_EXPANDED\r
- * @see IProperty\r
- * @see PropertyComparator\r
- */\r
-public class PropertyIsExpandedProcessor extends DefaultIsExpandedProcessor {\r
-\r
- private static final boolean DEBUG = false;\r
-\r
- private final Set<PropertyComparable> expandedProperties = new TreeSet<PropertyComparable>(PropertyComparator.INSTANCE);\r
- private final Map<PropertyComparable, PrimitiveQueryUpdater> expandedPropertyQueries = new TreeMap<PropertyComparable, PrimitiveQueryUpdater>(PropertyComparator.INSTANCE);\r
-\r
- @Override\r
- public String toString() {\r
- return "PropertyIsExpandedProcessor";\r
- }\r
-\r
- private PropertyComparable getProperty(NodeContext context) {\r
- return AdaptionUtils.adaptToSingle(context, PropertyComparable.class);\r
- }\r
-\r
- @Override\r
- public boolean setExpanded(NodeContext context, boolean expanded) {\r
- PropertyComparable prop = getProperty(context);\r
- if (prop != null)\r
- return _setExpanded(prop, expanded);\r
- return super.setExpanded(context, expanded);\r
- }\r
-\r
- private boolean _setExpanded(PropertyComparable prop, boolean expanded) {\r
- if (expanded) {\r
- return expandedProperties.add(prop);\r
- } else {\r
- return expandedProperties.remove(prop);\r
- }\r
- }\r
-\r
- @Override\r
- public Boolean query(PrimitiveQueryUpdater updater, NodeContext context, PrimitiveQueryKey<Boolean> key) {\r
- if (DEBUG)\r
- System.out.println("QUERY(" + context + ")");\r
-\r
- PropertyComparable prop = getProperty(context);\r
- if (prop != null) {\r
- if (DEBUG)\r
- System.out.println("expanded properties:\n" + EString.implode(expandedProperties, "\n\t"));\r
-\r
- boolean isExpanded = expandedProperties.contains(prop);\r
-\r
- if (DEBUG)\r
- System.out.println("property.isExpanded(" + updater + ", " + prop + "): " + isExpanded);\r
-\r
- expandedPropertyQueries.put(prop, updater);\r
- return Boolean.valueOf(isExpanded);\r
- }\r
-\r
- return super.query(updater, context, key);\r
- }\r
-\r
- @Override\r
- protected boolean nodeStatusChanged(NodeContext context, boolean expanded) {\r
- boolean result = false;\r
- PropertyComparable prop = getProperty(context);\r
- if (prop != null) {\r
- if (DEBUG)\r
- System.out.println("nodeStatusChanged(" + prop + ", " + expanded + ")");\r
-\r
- result = _setExpanded(prop, expanded);\r
- PrimitiveQueryUpdater updater = expandedPropertyQueries.get(prop);\r
- if (updater != null)\r
- updater.scheduleReplace(context, BuiltinKeys.IS_EXPANDED, expanded);\r
- } else {\r
- result = super.nodeStatusChanged(context, expanded);\r
- }\r
- return result;\r
- }\r
-\r
- @Override\r
- public void clear() {\r
- expandedProperties.clear();\r
- expandedPropertyQueries.clear();\r
- super.clear();\r
- }\r
-\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.browsing.ui.swt;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.simantics.browsing.ui.BuiltinKeys;
+import org.simantics.browsing.ui.NodeContext;
+import org.simantics.browsing.ui.NodeContext.PrimitiveQueryKey;
+import org.simantics.browsing.ui.PrimitiveQueryUpdater;
+import org.simantics.browsing.ui.common.property.IProperty;
+import org.simantics.browsing.ui.common.property.PropertyComparable;
+import org.simantics.browsing.ui.common.property.PropertyComparator;
+import org.simantics.utils.strings.EString;
+import org.simantics.utils.ui.AdaptionUtils;
+
+/**
+ * A custom processor implementation for the {@link BuiltinKeys#IS_EXPANDED}
+ * primitive query that specially handles all {@link NodeContext}s that contain
+ * {@link PropertyComparable} inputs.
+ *
+ * <p>
+ * This class is needed because default values for properties are generally
+ * asserted and adding instance properties for subjects with default values
+ * causes the data contained by IProperty instances to change. For this reason
+ * {@link PropertyComparable} contains two methods:
+ * {@link IProperty#propertyHashCode()} and
+ * {@link PropertyComparable#propertyEquals(Object)} for comparing whether
+ * two {@link PropertyComparable} instances represent the same property of the
+ * same subject, regardless of the property value. This allows the UI to
+ * correctly expand tree nodes for record-type and array-valued properties when
+ * the value changes from asserted to direct or vice versa.
+ *
+ * @author Tuukka Lehtonen
+ *
+ * @see BuiltinKeys#IS_EXPANDED
+ * @see IProperty
+ * @see PropertyComparator
+ */
+public class PropertyIsExpandedProcessor extends DefaultIsExpandedProcessor {
+
+ private static final boolean DEBUG = false;
+
+ private final Set<PropertyComparable> expandedProperties = new TreeSet<PropertyComparable>(PropertyComparator.INSTANCE);
+ private final Map<PropertyComparable, PrimitiveQueryUpdater> expandedPropertyQueries = new TreeMap<PropertyComparable, PrimitiveQueryUpdater>(PropertyComparator.INSTANCE);
+
+ @Override
+ public String toString() {
+ return "PropertyIsExpandedProcessor";
+ }
+
+ private PropertyComparable getProperty(NodeContext context) {
+ return AdaptionUtils.adaptToSingle(context, PropertyComparable.class);
+ }
+
+ @Override
+ public boolean setExpanded(NodeContext context, boolean expanded) {
+ PropertyComparable prop = getProperty(context);
+ if (prop != null)
+ return _setExpanded(prop, expanded);
+ return super.setExpanded(context, expanded);
+ }
+
+ private boolean _setExpanded(PropertyComparable prop, boolean expanded) {
+ if (expanded) {
+ return expandedProperties.add(prop);
+ } else {
+ return expandedProperties.remove(prop);
+ }
+ }
+
+ @Override
+ public Boolean query(PrimitiveQueryUpdater updater, NodeContext context, PrimitiveQueryKey<Boolean> key) {
+ if (DEBUG)
+ System.out.println("QUERY(" + context + ")");
+
+ PropertyComparable prop = getProperty(context);
+ if (prop != null) {
+ if (DEBUG)
+ System.out.println("expanded properties:\n" + EString.implode(expandedProperties, "\n\t"));
+
+ boolean isExpanded = expandedProperties.contains(prop);
+
+ if (DEBUG)
+ System.out.println("property.isExpanded(" + updater + ", " + prop + "): " + isExpanded);
+
+ expandedPropertyQueries.put(prop, updater);
+ return Boolean.valueOf(isExpanded);
+ }
+
+ return super.query(updater, context, key);
+ }
+
+ @Override
+ protected boolean nodeStatusChanged(NodeContext context, boolean expanded) {
+ boolean result = false;
+ PropertyComparable prop = getProperty(context);
+ if (prop != null) {
+ if (DEBUG)
+ System.out.println("nodeStatusChanged(" + prop + ", " + expanded + ")");
+
+ result = _setExpanded(prop, expanded);
+ PrimitiveQueryUpdater updater = expandedPropertyQueries.get(prop);
+ if (updater != null)
+ updater.scheduleReplace(context, BuiltinKeys.IS_EXPANDED, expanded);
+ } else {
+ result = super.nodeStatusChanged(context, expanded);
+ }
+ return result;
+ }
+
+ @Override
+ public void clear() {
+ expandedProperties.clear();
+ expandedPropertyQueries.clear();
+ super.clear();
+ }
+
}
\ No newline at end of file