diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/PluginResources.properties b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/PluginResources.properties index 0f1a95a8381..53389b17374 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/PluginResources.properties +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/PluginResources.properties @@ -55,8 +55,10 @@ BuildPropertyPage.error.Unknown_tree_element=Unknown type of element in tree of BrowseEntryDialog.error.Folder_name_invalid=Folder name invalid # ----------- New Configuration ----------- -NewConfiguration.label.name=Configuration name: -NewConfiguration.label.copy=Copy default settings from: +NewConfiguration.label.name=Name: +NewConfiguration.label.group=Copy settings from +NewConfiguration.label.copy=Default configuration: +NewConfiguration.label.clone=Existing configuration: NewConfiguration.error.title=Error NewConfiguration.error.duplicateName=A configuration named "{0}" already exists. @@ -70,7 +72,7 @@ ManageConfig.label.configs=Manage configurations ManageConfig.label.restore=Restore ManageConfig.label.configs.current=Current: ManageConfig.label.configs.deleted=Deleted: -ManageConfig.label.new.config.dialog=Create +ManageConfig.label.new.config.dialog=Create configuration # ----------- Build Property Common ----------- BuildPropertyCommon.label.title=Enter Value diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionSettingsPage.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionSettingsPage.java index eb581d94115..ee3f2ad253c 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionSettingsPage.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionSettingsPage.java @@ -94,14 +94,7 @@ public class BuildOptionSettingsPage extends BuildSettingsPage { fieldsList.add(listField); break; default : - SummaryFieldEditor summaryField = new SummaryFieldEditor( - opt.getId(), opt.getName(), category.getTool(), - getFieldEditorParent()); - addField(summaryField); - fieldsList.add(summaryField); break; - // default : - // break; } } } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildPropertyPage.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildPropertyPage.java index dff9bf690e9..6113a9a79b6 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildPropertyPage.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildPropertyPage.java @@ -89,6 +89,7 @@ public class BuildPropertyPage extends PropertyPage implements IWorkbenchPropert private static final String ADD_TIP = TIP + ".addconf"; //$NON-NLS-1$ private static final String MANAGE_TITLE = PREFIX + ".manage.title"; //$NON-NLS-1$ private static final int[] DEFAULT_SASH_WEIGHTS = new int[] { 20, 30 }; + private static final String ID_SEPARATOR = "."; //$NON-NLS-1$ /* * Dialog widgets @@ -598,7 +599,18 @@ public class BuildPropertyPage extends PropertyPage implements IWorkbenchPropert if (id < 0) { id *= -1; } - String newId = parent.getId() + "." + id; //$NON-NLS-1$ + + // Create ID for the new component based on the parent ID and random component + String newId = parent.getId(); + int index = newId.lastIndexOf(ID_SEPARATOR); + if (index > 0) { + String lastComponent = newId.substring(index + 1, newId.length()); + if (Character.isDigit(lastComponent.charAt(0))) { + // Strip the last component + newId = newId.substring(0, index); + } + } + newId += ID_SEPARATOR + id; IConfiguration newConfig = selectedTarget.createConfiguration(parent, newId); newConfig.setName(name); // Update the config lists diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ManageConfigDialog.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ManageConfigDialog.java index 19244877b3f..dbed3dd936c 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ManageConfigDialog.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ManageConfigDialog.java @@ -474,25 +474,15 @@ public class ManageConfigDialog extends Dialog { break; } } - // Get all the predefined configs - IConfiguration [] allDefinedConfigs = null; - if (parentTarget != null) { - allDefinedConfigs = parentTarget.getConfigurations(); - } - - // There should be predefined configurations .... - if (allDefinedConfigs != null && allDefinedConfigs.length != 0) { - NewConfigurationDialog dialog = new NewConfigurationDialog(getShell(), - allDefinedConfigs, - managedTarget, - ManagedBuilderUIPlugin.getResourceString(CONF_DLG)); - if (dialog.open() == NewConfigurationDialog.OK) { - // Get the new name and configuration to base the new config on - String newConfigName = dialog.getNewName(); - getNewConfigs().put(newConfigName, dialog.getParentConfiguration()); - currentConfigList.add(newConfigName); - currentConfigList.setSelection(currentConfigList.getItemCount() - 1); - } + NewConfigurationDialog dialog = new NewConfigurationDialog(getShell(), + managedTarget, + ManagedBuilderUIPlugin.getResourceString(CONF_DLG)); + if (dialog.open() == NewConfigurationDialog.OK) { + // Get the new name and configuration to base the new config on + String newConfigName = dialog.getNewName(); + getNewConfigs().put(newConfigName, dialog.getParentConfiguration()); + currentConfigList.add(newConfigName); + currentConfigList.setSelection(currentConfigList.getItemCount() - 1); } // Update the buttons based on the choices diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/NewConfigurationDialog.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/NewConfigurationDialog.java index 6ab7d18064e..d16a43fc71c 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/NewConfigurationDialog.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/NewConfigurationDialog.java @@ -14,7 +14,6 @@ package org.eclipse.cdt.managedbuilder.ui.properties; import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.ITarget; import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIPlugin; -import org.eclipse.cdt.utils.ui.controls.ControlFactory; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; @@ -23,11 +22,14 @@ import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; 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.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; @@ -38,36 +40,48 @@ public class NewConfigurationDialog extends Dialog { private static final String LABEL = PREFIX + ".label"; //$NON-NLS-1$ private static final String ERROR = PREFIX + ".error"; //$NON-NLS-1$ private static final String NAME = LABEL + ".name"; //$NON-NLS-1$ + private static final String GROUP = LABEL + ".group"; //$NON-NLS-1$ private static final String COPY = LABEL + ".copy"; //$NON-NLS-1$ + private static final String CLONE = LABEL + ".clone"; //$NON-NLS-1$ private static final String TITLE = ERROR + ".title"; //$NON-NLS-1$ private static final String DUPLICATE = ERROR + ".duplicateName"; //$NON-NLS-1$ // Widgets - private Combo configSelector; + private Button btnClone; + private Button btnCopy; private Button btnOk; private Text configName; + private Combo copyConfigSelector; + private Combo cloneConfigSelector; // Bookeeping - private IConfiguration[] definedConfigurations; + private boolean clone; + private IConfiguration[] defaultConfigs; + private IConfiguration[] definedConfigs; private IConfiguration parentConfig; private ITarget target; private String newName; - private String [] allNames; private String title = ""; //$NON-NLS-1$ /** * @param parentShell */ - protected NewConfigurationDialog(Shell parentShell, IConfiguration[] configs, ITarget managedTarget, String title) { + protected NewConfigurationDialog(Shell parentShell, ITarget managedTarget, String title) { super(parentShell); this.title = title; setShellStyle(getShellStyle()|SWT.RESIZE); newName = new String(); parentConfig = null; - definedConfigurations = configs == null ? new IConfiguration[0] : configs; - allNames = getConfigurationNames(); this.target = managedTarget; + + // The default behaviour is to clone the settings + clone = true; + + // Populate the list of default and defined configurations + definedConfigs = target.getConfigurations(); + ITarget grandparent = target.getParent(); + defaultConfigs = grandparent.getConfigurations(); } /* (non-Javadoc) @@ -78,12 +92,25 @@ public class NewConfigurationDialog extends Dialog { protected void buttonPressed(int buttonId) { if (buttonId == IDialogConstants.OK_ID) { newName = configName.getText().trim(); - String baseConfigName = configSelector.getItem(configSelector.getSelectionIndex()); - for (int i = 0; i < definedConfigurations.length; i++) { - IConfiguration config = definedConfigurations[i]; - if (config.getName().equals(baseConfigName)) { - parentConfig = config; - break; + String baseConfigName = new String(); + if (clone) { + baseConfigName = cloneConfigSelector.getItem(cloneConfigSelector.getSelectionIndex()); + for (int i = 0; i < definedConfigs.length; i++) { + IConfiguration config = definedConfigs[i]; + if (config.getName().equals(baseConfigName)) { + parentConfig = config; + break; + } + } + } else { + // Get the parent config out of the default config list + baseConfigName = copyConfigSelector.getItem(copyConfigSelector.getSelectionIndex()); + for (int i = 0; i < defaultConfigs.length; i++) { + IConfiguration config = defaultConfigs[i]; + if (config.getName().equals(baseConfigName)) { + parentConfig = config; + break; + } } } } else { @@ -116,17 +143,23 @@ public class NewConfigurationDialog extends Dialog { } protected Control createDialogArea(Composite parent) { - Composite composite = ControlFactory.createComposite(parent, 3); - GridData gd; + Composite composite = new Composite(parent, SWT.NULL); + composite.setFont(parent.getFont()); + composite.setLayout(new GridLayout(3, false)); + composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Add a label and a text widget - Label nameLabel = ControlFactory.createLabel(composite, ManagedBuilderUIPlugin.getResourceString(NAME)); - gd = new GridData(); + final Label nameLabel = new Label(composite, SWT.LEFT); + nameLabel.setFont(parent.getFont()); + nameLabel.setText(ManagedBuilderUIPlugin.getResourceString(NAME)); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 1; nameLabel.setLayoutData(gd); - configName = ControlFactory.createTextField(composite); + configName = new Text(composite, SWT.SINGLE | SWT.BORDER); + configName.setFont(composite.getFont()); gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL); gd.horizontalSpan = 2; + gd.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; configName.setLayoutData(gd); configName.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { @@ -134,24 +167,72 @@ public class NewConfigurationDialog extends Dialog { } }); - // Add a label and combo box to select the base config - Label configLabel = ControlFactory.createLabel(composite, ManagedBuilderUIPlugin.getResourceString(COPY)); - gd = new GridData(); - gd.horizontalSpan = 1; - configLabel.setLayoutData(gd); - configSelector = ControlFactory.createSelectCombo(composite, allNames, newName); + // Create a group fro the radio buttons + final Group group = new Group(composite, SWT.NONE); + group.setFont(composite.getFont()); + group.setText(ManagedBuilderUIPlugin.getResourceString(GROUP)); + GridLayout layout = new GridLayout(3, false); + group.setLayout(layout); + gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 3; + group.setLayoutData(gd); + + SelectionListener radioListener = new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + clone = btnClone.getSelection(); + updateComboState(); + } + }; + // Add a radio button and combo box to copy from default config + btnCopy = new Button(group, SWT.RADIO); + btnCopy.setFont(group.getFont()); + btnCopy.setText(ManagedBuilderUIPlugin.getResourceString(COPY)); + setButtonLayoutData(btnCopy); + btnCopy.addSelectionListener(radioListener); + + copyConfigSelector = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER); + copyConfigSelector.setFont(group.getFont()); + copyConfigSelector.setItems(getDefaultConfigNames()); + int index = copyConfigSelector.indexOf(newName); + copyConfigSelector.select(index < 0 ? 0 : index); gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL); gd.horizontalSpan = 2; - configSelector.setLayoutData(gd); - configSelector.addSelectionListener(new SelectionAdapter() { + gd.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; + copyConfigSelector.setLayoutData(gd); + copyConfigSelector.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { updateButtonState(); } }); + copyConfigSelector.setEnabled(false); + // Create a radio button and combo for clonable configs + btnClone = new Button(group, SWT.RADIO); + btnClone.setFont(group.getFont()); + btnClone.setText(ManagedBuilderUIPlugin.getResourceString(CLONE)); + setButtonLayoutData(btnClone); + btnClone.addSelectionListener(radioListener); + btnClone.setSelection(true); + + cloneConfigSelector = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER); + cloneConfigSelector.setFont(group.getFont()); + cloneConfigSelector.setItems(getDefinedConfigNames()); + index = cloneConfigSelector.indexOf(newName); + cloneConfigSelector.select(index < 0 ? 0 : index); + gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL); + gd.horizontalSpan = 2; + gd.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; + cloneConfigSelector.setLayoutData(gd); + cloneConfigSelector.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + updateButtonState(); + } + }); + return composite; } + /** * @return the IConfiguration the user selected as * the parent of the new configuration. @@ -161,17 +242,33 @@ public class NewConfigurationDialog extends Dialog { } /* - * Returns an array of configuration names + * Returns the array of configuration names defined for all targets + * of this type in the plugin manifest. This list will be used to + * populate the the configurations to copy default settings from. */ - private String [] getConfigurationNames() { - String [] names = new String[definedConfigurations.length]; - for (int index = 0; index < definedConfigurations.length; ++index) { - IConfiguration config = definedConfigurations[index]; + private String [] getDefaultConfigNames() { + String [] names = new String[defaultConfigs.length]; + for (int index = 0; index < defaultConfigs.length; ++index) { + IConfiguration config = defaultConfigs[index]; names[index] = config.getName(); } return names; } + /* + * Returns the array of configuration names defined for this target. + * This list will be used to populate the list of configurations to + * clone. + */ + private String [] getDefinedConfigNames() { + String [] names = new String[definedConfigs.length]; + for (int index = 0; index < definedConfigs.length; ++index) { + IConfiguration config = definedConfigs[index]; + names[index] = config.getName(); + } + return names; + } + /** * @return String containing the name chosen by the user for the * new configuration. @@ -179,7 +276,14 @@ public class NewConfigurationDialog extends Dialog { public String getNewName() { return newName; } - + + /* (non-Javadoc) + * Answers true if the name entered by the user clashes + * with an existing configuration name. + * + * @param newName + * @return + */ protected boolean isDuplicateName(String newName) { // Return true if there is already a config of that name defined on the target IConfiguration [] configs = target.getConfigurations(); @@ -192,17 +296,26 @@ public class NewConfigurationDialog extends Dialog { return false; } - /* + /* (non-Javadoc) * Enable the OK button if there is a valid name in the text widget * and there is a valid selection in the base configuration combo */ private void updateButtonState() { if (btnOk != null) { - int selectionIndex = configSelector.getSelectionIndex(); + int selectionIndex = copyConfigSelector.getSelectionIndex(); btnOk.setEnabled(validateName() && selectionIndex != -1); } } - + + /* (non-Javadoc) + * Radio button selection event handler calls this helper method to + * enable or disable the radio buttons. + */ + protected void updateComboState() { + cloneConfigSelector.setEnabled(clone); + copyConfigSelector.setEnabled(!clone); + } + private boolean validateName() { String currentName = configName.getText().trim(); int nameLength = currentName.length(); diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/SummaryFieldEditor.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/SummaryFieldEditor.java deleted file mode 100644 index 005d57af587..00000000000 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/SummaryFieldEditor.java +++ /dev/null @@ -1,120 +0,0 @@ -package org.eclipse.cdt.managedbuilder.ui.properties; - -/********************************************************************** - * 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 -***********************************************************************/ - -import org.eclipse.cdt.managedbuilder.core.ITool; -import org.eclipse.jface.preference.FieldEditor; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; - -public class SummaryFieldEditor extends FieldEditor { - // Whitespace character - private static final String WHITESPACE = " "; //$NON-NLS-1$ - - // The top level composite - protected Composite parent; - // The tool this category belongs to - protected ITool tool; - // The text widget to hold summary of all commands for the tool - protected Text summary; - - /** - * @param name - * @param labelText - * @param parent - */ - public SummaryFieldEditor(String name, String labelText, ITool tool, Composite parent) { - super(name, labelText, parent); - this.tool = tool; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.preference.FieldEditor#adjustForNumColumns(int) - */ - protected void adjustForNumColumns(int numColumns) { - // For now grab the excess space - GridData gd = (GridData) summary.getLayoutData(); - gd.horizontalSpan = numColumns - 1; - gd.grabExcessHorizontalSpace = true; - gd.grabExcessVerticalSpace = true; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.preference.FieldEditor#doFillIntoGrid(org.eclipse.swt.widgets.Composite, int) - */ - protected void doFillIntoGrid(Composite parent, int numColumns) { - this.parent = parent; - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan = numColumns; - this.parent.setLayoutData(gd); - - // Add the label - Label label = getLabelControl(parent); - GridData labelData = new GridData(); - labelData.horizontalSpan = numColumns; - label.setLayoutData(labelData); - - // Create the multi-line, read-only field - summary = new Text(parent, SWT.MULTI|SWT.READ_ONLY|SWT.WRAP); - GridData summaryData = new GridData(GridData.FILL_BOTH); - summaryData.horizontalSpan = numColumns; - summary.setLayoutData(summaryData); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.preference.FieldEditor#doLoad() - */ - protected void doLoad() { - // Look at the data store for every option defined for the tool -// IOption[] options = tool.getOptions(); -// for (int index = 0; index < options.length; ++index) { -// IOption option = options[index]; -// String command = option.getCommand(); -// if (command == null) { -// command = ""; -// } -// String id = option.getId(); -// String values = getPreferenceStore().getString(id); -// String[] valuesList = BuildToolsSettingsStore.parseString(values); -// for (int j = 0; j < valuesList.length; ++j) { -// String entry = valuesList[j]; -// summary.append(command + entry + WHITESPACE); -// } -// } - } - - /* (non-Javadoc) - * @see org.eclipse.jface.preference.FieldEditor#doLoadDefault() - */ - protected void doLoadDefault() { - doLoad(); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.preference.FieldEditor#doStore() - */ - protected void doStore() { - // This is a read-only summary field, so don't store data - return; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.preference.FieldEditor#getNumberOfControls() - */ - public int getNumberOfControls() { - // There is just the label from the parent and the text field - return 2; - } -}