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 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;
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.
28 * This class is not intended to be extended by clients.
31 public class SpecificFolderResourceComponent extends ResourceComponent {
36 public SpecificFolderResourceComponent() {
41 * Method declared on ResourceComponent.
43 protected void createSelectedResourceOption() {
44 // Do not present this option...
48 * Method declared on ResourceComponent.
50 protected void createResourceList() {
51 super.createResourceList();
52 if (resourceList != null)
53 resourceList.addFilter(new FileFilter());
57 * Method declared on ResourceComponent.
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$
68 * Method declared on ResourceComponent.
70 protected boolean validateResourceListSelection() {
71 if (resourceList == null)
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$
87 * Filter to remove any IFile resources.
89 private static final class FileFilter extends ViewerFilter {
91 * Method declared on ViewerFilter.
93 public boolean select(Viewer viewer, Object parentElement, Object element) {
94 IResource resource = null;
95 if (element instanceof IResource) {
96 resource = (IResource) element;
98 if (element instanceof IAdaptable) {
99 IAdaptable adaptable = (IAdaptable) element;
100 resource = (IResource) adaptable.getAdapter(IResource.class);
104 if (resource != null)
105 return resource.getType() != IResource.FILE;