]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/ToggleExternalFlag.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser / handlers / ToggleExternalFlag.java
index 5ef611bada2975c26966dcab7f5822568269717f..d03199d9c72f549f161d729fc82503fa749adfdd 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.modeling.ui.modelBrowser.handlers;\r
-\r
-import java.util.Map;\r
-\r
-import org.eclipse.core.commands.AbstractHandler;\r
-import org.eclipse.core.commands.Command;\r
-import org.eclipse.core.commands.ExecutionEvent;\r
-import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.core.commands.State;\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.jface.viewers.ISelectionProvider;\r
-import org.eclipse.ui.IWorkbenchSite;\r
-import org.eclipse.ui.PlatformUI;\r
-import org.eclipse.ui.commands.ICommandService;\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.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.request.WriteRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.modeling.ui.Activator;\r
-import org.simantics.ui.SimanticsUI;\r
-import org.simantics.utils.ui.AdaptionUtils;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-\r
-public class ToggleExternalFlag extends AbstractHandler implements IElementUpdater {\r
-\r
-    private static Resource getFlagResource(ISelection sel) {\r
-        Resource r = AdaptionUtils.adaptToSingle(sel, Resource.class);\r
-        return r;\r
-    }\r
-\r
-    @Override\r
-    public Object execute(ExecutionEvent event) throws ExecutionException {\r
-        ISelection sel = HandlerUtil.getCurrentSelection(event);\r
-        final Resource resource = getFlagResource(sel);\r
-        if (resource == null)\r
-            return null;\r
-\r
-        SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
-            @Override\r
-            public void perform(WriteGraph g) throws DatabaseException {\r
-                DiagramResource dr = DiagramResource.getInstance(g);\r
-                Boolean ext = g.hasStatement(resource, dr.ExternalFlag);\r
-                if (ext)\r
-                    g.deny(resource, dr.ExternalFlag);\r
-                else\r
-                    g.claim(resource, dr.ExternalFlag, resource);\r
-            }\r
-        });\r
-\r
-        return null;\r
-    }\r
-\r
-    @Override\r
-    public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {\r
-        ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);\r
-        Command command = commandService.getCommand("org.simantics.modeling.ui.toggleExternalFlag");\r
-\r
-        // Get a State object for the toggleSubscriptionGroup command\r
-        State state = command.getState("org.simantics.modeling.ui.toggleExternalFlag.state");\r
-        if (state == null) {\r
-            state = new State();\r
-            state.setValue(Boolean.TRUE);\r
-            command.addState("org.simantics.modeling.ui.toggleExternalFlag.state", state);\r
-        }\r
-\r
-        // Get the current value for the State object\r
-        Session s = SimanticsUI.peekSession();\r
-        if (s != null) {\r
-            Boolean value = Boolean.TRUE;\r
-            IWorkbenchSite site = (IWorkbenchSite) parameters.get("org.eclipse.ui.part.IWorkbenchPartSite");\r
-            ISelectionProvider sp = site.getSelectionProvider();\r
-            if (sp != null) {\r
-                final Resource resource = getFlagResource(sp.getSelection());\r
-                if (resource != null) {\r
-                    try {\r
-                        value = s.syncRequest(new Read<Boolean>() {\r
-                            @Override\r
-                            public Boolean perform(ReadGraph graph) throws DatabaseException {\r
-                                DiagramResource dr = DiagramResource.getInstance(graph);\r
-                                return Boolean.valueOf(graph.hasStatement(resource, dr.ExternalFlag));\r
-                            }\r
-                        });\r
-                    } catch (DatabaseException e) {\r
-                        ErrorLogger.defaultLogError(e);\r
-                    }\r
-                }\r
-            }\r
-            state.setValue(value);\r
-        }\r
-\r
-        Boolean checked = (Boolean) state.getValue();\r
-        element.setChecked(checked);\r
-        element.setIcon(checked ? Activator.TICK_ICON : null);\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.modeling.ui.modelBrowser.handlers;
+
+import java.util.Map;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.State;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.ui.IWorkbenchSite;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.commands.IElementUpdater;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.menus.UIElement;
+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.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.request.Read;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.modeling.ui.Activator;
+import org.simantics.ui.SimanticsUI;
+import org.simantics.utils.ui.AdaptionUtils;
+import org.simantics.utils.ui.ErrorLogger;
+
+public class ToggleExternalFlag extends AbstractHandler implements IElementUpdater {
+
+    private static Resource getFlagResource(ISelection sel) {
+        Resource r = AdaptionUtils.adaptToSingle(sel, Resource.class);
+        return r;
+    }
+
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        ISelection sel = HandlerUtil.getCurrentSelection(event);
+        final Resource resource = getFlagResource(sel);
+        if (resource == null)
+            return null;
+
+        SimanticsUI.getSession().asyncRequest(new WriteRequest() {
+            @Override
+            public void perform(WriteGraph g) throws DatabaseException {
+                DiagramResource dr = DiagramResource.getInstance(g);
+                Boolean ext = g.hasStatement(resource, dr.ExternalFlag);
+                if (ext)
+                    g.deny(resource, dr.ExternalFlag);
+                else
+                    g.claim(resource, dr.ExternalFlag, resource);
+            }
+        });
+
+        return null;
+    }
+
+    @Override
+    public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {
+        ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
+        Command command = commandService.getCommand("org.simantics.modeling.ui.toggleExternalFlag");
+
+        // Get a State object for the toggleSubscriptionGroup command
+        State state = command.getState("org.simantics.modeling.ui.toggleExternalFlag.state");
+        if (state == null) {
+            state = new State();
+            state.setValue(Boolean.TRUE);
+            command.addState("org.simantics.modeling.ui.toggleExternalFlag.state", state);
+        }
+
+        // Get the current value for the State object
+        Session s = SimanticsUI.peekSession();
+        if (s != null) {
+            Boolean value = Boolean.TRUE;
+            IWorkbenchSite site = (IWorkbenchSite) parameters.get("org.eclipse.ui.part.IWorkbenchPartSite");
+            ISelectionProvider sp = site.getSelectionProvider();
+            if (sp != null) {
+                final Resource resource = getFlagResource(sp.getSelection());
+                if (resource != null) {
+                    try {
+                        value = s.syncRequest(new Read<Boolean>() {
+                            @Override
+                            public Boolean perform(ReadGraph graph) throws DatabaseException {
+                                DiagramResource dr = DiagramResource.getInstance(graph);
+                                return Boolean.valueOf(graph.hasStatement(resource, dr.ExternalFlag));
+                            }
+                        });
+                    } catch (DatabaseException e) {
+                        ErrorLogger.defaultLogError(e);
+                    }
+                }
+            }
+            state.setValue(value);
+        }
+
+        Boolean checked = (Boolean) state.getValue();
+        element.setChecked(checked);
+        element.setIcon(checked ? Activator.TICK_ICON : null);
+    }
+
+}
+