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