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

Code cleanup.

Change-Id: Id1f1d6c0c098d94a4275188a3b4f6443ddc4843d
This commit is contained in:
Sergey Prigogin 2016-05-25 17:21:20 -07:00 committed by Gerrit Code Review @ Eclipse.org
parent 290c8dfe23
commit 1bdfc29020
7 changed files with 217 additions and 285 deletions

View file

@ -62,7 +62,7 @@ public class NewClassCreationWizard extends NewElementWizard {
} }
@Override @Override
protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException { protected void finishPage(IProgressMonitor monitor) throws CoreException {
fPage.createClass(monitor); // use the full progress monitor fPage.createClass(monitor); // use the full progress monitor
} }

View file

@ -12,9 +12,6 @@ package org.eclipse.cdt.internal.ui.wizards;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import org.eclipse.cdt.internal.ui.actions.WorkbenchRunnableAdapter;
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.IWorkspaceRunnable;
@ -34,8 +31,12 @@ import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IDE; import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
public abstract class NewElementWizard extends Wizard implements INewWizard { import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.actions.WorkbenchRunnableAdapter;
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
public abstract class NewElementWizard extends Wizard implements INewWizard {
private IWorkbench fWorkbench; private IWorkbench fWorkbench;
private IStructuredSelection fSelection; private IStructuredSelection fSelection;
@ -65,11 +66,8 @@ public abstract class NewElementWizard extends Wizard implements INewWizard {
/** /**
* Subclasses should override to perform the actions of the wizard. * Subclasses should override to perform the actions of the wizard.
* This method is run in the wizard container's context as a workspace runnable. * This method is run in the wizard container's context as a workspace runnable.
* @param monitor
* @throws InterruptedException
* @throws CoreException
*/ */
protected abstract void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException; protected abstract void finishPage(IProgressMonitor monitor) throws CoreException;
/** /**
* Returns the scheduling rule for creating the element. * Returns the scheduling rule for creating the element.
@ -78,31 +76,22 @@ public abstract class NewElementWizard extends Wizard implements INewWizard {
return ResourcesPlugin.getWorkspace().getRoot(); // look all by default return ResourcesPlugin.getWorkspace().getRoot(); // look all by default
} }
protected boolean canRunForked() { protected boolean canRunForked() {
return true; return true;
} }
protected void handleFinishException(Shell shell, InvocationTargetException e) { protected void handleFinishException(Shell shell, InvocationTargetException e) {
String title= NewWizardMessages.NewElementWizard_op_error_title; String title= NewWizardMessages.NewElementWizard_op_error_title;
String message= NewWizardMessages.NewElementWizard_op_error_message; String message= NewWizardMessages.NewElementWizard_op_error_message;
ExceptionHandler.handle(e, shell, title, message); ExceptionHandler.handle(e, shell, title, message);
} }
/*
* @see Wizard#performFinish
*/
@Override @Override
public boolean performFinish() { public boolean performFinish() {
IWorkspaceRunnable op= new IWorkspaceRunnable() { IWorkspaceRunnable op= new IWorkspaceRunnable() {
@Override @Override
public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException { public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
try { finishPage(monitor);
finishPage(monitor);
} catch (InterruptedException e) {
throw new OperationCanceledException(e.getMessage());
}
} }
}; };
try { try {
@ -110,15 +99,12 @@ public abstract class NewElementWizard extends Wizard implements INewWizard {
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
handleFinishException(getShell(), e); handleFinishException(getShell(), e);
return false; return false;
} catch (InterruptedException e) { } catch (InterruptedException e) {
return false; return false;
} }
return true; return true;
} }
/* (non-Javadoc)
* @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
*/
@Override @Override
public void init(IWorkbench workbench, IStructuredSelection currentSelection) { public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
fWorkbench= workbench; fWorkbench= workbench;
@ -136,5 +122,4 @@ public abstract class NewElementWizard extends Wizard implements INewWizard {
protected void selectAndReveal(IResource newResource) { protected void selectAndReveal(IResource newResource) {
BasicNewResourceWizard.selectAndReveal(newResource, fWorkbench.getActiveWorkbenchWindow()); BasicNewResourceWizard.selectAndReveal(newResource, fWorkbench.getActiveWorkbenchWindow());
} }
} }

View file

@ -29,10 +29,9 @@ 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.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document; import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
@ -181,19 +180,13 @@ public class NewClassCodeGenerator {
/** /**
* Creates the new class. * Creates the new class.
* *
* @param monitor * @param monitor a progress monitor to report progress
* a progress monitor to report progress. * @throws CoreException if the creation failed
* @throws CoreException
* Thrown when the creation failed.
* @throws InterruptedException
* Thrown when the operation was cancelled.
*/ */
public ICElement createClass(IProgressMonitor monitor) public ICElement createClass(IProgressMonitor monitor) throws CoreException {
throws CodeGeneratorException, CoreException, InterruptedException { SubMonitor progress = SubMonitor.convert(monitor,
if (monitor == null) NewClassWizardMessages.NewClassCodeGeneration_createType_mainTask,
monitor = new NullProgressMonitor(); (fHeaderPath != null ? 3 : 0) + (fSourcePath != null ? 3 : 0)+ (fTestPath != null ? 3 : 0));
monitor.beginTask(NewClassWizardMessages.NewClassCodeGeneration_createType_mainTask, 400);
ITranslationUnit headerTU = null; ITranslationUnit headerTU = null;
ITranslationUnit sourceTU = null; ITranslationUnit sourceTU = null;
@ -205,26 +198,25 @@ public class NewClassCodeGenerator {
IWorkingCopy testWorkingCopy = null; IWorkingCopy testWorkingCopy = null;
try { try {
if (fHeaderPath != null) { if (fHeaderPath != null) {
// Get method stubs // Get method stubs.
List<IMethodStub> publicMethods = getStubs(ASTAccessVisibility.PUBLIC, false); List<IMethodStub> publicMethods = getStubs(ASTAccessVisibility.PUBLIC, false);
List<IMethodStub> protectedMethods = getStubs(ASTAccessVisibility.PROTECTED, false); List<IMethodStub> protectedMethods = getStubs(ASTAccessVisibility.PROTECTED, false);
List<IMethodStub> privateMethods = getStubs(ASTAccessVisibility.PRIVATE, false); List<IMethodStub> privateMethods = getStubs(ASTAccessVisibility.PRIVATE, false);
IFile headerFile = NewSourceFileGenerator.createHeaderFile(fHeaderPath, true, IFile headerFile =
new SubProgressMonitor(monitor, 50)); NewSourceFileGenerator.createHeaderFile(fHeaderPath, true, progress.split(1));
if (headerFile != null) { if (headerFile != null) {
headerTU = (ITranslationUnit) CoreModel.getDefault().create(headerFile); headerTU = (ITranslationUnit) CoreModel.getDefault().create(headerFile);
if (headerTU == null) { if (headerTU == null) {
throw new CodeGeneratorException("Failed to create " + headerFile); //$NON-NLS-1$ throw new CodeGeneratorException("Failed to create " + headerFile); //$NON-NLS-1$
} }
// Create a working copy with a new owner // Create a working copy with a new owner.
headerWorkingCopy = headerTU.getWorkingCopy(); headerWorkingCopy = headerTU.getWorkingCopy();
// headerWorkingCopy = headerTU.getSharedWorkingCopy(null, CUIPlugin.getDefault().getBufferFactory());
String headerContent = constructHeaderFileContent(headerTU, publicMethods, String headerContent = constructHeaderFileContent(headerTU, publicMethods,
protectedMethods, privateMethods, headerWorkingCopy.getBuffer().getContents(), protectedMethods, privateMethods, headerWorkingCopy.getBuffer().getContents(),
new SubProgressMonitor(monitor, 100)); progress.split(1));
if (headerContent != null) { if (headerContent != null) {
headerContent= formatSource(headerContent, headerTU); headerContent= formatSource(headerContent, headerTU);
} else { } else {
@ -232,13 +224,8 @@ public class NewClassCodeGenerator {
} }
headerWorkingCopy.getBuffer().setContents(headerContent); headerWorkingCopy.getBuffer().setContents(headerContent);
if (monitor.isCanceled()) {
throw new InterruptedException();
}
headerWorkingCopy.reconcile(); headerWorkingCopy.reconcile();
headerWorkingCopy.commit(true, monitor); headerWorkingCopy.commit(true, progress.split(1));
monitor.worked(50);
createdClass = headerWorkingCopy.getElement(fFullyQualifiedClassName); createdClass = headerWorkingCopy.getElement(fFullyQualifiedClassName);
} }
@ -247,30 +234,27 @@ public class NewClassCodeGenerator {
} }
if (fSourcePath != null) { if (fSourcePath != null) {
// Get method stubs // Get method stubs.
List<IMethodStub> publicMethods = getStubs(ASTAccessVisibility.PUBLIC, true); List<IMethodStub> publicMethods = getStubs(ASTAccessVisibility.PUBLIC, true);
List<IMethodStub> protectedMethods = getStubs(ASTAccessVisibility.PROTECTED, true); List<IMethodStub> protectedMethods = getStubs(ASTAccessVisibility.PROTECTED, true);
List<IMethodStub> privateMethods = getStubs(ASTAccessVisibility.PRIVATE, true); List<IMethodStub> privateMethods = getStubs(ASTAccessVisibility.PRIVATE, true);
if (!fForceSourceFileCreation && publicMethods.isEmpty() && if (fForceSourceFileCreation || !publicMethods.isEmpty() ||
protectedMethods.isEmpty() && privateMethods.isEmpty()) { !protectedMethods.isEmpty() || !privateMethods.isEmpty()) {
monitor.worked(100); IFile sourceFile =
} else { NewSourceFileGenerator.createSourceFile(fSourcePath, true, progress.split(1));
IFile sourceFile = NewSourceFileGenerator.createSourceFile(fSourcePath, true,
new SubProgressMonitor(monitor, 50));
if (sourceFile != null) { if (sourceFile != null) {
sourceTU = (ITranslationUnit) CoreModel.getDefault().create(sourceFile); sourceTU = (ITranslationUnit) CoreModel.getDefault().create(sourceFile);
if (sourceTU == null) { if (sourceTU == null) {
throw new CodeGeneratorException("Failed to create " + sourceFile); //$NON-NLS-1$ throw new CodeGeneratorException("Failed to create " + sourceFile); //$NON-NLS-1$
} }
monitor.worked(50);
// Create a working copy with a new owner // Create a working copy with a new owner.
sourceWorkingCopy = sourceTU.getWorkingCopy(); sourceWorkingCopy = sourceTU.getWorkingCopy();
String sourceContent = constructSourceFileContent(sourceTU, headerTU, String sourceContent = constructSourceFileContent(sourceTU, headerTU,
publicMethods, protectedMethods, privateMethods, publicMethods, protectedMethods, privateMethods,
sourceWorkingCopy.getBuffer().getContents(), new SubProgressMonitor(monitor, 100)); sourceWorkingCopy.getBuffer().getContents(), progress.split(1));
if (sourceContent != null) { if (sourceContent != null) {
sourceContent = formatSource(sourceContent, sourceTU); sourceContent = formatSource(sourceContent, sourceTU);
} else { } else {
@ -278,13 +262,8 @@ public class NewClassCodeGenerator {
} }
sourceWorkingCopy.getBuffer().setContents(sourceContent); sourceWorkingCopy.getBuffer().setContents(sourceContent);
if (monitor.isCanceled()) {
throw new InterruptedException();
}
sourceWorkingCopy.reconcile(); sourceWorkingCopy.reconcile();
sourceWorkingCopy.commit(true, monitor); sourceWorkingCopy.commit(true, progress.split(1));
monitor.worked(50);
} }
fCreatedSourceTU = sourceTU; fCreatedSourceTU = sourceTU;
@ -292,30 +271,23 @@ public class NewClassCodeGenerator {
} }
if (fTestPath != null) { if (fTestPath != null) {
IFile testFile = NewSourceFileGenerator.createTestFile(fTestPath, true, IFile testFile = NewSourceFileGenerator.createTestFile(fTestPath, true, progress.split(1));
new SubProgressMonitor(monitor, 50));
if (testFile != null) { if (testFile != null) {
testTU = (ITranslationUnit) CoreModel.getDefault().create(testFile); testTU = (ITranslationUnit) CoreModel.getDefault().create(testFile);
if (testTU == null) { if (testTU == null) {
throw new CodeGeneratorException("Failed to create " + testFile); //$NON-NLS-1$ throw new CodeGeneratorException("Failed to create " + testFile); //$NON-NLS-1$
} }
monitor.worked(50);
// Create a working copy with a new owner // Create a working copy with a new owner
testWorkingCopy = testTU.getWorkingCopy(); testWorkingCopy = testTU.getWorkingCopy();
String testContent = constructTestFileContent(testTU, headerTU, String testContent = constructTestFileContent(testTU, headerTU,
testWorkingCopy.getBuffer().getContents(), new SubProgressMonitor(monitor, 100)); testWorkingCopy.getBuffer().getContents(), progress.split(1));
testContent= formatSource(testContent, testTU); testContent= formatSource(testContent, testTU);
testWorkingCopy.getBuffer().setContents(testContent); testWorkingCopy.getBuffer().setContents(testContent);
if (monitor.isCanceled()) {
throw new InterruptedException();
}
testWorkingCopy.reconcile(); testWorkingCopy.reconcile();
testWorkingCopy.commit(true, monitor); testWorkingCopy.commit(true, progress.split(1));
monitor.worked(50);
} }
fCreatedTestTU = testTU; fCreatedTestTU = testTU;
@ -332,7 +304,6 @@ public class NewClassCodeGenerator {
if (testWorkingCopy != null) { if (testWorkingCopy != null) {
testWorkingCopy.destroy(); testWorkingCopy.destroy();
} }
monitor.done();
} }
return fCreatedClass; return fCreatedClass;
@ -382,7 +353,8 @@ public class NewClassCodeGenerator {
public String constructHeaderFileContent(ITranslationUnit headerTU, List<IMethodStub> publicMethods, public String constructHeaderFileContent(ITranslationUnit headerTU, List<IMethodStub> publicMethods,
List<IMethodStub> protectedMethods, List<IMethodStub> privateMethods, String oldContents, List<IMethodStub> protectedMethods, List<IMethodStub> privateMethods, String oldContents,
IProgressMonitor monitor) throws CoreException { IProgressMonitor monitor) throws CoreException {
monitor.beginTask(NewClassWizardMessages.NewClassCodeGeneration_createType_task_header, 100); SubMonitor progress = SubMonitor.convert(monitor,
NewClassWizardMessages.NewClassCodeGeneration_createType_task_header, 1);
String lineDelimiter= StubUtility.getLineDelimiterUsed(headerTU); String lineDelimiter= StubUtility.getLineDelimiterUsed(headerTU);
@ -394,13 +366,12 @@ public class NewClassCodeGenerator {
privateMethods, lineDelimiter); privateMethods, lineDelimiter);
String includes = null; String includes = null;
if (fBaseClasses != null && fBaseClasses.length > 0) { if (fBaseClasses != null && fBaseClasses.length != 0) {
includes = constructBaseClassIncludes(headerTU, lineDelimiter, includes = constructBaseClassIncludes(headerTU, lineDelimiter, progress.split(1));
new SubProgressMonitor(monitor, 50));
} }
if (oldContents != null) { if (oldContents != null) {
if (oldContents.length() == 0) { if (oldContents.isEmpty()) {
oldContents = null; oldContents = null;
} else if (!oldContents.endsWith(lineDelimiter)) { } else if (!oldContents.endsWith(lineDelimiter)) {
oldContents += lineDelimiter; oldContents += lineDelimiter;
@ -466,8 +437,6 @@ public class NewClassCodeGenerator {
namespaceEnd, namespaceName, classComment, classDefinition, fClassName, namespaceEnd, namespaceName, classComment, classDefinition, fClassName,
lineDelimiter); lineDelimiter);
} }
monitor.done();
return fileContent; return fileContent;
} }
@ -710,7 +679,8 @@ public class NewClassCodeGenerator {
private String constructBaseClassIncludes(ITranslationUnit headerTU, String lineDelimiter, private String constructBaseClassIncludes(ITranslationUnit headerTU, String lineDelimiter,
IProgressMonitor monitor) throws CodeGeneratorException { IProgressMonitor monitor) throws CodeGeneratorException {
monitor.beginTask(NewClassWizardMessages.NewClassCodeGeneration_createType_task_header_includePaths, 100); SubMonitor progress = SubMonitor.convert(monitor,
NewClassWizardMessages.NewClassCodeGeneration_createType_task_header_includePaths, 1);
ICProject cProject = headerTU.getCProject(); ICProject cProject = headerTU.getCProject();
IProject project = cProject.getProject(); IProject project = cProject.getProject();
@ -723,7 +693,7 @@ public class NewClassCodeGenerator {
if (createIncludePaths()) { if (createIncludePaths()) {
List<IPath> newIncludePaths = getMissingIncludePaths(projectLocation, includePaths, baseClassPaths); List<IPath> newIncludePaths = getMissingIncludePaths(projectLocation, includePaths, baseClassPaths);
if (!newIncludePaths.isEmpty()) { if (!newIncludePaths.isEmpty()) {
addIncludePaths(cProject, newIncludePaths, monitor); addIncludePaths(cProject, newIncludePaths, progress.split(1));
} }
} }
@ -749,8 +719,6 @@ public class NewClassCodeGenerator {
text.append(lineDelimiter); text.append(lineDelimiter);
previousStyle = style; previousStyle = style;
} }
monitor.done();
return text.toString(); return text.toString();
} }
@ -772,8 +740,10 @@ public class NewClassCodeGenerator {
return NewClassWizardPrefs.createIncludePaths(); return NewClassWizardPrefs.createIncludePaths();
} }
private void addIncludePaths(ICProject cProject, List<IPath> newIncludePaths, IProgressMonitor monitor) throws CodeGeneratorException { private void addIncludePaths(ICProject cProject, List<IPath> newIncludePaths, IProgressMonitor monitor)
monitor.beginTask(NewClassWizardMessages.NewClassCodeGeneration_createType_task_header_addIncludePaths, 100); throws CodeGeneratorException {
SubMonitor progress = SubMonitor.convert(monitor,
NewClassWizardMessages.NewClassCodeGeneration_createType_task_header_addIncludePaths, 1);
//TODO prefs option whether to add to project or parent source folder? //TODO prefs option whether to add to project or parent source folder?
IPath addToResourcePath = cProject.getPath(); IPath addToResourcePath = cProject.getPath();
@ -802,18 +772,19 @@ public class NewClassCodeGenerator {
if (includeProject != null) { if (includeProject != null) {
// Make sure that the include is made the same way that build properties for // Make sure that the include is made the same way that build properties for
// projects makes them, so .contains below is a valid check // projects makes them, so .contains below is a valid check
IIncludeEntry entry = CoreModel.newIncludeEntry(addToResourcePath, null, new Path(includeProject.getProject().getLocationURI().getPath()), true); IIncludeEntry entry = CoreModel.newIncludeEntry(addToResourcePath, null,
new Path(includeProject.getProject().getLocationURI().getPath()), true);
if (!checkEntryList.contains(entry)) // if the path already exists in the #includes then don't add it // If the path already exists in the #includes then don't add it.
if (!checkEntryList.contains(entry))
pathEntryList.add(entry); pathEntryList.add(entry);
} }
} }
pathEntries = pathEntryList.toArray(new IPathEntry[pathEntryList.size()]); pathEntries = pathEntryList.toArray(new IPathEntry[pathEntryList.size()]);
cProject.setRawPathEntries(pathEntries, new SubProgressMonitor(monitor, 80)); cProject.setRawPathEntries(pathEntries, progress.split(1));
} catch (CModelException e) { } catch (CModelException e) {
throw new CodeGeneratorException(e); throw new CodeGeneratorException(e);
} }
monitor.done();
} }
private ICProject toCProject(IProject enclosingProject) { private ICProject toCProject(IProject enclosingProject) {
@ -925,12 +896,13 @@ public class NewClassCodeGenerator {
public String constructSourceFileContent(ITranslationUnit sourceTU, ITranslationUnit headerTU, public String constructSourceFileContent(ITranslationUnit sourceTU, ITranslationUnit headerTU,
List<IMethodStub> publicMethods, List<IMethodStub> protectedMethods, List<IMethodStub> publicMethods, List<IMethodStub> protectedMethods,
List<IMethodStub> privateMethods, String oldContents, IProgressMonitor monitor) throws CoreException { List<IMethodStub> privateMethods, String oldContents, IProgressMonitor monitor) throws CoreException {
monitor.beginTask(NewClassWizardMessages.NewClassCodeGeneration_createType_task_source, 150); SubMonitor progress = SubMonitor.convert(monitor,
NewClassWizardMessages.NewClassCodeGeneration_createType_task_source, 2);
String lineDelimiter= StubUtility.getLineDelimiterUsed(sourceTU); String lineDelimiter= StubUtility.getLineDelimiterUsed(sourceTU);
String includeString = null; String includeString = null;
if (headerTU != null) { if (headerTU != null) {
includeString = getHeaderIncludeString(sourceTU, headerTU, new SubProgressMonitor(monitor, 50)); includeString = getHeaderIncludeString(sourceTU, headerTU, progress.split(1));
if (includeString != null) { if (includeString != null) {
// Check if file already has the include. // Check if file already has the include.
if (oldContents != null && hasInclude(oldContents, includeString)) { if (oldContents != null && hasInclude(oldContents, includeString)) {
@ -944,7 +916,7 @@ public class NewClassCodeGenerator {
if (!publicMethods.isEmpty() || !protectedMethods.isEmpty() || !privateMethods.isEmpty()) { if (!publicMethods.isEmpty() || !protectedMethods.isEmpty() || !privateMethods.isEmpty()) {
// TODO sort methods (e.g. constructor always first?) // TODO sort methods (e.g. constructor always first?)
methodBodies = constructMethodBodies(sourceTU, publicMethods, protectedMethods, methodBodies = constructMethodBodies(sourceTU, publicMethods, protectedMethods,
privateMethods, lineDelimiter, new SubProgressMonitor(monitor, 50)); privateMethods, lineDelimiter, progress.split(1));
} }
String namespaceBegin = fNamespace == null ? String namespaceBegin = fNamespace == null ?
@ -1007,19 +979,19 @@ public class NewClassCodeGenerator {
fileContent= CodeGeneration.getBodyFileContent(sourceTU, includeString, namespaceBegin, fileContent= CodeGeneration.getBodyFileContent(sourceTU, includeString, namespaceBegin,
namespaceEnd, namespaceName, null, methodBodies, fClassName, lineDelimiter); namespaceEnd, namespaceName, null, methodBodies, fClassName, lineDelimiter);
} }
monitor.done();
return fileContent; return fileContent;
} }
public String constructTestFileContent(ITranslationUnit testTU, ITranslationUnit headerTU, public String constructTestFileContent(ITranslationUnit testTU, ITranslationUnit headerTU,
String oldContents, IProgressMonitor monitor) throws CoreException { String oldContents, IProgressMonitor monitor) throws CoreException {
monitor.beginTask(NewClassWizardMessages.NewClassCodeGeneration_createType_task_source, 150); SubMonitor progress = SubMonitor.convert(monitor,
NewClassWizardMessages.NewClassCodeGeneration_createType_task_source, 1);
String lineDelimiter= StubUtility.getLineDelimiterUsed(testTU); String lineDelimiter= StubUtility.getLineDelimiterUsed(testTU);
String includeString = null; String includeString = null;
if (headerTU != null) { if (headerTU != null) {
includeString = getHeaderIncludeString(testTU, headerTU, new SubProgressMonitor(monitor, 50)); includeString = getHeaderIncludeString(testTU, headerTU, progress.split(1));
if (includeString != null) { if (includeString != null) {
// Check if file already has the include. // Check if file already has the include.
if (oldContents != null && hasInclude(oldContents, includeString)) { if (oldContents != null && hasInclude(oldContents, includeString)) {
@ -1071,7 +1043,6 @@ public class NewClassCodeGenerator {
fileContent= CodeGeneration.getTestFileContent(testTU, includeString, namespaceBegin, fileContent= CodeGeneration.getTestFileContent(testTU, includeString, namespaceBegin,
namespaceEnd, namespaceName, null, fClassName, lineDelimiter); namespaceEnd, namespaceName, null, fClassName, lineDelimiter);
} }
monitor.done();
return fileContent; return fileContent;
} }

View file

@ -11,18 +11,19 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.wizards.filewizard; package org.eclipse.cdt.internal.ui.wizards.filewizard;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.wizards.NewElementWizard;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.wizards.NewElementWizard;
public abstract class AbstractFileCreationWizard extends NewElementWizard { public abstract class AbstractFileCreationWizard extends NewElementWizard {
protected AbstractFileCreationWizardPage fPage;
protected AbstractFileCreationWizardPage fPage = null;
public AbstractFileCreationWizard() { public AbstractFileCreationWizard() {
super(); super();
@ -31,35 +32,20 @@ public abstract class AbstractFileCreationWizard extends NewElementWizard {
setWindowTitle(NewFileWizardMessages.AbstractFileCreationWizard_title); setWindowTitle(NewFileWizardMessages.AbstractFileCreationWizard_title);
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.ui.wizards.NewElementWizard#canRunForked()
*/
@Override @Override
protected boolean canRunForked() { protected boolean canRunForked() {
return true; return true;
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.ui.wizards.NewElementWizard#finishPage(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override @Override
protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException { protected void finishPage(IProgressMonitor monitor) throws CoreException {
fPage.createFile(monitor); // use the full progress monitor fPage.createFile(monitor); // Use the full progress monitor.
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.wizard.IWizard#performFinish()
*/
@Override @Override
public boolean performFinish() { public boolean performFinish() {
boolean res = super.performFinish(); boolean result = super.performFinish();
if (res) { if (result) {
//TODO need prefs option for opening editor //TODO need prefs option for opening editor
boolean openInEditor = true; boolean openInEditor = true;
@ -72,6 +58,6 @@ public abstract class AbstractFileCreationWizard extends NewElementWizard {
} }
} }
} }
return res; return result;
} }
} }

View file

@ -23,9 +23,8 @@ 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.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
@ -79,78 +78,78 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage {
private StringButtonDialogField fProjectField; private StringButtonDialogField fProjectField;
private StatusInfo fProjectStatus; private StatusInfo fProjectStatus;
private StringButtonDialogField fRootDialogField; private StringButtonDialogField fRootDialogField;
private StatusInfo fRootStatus; private StatusInfo fRootStatus;
private SelectionButtonDialogField fExcludeInOthersFields; private SelectionButtonDialogField fExcludeInOthersFields;
private IWorkspaceRoot fWorkspaceRoot; private IWorkspaceRoot fWorkspaceRoot;
private ICProject fCurrCProject; private ICProject fCurrCProject;
private IPathEntry[] fEntries; private IPathEntry[] fEntries;
private IPathEntry[] fNewEntries; private IPathEntry[] fNewEntries;
private boolean fIsProjectAsSourceFolder; private boolean fIsProjectAsSourceFolder;
private ISourceRoot fCreatedRoot; private ISourceRoot fCreatedRoot;
public NewSourceFolderWizardPage() { public NewSourceFolderWizardPage() {
super(PAGE_NAME); super(PAGE_NAME);
setTitle(NewFolderWizardMessages.NewSourceFolderWizardPage_title); setTitle(NewFolderWizardMessages.NewSourceFolderWizardPage_title);
setDescription(NewFolderWizardMessages.NewSourceFolderWizardPage_description); setDescription(NewFolderWizardMessages.NewSourceFolderWizardPage_description);
fWorkspaceRoot= ResourcesPlugin.getWorkspace().getRoot(); fWorkspaceRoot= ResourcesPlugin.getWorkspace().getRoot();
RootFieldAdapter adapter= new RootFieldAdapter(); RootFieldAdapter adapter= new RootFieldAdapter();
fProjectField= new StringButtonDialogField(adapter); fProjectField= new StringButtonDialogField(adapter);
fProjectField.setDialogFieldListener(adapter); fProjectField.setDialogFieldListener(adapter);
fProjectField.setLabelText(NewFolderWizardMessages.NewSourceFolderWizardPage_project_label); fProjectField.setLabelText(NewFolderWizardMessages.NewSourceFolderWizardPage_project_label);
fProjectField.setButtonLabel(NewFolderWizardMessages.NewSourceFolderWizardPage_project_button); fProjectField.setButtonLabel(NewFolderWizardMessages.NewSourceFolderWizardPage_project_button);
fRootDialogField= new StringButtonDialogField(adapter); fRootDialogField= new StringButtonDialogField(adapter);
fRootDialogField.setDialogFieldListener(adapter); fRootDialogField.setDialogFieldListener(adapter);
fRootDialogField.setLabelText(NewFolderWizardMessages.NewSourceFolderWizardPage_root_label); fRootDialogField.setLabelText(NewFolderWizardMessages.NewSourceFolderWizardPage_root_label);
fRootDialogField.setButtonLabel(NewFolderWizardMessages.NewSourceFolderWizardPage_root_button); fRootDialogField.setButtonLabel(NewFolderWizardMessages.NewSourceFolderWizardPage_root_button);
fExcludeInOthersFields= new SelectionButtonDialogField(SWT.CHECK); fExcludeInOthersFields= new SelectionButtonDialogField(SWT.CHECK);
fExcludeInOthersFields.setDialogFieldListener(adapter); fExcludeInOthersFields.setDialogFieldListener(adapter);
fExcludeInOthersFields.setLabelText(NewFolderWizardMessages.NewSourceFolderWizardPage_exclude_label); fExcludeInOthersFields.setLabelText(NewFolderWizardMessages.NewSourceFolderWizardPage_exclude_label);
fRootStatus= new StatusInfo(); fRootStatus= new StatusInfo();
fProjectStatus= new StatusInfo(); fProjectStatus= new StatusInfo();
} }
// -------- Initialization --------- // -------- Initialization ---------
public void init(IStructuredSelection selection) { public void init(IStructuredSelection selection) {
if (selection == null || selection.isEmpty()) { if (selection == null || selection.isEmpty()) {
setDefaultAttributes(); setDefaultAttributes();
return; return;
} }
Object selectedElement= selection.getFirstElement(); Object selectedElement= selection.getFirstElement();
if (selectedElement == null) { if (selectedElement == null) {
selectedElement= EditorUtility.getActiveEditorCInput(); selectedElement= EditorUtility.getActiveEditorCInput();
} }
String projPath= null; String projPath= null;
if (selectedElement instanceof IResource) { if (selectedElement instanceof IResource) {
IProject proj= ((IResource) selectedElement).getProject(); IProject proj= ((IResource) selectedElement).getProject();
if (proj != null) { if (proj != null) {
projPath= proj.getFullPath().makeRelative().toString(); projPath= proj.getFullPath().makeRelative().toString();
} }
} else if (selectedElement instanceof ICElement) { } else if (selectedElement instanceof ICElement) {
ICProject jproject= ((ICElement) selectedElement).getCProject(); ICProject jproject= ((ICElement) selectedElement).getCProject();
if (jproject != null) { if (jproject != null) {
projPath= jproject.getProject().getFullPath().makeRelative().toString(); projPath= jproject.getProject().getFullPath().makeRelative().toString();
} }
} }
if (projPath != null) { if (projPath != null) {
fProjectField.setText(projPath); fProjectField.setText(projPath);
fRootDialogField.setText(""); //$NON-NLS-1$ fRootDialogField.setText(""); //$NON-NLS-1$
@ -158,10 +157,10 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage {
setDefaultAttributes(); setDefaultAttributes();
} }
} }
private void setDefaultAttributes() { private void setDefaultAttributes() {
String projPath= ""; //$NON-NLS-1$ String projPath= ""; //$NON-NLS-1$
try { try {
// find the first C project // find the first C project
IProject[] projects= fWorkspaceRoot.getProjects(); IProject[] projects= fWorkspaceRoot.getProjects();
@ -170,7 +169,7 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage {
projPath= proj.getFullPath().makeRelative().toString(); projPath= proj.getFullPath().makeRelative().toString();
break; break;
} }
} }
} catch (CoreException e) { } catch (CoreException e) {
// ignore here // ignore here
} }
@ -180,60 +179,51 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage {
// -------- UI Creation --------- // -------- UI Creation ---------
/*
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
@Override @Override
public void createControl(Composite parent) { public void createControl(Composite parent) {
initializeDialogUnits(parent); initializeDialogUnits(parent);
Composite composite= new Composite(parent, SWT.NONE); Composite composite= new Composite(parent, SWT.NONE);
GridLayout layout= new GridLayout(); GridLayout layout= new GridLayout();
layout.marginWidth= 0; layout.marginWidth= 0;
layout.marginHeight= 0; layout.marginHeight= 0;
layout.numColumns= 3; layout.numColumns= 3;
composite.setLayout(layout); composite.setLayout(layout);
fProjectField.doFillIntoGrid(composite, 3); fProjectField.doFillIntoGrid(composite, 3);
fRootDialogField.doFillIntoGrid(composite, 3); fRootDialogField.doFillIntoGrid(composite, 3);
fExcludeInOthersFields.doFillIntoGrid(composite, 3); fExcludeInOthersFields.doFillIntoGrid(composite, 3);
int maxFieldWidth= convertWidthInCharsToPixels(40); int maxFieldWidth= convertWidthInCharsToPixels(40);
LayoutUtil.setWidthHint(fProjectField.getTextControl(null), maxFieldWidth); LayoutUtil.setWidthHint(fProjectField.getTextControl(null), maxFieldWidth);
LayoutUtil.setHorizontalGrabbing(fProjectField.getTextControl(null), true); LayoutUtil.setHorizontalGrabbing(fProjectField.getTextControl(null), true);
LayoutUtil.setWidthHint(fRootDialogField.getTextControl(null), maxFieldWidth); LayoutUtil.setWidthHint(fRootDialogField.getTextControl(null), maxFieldWidth);
// Bug #220003 : consistency between New Source Folder dialog and Source Location Property tab. // Bug #220003 : consistency between New Source Folder dialog and Source Location Property tab.
fExcludeInOthersFields.setSelection(true); fExcludeInOthersFields.setSelection(true);
setControl(composite); setControl(composite);
Dialog.applyDialogFont(composite); Dialog.applyDialogFont(composite);
PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, ICHelpContextIds.NEW_SRCFLDER_WIZARD_PAGE); PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, ICHelpContextIds.NEW_SRCFLDER_WIZARD_PAGE);
} }
/*
* @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
*/
@Override @Override
public void setVisible(boolean visible) { public void setVisible(boolean visible) {
super.setVisible(visible); super.setVisible(visible);
if (visible) { if (visible) {
fRootDialogField.setFocus(); fRootDialogField.setFocus();
} }
} }
// -------- ContainerFieldAdapter -------- // -------- ContainerFieldAdapter --------
private class RootFieldAdapter implements IStringButtonAdapter, IDialogFieldListener { private class RootFieldAdapter implements IStringButtonAdapter, IDialogFieldListener {
// -------- IStringButtonAdapter
@Override @Override
public void changeControlPressed(DialogField field) { public void changeControlPressed(DialogField field) {
packRootChangeControlPressed(field); packRootChangeControlPressed(field);
} }
// -------- IDialogFieldListener
@Override @Override
public void dialogFieldChanged(DialogField field) { public void dialogFieldChanged(DialogField field) {
packRootDialogFieldChanged(field); packRootDialogFieldChanged(field);
@ -243,8 +233,8 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage {
protected void packRootChangeControlPressed(DialogField field) { protected void packRootChangeControlPressed(DialogField field) {
if (field == fRootDialogField) { if (field == fRootDialogField) {
IPath initialPath= new Path(fRootDialogField.getText()); IPath initialPath= new Path(fRootDialogField.getText());
String title= NewFolderWizardMessages.NewSourceFolderWizardPage_ChooseExistingRootDialog_title; String title= NewFolderWizardMessages.NewSourceFolderWizardPage_ChooseExistingRootDialog_title;
String message= NewFolderWizardMessages.NewSourceFolderWizardPage_ChooseExistingRootDialog_description; String message= NewFolderWizardMessages.NewSourceFolderWizardPage_ChooseExistingRootDialog_description;
IFolder folder= chooseFolder(title, message, initialPath); IFolder folder= chooseFolder(title, message, initialPath);
if (folder != null) { if (folder != null) {
IPath path= folder.getFullPath().removeFirstSegments(1); IPath path= folder.getFullPath().removeFirstSegments(1);
@ -256,9 +246,9 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage {
IPath path= jproject.getProject().getFullPath().makeRelative(); IPath path= jproject.getProject().getFullPath().makeRelative();
fProjectField.setText(path.toString()); fProjectField.setText(path.toString());
} }
} }
} }
protected void packRootDialogFieldChanged(DialogField field) { protected void packRootDialogFieldChanged(DialogField field) {
if (field == fRootDialogField) { if (field == fRootDialogField) {
updateRootStatus(); updateRootStatus();
@ -274,20 +264,20 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage {
private void updateProjectStatus() { private void updateProjectStatus() {
fCurrCProject= null; fCurrCProject= null;
fIsProjectAsSourceFolder= false; fIsProjectAsSourceFolder= false;
String str= fProjectField.getText(); String str= fProjectField.getText();
if (str.length() == 0) { if (str.isEmpty()) {
fProjectStatus.setError(NewFolderWizardMessages.NewSourceFolderWizardPage_error_EnterProjectName); fProjectStatus.setError(NewFolderWizardMessages.NewSourceFolderWizardPage_error_EnterProjectName);
return; return;
} }
IPath path= new Path(str); IPath path= new Path(str);
if (path.segmentCount() != 1) { if (path.segmentCount() != 1) {
fProjectStatus.setError(NewFolderWizardMessages.NewSourceFolderWizardPage_error_InvalidProjectPath); fProjectStatus.setError(NewFolderWizardMessages.NewSourceFolderWizardPage_error_InvalidProjectPath);
return; return;
} }
IProject project= fWorkspaceRoot.getProject(path.toString()); IProject project= fWorkspaceRoot.getProject(path.toString());
if (!project.exists()) { if (!project.exists()) {
fProjectStatus.setError(NewFolderWizardMessages.NewSourceFolderWizardPage_error_ProjectNotExists); fProjectStatus.setError(NewFolderWizardMessages.NewSourceFolderWizardPage_error_ProjectNotExists);
return; return;
} }
try { try {
@ -300,8 +290,8 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage {
} catch (CoreException e) { } catch (CoreException e) {
CUIPlugin.log(e); CUIPlugin.log(e);
fCurrCProject= null; fCurrCProject= null;
} }
fProjectStatus.setError(NewFolderWizardMessages.NewSourceFolderWizardPage_error_NotACProject); fProjectStatus.setError(NewFolderWizardMessages.NewSourceFolderWizardPage_error_NotACProject);
} }
private void updateRootStatus() { private void updateRootStatus() {
@ -311,44 +301,44 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage {
return; return;
} }
fRootStatus.setOK(); fRootStatus.setOK();
IPath projPath= fCurrCProject.getProject().getFullPath(); IPath projPath= fCurrCProject.getProject().getFullPath();
String str= fRootDialogField.getText(); String str= fRootDialogField.getText();
if (str.length() == 0) { if (str.length() == 0) {
fRootStatus.setError(NLS.bind(NewFolderWizardMessages.NewSourceFolderWizardPage_error_EnterRootName, fCurrCProject.getProject().getFullPath().toString())); fRootStatus.setError(NLS.bind(NewFolderWizardMessages.NewSourceFolderWizardPage_error_EnterRootName, fCurrCProject.getProject().getFullPath().toString()));
} else { } else {
IPath path= projPath.append(str); IPath path= projPath.append(str);
IStatus validate= fWorkspaceRoot.getWorkspace().validatePath(path.toString(), IResource.FOLDER); IStatus validate= fWorkspaceRoot.getWorkspace().validatePath(path.toString(), IResource.FOLDER);
if (validate.matches(IStatus.ERROR)) { if (validate.matches(IStatus.ERROR)) {
fRootStatus.setError(NLS.bind(NewFolderWizardMessages.NewSourceFolderWizardPage_error_InvalidRootName, validate.getMessage())); fRootStatus.setError(NLS.bind(NewFolderWizardMessages.NewSourceFolderWizardPage_error_InvalidRootName, validate.getMessage()));
} else { } else {
IResource res= fWorkspaceRoot.findMember(path); IResource res= fWorkspaceRoot.findMember(path);
if (res != null) { if (res != null) {
if (res.getType() != IResource.FOLDER) { if (res.getType() != IResource.FOLDER) {
fRootStatus.setError(NewFolderWizardMessages.NewSourceFolderWizardPage_error_NotAFolder); fRootStatus.setError(NewFolderWizardMessages.NewSourceFolderWizardPage_error_NotAFolder);
return; return;
} }
} }
ArrayList<IPathEntry> newEntries= new ArrayList<>(fEntries.length + 1); ArrayList<IPathEntry> newEntries= new ArrayList<>(fEntries.length + 1);
int projectEntryIndex= -1; int projectEntryIndex= -1;
for (int i= 0; i < fEntries.length; i++) { for (int i= 0; i < fEntries.length; i++) {
IPathEntry curr= fEntries[i]; IPathEntry curr= fEntries[i];
if (curr.getEntryKind() == IPathEntry.CDT_SOURCE) { if (curr.getEntryKind() == IPathEntry.CDT_SOURCE) {
if (path.equals(curr.getPath())) { if (path.equals(curr.getPath())) {
fRootStatus.setError(NewFolderWizardMessages.NewSourceFolderWizardPage_error_AlreadyExisting); fRootStatus.setError(NewFolderWizardMessages.NewSourceFolderWizardPage_error_AlreadyExisting);
return; return;
} }
if (projPath.equals(curr.getPath())) { if (projPath.equals(curr.getPath())) {
projectEntryIndex= i; projectEntryIndex= i;
} }
} }
newEntries.add(curr); newEntries.add(curr);
} }
IPathEntry newEntry= CoreModel.newSourceEntry(path); IPathEntry newEntry= CoreModel.newSourceEntry(path);
Set<IPathEntry> modified= new HashSet<>(); Set<IPathEntry> modified= new HashSet<>();
if (fExcludeInOthersFields.isSelected()) { if (fExcludeInOthersFields.isSelected()) {
InternalCoreModelUtil.addExclusionPatterns(newEntry, newEntries, modified); InternalCoreModelUtil.addExclusionPatterns(newEntry, newEntries, modified);
newEntries.add(CoreModel.newSourceEntry(path)); newEntries.add(CoreModel.newSourceEntry(path));
@ -360,7 +350,7 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage {
newEntries.add(CoreModel.newSourceEntry(path)); newEntries.add(CoreModel.newSourceEntry(path));
} }
} }
fNewEntries= newEntries.toArray(new IPathEntry[newEntries.size()]); fNewEntries= newEntries.toArray(new IPathEntry[newEntries.size()]);
ICModelStatus status= PathEntryManager.getDefault().validatePathEntry(fCurrCProject, fNewEntries); ICModelStatus status= PathEntryManager.getDefault().validatePathEntry(fCurrCProject, fNewEntries);
@ -372,64 +362,54 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage {
fRootStatus.setError(status.getMessage()); fRootStatus.setError(status.getMessage());
return; return;
} else if (fIsProjectAsSourceFolder) { } else if (fIsProjectAsSourceFolder) {
fRootStatus.setInfo(NewFolderWizardMessages.NewSourceFolderWizardPage_warning_ReplaceSF); fRootStatus.setInfo(NewFolderWizardMessages.NewSourceFolderWizardPage_warning_ReplaceSF);
return; return;
} }
if (!modified.isEmpty()) { if (!modified.isEmpty()) {
fRootStatus.setInfo(NLS.bind(NewFolderWizardMessages.NewSourceFolderWizardPage_warning_AddedExclusions, String.valueOf(modified.size()))); fRootStatus.setInfo(NLS.bind(NewFolderWizardMessages.NewSourceFolderWizardPage_warning_AddedExclusions, String.valueOf(modified.size())));
return; return;
} }
} }
} }
} }
// ---- creation ---------------- // ---- creation ----------------
public ISourceRoot getNewSourceRoot() { public ISourceRoot getNewSourceRoot() {
return fCreatedRoot; return fCreatedRoot;
} }
public IResource getCorrespondingResource() { public IResource getCorrespondingResource() {
return fCurrCProject.getProject().getFolder(fRootDialogField.getText()); return fCurrCProject.getProject().getFolder(fRootDialogField.getText());
} }
public void createSourceRoot(IProgressMonitor monitor) throws CoreException, InterruptedException { public void createSourceRoot(IProgressMonitor monitor) throws CoreException {
if (monitor == null) { SubMonitor progress = SubMonitor.convert(monitor,
monitor= new NullProgressMonitor(); NewFolderWizardMessages.NewSourceFolderWizardPage_operation, 3);
String relPath= fRootDialogField.getText();
IProject project = fCurrCProject.getProject();
IFolder folder= project.getFolder(relPath);
if (!folder.exists()) {
CoreUtility.createFolder(folder, true, true, progress.split(1));
} }
monitor.beginTask(NewFolderWizardMessages.NewSourceFolderWizardPage_operation, 3);
try { if (CCorePlugin.getDefault().isNewStyleProject(project)) {
String relPath= fRootDialogField.getText(); InternalCoreModelUtil.addSourceEntry(project, folder, fIsProjectAsSourceFolder, progress.split(2));
} else {
IProject project = fCurrCProject.getProject(); fCurrCProject.setRawPathEntries(fNewEntries, progress.split(2));
IFolder folder= project.getFolder(relPath);
if (!folder.exists()) {
CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 1));
}
if (monitor.isCanceled()) {
throw new InterruptedException();
}
if (CCorePlugin.getDefault().isNewStyleProject(project)) {
InternalCoreModelUtil.addSourceEntry(project, folder, fIsProjectAsSourceFolder,
new SubProgressMonitor(monitor, 2));
} else {
fCurrCProject.setRawPathEntries(fNewEntries, new SubProgressMonitor(monitor, 2));
}
fCreatedRoot= fCurrCProject.findSourceRoot(folder);
} finally {
monitor.done();
} }
fCreatedRoot= fCurrCProject.findSourceRoot(folder);
} }
// ------------- choose dialogs // ------------- choose dialogs
private IFolder chooseFolder(String title, String message, IPath initialPath) { private IFolder chooseFolder(String title, String message, IPath initialPath) {
Class<?>[] acceptedClasses= new Class<?>[] { IFolder.class }; Class<?>[] acceptedClasses= new Class<?>[] { IFolder.class };
ISelectionStatusValidator validator= new TypedElementSelectionValidator(acceptedClasses, false); ISelectionStatusValidator validator= new TypedElementSelectionValidator(acceptedClasses, false);
ViewerFilter filter= new TypedViewerFilter(acceptedClasses, null); ViewerFilter filter= new TypedViewerFilter(acceptedClasses, null);
ILabelProvider lp= new WorkbenchLabelProvider(); ILabelProvider lp= new WorkbenchLabelProvider();
ITreeContentProvider cp= new WorkbenchContentProvider(); ITreeContentProvider cp= new WorkbenchContentProvider();
@ -449,10 +429,10 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage {
if (dialog.open() == Window.OK) { if (dialog.open() == Window.OK) {
return (IFolder) dialog.getFirstResult(); return (IFolder) dialog.getFirstResult();
} }
return null; return null;
} }
private ICProject chooseProject() { private ICProject chooseProject() {
ICProject[] projects; ICProject[] projects;
try { try {
@ -461,16 +441,16 @@ public class NewSourceFolderWizardPage extends NewElementWizardPage {
CUIPlugin.log(e); CUIPlugin.log(e);
projects= new ICProject[0]; projects= new ICProject[0];
} }
ILabelProvider labelProvider= new CElementLabelProvider(CElementLabelProvider.SHOW_DEFAULT); ILabelProvider labelProvider= new CElementLabelProvider(CElementLabelProvider.SHOW_DEFAULT);
ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), labelProvider); ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), labelProvider);
dialog.setTitle(NewFolderWizardMessages.NewSourceFolderWizardPage_ChooseProjectDialog_title); dialog.setTitle(NewFolderWizardMessages.NewSourceFolderWizardPage_ChooseProjectDialog_title);
dialog.setMessage(NewFolderWizardMessages.NewSourceFolderWizardPage_ChooseProjectDialog_description); dialog.setMessage(NewFolderWizardMessages.NewSourceFolderWizardPage_ChooseProjectDialog_description);
dialog.setElements(projects); dialog.setElements(projects);
dialog.setInitialSelections(new Object[] { fCurrCProject }); dialog.setInitialSelections(new Object[] { fCurrCProject });
if (dialog.open() == Window.OK) { if (dialog.open() == Window.OK) {
return (ICProject) dialog.getFirstResult(); return (ICProject) dialog.getFirstResult();
} }
return null; return null;
} }
} }

View file

@ -568,6 +568,9 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
* Returns the method stubs to display in the wizard. * Returns the method stubs to display in the wizard.
* *
* @return array of method stubs * @return array of method stubs
*
* @noreference This method is not intended to be referenced by clients.
* @nooverride This method is not intended to be re-implemented or extended by clients.
*/ */
protected IMethodStub[] getDefaultMethodStubs() { protected IMethodStub[] getDefaultMethodStubs() {
return new IMethodStub[] { return new IMethodStub[] {
@ -717,6 +720,9 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
* Returns the currently selected (checked) method stubs. * Returns the currently selected (checked) method stubs.
* *
* @return array of <code>IMethodStub</code> or empty array if none selected. * @return array of <code>IMethodStub</code> or empty array if none selected.
*
* @noreference This method is not intended to be referenced by clients.
* @nooverride This method is not intended to be re-implemented or extended by clients.
*/ */
protected IMethodStub[] getSelectedMethodStubs() { protected IMethodStub[] getSelectedMethodStubs() {
return fMethodStubsDialogField.getCheckedMethodStubs(); return fMethodStubsDialogField.getCheckedMethodStubs();
@ -724,8 +730,12 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
/** /**
* Adds a method stub to the method stubs field. * Adds a method stub to the method stubs field.
*
* @param methodStub the method stub to add * @param methodStub the method stub to add
* @param selected <code>true</code> if the stub is initially selected (checked) * @param selected <code>true</code> if the stub is initially selected (checked)
*
* @noreference This method is not intended to be referenced by clients.
* @nooverride This method is not intended to be re-implemented or extended by clients.
*/ */
protected void addMethodStub(IMethodStub methodStub, boolean selected) { protected void addMethodStub(IMethodStub methodStub, boolean selected) {
fMethodStubsDialogField.addMethodStub(methodStub, selected); fMethodStubsDialogField.addMethodStub(methodStub, selected);
@ -735,6 +745,9 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
* Returns the contents of the base classes field. * Returns the contents of the base classes field.
* *
* @return array of <code>IBaseClassInfo</code> * @return array of <code>IBaseClassInfo</code>
*
* @noreference This method is not intended to be referenced by clients.
* @nooverride This method is not intended to be re-implemented or extended by clients.
*/ */
protected IBaseClassInfo[] getBaseClasses() { protected IBaseClassInfo[] getBaseClasses() {
List<IBaseClassInfo> classesList = fBaseClassesDialogField.getElements(); List<IBaseClassInfo> classesList = fBaseClassesDialogField.getElements();
@ -748,7 +761,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
* @param isVirtual <code>true</code> if the inheritance is virtual * @param isVirtual <code>true</code> if the inheritance is virtual
*/ */
protected void addBaseClass(ITypeInfo newBaseClass, ASTAccessVisibility access, boolean isVirtual) { protected void addBaseClass(ITypeInfo newBaseClass, ASTAccessVisibility access, boolean isVirtual) {
// check if already exists // Check if already exists.
List<IBaseClassInfo> baseClasses = fBaseClassesDialogField.getElements(); List<IBaseClassInfo> baseClasses = fBaseClassesDialogField.getElements();
if (baseClasses != null) { if (baseClasses != null) {
for (IBaseClassInfo baseClassInfo : baseClasses) { for (IBaseClassInfo baseClassInfo : baseClasses) {
@ -771,8 +784,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
* Sets the use test file creation checkbox's selection state. * Sets the use test file creation checkbox's selection state.
* *
* @param isSelected the checkbox's selection state * @param isSelected the checkbox's selection state
* @param canBeModified if <code>true</code> the checkbox is * @param canBeModified if <code>true</code> the checkbox is modifiable; otherwise it is read-only.
* modifiable; otherwise it is read-only.
* @since 5.3 * @since 5.3
*/ */
public void setTestFileSelection(boolean isSelected, boolean canBeModified) { public void setTestFileSelection(boolean isSelected, boolean canBeModified) {
@ -1725,6 +1737,9 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
* @param baseClasses an array of base classes * @param baseClasses an array of base classes
* *
* @return the status of the validation * @return the status of the validation
*
* @noreference This method is not intended to be referenced by clients.
* @nooverride This method is not intended to be re-implemented or extended by clients.
*/ */
protected IStatus baseClassesChanged(ICProject project, IPath sourceFolder, IBaseClassInfo[] baseClasses) { protected IStatus baseClassesChanged(ICProject project, IPath sourceFolder, IBaseClassInfo[] baseClasses) {
MultiStatus status = new MultiStatus(CUIPlugin.getPluginId(), IStatus.OK, "", null); //$NON-NLS-1$ MultiStatus status = new MultiStatus(CUIPlugin.getPluginId(), IStatus.OK, "", null); //$NON-NLS-1$
@ -2020,9 +2035,8 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
* *
* @param monitor a progress monitor to report progress. * @param monitor a progress monitor to report progress.
* @throws CoreException Thrown when the creation failed. * @throws CoreException Thrown when the creation failed.
* @throws InterruptedException Thrown when the operation was cancelled.
*/ */
public void createClass(IProgressMonitor monitor) throws CoreException, InterruptedException { public void createClass(IProgressMonitor monitor) throws CoreException {
// Update dialog settings. // Update dialog settings.
fDialogSettings.put(KEY_NAMESPACE_SELECTED, fNamespaceSelection.isSelected()); fDialogSettings.put(KEY_NAMESPACE_SELECTED, fNamespaceSelection.isSelected());
fDialogSettings.put(KEY_TEST_FILE_SELECTED, fTestFileSelection.isSelected()); fDialogSettings.put(KEY_TEST_FILE_SELECTED, fTestFileSelection.isSelected());
@ -2075,12 +2089,14 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
* @param methodStubs array of method stubs * @param methodStubs array of method stubs
* @param monitor a progress monitor * @param monitor a progress monitor
* @throws CoreException if the creation failed * @throws CoreException if the creation failed
* @throws InterruptedException if the operation was cancelled
* @since 5.3 * @since 5.3
*
* @noreference This method is not intended to be referenced by clients.
* @nooverride This method is not intended to be re-implemented or extended by clients.
*/ */
protected void createClass(IPath headerPath, IPath sourcePath, IPath testPath, String className, protected void createClass(IPath headerPath, IPath sourcePath, IPath testPath, String className,
String namespace, IBaseClassInfo[] baseClasses, IMethodStub[] methodStubs, IProgressMonitor monitor) String namespace, IBaseClassInfo[] baseClasses, IMethodStub[] methodStubs, IProgressMonitor monitor)
throws CoreException, InterruptedException { throws CoreException {
NewClassCodeGenerator generator = new NewClassCodeGenerator( NewClassCodeGenerator generator = new NewClassCodeGenerator(
headerPath, headerPath,
sourcePath, sourcePath,
@ -2098,16 +2114,19 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
fCreatedTestFile = generator.getCreatedTestFile(); fCreatedTestFile = generator.getCreatedTestFile();
} }
/**
* @noreference This method is not intended to be referenced by clients.
* @nooverride This method is not intended to be re-implemented or extended by clients.
*/
protected void createClass(IPath headerPath, IPath sourcePath, String className, String namespace, protected void createClass(IPath headerPath, IPath sourcePath, String className, String namespace,
IBaseClassInfo[] baseClasses, IMethodStub[] methodStubs, IProgressMonitor monitor) IBaseClassInfo[] baseClasses, IMethodStub[] methodStubs, IProgressMonitor monitor)
throws CoreException, InterruptedException { throws CoreException {
createClass(headerPath, sourcePath, null, className, namespace, baseClasses, methodStubs, createClass(headerPath, sourcePath, null, className, namespace, baseClasses, methodStubs, monitor);
monitor);
} }
/** /**
* Returns the created class. The method only returns a valid class * Returns the created class. The method only returns a valid class
* after <code>createClass</code> has been called. * after {@link #createClass} has been called.
* *
* @return the created class * @return the created class
* @see #createClass(IProgressMonitor) * @see #createClass(IProgressMonitor)
@ -2118,7 +2137,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
/** /**
* Returns the created header file. The method only returns a valid file * Returns the created header file. The method only returns a valid file
* after <code>createClass</code> has been called. * after {@link #createClass} has been called.
* *
* @return the created header file * @return the created header file
* @see #createClass(IProgressMonitor) * @see #createClass(IProgressMonitor)
@ -2129,7 +2148,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
/** /**
* Returns the created source file. The method only returns a valid file * Returns the created source file. The method only returns a valid file
* after <code>createClass</code> has been called. * after {@link #createClass} has been called.
* *
* @return the created source file * @return the created source file
* @see #createClass(IProgressMonitor) * @see #createClass(IProgressMonitor)
@ -2140,7 +2159,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
/** /**
* Returns the created test file. The method only returns a valid file * Returns the created test file. The method only returns a valid file
* after <code>createClass</code> has been called. * after {@link #createClass} has been called.
* *
* @return the created test file * @return the created test file
* @see #createClass(IProgressMonitor) * @see #createClass(IProgressMonitor)

View file

@ -10,16 +10,17 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.wizards; package org.eclipse.cdt.ui.wizards;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.CPluginImages; import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.wizards.NewElementWizard; import org.eclipse.cdt.internal.ui.wizards.NewElementWizard;
import org.eclipse.cdt.internal.ui.wizards.folderwizard.NewFolderWizardMessages; import org.eclipse.cdt.internal.ui.wizards.folderwizard.NewFolderWizardMessages;
import org.eclipse.cdt.internal.ui.wizards.folderwizard.NewSourceFolderWizardPage; import org.eclipse.cdt.internal.ui.wizards.folderwizard.NewSourceFolderWizardPage;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
public class NewSourceFolderCreationWizard extends NewElementWizard { public class NewSourceFolderCreationWizard extends NewElementWizard {
private NewSourceFolderWizardPage fPage; private NewSourceFolderWizardPage fPage;
public NewSourceFolderCreationWizard() { public NewSourceFolderCreationWizard() {
@ -29,9 +30,6 @@ public class NewSourceFolderCreationWizard extends NewElementWizard {
setWindowTitle(NewFolderWizardMessages.NewSourceFolderCreationWizard_title); setWindowTitle(NewFolderWizardMessages.NewSourceFolderCreationWizard_title);
} }
/*
* @see Wizard#addPages
*/
@Override @Override
public void addPages() { public void addPages() {
super.addPages(); super.addPages();
@ -40,17 +38,11 @@ public class NewSourceFolderCreationWizard extends NewElementWizard {
fPage.init(getSelection()); fPage.init(getSelection());
} }
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#finishPage(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override @Override
protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException { protected void finishPage(IProgressMonitor monitor) throws CoreException {
fPage.createSourceRoot(monitor); // use the full progress monitor fPage.createSourceRoot(monitor); // Use the full progress monitor.
} }
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.IWizard#performFinish()
*/
@Override @Override
public boolean performFinish() { public boolean performFinish() {
boolean res= super.performFinish(); boolean res= super.performFinish();
@ -59,5 +51,4 @@ public class NewSourceFolderCreationWizard extends NewElementWizard {
} }
return res; return res;
} }
} }