]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.event/src/org/simantics/event/view/handler/PreferenceHandler.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.event / src / org / simantics / event / view / handler / PreferenceHandler.java
index 8f9da61dad5d395daf9c05badc74161220055075..e75d24f222a628eb3c89ad2f6644c3c96a98ab06 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 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.event.view.handler;\r
-\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.eclipse.core.commands.AbstractHandler;\r
-import org.eclipse.core.commands.ExecutionEvent;\r
-import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.ui.commands.IElementUpdater;\r
-import org.eclipse.ui.handlers.HandlerUtil;\r
-import org.eclipse.ui.menus.UIElement;\r
-import org.simantics.Simantics;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.utils.TagUtil;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.SelectionHints;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-import org.simantics.utils.ui.ISelectionUtils;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-class PreferenceHandler extends AbstractHandler implements IElementUpdater {\r
-\r
-    protected final String virtualGraphId;\r
-    private final String   tagURI;\r
-    private final boolean  tag;\r
-\r
-    public PreferenceHandler() {\r
-        this("preferences", null, false);\r
-    }\r
-\r
-    public PreferenceHandler(String tagURI, boolean tag) {\r
-        this("preferences", tagURI, tag);\r
-    }\r
-\r
-    public PreferenceHandler(String virtualGraphId) {\r
-        this(virtualGraphId, null, false);\r
-    }\r
-\r
-    public PreferenceHandler(String virtualGraphId, String tagURI, boolean tag) {\r
-        this.virtualGraphId = virtualGraphId;\r
-        this.tagURI = tagURI;\r
-        this.tag = tag;\r
-    }\r
-\r
-    @Override\r
-    public Object execute(ExecutionEvent event) throws ExecutionException {\r
-        Session session = Simantics.peekSession();\r
-        if (session == null)\r
-            return null;\r
-        ISelection selection = HandlerUtil.getCurrentSelection(event);\r
-        final List<Resource> resources = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);\r
-        new TagUtil(virtualGraphId, tagURI, tag) {\r
-            @Override\r
-            protected void processSelection(WriteGraph graph, List<Resource> resources) throws DatabaseException {\r
-                if (!process(graph))\r
-                    return;\r
-                super.processSelection(graph, resources);\r
-            }\r
-        }.execute(session, resources);\r
-        return null;\r
-    }\r
-\r
-    /**\r
-     * @return <code>false</code> to perform no further actions after this\r
-     *         method completes.\r
-     */\r
-    protected boolean process(WriteGraph graph) throws DatabaseException {\r
-        return true;\r
-    }\r
-\r
-    @SuppressWarnings("rawtypes")\r
-    @Override\r
-    public void updateElement(UIElement element, Map parameters) {\r
-        Session session = Simantics.peekSession();\r
-        if (session == null)\r
-            return;\r
-        try {\r
-            boolean checked = session.syncRequest(new Read<Boolean>() {\r
-                @Override\r
-                public Boolean perform(ReadGraph graph) throws DatabaseException {\r
-                    return isChecked(graph);\r
-                }\r
-            });\r
-            element.setChecked(checked);\r
-        } catch (DatabaseException e) {\r
-            ErrorLogger.defaultLogError(e);\r
-        }\r
-    }\r
-\r
-    protected boolean isChecked(ReadGraph graph) throws DatabaseException {\r
-        return false;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2011 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.event.view.handler;
+
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.commands.IElementUpdater;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.menus.UIElement;
+import org.simantics.Simantics;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.utils.TagUtil;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.SelectionHints;
+import org.simantics.db.request.Read;
+import org.simantics.utils.ui.ErrorLogger;
+import org.simantics.utils.ui.ISelectionUtils;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+class PreferenceHandler extends AbstractHandler implements IElementUpdater {
+
+    protected final String virtualGraphId;
+    private final String   tagURI;
+    private final boolean  tag;
+
+    public PreferenceHandler() {
+        this("preferences", null, false);
+    }
+
+    public PreferenceHandler(String tagURI, boolean tag) {
+        this("preferences", tagURI, tag);
+    }
+
+    public PreferenceHandler(String virtualGraphId) {
+        this(virtualGraphId, null, false);
+    }
+
+    public PreferenceHandler(String virtualGraphId, String tagURI, boolean tag) {
+        this.virtualGraphId = virtualGraphId;
+        this.tagURI = tagURI;
+        this.tag = tag;
+    }
+
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        Session session = Simantics.peekSession();
+        if (session == null)
+            return null;
+        ISelection selection = HandlerUtil.getCurrentSelection(event);
+        final List<Resource> resources = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);
+        new TagUtil(virtualGraphId, tagURI, tag) {
+            @Override
+            protected void processSelection(WriteGraph graph, List<Resource> resources) throws DatabaseException {
+                if (!process(graph))
+                    return;
+                super.processSelection(graph, resources);
+            }
+        }.execute(session, resources);
+        return null;
+    }
+
+    /**
+     * @return <code>false</code> to perform no further actions after this
+     *         method completes.
+     */
+    protected boolean process(WriteGraph graph) throws DatabaseException {
+        return true;
+    }
+
+    @SuppressWarnings("rawtypes")
+    @Override
+    public void updateElement(UIElement element, Map parameters) {
+        Session session = Simantics.peekSession();
+        if (session == null)
+            return;
+        try {
+            boolean checked = session.syncRequest(new Read<Boolean>() {
+                @Override
+                public Boolean perform(ReadGraph graph) throws DatabaseException {
+                    return isChecked(graph);
+                }
+            });
+            element.setChecked(checked);
+        } catch (DatabaseException e) {
+            ErrorLogger.defaultLogError(e);
+        }
+    }
+
+    protected boolean isChecked(ReadGraph graph) throws DatabaseException {
+        return false;
+    }
+
+}