1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

bug 250982 - add progress reporting to new project wizard

This commit is contained in:
Vivian Kong 2008-11-13 16:12:38 +00:00
parent d60c8570b9
commit 926ee25abb
7 changed files with 220 additions and 96 deletions

View file

@ -55,6 +55,7 @@ import org.eclipse.cdt.ui.wizards.EntryDescriptor;
import org.eclipse.cdt.ui.wizards.IWizardItemsListListener;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.operation.IRunnableWithProgress;
@ -520,54 +521,63 @@ public class MBSWizardHandler extends CWizardHandler {
full_tcs.put(tc.getUniqueRealName(), tc);
}
public void createProject(IProject project, boolean defaults, boolean onFinish) throws CoreException {
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
ICProjectDescription des = mngr.createProjectDescription(project, false, !onFinish);
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
cfgs = fConfigPage.getCfgItems(false);
if (cfgs == null || cfgs.length == 0)
cfgs = CDTConfigWizardPage.getDefaultCfgs(this);
if (cfgs == null || cfgs.length == 0 || cfgs[0].getConfiguration() == null) {
throw new CoreException(new Status(IStatus.ERROR,
ManagedBuilderUIPlugin.getUniqueIdentifier(),
Messages.getString("CWizardHandler.6"))); //$NON-NLS-1$
}
Configuration cf = (Configuration)cfgs[0].getConfiguration();
ManagedProject mProj = new ManagedProject(project, cf.getProjectType());
info.setManagedProject(mProj);
cfgs = CfgHolder.unique(cfgs);
cfgs = CfgHolder.reorder(cfgs);
ICConfigurationDescription cfgDebug = null;
ICConfigurationDescription cfgFirst = null;
for(int i = 0; i < cfgs.length; i++){
cf = (Configuration)cfgs[i].getConfiguration();
String id = ManagedBuildManager.calculateChildId(cf.getId(), null);
Configuration config = new Configuration(mProj, cf, id, false, true);
CConfigurationData data = config.getConfigurationData();
ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
config.setConfigurationDescription(cfgDes);
config.exportArtifactInfo();
IBuilder bld = config.getEditableBuilder();
if (bld != null) { bld.setManagedBuildOn(true); }
public void createProject(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor) throws CoreException {
try {
monitor.beginTask("", 100); //$NON-NLS-1$
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
ICProjectDescription des = mngr.createProjectDescription(project, false, !onFinish);
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
monitor.worked(10);
cfgs = fConfigPage.getCfgItems(false);
if (cfgs == null || cfgs.length == 0)
cfgs = CDTConfigWizardPage.getDefaultCfgs(this);
config.setName(cfgs[i].getName());
config.setArtifactName(removeSpaces(project.getName()));
if (cfgs == null || cfgs.length == 0 || cfgs[0].getConfiguration() == null) {
throw new CoreException(new Status(IStatus.ERROR,
ManagedBuilderUIPlugin.getUniqueIdentifier(),
Messages.getString("CWizardHandler.6"))); //$NON-NLS-1$
}
Configuration cf = (Configuration)cfgs[0].getConfiguration();
ManagedProject mProj = new ManagedProject(project, cf.getProjectType());
info.setManagedProject(mProj);
monitor.worked(10);
cfgs = CfgHolder.unique(cfgs);
cfgs = CfgHolder.reorder(cfgs);
IBuildProperty b = config.getBuildProperties().getProperty(PROPERTY);
if (cfgDebug == null && b != null && b.getValue() != null && PROP_VAL.equals(b.getValue().getId()))
cfgDebug = cfgDes;
if (cfgFirst == null) // select at least first configuration
cfgFirst = cfgDes;
ICConfigurationDescription cfgDebug = null;
ICConfigurationDescription cfgFirst = null;
int work = 50/cfgs.length;
for(int i = 0; i < cfgs.length; i++){
cf = (Configuration)cfgs[i].getConfiguration();
String id = ManagedBuildManager.calculateChildId(cf.getId(), null);
Configuration config = new Configuration(mProj, cf, id, false, true);
CConfigurationData data = config.getConfigurationData();
ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
config.setConfigurationDescription(cfgDes);
config.exportArtifactInfo();
IBuilder bld = config.getEditableBuilder();
if (bld != null) { bld.setManagedBuildOn(true); }
config.setName(cfgs[i].getName());
config.setArtifactName(removeSpaces(project.getName()));
IBuildProperty b = config.getBuildProperties().getProperty(PROPERTY);
if (cfgDebug == null && b != null && b.getValue() != null && PROP_VAL.equals(b.getValue().getId()))
cfgDebug = cfgDes;
if (cfgFirst == null) // select at least first configuration
cfgFirst = cfgDes;
monitor.worked(work);
}
mngr.setProjectDescription(project, des);
doTemplatesPostProcess(project);
doCustom(project);
monitor.worked(30);
} finally {
monitor.done();
}
mngr.setProjectDescription(project, des);
doTemplatesPostProcess(project);
doCustom(project);
}
protected void doTemplatesPostProcess(IProject prj) {

View file

@ -7,6 +7,7 @@
*
* Contributors:
* Intel Corporation - initial API and implementation
* IBM Corporation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.ui.wizards;
@ -26,6 +27,7 @@ import org.eclipse.cdt.managedbuilder.ui.properties.Messages;
import org.eclipse.cdt.ui.newui.UIMessages;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.swt.widgets.Composite;
@ -48,40 +50,49 @@ public class STDWizardHandler extends MBSWizardHandler {
/**
* Note that configurations parameter is ignored
*/
public void createProject(IProject project, boolean defaults, boolean onFinish) throws CoreException {
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
ICProjectDescription des = mngr.createProjectDescription(project, false, !onFinish);
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
ManagedProject mProj = new ManagedProject(des);
info.setManagedProject(mProj);
cfgs = CfgHolder.unique(fConfigPage.getCfgItems(defaults));
cfgs = CfgHolder.reorder(cfgs);
for (int i=0; i<cfgs.length; i++) {
String s = (cfgs[i].getToolChain() == null) ? "0" : ((ToolChain)(cfgs[i].getToolChain())).getId(); //$NON-NLS-1$
Configuration cfg = new Configuration(mProj, (ToolChain)cfgs[i].getToolChain(), ManagedBuildManager.calculateChildId(s, null), cfgs[i].getName());
IBuilder bld = cfg.getEditableBuilder();
if (bld != null) {
if(bld.isInternalBuilder()){
IConfiguration prefCfg = ManagedBuildManager.getPreferenceConfiguration(false);
IBuilder prefBuilder = prefCfg.getBuilder();
cfg.changeBuilder(prefBuilder, ManagedBuildManager.calculateChildId(cfg.getId(), null), prefBuilder.getName());
bld = cfg.getEditableBuilder();
bld.setBuildPath(null);
}
bld.setManagedBuildOn(false);
} else {
System.out.println(UIMessages.getString("StdProjectTypeHandler.3")); //$NON-NLS-1$
}
cfg.setArtifactName(removeSpaces(project.getName()));
CConfigurationData data = cfg.getConfigurationData();
des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
}
mngr.setProjectDescription(project, des);
@Override
public void createProject(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor) throws CoreException {
try {
monitor.beginTask("", 100);//$NON-NLS-1$
doTemplatesPostProcess(project);
doCustom(project);
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
ICProjectDescription des = mngr.createProjectDescription(project, false, !onFinish);
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
ManagedProject mProj = new ManagedProject(des);
info.setManagedProject(mProj);
monitor.worked(20);
cfgs = CfgHolder.unique(fConfigPage.getCfgItems(defaults));
cfgs = CfgHolder.reorder(cfgs);
int work = 50/cfgs.length;
for (int i=0; i<cfgs.length; i++) {
String s = (cfgs[i].getToolChain() == null) ? "0" : ((ToolChain)(cfgs[i].getToolChain())).getId(); //$NON-NLS-1$
Configuration cfg = new Configuration(mProj, (ToolChain)cfgs[i].getToolChain(), ManagedBuildManager.calculateChildId(s, null), cfgs[i].getName());
IBuilder bld = cfg.getEditableBuilder();
if (bld != null) {
if(bld.isInternalBuilder()){
IConfiguration prefCfg = ManagedBuildManager.getPreferenceConfiguration(false);
IBuilder prefBuilder = prefCfg.getBuilder();
cfg.changeBuilder(prefBuilder, ManagedBuildManager.calculateChildId(cfg.getId(), null), prefBuilder.getName());
bld = cfg.getEditableBuilder();
bld.setBuildPath(null);
}
bld.setManagedBuildOn(false);
} else {
System.out.println(UIMessages.getString("StdProjectTypeHandler.3")); //$NON-NLS-1$
}
cfg.setArtifactName(removeSpaces(project.getName()));
CConfigurationData data = cfg.getConfigurationData();
des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
monitor.worked(work);
}
mngr.setProjectDescription(project, des);
doTemplatesPostProcess(project);
doCustom(project);
monitor.worked(30);
} finally {
monitor.done();
}
}
public boolean canCreateWithoutToolchain() { return true; }

View file

@ -526,6 +526,8 @@ NewCfgDialog.4=Import from projects
NewCfgDialog.5=Import predefined
CDTMainWizardPage.0=Project name cannot contain '\#' symbol
CDTMainWizardPage.1=Project category is selected. Expand the category and select a concrete project type.
CProjectWizard.0=Add C Project Nature
CCProjectWizard.0=Add CC Project Nature
WorkingSetConfigAction.0=Symbols '
WorkingSetConfigAction.1=Choose active configs for Working Sets
WorkingSetConfigAction.10=-- CURRENT --

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Intel Corporation and others.
* Copyright (c) 2007, 2008 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
@ -7,12 +7,14 @@
*
* Contributors:
* Intel Corporation - initial API and implementation
* IBM Corporation
*******************************************************************************/
package org.eclipse.cdt.ui.wizards;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin;
@ -32,10 +34,16 @@ public class CCProjectWizard extends CDTCommonProjectWizard {
@Override
protected IProject continueCreation(IProject prj) {
if (continueCreationMonitor == null) {
continueCreationMonitor = new NullProgressMonitor();
}
try {
CProjectNature.addCNature(prj, new NullProgressMonitor());
CCProjectNature.addCCNature(prj, new NullProgressMonitor());
continueCreationMonitor.beginTask(UIMessages.getString("CCProjectWizard.0"), 2); //$NON-NLS-1$
CProjectNature.addCNature(prj, new SubProgressMonitor(continueCreationMonitor, 1));
CCProjectNature.addCCNature(prj, new SubProgressMonitor(continueCreationMonitor, 1));
} catch (CoreException e) {}
finally {continueCreationMonitor.done();}
return prj;
}

View file

@ -34,6 +34,7 @@ import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager;
import org.eclipse.jface.dialogs.MessageDialog;
@ -230,23 +231,70 @@ implements IExecutableExtension, IWizardWithMemory
final boolean defaults = _defaults;
return new IRunnableWithProgress() {
public void run(IProgressMonitor imonitor) throws InvocationTargetException, InterruptedException {
final Exception except[] = new Exception[1];
getShell().getDisplay().syncExec(new Runnable() {
public void run() {
public void run() {
IRunnableWithProgress op= new WorkspaceModifyDelegatingOperation(new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
final IProgressMonitor fMonitor;
if (monitor == null) {
fMonitor= new NullProgressMonitor();
} else {
fMonitor = monitor;
}
fMonitor.beginTask(CUIPlugin.getResourceString("CProjectWizard.op_description"), 100); //$NON-NLS-1$
fMonitor.worked(10);
try {
newProject = createIProject(lastProjectName, lastProjectLocation, new SubProgressMonitor(fMonitor, 40));
if (newProject != null)
fMainPage.h_selected.createProject(newProject, defaults, onFinish, new SubProgressMonitor(fMonitor, 40));
fMonitor.worked(10);
} catch (CoreException e) { CUIPlugin.log(e); }
finally {
fMonitor.done();
}
}
});
try {
newProject = createIProject(lastProjectName, lastProjectLocation);
if (newProject != null)
fMainPage.h_selected.createProject(newProject, defaults, onFinish);
} catch (CoreException e) { CUIPlugin.log(e); }
getContainer().run(false, true, op);
} catch (InvocationTargetException e) {
except[0] = e;
} catch (InterruptedException e) {
except[0] = e;
}
}
});
if (except[0] != null) {
if (except[0] instanceof InvocationTargetException) {
throw (InvocationTargetException)except[0];
}
if (except[0] instanceof InterruptedException) {
throw (InterruptedException)except[0];
}
throw new InvocationTargetException(except[0]);
}
}
};
}
public IProject createIProject(final String name, final URI location) throws CoreException{
return createIProject(name, location, new NullProgressMonitor());
}
/**
* @since 5.1
*/
protected IProgressMonitor continueCreationMonitor;
/**
* @param monitor
* @since 5.1
*
*/
public IProject createIProject(final String name, final URI location) throws CoreException{
public IProject createIProject(final String name, final URI location, IProgressMonitor monitor) throws CoreException{
monitor.beginTask("createIProject", 100);
if (newProject != null) return newProject;
IWorkspace workspace = ResourcesPlugin.getWorkspace();
@ -260,23 +308,28 @@ implements IExecutableExtension, IWizardWithMemory
IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
if(location != null)
description.setLocationURI(location);
newProject = CCorePlugin.getDefault().createCDTProject(description, newProjectHandle, new NullProgressMonitor());
newProject = CCorePlugin.getDefault().createCDTProject(description, newProjectHandle, new SubProgressMonitor(monitor,25));
} else {
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
newProjectHandle.refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
};
NullProgressMonitor monitor = new NullProgressMonitor();
workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, monitor);
workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, new SubProgressMonitor(monitor,25));
newProject = newProjectHandle;
}
// Open the project if we have to
if (!newProject.isOpen()) {
newProject.open(new NullProgressMonitor());
newProject.open(new SubProgressMonitor(monitor,25));
}
return continueCreation(newProject);
continueCreationMonitor = new SubProgressMonitor(monitor,25);
IProject proj = continueCreation(newProject);
monitor.done();
return proj;
}
protected abstract IProject continueCreation(IProject prj);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Intel Corporation and others.
* Copyright (c) 2007, 2008 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
@ -7,12 +7,14 @@
*
* Contributors:
* Intel Corporation - initial API and implementation
* IBM Corporation
*******************************************************************************/
package org.eclipse.cdt.ui.wizards;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature;
@ -29,12 +31,18 @@ public class CProjectWizard extends CDTCommonProjectWizard {
public String[] getNatures() {
return new String[] { CProjectNature.C_NATURE_ID };
}
@Override
protected IProject continueCreation(IProject prj) {
if (continueCreationMonitor == null) {
continueCreationMonitor = new NullProgressMonitor();
}
try {
CProjectNature.addCNature(prj, new NullProgressMonitor());
continueCreationMonitor.beginTask(UIMessages.getString("CProjectWizard.0"), 1); //$NON-NLS-1$
CProjectNature.addCNature(prj, new SubProgressMonitor(continueCreationMonitor, 1));
} catch (CoreException e) {}
finally {continueCreationMonitor.done();}
return prj;
}

View file

@ -7,6 +7,7 @@
*
* Contributors:
* Intel Corporation - initial API and implementation
* IBM Corporation
*******************************************************************************/
package org.eclipse.cdt.ui.wizards;
@ -14,6 +15,7 @@ import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
@ -148,7 +150,7 @@ public class CWizardHandler implements Cloneable {
* @param proj - simple project to be used as base
* @param defaults - true if called from 1st Wizard page
* @param onFinish - true when the project creation is performed on finish. false -otherwise
* false means that the project created is actually a temporary one that can be removed in case cancell is pressed
* false means that the project created is actually a temporary one that can be removed in case cancel is pressed
*
* @throws CoreException
*/
@ -156,6 +158,36 @@ public class CWizardHandler implements Cloneable {
throws CoreException {
createProject(proj, defaults);
}
/**
* Creates project
*
* @param proj - simple project to be used as base
* @param defaults - true if called from 1st Wizard page
* @param monitor - progress monitor to track the creation process
* @throws CoreException
* @since 5.1
*/
public void createProject(IProject proj, boolean defaults, IProgressMonitor monitor)
throws CoreException {}
/**
* Creates project
*
* @param proj - simple project to be used as base
* @param defaults - true if called from 1st Wizard page
* @param onFinish - true when the project creation is performed on finish. false -otherwise
* false means that the project created is actually a temporary one that can be removed in case cancel is pressed
* @param monitor - progress monitor to track the creation process
*
* @throws CoreException
* @since 5.1
*/
public void createProject(IProject proj, boolean defaults, boolean onFinish, IProgressMonitor monitor)
throws CoreException {
createProject(proj, defaults, monitor);
}
/**
*
* @return true if settings were changed