Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Recoskie2011-03-09 22:28:20 +0000
committerChris Recoskie2011-03-09 22:28:20 +0000
commit928076556c8a4b0f331df02b59db9f63d2c13bd5 (patch)
tree7f923cf95427091601af0a3f48bb6dc200cd38eb /build/org.eclipse.cdt.managedbuilder.ui
parent35bb3c28336f7e6d5a7b1fdbce3262747b987817 (diff)
downloadorg.eclipse.cdt-928076556c8a4b0f331df02b59db9f63d2c13bd5.tar.gz
org.eclipse.cdt-928076556c8a4b0f331df02b59db9f63d2c13bd5.tar.xz
org.eclipse.cdt-928076556c8a4b0f331df02b59db9f63d2c13bd5.zip
Bug 320949 - Add ability to contribute custom field-editor GUI to the Build Option Settings page
Diffstat (limited to 'build/org.eclipse.cdt.managedbuilder.ui')
-rw-r--r--build/org.eclipse.cdt.managedbuilder.ui/plugin.properties1
-rw-r--r--build/org.eclipse.cdt.managedbuilder.ui/plugin.xml1
-rw-r--r--build/org.eclipse.cdt.managedbuilder.ui/schema/buildDefinitionsUI.exsd127
-rw-r--r--build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionSettingsUI.java122
-rw-r--r--build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ICustomBuildOptionEditor.java54
5 files changed, 300 insertions, 5 deletions
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties b/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties
index 8f36122bf02..f511362e8b3 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties
+++ b/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties
@@ -102,4 +102,5 @@ multicfg=Multiple Configurations Edit
# menu labels
Configurations.menu=Build Configurations
+buildDefinitionsUI.ep.name = Build Definitions UI
extension-point.name = Custom MBS New Wizard Pages \ No newline at end of file
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml
index d586182b82e..91b7a5ce094 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml
+++ b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml
@@ -2,6 +2,7 @@
<?eclipse version="3.0"?>
<plugin>
+ <extension-point id="buildDefinitionsUI" name="%buildDefinitionsUI.ep.name" schema="schema/buildDefinitionsUI.exsd"/>
<extension-point id="newWizardPages" name="%extension-point.name" schema="schema/newWizardPages.exsd"/>
<extension
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/schema/buildDefinitionsUI.exsd b/build/org.eclipse.cdt.managedbuilder.ui/schema/buildDefinitionsUI.exsd
new file mode 100644
index 00000000000..286aea816d8
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.ui/schema/buildDefinitionsUI.exsd
@@ -0,0 +1,127 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.cdt.managedbuilder.ui" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.cdt.managedbuilder.ui" id="buildDefinitionsUI" name="Build Definitions UI Extensions"/>
+ </appInfo>
+ <documentation>
+ This extension point allows for the contribution of various UI extensions which can be referenced from the &lt;code&gt;org.eclipse.cdt.managedbuilder.core.buildDefinitions&lt;/code&gt; extensions. Via this extension point, for example, the developer may contribute a custom JFace field-editor, which can then be referenced by its ID from an &lt;code&gt;&amp;lt;option&amp;gt;&lt;/code&gt; element of an &lt;code&gt;org.eclipse.cdt.managedbuilder.core.buildDefinitions&lt;/code&gt; extension.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="fieldEditor" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="fieldEditor">
+ <annotation>
+ <documentation>
+ This element can be used to contribute a custom JFace field-editor to represent a build-option in the project Properties dialog UI. Contributing a custom field-editor through this element is not enough - the custom field-editor must also be referenced by its ID from an &lt;code&gt;&amp;lt;option&amp;gt;&lt;/code&gt; element of an &lt;code&gt;org.eclipse.cdt.managedbuilder.core.buildDefinitions&lt;/code&gt; extension.
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ A unique identifier which will be used to reference this field-editor from an &lt;code&gt;&amp;lt;option&amp;gt;&lt;/code&gt; element of an &lt;code&gt;org.eclipse.cdt.managedbuilder.core.buildDefinitions&lt;/code&gt; extension.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ Specifies the Java class which implements the custom field-editor. This class must extend JFace&apos;s &lt;code&gt;FieldEditor&lt;/code&gt; abstract class, and implement the &lt;code&gt;ICustomBuildOptionEditor&lt;/code&gt; interface.
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn="org.eclipse.jface.preference.FieldEditor:org.eclipse.cdt.managedbuilder.ui.properties.ICustomBuildOptionEditor"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ 8.0
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ &lt;extension point=&quot;org.eclipse.cdt.managedbuilder.ui.buildDefinitionsUI&quot;&gt;
+ &lt;fieldEditor
+ id=&quot;org.eclipse.cdt.managedbuilder.ui.tests.fieldEditors.CustomFieldEditor&quot;
+ class=&quot;org.eclipse.cdt.managedbuilder.ui.tests.fieldEditors.CustomFieldEditor&quot;/&gt;
+&lt;/extension&gt;
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ None
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ None
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+ Copyright (c) 2011 Texas Instruments Incorporated and others.
+All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available on the &lt;a href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt; Eclipse&lt;/a&gt; website.
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionSettingsUI.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionSettingsUI.java
index 7e6c9955cc9..215d396cf62 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionSettingsUI.java
+++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionSettingsUI.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2010 IBM Corporation and others.
+ * Copyright (c) 2003, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
* IBM Rational Software - Initial API and implementation
* ARM Ltd. - basic tooltip support
* Miwako Tokugawa (Intel Corporation) - Fixed-location tooltip support
+ * Baltasar Belyavsky (Texas Instruments) - custom field-editor support
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.ui.properties;
@@ -38,6 +39,10 @@ import org.eclipse.cdt.managedbuilder.internal.ui.Messages;
import org.eclipse.cdt.managedbuilder.macros.BuildMacroException;
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
import org.eclipse.cdt.ui.newui.AbstractPage;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.DirectoryFieldEditor;
import org.eclipse.jface.preference.FieldEditor;
@@ -52,11 +57,14 @@ import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
+import org.osgi.framework.Bundle;
+
/**
* Option settings page in project properties Build Settings under Tool Settings tab.
@@ -70,6 +78,7 @@ public class BuildOptionSettingsUI extends AbstractToolSettingUI {
private IHoldsOptions[] ohs;
/** The index of the current IHoldsOptions in ohs */
private int curr = -1;
+ private Map<String, CustomFieldEditorDescriptor> customFieldEditorDescriptorIndex;
private Map<FieldEditor, Composite> fieldEditorsToParentMap =
new HashMap<FieldEditor, Composite>();
/** True if the user selected "Display tool option tips at a fixed location" in Preferences */
@@ -215,9 +224,35 @@ public class BuildOptionSettingsUI extends AbstractToolSettingUI {
// Figure out which type the option is and add a proper field
// editor for it
Composite fieldEditorParent = getFieldEditorParent();
- FieldEditor fieldEditor;
-
- switch (opt.getValueType()) {
+ FieldEditor fieldEditor = null;
+
+ String customFieldEditorId = opt.getFieldEditorId();
+ if(customFieldEditorId != null) {
+ fieldEditor = createCustomFieldEditor(customFieldEditorId);
+ if(fieldEditor != null) {
+ ICustomBuildOptionEditor customFieldEditor = (ICustomBuildOptionEditor)fieldEditor;
+ if(customFieldEditor.init(opt, opt.getFieldEditorExtraArgument(), optId, fieldEditorParent)) {
+ Control[] toolTipSources = customFieldEditor.getToolTipSources();
+ if(toolTipSources != null) {
+ for(Control control : toolTipSources) {
+ if(pageHasToolTipBox) {
+ control.setData(new TipInfo(nameStr,tipStr));
+ control.addListener(selectAction, tipSetListener);
+ }
+ else {
+ control.setToolTipText(tipStr);
+ }
+ }
+ }
+ }
+ else {
+ fieldEditor = null;
+ }
+ }
+ }
+
+ if(fieldEditor == null) {
+ switch (opt.getValueType()) {
case IOption.STRING: {
StringFieldEditor stringField;
@@ -378,8 +413,9 @@ public class BuildOptionSettingsUI extends AbstractToolSettingUI {
default:
throw new BuildException(null);
+ }
}
-
+
setFieldEditorEnablement(holder, opt, applicabilityCalculator, fieldEditor, fieldEditorParent);
addField(fieldEditor);
@@ -393,6 +429,82 @@ public class BuildOptionSettingsUI extends AbstractToolSettingUI {
}
/**
+ * Instantiates the custom-field editor registered under the given id.
+ */
+ private FieldEditor createCustomFieldEditor(String customFieldEditorId) {
+ if(this.customFieldEditorDescriptorIndex == null) {
+ loadCustomFieldEditorDescriptors();
+ }
+
+ CustomFieldEditorDescriptor editorDescriptor = this.customFieldEditorDescriptorIndex.get(customFieldEditorId);
+ if(editorDescriptor != null) {
+ return editorDescriptor.createEditor();
+ }
+
+ return null;
+ }
+
+ /**
+ * Holds all the information necessary to instantiate a custom field-editor.
+ * Also acts as a factory - instantiates and returns a non-initialized field-editor.
+ */
+ private class CustomFieldEditorDescriptor
+ {
+ private final String editorClassName;
+ private final String bundleName;
+
+ CustomFieldEditorDescriptor(String editorClassName, String bundleName) {
+ this.editorClassName = editorClassName;
+ this.bundleName = bundleName;
+ }
+
+ FieldEditor createEditor() {
+ try {
+ Bundle bundle = Platform.getBundle(this.bundleName);
+ if(bundle != null) {
+ Class<?> editorClass = bundle.loadClass(this.editorClassName);
+ if(editorClass != null) {
+ Object editor = editorClass.newInstance();
+ if(editor instanceof FieldEditor && editor instanceof ICustomBuildOptionEditor) {
+ return (FieldEditor)editor;
+ }
+ }
+ }
+ }
+ catch(Exception x) {
+ ManagedBuilderUIPlugin.log(x);
+ }
+
+ return null;
+ }
+ }
+
+ /**
+ * Loads all the registered custom field-editor descriptors.
+ * Synchronization is not necessary as this would always be invoked on the UI thread.
+ */
+ private void loadCustomFieldEditorDescriptors() {
+ if(this.customFieldEditorDescriptorIndex != null)
+ return;
+
+ this.customFieldEditorDescriptorIndex = new HashMap<String, CustomFieldEditorDescriptor>();
+
+ IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint(
+ ManagedBuilderUIPlugin.getUniqueIdentifier() + ".buildDefinitionsUI"); //$NON-NLS-1$
+
+ for(IExtension e : ep.getExtensions()) {
+ for(IConfigurationElement providerElement : e.getConfigurationElements()) {
+ String editorId = providerElement.getAttribute("id"); //$NON-NLS-1$
+ String editorClassName = providerElement.getAttribute("class"); //$NON-NLS-1$
+
+ String bundleName = providerElement.getContributor().getName();
+
+ this.customFieldEditorDescriptorIndex.put(editorId, new CustomFieldEditorDescriptor(editorClassName, bundleName));
+ }
+ }
+ }
+
+ /**
* Answers <code>true</code> if the settings page has been created for the
* option category specified in the argument.
*
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ICustomBuildOptionEditor.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ICustomBuildOptionEditor.java
new file mode 100644
index 00000000000..af2ce51c5f8
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ICustomBuildOptionEditor.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 Texas Instruments, and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Texas Instruments - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.managedbuilder.ui.properties;
+
+import org.eclipse.cdt.managedbuilder.core.IOption;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+
+/**
+ * This interface can be implemented by clients to contribute custom build-option
+ * editors to the CDT Build Settings page in the project Properties dialog.
+ *
+ * In addition to implementing this interface, the custom build-option editor class
+ * must also extend the {@link org.eclipse.jface.preference.FieldEditor} class. The
+ * custom build-option editor class should be contributed through the <fieldEditor>
+ * element of the org.eclipse.cdt.managedbuilder.ui.buildDefinitionsUI extension-point,
+ * and then referenced, by its ID, from the <option>/fieldEditorId attribute of the
+ * org.eclipse.cdt.managedbuilder.core.buildDefinitions extension-point.
+ *
+ * @since 8.0
+ */
+public interface ICustomBuildOptionEditor
+{
+ /**
+ * Initializes the custom field-editor.
+ *
+ * @param option the underlying build-option.
+ * @param extraArgument an optional {@link IOption#getFieldEditorExtraArgument() extra argument}
+ * for the field-editor. May be {@code null}.
+ * @param preferenceName the name of the preference this field editor binds to.
+ * @param parent the parent of the field editor's control.
+ * @return {@code true} iff the custom field-editor can be successfully displayed. Returning {@code false}
+ * would cause the built-in field-editor to be displayed based on the option's {@link IOption#getValueType() valueType}.
+ */
+ boolean init(IOption option, String extraArgument, String preferenceName, Composite parent);
+
+ /**
+ * Returns the list of controls for which tool-tips should be displayed by the Build Settings dialog-page.
+ *
+ * @return the list of controls for which tool-tips should automatically be displayed by the Build Settings dialog-page.
+ * May return {@code null} to signify that tool-tips are handled by the custom field-editor itself.
+ */
+ Control[] getToolTipSources();
+
+}

Back to the top