]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/modifiers/AbstractEnumerationModifier.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.common / src / org / simantics / browsing / ui / common / modifiers / AbstractEnumerationModifier.java
index d42d09bc2a4150b9b1ceaab33293333bf7c62dd2..7ea741b637b45cb2904379634fb0233c298f0cf5 100644 (file)
@@ -1,85 +1,85 @@
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 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.common.modifiers;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.simantics.browsing.ui.content.Labeler.EnumerationModifier;\r
-\r
-/**\r
- * A trivial EnumerationModifier base implementation\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public abstract class AbstractEnumerationModifier<T> implements EnumerationModifier {\r
-\r
-    private final Enumeration<T>     enumeration;\r
-    private final EnumeratedValue<T> value;\r
-    private final List<String>       values;\r
-\r
-    public AbstractEnumerationModifier(Enumeration<T> enumeration, EnumeratedValue<T> value) {\r
-        assert enumeration != null;\r
-        assert enumeration.size() > 0;\r
-\r
-        this.enumeration = enumeration;\r
-        this.value = value;\r
-\r
-        this.values = new ArrayList<String>(enumeration.size());\r
-        for (EnumeratedValue<T> v : enumeration.values())\r
-            values.add(v.getName());\r
-    }\r
-\r
-    @Override\r
-    public final List<String> getValues() {\r
-        return values;\r
-    }\r
-\r
-    @Override\r
-    public final String getValue() {\r
-        if (value != null)\r
-            return value.getName();\r
-        return enumeration.values().get(0).getName();\r
-    }\r
-\r
-    @Override\r
-    public final String isValid(String label) {\r
-        if (!values.contains(label))\r
-            return "Value '" + label + "' is not among the enumerated values " + values;\r
-        return null;\r
-    }\r
-\r
-    @Override\r
-    public final void modify(String label) {\r
-        int index = values.indexOf(label);\r
-        if (index == -1)\r
-            throw new IllegalArgumentException("Cannot modify enumeration with value '" + label + "', not among the enumerated values " + values);\r
-        modifyWithValue(value, enumeration.values().get(index));\r
-    }\r
-\r
-    protected void modifyWithValue(EnumeratedValue<T> oldEnumValue, EnumeratedValue<T> enumValue) {\r
-        T oldObject = oldEnumValue != null ? oldEnumValue.getObject() : null;\r
-        T newObject = enumValue != null ? enumValue.getObject() : null;\r
-        modifyWithObject(oldObject, newObject);\r
-    }\r
-\r
-    /**\r
-     * At least implement this if you don't override\r
-     * {@link #modifyWithValue(EnumeratedValue, EnumeratedValue)}.\r
-     * \r
-     * @param oldEnumObject\r
-     * @param enumObject\r
-     */\r
-    protected void modifyWithObject(T oldEnumObject, T enumObject) {\r
-    }\r
-\r
-};\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 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.common.modifiers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.simantics.browsing.ui.content.Labeler.EnumerationModifier;
+
+/**
+ * A trivial EnumerationModifier base implementation
+ * 
+ * @author Tuukka Lehtonen
+ */
+public abstract class AbstractEnumerationModifier<T> implements EnumerationModifier {
+
+    private final Enumeration<T>     enumeration;
+    private final EnumeratedValue<T> value;
+    private final List<String>       values;
+
+    public AbstractEnumerationModifier(Enumeration<T> enumeration, EnumeratedValue<T> value) {
+        assert enumeration != null;
+        assert enumeration.size() > 0;
+
+        this.enumeration = enumeration;
+        this.value = value;
+
+        this.values = new ArrayList<String>(enumeration.size());
+        for (EnumeratedValue<T> v : enumeration.values())
+            values.add(v.getName());
+    }
+
+    @Override
+    public final List<String> getValues() {
+        return values;
+    }
+
+    @Override
+    public final String getValue() {
+        if (value != null)
+            return value.getName();
+        return enumeration.values().get(0).getName();
+    }
+
+    @Override
+    public final String isValid(String label) {
+        if (!values.contains(label))
+            return "Value '" + label + "' is not among the enumerated values " + values;
+        return null;
+    }
+
+    @Override
+    public final void modify(String label) {
+        int index = values.indexOf(label);
+        if (index == -1)
+            throw new IllegalArgumentException("Cannot modify enumeration with value '" + label + "', not among the enumerated values " + values);
+        modifyWithValue(value, enumeration.values().get(index));
+    }
+
+    protected void modifyWithValue(EnumeratedValue<T> oldEnumValue, EnumeratedValue<T> enumValue) {
+        T oldObject = oldEnumValue != null ? oldEnumValue.getObject() : null;
+        T newObject = enumValue != null ? enumValue.getObject() : null;
+        modifyWithObject(oldObject, newObject);
+    }
+
+    /**
+     * At least implement this if you don't override
+     * {@link #modifyWithValue(EnumeratedValue, EnumeratedValue)}.
+     * 
+     * @param oldEnumObject
+     * @param enumObject
+     */
+    protected void modifyWithObject(T oldEnumObject, T enumObject) {
+    }
+
+};