Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] New Class Wizard, non-CModel selection problem fixed


Hello,

The user may start the wizard from the navigator view. In this case, the selection is a resource, not a CModel Element, which caused some troubles.
This patch fixes this problem. Change log has been updated.

Hoda Amer
Senior Software Engineer
Rational Software - IBM Software Group



Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/ChangeLog,v
retrieving revision 1.97
diff -u -r1.97 ChangeLog
--- ChangeLog	28 Apr 2003 02:36:20 -0000	1.97
+++ ChangeLog	30 May 2003 14:50:10 -0000
@@ -1,3 +1,8 @@
+2003-05-30 Hoda Amer
+	Added the new claass wizard on May 27th
+	Fixed the inclusion problem on May 28th
+	Fixed the non-cmodel selection problem May 30th.
+	
 2003-04-27 Alain Magloire
 
 	PR 36759, the outline does not update
Index: src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties,v
retrieving revision 1.1
diff -u -r1.1 NewWizardMessages.properties
--- src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties	27 May 2003 21:33:02 -0000	1.1
+++ src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties	30 May 2003 14:50:11 -0000
@@ -160,6 +160,7 @@
 NewClassWizardPage.error.InvalidBaseClassName=Base class name is not valid.
 NewClassWizardPage.warning.BaseClassNotExists=Warning: Base class does not exist in current project.
 
+NewClassWizardPage.operations.getProjectClasses=Looking for classes in project
 # ------- BaseClassSelectionDialog -----
 
 BaseClassSelectionDialog.title=Classes in this project
Index: src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java,v
retrieving revision 1.2
diff -u -r1.2 NewClassWizardPage.java
--- src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java	28 May 2003 18:10:13 -0000	1.2
+++ src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java	30 May 2003 14:50:12 -0000
@@ -197,7 +197,7 @@
 		setErrorMessage(null);
 		setMessage(null);
 		setControl(composite);
-
+		
 	}
 	
 	protected void createClassNameControls(Composite composite, int nColumns) {		
@@ -349,12 +349,27 @@
 			List list= ((IStructuredSelection)sel).toList();
 			if (list.size() == 1) {
 				Object element= list.get(0);
-				if ( (element instanceof ICElement) 
-				//&& ((ICElement)element).getElementType() == ICElement.C_CCONTAINER)
-				) 
-				{
+				if (element instanceof ICElement) {
 					return (ICElement)element;
-				}
+				} 
+			}
+		}
+		return null;
+	}
+
+	private IResource getSelectionResourceElement(IStructuredSelection sel) {
+		if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
+			List list= ((IStructuredSelection)sel).toList();
+			if (list.size() == 1) {
+				Object element= list.get(0);
+				if (element instanceof IResource) {
+					if(element instanceof IFile){
+						IFile file = (IFile)element;
+						return (IResource) file.getParent();
+					}else {
+						return (IResource)element;
+					}
+				} 
 			}
 		}
 		return null;
@@ -380,35 +395,39 @@
 	}
 	
 	private ArrayList findClassElementsInProject(){		
-		if(	elementsOfTypeClassInProject == null ){
-			elementsOfTypeClassInProject = new ArrayList();		
-			IRunnableWithProgress runnable= new IRunnableWithProgress() {
-				public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
-					if (monitor == null) {
-						monitor= new NullProgressMonitor();
-					}				
-					monitor.beginTask("", 5); //$NON-NLS-1$
-					try{
-						if(eSelection != null){
-							ICProject cProject = eSelection.getCProject();
-							getChildrenOfTypeClass((IParent)cProject, elementsOfTypeClassInProject, monitor, 1);
-						}
-						monitor.worked(5);
-					} finally{
-						monitor.done();
-					}
+		if(eSelection == null){
+			return new ArrayList();			
+		}
+
+		if(	elementsOfTypeClassInProject != null ){
+			return elementsOfTypeClassInProject;
+		}
+
+		elementsOfTypeClassInProject = new ArrayList();		
+		IRunnableWithProgress runnable= new IRunnableWithProgress() {
+			public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+				if (monitor == null) {
+					monitor= new NullProgressMonitor();
+				}				
+				monitor.beginTask(NewWizardMessages.getString("NewClassWizardPage.operations.getProjectClasses"), 5); //$NON-NLS-1$
+				try{
+					ICProject cProject = eSelection.getCProject();
+					getChildrenOfTypeClass((IParent)cProject, elementsOfTypeClassInProject, monitor, 1);
+					monitor.worked(5);
+				} finally{
+					monitor.done();
 				}
-			};
-			
-			try {
-				getWizard().getContainer().run(false, true, runnable);
-			} catch (InvocationTargetException e) {				
-			} catch (InterruptedException e) {
-			} 
-			finally {
 			}
-		}							 
-		return elementsOfTypeClassInProject;
+		};
+		
+		try {
+			getWizard().getContainer().run(false, true, runnable);
+		} catch (InvocationTargetException e) {				
+		} catch (InterruptedException e) {
+		} 
+		finally {
+		}
+		return elementsOfTypeClassInProject;				
 	}
 	
 	protected ICElement chooseBaseClass(){
@@ -613,6 +632,14 @@
 	
 	// -------------Helper methods for creating the class -------
 	protected IPath getSelectionPath(){
+		if(eSelection == null){
+			IResource resourceSelection = getSelectionResourceElement(currentSelection);
+			if(resourceSelection != null){
+				return resourceSelection.getLocation().makeAbsolute();
+			}
+			else
+				return null;
+		}		
 		// if it is a file, return the parent path
 		if(eSelection instanceof ITranslationUnit)
 			return (eSelection.getParent().getPath());

Back to the top