This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 42870
Collapse All | Expand All

(-)projects/projectui/src/org/netbeans/modules/project/ui/NewProjectWizard.java (+60 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.modules.project.ui;
15
16
import java.awt.Component;
17
import java.io.IOException;
18
import java.text.MessageFormat;
19
import java.util.ArrayList;
20
import java.util.Iterator;
21
import java.util.List;
22
import java.util.Set;
23
import javax.swing.event.ChangeEvent;
24
import javax.swing.event.ChangeListener;
25
import org.netbeans.api.project.Project;
26
import org.netbeans.api.project.ProjectUtils;
27
import org.netbeans.modules.project.uiapi.ProjectChooserFactory;
28
import org.netbeans.api.project.Sources;
29
import org.netbeans.api.project.SourceGroup;
30
//import org.netbeans.spi.project.ui.templates.support.InstantiatingIterator;
31
import org.netbeans.spi.project.ui.templates.support.Templates;
32
import org.openide.WizardDescriptor;
33
import org.openide.filesystems.FileObject;
34
import org.openide.loaders.DataFolder;
35
import org.openide.loaders.DataObject;
36
import org.openide.loaders.DataObjectNotFoundException;
37
38
import org.openide.loaders.TemplateWizard;
39
import org.openide.util.HelpCtx;
40
41
public final class NewProjectWizard extends TemplateWizard {
42
        
43
    private Project p;
44
    // private String[] recommendedTypes;
45
    private FileObject templatesFO;
46
47
    public NewProjectWizard (FileObject fo) {
48
        this.templatesFO = fo;
49
        // this.recommendedTypes = recommendedTypes;        
50
        setTitle( "New Project" );
51
        setTitleFormat( new MessageFormat( "{0}") );
52
        initWizard ();
53
    }
54
    
55
    private void initWizard () {
56
        DataFolder templates = DataFolder.findFolder( templatesFO );
57
        setTemplatesFolder( templates ); 
58
    }
59
    
60
}
(-)projects/projectui/src/org/netbeans/modules/project/ui/actions/NewFile.java (-1 / +19 lines)
Lines 13-29 Link Here
13
13
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.beans.PropertyChangeEvent;
17
import java.beans.PropertyChangeEvent;
17
import java.beans.PropertyChangeListener;
18
import java.beans.PropertyChangeListener;
18
import java.io.IOException;
19
import java.io.IOException;
20
import java.util.Iterator;
21
import java.util.Set;
19
import javax.swing.Action;
22
import javax.swing.Action;
20
import javax.swing.Icon;
23
import javax.swing.Icon;
21
import javax.swing.ImageIcon;
24
import javax.swing.ImageIcon;
25
import javax.swing.SwingUtilities;
22
import org.netbeans.api.project.Project;
26
import org.netbeans.api.project.Project;
23
import org.netbeans.modules.project.ui.NewFileWizard;
27
import org.netbeans.modules.project.ui.NewFileWizard;
24
import org.netbeans.modules.project.ui.OpenProjectList;
28
import org.netbeans.modules.project.ui.OpenProjectList;
25
import org.openide.loaders.DataFolder;
29
import org.openide.loaders.DataFolder;
26
import org.openide.loaders.DataObject;
30
import org.openide.loaders.DataObject;
31
import org.openide.nodes.Node;
27
import org.openide.util.Lookup;
32
import org.openide.util.Lookup;
28
import org.openide.util.NbBundle;
33
import org.openide.util.NbBundle;
29
import org.openide.util.Utilities;
34
import org.openide.util.Utilities;
Lines 63-69 Link Here
63
        }
68
        }
64
69
65
        try { 
70
        try { 
66
            wd.instantiate();
71
            Set result = wd.instantiate();
72
            Iterator it = result.iterator ();
73
            Object obj = it.next ();
74
            // Same what template wizard does - not vey nice
75
            // run default action (hopefully should be here)
76
            final Node node = ((DataObject)obj).getNodeDelegate ();
77
            final Action a = node.getPreferredAction();
78
            if (a != null) {
79
                SwingUtilities.invokeLater(new Runnable() {
80
                    public void run() {
81
                        a.actionPerformed(new ActionEvent(node, ActionEvent.ACTION_PERFORMED, "")); // NOI18N
82
                    }
83
                });
84
            }
67
        }
85
        }
