]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/EnumerationVariableModifier.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph.impl / src / org / simantics / browsing / ui / graph / impl / EnumerationVariableModifier.java
index 42fa4045d4a2c77de0e33389898930da202b906d..b551adae60a163969ba1ea2b356deefa3fb71be4 100644 (file)
-/*******************************************************************************\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.graph.impl;\r
-\r
-import java.util.List;\r
-\r
-import org.simantics.browsing.ui.content.Labeler.EnumerationModifier;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.RequestProcessor;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.UndoContext;\r
-import org.simantics.db.common.request.ReadRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.db.layer0.variable.VariableWrite;\r
-import org.simantics.utils.datastructures.Callback;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class EnumerationVariableModifier implements EnumerationModifier {\r
-\r
-    protected final Session      session;\r
-    protected final UndoContext  undoContext;\r
-    protected final Variable     variable;\r
-    protected final List<String> allowedValues;\r
-    protected final String       defaultValue;\r
-\r
-    private String             initialValue;\r
-    protected Throwable        modifierFailed;\r
-\r
-    public EnumerationVariableModifier(RequestProcessor processor, UndoContext undoContext, Variable variable,\r
-            List<String> allowedValues, String defaultValue) {\r
-        this.session = processor.getSession();\r
-        this.undoContext = undoContext;\r
-        this.variable = variable;\r
-        this.allowedValues = allowedValues;\r
-        this.defaultValue = defaultValue;\r
-\r
-        initializeModifier(processor);\r
-    }\r
-\r
-    protected void initializeModifier(RequestProcessor processor) {\r
-        try {\r
-            processor.syncRequest(new ReadRequest() {\r
-                @Override\r
-                public void run(ReadGraph graph) throws DatabaseException {\r
-                    initialValue = getInitialValue(graph);\r
-                }\r
-            });\r
-        } catch (DatabaseException e) {\r
-            modifierFailed = e;\r
-        }\r
-    }\r
-\r
-    protected void doModify(final String label) {\r
-        session.asyncRequest(new VariableWrite(variable, label, null, null),\r
-                new Callback<DatabaseException>() {\r
-            @Override\r
-            public void run(DatabaseException parameter) {\r
-                if (parameter != null)\r
-                    ErrorLogger.defaultLogError(parameter);\r
-            }\r
-        });\r
-    }\r
-\r
-    protected String getInitialValue(ReadGraph graph) throws DatabaseException {\r
-        Object value = variable.getValue(graph);\r
-        return value == null ? defaultValue : value.toString();\r
-    }\r
-\r
-    @Override\r
-    public String getValue() {\r
-        return initialValue;\r
-    }\r
-\r
-    @Override\r
-    public String isValid(String label) {\r
-        if (modifierFailed != null)\r
-            return "Could not resolve validator for this value, modification denied. Reason: "\r
-            + modifierFailed.getMessage();\r
-        // Validity should already be enforced by the editing UI for\r
-        // enumerations.\r
-        return null;\r
-    }\r
-\r
-    @Override\r
-    public final void modify(String label) {\r
-        if (modifierFailed != null)\r
-            // Should never end up here, isValid should prevent it.\r
-            throw new Error("modifier failed: " + modifierFailed.getMessage());\r
-        doModify(label);\r
-    }\r
-\r
-    @Override\r
-    public List<String> getValues() {\r
-        return allowedValues;\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.graph.impl;
+
+import java.util.List;
+
+import org.simantics.browsing.ui.content.Labeler.EnumerationModifier;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.RequestProcessor;
+import org.simantics.db.Session;
+import org.simantics.db.UndoContext;
+import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.layer0.variable.VariableWrite;
+import org.simantics.utils.datastructures.Callback;
+import org.simantics.utils.ui.ErrorLogger;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class EnumerationVariableModifier implements EnumerationModifier {
+
+    protected final Session      session;
+    protected final UndoContext  undoContext;
+    protected final Variable     variable;
+    protected final List<String> allowedValues;
+    protected final String       defaultValue;
+
+    private String             initialValue;
+    protected Throwable        modifierFailed;
+
+    public EnumerationVariableModifier(RequestProcessor processor, UndoContext undoContext, Variable variable,
+            List<String> allowedValues, String defaultValue) {
+        this.session = processor.getSession();
+        this.undoContext = undoContext;
+        this.variable = variable;
+        this.allowedValues = allowedValues;
+        this.defaultValue = defaultValue;
+
+        initializeModifier(processor);
+    }
+
+    protected void initializeModifier(RequestProcessor processor) {
+        try {
+            processor.syncRequest(new ReadRequest() {
+                @Override
+                public void run(ReadGraph graph) throws DatabaseException {
+                    initialValue = getInitialValue(graph);
+                }
+            });
+        } catch (DatabaseException e) {
+            modifierFailed = e;
+        }
+    }
+
+    protected void doModify(final String label) {
+        session.asyncRequest(new VariableWrite(variable, label, null, null),
+                new Callback<DatabaseException>() {
+            @Override
+            public void run(DatabaseException parameter) {
+                if (parameter != null)
+                    ErrorLogger.defaultLogError(parameter);
+            }
+        });
+    }
+
+    protected String getInitialValue(ReadGraph graph) throws DatabaseException {
+        Object value = variable.getValue(graph);
+        return value == null ? defaultValue : value.toString();
+    }
+
+    @Override
+    public String getValue() {
+        return initialValue;
+    }
+
+    @Override
+    public String isValid(String label) {
+        if (modifierFailed != null)
+            return "Could not resolve validator for this value, modification denied. Reason: "
+            + modifierFailed.getMessage();
+        // Validity should already be enforced by the editing UI for
+        // enumerations.
+        return null;
+    }
+
+    @Override
+    public final void modify(String label) {
+        if (modifierFailed != null)
+            // Should never end up here, isValid should prevent it.
+            throw new Error("modifier failed: " + modifierFailed.getMessage());
+        doModify(label);
+    }
+
+    @Override
+    public List<String> getValues() {
+        return allowedValues;
+    }
+
+};