1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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.selectionview;
14 import org.eclipse.swt.graphics.Image;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.ui.IWorkbenchSite;
17 import org.simantics.db.management.ISessionContext;
20 * A wrapper for {@link PropertyTabContributor} to label/image it and make it
21 * comparable by assigning a number to it. Used in {@link SelectionProcessor}
22 * implementations to contribute tabs to tabbed property pages.
24 * @author Tuukka Lehtonen
25 * @see PropertyTabContributor
27 public class ComparableTabContributor implements PropertyTabContributor, Comparable<ComparableTabContributor> {
29 private final PropertyTabContributor orig;
30 private final double priority;
31 private final Object input;
32 private final String label;
33 private final String id;
34 private final Image image;
36 public ComparableTabContributor(PropertyTabContributor orig, double priority, Object input, String label) {
37 this(orig, priority, input, label, null);
40 public ComparableTabContributor(PropertyTabContributor orig, double priority, Object input, String label, Image image) {
41 this(orig, priority, input, label, label, image);
44 public ComparableTabContributor(PropertyTabContributor orig, double priority, Object input, String label, String id, Image image) {
46 throw new NullPointerException("null property tab contributor");
48 throw new NullPointerException("null input");
50 throw new NullPointerException("null label");
52 this.priority = priority;
60 public IPropertyTab create(Composite parent, IWorkbenchSite site, ISessionContext context, Object input) {
61 return orig.create(parent, site, context, input);
64 public String getLabel() {
68 public Image getImage() {
72 public Object getInput() {
76 public String getId() {
81 public int compareTo(ComparableTabContributor o) {
82 int comp = Double.compare(o.priority, priority);
83 if(comp != 0) return comp;
84 return id.compareTo(o.id);
88 public int hashCode() {
89 return orig.hashCode() ^ Double.valueOf(priority).hashCode() ^ input.hashCode() ^ label.hashCode();
93 public boolean equals(Object object) {
96 else if (object == null)
98 else if (!(object instanceof ComparableTabContributor))
101 ComparableTabContributor r = (ComparableTabContributor)object;
102 return orig.equals(r.orig) && priority == r.priority && input.equals(r.input) && label.equals(r.label);
106 public String toString() {
107 return orig + "[" + label + "] " + priority + " " + input;