diff --git a/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties b/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties index 96692bc40b1..79c08ba4dd7 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties +++ b/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties @@ -26,3 +26,6 @@ MngBuildPref.name=Managed Build #The Resource Property page MngResourceProp.name=C/C++ Build + +#The Project Converter page +ConvertTargetAction.label=Convert To... diff --git a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml index b3261dbb275..d61427c4572 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml @@ -121,5 +121,25 @@ id="org.eclipse.cdt.managedbuilder.ui.preferences.BuildPreferences"> - + + + + + + + + + + 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 7bf5d8277d0..2d39fa9dc50 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 @@ -327,3 +327,17 @@ MngMakeProjectPropertyPage.internalError=An Internal error has occur please chec showAdvanced = &Advanced >> hideAdvanced = << &Advanced NewFolderDialog.folderNameEmpty = Folder name must be specified + +# Project Conversion Dialog messages +ProjectConvert.confirmdialog.title=Confirm Project Conversion +ProjectConvert.confirmdialog.message=The selected project {0} will be converted. Do you want to proceed ? + +ProjectConvert.conversionErrordialog.title=Project Conversion Error +ProjectConvert.conversionErrordialog.message=Error has occured during the conversion of the project {0} . + +ProjectConvert.noConverterErrordialog.title=Project Conversion Error +ProjectConvert.noConverterErrordialog.message=There are no converters available to convert the project {0} . + +ProjectConvert.title=Project Converters for {0} +ProjectConvert.convertersList=Converters List + 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 index 4cd1afd1c12..1c4c67f0c4f 100644 --- 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 @@ -10,10 +10,6 @@ *******************************************************************************/ 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; @@ -22,11 +18,6 @@ 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; @@ -40,93 +31,29 @@ 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 final String PREFIX = "ProjectConvert"; //$NON-NLS-1$ + public static final String PROJECT_CONVERTER_DIALOG = PREFIX + ".title"; //$NON-NLS-1$ + 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; - + 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); + return; } } + setSelectedProject(null); } - + private IProjectType getProjectType(IProject project) { IProjectType projectType = null; @@ -134,76 +61,48 @@ public class ConvertTargetAction IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); if (info != null) { IManagedProject managedProject = info.getManagedProject(); - projectType = managedProject.getProjectType(); + if ( managedProject != null ) + 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(); + public void run(IAction action) { + Shell shell = ManagedBuilderUIPlugin.getDefault().getShell(); + + // Check whether the converters available for the selected project + // If there are no converters display error dialog otherwise display converters list + + if( ManagedBuildManager.hasTargetConversionElements(getProjectType(getSelectedProject())) == true ) { + handleConvertTargetAction(); + } else { + MessageDialog.openError(shell,ManagedBuilderUIMessages.getResourceString("ProjectConvert.noConverterErrordialog.title"), //$NON-NLS-1$ + ManagedBuilderUIMessages.getFormattedString("ProjectConvert.noConverterErrordialog.message", new String[] {getSelectedProject().getName()}) ); //$NON-NLS-1$ } - 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); + private void handleConvertTargetAction() { + Shell shell = ManagedBuilderUIPlugin.getDefault().getShell(); + + String title = ManagedBuilderUIMessages.getFormattedString(PROJECT_CONVERTER_DIALOG, new String(getSelectedProject().getName())); + ConvertTargetDialog dialog = new ConvertTargetDialog(shell, getSelectedProject(), title); + if ( dialog.open() == ConvertTargetDialog.OK ) { + if ( ConvertTargetDialog.isConversionSuccessful() == false) { + MessageDialog.openError( + shell, + ManagedBuilderUIMessages + .getResourceString("ProjectConvert.conversionErrordialog.title"), //$NON-NLS-1$ + ManagedBuilderUIMessages + .getFormattedString( + "ProjectConvert.conversionErrordialog.message", new String[] { getSelectedProject().getName() })); //$NON-NLS-1$ } } - + return; } - + 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; + // TODO Auto-generated method stub } /** @@ -219,18 +118,4 @@ public class ConvertTargetAction 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/actions/ConvertTargetDialog.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/ConvertTargetDialog.java new file mode 100644 index 00000000000..de9a12fdfde --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/ConvertTargetDialog.java @@ -0,0 +1,225 @@ +/******************************************************************************* + * 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.HashMap; +import java.util.Map; +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.internal.ui.dialogs.StatusDialog; +import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; + +public class ConvertTargetDialog extends StatusDialog { + + final private String title; + protected List convertersList; + private IProject project; + private Map conversionElements; + private IConfigurationElement selectedConversionElement; + private static boolean isConversionSuccessful = false; + + public static final String PREFIX = "ProjectConvert"; //$NON-NLS-1$ + public static final String CONVERTERS_LIST = PREFIX +".convertersList"; //$NON-NLS-1$ + + + /** + * @param parentShell + * @param project + * @param title The title of the dialog + */ + protected ConvertTargetDialog(Shell parentShell, IProject project, String title) { + super(parentShell); + this.title = title; + setProject(project); + + conversionElements = ManagedBuildManager.getConversionElements(getProjectType()); + + setShellStyle(getShellStyle()|SWT.RESIZE); + } + + protected void buttonPressed(int buttonId) { + if (buttonId == IDialogConstants.OK_ID) { + + handleConverterSelection(); + IConvertManagedBuildObject convertBuildObject = null; + try { + convertBuildObject = (IConvertManagedBuildObject) getSelectedConversionElement() + .createExecutableExtension("class"); //$NON-NLS-1$ + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (convertBuildObject != null) { + String fromId = getSelectedConversionElement().getAttribute( + "fromId"); //$NON-NLS-1$ + String toId = getSelectedConversionElement().getAttribute( + "toId"); //$NON-NLS-1$ + + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(getProject()); + if (info != null) { + IManagedProject managedProject = info.getManagedProject(); + if (managedProject != null) { + if (convertBuildObject.convert(managedProject, fromId, + toId, true) == null) { + setConversionSuccessful(false); + } else { + setConversionSuccessful(true); + } + } else { + setConversionSuccessful(false); + } + } else { + setConversionSuccessful(false); + } + } else { + setConversionSuccessful(false); + } + } + super.buttonPressed(buttonId); + } + + + protected void configureShell(Shell shell) { + super.configureShell(shell); + if (title != null) + shell.setText(title); + } + + protected Control createDialogArea(Composite parent) { + + Composite comp = new Composite(parent, SWT.NULL); + comp.setFont(parent.getFont()); + comp.setLayout(new GridLayout(1, true)); + comp.setLayoutData(new GridData(GridData.FILL_BOTH)); + + // Create the converters list group area + final Group convertersListGroup = new Group(comp, SWT.NONE); + convertersListGroup.setFont(parent.getFont()); + convertersListGroup.setText(ManagedBuilderUIMessages.getResourceString(CONVERTERS_LIST)); + convertersListGroup.setLayout(new GridLayout(1, false)); + convertersListGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); + + // Create the current config List + convertersList = new List(convertersListGroup, SWT.SINGLE|SWT.V_SCROLL|SWT.H_SCROLL|SWT.BORDER); + convertersList.setFont(convertersListGroup.getFont()); + GridData data = new GridData(GridData.FILL_BOTH); + convertersList.setLayoutData(data); + convertersList.addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent event) { + convertersList = null; + } + }); + convertersList.addListener (SWT.Selection, new Listener () { + public void handleEvent(Event e) { + validateState(); + } + }); + Object [] objs = getConversionElements().keySet().toArray(); + String [] names = new String[objs.length]; + for (int i = 0; i < objs.length; i++) { + Object object = objs[i]; + names[i] = (String)object; + } + convertersList.setItems(names); + validateState(); + return comp; + } + + private void handleConverterSelection() { + // Determine which configuration was selected + int selectionIndex = convertersList.getSelectionIndex(); + + String selectedConverterName = convertersList + .getItem(selectionIndex); + + IConfigurationElement selectedElement = (IConfigurationElement) getConversionElements() + .get(selectedConverterName); + setSelectedConversionElement(selectedElement); + return; + } + + private void validateState() { + StatusInfo status= new StatusInfo(); + if ( convertersList.getSelectionIndex() == -1 ) { + // No error, just disable 'Ok' button + status.setError(""); //$NON-NLS-1$ + } + updateStatus(status); + return; + } + + private Map getConversionElements() { + if (conversionElements == null) { + conversionElements = new HashMap(); + } + return conversionElements; + } + + private IProjectType getProjectType() { + IProjectType projectType = null; + + // Get the projectType from project. + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(getProject()); + if (info != null) { + IManagedProject managedProject = info.getManagedProject(); + if ( managedProject != null) { + projectType = managedProject.getProjectType(); + } + } + return projectType; + } + + public IProject getProject() { + return project; + } + + public void setProject(IProject project) { + this.project = project; + } + + public IConfigurationElement getSelectedConversionElement() { + return selectedConversionElement; + } + + public void setSelectedConversionElement( + IConfigurationElement selectedConversionElement) { + this.selectedConversionElement = selectedConversionElement; + } + + public static boolean isConversionSuccessful() { + return isConversionSuccessful; + } + + public void setConversionSuccessful(boolean isConversionSuccessful) { + ConvertTargetDialog.isConversionSuccessful = isConversionSuccessful; + } +} +