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.ExternalToolsModelMessages;
14 import net.sourceforge.phpdt.externaltools.variable.IVariableComponent;
15 import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin;
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(
35 private String description;
37 private IConfigurationElement element;
40 * Creates an variable definition
45 * a short description of what the variable will expand to
47 * the configuration element
49 /* package */ExternalToolVariable(String tag, String description,
50 IConfigurationElement element) {
53 this.description = description;
54 this.element = element;
58 * Creates an instance of the class specified by the given element attribute
59 * name. Can return <code>null</code> if none or if problems creating the
62 protected final Object createObject(String attributeName) {
64 return element.createExecutableExtension(attributeName);
65 } catch (CoreException e) {
66 ExternalToolsPlugin.getDefault().getLog().log(e.getStatus());
72 * Returns the component class to allow visual editing of the variable's
75 public final IVariableComponent getComponent() {
76 String className = element
77 .getAttribute(ExternalToolVariableRegistry.TAG_COMPONENT_CLASS);
78 if (className == null || className.trim().length() == 0)
79 return defaultComponent;
81 Object component = createObject(ExternalToolVariableRegistry.TAG_COMPONENT_CLASS);
82 if (component == null)
83 return new DefaultVariableComponent(true);
85 return (IVariableComponent) component;
89 * Returns the variable's description
91 public final String getDescription() {
96 * Returns the variable's tag
98 public final String getTag() {
103 * Default variable component implementation which does not allow variable
104 * value editing visually.
106 private static final class DefaultVariableComponent implements
108 private boolean showError = false;
110 private Label message = null;
112 public DefaultVariableComponent(boolean showError) {
114 this.showError = showError;
118 * (non-Javadoc) Method declared on IVariableComponent.
120 public Control getControl() {
125 * (non-Javadoc) Method declared on IVariableComponent.
127 public void createContents(Composite parent, String varTag,
128 IGroupDialogPage page) {
130 message = new Label(parent, SWT.NONE);
131 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
132 message.setLayoutData(data);
133 message.setFont(parent.getFont());
135 .setText(ExternalToolsModelMessages
136 .getString("ExternalToolVariable.componentErrorMessage")); //$NON-NLS-1$
137 message.setForeground(JFaceColors.getErrorText(message
143 * (non-Javadoc) Method declared on IVariableComponent.
145 public String getVariableValue() {
150 * (non-Javadoc) Method declared on IVariableComponent.
152 public boolean isValid() {
157 * (non-Javadoc) Method declared on IVariableComponent.
159 public void setVariableValue(String varValue) {
163 * (non-Javadoc) Method declared on IVariableComponent.
165 public void validate() {