01: package org.tcat.citd.sim.udig.bookmarks.internal;
02:
03: import java.util.Collection;
04: import java.util.Vector;
05:
06: import net.refractions.udig.project.IProject;
07:
08: /**
09: * This class provides a wrapper for displaying <code>IProject</code> objects as folders in the
10: * <code>BookmarksView</code>.<BR>
11: * <BR>
12: * This gives the advantage of more easily displaying custom menus and icons.
13: * <p>
14: * </p>
15: *
16: * @author cole.markham
17: * @since 1.0.0
18: */
19: public class ProjectWrapper {
20: private IProject project;
21:
22: /**
23: * Default constructor
24: *
25: * @param project The project that this object will wrap.
26: */
27: public ProjectWrapper(IProject project) {
28: this .project = project;
29: }
30:
31: /**
32: * @return Returns the project.
33: */
34: public IProject getProject() {
35: return project;
36: }
37:
38: /**
39: * @param project The project to set.
40: */
41: public void setProject(IProject project) {
42: this .project = project;
43: }
44:
45: /**
46: * Get the name for the project
47: *
48: * @return the name
49: */
50: public String getName() {
51: return project.getName();
52: }
53:
54: @Override
55: public String toString() {
56: return this .getName();
57: }
58:
59: /**
60: * Unwrap all of the projects in the given list
61: *
62: * @param wrappedProjects
63: * @return a List of IProject objects
64: */
65: public static Collection<IProject> unwrap(Collection wrappedProjects) {
66: Vector<IProject> projects = new Vector<IProject>(
67: wrappedProjects.size());
68: for (Object element : wrappedProjects) {
69: if (element instanceof ProjectWrapper) {
70: ProjectWrapper wrapper = (ProjectWrapper) element;
71: projects.add(wrapper.getProject());
72: }
73: }
74: return projects;
75: }
76:
77: /**
78: * Wrap the projects in the given list
79: *
80: * @param projects
81: * @return a List of ProjectWrapper objects
82: */
83: public static Collection<ProjectWrapper> wrap(
84: Collection<IProject> projects) {
85: Vector<ProjectWrapper> wrapped = new Vector<ProjectWrapper>(
86: projects.size());
87: for (IProject project : projects) {
88: wrapped.add(new ProjectWrapper(project));
89: }
90: return wrapped;
91: }
92: }
|