1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.utils.ui.action;
14 import org.eclipse.jface.action.Action;
15 import org.eclipse.jface.resource.ImageDescriptor;
18 * Extendable implementation of {@link IPriorityAction} based on {@link Action}.
19 * PriorityActions are comparable by their priorities.
21 * Note: this class has a natural ordering that is inconsistent with equals.
23 * @author Tuukka Lehtonen
25 public class PriorityAction extends Action implements IPriorityAction {
27 private final int priority;
29 public PriorityAction() {
31 this.priority = IPriorityAction.NORMAL;
34 public PriorityAction(String text, ImageDescriptor image) {
36 this.priority = IPriorityAction.NORMAL;
39 public PriorityAction(String text, int style) {
41 this.priority = IPriorityAction.NORMAL;
44 public PriorityAction(String text) {
46 this.priority = IPriorityAction.NORMAL;
49 public PriorityAction(int priority) {
51 this.priority = priority;
54 public PriorityAction(int priority, String text, ImageDescriptor image) {
56 this.priority = priority;
59 public PriorityAction(int priority, String text, int style) {
61 this.priority = priority;
64 public PriorityAction(int priority, String text) {
66 this.priority = priority;
70 * @see org.simantics.utils.ui.action.IPriorityAction#getPriority()
72 public int getPriority() {
76 public int compareTo(IPriorityAction o) {
77 int op = o.getPriority();
78 // delta < 0 when priority < op
79 // delta > 0 when priority > op
80 int delta = op - getPriority();