68
        catch ( IOException e ) {
86
        catch ( IOException e ) {
69
            // XXX
87
            // XXX
(-)projects/projectui/src/org/netbeans/modules/project/ui/actions/NewProject.java (-17 / +60 lines)
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
}
(-)java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/wizards/NewJ2SEProjectWizardIterator.java (-7 / +31 lines)
Lines 17-22 Link Here
17
import java.io.File;
17
import java.io.File;
18
import java.io.IOException;
18
import java.io.IOException;
19
import java.util.Collections;
19
import java.util.Collections;
20
import java.util.HashSet;
20
import java.util.NoSuchElementException;
21
import java.util.NoSuchElementException;
21
import java.util.Set;
22
import java.util.Set;
22
import javax.swing.JComponent;
23
import javax.swing.JComponent;
Lines 25-30 Link Here
25
import org.netbeans.api.project.ProjectManager;
26
import org.netbeans.api.project.ProjectManager;
26
import org.netbeans.modules.java.j2seproject.J2SEProjectGenerator;
27
import org.netbeans.modules.java.j2seproject.J2SEProjectGenerator;
27
import org.netbeans.spi.project.support.ant.AntProjectHelper;
28
import org.netbeans.spi.project.support.ant.AntProjectHelper;
29
import org.netbeans.spi.project.support.ant.EditableProperties;
28
import org.openide.WizardDescriptor;
30
import org.openide.WizardDescriptor;
29
import org.openide.filesystems.FileObject;
31
import org.openide.filesystems.FileObject;
30
import org.openide.filesystems.FileUtil;
32
import org.openide.filesystems.FileUtil;
Lines 37-43 Link Here
37
 * Wizard to create a new J2SE project.
39
 * Wizard to create a new J2SE project.
38
 * @author Jesse Glick
40
 * @author Jesse Glick
39
 */
41
 */
40
public class NewJ2SEProjectWizardIterator implements TemplateWizard.Iterator {
42
public class NewJ2SEProjectWizardIterator implements WizardDescriptor.InstantiatingIterator {
41
43
42
    static final int TYPE_APP = 0;
44
    static final int TYPE_APP = 0;
43
    static final int TYPE_LIB = 1;
45
    static final int TYPE_LIB = 1;
Lines 102-108 Link Here
102
    }
104
    }
103
    
105
    
104
    
106
    
105
    public Set/*<DataObject>*/ instantiate(TemplateWizard wiz) throws IOException/*, IllegalStateException*/ {
107
    public Set/*<FileObject>*/ instantiate () throws IOException/*, IllegalStateException*/ {
108
        Set resultSet = new HashSet ();
106
        File dirF = (File)wiz.getProperty("projdir");
109
        File dirF = (File)wiz.getProperty("projdir");
107
        String codename = (String)wiz.getProperty("codename");
110
        String codename = (String)wiz.getProperty("codename");
108
        String displayName = (String)wiz.getProperty("displayName");
111
        String displayName = (String)wiz.getProperty("displayName");
Lines 116-137 Link Here
116
            J2SEProjectGenerator.createProject(dirF, codename, displayName, sourceFolder, testFolder );
119
            J2SEProjectGenerator.createProject(dirF, codename, displayName, sourceFolder, testFolder );
117
        }
120
        }
118
        else {
121
        else {
119
            J2SEProjectGenerator.createProject(dirF, codename, displayName, mainClass );
122
            AntProjectHelper h = J2SEProjectGenerator.createProject(dirF, codename, displayName, mainClass );
123
            try {
124
                //String sourceRoot = "src"; //(String)j2seProperties.get (J2SEProjectProperties.SRC_DIR);
125
                FileObject sourcesRoot = h.getProjectDirectory ().getFileObject ("src");
126
                FileObject mainClassFo = getMainClassFO (sourcesRoot, mainClass);
127
                resultSet.add (mainClassFo);
128
            } catch (Exception x) {
129
                // XXX
130
                x.printStackTrace();
131
            }
120
        }
132
        }
121
        FileObject dir = FileUtil.toFileObject(dirF);
133
        FileObject dir = FileUtil.toFileObject(dirF);
122
        Project p = ProjectManager.getDefault().findProject(dir);
134
        Project p = ProjectManager.getDefault().findProject(dir);
123
        
135
        
124
        // Returning set of DataObject of project diretory. 
136
        // Returning set of DataObject of project diretory. 
125
        // Project will be open and set as main
137
        // Project will be open and set as main
126
        return Collections.singleton(DataObject.find(dir));
138
        resultSet.add (dir);
139
        return resultSet;
127
    }
140
    }
128
    
141
    
129
        
142
        
130
    private transient int index;
143
    private transient int index;
131
    private transient WizardDescriptor.Panel[] panels;
144
    private transient WizardDescriptor.Panel[] panels;
132
    private transient TemplateWizard wiz;
145
    private transient WizardDescriptor wiz;
133
    
146
    
134
    public void initialize(TemplateWizard wiz) {
147
    public void initialize(WizardDescriptor wiz) {
135
        this.wiz = wiz;
148
        this.wiz = wiz;
136
        index = 0;
149
        index = 0;
137
        panels = createPanels();
150
        panels = createPanels();
Lines 154-160 Link Here
154
            }
167
            }
155
        }
168
        }
156
    }
169
    }
157
    public void uninitialize(TemplateWizard wiz) {
170
    public void uninitialize(WizardDescriptor wiz) {
158
        this.wiz = null;
171
        this.wiz = null;
159
        panels = null;
172
        panels = null;
160
    }
173
    }
Lines 184-189 Link Here
184
    // If nothing unusual changes in the middle of the wizard, simply:
197
    // If nothing unusual changes in the middle of the wizard, simply:
185
    public final void addChangeListener(ChangeListener l) {}
198
    public final void addChangeListener(ChangeListener l) {}
186
    public final void removeChangeListener(ChangeListener l) {}
199
    public final void removeChangeListener(ChangeListener l) {}
200
    
201
    // helper methods
202
    private FileObject getMainClassFO (FileObject sourcesRoot, String mainClass) {
203
        // replace '.' with '/'
204
        mainClass = mainClass.replace ('.', File.separatorChar); // XXX // NOI18N
205
        // find mainclass's FileObject
206
        FileObject mainFO = sourcesRoot.getFileObject (mainClass, "java"); // XXX // NOI18N
207
        // check MainClassChooser.hasMainMethod (mainFO);
208
        // ignore unvalid mainClass
209
        return mainFO;
210
    }
187
    // If something changes dynamically (besides moving between panels),
211
    // If something changes dynamically (besides moving between panels),
188
    // e.g. the number of panels changes in response to user input, then
212
    // e.g. the number of panels changes in response to user input, then
189
    // uncomment the following and call when needed:
213
    // uncomment the following and call when needed:

Return to bug 42870