mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-12 10:45:37 +02:00
Bug 558474 - CleanUp deprecated methods in org.eclipse.cdt.ui
Reworked SubMonitors (Part3) Change-Id: I146ba515f78ad15e94267b52d0123bf53f98289b Signed-off-by: Sergey Kovalchuk <sergei.kovalchuk@arsysop.ru>
This commit is contained in:
parent
b74f56878c
commit
9cbe95695c
2 changed files with 10 additions and 29 deletions
|
@ -28,9 +28,8 @@ import org.eclipse.core.resources.IWorkspaceRoot;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.OperationCanceledException;
|
|
||||||
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.preferences.IPreferencesService;
|
import org.eclipse.core.runtime.preferences.IPreferencesService;
|
||||||
import org.eclipse.ui.dialogs.ContainerGenerator;
|
import org.eclipse.ui.dialogs.ContainerGenerator;
|
||||||
|
|
||||||
|
@ -120,43 +119,35 @@ public class NewSourceFileGenerator {
|
||||||
|
|
||||||
private static IFile createNewFile(IPath newFilePath, InputStream contents, boolean force, IProgressMonitor monitor)
|
private static IFile createNewFile(IPath newFilePath, InputStream contents, boolean force, IProgressMonitor monitor)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
int totalWork = 100;
|
SubMonitor subMonitor = SubMonitor.convert(monitor,
|
||||||
int createFileWork = totalWork;
|
NewFileWizardMessages.NewSourceFileGenerator_createFile_task, 100);
|
||||||
|
|
||||||
monitor.beginTask(NewFileWizardMessages.NewSourceFileGenerator_createFile_task, totalWork);
|
|
||||||
|
|
||||||
IWorkspaceRoot root = CUIPlugin.getWorkspace().getRoot();
|
IWorkspaceRoot root = CUIPlugin.getWorkspace().getRoot();
|
||||||
IFile newFile = root.getFileForLocation(newFilePath);
|
IFile newFile = root.getFileForLocation(newFilePath);
|
||||||
if (newFile == null)
|
if (newFile == null)
|
||||||
newFile = root.getFile(newFilePath);
|
newFile = root.getFile(newFilePath);
|
||||||
if (newFile.exists()) {
|
if (newFile.exists()) {
|
||||||
monitor.done();
|
|
||||||
return newFile;
|
return newFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newFilePath.segmentCount() > 1) {
|
if (newFilePath.segmentCount() > 1) {
|
||||||
IPath containerPath = newFilePath.removeLastSegments(1);
|
IPath containerPath = newFilePath.removeLastSegments(1);
|
||||||
if (root.getContainerForLocation(containerPath) == null) {
|
if (root.getContainerForLocation(containerPath) == null) {
|
||||||
int containerWork = totalWork / 2;
|
|
||||||
createFileWork = totalWork / 2;
|
|
||||||
ContainerGenerator generator = new ContainerGenerator(containerPath);
|
ContainerGenerator generator = new ContainerGenerator(containerPath);
|
||||||
generator.generateContainer(new SubProgressMonitor(monitor, containerWork));
|
generator.generateContainer(subMonitor.split(50));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
createFile(newFile, contents, force, subMonitor.split(50));
|
||||||
createFile(newFile, contents, force, new SubProgressMonitor(monitor, createFileWork));
|
|
||||||
monitor.done();
|
|
||||||
|
|
||||||
return newFile;
|
return newFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createFile(IFile fileHandle, InputStream contents, boolean force, IProgressMonitor monitor)
|
private static void createFile(IFile fileHandle, InputStream contents, boolean force, IProgressMonitor monitor)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
|
SubMonitor subMonitor = SubMonitor.convert(monitor, 1);
|
||||||
if (contents == null)
|
if (contents == null)
|
||||||
contents = new ByteArrayInputStream(new byte[0]);
|
contents = new ByteArrayInputStream(new byte[0]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fileHandle.create(contents, force, monitor);
|
fileHandle.create(contents, force, subMonitor.split(1));
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
// If the file already existed locally, just refresh to get contents
|
// If the file already existed locally, just refresh to get contents
|
||||||
if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED)
|
if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED)
|
||||||
|
@ -164,8 +155,5 @@ public class NewSourceFileGenerator {
|
||||||
else
|
else
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (monitor.isCanceled())
|
|
||||||
throw new OperationCanceledException();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,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.
|
||||||
|
@ -38,16 +37,10 @@ public class CProjectWizard extends CDTCommonProjectWizard {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IProject continueCreation(IProject prj) {
|
protected IProject continueCreation(IProject prj) {
|
||||||
if (continueCreationMonitor == null) {
|
SubMonitor subMonitor = SubMonitor.convert(continueCreationMonitor, Messages.CProjectWizard_0, 1);
|
||||||
continueCreationMonitor = new NullProgressMonitor();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
continueCreationMonitor.beginTask(Messages.CProjectWizard_0, 1);
|
CProjectNature.addCNature(prj, subMonitor.split(1));
|
||||||
CProjectNature.addCNature(prj, new SubProgressMonitor(continueCreationMonitor, 1));
|
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
} finally {
|
|
||||||
continueCreationMonitor.done();
|
|
||||||
}
|
}
|
||||||
return prj;
|
return prj;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue