KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bull > eclipse > jonas > editors > ProjectListElement


1 package com.bull.eclipse.jonas.editors;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6 import org.eclipse.core.resources.IProject;
7 import org.eclipse.core.resources.IWorkspaceRoot;
8 import org.eclipse.core.resources.ResourcesPlugin;
9
10 public class ProjectListElement {
11
12     IProject project;
13
14     public ProjectListElement(IProject project) {
15         super();
16         this.project = project;
17     }
18
19     public ProjectListElement(String JavaDoc name) {
20         super();
21 // this.project = project;
22
}
23
24
25
26
27     public String JavaDoc toString() {
28         return getID(project);
29     }
30     
31     public String JavaDoc getID() {
32         return getID(project);
33     }
34     
35     static protected String JavaDoc getID(IProject project) {
36         return project.getName();
37     }
38     
39     static public List JavaDoc stringsToProjectsList(List JavaDoc projectIdList) {
40         IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
41         IProject[] projects = root.getProjects();
42         
43     List JavaDoc selectedProjects = new ArrayList JavaDoc();
44         for(int i=0; i<projects.length; i++) {
45             if(projectIdList.contains(getID(projects[i]))) {
46                 selectedProjects.add(new ProjectListElement(projects[i]));
47             }
48         }
49
50         return selectedProjects;
51     }
52     
53     /*
54      * @see Object#equals(Object)
55      */

56     public boolean equals(Object JavaDoc obj) {
57         if(obj instanceof ProjectListElement)
58             return this.getID().equals(((ProjectListElement)obj).getID());
59
60         return false;
61     }
62
63     /*
64      * @see Object#hashCode()
65      */

66     public int hashCode() {
67         return this.getID().hashCode();
68     }
69
70     /**
71      * Gets the project.
72      * @return Returns a IProject
73      */

74     public IProject getProject() {
75         return project;
76     }
77
78
79 }
80
Popular Tags