Lines 10-24
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.photran.cdtinterface.ui; |
11 |
package org.eclipse.photran.cdtinterface.ui; |
12 |
|
12 |
|
|
|
13 |
import java.io.ByteArrayInputStream; |
14 |
import java.io.FileNotFoundException; |
15 |
import java.io.IOException; |
16 |
import java.io.RandomAccessFile; |
17 |
import java.util.ArrayList; |
18 |
import java.util.Iterator; |
19 |
|
13 |
import org.eclipse.cdt.core.CProjectNature; |
20 |
import org.eclipse.cdt.core.CProjectNature; |
|
|
21 |
import org.eclipse.cdt.core.model.CoreModel; |
22 |
import org.eclipse.cdt.core.settings.model.ICProjectDescription; |
23 |
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; |
14 |
import org.eclipse.cdt.ui.newui.UIMessages; |
24 |
import org.eclipse.cdt.ui.newui.UIMessages; |
15 |
import org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard; |
25 |
import org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard; |
|
|
26 |
import org.eclipse.core.resources.IFile; |
16 |
import org.eclipse.core.resources.IProject; |
27 |
import org.eclipse.core.resources.IProject; |
|
|
28 |
import org.eclipse.core.resources.IProjectDescription; |
17 |
import org.eclipse.core.runtime.CoreException; |
29 |
import org.eclipse.core.runtime.CoreException; |
18 |
import org.eclipse.core.runtime.NullProgressMonitor; |
30 |
import org.eclipse.core.runtime.NullProgressMonitor; |
|
|
31 |
import org.eclipse.photran.core.FProjectNature; |
19 |
|
32 |
|
20 |
/** |
33 |
/** |
21 |
* @author ??? |
34 |
* @author ??? |
|
|
35 |
* @author Matt Scarpino - 7/20/2009 - Updated to include Fortran nature in project |
22 |
*/ |
36 |
*/ |
23 |
public class FortranProjectWizard extends CDTCommonProjectWizard |
37 |
public class FortranProjectWizard extends CDTCommonProjectWizard |
24 |
{ |
38 |
{ |
Lines 31-48
Link Here
|
31 |
|
45 |
|
32 |
public String[] getNatures() |
46 |
public String[] getNatures() |
33 |
{ |
47 |
{ |
34 |
return new String[] { CProjectNature.C_NATURE_ID }; |
48 |
return new String[] { FProjectNature.F_NATURE_ID, CProjectNature.C_NATURE_ID }; |
35 |
} |
49 |
} |
36 |
|
50 |
|
|
|
51 |
/** |
52 |
* This method is called immediately after the createIProject() method in |
53 |
* the CDTCommonProjectWizard class |
54 |
*/ |
37 |
protected IProject continueCreation(IProject prj) |
55 |
protected IProject continueCreation(IProject prj) |
38 |
{ |
56 |
{ |
39 |
try |
57 |
try |
40 |
{ |
58 |
{ |
41 |
CProjectNature.addCNature(prj, new NullProgressMonitor()); |
59 |
// Add C nature to the project |
|
|
60 |
CProjectNature.addCNature(prj, new NullProgressMonitor()); |
61 |
|
62 |
// Add Fortran nature to the project |
63 |
FProjectNature.addFNature(prj, new NullProgressMonitor()); |
42 |
} |
64 |
} |
43 |
catch (CoreException e) {} |
65 |
catch (CoreException e) {} |
44 |
|
66 |
|
45 |
return prj; |
67 |
return prj; |
46 |
} |
68 |
} |
|
|
69 |
|
70 |
/** |
71 |
* This method is called within the performFinish() method of the |
72 |
* CDTCommonProjectWizard class. Among other things, it sets the Photran |
73 |
* nature first in the project's nature list. This ensures that the project |
74 |
* will be displayed as a Fortran project in the Photran navigator. |
75 |
*/ |
76 |
protected boolean setCreated() throws CoreException |
77 |
{ |
78 |
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); |
79 |
|
80 |
ICProjectDescription des = mngr.getProjectDescription(newProject, false); |
81 |
if(des.isCdtProjectCreating()) |
82 |
{ |
83 |
des = mngr.getProjectDescription(newProject, true); |
84 |
des.setCdtProjectCreated(); |
85 |
mngr.setProjectDescription(newProject, des, false, null); |
86 |
return true; |
87 |
} |
88 |
|
89 |
// Access the .project file in the recently-created project |
90 |
final IFile projFile = (IFile)newProject.findMember(IProjectDescription.DESCRIPTION_FILE_NAME); |
91 |
if(projFile.exists()) |
92 |
{ |
93 |
try |
94 |
{ |
95 |
// Create a list of lines in .project file |
96 |
RandomAccessFile raFile = new RandomAccessFile(projFile.getLocation().toOSString(), "rws"); |
97 |
ArrayList lineList = new ArrayList(); |
98 |
String line; |
99 |
while((line = raFile.readLine()) != null) |
100 |
lineList.add(line); |
101 |
raFile.close(); |
102 |
|
103 |
// Find the natures in the list |
104 |
Iterator itr = lineList.iterator(); |
105 |
int first_index = 0, phot_index = 0; |
106 |
while (itr.hasNext()) |
107 |
{ |
108 |
line = (String)itr.next(); |
109 |
if(line.trim().equals("<natures>")) |
110 |
first_index = lineList.indexOf(line) + 1; |
111 |
else if(line.contains("photran")) |
112 |
phot_index = lineList.indexOf(line); |
113 |
} |
114 |
|
115 |
// Swap the photran nature with the first nature |
116 |
String temp = (String)lineList.get(first_index); |
117 |
lineList.set(first_index, lineList.get(phot_index)); |
118 |
lineList.set(phot_index, temp); |
119 |
|
120 |
// Write the new lines to the .project file |
121 |
itr = lineList.iterator(); |
122 |
StringBuffer content = new StringBuffer(""); |
123 |
while (itr.hasNext()) |
124 |
{ |
125 |
content.append((String)itr.next() + "\n"); |
126 |
} |
127 |
projFile.setContents(new ByteArrayInputStream(content.toString().getBytes()), IFile.FORCE, null); |
47 |
|
128 |
|
|
|
129 |
// Deallocate |
130 |
lineList.clear(); |
131 |
} |
132 |
catch (FileNotFoundException e) { |
133 |
e.printStackTrace(); |
134 |
} |
135 |
catch (IOException e) { |
136 |
e.printStackTrace(); |
137 |
} |
138 |
catch (CoreException e) { |
139 |
e.printStackTrace(); |
140 |
} |
141 |
} |
142 |
return false; |
143 |
} |
48 |
} |
144 |
} |