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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.selectionview;
\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
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
24 * @author Tuukka Lehtonen
\r
25 * @see PropertyTabContributor
\r
27 public class ComparableTabContributor implements PropertyTabContributor, Comparable<ComparableTabContributor> {
\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
36 public ComparableTabContributor(PropertyTabContributor orig, double priority, Object input, String label) {
\r
37 this(orig, priority, input, label, null);
\r
40 public ComparableTabContributor(PropertyTabContributor orig, double priority, Object input, String label, Image image) {
\r
41 this(orig, priority, input, label, label, image);
\r
44 public ComparableTabContributor(PropertyTabContributor orig, double priority, Object input, String label, String id, Image image) {
\r
46 throw new NullPointerException("null property tab contributor");
\r
48 throw new NullPointerException("null input");
\r
50 throw new NullPointerException("null label");
\r
52 this.priority = priority;
\r
60 public IPropertyTab create(Composite parent, IWorkbenchSite site, ISessionContext context, Object input) {
\r
61 return orig.create(parent, site, context, input);
\r
64 public String getLabel() {
\r
68 public Image getImage() {
\r
72 public Object getInput() {
\r
76 public String getId() {
\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
87 public int hashCode() {
\r
88 return orig.hashCode() ^ Double.valueOf(priority).hashCode() ^ input.hashCode() ^ label.hashCode();
\r
92 public boolean equals(Object object) {
\r
95 else if (object == null)
\r
97 else if (!(object instanceof ComparableTabContributor))
\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
105 public String toString() {
\r
106 return orig + "[" + label + "] " + priority + " " + input;
\r