]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.selectionview/src/org/simantics/selectionview/ComparableTabContributor.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.selectionview / src / org / simantics / selectionview / ComparableTabContributor.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in 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.selectionview;\r
13 \r
14 import org.eclipse.swt.graphics.Image;\r
15 import org.eclipse.swt.widgets.Composite;\r
16 import org.eclipse.ui.IWorkbenchSite;\r
17 import org.simantics.db.management.ISessionContext;\r
18 \r
19 /**\r
20  * A wrapper for {@link PropertyTabContributor} to label/image it and make it\r
21  * comparable by assigning a number to it. Used in {@link SelectionProcessor}\r
22  * implementations to contribute tabs to tabbed property pages.\r
23  * \r
24  * @author Tuukka Lehtonen\r
25  * @see PropertyTabContributor\r
26  */\r
27 public class ComparableTabContributor implements PropertyTabContributor, Comparable<ComparableTabContributor> {\r
28 \r
29     private final PropertyTabContributor orig;\r
30     private final double                 priority;\r
31     private final Object                 input;\r
32     private final String                 label;\r
33     private final String                 id;\r
34     private final Image                  image;\r
35 \r
36     public ComparableTabContributor(PropertyTabContributor orig, double priority, Object input, String label) {\r
37         this(orig, priority, input, label, null);\r
38     }\r
39 \r
40     public ComparableTabContributor(PropertyTabContributor orig, double priority, Object input, String label, Image image) {\r
41         this(orig, priority, input, label, label, image);\r
42     }\r
43 \r
44     public ComparableTabContributor(PropertyTabContributor orig, double priority, Object input, String label, String id, Image image) {\r
45         if (orig == null)\r
46             throw new NullPointerException("null property tab contributor");\r
47         if (input == null)\r
48             throw new NullPointerException("null input");\r
49         if (label == null)\r
50             throw new NullPointerException("null label");\r
51         this.orig = orig;\r
52         this.priority = priority;\r
53         this.input = input;\r
54         this.label = label;\r
55         this.id = id;\r
56         this.image = image;\r
57     }\r
58 \r
59     @Override\r
60     public IPropertyTab create(Composite parent, IWorkbenchSite site, ISessionContext context, Object input) {\r
61         return orig.create(parent, site, context, input);\r
62     }\r
63 \r
64     public String getLabel() {\r
65         return label;\r
66     }\r
67 \r
68     public Image getImage() {\r
69         return image;\r
70     }\r
71 \r
72     public Object getInput() {\r
73         return input;\r
74     }\r
75     \r
76     public String getId() {\r
77         return id;\r
78     }\r
79 \r
80     @Override\r
81     public int compareTo(ComparableTabContributor o) {\r
82         double d = o.priority - priority;\r
83         return (d < 0) ? -1 : (d > 0) ? 1 : 0;\r
84     }\r
85 \r
86     @Override\r
87     public int hashCode() {\r
88         return orig.hashCode() ^ Double.valueOf(priority).hashCode() ^ input.hashCode() ^ label.hashCode();\r
89     }\r
90 \r
91     @Override\r
92     public boolean equals(Object object) {\r
93         if (this == object)\r
94             return true;\r
95         else if (object == null)\r
96             return false;\r
97         else if (!(object instanceof ComparableTabContributor))\r
98             return false;\r
99 \r
100         ComparableTabContributor r = (ComparableTabContributor)object;\r
101         return orig.equals(r.orig) && priority == r.priority && input.equals(r.input) && label.equals(r.label);\r
102     }\r
103 \r
104     @Override\r
105     public String toString() {\r
106         return orig + "[" + label + "] " + priority + " " + input;\r
107     }\r
108 \r
109 }