1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-07 02:23:18 +02:00

Bug 558474 - CleanUp deprecated methods in org.eclipse.cdt.ui

Reworked SubMonitors (Part2)
Fixed percentage counting
Removed explicit cancellation checks.

Change-Id: Ibd9ef2664885746ab9ac2be556ac5effc994a512
Signed-off-by: Sergey Kovalchuk <sergei.kovalchuk@arsysop.ru>
This commit is contained in:
Sergey Kovalchuk 2020-01-03 10:52:38 +03:00 committed by Jonah Graham
parent 55e08c0dfa
commit b74f56878c
3 changed files with 34 additions and 57 deletions

View file

@ -61,6 +61,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.IWizard; import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.IWizardPage; import org.eclipse.jface.wizard.IWizardPage;
@ -576,15 +577,11 @@ public class MBSWizardHandler extends CWizardHandler {
@Override @Override
public void createProject(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor) public void createProject(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor)
throws CoreException { throws CoreException {
try { SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
monitor.beginTask("", 100); //$NON-NLS-1$ setProjectDescription(project, defaults, onFinish, subMonitor.split(70));
setProjectDescription(project, defaults, onFinish, monitor); doTemplatesPostProcess(project);
doTemplatesPostProcess(project); doCustom(project);
doCustom(project); subMonitor.worked(30);
monitor.worked(30);
} finally {
monitor.done();
}
} }
@Override @Override
@ -594,10 +591,11 @@ public class MBSWizardHandler extends CWizardHandler {
private void setProjectDescription(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor) private void setProjectDescription(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor)
throws CoreException { throws CoreException {
SubMonitor subMonitor = SubMonitor.convert(monitor, 3);
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
ICProjectDescription des = mngr.createProjectDescription(project, false, !onFinish); ICProjectDescription des = mngr.createProjectDescription(project, false, !onFinish);
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project); ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
monitor.worked(10); subMonitor.worked(1);
cfgs = getCfgItems(false); cfgs = getCfgItems(false);
if (cfgs == null || cfgs.length == 0) if (cfgs == null || cfgs.length == 0)
cfgs = CDTConfigWizardPage.getDefaultCfgs(this); cfgs = CDTConfigWizardPage.getDefaultCfgs(this);
@ -609,15 +607,15 @@ public class MBSWizardHandler extends CWizardHandler {
Configuration cf = (Configuration) cfgs[0].getConfiguration(); Configuration cf = (Configuration) cfgs[0].getConfiguration();
ManagedProject mProj = new ManagedProject(project, cf.getProjectType()); ManagedProject mProj = new ManagedProject(project, cf.getProjectType());
info.setManagedProject(mProj); info.setManagedProject(mProj);
monitor.worked(10);
cfgs = CfgHolder.unique(cfgs); cfgs = CfgHolder.unique(cfgs);
cfgs = CfgHolder.reorder(cfgs); cfgs = CfgHolder.reorder(cfgs);
ICConfigurationDescription cfgDebug = null; ICConfigurationDescription cfgDebug = null;
ICConfigurationDescription cfgFirst = null; ICConfigurationDescription cfgFirst = null;
subMonitor.worked(1);
int work = 50 / cfgs.length; SubMonitor cfgMonitor = SubMonitor.convert(subMonitor.split(1), cfgs.length);
for (CfgHolder cfg : cfgs) { for (CfgHolder cfg : cfgs) {
cf = (Configuration) cfg.getConfiguration(); cf = (Configuration) cfg.getConfiguration();
String id = ManagedBuildManager.calculateChildId(cf.getId(), null); String id = ManagedBuildManager.calculateChildId(cf.getId(), null);
@ -640,7 +638,7 @@ public class MBSWizardHandler extends CWizardHandler {
cfgDebug = cfgDes; cfgDebug = cfgDes;
if (cfgFirst == null) // select at least first configuration if (cfgFirst == null) // select at least first configuration
cfgFirst = cfgDes; cfgFirst = cfgDes;
monitor.worked(work); cfgMonitor.worked(1);
} }
mngr.setProjectDescription(project, des); mngr.setProjectDescription(project, des);
} }

View file

@ -20,8 +20,7 @@ import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.internal.ui.newui.Messages; import org.eclipse.cdt.internal.ui.newui.Messages;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
/** /**
* The wizard to create new MBS C++ Project. * The wizard to create new MBS C++ Project.
@ -39,17 +38,11 @@ public class CCProjectWizard extends CDTCommonProjectWizard {
@Override @Override
protected IProject continueCreation(IProject prj) { protected IProject continueCreation(IProject prj) {
if (continueCreationMonitor == null) { SubMonitor subMonitor = SubMonitor.convert(continueCreationMonitor, Messages.CCProjectWizard_0, 2);
continueCreationMonitor = new NullProgressMonitor();
}
try { try {
continueCreationMonitor.beginTask(Messages.CCProjectWizard_0, 2); CProjectNature.addCNature(prj, subMonitor.split(1));
CProjectNature.addCNature(prj, new SubProgressMonitor(continueCreationMonitor, 1)); CCProjectNature.addCCNature(prj, subMonitor.split(1));
CCProjectNature.addCCNature(prj, new SubProgressMonitor(continueCreationMonitor, 1));
} catch (CoreException e) { } catch (CoreException e) {
} finally {
continueCreationMonitor.done();
} }
return prj; return prj;
} }

View file

@ -45,7 +45,7 @@ import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.content.IContentType; import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager; import org.eclipse.core.runtime.content.IContentTypeManager;
import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.MessageDialog;
@ -242,25 +242,18 @@ public abstract class CDTCommonProjectWizard extends BasicNewResourceWizard
final Exception except[] = new Exception[1]; final Exception except[] = new Exception[1];
getShell().getDisplay().syncExec(() -> { getShell().getDisplay().syncExec(() -> {
IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(monitor -> { IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(monitor -> {
final IProgressMonitor fMonitor;
if (monitor == null) { SubMonitor subMonitor = SubMonitor.convert(monitor,
fMonitor = new NullProgressMonitor(); CUIPlugin.getResourceString("CProjectWizard.op_description"), 100);//$NON-NLS-1$
} else { subMonitor.worked(10);
fMonitor = monitor;
}
fMonitor.beginTask(CUIPlugin.getResourceString("CProjectWizard.op_description"), 100); //$NON-NLS-1$
fMonitor.worked(10);
try { try {
newProject = createIProject(lastProjectName, lastProjectLocation, newProject = createIProject(lastProjectName, lastProjectLocation, subMonitor.split(40));
new SubProgressMonitor(fMonitor, 40)); if (newProject != null) {
if (newProject != null) fMainPage.h_selected.createProject(newProject, defaults, onFinish, subMonitor.split(40));
fMainPage.h_selected.createProject(newProject, defaults, onFinish, }
new SubProgressMonitor(fMonitor, 40)); subMonitor.worked(10);
fMonitor.worked(10);
} catch (CoreException e) { } catch (CoreException e) {
CUIPlugin.errorDialog(getShell(), title, message, e, true); CUIPlugin.errorDialog(getShell(), title, message, e, true);
} finally {
fMonitor.done();
} }
}); });
try { try {
@ -301,9 +294,7 @@ public abstract class CDTCommonProjectWizard extends BasicNewResourceWizard
@Override @Override
public IProject createIProject(final String name, final URI location, IProgressMonitor monitor) public IProject createIProject(final String name, final URI location, IProgressMonitor monitor)
throws CoreException { throws CoreException {
SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.CDTCommonProjectWizard_creatingProject, 100);
monitor.beginTask(Messages.CDTCommonProjectWizard_creatingProject, 100);
if (newProject != null) if (newProject != null)
return newProject; return newProject;
@ -316,27 +307,22 @@ public abstract class CDTCommonProjectWizard extends BasicNewResourceWizard
// workspaceDesc.setAutoBuilding(false); // workspaceDesc.setAutoBuilding(false);
// workspace.setDescription(workspaceDesc); // workspace.setDescription(workspaceDesc);
IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName()); IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
if (location != null) if (location != null) {
description.setLocationURI(location); description.setLocationURI(location);
newProject = CCorePlugin.getDefault().createCDTProject(description, newProjectHandle, }
new SubProgressMonitor(monitor, 25)); newProject = CCorePlugin.getDefault().createCDTProject(description, newProjectHandle, subMonitor.split(50));
} else { } else {
IWorkspaceRunnable runnable = monitor1 -> newProjectHandle.refreshLocal(IResource.DEPTH_INFINITE, monitor1); IWorkspaceRunnable runnable = monitor1 -> newProjectHandle.refreshLocal(IResource.DEPTH_INFINITE, monitor1);
workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, new SubProgressMonitor(monitor, 25)); workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, subMonitor.split(50));
newProject = newProjectHandle; newProject = newProjectHandle;
} }
// Open the project if we have to // Open the project if we have to
if (!newProject.isOpen()) { if (!newProject.isOpen()) {
newProject.open(new SubProgressMonitor(monitor, 25)); newProject.open(subMonitor.split(25));
} }
continueCreationMonitor = subMonitor.split(25);
continueCreationMonitor = new SubProgressMonitor(monitor, 25); return continueCreation(newProject);
IProject proj = continueCreation(newProject);
monitor.done();
return proj;
} }
protected abstract IProject continueCreation(IProject prj); protected abstract IProject continueCreation(IProject prj);