Lines 14-33
Link Here
|
14 |
package org.netbeans.modules.project.ui.actions; |
14 |
package org.netbeans.modules.project.ui.actions; |
15 |
|
15 |
|
16 |
import java.awt.event.ActionEvent; |
16 |
import java.awt.event.ActionEvent; |
|
|
17 |
import java.io.File; |
17 |
import java.io.IOException; |
18 |
import java.io.IOException; |
18 |
import java.util.Iterator; |
19 |
import java.util.Iterator; |
19 |
import java.util.Set; |
20 |
import java.util.Set; |
|
|
21 |
import javax.swing.Action; |
20 |
import javax.swing.Icon; |
22 |
import javax.swing.Icon; |
21 |
import javax.swing.ImageIcon; |
23 |
import javax.swing.ImageIcon; |
|
|
24 |
import javax.swing.SwingUtilities; |
22 |
import org.netbeans.api.project.Project; |
25 |
import org.netbeans.api.project.Project; |
23 |
import org.netbeans.api.project.ProjectManager; |
26 |
import org.netbeans.api.project.ProjectManager; |
|
|
27 |
import org.netbeans.modules.project.ui.NewProjectWizard; |
24 |
import org.netbeans.modules.project.ui.OpenProjectList; |
28 |
import org.netbeans.modules.project.ui.OpenProjectList; |
25 |
import org.openide.ErrorManager; |
29 |
import org.openide.ErrorManager; |
26 |
import org.openide.filesystems.FileObject; |
30 |
import org.openide.filesystems.FileObject; |
27 |
import org.openide.filesystems.Repository; |
31 |
import org.openide.filesystems.Repository; |
28 |
import org.openide.loaders.DataFolder; |
32 |
import org.openide.loaders.DataFolder; |
29 |
import org.openide.loaders.DataObject; |
33 |
import org.openide.loaders.DataObject; |
30 |
import org.openide.loaders.TemplateWizard; |
34 |
import org.openide.nodes.Node; |
31 |
import org.openide.util.NbBundle; |
35 |
import org.openide.util.NbBundle; |
32 |
import org.openide.util.Utilities; |
36 |
import org.openide.util.Utilities; |
33 |
|
37 |
|
Lines 37-43
Link Here
|
37 |
private static final String NAME = NbBundle.getMessage( NewProject.class, "LBL_NewProjectAction_Name" ); // NOI18N |
41 |
private static final String NAME = NbBundle.getMessage( NewProject.class, "LBL_NewProjectAction_Name" ); // NOI18N |
38 |
|
42 |
|
39 |
|
43 |
|
40 |
private static TemplateWizard wizard; |
44 |
private static NewProjectWizard wizard; |
41 |
|
45 |
|
42 |
public NewProject() { |
46 |
public NewProject() { |
43 |
super( NAME, ICON ); |
47 |
super( NAME, ICON ); |
Lines 46-60
Link Here
|
46 |
public void actionPerformed( ActionEvent evt ) { |
50 |
public void actionPerformed( ActionEvent evt ) { |
47 |
|
51 |
|
48 |
if ( wizard == null ) { |
52 |
if ( wizard == null ) { |
49 |
wizard = new TemplateWizard(); // XXX Create NewProjectWizard instead of TemplateWizard |
|
|
50 |
FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource( "Templates/Project" ); //NOI18N |
53 |
FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource( "Templates/Project" ); //NOI18N |
51 |
|
54 |
wizard = new NewProjectWizard(fo); |
52 |
DataFolder templates = DataFolder.findFolder( fo ); |
|
|
53 |
wizard.setTemplatesFolder( templates ); |
54 |
} |
55 |
} |
55 |
|
56 |
|
56 |
try { |
57 |
try { |
57 |
Set dataObjects = wizard.instantiate(); |
58 |
Set newObjects = wizard.instantiate(); |
58 |
|
59 |
|
59 |
Object mainProperty = wizard.getProperty( /* XXX Define somewhere */ "setAsMain" ); // NOI18N |
60 |
Object mainProperty = wizard.getProperty( /* XXX Define somewhere */ "setAsMain" ); // NOI18N |
60 |
boolean main = true; |
61 |
boolean main = true; |
Lines 62-76
Link Here
|
62 |
main = ((Boolean)mainProperty).booleanValue(); |
63 |
main = ((Boolean)mainProperty).booleanValue(); |
63 |
} |
64 |
} |
64 |
|
65 |
|
65 |
if ( dataObjects != null && !dataObjects.isEmpty() ) { // Open all returned projects in the GUI |
66 |
if ( newObjects != null && !newObjects.isEmpty() ) { // Open all returned projects in the GUI |
66 |
for( Iterator it = dataObjects.iterator(); it.hasNext(); ) { |
67 |
for( Iterator it = newObjects.iterator(); it.hasNext(); ) { |
67 |
DataObject prjDirDo = (DataObject)it.next(); |
68 |
Object obj = it.next (); |
68 |
FileObject prjDirFo = prjDirDo.getPrimaryFile(); |
69 |
FileObject prjDirFo = null; |
69 |
Project p = ProjectManager.getDefault().findProject( prjDirFo ); |
70 |
if (obj instanceof DataObject) { |
70 |
if ( p != null ) { |
71 |
// old style's way |
71 |
OpenProjectList.getDefault().open( p, true ); |
72 |
DataObject prjDirDo = (DataObject)obj; |
72 |
if ( main ) { |
73 |
prjDirFo = prjDirDo.getPrimaryFile(); |
73 |
OpenProjectList.getDefault().setMainProject( p ); |
74 |
} else if (obj instanceof FileObject) { |
|
|
75 |
prjDirFo = (FileObject)obj; |
76 |
} else { |
77 |
assert false : obj; |
78 |
} |
79 |
if (prjDirFo.isFolder ()) { |
80 |
Project p = ProjectManager.getDefault().findProject( prjDirFo ); |
81 |
if ( p != null ) { |
82 |
OpenProjectList.getDefault().open( p, true ); |
83 |
if ( main ) { |
84 |
OpenProjectList.getDefault().setMainProject( p ); |
85 |
// open main class in editor |
86 |
FileObject mainFO = getMainClassFO (getSourcesRoot (p), "com.myapp.Test"); |
87 |
} |
88 |
} |
89 |
} else { |
90 |
// propably main class |
91 |
if (obj instanceof DataObject) { |
92 |
final Node node = ((DataObject)obj).getNodeDelegate (); |
93 |
final Action a = node.getPreferredAction(); |
94 |
if (a != null) { |
95 |
SwingUtilities.invokeLater(new Runnable() { |
96 |
public void run() { |
97 |
a.actionPerformed(new ActionEvent(node, ActionEvent.ACTION_PERFORMED, "")); // NOI18N |
98 |
} |
99 |
}); |
100 |
} |
74 |
} |
101 |
} |
75 |
} |
102 |
} |
76 |
} |
103 |
} |
Lines 79-85
Link Here
|
79 |
catch ( IOException e ) { |
106 |
catch ( IOException e ) { |
80 |
ErrorManager.getDefault().notify( ErrorManager.INFORMATIONAL, e ); |
107 |
ErrorManager.getDefault().notify( ErrorManager.INFORMATIONAL, e ); |
81 |
} |
108 |
} |
82 |
|
109 |
} |
|
|
110 |
|
111 |
// helper methods |
112 |
private FileObject getMainClassFO (FileObject sourcesRoot, String mainClass) { |
113 |
// replace '.' with '/' |
114 |
mainClass = mainClass.replace ('.', File.separatorChar); // XXX // NOI18N |
115 |
// find mainclass's FileObject |
116 |
FileObject mainFO = sourcesRoot.getFileObject (mainClass, "java"); // XXX // NOI18N |
117 |
// check MainClassChooser.hasMainMethod (mainFO); |
118 |
// ignore unvalid mainClass |
119 |
return mainFO; |
120 |
} |
121 |
|
122 |
private FileObject getSourcesRoot (Project p) { |
123 |
FileObject root = p.getProjectDirectory (); |
124 |
String sourceRoot = "src"; //(String)j2seProperties.get (J2SEProjectProperties.SRC_DIR); |
125 |
return root.getFileObject (sourceRoot); |
83 |
} |
126 |
} |
84 |
|
127 |
|
85 |
} |
128 |
} |