]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/ComparableTabContributor.java b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/ComparableTabContributor.java
new file mode 100644 (file)
index 0000000..29891d5
--- /dev/null
@@ -0,0 +1,109 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.selectionview;\r
+\r
+import org.eclipse.swt.graphics.Image;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.db.management.ISessionContext;\r
+\r
+/**\r
+ * A wrapper for {@link PropertyTabContributor} to label/image it and make it\r
+ * comparable by assigning a number to it. Used in {@link SelectionProcessor}\r
+ * implementations to contribute tabs to tabbed property pages.\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ * @see PropertyTabContributor\r
+ */\r
+public class ComparableTabContributor implements PropertyTabContributor, Comparable<ComparableTabContributor> {\r
+\r
+    private final PropertyTabContributor orig;\r
+    private final double                 priority;\r
+    private final Object                 input;\r
+    private final String                 label;\r
+    private final String                 id;\r
+    private final Image                  image;\r
+\r
+    public ComparableTabContributor(PropertyTabContributor orig, double priority, Object input, String label) {\r
+        this(orig, priority, input, label, null);\r
+    }\r
+\r
+    public ComparableTabContributor(PropertyTabContributor orig, double priority, Object input, String label, Image image) {\r
+       this(orig, priority, input, label, label, image);\r
+    }\r
+\r
+    public ComparableTabContributor(PropertyTabContributor orig, double priority, Object input, String label, String id, Image image) {\r
+        if (orig == null)\r
+            throw new NullPointerException("null property tab contributor");\r
+        if (input == null)\r
+            throw new NullPointerException("null input");\r
+        if (label == null)\r
+            throw new NullPointerException("null label");\r
+        this.orig = orig;\r
+        this.priority = priority;\r
+        this.input = input;\r
+        this.label = label;\r
+        this.id = id;\r
+        this.image = image;\r
+    }\r
+\r
+    @Override\r
+    public IPropertyTab create(Composite parent, IWorkbenchSite site, ISessionContext context, Object input) {\r
+        return orig.create(parent, site, context, input);\r
+    }\r
+\r
+    public String getLabel() {\r
+        return label;\r
+    }\r
+\r
+    public Image getImage() {\r
+        return image;\r
+    }\r
+\r
+    public Object getInput() {\r
+        return input;\r
+    }\r
+    \r
+    public String getId() {\r
+       return id;\r
+    }\r
+\r
+    @Override\r
+    public int compareTo(ComparableTabContributor o) {\r
+        double d = o.priority - priority;\r
+        return (d < 0) ? -1 : (d > 0) ? 1 : 0;\r
+    }\r
+\r
+    @Override\r
+    public int hashCode() {\r
+        return orig.hashCode() ^ Double.valueOf(priority).hashCode() ^ input.hashCode() ^ label.hashCode();\r
+    }\r
+\r
+    @Override\r
+    public boolean equals(Object object) {\r
+        if (this == object)\r
+            return true;\r
+        else if (object == null)\r
+            return false;\r
+        else if (!(object instanceof ComparableTabContributor))\r
+            return false;\r
+\r
+        ComparableTabContributor r = (ComparableTabContributor)object;\r
+        return orig.equals(r.orig) && priority == r.priority && input.equals(r.input) && label.equals(r.label);\r
+    }\r
+\r
+    @Override\r
+    public String toString() {\r
+        return orig + "[" + label + "] " + priority + " " + input;\r
+    }\r
+\r
+}
\ No newline at end of file