X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/variable/ResourceComponent.java b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/variable/ResourceComponent.java index 143a6e6..a4b422b 100644 --- a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/variable/ResourceComponent.java +++ b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/variable/ResourceComponent.java @@ -1,13 +1,13 @@ package net.sourceforge.phpdt.externaltools.variable; /********************************************************************** -Copyright (c) 2002 IBM Corp. and others. All rights reserved. -This file is made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v10.html - -Contributors: -**********************************************************************/ + Copyright (c) 2002 IBM Corp. and others. All rights reserved. + This file is made available under the terms of the Common Public License v1.0 + which accompanies this distribution, and is available at + http://www.eclipse.org/legal/cpl-v10.html + � + Contributors: + **********************************************************************/ import net.sourceforge.phpdt.externaltools.group.IGroupDialogPage; import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsModelMessages; @@ -35,22 +35,26 @@ import org.eclipse.ui.model.WorkbenchContentProvider; import org.eclipse.ui.model.WorkbenchLabelProvider; /** - * Visual component to edit the resource type variable - * value. + * Visual component to edit the resource type variable value. *
* This class is not intended to be extended by clients. *
*/ public class ResourceComponent implements IVariableComponent { private IGroupDialogPage page; + private boolean isValid = true; - + protected Group mainGroup; + protected Button selectedResourceButton; + protected Button specificResourceButton; + protected TreeViewer resourceList; + private IResource selectedResource; - + /** * Creates the component */ @@ -58,12 +62,13 @@ public class ResourceComponent implements IVariableComponent { super(); } - /* (non-Javadoc) - * Method declared on IVariableComponent. + /* + * (non-Javadoc) Method declared on IVariableComponent. */ - public void createContents(Composite parent, String varTag, IGroupDialogPage page) { + public void createContents(Composite parent, String varTag, + IGroupDialogPage page) { this.page = page; - + // main composite mainGroup = new Group(parent, SWT.NONE); GridLayout layout = new GridLayout(); @@ -75,11 +80,11 @@ public class ResourceComponent implements IVariableComponent { mainGroup.setLayoutData(gridData); mainGroup.setFont(parent.getFont()); mainGroup.setText(ToolUtil.buildVariableTag(varTag, null)); - + createSelectedResourceOption(); createSpecificResourceOption(); createResourceList(); - + updateResourceListEnablement(); } @@ -92,53 +97,55 @@ public class ResourceComponent implements IVariableComponent { data.heightHint = tree.getItemHeight() * getInitialVisibleItemCount(); tree.setLayoutData(data); tree.setFont(mainGroup.getFont()); - + resourceList = new TreeViewer(tree); - resourceList.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - validateResourceListSelection(); - selectedResource= (IResource) ((IStructuredSelection)event.getSelection()).getFirstElement(); - } - }); + resourceList + .addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + validateResourceListSelection(); + selectedResource = (IResource) ((IStructuredSelection) event + .getSelection()).getFirstElement(); + } + }); resourceList.setContentProvider(new WorkbenchContentProvider()); resourceList.setLabelProvider(new WorkbenchLabelProvider()); resourceList.setInput(ResourcesPlugin.getWorkspace().getRoot()); } - + /** - * Creates the option button for using the selected - * resource. + * Creates the option button for using the selected resource. */ protected void createSelectedResourceOption() { selectedResourceButton = new Button(mainGroup, SWT.RADIO); - selectedResourceButton.setText(ExternalToolsModelMessages.getString("ResourceComponent.selectedResLabel")); //$NON-NLS-1$ + selectedResourceButton.setText(ExternalToolsModelMessages + .getString("ResourceComponent.selectedResLabel")); //$NON-NLS-1$ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); selectedResourceButton.setLayoutData(data); selectedResourceButton.setFont(mainGroup.getFont()); selectedResourceButton.setSelection(true); } - + /** - * Creates the option button for using a specific - * resource. + * Creates the option button for using a specific resource. */ protected void createSpecificResourceOption() { specificResourceButton = new Button(mainGroup, SWT.RADIO); - specificResourceButton.setText(ExternalToolsModelMessages.getString("ResourceComponent.specificResLabel")); //$NON-NLS-1$ + specificResourceButton.setText(ExternalToolsModelMessages + .getString("ResourceComponent.specificResLabel")); //$NON-NLS-1$ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); specificResourceButton.setLayoutData(data); specificResourceButton.setFont(mainGroup.getFont()); specificResourceButton.setSelection(false); - + specificResourceButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { updateResourceListEnablement(); } }); } - - /* (non-Javadoc) - * Method declared on IVariableComponent. + + /* + * (non-Javadoc) Method declared on IVariableComponent. */ public Control getControl() { return mainGroup; @@ -150,44 +157,46 @@ public class ResourceComponent implements IVariableComponent { protected final IGroupDialogPage getPage() { return page; } - - /* (non-Javadoc) - * Method declared on IVariableComponent. + + /* + * (non-Javadoc) Method declared on IVariableComponent. */ public String getVariableValue() { - if (selectedResourceButton != null && selectedResourceButton.getSelection()) + if (selectedResourceButton != null + && selectedResourceButton.getSelection()) return null; - + if (resourceList != null) { if (selectedResource != null) return selectedResource.getFullPath().toString(); } - + return null; } /** - * Returns the number of items to be visible in the - * resource list. This will determine the initial height. + * Returns the number of items to be visible in the resource list. This will + * determine the initial height. */ protected int getInitialVisibleItemCount() { return 10; } - - /* (non-Javadoc) - * Method declared on IVariableComponent. + + /* + * (non-Javadoc) Method declared on IVariableComponent. */ public boolean isValid() { return isValid; } /** - * Sets whether the component's values are all valid. - * Updates the components's page valid state. No action - * taken if new valid state same as current one. + * Sets whether the component's values are all valid. Updates the + * components's page valid state. No action taken if new valid state same as + * current one. * - * @param isValidtrue
if all values valid,
- * false
otherwise
+ * @param isValid
+ * true
if all values valid, false
+ * otherwise
*/
protected final void setIsValid(boolean isValid) {
if (this.isValid != isValid) {
@@ -195,17 +204,18 @@ public class ResourceComponent implements IVariableComponent {
this.page.updateValidState();
}
}
-
+
/**
* Updates the enablement of the resource list if needed
*/
protected void updateResourceListEnablement() {
if (specificResourceButton != null && resourceList != null)
- resourceList.getTree().setEnabled(specificResourceButton.getSelection());
+ resourceList.getTree().setEnabled(
+ specificResourceButton.getSelection());
}
-
- /* (non-Javadoc)
- * Method declared on IVariableComponent.
+
+ /*
+ * (non-Javadoc) Method declared on IVariableComponent.
*/
public void setVariableValue(String varValue) {
if (varValue == null || varValue.length() == 0) {
@@ -222,20 +232,23 @@ public class ResourceComponent implements IVariableComponent {
specificResourceButton.setSelection(true);
if (resourceList != null) {
resourceList.getTree().setEnabled(true);
- IResource member = ResourcesPlugin.getWorkspace().getRoot().findMember(varValue);
+ IResource member = ResourcesPlugin.getWorkspace().getRoot()
+ .findMember(varValue);
if (member != null)
- resourceList.setSelection(new StructuredSelection(member), true);
+ resourceList.setSelection(new StructuredSelection(member),
+ true);
else
resourceList.setSelection(StructuredSelection.EMPTY);
}
}
}
-
- /* (non-Javadoc)
- * Method declared on IVariableComponent.
+
+ /*
+ * (non-Javadoc) Method declared on IVariableComponent.
*/
public void validate() {
- if (specificResourceButton != null && specificResourceButton.getSelection()) {
+ if (specificResourceButton != null
+ && specificResourceButton.getSelection()) {
validateResourceListSelection();
}
@@ -244,22 +257,25 @@ public class ResourceComponent implements IVariableComponent {
}
/**
- * Returns whether that the resource list selection is valid.
- * If the list was not created, returns true
.
+ * Returns whether that the resource list selection is valid. If the list
+ * was not created, returns true
.
*
- * @return true
to continue validating other
- * fields, false
to stop.
+ * @return true
to continue validating other fields,
+ * false
to stop.
*/
protected boolean validateResourceListSelection() {
if (resourceList == null)
return true;
if (resourceList.getSelection().isEmpty()) {
- getPage().setMessage(ExternalToolsModelMessages.getString("ResourceComponent.selectionRequired"), IMessageProvider.WARNING); //$NON-NLS-1$
+ getPage()
+ .setMessage(
+ ExternalToolsModelMessages
+ .getString("ResourceComponent.selectionRequired"), IMessageProvider.WARNING); //$NON-NLS-1$
setIsValid(false);
return false;
}
-
+
return true;
}
}