diff options
author | Leo Treggiari | 2005-06-10 15:22:01 +0000 |
---|---|---|
committer | Leo Treggiari | 2005-06-10 15:22:01 +0000 |
commit | 92e840899d033d630edb865a9bfd65d8e800ac34 (patch) | |
tree | afbaff28ea49e7e0b05de3827975de5ab8e7ba88 /build/org.eclipse.cdt.managedbuilder.ui | |
parent | cc72de6f6088c1e66777e87a388d9432fdc95c7c (diff) | |
download | org.eclipse.cdt-92e840899d033d630edb865a9bfd65d8e800ac34.tar.gz org.eclipse.cdt-92e840899d033d630edb865a9bfd65d8e800ac34.tar.xz org.eclipse.cdt-92e840899d033d630edb865a9bfd65d8e800ac34.zip |
Apply patch from Sunil Davasam for multi-version and converter support
Diffstat (limited to 'build/org.eclipse.cdt.managedbuilder.ui')
4 files changed, 384 insertions, 10 deletions
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ConvertStartup.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ConvertStartup.java new file mode 100644 index 00000000000..95b91f4859a --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ConvertStartup.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2005 Intel 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.managedbuilder.internal.ui; + +import org.eclipse.cdt.managedbuilder.ui.actions.ConvertTargetAction; +import org.eclipse.ui.IStartup; + + +public class ConvertStartup implements IStartup { + + /* (non-Javadoc) + * @see org.eclipse.ui.IStartup#earlyStartup() + */ + /* + * This code is needed incase we want to add cascading menu for project converters in UI. + */ + public void earlyStartup() { + ConvertTargetAction.initStartup(); + } +} 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 0ddc652d4d7..8e139e8c30a 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 @@ -276,6 +276,10 @@ ManageConfig.label.rename.config.dialog=Rename configuration ManageConfig.deletedialog.message=Are you sure you want to delete the "{0}" configuration? ManageConfig.deletedialog.title=Confirm Delete +# Toolchain Conversion Target confirmation Dialog +ConfigurationConvert.confirmdialog.message=Currently the "{0}" Configuration uses "{1}" tool-chain. After conversion it will use "{2}" tool-chain. Do you want to proceed? +ConfigurationConvert.confirmdialog.title=Confirm Configuration Conversion + # ----------- Build Property Common ----------- BuildPropertyCommon.label.title=Enter Value BuildPropertyCommon.label.new=New... diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/ConvertTargetAction.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/ConvertTargetAction.java new file mode 100644 index 00000000000..4cd1afd1c12 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/ConvertTargetAction.java @@ -0,0 +1,236 @@ +/******************************************************************************* + * Copyright (c) 2005 Intel 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.managedbuilder.ui.actions; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.managedbuilder.core.IConvertManagedBuildObject; +import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; +import org.eclipse.cdt.managedbuilder.core.IManagedProject; +import org.eclipse.cdt.managedbuilder.core.IProjectType; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIMessages; +import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIPlugin; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +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.action.IAction; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IObjectActionDelegate; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.actions.ActionDelegate; + +public class ConvertTargetAction + extends ActionDelegate + implements IObjectActionDelegate { + + private String converterId = null; + private String fromId = null; + private String toId = null; + private IConvertManagedBuildObject convertBuildObject = null; + private IProject selectedProject = null; + + public static void initStartup() { + return; + } + + public void initConvertAction(IAction action) { + convertBuildObject = null; + String id = action.getId(); + try { + + // Get the Converter Extension Point + IExtensionPoint extensionPoint = Platform.getExtensionRegistry() + .getExtensionPoint("org.eclipse.cdt.managedbuilder.core", //$NON-NLS-1$ + "projectConverter"); //$NON-NLS-1$ + if (extensionPoint != null) { + // Get the Converter Extensions + IExtension[] extensions = extensionPoint.getExtensions(); + List list = new ArrayList(extensions.length); + for (int i = 0; i < extensions.length; i++) { + + // Get the configuration elements for each extension + IConfigurationElement[] configElements = extensions[i] + .getConfigurationElements(); + + for (int j = 0; j < configElements.length; j++) { + IConfigurationElement element = configElements[j]; + + if (element.getName().equals("converter")) { //$NON-NLS-1$ + // Get the converter 'id' + String tmpConverterID = element.getAttribute("id"); //$NON-NLS-1$ + // If the converter 'id' and action 'id' are same. + if (id.equals(tmpConverterID)) { + + convertBuildObject = (IConvertManagedBuildObject) element + .createExecutableExtension("class"); //$NON-NLS-1$ + fromId = element.getAttribute("fromId"); //$NON-NLS-1$ + toId = element.getAttribute("toId"); //$NON-NLS-1$ + return; + } + } + } + } + } + } catch (CoreException e) { + } + } + + public void selectionChanged(IAction action, ISelection selection) { + initConvertAction(action); + if (selection instanceof IStructuredSelection) { + IStructuredSelection sel = (IStructuredSelection) selection; + Object obj = sel.getFirstElement(); + if (obj instanceof IProject) { + IProject project = (IProject)obj; + + // Save the selected project. + setSelectedProject(project); + + // If the project does not have managed build nature then disable the action. + try { + if(!project.hasNature("org.eclipse.cdt.managedbuilder.core.managedBuildNature")) { //$NON-NLS-1$ + action.setEnabled(false); + return; + } + } catch (CoreException e) { +// e.printStackTrace(); + } + + // Get the projectType of the project. + IProjectType projectType = getProjectType(project); + + // Check whether the Converter can convert the selected project. + if( isProjectConvertable(projectType)) + action.setEnabled(true); + else + action.setEnabled(false); + } else { + action.setEnabled(false); + } + } + } + + private IProjectType getProjectType(IProject project) { + IProjectType projectType = null; + + // Get the projectType from project. + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + if (info != null) { + IManagedProject managedProject = info.getManagedProject(); + projectType = managedProject.getProjectType(); + } + return projectType; + } + + + private boolean isProjectConvertable(IProjectType projectType) { + + IProjectType tmpProjectType = projectType; + +// Check whether the converter can convert the given projectType + if(fromId == null) + return false; + + while( tmpProjectType != null) { + String id = tmpProjectType.getId(); + + if (fromId.equals(id)) + return true; + else + tmpProjectType = tmpProjectType.getSuperClass(); + } + return false; + } + + + + public void run(IAction action) { + if( convertBuildObject != null) { +// Get the confirmation from user before converting the selected project + Shell shell = ManagedBuilderUIPlugin.getDefault().getShell(); + boolean shouldConvert = MessageDialog.openQuestion(shell, + ManagedBuilderUIMessages.getResourceString("ProjectConvert.confirmdialog.title"), //$NON-NLS-1$ + ManagedBuilderUIMessages.getFormattedString("ProjectConvert.confirmdialog.message", //$NON-NLS-1$ + new String[] {getSelectedProject().getName()})); + + if (shouldConvert) { + convertBuildObject.convert( getProjectType(getSelectedProject()), getFromId(), getToId(), true); + } + } + + } + + public void setActivePart(IAction action, IWorkbenchPart targetPart) { + // TODO Auto-generated method stub + + } + + private IConvertManagedBuildObject getConvertBuildObject() { + return convertBuildObject; + } + + private void setConvertBuildObject(IConvertManagedBuildObject convertBuildObject) { + this.convertBuildObject = convertBuildObject; + } + + private String getConverterId() { + return converterId; + } + + private void setConverterId(String converterId) { + this.converterId = converterId; + } + + private String getFromId() { + return fromId; + } + + private void setFromId(String fromId) { + this.fromId = fromId; + } + + /** + * @return Returns the selectedProject. + */ + private IProject getSelectedProject() { + return selectedProject; + } + + /** + * @param selectedProject The selectedProject to set. + */ + private void setSelectedProject(IProject selectedProject) { + this.selectedProject = selectedProject; + } + + /** + * @return Returns the toId. + */ + private String getToId() { + return toId; + } + + /** + * @param toId The toId to set. + */ + private void setToId(String toId) { + this.toId = toId; + } +} 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 f5a0ef440e7..20df0d42a68 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 @@ -14,14 +14,21 @@ import java.util.ArrayList; import java.util.SortedMap; import java.util.TreeMap; +import org.eclipse.cdt.managedbuilder.core.IConvertManagedBuildObject; import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; import org.eclipse.cdt.managedbuilder.core.IManagedProject; import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.IToolChain; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIMessages; import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIPlugin; import org.eclipse.cdt.utils.ui.controls.ControlFactory; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +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.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; @@ -83,6 +90,11 @@ public class ManageConfigDialog extends Dialog { private Combo conversionTargetSelector; private Button convertTargetBtn; + private Composite conversionGroup; + + // The list of conversion targets for the selected configuration + private SortedMap conversionTargets; + // Widgets protected List currentConfigList; @@ -173,13 +185,15 @@ public class ManageConfigDialog extends Dialog { }); // Create a composite for the conversion target combo - final Composite conversionGroup = new Composite(configListGroup, SWT.NULL); +// final Composite conversionGroup = new Composite(configListGroup, SWT.NULL); + conversionGroup = new Composite(configListGroup, SWT.NULL); conversionGroup.setFont(configListGroup.getFont()); conversionGroup.setLayout(new GridLayout(2, true)); conversionGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the Tool chain conversion target list Label conversionTargetLabel = ControlFactory.createLabel(conversionGroup, ManagedBuilderUIMessages.getResourceString(CONVERSION_TARGET_LABEL)); + conversionTargetSelector = new Combo(conversionGroup, SWT.READ_ONLY|SWT.DROP_DOWN); conversionTargetSelector.addListener(SWT.Selection, new Listener () { public void handleEvent(Event e) { @@ -187,6 +201,7 @@ public class ManageConfigDialog extends Dialog { } }); conversionTargetSelector.setToolTipText(ManagedBuilderUIMessages.getResourceString(CONVERSION_TARGET_TIP)); + conversionTargetSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create a composite for the buttons final Composite buttonBar = new Composite(configListGroup, SWT.NULL); @@ -250,9 +265,38 @@ public class ManageConfigDialog extends Dialog { } private void handleConversionTargetSelection() { - return; + IConfigurationElement element = null; + String selectedConversionTargetName = null; + + // Determine which conversion target was selected + int selectionIndex = conversionTargetSelector.getSelectionIndex(); + if (selectionIndex != -1) { + // Get the converter based on selection + selectedConversionTargetName = conversionTargetSelector.getItem(selectionIndex); + element = (IConfigurationElement) getConversionTargets().get(selectedConversionTargetName); + + // Get the confirmation from the user + Shell shell = ManagedBuilderUIPlugin.getDefault().getShell(); + boolean shouldConvert = MessageDialog.openQuestion(shell, + ManagedBuilderUIMessages.getResourceString("ConfigurationConvert.confirmdialog.title"), //$NON-NLS-1$ + ManagedBuilderUIMessages.getFormattedString("ConfigurationConvert.confirmdialog.message", //$NON-NLS-1$ + new String[] {getSelectedConfiguration().getName(), getSelectedConfiguration().getToolChain().getName(), element.getAttribute("name")})); //$NON-NLS-1$ + if (shouldConvert) { + IConvertManagedBuildObject convertBuildObject = null; + try { + convertBuildObject = (IConvertManagedBuildObject) element.createExecutableExtension("class"); //$NON-NLS-1$ + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + String fromId = element.getAttribute("fromId"); //$NON-NLS-1$ + String toId = element.getAttribute("toId"); //$NON-NLS-1$ + + if(convertBuildObject != null ) + convertBuildObject.convert( getSelectedConfiguration().getToolChain(), fromId, toId, true); + } + } } - /* (non-Javadoc) * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ @@ -289,17 +333,71 @@ public class ManageConfigDialog extends Dialog { } private String [] getConversionTargetList(IConfiguration config) { - // This is temporary, once I implement backend & converter extension point, - // this will be replaced with original code. - String [] conversionTargetNames = { "GNU Toolchain version 4.0"}; //$NON-NLS-1$ - return conversionTargetNames; + + String []emptyList = new String[0]; + + String fromId = null; + + // Get the id of the toolchain used in the given configuration. + String id = config.getToolChain().getId(); + + // Clear the conversionTargets list. + getConversionTargets().clear(); + + // Get the Converter Extension Point + IExtensionPoint extensionPoint = Platform.getExtensionRegistry() + .getExtensionPoint("org.eclipse.cdt.managedbuilder.core", //$NON-NLS-1$ + "projectConverter"); //$NON-NLS-1$ + if (extensionPoint != null) { + // Get the extensions + IExtension[] extensions = extensionPoint.getExtensions(); + for (int i = 0; i < extensions.length; i++) { + // Get the configuration elements of each extension + IConfigurationElement[] configElements = extensions[i] + .getConfigurationElements(); + for (int j = 0; j < configElements.length; j++) { + + IConfigurationElement element = configElements[j]; + if (element.getName().equals("converter")) { //$NON-NLS-1$ + + fromId = element.getAttribute("fromId"); //$NON-NLS-1$ + // Check whether the current converter can be used for the selected configuration(toolchain) + if (hasToolChainConverters(config.getToolChain(), fromId)) { + // Add this converter to the display list + getConversionTargets().put( element.getAttribute("name"), element); //$NON-NLS-1$ + } + } + } + } + } + if ( getConversionTargets().isEmpty()) + return (String []) emptyList; + else + return (String []) getConversionTargets().keySet().toArray(new String[getConversionTargets().size()]); + } + + private boolean hasToolChainConverters(IToolChain toolChain, String fromId) { + +// Check whether the converter's 'fromId' and the given toolChain 'id' are equal + if(fromId == null) + return false; + + while( toolChain != null) { + String id = toolChain.getId(); + + if (fromId.equals(id)) + return true; + else + toolChain = toolChain.getSuperClass(); + } + return false; } private void updateConversionTargets(IConfiguration config) { conversionTargetSelector.setItems( getConversionTargetList(config)); conversionTargetSelector.select(0); - conversionTargetSelector.setEnabled(conversionTargetSelector.getItemCount() > 1); - convertTargetBtn.setEnabled( conversionTargetSelector.getItemCount() > 1); + conversionGroup.setEnabled(conversionTargetSelector.getItemCount() > 0); + convertTargetBtn.setEnabled( conversionTargetSelector.getItemCount() > 0); } private String [] getConfigurationNamesAndDescriptions() { @@ -337,6 +435,13 @@ public class ManageConfigDialog extends Dialog { } + protected SortedMap getConversionTargets() { + if (conversionTargets == null) { + conversionTargets = new TreeMap(); + } + return conversionTargets; + } + /* * @return the <code>IProject</code> associated with the managed project */ @@ -525,7 +630,7 @@ public class ManageConfigDialog extends Dialog { private void updateButtons() { // Disable the remove button if there is only 1 configuration removeBtn.setEnabled(currentConfigList.getItemCount() > 1); - convertTargetBtn.setEnabled( conversionTargetSelector.getItemCount() > 1); + convertTargetBtn.setEnabled( conversionTargetSelector.getItemCount() > 0); } private void handleConfigSelection() { |