]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LabelModifier.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 / LabelModifier.java
index e4ce0cc37ebcbe60b8688d37acc8477016f12abd..f0583a500c6075eb7475e2676f29e8c8ef4c246d 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 org.simantics.browsing.ui.content.Labeler.Modifier;\r
-import org.simantics.browsing.ui.graph.impl.request.GetLabel;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.util.Layer0Utils;\r
-import org.simantics.db.request.Write;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.utils.datastructures.Callback;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-import org.simantics.utils.ui.ExceptionUtils;\r
-\r
-/**\r
- * NOTE: By default writing Label property, NOT Name property! Name is\r
- * considered a unique immutable identifier for the model. This helps with\r
- * writing stuff on disk and keeping the names coherent.\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public class LabelModifier implements Modifier, Callback<DatabaseException> {\r
-\r
-    private final Session  session;\r
-    protected final Resource resource;\r
-    protected final Resource targetProperty;\r
-\r
-    /**\r
-     * @param session database access point\r
-     * @param resource the resource for which to modify the label\r
-     * @param writeCallback a callback that is invoked once the graph write has\r
-     *        finished. The exception will be null if the write was successful.\r
-     */\r
-    public LabelModifier(Session session, Resource resource) {\r
-        this(session, resource, session.getService(Layer0.class).HasLabel);\r
-    }\r
-\r
-    /**\r
-     * @param session database access point\r
-     * @param resource the resource for which to modify the label\r
-     * @param targetProperty the relation of the target property to be claimed\r
-     *        by the modifier.\r
-     * @param writeCallback a callback that is invoked once the graph write has\r
-     *        finished. The exception will be null if the write was successful.\r
-     */\r
-    public LabelModifier(Session session, Resource resource, Resource targetProperty) {\r
-        this.session = session;\r
-        this.resource = resource;\r
-        this.targetProperty = targetProperty;\r
-    }\r
-\r
-    @Override\r
-    public String getValue() {\r
-        try {\r
-            return session.syncRequest(new GetLabel(resource));\r
-        } catch (DatabaseException e) {\r
-            ErrorLogger.defaultLogWarning("Problem reading current label, see exception for details.", e);\r
-            return "";\r
-        }\r
-    }\r
-\r
-    @Override\r
-    public String isValid(String label) {\r
-        if (label.isEmpty())\r
-            return "Empty label not allowed";\r
-        return null;\r
-    }\r
-\r
-    @Override\r
-    public void modify(String label) {\r
-        session.asyncRequest(getWriteRequest(label), this);\r
-    }\r
-\r
-    protected Write getWriteRequest(final String label) {\r
-        return new WriteRequest() {\r
-            @Override\r
-            public void perform(WriteGraph g) throws DatabaseException {\r
-                g.markUndoPoint();\r
-                Layer0Utils.addCommentMetadata(g, "Renamed " + g.getRelatedValue2(resource, Layer0.getInstance(g).HasName, Bindings.STRING) + " to " + label + " " + resource.toString());\r
-                g.claimLiteral(resource, targetProperty, label);\r
-            }\r
-        };\r
-    }\r
-\r
-    @Override\r
-    public void run(DatabaseException parameter) {\r
-        if (parameter != null) {\r
-            ExceptionUtils.logError("Label modification failed, see exception for details.", parameter);\r
-        }\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 org.simantics.browsing.ui.content.Labeler.Modifier;
+import org.simantics.browsing.ui.graph.impl.request.GetLabel;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.util.Layer0Utils;
+import org.simantics.db.request.Write;
+import org.simantics.layer0.Layer0;
+import org.simantics.utils.datastructures.Callback;
+import org.simantics.utils.ui.ErrorLogger;
+import org.simantics.utils.ui.ExceptionUtils;
+
+/**
+ * NOTE: By default writing Label property, NOT Name property! Name is
+ * considered a unique immutable identifier for the model. This helps with
+ * writing stuff on disk and keeping the names coherent.
+ * 
+ * @author Tuukka Lehtonen
+ */
+public class LabelModifier implements Modifier, Callback<DatabaseException> {
+
+    private final Session  session;
+    protected final Resource resource;
+    protected final Resource targetProperty;
+
+    /**
+     * @param session database access point
+     * @param resource the resource for which to modify the label
+     * @param writeCallback a callback that is invoked once the graph write has
+     *        finished. The exception will be null if the write was successful.
+     */
+    public LabelModifier(Session session, Resource resource) {
+        this(session, resource, session.getService(Layer0.class).HasLabel);
+    }
+
+    /**
+     * @param session database access point
+     * @param resource the resource for which to modify the label
+     * @param targetProperty the relation of the target property to be claimed
+     *        by the modifier.
+     * @param writeCallback a callback that is invoked once the graph write has
+     *        finished. The exception will be null if the write was successful.
+     */
+    public LabelModifier(Session session, Resource resource, Resource targetProperty) {
+        this.session = session;
+        this.resource = resource;
+        this.targetProperty = targetProperty;
+    }
+
+    @Override
+    public String getValue() {
+        try {
+            return session.syncRequest(new GetLabel(resource));
+        } catch (DatabaseException e) {
+            ErrorLogger.defaultLogWarning("Problem reading current label, see exception for details.", e);
+            return "";
+        }
+    }
+
+    @Override
+    public String isValid(String label) {
+        if (label.isEmpty())
+            return "Empty label not allowed";
+        return null;
+    }
+
+    @Override
+    public void modify(String label) {
+        session.asyncRequest(getWriteRequest(label), this);
+    }
+
+    protected Write getWriteRequest(final String label) {
+        return new WriteRequest() {
+            @Override
+            public void perform(WriteGraph g) throws DatabaseException {
+                g.markUndoPoint();
+                Layer0Utils.addCommentMetadata(g, "Renamed " + g.getRelatedValue2(resource, Layer0.getInstance(g).HasName, Bindings.STRING) + " to " + label + " " + resource.toString());
+                g.claimLiteral(resource, targetProperty, label);
+            }
+        };
+    }
+
+    @Override
+    public void run(DatabaseException parameter) {
+        if (parameter != null) {
+            ExceptionUtils.logError("Label modification failed, see exception for details.", parameter);
+        }
+    }
+
+}