mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
Committing work submitted by BitMethods to round-trip tool options from a summary field back into the option.
This commit is contained in:
parent
f7039b36d4
commit
3b191e5ddc
10 changed files with 1115 additions and 99 deletions
|
@ -6,6 +6,10 @@
|
|||
<project>org.eclipse.cdt.core</project>
|
||||
<project>org.eclipse.cdt.managedbuilder.core</project>
|
||||
<project>org.eclipse.cdt.ui</project>
|
||||
<project>org.eclipse.core.boot</project>
|
||||
<project>org.eclipse.core.resources</project>
|
||||
<project>org.eclipse.core.runtime</project>
|
||||
<project>org.eclipse.ui</project>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
|
|
|
@ -85,4 +85,10 @@ BuildPropertyCommon.label.browse=Browse...
|
|||
BuildPropertyCommon.label.configs=Defined configurations:
|
||||
|
||||
# ----------- Field Editors -----------
|
||||
FieldEditors.tool.command=Command:
|
||||
FieldEditors.tool.command=Command:
|
||||
Multiline.error.message=Please give correct input
|
||||
|
||||
# ----------- Default flag names -----------
|
||||
BuildToolSettingsPage.compilerflags=Other flags
|
||||
BuildToolSettingsPage.linkerflags=Linker flags
|
||||
BuildToolSettingsPage.alloptions=All Options
|
|
@ -76,13 +76,12 @@ public class BuildOptionComboFieldEditor extends FieldEditor {
|
|||
* @see org.eclipse.jface.preference.FieldEditor#doLoad()
|
||||
*/
|
||||
protected void doLoad() {
|
||||
// Retrieve the option string from the store
|
||||
String values = getPreferenceStore().getString(getPreferenceName());
|
||||
|
||||
// Convert it to a string array
|
||||
options = BuildToolsSettingsStore.parseString(values);
|
||||
// set all the options to option selector
|
||||
optionSelector.removeAll();
|
||||
optionSelector.setItems(options);
|
||||
|
||||
// get the selected option from preference store
|
||||
selected = getPreferenceStore().getString(getPreferenceName());
|
||||
|
||||
// Set the index of selection in the combo box
|
||||
int index = optionSelector.indexOf(selected);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.eclipse.cdt.managedbuilder.ui.properties;
|
||||
|
||||
/**********************************************************************
|
||||
* Copyright (c) 2002,2004 Rational Software Corporation and others.
|
||||
* Copyright (c) 2002,2004 IBM Rational Software Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -25,6 +25,7 @@ import org.eclipse.swt.events.MouseEvent;
|
|||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
|
@ -210,8 +211,9 @@ public class BuildOptionListFieldEditor extends FieldEditor {
|
|||
|
||||
// Create a grid data that takes up the extra space in the dialog and spans one column.
|
||||
GridData listData = new GridData(GridData.FILL_HORIZONTAL);
|
||||
listData.heightHint = buttonGroup.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
|
||||
listData.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
|
||||
Point buttonGroupSize = buttonGroup.computeSize(SWT.DEFAULT, SWT.DEFAULT);
|
||||
listData.heightHint = buttonGroupSize.y;
|
||||
listData.widthHint = buttonGroupSize.x * 2;
|
||||
list.setLayoutData(listData);
|
||||
}
|
||||
|
||||
|
@ -251,12 +253,16 @@ public class BuildOptionListFieldEditor extends FieldEditor {
|
|||
swap(false);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* Event handler for the edit button pressed event. Delegates
|
||||
* the work to a helper method.
|
||||
*/
|
||||
private void editPressed() {
|
||||
editSelection();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* Edit the value of the selected item.
|
||||
*/
|
||||
protected void editSelection() {
|
||||
// Edit the selection index
|
||||
|
@ -378,7 +384,11 @@ public class BuildOptionListFieldEditor extends FieldEditor {
|
|||
int index = list.getSelectionIndex();
|
||||
if (index >= 0) {
|
||||
list.remove(index);
|
||||
list.setSelection(index - 1);
|
||||
if (index - 1 < 0) {
|
||||
list.setSelection(0);
|
||||
} else {
|
||||
list.setSelection(index - 1);
|
||||
}
|
||||
selectionChanged();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,32 @@
|
|||
package org.eclipse.cdt.managedbuilder.ui.properties;
|
||||
|
||||
/**********************************************************************
|
||||
* Copyright (c) 2003,2004 IBM Rational Software Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.managedbuilder.core.BuildException;
|
||||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
import org.eclipse.cdt.managedbuilder.core.IOption;
|
||||
import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||
import org.eclipse.jface.preference.BooleanFieldEditor;
|
||||
import org.eclipse.jface.preference.FieldEditor;
|
||||
import org.eclipse.jface.preference.StringFieldEditor;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
|
||||
public class BuildOptionSettingsPage extends BuildSettingsPage {
|
||||
|
||||
private ArrayList fieldsList = new ArrayList();
|
||||
private IOptionCategory category;
|
||||
|
||||
|
||||
BuildOptionSettingsPage(IConfiguration configuration, IOptionCategory category) {
|
||||
// Cache the configuration and option category this page is created for
|
||||
super(configuration);
|
||||
|
@ -20,64 +34,82 @@ public class BuildOptionSettingsPage extends BuildSettingsPage {
|
|||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.PreferencePage#computeSize()
|
||||
* @see org.eclipse.jface.preference.IPreferencePage#computeSize()
|
||||
*/
|
||||
public Point computeSize() {
|
||||
return super.computeSize();
|
||||
}
|
||||
|
||||
/**
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
|
||||
*/
|
||||
protected void createFieldEditors() {
|
||||
// Get the preference store for the build settings
|
||||
super.createFieldEditors();
|
||||
|
||||
// Iterate over the options in the category and create a field editor for each
|
||||
// Iterate over the options in the category and create a field editor
|
||||
// for each
|
||||
IOption[] options = category.getOptions(configuration);
|
||||
for (int index = 0; index < options.length; ++index) {
|
||||
// Get the option
|
||||
IOption opt = options[index];
|
||||
// Figure out which type the option is and add a proper field editor for it
|
||||
// Figure out which type the option is and add a proper field
|
||||
// editor for it
|
||||
switch (opt.getValueType()) {
|
||||
case IOption.STRING :
|
||||
StringFieldEditor stringField = new StringFieldEditor(opt.getId(), opt.getName(), getFieldEditorParent());
|
||||
StringFieldEditor stringField = new StringFieldEditor(opt
|
||||
.getId(), opt.getName(), getFieldEditorParent());
|
||||
addField(stringField);
|
||||
fieldsList.add(stringField);
|
||||
break;
|
||||
case IOption.BOOLEAN :
|
||||
BooleanFieldEditor booleanField = new BooleanFieldEditor(opt.getId(), opt.getName(), getFieldEditorParent());
|
||||
BooleanFieldEditor booleanField = new BooleanFieldEditor(
|
||||
opt.getId(), opt.getName(), getFieldEditorParent());
|
||||
addField(booleanField);
|
||||
fieldsList.add(booleanField);
|
||||
break;
|
||||
case IOption.ENUMERATED :
|
||||
String sel;
|
||||
try {
|
||||
sel = opt.getSelectedEnum();
|
||||
} catch (BuildException e) {
|
||||
// If we get this exception, then the option type is wrong
|
||||
// If we get this exception, then the option type is
|
||||
// wrong
|
||||
break;
|
||||
}
|
||||
BuildOptionComboFieldEditor comboField = new BuildOptionComboFieldEditor(opt.getId(), opt.getName(), opt.getApplicableValues(), sel, getFieldEditorParent());
|
||||
addField(comboField);
|
||||
BuildOptionComboFieldEditor comboField = new BuildOptionComboFieldEditor(
|
||||
opt.getId(), opt.getName(), opt
|
||||
.getApplicableValues(), sel,
|
||||
getFieldEditorParent());
|
||||
addField(comboField);
|
||||
fieldsList.add(comboField);
|
||||
break;
|
||||
case IOption.STRING_LIST :
|
||||
case IOption.INCLUDE_PATH :
|
||||
case IOption.PREPROCESSOR_SYMBOLS :
|
||||
case IOption.LIBRARIES :
|
||||
case IOption.OBJECTS:
|
||||
BuildOptionListFieldEditor listField = new BuildOptionListFieldEditor(opt.getId(), opt.getName(), getFieldEditorParent());
|
||||
addField(listField);
|
||||
case IOption.OBJECTS :
|
||||
BuildOptionListFieldEditor listField = new BuildOptionListFieldEditor(
|
||||
opt.getId(), opt.getName(), getFieldEditorParent());
|
||||
addField(listField);
|
||||
fieldsList.add(listField);
|
||||
break;
|
||||
default :
|
||||
SummaryFieldEditor summaryField = new SummaryFieldEditor(opt.getId(), opt.getName(), category.getTool(), getFieldEditorParent());
|
||||
SummaryFieldEditor summaryField = new SummaryFieldEditor(
|
||||
opt.getId(), opt.getName(), category.getTool(),
|
||||
getFieldEditorParent());
|
||||
addField(summaryField);
|
||||
fieldsList.add(summaryField);
|
||||
break;
|
||||
// default :
|
||||
// break;
|
||||
// default :
|
||||
// break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Answers <code>true</code> if the settings page has been created for
|
||||
* the option category specified in the argument.
|
||||
*
|
||||
* @param category
|
||||
* @return
|
||||
*/
|
||||
|
@ -87,14 +119,13 @@ public class BuildOptionSettingsPage extends BuildSettingsPage {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IPreferencePage#performOk()
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferencePage#performOk()
|
||||
*/
|
||||
public boolean performOk() {
|
||||
// Write the field editor contents out to the preference store
|
||||
boolean ok = super.performOk();
|
||||
|
||||
// Write the preference store values back to the build model
|
||||
IOption[] options = category.getOptions(configuration);
|
||||
for (int i = 0; i < options.length; i++) {
|
||||
|
@ -103,32 +134,57 @@ public class BuildOptionSettingsPage extends BuildSettingsPage {
|
|||
// Transfer value from preference store to options
|
||||
switch (option.getValueType()) {
|
||||
case IOption.BOOLEAN :
|
||||
boolean boolVal = getPreferenceStore().getBoolean(option.getId());
|
||||
ManagedBuildManager.setOption(configuration, option, boolVal);
|
||||
boolean boolVal = getPreferenceStore().getBoolean(
|
||||
option.getId());
|
||||
ManagedBuildManager.setOption(configuration, option,
|
||||
boolVal);
|
||||
break;
|
||||
case IOption.ENUMERATED :
|
||||
String enumVal = getPreferenceStore().getString(option.getId());
|
||||
ManagedBuildManager.setOption(configuration, option, enumVal);
|
||||
String enumVal = getPreferenceStore().getString(
|
||||
option.getId());
|
||||
ManagedBuildManager.setOption(configuration, option,
|
||||
enumVal);
|
||||
break;
|
||||
case IOption.STRING :
|
||||
String strVal = getPreferenceStore().getString(option.getId());
|
||||
ManagedBuildManager.setOption(configuration, option, strVal);
|
||||
String strVal = getPreferenceStore().getString(
|
||||
option.getId());
|
||||
ManagedBuildManager
|
||||
.setOption(configuration, option, strVal);
|
||||
break;
|
||||
case IOption.STRING_LIST :
|
||||
case IOption.INCLUDE_PATH :
|
||||
case IOption.PREPROCESSOR_SYMBOLS :
|
||||
case IOption.LIBRARIES :
|
||||
case IOption.OBJECTS:
|
||||
String listStr = getPreferenceStore().getString(option.getId());
|
||||
String[] listVal = BuildToolsSettingsStore.parseString(listStr);
|
||||
ManagedBuildManager.setOption(configuration, option, listVal);
|
||||
case IOption.OBJECTS :
|
||||
String listStr = getPreferenceStore().getString(
|
||||
option.getId());
|
||||
String[] listVal = BuildToolsSettingsStore
|
||||
.parseString(listStr);
|
||||
ManagedBuildManager.setOption(configuration, option,
|
||||
listVal);
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update field editors in this page when the page is loaded.
|
||||
*/
|
||||
public void updateFields() {
|
||||
for (int i = 0; i < fieldsList.size(); i++) {
|
||||
FieldEditor editor = (FieldEditor) fieldsList.get(i);
|
||||
editor.loadDefault();
|
||||
editor.load();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* saves all field editors
|
||||
*/
|
||||
public void storeSettings() {
|
||||
super.performOk();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,12 +25,14 @@ import java.util.regex.Pattern;
|
|||
|
||||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
|
||||
import org.eclipse.cdt.managedbuilder.core.IOption;
|
||||
import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
|
||||
import org.eclipse.cdt.managedbuilder.core.ITarget;
|
||||
import org.eclipse.cdt.managedbuilder.core.ITool;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||
import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIPlugin;
|
||||
import org.eclipse.cdt.managedbuilder.ui.properties.BuildSettingsPage;
|
||||
import org.eclipse.cdt.managedbuilder.ui.properties.BuildToolsSettingsStore;
|
||||
import org.eclipse.cdt.managedbuilder.ui.properties.ToolListContentProvider;
|
||||
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.jface.preference.IPreferencePageContainer;
|
||||
|
@ -325,6 +327,23 @@ public class BuildPropertyPage extends PropertyPage implements IWorkbenchPropert
|
|||
children[i].setVisible(false);
|
||||
}
|
||||
currentSettingsPage.setVisible(true);
|
||||
|
||||
// save the last page build options.
|
||||
// If the last page is tool page then parse all the options
|
||||
// and put it in the appropriate preference store.
|
||||
if (oldPage != null){
|
||||
if(oldPage instanceof BuildOptionSettingsPage) {
|
||||
((BuildOptionSettingsPage)oldPage).storeSettings();
|
||||
}
|
||||
else if(oldPage instanceof BuildToolSettingsPage) {
|
||||
((BuildToolSettingsPage)oldPage).storeSettings();
|
||||
((BuildToolSettingsPage)oldPage).parseAllOptions();
|
||||
}
|
||||
}
|
||||
//update the field editors in the current page
|
||||
if(currentSettingsPage instanceof BuildOptionSettingsPage)
|
||||
((BuildOptionSettingsPage)currentSettingsPage).updateFields();
|
||||
|
||||
if (oldPage != null)
|
||||
oldPage.setVisible(false);
|
||||
|
||||
|
@ -376,6 +395,23 @@ public class BuildPropertyPage extends PropertyPage implements IWorkbenchPropert
|
|||
children[i].setVisible(false);
|
||||
}
|
||||
currentSettingsPage.setVisible(true);
|
||||
|
||||
// save the last page build options.
|
||||
// If the last page is tool page then parse all the options
|
||||
// and put it in the appropriate preference store.
|
||||
if (oldPage != null){
|
||||
if(oldPage instanceof BuildOptionSettingsPage) {
|
||||
((BuildOptionSettingsPage)oldPage).storeSettings();
|
||||
}
|
||||
else if(oldPage instanceof BuildToolSettingsPage) {
|
||||
((BuildToolSettingsPage)oldPage).storeSettings();
|
||||
((BuildToolSettingsPage)oldPage).parseAllOptions();
|
||||
}
|
||||
}
|
||||
//update the field editor that displays all the build options
|
||||
if(currentSettingsPage instanceof BuildToolSettingsPage)
|
||||
((BuildToolSettingsPage)currentSettingsPage).updateAllOptionField();
|
||||
|
||||
if (oldPage != null)
|
||||
oldPage.setVisible(false);
|
||||
|
||||
|
@ -395,7 +431,7 @@ public class BuildPropertyPage extends PropertyPage implements IWorkbenchPropert
|
|||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
/* (non-Javadoc)
|
||||
* @return
|
||||
*/
|
||||
protected Point getLastShellSize() {
|
||||
|
@ -440,10 +476,10 @@ public class BuildPropertyPage extends PropertyPage implements IWorkbenchPropert
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
/* (non-Javadoc)
|
||||
* @return
|
||||
*/
|
||||
public IConfiguration getSelectedConfiguration() {
|
||||
protected IConfiguration getSelectedConfiguration() {
|
||||
return selectedConfiguration;
|
||||
}
|
||||
|
||||
|
@ -478,9 +514,9 @@ public class BuildPropertyPage extends PropertyPage implements IWorkbenchPropert
|
|||
Object primary = elements.length > 0 ? elements[0] : null;
|
||||
|
||||
if (primary != null && primary instanceof ITool) {
|
||||
// Check to see if there are any options.
|
||||
// set the tool as primary selection in the tree hence it displays all the build options.
|
||||
ITool tool = (ITool)primary;
|
||||
IOptionCategory top = tool.getTopOptionCategory();
|
||||
/* IOptionCategory top = tool.getTopOptionCategory();
|
||||
IOption[] topOpts = top.getOptions(selectedConfiguration);
|
||||
if (topOpts != null && topOpts.length == 0) {
|
||||
// Get the children categories and start looking
|
||||
|
@ -493,7 +529,7 @@ public class BuildPropertyPage extends PropertyPage implements IWorkbenchPropert
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
if (primary != null) {
|
||||
|
@ -543,6 +579,7 @@ public class BuildPropertyPage extends PropertyPage implements IWorkbenchPropert
|
|||
configurations = selectedTarget.getConfigurations();
|
||||
configSelector.removeAll();
|
||||
configSelector.setItems(getConfigurationNames());
|
||||
configSelector.add(ManagedBuilderUIPlugin.getResourceString(ALL_CONFS));
|
||||
configSelector.select(0);
|
||||
updateConfigs = true;
|
||||
}
|
||||
|
@ -568,6 +605,7 @@ public class BuildPropertyPage extends PropertyPage implements IWorkbenchPropert
|
|||
configurations = selectedTarget.getConfigurations();
|
||||
configSelector.removeAll();
|
||||
configSelector.setItems(getConfigurationNames());
|
||||
configSelector.add(ManagedBuilderUIPlugin.getResourceString(ALL_CONFS));
|
||||
configSelector.select(configSelector.indexOf(name));
|
||||
updateConfigs = true;
|
||||
}
|
||||
|
@ -768,6 +806,11 @@ public class BuildPropertyPage extends PropertyPage implements IWorkbenchPropert
|
|||
while (iter.hasNext()) {
|
||||
BuildSettingsPage page = (BuildSettingsPage) iter.next();
|
||||
if (page instanceof BuildToolSettingsPage) {
|
||||
// if the currentsettings page is not the tool settings page
|
||||
// then update the all build options field editor based on the
|
||||
// build options in other options settings page.
|
||||
if (!(currentSettingsPage instanceof BuildToolSettingsPage))
|
||||
((BuildToolSettingsPage)page).updateAllOptionField();
|
||||
((BuildToolSettingsPage)page).performOk();
|
||||
} else if (page instanceof BuildOptionSettingsPage) {
|
||||
((BuildOptionSettingsPage)page).performOk();
|
||||
|
|
|
@ -10,49 +10,334 @@ package org.eclipse.cdt.managedbuilder.ui.properties;
|
|||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* **********************************************************************/
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.managedbuilder.core.BuildException;
|
||||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
import org.eclipse.cdt.managedbuilder.core.IOption;
|
||||
import org.eclipse.cdt.managedbuilder.core.ITool;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||
import org.eclipse.cdt.managedbuilder.internal.core.ToolReference;
|
||||
import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIPlugin;
|
||||
import org.eclipse.jface.preference.StringFieldEditor;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
|
||||
public class BuildToolSettingsPage extends BuildSettingsPage {
|
||||
// Field editor label
|
||||
private static final String COMMAND = "FieldEditors.tool.command"; //$NON-NLS-1$
|
||||
|
||||
private static final String COMMAND = "FieldEditors.tool.command"; //$NON-NLS-1$
|
||||
// option names that stores additional options
|
||||
private static final String COMPILER_FLAGS = ManagedBuilderUIPlugin.getResourceString("BuildToolSettingsPage.compilerflags"); //$NON-NLS-1$
|
||||
private static final String LINKER_FLAGS = ManagedBuilderUIPlugin.getResourceString("BuildToolSettingsPage.linkerflags"); //$NON-NLS-1$
|
||||
// all build options field editor label
|
||||
private static final String ALL_OPTIONS = ManagedBuilderUIPlugin.getResourceString("BuildToolSettingsPage.alloptions"); //$NON-NLS-1$
|
||||
// Whitespace character
|
||||
private static final String WHITESPACE = " "; //$NON-NLS-1$
|
||||
// field editor that displays all the build options for a particular tool
|
||||
private MultiLineTextFieldEditor allOptionFieldEditor;
|
||||
private static final String DEFAULT_SEPERATOR = ";"; //$NON-NLS-1$
|
||||
// Tool the settings belong to
|
||||
private ITool tool;
|
||||
|
||||
// all build options preference store id
|
||||
private String allOptionsId = ""; //$NON-NLS-1$
|
||||
|
||||
BuildToolSettingsPage(IConfiguration configuration, ITool tool) {
|
||||
// Cache the configuration and tool this page is for
|
||||
super(configuration);
|
||||
this.tool = tool;
|
||||
allOptionsId = tool.getId() + ".allOptions"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.jface.preference.PreferencePage#computeSize()
|
||||
*/
|
||||
public Point computeSize() {
|
||||
return super.computeSize();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
|
||||
*/
|
||||
protected void createFieldEditors() {
|
||||
// Load up the preference store
|
||||
super.createFieldEditors();
|
||||
|
||||
// Add a string editor to edit the tool command
|
||||
StringFieldEditor stringField = new StringFieldEditor(tool.getId(), ManagedBuilderUIPlugin.getResourceString(COMMAND), getFieldEditorParent());
|
||||
StringFieldEditor stringField = new StringFieldEditor(tool.getId(),
|
||||
ManagedBuilderUIPlugin.getResourceString(COMMAND),
|
||||
getFieldEditorParent());
|
||||
stringField.setEmptyStringAllowed(false);
|
||||
addField(stringField);
|
||||
addField(stringField);
|
||||
// Add a field editor that displays over all build options
|
||||
allOptionFieldEditor = new MultiLineTextFieldEditor(allOptionsId,
|
||||
ALL_OPTIONS, getFieldEditorParent());
|
||||
getPreferenceStore().setValue(allOptionsId, ""); //$NON-NLS-1$
|
||||
addField(allOptionFieldEditor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the field editor that displays all the build options
|
||||
*/
|
||||
public void updateAllOptionField() {
|
||||
try {
|
||||
if (getToolFlags() != null) {
|
||||
getPreferenceStore().setValue(allOptionsId, getToolFlags());
|
||||
allOptionFieldEditor.load();
|
||||
}
|
||||
} catch (BuildException e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* saves all field editors
|
||||
*/
|
||||
public void storeSettings() {
|
||||
super.performOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers <code>true</code> if the receiver manages settings for the argument
|
||||
* Returns all the build options string
|
||||
*
|
||||
* @return @throws
|
||||
* BuildException
|
||||
*/
|
||||
private String getToolFlags() throws BuildException {
|
||||
ITool[] tools = configuration.getTools();
|
||||
for (int i = 0; i < tools.length; ++i) {
|
||||
if (tools[i] instanceof ToolReference) {
|
||||
if (((ToolReference) tools[i]).references(tool)) {
|
||||
tool = tools[i];
|
||||
break;
|
||||
}
|
||||
} else if (tools[i].equals(tool))
|
||||
break;
|
||||
}
|
||||
StringBuffer buf = new StringBuffer();
|
||||
// get the options for this tool
|
||||
IOption[] options = tool.getOptions();
|
||||
String listStr = ""; //$NON-NLS-1$
|
||||
String[] listVal = null;
|
||||
for (int k = 0; k < options.length; k++) {
|
||||
IOption option = options[k];
|
||||
switch (option.getValueType()) {
|
||||
case IOption.BOOLEAN :
|
||||
if (getPreferenceStore().getBoolean(option.getId())) {
|
||||
buf.append(option.getCommand() + ITool.WHITE_SPACE);
|
||||
}
|
||||
break;
|
||||
case IOption.ENUMERATED :
|
||||
String enumCommand = getPreferenceStore().getString(
|
||||
option.getId());
|
||||
if (enumCommand.indexOf(DEFAULT_SEPERATOR) != -1)
|
||||
enumCommand = option.getSelectedEnum();
|
||||
String enum = option.getEnumCommand(enumCommand);
|
||||
if (enum.length() > 0) {
|
||||
buf.append(enum + ITool.WHITE_SPACE);
|
||||
}
|
||||
break;
|
||||
case IOption.STRING :
|
||||
String val = getPreferenceStore().getString(option.getId());
|
||||
if (val.length() > 0) {
|
||||
buf.append(val + ITool.WHITE_SPACE);
|
||||
}
|
||||
break;
|
||||
case IOption.STRING_LIST :
|
||||
case IOption.INCLUDE_PATH :
|
||||
case IOption.PREPROCESSOR_SYMBOLS :
|
||||
case IOption.LIBRARIES :
|
||||
case IOption.OBJECTS :
|
||||
String cmd = option.getCommand();
|
||||
listStr = getPreferenceStore().getString(option.getId());
|
||||
listVal = BuildToolsSettingsStore.parseString(listStr);
|
||||
for (int j = 0; j < listVal.length; j++) {
|
||||
String temp = listVal[j];
|
||||
if (cmd != null)
|
||||
buf.append(cmd + temp + ITool.WHITE_SPACE);
|
||||
else
|
||||
buf.append(temp + ITool.WHITE_SPACE);
|
||||
}
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
return buf.toString().trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates single string from the string array with a separator
|
||||
*
|
||||
* @param items
|
||||
* @return
|
||||
*/
|
||||
private String createList(String[] items) {
|
||||
StringBuffer path = new StringBuffer(""); //$NON-NLS-1$
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
path.append(items[i]);
|
||||
if (i < (items.length - 1)) {
|
||||
path.append(DEFAULT_SEPERATOR);
|
||||
}
|
||||
}
|
||||
return path.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method parses the string that is entered in the all build option
|
||||
* field editor and stores the options to the corresponding option fields.
|
||||
*/
|
||||
public void parseAllOptions() {
|
||||
ITool[] tools = configuration.getTools();
|
||||
for (int i = 0; i < tools.length; ++i) {
|
||||
if (tools[i] instanceof ToolReference) {
|
||||
if (((ToolReference) tools[i]).references(tool)) {
|
||||
tool = tools[i];
|
||||
break;
|
||||
}
|
||||
} else if (tools[i].equals(tool))
|
||||
break;
|
||||
}
|
||||
// Get the all build options string from all options field
|
||||
String alloptions = getPreferenceStore().getString(allOptionsId);
|
||||
// list that holds the options for the option type other than
|
||||
// boolean,string and enumerated
|
||||
List optionsList = new ArrayList();
|
||||
// additional options buffer
|
||||
StringBuffer addnOptions = new StringBuffer();
|
||||
// split all build options string
|
||||
String[] optionsArr = alloptions.split(WHITESPACE);
|
||||
for (int j = 0; j < optionsArr.length; j++) {
|
||||
boolean optionValueExist = false;
|
||||
// get the options for this tool
|
||||
IOption[] options = tool.getOptions();
|
||||
for (int k = 0; k < options.length; ++k) {
|
||||
IOption opt = options[k];
|
||||
String name = opt.getId();
|
||||
// check whether the option value is already exist
|
||||
// and also change the preference store based on
|
||||
// the option value
|
||||
switch (opt.getValueType()) {
|
||||
case IOption.BOOLEAN :
|
||||
if (opt.getCommand().equals(optionsArr[j])) {
|
||||
getPreferenceStore().setValue(opt.getId(), true);
|
||||
optionValueExist = true;
|
||||
}
|
||||
break;
|
||||
case IOption.ENUMERATED :
|
||||
String enum = ""; //$NON-NLS-1$
|
||||
String[] enumValues = opt.getApplicableValues();
|
||||
for (int i = 0; i < enumValues.length; i++) {
|
||||
if (opt.getEnumCommand(enumValues[i]).equals(
|
||||
optionsArr[j])) {
|
||||
enum = enumValues[i];
|
||||
optionValueExist = true;
|
||||
}
|
||||
}
|
||||
if (!enum.equals("")) //$NON-NLS-1$
|
||||
getPreferenceStore().setValue(opt.getId(), enum);
|
||||
break;
|
||||
case IOption.STRING :
|
||||
String str = getPreferenceStore()
|
||||
.getString(opt.getId());
|
||||
if (alloptions.indexOf(str) == -1) {
|
||||
getPreferenceStore().setValue(opt.getId(), ""); //$NON-NLS-1$
|
||||
}
|
||||
if (str.indexOf(optionsArr[j]) != -1) {
|
||||
optionValueExist = true;
|
||||
}
|
||||
break;
|
||||
case IOption.STRING_LIST :
|
||||
case IOption.INCLUDE_PATH :
|
||||
case IOption.PREPROCESSOR_SYMBOLS :
|
||||
case IOption.LIBRARIES :
|
||||
if (opt.getCommand() != null
|
||||
&& optionsArr[j].startsWith(opt.getCommand())
|
||||
&& !optionsList.contains(optionsArr[j])) {
|
||||
optionsList.add(optionsArr[j]);
|
||||
optionValueExist = true;
|
||||
}
|
||||
break;
|
||||
case IOption.OBJECTS :
|
||||
String userObjStr = getPreferenceStore().getString(
|
||||
opt.getId());
|
||||
String[] userObjs = BuildToolsSettingsStore
|
||||
.parseString(userObjStr);
|
||||
for (int m = 0; m < userObjs.length; m++) {
|
||||
if (userObjs[m].equalsIgnoreCase(optionsArr[j]))
|
||||
optionValueExist = true;
|
||||
}
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If the parsed string does not match with any previous option
|
||||
// values then consider this option as a additional build option
|
||||
if (!optionValueExist) {
|
||||
addnOptions.append(optionsArr[j] + ITool.WHITE_SPACE);
|
||||
}
|
||||
}
|
||||
// Now update the preference store with parsed options
|
||||
// Get the options for this tool
|
||||
IOption[] options = tool.getOptions();
|
||||
for (int k = 0; k < options.length; ++k) {
|
||||
IOption opt = options[k];
|
||||
String name = opt.getId();
|
||||
String listStr = ""; //$NON-NLS-1$
|
||||
String[] listVal = null;
|
||||
switch (opt.getValueType()) {
|
||||
case IOption.BOOLEAN :
|
||||
ArrayList optsList = new ArrayList(Arrays
|
||||
.asList(optionsArr));
|
||||
if (opt.getCommand() != null
|
||||
&& !optsList.contains(opt.getCommand()))
|
||||
getPreferenceStore().setValue(opt.getId(), false);
|
||||
break;
|
||||
case IOption.STRING :
|
||||
// put the additional options in the compiler flag or
|
||||
// linker flag field
|
||||
if (opt.getName().equals(COMPILER_FLAGS)
|
||||
|| opt.getName().equals(LINKER_FLAGS)) {
|
||||
String newOptions = getPreferenceStore().getString(
|
||||
opt.getId());
|
||||
if (addnOptions.length() > 0) {
|
||||
newOptions = newOptions + ITool.WHITE_SPACE
|
||||
+ addnOptions.toString().trim();
|
||||
}
|
||||
getPreferenceStore().setValue(opt.getId(), newOptions);
|
||||
}
|
||||
break;
|
||||
case IOption.STRING_LIST :
|
||||
case IOption.INCLUDE_PATH :
|
||||
case IOption.PREPROCESSOR_SYMBOLS :
|
||||
case IOption.LIBRARIES :
|
||||
ArrayList newList = new ArrayList();
|
||||
for (int i = 0; i < optionsList.size(); i++) {
|
||||
if (opt.getCommand() != null
|
||||
&& ((String) optionsList.get(i)).startsWith(opt
|
||||
.getCommand())) {
|
||||
newList.add(((String) optionsList.get(i))
|
||||
.substring(opt.getCommand().length()));
|
||||
}
|
||||
}
|
||||
String[] strlist = new String[newList.size()];
|
||||
newList.toArray(strlist);
|
||||
newList.clear();
|
||||
getPreferenceStore().setValue(opt.getId(),
|
||||
BuildToolsSettingsStore.createList(strlist));
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers <code>true</code> if the receiver manages settings for the
|
||||
* argument
|
||||
*
|
||||
* @param tool
|
||||
* @return
|
||||
|
@ -71,6 +356,61 @@ public class BuildToolSettingsPage extends BuildSettingsPage {
|
|||
// Do the super-class thang
|
||||
boolean result = super.performOk();
|
||||
|
||||
//parse and store all build options in the corresponding preference store
|
||||
parseAllOptions();
|
||||
|
||||
// Write the preference store values back to the build model
|
||||
ITool[] tools = configuration.getTools();
|
||||
for (int i = 0; i < tools.length; ++i) {
|
||||
if (tools[i] instanceof ToolReference) {
|
||||
if (((ToolReference) tools[i]).references(tool)) {
|
||||
tool = tools[i];
|
||||
break;
|
||||
}
|
||||
} else if (tools[i].equals(tool)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
IOption[] options = tool.getOptions();
|
||||
for (int i = 0; i < options.length; i++) {
|
||||
IOption option = options[i];
|
||||
// Transfer value from preference store to options
|
||||
switch (option.getValueType()) {
|
||||
case IOption.BOOLEAN :
|
||||
boolean boolVal = getPreferenceStore().getBoolean(
|
||||
option.getId());
|
||||
ManagedBuildManager.setOption(configuration, option,
|
||||
boolVal);
|
||||
break;
|
||||
case IOption.ENUMERATED :
|
||||
String enumVal = getPreferenceStore().getString(
|
||||
option.getId());
|
||||
ManagedBuildManager.setOption(configuration, option,
|
||||
enumVal);
|
||||
break;
|
||||
case IOption.STRING :
|
||||
String strVal = getPreferenceStore().getString(
|
||||
option.getId());
|
||||
ManagedBuildManager
|
||||
.setOption(configuration, option, strVal);
|
||||
break;
|
||||
case IOption.STRING_LIST :
|
||||
case IOption.INCLUDE_PATH :
|
||||
case IOption.PREPROCESSOR_SYMBOLS :
|
||||
case IOption.LIBRARIES :
|
||||
case IOption.OBJECTS :
|
||||
String listStr = getPreferenceStore().getString(
|
||||
option.getId());
|
||||
String[] listVal = BuildToolsSettingsStore
|
||||
.parseString(listStr);
|
||||
ManagedBuildManager.setOption(configuration, option,
|
||||
listVal);
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the actual value out of the field editor
|
||||
String command = getPreferenceStore().getString(tool.getId());
|
||||
if (command.length() == 0) {
|
||||
|
|
|
@ -11,10 +11,8 @@ package org.eclipse.cdt.managedbuilder.ui.properties;
|
|||
* IBM Rational Software - Initial API and implementation
|
||||
* **********************************************************************/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.eclipse.cdt.managedbuilder.core.BuildException;
|
||||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
|
@ -54,14 +52,14 @@ public class BuildToolsSettingsStore implements IPreferenceStore {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
|
||||
*/
|
||||
public void addPropertyChangeListener(IPropertyChangeListener listener) {
|
||||
listenerList.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#contains(java.lang.String)
|
||||
*/
|
||||
public boolean contains(String name) {
|
||||
|
@ -87,7 +85,7 @@ public class BuildToolsSettingsStore implements IPreferenceStore {
|
|||
return path.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#firePropertyChangeEvent(java.lang.String, java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
|
||||
|
@ -103,7 +101,7 @@ public class BuildToolsSettingsStore implements IPreferenceStore {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#getBoolean(java.lang.String)
|
||||
*/
|
||||
public boolean getBoolean(String name) {
|
||||
|
@ -185,7 +183,7 @@ public class BuildToolsSettingsStore implements IPreferenceStore {
|
|||
return getDefaultLong(name);
|
||||
}
|
||||
|
||||
/* (non-javadoc)
|
||||
/* (non-Javadoc)
|
||||
* Answers the map containing the strings associated with each option
|
||||
* ID.
|
||||
*
|
||||
|
@ -223,8 +221,12 @@ public class BuildToolsSettingsStore implements IPreferenceStore {
|
|||
break;
|
||||
|
||||
case IOption.ENUMERATED :
|
||||
value = createList(opt.getApplicableValues());
|
||||
getSettingsMap().put(name, value);
|
||||
try{
|
||||
value = opt.getSelectedEnum();
|
||||
} catch (BuildException e) {
|
||||
break;
|
||||
}
|
||||
getSettingsMap().put(name, value);
|
||||
break;
|
||||
|
||||
case IOption.STRING :
|
||||
|
@ -282,7 +284,7 @@ public class BuildToolsSettingsStore implements IPreferenceStore {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#getString(java.lang.String)
|
||||
*/
|
||||
public String getString(String name) {
|
||||
|
@ -295,30 +297,33 @@ public class BuildToolsSettingsStore implements IPreferenceStore {
|
|||
return getDefaultString(name);
|
||||
}
|
||||
|
||||
/**
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#isDefault(java.lang.String)
|
||||
*/
|
||||
public boolean isDefault(String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#needsSaving()
|
||||
*/
|
||||
public boolean needsSaving() {
|
||||
return dirtyFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stringList
|
||||
* @return
|
||||
*/
|
||||
public static String[] parseString(String stringList) {
|
||||
StringTokenizer tokenizer = new StringTokenizer(stringList, BuildToolsSettingsStore.DEFAULT_SEPERATOR);
|
||||
ArrayList list = new ArrayList();
|
||||
while (tokenizer.hasMoreElements()) {
|
||||
list.add(tokenizer.nextElement());
|
||||
if (stringList == null || stringList.length() == 0) {
|
||||
return new String[0];
|
||||
} else {
|
||||
return stringList.split(BuildToolsSettingsStore.DEFAULT_SEPERATOR);
|
||||
}
|
||||
return (String[]) list.toArray(new String[list.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
*/
|
||||
private void populateSettingsMap() {
|
||||
|
@ -335,7 +340,7 @@ public class BuildToolsSettingsStore implements IPreferenceStore {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#putValue(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void putValue(String name, String value) {
|
||||
|
@ -347,19 +352,19 @@ public class BuildToolsSettingsStore implements IPreferenceStore {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
|
||||
*/
|
||||
public void removePropertyChangeListener(IPropertyChangeListener listener) {
|
||||
}
|
||||
|
||||
/**
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String, double)
|
||||
*/
|
||||
public void setDefault(String name, double value) {
|
||||
}
|
||||
|
||||
/**
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String, float)
|
||||
*/
|
||||
public void setDefault(String name, float value) {
|
||||
|
@ -424,7 +429,7 @@ public class BuildToolsSettingsStore implements IPreferenceStore {
|
|||
public void setValue(String name, long value) {
|
||||
}
|
||||
|
||||
/**
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void setValue(String name, String value) {
|
||||
|
@ -437,7 +442,7 @@ public class BuildToolsSettingsStore implements IPreferenceStore {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String, boolean)
|
||||
*/
|
||||
public void setValue(String name, boolean value) {
|
||||
|
|
|
@ -0,0 +1,553 @@
|
|||
package org.eclipse.cdt.managedbuilder.ui.properties;
|
||||
|
||||
/**********************************************************************
|
||||
* Copyright (c) 2004 BitMethods Inc and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* BitMethods Inc - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIPlugin;
|
||||
import org.eclipse.jface.preference.FieldEditor;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.DisposeEvent;
|
||||
import org.eclipse.swt.events.DisposeListener;
|
||||
import org.eclipse.swt.events.FocusAdapter;
|
||||
import org.eclipse.swt.events.FocusEvent;
|
||||
import org.eclipse.swt.events.KeyAdapter;
|
||||
import org.eclipse.swt.events.KeyEvent;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
/**
|
||||
* MultiLineTextFieldEditor.
|
||||
* Field editor that is same as string field editor but
|
||||
* will have the multi line text field for user input.
|
||||
*/
|
||||
public class MultiLineTextFieldEditor extends FieldEditor {
|
||||
|
||||
private static final String ERROR_MESSAGE = "Multiline.error.message"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Validation strategy constant (value <code>0</code>) indicating that
|
||||
* the editor should perform validation after every key stroke.
|
||||
*
|
||||
* @see #setValidateStrategy
|
||||
*/
|
||||
public static final int VALIDATE_ON_KEY_STROKE = 0;
|
||||
|
||||
/**
|
||||
* Validation strategy constant (value <code>1</code>) indicating that
|
||||
* the editor should perform validation only when the text widget
|
||||
* loses focus.
|
||||
*
|
||||
* @see #setValidateStrategy
|
||||
*/
|
||||
public static final int VALIDATE_ON_FOCUS_LOST = 1;
|
||||
|
||||
/**
|
||||
* Text limit constant (value <code>-1</code>) indicating unlimited
|
||||
* text limit and width.
|
||||
*/
|
||||
public static int UNLIMITED = -1;
|
||||
|
||||
/**
|
||||
* Cached valid state.
|
||||
*/
|
||||
private boolean isValid;
|
||||
|
||||
/**
|
||||
* Old text value.
|
||||
*/
|
||||
private String oldValue;
|
||||
private String compTitle;
|
||||
private Label title;
|
||||
|
||||
/**
|
||||
* The text field, or <code>null</code> if none.
|
||||
*/
|
||||
private Text textField;
|
||||
|
||||
/**
|
||||
* Width of text field in characters; initially unlimited.
|
||||
*/
|
||||
private int widthInChars = UNLIMITED;
|
||||
|
||||
/**
|
||||
* Text limit of text field in characters; initially unlimited.
|
||||
*/
|
||||
private int textLimit = UNLIMITED;
|
||||
|
||||
/**
|
||||
* The error message, or <code>null</code> if none.
|
||||
*/
|
||||
private String errorMessage;
|
||||
|
||||
/**
|
||||
* Indicates whether the empty string is legal;
|
||||
* <code>true</code> by default.
|
||||
*/
|
||||
private boolean emptyStringAllowed = true;
|
||||
|
||||
/**
|
||||
* The validation strategy;
|
||||
* <code>VALIDATE_ON_KEY_STROKE</code> by default.
|
||||
*/
|
||||
private int validateStrategy = VALIDATE_ON_KEY_STROKE;
|
||||
/**
|
||||
* Creates a new string field editor
|
||||
*/
|
||||
protected MultiLineTextFieldEditor() {
|
||||
}
|
||||
/**
|
||||
* Creates a string field editor.
|
||||
* Use the method <code>setTextLimit</code> to limit the text.
|
||||
*
|
||||
* @param name the name of the preference this field editor works on
|
||||
* @param labelText the label text of the field editor
|
||||
* @param width the width of the text input field in characters,
|
||||
* or <code>UNLIMITED</code> for no limit
|
||||
* @param strategy either <code>VALIDATE_ON_KEY_STROKE</code> to perform
|
||||
* on the fly checking (the default), or <code>VALIDATE_ON_FOCUS_LOST</code> to
|
||||
* perform validation only after the text has been typed in
|
||||
* @param parent the parent of the field editor's control
|
||||
* @since 2.0
|
||||
*/
|
||||
public MultiLineTextFieldEditor(
|
||||
String name,
|
||||
String labelText,
|
||||
int width,
|
||||
int strategy,
|
||||
Composite parent) {
|
||||
init(name, labelText);
|
||||
widthInChars = width;
|
||||
setValidateStrategy(strategy);
|
||||
isValid = false;
|
||||
errorMessage = ManagedBuilderUIPlugin.getResourceString(ERROR_MESSAGE);
|
||||
createControl(parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string field editor.
|
||||
* Use the method <code>setTextLimit</code> to limit the text.
|
||||
*
|
||||
* @param name the name of the preference this field editor works on
|
||||
* @param labelText the label text of the field editor
|
||||
* @param width the width of the text input field in characters,
|
||||
* or <code>UNLIMITED</code> for no limit
|
||||
* @param parent the parent of the field editor's control
|
||||
*/
|
||||
public MultiLineTextFieldEditor(String name, String labelText, int width, Composite parent) {
|
||||
this(name, labelText, width, VALIDATE_ON_KEY_STROKE, parent);
|
||||
this.compTitle = labelText;
|
||||
}
|
||||
/**
|
||||
* Creates a string field editor of unlimited width.
|
||||
* Use the method <code>setTextLimit</code> to limit the text.
|
||||
*
|
||||
* @param name the name of the preference this field editor works on
|
||||
* @param labelText the label text of the field editor
|
||||
* @param parent the parent of the field editor's control
|
||||
*/
|
||||
public MultiLineTextFieldEditor(String name, String labelText, Composite parent) {
|
||||
this(name, labelText, UNLIMITED, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the horizontal span of this field editor's basic controls
|
||||
* <p>
|
||||
* Subclasses must implement this method to adjust the horizontal span
|
||||
* of controls so they appear correct in the given number of columns.
|
||||
* </p>
|
||||
* <p>
|
||||
* The number of columns will always be equal to or greater than the
|
||||
* value returned by this editor's <code>getNumberOfControls</code> method.
|
||||
*
|
||||
* @param numColumns the number of columns
|
||||
*/
|
||||
protected void adjustForNumColumns(int numColumns) {
|
||||
GridData gd = (GridData) textField.getLayoutData();
|
||||
gd.horizontalSpan = numColumns - 1;
|
||||
// We only grab excess space if we have to
|
||||
// If another field editor has more columns then
|
||||
// we assume it is setting the width.
|
||||
gd.grabExcessHorizontalSpace = gd.horizontalSpan == 1;
|
||||
}
|
||||
/**
|
||||
* Checks whether the text input field contains a valid value or not.
|
||||
*
|
||||
* @return <code>true</code> if the field value is valid,
|
||||
* and <code>false</code> if invalid
|
||||
*/
|
||||
protected boolean checkState() {
|
||||
boolean result = false;
|
||||
if (emptyStringAllowed)
|
||||
result = true;
|
||||
|
||||
if (textField == null)
|
||||
result = false;
|
||||
|
||||
String txt = textField.getText();
|
||||
|
||||
if (txt == null)
|
||||
result = false;
|
||||
|
||||
result = (txt.trim().length() > 0) || emptyStringAllowed;
|
||||
|
||||
// call hook for subclasses
|
||||
result = result && doCheckState();
|
||||
|
||||
if (result)
|
||||
clearErrorMessage();
|
||||
else
|
||||
showErrorMessage(errorMessage);
|
||||
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Hook for subclasses to do specific state checks.
|
||||
* <p>
|
||||
* The default implementation of this framework method does
|
||||
* nothing and returns <code>true</code>. Subclasses should
|
||||
* override this method to specific state checks.
|
||||
* </p>
|
||||
*
|
||||
* @return <code>true</code> if the field value is valid,
|
||||
* and <code>false</code> if invalid
|
||||
*/
|
||||
protected boolean doCheckState() {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Fills this field editor's basic controls into the given parent.
|
||||
* <p>
|
||||
* The string field implementation of this <code>FieldEditor</code>
|
||||
* framework method contributes the text field. Subclasses may override
|
||||
* but must call <code>super.doFillIntoGrid</code>.
|
||||
* </p>
|
||||
*/
|
||||
protected void doFillIntoGrid(Composite parent, int numColumns) {
|
||||
|
||||
title = new Label(parent, SWT.UP);
|
||||
this.compTitle = getLabelText();
|
||||
title.setText(this.compTitle);
|
||||
GridData gd1 = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
|
||||
gd1.widthHint = 80;
|
||||
title.setLayoutData(gd1);
|
||||
|
||||
textField = getTextControl(parent);
|
||||
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
||||
gd.widthHint = 100;
|
||||
gd.heightHint = 70;
|
||||
textField.setLayoutData(gd);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes this field editor with the preference value from
|
||||
* the preference store.
|
||||
* <p>
|
||||
* Subclasses must implement this method to properly initialize
|
||||
* the field editor.
|
||||
* </p>
|
||||
*/
|
||||
protected void doLoad() {
|
||||
if (textField != null) {
|
||||
String value = getPreferenceStore().getString(getPreferenceName());
|
||||
textField.setText(value);
|
||||
oldValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes this field editor with the default preference value from
|
||||
* the preference store.
|
||||
* <p>
|
||||
* Subclasses must implement this method to properly initialize
|
||||
* the field editor.
|
||||
* </p>
|
||||
*/
|
||||
protected void doLoadDefault() {
|
||||
if (textField != null) {
|
||||
String value =
|
||||
getPreferenceStore().getDefaultString(getPreferenceName());
|
||||
textField.setText(value);
|
||||
}
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.FieldEditor#doStore()
|
||||
*/
|
||||
protected void doStore() {
|
||||
getPreferenceStore().setValue(getPreferenceName(), textField.getText());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the error message that will be displayed when and if
|
||||
* an error occurs.
|
||||
*
|
||||
* @return the error message, or <code>null</code> if none
|
||||
*/
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
/**
|
||||
* Returns the number of basic controls this field editor consists of.
|
||||
*
|
||||
* @return the number of controls
|
||||
*/
|
||||
public int getNumberOfControls() {
|
||||
return 2;
|
||||
}
|
||||
/**
|
||||
* Returns the field editor's value.
|
||||
*
|
||||
* @return the current value
|
||||
*/
|
||||
public String getStringValue() {
|
||||
if (textField != null)
|
||||
return textField.getText();
|
||||
else
|
||||
return getPreferenceStore().getString(getPreferenceName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this field editor's text control.
|
||||
*
|
||||
* @param parent the parent
|
||||
* @return the text control, or <code>null</code> if no
|
||||
* text field is created yet
|
||||
*/
|
||||
protected Text getTextControl() {
|
||||
return textField;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this field editor's text control.
|
||||
* <p>
|
||||
* The control is created if it does not yet exist
|
||||
* </p>
|
||||
*
|
||||
* @param parent the parent
|
||||
* @return the text control
|
||||
*/
|
||||
public Text getTextControl(Composite parent) {
|
||||
if (textField == null) {
|
||||
textField =
|
||||
new Text(
|
||||
parent,
|
||||
SWT.MULTI | SWT.V_SCROLL | SWT.BORDER | SWT.WRAP);
|
||||
textField.setFont(parent.getFont());
|
||||
switch (validateStrategy) {
|
||||
case VALIDATE_ON_KEY_STROKE :
|
||||
textField.addKeyListener(new KeyAdapter() {
|
||||
public void keyPressed(KeyEvent e) {
|
||||
valueChanged();
|
||||
}
|
||||
});
|
||||
|
||||
textField.addFocusListener(new FocusAdapter() {
|
||||
public void focusGained(FocusEvent e) {
|
||||
refreshValidState();
|
||||
}
|
||||
public void focusLost(FocusEvent e) {
|
||||
clearErrorMessage();
|
||||
}
|
||||
});
|
||||
break;
|
||||
case VALIDATE_ON_FOCUS_LOST :
|
||||
textField.addKeyListener(new KeyAdapter() {
|
||||
public void keyPressed(KeyEvent e) {
|
||||
clearErrorMessage();
|
||||
}
|
||||
});
|
||||
textField.addFocusListener(new FocusAdapter() {
|
||||
public void focusGained(FocusEvent e) {
|
||||
refreshValidState();
|
||||
}
|
||||
public void focusLost(FocusEvent e) {
|
||||
valueChanged();
|
||||
clearErrorMessage();
|
||||
}
|
||||
});
|
||||
break;
|
||||
default :
|
||||
Assert.isTrue(false, "Unknown validate strategy"); //$NON-NLS-1$
|
||||
}
|
||||
textField.addDisposeListener(new DisposeListener() {
|
||||
public void widgetDisposed(DisposeEvent event) {
|
||||
textField = null;
|
||||
}
|
||||
});
|
||||
if (textLimit > 0) { //Only set limits above 0 - see SWT spec
|
||||
textField.setTextLimit(textLimit);
|
||||
}
|
||||
} else {
|
||||
checkParent(textField, parent);
|
||||
}
|
||||
return textField;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether an empty string is a valid value.
|
||||
*
|
||||
* @return <code>true</code> if an empty string is a valid value, and
|
||||
* <code>false</code> if an empty string is invalid
|
||||
* @see #setEmptyStringAllowed
|
||||
*/
|
||||
public boolean isEmptyStringAllowed() {
|
||||
return emptyStringAllowed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this field editor contains a valid value.
|
||||
* <p>
|
||||
* The default implementation of this framework method
|
||||
* returns <code>true</code>. Subclasses wishing to perform
|
||||
* validation should override both this method and
|
||||
* <code>refreshValidState</code>.
|
||||
* </p>
|
||||
*
|
||||
* @return <code>true</code> if the field value is valid,
|
||||
* and <code>false</code> if invalid
|
||||
* @see #refreshValidState
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes this field editor's valid state after a value change
|
||||
* and fires an <code>IS_VALID</code> property change event if
|
||||
* warranted.
|
||||
* <p>
|
||||
* The default implementation of this framework method does
|
||||
* nothing. Subclasses wishing to perform validation should override
|
||||
* both this method and <code>isValid</code>.
|
||||
* </p>
|
||||
* @see #isValid
|
||||
*/
|
||||
protected void refreshValidState() {
|
||||
isValid = checkState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the empty string is a valid value or not.
|
||||
*
|
||||
* @param b <code>true</code> if the empty string is allowed,
|
||||
* and <code>false</code> if it is considered invalid
|
||||
*/
|
||||
public void setEmptyStringAllowed(boolean b) {
|
||||
emptyStringAllowed = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the error message that will be displayed when and if
|
||||
* an error occurs.
|
||||
*
|
||||
* @param message the error message
|
||||
*/
|
||||
public void setErrorMessage(String message) {
|
||||
errorMessage = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the focus to this field editor.
|
||||
* <p>
|
||||
* The default implementation of this framework method
|
||||
* does nothing. Subclasses may reimplement.
|
||||
* </p>
|
||||
*/
|
||||
public void setFocus() {
|
||||
if (textField != null) {
|
||||
textField.setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this field editor's value.
|
||||
*
|
||||
* @param value the new value, or <code>null</code> meaning the empty string
|
||||
*/
|
||||
public void setStringValue(String value) {
|
||||
if (textField != null) {
|
||||
if (value == null)
|
||||
value = ""; //$NON-NLS-1$
|
||||
oldValue = textField.getText();
|
||||
if (!oldValue.equals(value)) {
|
||||
textField.setText(value);
|
||||
valueChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this text field's text limit.
|
||||
*
|
||||
* @param limit the limit on the number of character in the text
|
||||
* input field, or <code>UNLIMITED</code> for no limit
|
||||
*/
|
||||
public void setTextLimit(int limit) {
|
||||
textLimit = limit;
|
||||
if (textField != null)
|
||||
textField.setTextLimit(limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the strategy for validating the text.
|
||||
* <p>
|
||||
* Calling this method has no effect after <code>createPartControl</code>
|
||||
* is called. Thus this method is really only useful for subclasses to call
|
||||
* in their constructor. However, it has public visibility for backward
|
||||
* compatibility.
|
||||
* </p>
|
||||
*
|
||||
* @param value either <code>VALIDATE_ON_KEY_STROKE</code> to perform
|
||||
* on the fly checking (the default), or <code>VALIDATE_ON_FOCUS_LOST</code> to
|
||||
* perform validation only after the text has been typed in
|
||||
*/
|
||||
public void setValidateStrategy(int value) {
|
||||
Assert.isTrue(
|
||||
value == VALIDATE_ON_FOCUS_LOST || value == VALIDATE_ON_KEY_STROKE);
|
||||
validateStrategy = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the error message set via <code>setErrorMessage</code>.
|
||||
*/
|
||||
public void showErrorMessage() {
|
||||
showErrorMessage(errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Informs this field editor's listener, if it has one, about a change
|
||||
* to the value (<code>VALUE</code> property) provided that the old and
|
||||
* new values are different.
|
||||
* <p>
|
||||
* This hook is <em>not</em> called when the text is initialized
|
||||
* (or reset to the default value) from the preference store.
|
||||
* </p>
|
||||
*/
|
||||
protected void valueChanged() {
|
||||
setPresentsDefaultValue(false);
|
||||
boolean oldState = isValid;
|
||||
refreshValidState();
|
||||
|
||||
if (isValid != oldState)
|
||||
fireStateChanged(IS_VALID, oldState, isValid);
|
||||
|
||||
String newValue = textField.getText();
|
||||
if (!newValue.equals(oldValue)) {
|
||||
fireValueChanged(VALUE, oldValue, newValue);
|
||||
oldValue = newValue;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,16 @@
|
|||
package org.eclipse.cdt.managedbuilder.ui.properties;
|
||||
|
||||
/**********************************************************************
|
||||
* Copyright (c) 2003,2004 IBM Rational Software Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
import org.eclipse.cdt.managedbuilder.core.ITarget;
|
||||
import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIPlugin;
|
||||
|
@ -21,17 +32,6 @@ import org.eclipse.swt.widgets.Label;
|
|||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 Rational Software Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
public class NewConfigurationDialog extends Dialog {
|
||||
// String constants
|
||||
private static final String PREFIX = "NewConfiguration"; //$NON-NLS-1$
|
||||
|
|
Loading…
Add table
Reference in a new issue