1 package net.sourceforge.phpdt.externaltools.variable;
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
10 **********************************************************************/
12 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsModelMessages;
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;
25 * Visual component to edit the resource type variable value for the working
26 * directory. Variable is limited to a specific <code>IContainer</code>
29 * This class is not intended to be extended by clients.
32 public class SpecificFolderResourceComponent extends ResourceComponent {
37 public SpecificFolderResourceComponent() {
42 * (non-Javadoc) Method declared on ResourceComponent.
44 protected void createSelectedResourceOption() {
45 // Do not present this option...
49 * (non-Javadoc) Method declared on ResourceComponent.
51 protected void createResourceList() {
52 super.createResourceList();
53 if (resourceList != null)
54 resourceList.addFilter(new FileFilter());
58 * (non-Javadoc) Method declared on ResourceComponent.
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$
70 * (non-Javadoc) Method declared on ResourceComponent.
72 protected boolean validateResourceListSelection() {
73 if (resourceList == null)
76 IStructuredSelection sel = (IStructuredSelection) resourceList
78 IResource resource = (IResource) sel.getFirstElement();
79 if (resource == null || resource.getType() == IResource.FILE) {
82 ExternalToolsModelMessages
83 .getString("ResourceComponent.selectionRequired"), IMessageProvider.WARNING); //$NON-NLS-1$
92 * Filter to remove any IFile resources.
94 private static final class FileFilter extends ViewerFilter {
96 * (non-Javadoc) Method declared on ViewerFilter.
98 public boolean select(Viewer viewer, Object parentElement,
100 IResource resource = null;
101 if (element instanceof IResource) {
102 resource = (IResource) element;
104 if (element instanceof IAdaptable) {
105 IAdaptable adaptable = (IAdaptable) element;
106 resource = (IResource) adaptable
107 .getAdapter(IResource.class);
111 if (resource != null)
112 return resource.getType() != IResource.FILE;