KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > site > SiteFeatureAdapter


1 /*******************************************************************************
2  * Copyright (c) 2003, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.editor.site;
12
13 import java.io.PrintWriter JavaDoc;
14 import java.io.Serializable JavaDoc;
15
16 import org.eclipse.pde.core.IWritable;
17 import org.eclipse.pde.internal.core.isite.ISiteFeature;
18
19 public class SiteFeatureAdapter implements Serializable JavaDoc, IWritable {
20
21     private static final long serialVersionUID = 1L;
22
23     String JavaDoc category;
24     ISiteFeature feature;
25
26     public SiteFeatureAdapter(String JavaDoc category, ISiteFeature feature) {
27         this.category = category;
28         this.feature = feature;
29     }
30
31     /* (non-Javadoc)
32      * @see org.eclipse.pde.core.IWritable#write(java.lang.String, java.io.PrintWriter)
33      */

34     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
35         feature.write(indent, writer);
36     }
37
38     /*
39      * For retaining selectiong in the tree, when modyfing or moving features,
40      * SiteFeatureAdapter are equal if features are equal (same ID and version)
41      *
42      * @see java.lang.Object#equals(java.lang.Object)
43      */

44     public boolean equals(Object JavaDoc obj) {
45         if (obj instanceof SiteFeatureAdapter) {
46             SiteFeatureAdapter adapter = (SiteFeatureAdapter) obj;
47             String JavaDoc id = feature.getId();
48             String JavaDoc id2 = adapter.feature.getId();
49             boolean sameFeature = id != null && id2 != null && id.equals(id2);
50             if (sameFeature) {
51                 String JavaDoc version = feature.getVersion();
52                 String JavaDoc version2 = adapter.feature.getVersion();
53                 sameFeature = version != null && version2 != null && version.equals(version2);
54             }
55             boolean sameCategory = adapter.category != null && category != null
56                                         ? adapter.category.equals(category) : true;
57             return sameFeature && sameCategory;
58         }
59         return super.equals(obj);
60     }
61     /* (non-Javadoc)
62      * @see java.lang.Object#hashCode()
63      */

64     public int hashCode() {
65         int code = feature.getId().hashCode()+feature.getVersion().hashCode();
66         if(category!=null){
67             code+=category.hashCode();
68         }
69         return code;
70     }
71 }
72
Popular Tags