|
|
|
|
|
|
Re: creating source folder [message #310547 is a reply to message #310534] |
Thu, 07 December 2006 09:57  |
Eclipse User |
|
|
|
I tried with below method in NewCProjectWizard.java, while creating new
project I want source folder to be created with it. I call this method in
performFinish() mehtod.
But it creates two source folder with same name "src", out of which one
is source folder & other is normal folder.
If I uncomment the condition given at line no. 28 then it gives me only
one soruce folder but it's normal folder not source folder.
What should I do,
please tell me.
/*********************************************************** **********/
1 public void createSrc() {
2 StatusInfo fRootStatus = new StatusInfo();
3 StatusInfo fProjectSt1atus = new StatusInfo();
4 boolean fIsProjectAsSourceFolder = false;
5
6 ICProject fCurrCProject;
7 IPathEntry[] fEntries;
8 StatusInfo fProjectStatus = null;
9 IPathEntry[] fNewEntries;
10 ISourceRoot sourceRoot;
11
12 boolean isSelected = fMainPage.getTemplateSelection();
13 if (isSelected) {
14 String path = newProject.getProject().getFullPath().toString();
15 IPath prjPath = newProject.getProject().getFullPath().append("src");
16 IFolder srcFolder = newProject.getProject().getFolder("src");
17 try {
18 CoreUtility.createFolder(srcFolder, true, true,
19 new SubProgressMonitor(tempMonitor, 1));
20 if (tempMonitor.isCanceled()) {
21 throw new InterruptedException();
22 }
23
24 /*
25 * if I uncomment the following condition it gives me one "src"
26 * folder but it's normal folder not source folder.
27 */
28 // if (newProject.hasNature(CProjectNature.C_NATURE_ID) ||
29 // newProject.hasNature(CCProjectNature.CC_NATURE_ID)) {
30 fCurrCProject = CoreModel.getDefault().create(newProject);
31 fEntries = fCurrCProject.getRawPathEntries();
32 fProjectStatus.setOK();
33 // return;
34 // }
35
36 // fCurrCProject.setRawPathEntries(fNewEntries, new
37 // SubProgressMonitor(monitor, 2));
38 // fCreatedRoot= fCurrCProject.findSourceRoot(folder);
39
40 ArrayList newEntries = new ArrayList(fEntries.length + 1);
41 int projectEntryIndex = -1;
42
43 for (int i = 0; i < fEntries.length; i++) {
44 IPathEntry curr = fEntries[i];
45 if (curr.getEntryKind() == IPathEntry.CDT_SOURCE) {
46 if (path.equals(curr.getPath())) {
47 fRootStatus.setError(NewFolderWizardMessages.getString("NewSourceFolderWizardPage.error.AlreadyExisting "));
//$NON-NLS-1$
48 return;
49 }
50 if (path.equals(curr.getPath())) {
51 projectEntryIndex = i;
52 }
53 }
54 newEntries.add(curr);
55 }
56
57 IPathEntry newEntry =
CoreModel.newSourceEntry(srcFolder.getFullPath());
58
59 Set modified = new HashSet();
60 // if (fExcludeInOthersFields.isSelected()) {
61 // addExclusionPatterns(newEntry, newEntries, modified);
62 // newEntries.add(CoreModel.newSourceEntry(path));
63 // } else {
64 if (projectEntryIndex != -1) {
65 fIsProjectAsSourceFolder = true;
66 newEntries.set(projectEntryIndex, newEntry);
67 } else {
68 newEntries.add(CoreModel.newSourceEntry(srcFolder
.getFullPath()));
69 }
70 // }
71
72 fNewEntries = (IPathEntry[]) newEntries
.toArray(new IPathEntry[newEntries.size()]);
73 fCurrCProject.setRawPathEntries(fNewEntries,
new SubProgressMonitor(tempMonitor, 2));
74
75 sourceRoot = fCurrCProject.findSourceRoot(srcFolder);
76
78 } catch (Exception e) {
79 CUIPlugin.getDefault().log(e);
80 } finally {
81 tempMonitor.done();
82 }
83 }
84 }
/*********************************************************** **********/
Thanks,
parag
|
|
|
Powered by
FUDForum. Page generated in 0.03399 seconds