KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > ui > sourcelookup > WorkingSetSourceContainer


1 /*******************************************************************************
2  * Copyright (c) 2003, 2005 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.debug.ui.sourcelookup;
12
13 import java.util.ArrayList JavaDoc;
14 import org.eclipse.core.resources.IFolder;
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IAdaptable;
19 import org.eclipse.debug.core.sourcelookup.ISourceContainer;
20 import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
21 import org.eclipse.debug.core.sourcelookup.containers.CompositeSourceContainer;
22 import org.eclipse.debug.core.sourcelookup.containers.FolderSourceContainer;
23 import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer;
24 import org.eclipse.debug.internal.ui.DebugUIPlugin;
25 import org.eclipse.ui.IWorkingSet;
26
27 /**
28  * A working set in the workspace. Source is searched for in the projects (referenced
29  * projects) and folders (sub-folders) that are part of the working set.
30  * <p>
31  * This class may be instantiated; it is not intended to be subclassed.
32  * </p>
33  * @since 3.0
34  */

35 public class WorkingSetSourceContainer extends CompositeSourceContainer{
36     
37     private IWorkingSet fWorkingSet;
38     /**
39      * Unique identifier for the working set source container type
40      * (value <code>org.eclipse.debug.ui.containerType.workingSet</code>.)
41      */

42     public static final String JavaDoc TYPE_ID = DebugUIPlugin.getUniqueIdentifier()+".containerType.workingSet"; //$NON-NLS-1$
43

44     /**
45      * Creates a source container for the working set.
46      * @param workingSet the working set represented by this container
47      */

48     public WorkingSetSourceContainer(IWorkingSet workingSet) {
49         fWorkingSet = workingSet;
50     }
51     
52     /* (non-Javadoc)
53      * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getName()
54      */

55     public String JavaDoc getName() {
56         return fWorkingSet.getName();
57     }
58     
59     /* (non-Javadoc)
60      * @see java.lang.Object#equals(java.lang.Object)
61      */

62     public boolean equals(Object JavaDoc obj) {
63         if (obj != null && obj instanceof WorkingSetSourceContainer) {
64             return ((WorkingSetSourceContainer)obj).fWorkingSet.equals(fWorkingSet);
65         }
66         return false;
67     }
68
69     public int hashCode() {
70         return fWorkingSet.hashCode();
71     }
72     
73     /* (non-Javadoc)
74      * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getType()
75      */

76     public ISourceContainerType getType() {
77         return getSourceContainerType(TYPE_ID);
78     }
79             
80     /* (non-Javadoc)
81      * @see org.eclipse.debug.core.sourcelookup.containers.CompositeSourceContainer#createSourceContainers()
82      */

83     protected ISourceContainer[] createSourceContainers() throws CoreException {
84         IAdaptable[] elements = fWorkingSet.getElements();
85         
86         if(elements == null)
87             return new ISourceContainer[0];
88         
89         ArrayList JavaDoc locationList = new ArrayList JavaDoc();
90         for (int i = 0; i < elements.length; i++) {
91             IResource resource = (IResource) elements[i].getAdapter(IResource.class);
92             
93             if (resource != null) {
94                 switch (resource.getType()) {
95                 case IResource.FOLDER:
96                     locationList.add(new FolderSourceContainer((IFolder)resource, true));
97                     break;
98                 case IResource.PROJECT:
99                     locationList.add(new ProjectSourceContainer((IProject)resource, true));
100                     break;
101                     //if the element corresponds to an IFile, do nothing
102
}
103             }
104         }
105         return (ISourceContainer[])locationList.toArray(new ISourceContainer[locationList.size()]);
106     }
107
108 }
109
Popular Tags