1 package net.sourceforge.phpdt.externaltools.internal.registry;
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.group.IGroupDialogPage;
13 import net.sourceforge.phpdt.externaltools.internal.model.ToolMessages;
14 import net.sourceforge.phpdt.externaltools.variable.IVariableComponent;
15 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IConfigurationElement;
19 import org.eclipse.jface.resource.JFaceColors;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Control;
24 import org.eclipse.swt.widgets.Label;
27 * Abtract representation of the different variables.
29 public abstract class ExternalToolVariable {
30 private static final IVariableComponent defaultComponent = new DefaultVariableComponent(false);
33 private String description;
34 private IConfigurationElement element;
37 * Creates an variable definition
39 * @param tag the variable tag
40 * @param description a short description of what the variable will expand to
41 * @param element the configuration element
43 /*package*/ ExternalToolVariable(String tag, String description, IConfigurationElement element) {
46 this.description = description;
47 this.element = element;
51 * Creates an instance of the class specified by
52 * the given element attribute name. Can return
53 * <code>null</code> if none or if problems creating
56 protected final Object createObject(String attributeName) {
58 return element.createExecutableExtension(attributeName);
59 } catch (CoreException e) {
60 PHPeclipsePlugin.getDefault().getLog().log(e.getStatus());
66 * Returns the component class to allow
67 * visual editing of the variable's value.
69 public final IVariableComponent getComponent() {
70 String className = element.getAttribute(ExternalToolVariableRegistry.TAG_COMPONENT_CLASS);
71 if (className == null || className.trim().length() == 0)
72 return defaultComponent;
74 Object component = createObject(ExternalToolVariableRegistry.TAG_COMPONENT_CLASS);
75 if (component == null)
76 return new DefaultVariableComponent(true);
78 return (IVariableComponent)component;
82 * Returns the variable's description
84 public final String getDescription() {
89 * Returns the variable's tag
91 public final String getTag() {
97 * Default variable component implementation which does not
98 * allow variable value editing visually.
100 private static final class DefaultVariableComponent implements IVariableComponent {
101 private boolean showError = false;
102 private Label message = null;
104 public DefaultVariableComponent(boolean showError) {
106 this.showError = showError;
110 * Method declared on IVariableComponent.
112 public Control getControl() {
117 * Method declared on IVariableComponent.
119 public void createContents(Composite parent, String varTag, IGroupDialogPage page) {
121 message = new Label(parent, SWT.NONE);
122 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
123 message.setLayoutData(data);
124 message.setFont(parent.getFont());
125 message.setText(ToolMessages.getString("ExternalToolVariable.componentErrorMessage")); //$NON-NLS-1$
126 message.setForeground(JFaceColors.getErrorText(message.getDisplay()));
131 * Method declared on IVariableComponent.
133 public String getVariableValue() {
138 * Method declared on IVariableComponent.
140 public boolean isValid() {
145 * Method declared on IVariableComponent.
147 public void setVariableValue(String varValue) {
151 * Method declared on IVariableComponent.
153 public void validate() {