]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/action/PriorityAction.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / action / PriorityAction.java
diff --git a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/action/PriorityAction.java b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/action/PriorityAction.java
new file mode 100644 (file)
index 0000000..92e3f64
--- /dev/null
@@ -0,0 +1,84 @@
+/*******************************************************************************\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.utils.ui.action;\r
+\r
+import org.eclipse.jface.action.Action;\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+\r
+/**\r
+ * Extendable implementation of {@link IPriorityAction} based on {@link Action}.\r
+ * PriorityActions are comparable by their priorities.\r
+ * \r
+ * Note: this class has a natural ordering that is inconsistent with equals.\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class PriorityAction extends Action implements IPriorityAction {\r
+\r
+    private final int priority;\r
+    \r
+    public PriorityAction() {\r
+        super();\r
+        this.priority = IPriorityAction.NORMAL;\r
+    }\r
+\r
+    public PriorityAction(String text, ImageDescriptor image) {\r
+        super(text, image);\r
+        this.priority = IPriorityAction.NORMAL;\r
+    }\r
+\r
+    public PriorityAction(String text, int style) {\r
+        super(text, style);\r
+        this.priority = IPriorityAction.NORMAL;\r
+    }\r
+\r
+    public PriorityAction(String text) {\r
+        super(text);\r
+        this.priority = IPriorityAction.NORMAL;\r
+    }\r
+\r
+    public PriorityAction(int priority) {\r
+        super();\r
+        this.priority = priority;\r
+    }\r
+\r
+    public PriorityAction(int priority, String text, ImageDescriptor image) {\r
+        super(text, image);\r
+        this.priority = priority;\r
+    }\r
+\r
+    public PriorityAction(int priority, String text, int style) {\r
+        super(text, style);\r
+        this.priority = priority;\r
+    }\r
+\r
+    public PriorityAction(int priority, String text) {\r
+        super(text);\r
+        this.priority = priority;\r
+    }\r
+    \r
+    /* (non-Javadoc)\r
+     * @see org.simantics.utils.ui.action.IPriorityAction#getPriority()\r
+     */\r
+    public int getPriority() {\r
+        return priority;\r
+    }\r
+\r
+    public int compareTo(IPriorityAction o) {\r
+        int op = o.getPriority();\r
+        // delta < 0 when priority < op\r
+        // delta > 0 when priority > op\r
+        int delta = op - getPriority();\r
+        return delta;\r
+    }\r
+    \r
+}\r