1 /*******************************************************************************
2 * Copyright (c) 2010, 2011 Association for Decentralized Information Management in
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.browsing.ui.model.actions;
14 import org.simantics.databoard.Bindings;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.common.utils.NameUtils;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.viewpoint.ontology.ViewpointResource;
21 public class ActionCategory implements IActionCategory {
28 public ActionCategory(Resource resource, String label, double priority, boolean isSubmenu) {
29 this.resource = resource;
31 this.priority = priority;
32 this.isSubmenu = isSubmenu;
36 public String getLabel() {
41 public double getPriority() {
46 public boolean isSubmenu() {
50 public static ActionCategory create(ReadGraph g, Resource r) throws DatabaseException {
51 ViewpointResource vr = ViewpointResource.getInstance(g);
53 String label = NameUtils.getSafeLabel(g, r);
55 Resource priorityResource = g.getPossibleObject(r, vr.ActionCategory_HasPriority);
56 double priority = priorityResource == null ? 0.0 : (Double)g.getValue(priorityResource, Bindings.DOUBLE);
58 Resource isSubmenuResource = g.getPossibleObject(r, vr.ActionCategory_IsSubmenu);
59 boolean isSubmenu = isSubmenuResource == null ? false : (Boolean)g.getValue(isSubmenuResource, Bindings.BOOLEAN);
61 return new ActionCategory(r, label, priority, isSubmenu);
65 public int hashCode() {
66 return resource.hashCode();
70 public boolean equals(Object obj) {
73 if(obj == null || obj.getClass() != ActionCategory.class)
75 return resource.equals(((ActionCategory)obj).resource);