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
26 * value for the working directory. Variable is limited to a specific
27 * <code>IContainer</code> resource.
29 * This class is not intended to be extended by clients.
32 public class SpecificFolderResourceComponent extends ResourceComponent {
37 public SpecificFolderResourceComponent() {
42 * Method declared on ResourceComponent.
44 protected void createSelectedResourceOption() {
45 // Do not present this option...
49 * Method declared on ResourceComponent.
51 protected void createResourceList() {
52 super.createResourceList();
53 if (resourceList != null)
54 resourceList.addFilter(new FileFilter());
58 * 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.getString("ResourceComponent.specificResLabel")); //$NON-NLS-1$
69 * Method declared on ResourceComponent.
71 protected boolean validateResourceListSelection() {
72 if (resourceList == null)
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$
88 * Filter to remove any IFile resources.
90 private static final class FileFilter extends ViewerFilter {
92 * Method declared on ViewerFilter.
94 public boolean select(Viewer viewer, Object parentElement, Object element) {
95 IResource resource = null;
96 if (element instanceof IResource) {
97 resource = (IResource) element;
99 if (element instanceof IAdaptable) {
100 IAdaptable adaptable = (IAdaptable) element;
101 resource = (IResource) adaptable.getAdapter(IResource.class);
105 if (resource != null)
106 return resource.getType() != IResource.FILE;