]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/actions/ActionCategory.java
19485c0d9c1929751dc30c7f39b0d2d03a10bcd1
[simantics/platform.git] / bundles / org.simantics.browsing.ui.model / src / org / simantics / browsing / ui / model / actions / ActionCategory.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 org.simantics.databoard.Bindings;\r
15 import org.simantics.db.ReadGraph;\r
16 import org.simantics.db.Resource;\r
17 import org.simantics.db.common.utils.NameUtils;\r
18 import org.simantics.db.exception.DatabaseException;\r
19 import org.simantics.viewpoint.ontology.ViewpointResource;\r
20 \r
21 public class ActionCategory implements IActionCategory {\r
22 \r
23     Resource resource;\r
24     String label;\r
25     double priority;\r
26     boolean isSubmenu;\r
27     \r
28     public ActionCategory(Resource resource, String label, double priority, boolean isSubmenu) {\r
29         this.resource = resource;\r
30         this.label = label;\r
31         this.priority = priority;\r
32         this.isSubmenu = isSubmenu;\r
33     }\r
34 \r
35     @Override\r
36     public String getLabel() {\r
37         return label;\r
38     }\r
39 \r
40     @Override\r
41     public double getPriority() {\r
42         return priority;\r
43     }\r
44 \r
45     @Override\r
46     public boolean isSubmenu() {\r
47         return isSubmenu;\r
48     }\r
49 \r
50     public static ActionCategory create(ReadGraph g, Resource r) throws DatabaseException {\r
51         ViewpointResource vr = ViewpointResource.getInstance(g);       \r
52         \r
53         String label = NameUtils.getSafeLabel(g, r);\r
54         \r
55         Resource priorityResource = g.getPossibleObject(r, vr.ActionCategory_HasPriority);\r
56         double priority = priorityResource == null ? 0.0 : (Double)g.getValue(priorityResource, Bindings.DOUBLE);\r
57 \r
58         Resource isSubmenuResource = g.getPossibleObject(r, vr.ActionCategory_IsSubmenu);\r
59         boolean isSubmenu = isSubmenuResource == null ? false : (Boolean)g.getValue(isSubmenuResource, Bindings.BOOLEAN);\r
60         \r
61         return new ActionCategory(r, label, priority, isSubmenu);\r
62     }\r
63     \r
64     @Override\r
65     public int hashCode() {\r
66         return resource.hashCode();\r
67     }\r
68     \r
69     @Override\r
70     public boolean equals(Object obj) {\r
71         if(this == obj)\r
72             return true;\r
73         if(obj == null || obj.getClass() != ActionCategory.class)\r
74             return false;\r
75         return resource.equals(((ActionCategory)obj).resource);\r
76     }\r
77 }\r