mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
Bug 558474 - CleanUp deprecated methods in org.eclipse.cdt.ui
Reworked deprecated usages of SubProgressMonitor by SubMonitor (Part 5 Latest) Change-Id: Ia7a06893c5acda374f2045666447ec494b8fccdc Signed-off-by: Sergey Kovalchuk <sergei.kovalchuk@arsysop.ru>
This commit is contained in:
parent
711cb3c4b9
commit
4ec47dbc35
7 changed files with 89 additions and 122 deletions
|
@ -26,7 +26,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
|||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.ProgressMonitorWrapper;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.jface.dialogs.ErrorDialog;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||
|
@ -144,14 +144,13 @@ public class ChangeExceptionHandler {
|
|||
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
|
||||
@Override
|
||||
public void run(IProgressMonitor monitor) throws CoreException {
|
||||
monitor.beginTask("", 11); //$NON-NLS-1$
|
||||
SubMonitor subMonitor = SubMonitor.convert(monitor, 11);
|
||||
try {
|
||||
undo.initializeValidationData(new NotCancelableProgressMonitor(new SubProgressMonitor(monitor, 1)));
|
||||
if (undo.isValid(new SubProgressMonitor(monitor, 1)).hasFatalError()) {
|
||||
monitor.done();
|
||||
undo.initializeValidationData(new NotCancelableProgressMonitor(subMonitor.split(1)));
|
||||
if (undo.isValid(subMonitor.split(1)).hasFatalError()) {
|
||||
return;
|
||||
}
|
||||
undo.perform(new SubProgressMonitor(monitor, 9));
|
||||
undo.perform(subMonitor.split(9));
|
||||
} finally {
|
||||
undo.dispose();
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ import org.eclipse.core.runtime.IAdaptable;
|
|||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.search.core.text.TextSearchEngine;
|
||||
import org.eclipse.search.core.text.TextSearchMatchAccess;
|
||||
import org.eclipse.search.core.text.TextSearchRequestor;
|
||||
|
@ -262,6 +262,7 @@ public class TextSearchWrapper {
|
|||
*/
|
||||
public IStatus searchWord(IFile[] filesToSearch, int scope, IFile scopeAnchor, String workingSet, String[] patterns,
|
||||
String word, IProgressMonitor monitor, final List<CRefactoringMatch> target) {
|
||||
SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
|
||||
int startPos = target.size();
|
||||
TextSearchEngine engine = TextSearchEngine.create();
|
||||
StringBuilder searchPattern = new StringBuilder(word.length() + 8);
|
||||
|
@ -285,14 +286,15 @@ public class TextSearchWrapper {
|
|||
return true;
|
||||
}
|
||||
};
|
||||
IStatus result = engine.search(searchscope, requestor, pattern, new SubProgressMonitor(monitor, 95));
|
||||
categorizeMatches(target.subList(startPos, target.size()), new SubProgressMonitor(monitor, 5));
|
||||
IStatus result = engine.search(searchscope, requestor, pattern, subMonitor.split(95));
|
||||
categorizeMatches(target.subList(startPos, target.size()), subMonitor.split(5));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void categorizeMatches(List<CRefactoringMatch> matches, IProgressMonitor monitor) {
|
||||
monitor.beginTask(RenameMessages.TextSearch_monitor_categorizeMatches, matches.size());
|
||||
SubMonitor subMonitor = SubMonitor.convert(monitor, RenameMessages.TextSearch_monitor_categorizeMatches,
|
||||
matches.size());
|
||||
IFile file = null;
|
||||
ArrayList<int[]> locations = null;
|
||||
for (Iterator<CRefactoringMatch> iter = matches.iterator(); iter.hasNext();) {
|
||||
|
@ -304,7 +306,7 @@ public class TextSearchWrapper {
|
|||
computeLocations(file, locations);
|
||||
}
|
||||
match.setLocation(findLocation(match, locations));
|
||||
monitor.worked(1);
|
||||
subMonitor.worked(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.eclipse.core.resources.IProject;
|
|||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.MultiStatus;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.jface.dialogs.ErrorDialog;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
|
@ -327,7 +327,7 @@ public class TeamProjectIndexExportWizardPage extends WizardPage implements List
|
|||
IRunnableWithProgress op = new IRunnableWithProgress() {
|
||||
@Override
|
||||
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
|
||||
monitor.beginTask("", projects.length); //$NON-NLS-1$
|
||||
SubMonitor subMonitor = SubMonitor.convert(monitor, projects.length);
|
||||
for (ICProject project : projects) {
|
||||
TeamPDOMExportOperation op = new TeamPDOMExportOperation(project);
|
||||
op.setTargetLocation(dest);
|
||||
|
@ -335,7 +335,7 @@ public class TeamProjectIndexExportWizardPage extends WizardPage implements List
|
|||
op.setOptions(TeamPDOMExportOperation.EXPORT_OPTION_RESOURCE_SNAPSHOT);
|
||||
}
|
||||
try {
|
||||
op.run(new SubProgressMonitor(monitor, 1));
|
||||
op.run(subMonitor.split(1));
|
||||
} catch (CoreException e) {
|
||||
status.merge(e.getStatus());
|
||||
}
|
||||
|
|
|
@ -51,9 +51,8 @@ import org.eclipse.core.runtime.IPath;
|
|||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.MultiStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.dialogs.ErrorDialog;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
|
@ -338,70 +337,57 @@ public class FormatAllAction extends SelectionDispatchAction {
|
|||
|
||||
private void doRunOnMultiple(ITranslationUnit[] tus, MultiStatus status, IProgressMonitor monitor)
|
||||
throws OperationCanceledException {
|
||||
if (monitor == null) {
|
||||
monitor = new NullProgressMonitor();
|
||||
}
|
||||
monitor.setTaskName(ActionMessages.FormatAllAction_operation_description);
|
||||
SubMonitor subMonitor = SubMonitor.convert(monitor, ActionMessages.FormatAllAction_operation_description,
|
||||
tus.length * 4);
|
||||
Map<String, Object> lastOptions = null;
|
||||
ICProject lastProject = null;
|
||||
|
||||
monitor.beginTask("", tus.length * 4); //$NON-NLS-1$
|
||||
try {
|
||||
Map<String, Object> lastOptions = null;
|
||||
ICProject lastProject = null;
|
||||
|
||||
for (int i = 0; i < tus.length; i++) {
|
||||
ITranslationUnit tu = tus[i];
|
||||
IPath path = tu.getPath();
|
||||
if (lastProject == null || lastOptions == null || !lastProject.equals(tu.getCProject())) {
|
||||
lastProject = tu.getCProject();
|
||||
lastOptions = getFomatterSettings(lastProject);
|
||||
}
|
||||
|
||||
ILanguage language = null;
|
||||
try {
|
||||
language = tu.getLanguage();
|
||||
} catch (CoreException exc) {
|
||||
// use fallback CPP
|
||||
language = GPPLanguage.getDefault();
|
||||
}
|
||||
|
||||
// use working copy if available
|
||||
ITranslationUnit wc = CDTUITools.getWorkingCopyManager().findSharedWorkingCopy(tu);
|
||||
if (wc != null) {
|
||||
tu = wc;
|
||||
}
|
||||
lastOptions.put(DefaultCodeFormatterConstants.FORMATTER_TRANSLATION_UNIT, tu);
|
||||
lastOptions.put(DefaultCodeFormatterConstants.FORMATTER_LANGUAGE, language);
|
||||
lastOptions.put(DefaultCodeFormatterConstants.FORMATTER_CURRENT_FILE, tu.getResource());
|
||||
|
||||
if (monitor.isCanceled()) {
|
||||
throw new OperationCanceledException();
|
||||
}
|
||||
|
||||
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
|
||||
try {
|
||||
try {
|
||||
manager.connect(path, LocationKind.IFILE, new SubProgressMonitor(monitor, 1));
|
||||
|
||||
monitor.subTask(path.makeRelative().toString());
|
||||
ITextFileBuffer fileBuffer = manager.getTextFileBuffer(path, LocationKind.IFILE);
|
||||
boolean wasDirty = fileBuffer.isDirty();
|
||||
|
||||
formatTranslationUnit(fileBuffer, lastOptions);
|
||||
|
||||
if (fileBuffer.isDirty() && !wasDirty) {
|
||||
fileBuffer.commit(new SubProgressMonitor(monitor, 2), false);
|
||||
} else {
|
||||
monitor.worked(2);
|
||||
}
|
||||
} finally {
|
||||
manager.disconnect(path, LocationKind.IFILE, new SubProgressMonitor(monitor, 1));
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
status.add(e.getStatus());
|
||||
}
|
||||
for (int i = 0; i < tus.length; i++) {
|
||||
ITranslationUnit tu = tus[i];
|
||||
IPath path = tu.getPath();
|
||||
if (lastProject == null || lastOptions == null || !lastProject.equals(tu.getCProject())) {
|
||||
lastProject = tu.getCProject();
|
||||
lastOptions = getFomatterSettings(lastProject);
|
||||
}
|
||||
|
||||
ILanguage language = null;
|
||||
try {
|
||||
language = tu.getLanguage();
|
||||
} catch (CoreException exc) {
|
||||
// use fallback CPP
|
||||
language = GPPLanguage.getDefault();
|
||||
}
|
||||
|
||||
// use working copy if available
|
||||
ITranslationUnit wc = CDTUITools.getWorkingCopyManager().findSharedWorkingCopy(tu);
|
||||
if (wc != null) {
|
||||
tu = wc;
|
||||
}
|
||||
lastOptions.put(DefaultCodeFormatterConstants.FORMATTER_TRANSLATION_UNIT, tu);
|
||||
lastOptions.put(DefaultCodeFormatterConstants.FORMATTER_LANGUAGE, language);
|
||||
lastOptions.put(DefaultCodeFormatterConstants.FORMATTER_CURRENT_FILE, tu.getResource());
|
||||
|
||||
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
|
||||
try {
|
||||
try {
|
||||
manager.connect(path, LocationKind.IFILE, subMonitor.split(1));
|
||||
subMonitor.subTask(path.makeRelative().toString());
|
||||
ITextFileBuffer fileBuffer = manager.getTextFileBuffer(path, LocationKind.IFILE);
|
||||
boolean wasDirty = fileBuffer.isDirty();
|
||||
|
||||
formatTranslationUnit(fileBuffer, lastOptions);
|
||||
|
||||
if (fileBuffer.isDirty() && !wasDirty) {
|
||||
fileBuffer.commit(subMonitor.split(2), false);
|
||||
} else {
|
||||
subMonitor.worked(2);
|
||||
}
|
||||
} finally {
|
||||
manager.disconnect(path, LocationKind.IFILE, subMonitor.split(1));
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
status.add(e.getStatus());
|
||||
}
|
||||
} finally {
|
||||
monitor.done();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,10 +39,9 @@ import org.eclipse.core.runtime.IConfigurationElement;
|
|||
import org.eclipse.core.runtime.IExtension;
|
||||
import org.eclipse.core.runtime.IExtensionPoint;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Preferences;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.jface.layout.PixelConverter;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
|
@ -225,10 +224,7 @@ public class BinaryParserBlock extends AbstractBinaryParserPage {
|
|||
|
||||
@Override
|
||||
public void performApply(IProgressMonitor monitor) throws CoreException {
|
||||
if (monitor == null) {
|
||||
monitor = new NullProgressMonitor();
|
||||
}
|
||||
monitor.beginTask(CUIMessages.BinaryParserBlock_settingBinaryParser, 2);
|
||||
SubMonitor subMonitor = SubMonitor.convert(monitor, CUIMessages.BinaryParserBlock_settingBinaryParser, 2);
|
||||
List<BinaryParserConfiguration> parsers = binaryList.getElements();
|
||||
final List<BinaryParserConfiguration> selected = new ArrayList<>(); // must do this to get proper order.
|
||||
for (int i = 0; i < parsers.size(); i++) {
|
||||
|
@ -241,13 +237,14 @@ public class BinaryParserBlock extends AbstractBinaryParserPage {
|
|||
|
||||
@Override
|
||||
public void execute(ICDescriptor descriptor, IProgressMonitor monitor) throws CoreException {
|
||||
SubMonitor subMonitor = SubMonitor.convert(monitor, 2);
|
||||
if (initialSelected == null || !selected.equals(initialSelected)) {
|
||||
descriptor.remove(CCorePlugin.BINARY_PARSER_UNIQ_ID);
|
||||
for (int i = 0; i < selected.size(); i++) {
|
||||
descriptor.create(CCorePlugin.BINARY_PARSER_UNIQ_ID, selected.get(i).getID());
|
||||
}
|
||||
}
|
||||
monitor.worked(1);
|
||||
subMonitor.worked(1);
|
||||
// Give a chance to the contributions to save.
|
||||
// We have to do it last to make sure the parser id
|
||||
// is save
|
||||
|
@ -255,13 +252,13 @@ public class BinaryParserBlock extends AbstractBinaryParserPage {
|
|||
for (int i = 0; i < selected.size(); i++) {
|
||||
ICOptionPage page = getBinaryParserPage(selected.get(i).getID());
|
||||
if (page != null && page.getControl() != null) {
|
||||
page.performApply(new SubProgressMonitor(monitor, 1));
|
||||
page.performApply(subMonitor.split(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
CCorePlugin.getDefault().getCDescriptorManager().runDescriptorOperation(getContainer().getProject(), op,
|
||||
monitor);
|
||||
subMonitor.split(2));
|
||||
} else {
|
||||
if (initialSelected == null || !selected.equals(initialSelected)) {
|
||||
Preferences store = getContainer().getPreferences();
|
||||
|
@ -269,17 +266,16 @@ public class BinaryParserBlock extends AbstractBinaryParserPage {
|
|||
store.setValue(CCorePlugin.PREF_BINARY_PARSER, arrayToString(selected.toArray()));
|
||||
}
|
||||
}
|
||||
monitor.worked(1);
|
||||
subMonitor.worked(1);
|
||||
// Give a chance to the contributions to save.
|
||||
for (int i = 0; i < selected.size(); i++) {
|
||||
ICOptionPage page = getBinaryParserPage(selected.get(i).getID());
|
||||
if (page != null && page.getControl() != null) {
|
||||
page.performApply(new SubProgressMonitor(monitor, 1));
|
||||
page.performApply(subMonitor.split(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
initialSelected = selected;
|
||||
monitor.done();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,8 +24,7 @@ import org.eclipse.core.resources.IWorkspace;
|
|||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.jface.viewers.CheckboxTableViewer;
|
||||
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
||||
import org.eclipse.swt.SWT;
|
||||
|
@ -168,18 +167,11 @@ public class ReferenceBlock extends AbstractCOptionPage {
|
|||
IProject[] refProjects = getReferencedProjects();
|
||||
if (refProjects != null) {
|
||||
IProject project = getContainer().getProject();
|
||||
if (monitor == null) {
|
||||
monitor = new NullProgressMonitor();
|
||||
}
|
||||
monitor.beginTask(CUIMessages.ReferenceBlock_task_ReferenceProjects, 1);
|
||||
try {
|
||||
IProjectDescription description = project.getDescription();
|
||||
description.setReferencedProjects(refProjects);
|
||||
project.setDescription(description, new SubProgressMonitor(monitor, 1));
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
SubMonitor subMonitor = SubMonitor.convert(monitor, CUIMessages.ReferenceBlock_task_ReferenceProjects, 1);
|
||||
IProjectDescription description = project.getDescription();
|
||||
description.setReferencedProjects(refProjects);
|
||||
project.setDescription(description, subMonitor.split(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,8 +22,7 @@ import org.eclipse.cdt.ui.CUIPlugin;
|
|||
import org.eclipse.cdt.utils.ui.controls.TabFolderLayout;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
|
@ -151,24 +150,17 @@ public abstract class TabFolderOptionBlock {
|
|||
public boolean performApply(IProgressMonitor monitor) {
|
||||
if (initializingTabs)
|
||||
return false;
|
||||
if (monitor == null) {
|
||||
monitor = new NullProgressMonitor();
|
||||
}
|
||||
monitor.beginTask("", pages.size()); //$NON-NLS-1$
|
||||
try {
|
||||
Iterator<ICOptionPage> iter = pages.iterator();
|
||||
while (iter.hasNext()) {
|
||||
ICOptionPage tab = iter.next();
|
||||
try {
|
||||
tab.performApply(new SubProgressMonitor(monitor, 1));
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.errorDialog(composite.getShell(), CUIMessages.TabFolderOptionBlock_error,
|
||||
CUIMessages.TabFolderOptionBlock_error_settingOptions, e, true);
|
||||
return false;
|
||||
}
|
||||
SubMonitor subMonitor = SubMonitor.convert(monitor, pages.size());
|
||||
Iterator<ICOptionPage> iter = pages.iterator();
|
||||
while (iter.hasNext()) {
|
||||
ICOptionPage tab = iter.next();
|
||||
try {
|
||||
tab.performApply(subMonitor.split(1));
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.errorDialog(composite.getShell(), CUIMessages.TabFolderOptionBlock_error,
|
||||
CUIMessages.TabFolderOptionBlock_error_settingOptions, e, true);
|
||||
return false;
|
||||
}
|
||||
} finally {
|
||||
monitor.done();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue