001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: ******************************************************************************/package org.eclipse.ui.views.properties.tabbed;
011:
012: import java.util.ArrayList;
013: import java.util.Iterator;
014: import java.util.List;
015:
016: import org.eclipse.core.runtime.IStatus;
017: import org.eclipse.core.runtime.Status;
018: import org.eclipse.swt.graphics.Image;
019: import org.eclipse.ui.internal.views.properties.tabbed.TabbedPropertyViewPlugin;
020:
021: /**
022: * An abstract implementation of a tab descriptor for the tabbed property view.
023: *
024: * @author Anthony Hunter
025: * @since 3.4
026: */
027: public abstract class AbstractTabDescriptor implements ITabDescriptor,
028: Cloneable {
029:
030: private List sectionDescriptors;
031:
032: /**
033: * Constructor for AbstractTabDescriptor.
034: */
035: public AbstractTabDescriptor() {
036: super ();
037: sectionDescriptors = new ArrayList(5);
038: }
039:
040: /*
041: * @see java.lang.Object#clone()
042: */
043: public Object clone() {
044: try {
045: return super .clone();
046: } catch (CloneNotSupportedException exception) {
047: IStatus status = new Status(IStatus.ERROR,
048: TabbedPropertyViewPlugin.getPlugin().getBundle()
049: .getSymbolicName(), 666, exception
050: .getMessage(), exception);
051: TabbedPropertyViewPlugin.getPlugin().getLog().log(status);
052: }
053: return null;
054: }
055:
056: /*
057: * @see org.eclipse.ui.views.properties.tabbed.ITabDescriptor#createTab()
058: */
059: public TabContents createTab() {
060: List sections = new ArrayList(getSectionDescriptors().size());
061: for (Iterator iter = getSectionDescriptors().iterator(); iter
062: .hasNext();) {
063: ISectionDescriptor descriptor = (ISectionDescriptor) iter
064: .next();
065: ISection section = descriptor.getSectionClass();
066: sections.add(section);
067: }
068: TabContents tab = new TabContents();
069: tab.setSections((ISection[]) sections
070: .toArray(new ISection[sections.size()]));
071: return tab;
072: }
073:
074: /*
075: * @see java.lang.Object#equals(java.lang.Object)
076: */
077: public boolean equals(Object object) {
078: if (this == object) {
079: return true;
080: }
081:
082: if (this .getClass() == object.getClass()) {
083: AbstractTabDescriptor descriptor = (AbstractTabDescriptor) object;
084: if (this .getCategory().equals(descriptor.getCategory())
085: && this .getId().equals(descriptor.getId())
086: && this .getSectionDescriptors().size() == descriptor
087: .getSectionDescriptors().size()) {
088:
089: Iterator i = this .getSectionDescriptors().iterator();
090: Iterator j = descriptor.getSectionDescriptors()
091: .iterator();
092:
093: // the order is important here - so as long as the sizes of the
094: // lists are the same and id of the section at the same
095: // positions are the same - the lists are the same
096: while (i.hasNext()) {
097: ISectionDescriptor source = (ISectionDescriptor) i
098: .next();
099: ISectionDescriptor target = (ISectionDescriptor) j
100: .next();
101: if (!source.getId().equals(target.getId())) {
102: return false;
103: }
104: }
105:
106: return true;
107: }
108:
109: }
110:
111: return false;
112: }
113:
114: /*
115: * @see org.eclipse.ui.views.properties.tabbed.ITabDescriptor#getAfterTab()
116: */
117: public String getAfterTab() {
118: return TOP;
119: }
120:
121: /*
122: * @see org.eclipse.ui.views.properties.tabbed.ITabItem#getImage()
123: */
124: public Image getImage() {
125: return null;
126: }
127:
128: /**
129: * Get the list of section descriptors for the tab.
130: *
131: * @return the list of section descriptors for the tab.
132: */
133: public List getSectionDescriptors() {
134: return sectionDescriptors;
135: }
136:
137: /*
138: * @see org.eclipse.ui.views.properties.tabbed.ITabItem#getText()
139: */
140: public String getText() {
141: return getLabel();
142: }
143:
144: /*
145: * @see java.lang.Object#hashCode()
146: */
147: public int hashCode() {
148:
149: int hashCode = getCategory().hashCode();
150: hashCode ^= getId().hashCode();
151: Iterator i = this .getSectionDescriptors().iterator();
152: while (i.hasNext()) {
153: ISectionDescriptor section = (ISectionDescriptor) i.next();
154: hashCode ^= section.getId().hashCode();
155: }
156: return hashCode;
157: }
158:
159: /*
160: * @see org.eclipse.ui.views.properties.tabbed.ITabItem#isIndented()
161: */
162: public boolean isIndented() {
163: return false;
164: }
165:
166: /*
167: * @see org.eclipse.ui.views.properties.tabbed.ITabItem#isSelected()
168: */
169: public boolean isSelected() {
170: return false;
171: }
172:
173: /**
174: * Set the list of section descriptors for the tab.
175: *
176: * @param sectionDescriptors
177: * the list of section descriptors for the tab.
178: */
179: public void setSectionDescriptors(List sectionDescriptors) {
180: this.sectionDescriptors = sectionDescriptors;
181: }
182: }
|