-/*******************************************************************************\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.actions.e4;\r
-\r
-import java.util.Arrays;\r
-import java.util.List;\r
-\r
-import javax.inject.Named;\r
-\r
-import org.eclipse.e4.core.contexts.Active;\r
-import org.eclipse.e4.core.di.annotations.CanExecute;\r
-import org.eclipse.e4.core.di.annotations.Execute;\r
-import org.eclipse.e4.ui.model.application.ui.basic.MPart;\r
-import org.eclipse.e4.ui.services.IServiceConstants;\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor;\r
-import org.simantics.Simantics;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.UnaryRead;\r
-import org.simantics.db.common.utils.RequestUtil;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.modeling.ui.actions.style.EditStyle;\r
-import org.simantics.modeling.ui.diagramEditor.DiagramEditor;\r
-import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.utils.ResourceAdaptionUtils;\r
-\r
-/**\r
- * Style Edit\r
- * \r
- * TODO : should we have extension point for expanding styles?\r
- * TODO : default ColorChooser is not suitable for this task\r
- * TODO : how to store MetricsFormat template list\r
- * \r
- * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
- *\r
- */\r
-public class EditStyleHandler {\r
-\r
- private Resource[] lastResources = Resource.NONE;\r
- private boolean cachedCanExecute;\r
-\r
- @CanExecute\r
- public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) ISelection s, @Active MPart part) throws DatabaseException, InterruptedException {\r
- if (!(part.getObject() instanceof CompatibilityEditor))\r
- return false;\r
- CompatibilityEditor editor = (CompatibilityEditor) part.getObject();\r
- if (!(editor.getPart() instanceof DiagramEditor))\r
- return false;\r
- if (s == null)\r
- return false;\r
-\r
- final Resource[] resources = ResourceAdaptionUtils.toResources(s);\r
- if (resources.length != 0) {\r
- if (!Arrays.equals(resources, lastResources)) {\r
- lastResources = resources;\r
- cachedCanExecute = areStyleProviders(resources);\r
- }\r
- return cachedCanExecute;\r
- }\r
- return false;\r
- }\r
-\r
- private static boolean areStyleProviders(Resource[] resources) throws DatabaseException, InterruptedException {\r
- return RequestUtil.trySyncRequest(\r
- Simantics.getSession(),\r
- SimanticsUI.UI_THREAD_REQUEST_START_TIMEOUT,\r
- SimanticsUI.UI_THREAD_REQUEST_EXECUTION_TIMEOUT,\r
- false,\r
- new StyleProviderCheck(Arrays.asList(resources)));\r
- }\r
-\r
- private static class StyleProviderCheck extends UnaryRead<List<Resource>, Boolean> {\r
-\r
- public StyleProviderCheck(List<Resource> parameter) {\r
- super(parameter);\r
- }\r
-\r
- @Override\r
- public Boolean perform(ReadGraph graph) throws DatabaseException {\r
- DiagramResource DIA = DiagramResource.getInstance(graph);\r
- // Find what kind of styles selected objects support\r
- for (Resource r : parameter)\r
- if (!graph.isInstanceOf(r, DIA.StyleProvider))\r
- return false;\r
- return true;\r
- }\r
-\r
- }\r
-\r
- @Execute\r
- public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) ISelection s) {\r
- final Resource[] resources = ResourceAdaptionUtils.toResources(s);\r
- if (resources.length != 0)\r
- EditStyle.openStyleDialog(resources);\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.actions.e4;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.inject.Named;
+
+import org.eclipse.e4.core.contexts.Active;
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor;
+import org.simantics.DatabaseJob;
+import org.simantics.Simantics;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.UnaryRead;
+import org.simantics.db.common.utils.RequestUtil;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.modeling.ui.actions.style.EditStyle;
+import org.simantics.modeling.ui.diagramEditor.DiagramEditor;
+import org.simantics.ui.SimanticsUI;
+import org.simantics.ui.utils.ResourceAdaptionUtils;
+
+/**
+ * Style Edit
+ *
+ * TODO : should we have extension point for expanding styles?
+ * TODO : default ColorChooser is not suitable for this task
+ * TODO : how to store MetricsFormat template list
+ *
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
+ *
+ */
+public class EditStyleHandler {
+
+ private Resource[] lastResources = Resource.NONE;
+ private boolean cachedCanExecute;
+
+ @CanExecute
+ public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) ISelection s, @Active MPart part) throws DatabaseException, InterruptedException {
+ if (!(part.getObject() instanceof CompatibilityEditor))
+ return false;
+ CompatibilityEditor editor = (CompatibilityEditor) part.getObject();
+ if (!(editor.getPart() instanceof DiagramEditor))
+ return false;
+ if (s == null)
+ return false;
+ if (DatabaseJob.inProgress())
+ return false;
+ final Resource[] resources = ResourceAdaptionUtils.toResources(s);
+ if (resources.length != 0) {
+ if (!Arrays.equals(resources, lastResources)) {
+ lastResources = resources;
+ cachedCanExecute = areStyleProviders(resources);
+ }
+ return cachedCanExecute;
+ }
+ return false;
+ }
+
+ private static boolean areStyleProviders(Resource[] resources) throws DatabaseException, InterruptedException {
+ return RequestUtil.trySyncRequest(
+ Simantics.getSession(),
+ SimanticsUI.UI_THREAD_REQUEST_START_TIMEOUT,
+ SimanticsUI.UI_THREAD_REQUEST_EXECUTION_TIMEOUT,
+ false,
+ new StyleProviderCheck(Arrays.asList(resources)));
+ }
+
+ private static class StyleProviderCheck extends UnaryRead<List<Resource>, Boolean> {
+
+ public StyleProviderCheck(List<Resource> parameter) {
+ super(parameter);
+ }
+
+ @Override
+ public Boolean perform(ReadGraph graph) throws DatabaseException {
+ DiagramResource DIA = DiagramResource.getInstance(graph);
+ // Find what kind of styles selected objects support
+ for (Resource r : parameter)
+ if (!graph.isInstanceOf(r, DIA.StyleProvider))
+ return false;
+ return true;
+ }
+
+ }
+
+ @Execute
+ public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) ISelection s) {
+ final Resource[] resources = ResourceAdaptionUtils.toResources(s);
+ if (resources.length != 0)
+ EditStyle.openStyleDialog(resources);
+ }
+
+}