-/*******************************************************************************\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.diagramEditor.handlers;\r
-\r
-import java.util.Set;\r
-\r
-import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.jface.action.IAction;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.ui.IWorkbenchPage;\r
-import org.eclipse.ui.PartInitException;\r
-import org.eclipse.ui.PlatformUI;\r
-import org.simantics.Simantics;\r
-import org.simantics.browsing.ui.common.ErrorLogger;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.UniqueRead;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;\r
-import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;\r
-import org.simantics.g2d.diagram.participant.Selection;\r
-import org.simantics.g2d.element.ElementHints;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;\r
-import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent;\r
-import org.simantics.ui.workbench.action.ChooseActionRequest;\r
-import org.simantics.utils.ui.ExceptionUtils;\r
-import org.simantics.utils.ui.action.IPriorityAction;\r
-import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
-\r
-/**\r
- * Really simple support for activating property view from diagram when a single\r
- * element is double clicked.\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public class DefaultElementDoubleClickHandler extends AbstractCanvasParticipant {\r
-\r
- @Dependency\r
- Selection selection;\r
-\r
- public boolean accept(IElement element) {\r
- return true;\r
- }\r
- \r
- @EventHandler(priority = -10)\r
- public boolean handleDoubleClick(MouseDoubleClickedEvent me) {\r
- \r
- Set<IElement> sel = selection.getSelection(0);\r
- if (sel.size() == 1) {\r
- \r
- IElement e = sel.iterator().next();\r
- if(!accept(e)) return false;\r
- \r
- final Object data = e.getHint(ElementHints.KEY_OBJECT);\r
-\r
- final Display display = PlatformUI.getWorkbench().getDisplay();\r
- if (display == null)\r
- return false;\r
-\r
- // See if there's any highest-priority editor adapter that we could use for the object:\r
- try {\r
- Boolean consumed = Simantics.getSession().sync(new UniqueRead<Boolean>() {\r
- @Override\r
- public Boolean perform(ReadGraph graph) throws DatabaseException {\r
- IPriorityAction[] actions = ChooseActionRequest.findActions(graph, null, data, "", false, false);\r
- IPriorityAction priorityAction = (IPriorityAction) ChooseActionRequest.chooseAction(null, actions, null, true);\r
- if (priorityAction != null && priorityAction.getPriority() >= 10) {\r
- //System.out.println("HIGH PRIORITY ACTION(" + priorityAction.getPriority() + "): " + priorityAction);\r
- display.asyncExec( actionAsRunnable( priorityAction) );\r
- return true;\r
- } else if (data instanceof Resource) {\r
- PlatformUI.getWorkbench().getDisplay().asyncExec( revealView("org.simantics.browsing.ui.graph.propertyView") );\r
- return true;\r
- }\r
- return false;\r
- }\r
- });\r
- return consumed;\r
- } catch (DatabaseException ex) {\r
- ErrorLogger.defaultLogError(ex);\r
- }\r
- }\r
-\r
- return false;\r
- }\r
-\r
- public static Runnable revealView(final String viewIdPart) {\r
- return new Runnable() {\r
- @Override\r
- public void run() {\r
- try {\r
- WorkbenchUtils.showView(viewIdPart, IWorkbenchPage.VIEW_VISIBLE);\r
- } catch (PartInitException e) {\r
- ExceptionUtils.logAndShowError(e);\r
- }\r
- }\r
- };\r
- }\r
-\r
- public static Runnable revealAndShowView(final String viewIdPart) {\r
- return new Runnable() {\r
- @Override\r
- public void run() {\r
- try {\r
- WorkbenchUtils.showView(viewIdPart, IWorkbenchPage.VIEW_VISIBLE);\r
-\r
- // Give the post selection listeners time to settle.\r
- PlatformUI.getWorkbench().getDisplay().timerExec( 500, showView(viewIdPart) );\r
- } catch (PartInitException e) {\r
- ExceptionUtils.logAndShowError(e);\r
- }\r
- }\r
- };\r
- }\r
-\r
- public static Runnable showView(final String viewIdPart) {\r
- return new Runnable() {\r
- @Override\r
- public void run() {\r
- try {\r
- CommandUtil.showView(viewIdPart);\r
- } catch (ExecutionException e) {\r
- ExceptionUtils.logAndShowError(e);\r
- }\r
- }\r
- };\r
- }\r
-\r
- public static Runnable actionAsRunnable(final IAction action) {\r
- return new Runnable() {\r
- @Override\r
- public void run() {\r
- action.run();\r
- }\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.diagramEditor.handlers;
+
+import java.util.Set;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.simantics.Simantics;
+import org.simantics.browsing.ui.common.ErrorLogger;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.UniqueRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;
+import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;
+import org.simantics.g2d.diagram.participant.Selection;
+import org.simantics.g2d.element.ElementHints;
+import org.simantics.g2d.element.IElement;
+import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent;
+import org.simantics.ui.workbench.action.ChooseActionRequest;
+import org.simantics.utils.ui.ExceptionUtils;
+import org.simantics.utils.ui.action.IPriorityAction;
+import org.simantics.utils.ui.workbench.WorkbenchUtils;
+
+/**
+ * Really simple support for activating property view from diagram when a single
+ * element is double clicked.
+ *
+ * @author Tuukka Lehtonen
+ */
+public class DefaultElementDoubleClickHandler extends AbstractCanvasParticipant {
+
+ @Dependency
+ Selection selection;
+
+ public boolean accept(IElement element) {
+ return true;
+ }
+
+ @EventHandler(priority = -10)
+ public boolean handleDoubleClick(MouseDoubleClickedEvent me) {
+
+ Set<IElement> sel = selection.getSelection(0);
+ if (sel.size() == 1) {
+
+ IElement e = sel.iterator().next();
+ if(!accept(e)) return false;
+
+ final Object data = e.getHint(ElementHints.KEY_OBJECT);
+
+ final Display display = PlatformUI.getWorkbench().getDisplay();
+ if (display == null)
+ return false;
+
+ // See if there's any highest-priority editor adapter that we could use for the object:
+ try {
+ Boolean consumed = Simantics.getSession().sync(new UniqueRead<Boolean>() {
+ @Override
+ public Boolean perform(ReadGraph graph) throws DatabaseException {
+ IPriorityAction[] actions = ChooseActionRequest.findActions(graph, null, data, "", false, false);
+ IPriorityAction priorityAction = (IPriorityAction) ChooseActionRequest.chooseAction(null, actions, null, true);
+ if (priorityAction != null && priorityAction.getPriority() >= 10) {
+ //System.out.println("HIGH PRIORITY ACTION(" + priorityAction.getPriority() + "): " + priorityAction);
+ display.asyncExec( actionAsRunnable( priorityAction) );
+ return true;
+ } else if (data instanceof Resource) {
+ PlatformUI.getWorkbench().getDisplay().asyncExec( revealView("org.simantics.browsing.ui.graph.propertyView") );
+ return true;
+ }
+ return false;
+ }
+ });
+ return consumed;
+ } catch (DatabaseException ex) {
+ ErrorLogger.defaultLogError(ex);
+ }
+ }
+
+ return false;
+ }
+
+ public static Runnable revealView(final String viewIdPart) {
+ return new Runnable() {
+ @Override
+ public void run() {
+ try {
+ WorkbenchUtils.showView(viewIdPart, IWorkbenchPage.VIEW_VISIBLE);
+ } catch (PartInitException e) {
+ ExceptionUtils.logAndShowError(e);
+ }
+ }
+ };
+ }
+
+ public static Runnable revealAndShowView(final String viewIdPart) {
+ return new Runnable() {
+ @Override
+ public void run() {
+ try {
+ WorkbenchUtils.showView(viewIdPart, IWorkbenchPage.VIEW_VISIBLE);
+
+ // Give the post selection listeners time to settle.
+ PlatformUI.getWorkbench().getDisplay().timerExec( 500, showView(viewIdPart) );
+ } catch (PartInitException e) {
+ ExceptionUtils.logAndShowError(e);
+ }
+ }
+ };
+ }
+
+ public static Runnable showView(final String viewIdPart) {
+ return new Runnable() {
+ @Override
+ public void run() {
+ try {
+ CommandUtil.showView(viewIdPart);
+ } catch (ExecutionException e) {
+ ExceptionUtils.logAndShowError(e);
+ }
+ }
+ };
+ }
+
+ public static Runnable actionAsRunnable(final IAction action) {
+ return new Runnable() {
+ @Override
+ public void run() {
+ action.run();
+ }
+ };
+ }
+
+}