Use abstraction of PHPOutlinePage
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / externaltools / variable / SpecificFileResourceComponent.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.jface.dialogs.IMessageProvider;
14 import org.eclipse.jface.viewers.IStructuredSelection;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.widgets.Label;
18 import net.sourceforge.phpdt.externaltools.internal.model.ToolMessages;
19
20 /**
21  * Visual component to edit the resource type variable
22  * value for the file location. Variable is limited to a specific
23  * <code>IFile</code> resource.
24  * <p>
25  * This class is not intended to be extended by clients.
26  * </p>
27  */
28 public class SpecificFileResourceComponent extends ResourceComponent {
29
30         /**
31          * Creates an instance
32          */
33         public SpecificFileResourceComponent() {
34                 super();
35         }
36
37         /* (non-Javadoc)
38          * Method declared on ResourceComponent.
39          */
40         protected void createSelectedResourceOption() {
41                 // Do not present this option...
42         }
43         
44         /* (non-Javadoc)
45          * Method declared on ResourceComponent.
46          */
47         protected void createSpecificResourceOption() {
48                 Label label = new Label(mainGroup, SWT.NONE);
49                 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
50                 label.setLayoutData(data);
51                 label.setFont(mainGroup.getFont());
52                 label.setText(ToolMessages.getString("ResourceComponent.specificResLabel")); //$NON-NLS-1$
53         }
54
55         /* (non-Javadoc)
56          * Method declared on ResourceComponent.
57          */
58         protected boolean validateResourceListSelection() {
59                 if (resourceList == null)
60                         return true;
61                         
62                 IStructuredSelection sel = (IStructuredSelection) resourceList.getSelection();
63                 IResource resource = (IResource) sel.getFirstElement();
64                 if (resource == null || resource.getType() != IResource.FILE) {
65                         getPage().setMessage(ToolMessages.getString("ResourceComponent.selectionRequired"), IMessageProvider.WARNING); //$NON-NLS-1$
66                         setIsValid(false);
67                         return false;
68                 }
69                 
70                 return true;
71         }
72 }