Fix SourceLookupMessage constant.(SourceLookupMessages.DefaultSourceContainer_0 eclip...
[phpeclipse.git] / net.sourceforge.phpeclipse.externaltools / 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 value for the working
26  * directory. Variable is limited to a specific <code>IContainer</code>
27  * 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         /*
42          * (non-Javadoc) Method declared on ResourceComponent.
43          */
44         protected void createSelectedResourceOption() {
45                 // Do not present this option...
46         }
47
48         /*
49          * (non-Javadoc) Method declared on ResourceComponent.
50          */
51         protected void createResourceList() {
52                 super.createResourceList();
53                 if (resourceList != null)
54                         resourceList.addFilter(new FileFilter());
55         }
56
57         /*
58          * (non-Javadoc) 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
66                                 .getString("ResourceComponent.specificResLabel")); //$NON-NLS-1$
67         }
68
69         /*
70          * (non-Javadoc) Method declared on ResourceComponent.
71          */
72         protected boolean validateResourceListSelection() {
73                 if (resourceList == null)
74                         return true;
75
76                 IStructuredSelection sel = (IStructuredSelection) resourceList
77                                 .getSelection();
78                 IResource resource = (IResource) sel.getFirstElement();
79                 if (resource == null || resource.getType() == IResource.FILE) {
80                         getPage()
81                                         .setMessage(
82                                                         ExternalToolsModelMessages
83                                                                         .getString("ResourceComponent.selectionRequired"), IMessageProvider.WARNING); //$NON-NLS-1$
84                         setIsValid(false);
85                         return false;
86                 }
87
88                 return true;
89         }
90
91         /**
92          * Filter to remove any IFile resources.
93          */
94         private static final class FileFilter extends ViewerFilter {
95                 /*
96                  * (non-Javadoc) Method declared on ViewerFilter.
97                  */
98                 public boolean select(Viewer viewer, Object parentElement,
99                                 Object element) {
100                         IResource resource = null;
101                         if (element instanceof IResource) {
102                                 resource = (IResource) element;
103                         } else {
104                                 if (element instanceof IAdaptable) {
105                                         IAdaptable adaptable = (IAdaptable) element;
106                                         resource = (IResource) adaptable
107                                                         .getAdapter(IResource.class);
108                                 }
109                         }
110
111                         if (resource != null)
112                                 return resource.getType() != IResource.FILE;
113                         else
114                                 return false;
115                 }
116         }
117 }