01: /*******************************************************************************
02: * Copyright (c) 2003, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.site;
11:
12: import java.io.PrintWriter;
13: import java.io.Serializable;
14:
15: import org.eclipse.pde.core.IWritable;
16: import org.eclipse.pde.internal.core.isite.ISiteFeature;
17:
18: public class SiteFeatureAdapter implements Serializable, IWritable {
19:
20: private static final long serialVersionUID = 1L;
21:
22: String category;
23: ISiteFeature feature;
24:
25: public SiteFeatureAdapter(String category, ISiteFeature feature) {
26: this .category = category;
27: this .feature = feature;
28: }
29:
30: /* (non-Javadoc)
31: * @see org.eclipse.pde.core.IWritable#write(java.lang.String, java.io.PrintWriter)
32: */
33: public void write(String indent, PrintWriter writer) {
34: feature.write(indent, writer);
35: }
36:
37: /*
38: * For retaining selectiong in the tree, when modyfing or moving features,
39: * SiteFeatureAdapter are equal if features are equal (same ID and version)
40: *
41: * @see java.lang.Object#equals(java.lang.Object)
42: */
43: public boolean equals(Object obj) {
44: if (obj instanceof SiteFeatureAdapter) {
45: SiteFeatureAdapter adapter = (SiteFeatureAdapter) obj;
46: String id = feature.getId();
47: String id2 = adapter.feature.getId();
48: boolean sameFeature = id != null && id2 != null
49: && id.equals(id2);
50: if (sameFeature) {
51: String version = feature.getVersion();
52: String version2 = adapter.feature.getVersion();
53: sameFeature = version != null && version2 != null
54: && version.equals(version2);
55: }
56: boolean sameCategory = adapter.category != null
57: && category != null ? adapter.category
58: .equals(category) : true;
59: return sameFeature && sameCategory;
60: }
61: return super .equals(obj);
62: }
63:
64: /* (non-Javadoc)
65: * @see java.lang.Object#hashCode()
66: */
67: public int hashCode() {
68: int code = feature.getId().hashCode()
69: + feature.getVersion().hashCode();
70: if (category != null) {
71: code += category.hashCode();
72: }
73: return code;
74: }
75: }
|