A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse.externaltools / src / net / sourceforge / phpdt / externaltools / variable / WorkingSetExpander.java
1 package net.sourceforge.phpdt.externaltools.variable;
2
3 /**********************************************************************
4  Copyright (c) 2002 IBM Corp. and others. All rights reserved.
5  This file is made available under the terms of the Common Public License v1.0
6  which accompanies this distribution, and is available at
7  http://www.eclipse.org/legal/cpl-v10.html
8  �
9  Contributors:
10  **********************************************************************/
11
12 import org.eclipse.core.resources.IResource;
13 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.ui.IWorkingSet;
15 import org.eclipse.ui.PlatformUI;
16
17 /**
18  * Expands a working set type variable into the desired result format.
19  * <p>
20  * This class is not intended to be extended by clients.
21  * </p>
22  */
23 public class WorkingSetExpander implements IVariableResourceExpander {
24
25         /**
26          * Create an instance
27          */
28         public WorkingSetExpander() {
29                 super();
30         }
31
32         /*
33          * (non-Javadoc) Method declared on IVariableResourceExpander.
34          */
35         public IResource[] getResources(String varTag, String varValue,
36                         ExpandVariableContext context) {
37                 if (varValue == null || varValue.length() == 0)
38                         return null;
39
40                 IWorkingSet set = PlatformUI.getWorkbench().getWorkingSetManager()
41                                 .getWorkingSet(varValue);
42                 if (set == null)
43                         return null;
44
45                 IAdaptable[] elements = set.getElements();
46                 IResource[] resources = new IResource[elements.length];
47                 for (int i = 0; i < elements.length; i++) {
48                         IAdaptable adaptable = elements[i];
49                         if (adaptable instanceof IResource)
50                                 resources[i] = (IResource) adaptable;
51                         else
52                                 resources[i] = (IResource) adaptable
53                                                 .getAdapter(IResource.class);
54                 }
55
56                 return resources;
57         }
58 }