--- /dev/null
+/*******************************************************************************\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.ui;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.EventObject;\r
+import java.util.List;\r
+\r
+import org.eclipse.jface.action.IAction;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.utils.datastructures.hints.HintContext;\r
+import org.simantics.utils.ui.action.IPriorityAction;\r
+import org.simantics.utils.ui.action.PriorityActionAdapter;\r
+\r
+/**\r
+ * TODO: multiple selection support\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class DoubleClickEvent extends EventObject {\r
+\r
+ private static final long serialVersionUID = 1730213767249571862L;\r
+\r
+ private boolean consumed = false;\r
+\r
+ private final ReadGraph graph;\r
+\r
+ private final Object resource;\r
+\r
+ private List<IPriorityAction> actions = new ArrayList<IPriorityAction>();\r
+\r
+ private HintContext hintContext = new HintContext();\r
+\r
+ public DoubleClickEvent(Object source, ReadGraph g, Object resource) {\r
+ super(source);\r
+ this.graph = g;\r
+ this.resource = resource;\r
+ }\r
+\r
+ public ReadGraph getGraph() {\r
+ return graph;\r
+ }\r
+\r
+ public Object getResource() {\r
+ return resource;\r
+ }\r
+\r
+ /**\r
+ * Mark the event as accepted which suppresses further double click handler\r
+ * calls.\r
+ */\r
+ public void consume() {\r
+ consumed = true;\r
+ }\r
+\r
+ public boolean isConsumed() {\r
+ return consumed;\r
+ }\r
+\r
+ /**\r
+ * Add a possible action with normal priority.\r
+ * \r
+ * @param action\r
+ */\r
+ public void add(IAction action) {\r
+ actions.add(new PriorityActionAdapter(IPriorityAction.NORMAL, action));\r
+ }\r
+\r
+ /**\r
+ * Add a possible prioritized action.\r
+ * \r
+ * @param action\r
+ */\r
+ public void add(IPriorityAction action) {\r
+ actions.add(action);\r
+ }\r
+\r
+ /**\r
+ * Only used internally by the doubleclick extension point.\r
+ * \r
+ * @return\r
+ */\r
+ public IPriorityAction[] getOrderedActions() {\r
+ List<IPriorityAction> copy = new ArrayList<IPriorityAction>(actions);\r
+ Collections.sort(copy);\r
+ return copy.toArray(new IPriorityAction[copy.size()]);\r
+ }\r
+\r
+ public HintContext getHintContext() {\r
+ return hintContext;\r
+ }\r
+\r
+}\r