--- /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.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