]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/actions/IActionCategory.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.browsing.ui.model / src / org / simantics / browsing / ui / model / actions / IActionCategory.java
1 /*******************************************************************************\r
2  * Copyright (c) 2010, 2011 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.browsing.ui.model.actions;\r
13 \r
14 import java.util.Comparator;\r
15 \r
16 public interface IActionCategory {\r
17     String getLabel();\r
18     double getPriority();\r
19     boolean isSubmenu();\r
20     \r
21     public static final Comparator<IActionCategory> ACTION_CATEGORY_COMPARATOR = new Comparator<IActionCategory>() {\r
22         @Override\r
23         public int compare(IActionCategory o1, IActionCategory o2) {\r
24             if(o1 == null) {\r
25                 if(o2 == null)\r
26                     return 0;\r
27                 return -1;\r
28             }\r
29             if(o2 == null)\r
30                 return 1;\r
31             double p1 = o1.getPriority();\r
32             double p2 = o2.getPriority();\r
33             if(p1 < p2)\r
34                 return -1;\r
35             if(p1 > p2)\r
36                 return 1;\r
37             String label1 = o1.getLabel();\r
38             String label2 = o2.getLabel();\r
39             if(label1 == null) {\r
40                 if(label2 == null)\r
41                     return 0;\r
42                 else\r
43                     return -1;\r
44             }\r
45             else {\r
46                 if(label2 == null)\r
47                     return 1;\r
48                 else\r
49                     return label1.compareTo(label2);\r
50             } \r
51         }\r
52     };\r
53 }\r