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