added class const identifiers to outline
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / externaltools / variable / SpecificFolderResourceComponent.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 net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsModelMessages;
13
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.runtime.IAdaptable;
16 import org.eclipse.jface.dialogs.IMessageProvider;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18 import org.eclipse.jface.viewers.Viewer;
19 import org.eclipse.jface.viewers.ViewerFilter;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.widgets.Label;
23
24 /**
25  * Visual component to edit the resource type variable
26  * value for the working directory. Variable is limited to a specific
27  * <code>IContainer</code> resource.
28  * <p>
29  * This class is not intended to be extended by clients.
30  * </p>
31  */
32 public class SpecificFolderResourceComponent extends ResourceComponent {
33
34         /**
35          * Creates an instance
36          */
37         public SpecificFolderResourceComponent() {
38                 super();
39         }
40
41         /* (non-Javadoc)
42          * Method declared on ResourceComponent.
43          */
44         protected void createSelectedResourceOption() {
45                 // Do not present this option...
46         }
47         
48         /* (non-Javadoc)
49          * Method declared on ResourceComponent.
50          */
51         protected void createResourceList() {
52                 super.createResourceList();
53                 if (resourceList != null)
54                         resourceList.addFilter(new FileFilter());
55         }
56
57         /* (non-Javadoc)
58          * Method declared on ResourceComponent.
59          */
60         protected void createSpecificResourceOption() {
61                 Label label = new Label(mainGroup, SWT.NONE);
62                 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
63                 label.setLayoutData(data);
64                 label.setFont(mainGroup.getFont());
65                 label.setText(ExternalToolsModelMessages.getString("ResourceComponent.specificResLabel")); //$NON-NLS-1$
66         }
67
68         /* (non-Javadoc)
69          * Method declared on ResourceComponent.
70          */
71         protected boolean validateResourceListSelection() {
72                 if (resourceList == null)
73                         return true;
74                         
75                 IStructuredSelection sel = (IStructuredSelection) resourceList.getSelection();
76                 IResource resource = (IResource) sel.getFirstElement();
77                 if (resource == null || resource.getType() == IResource.FILE) {
78                         getPage().setMessage(ExternalToolsModelMessages.getString("ResourceComponent.selectionRequired"), IMessageProvider.WARNING); //$NON-NLS-1$
79                         setIsValid(false);
80                         return false;
81                 }
82                 
83                 return true;
84         }
85         
86         
87         /**
88          * Filter to remove any IFile resources.
89          */
90         private static final class FileFilter extends ViewerFilter {
91                 /* (non-Javadoc)
92                  * Method declared on ViewerFilter.
93                  */
94                 public boolean select(Viewer viewer, Object parentElement, Object element) {
95                         IResource resource = null;
96                         if (element instanceof IResource) {
97                                 resource = (IResource) element;
98                         } else {
99                                 if (element instanceof IAdaptable) {
100                                         IAdaptable adaptable = (IAdaptable) element;
101                                         resource = (IResource) adaptable.getAdapter(IResource.class);
102                                 }
103                         }
104                         
105                         if (resource != null)
106                                 return resource.getType() != IResource.FILE;
107                         else
108                                 return false;
109                 }
110         }
111 }