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 61546
Collapse All | Expand All

(-)projects/projectuiapi/src/org/netbeans/spi/project/ui/support/CommonProjectActions.java (+42 lines)
Lines 113-118 Link Here
113
    }
113
    }
114
114
115
    /**
115
    /**
116
     * Create an action "Copy Project".
117
     * It should be invoked with an action context containing
118
     * one or more {@link org.netbeans.api.project.Project}s.
119
     * <p class="nonnormative">
120
     * You might include this in the context menu of a logical view.
121
     * </p>
122
     * @since 1.10
123
     * @return an action
124
     */
125
    public static Action copyProjectAction() {
126
        return Utilities.getActionsFactory().copyProjectAction();
127
    }
128
    
129
    /**
130
     * Create an action "Move Project".
131
     * It should be invoked with an action context containing
132
     * one or more {@link org.netbeans.api.project.Project}s.
133
     * <p class="nonnormative">
134
     * You might include this in the context menu of a logical view.
135
     * </p>
136
     * @since 1.10
137
     * @return an action
138
     */
139
    public static Action moveProjectAction() {
140
        return Utilities.getActionsFactory().moveProjectAction();
141
    }
142
    
143
    /**
144
     * Create an action "Rename Project".
145
     * It should be invoked with an action context containing
146
     * one or more {@link org.netbeans.api.project.Project}s.
147
     * <p class="nonnormative">
148
     * You might include this in the context menu of a logical view.
149
     * </p>
150
     * @since 1.10
151
     * @return an action
152
     */
153
    public static Action renameProjectAction() {
154
        return Utilities.getActionsFactory().renameProjectAction();
155
    }
156
    
157
    /**
116
     * Creates action that invokes <b>New Project</b> wizard.
158
     * Creates action that invokes <b>New Project</b> wizard.
117
     * 
159
     * 
118
     * <p>{@link #EXISTING_SOURCES_FOLDER} keyed action
160
     * <p>{@link #EXISTING_SOURCES_FOLDER} keyed action
(-)projects/projectuiapi/src/org/netbeans/spi/project/ui/support/DefaultProjectOperations.java (+130 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-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
package org.netbeans.spi.project.ui.support;
14
15
import org.netbeans.api.project.Project;
16
import org.netbeans.spi.project.support.ProjectOperations;
17
import org.netbeans.modules.project.uiapi.DefaultProjectOperationsImplementation;
18
19
/**Support class to allow the project type implementors to perform {@link ProjectOperations}
20
 * by simply calling a method in this class. Each method in this class provides a default
21
 * confirmation dialog and default behavior.
22
 *
23
 * If the project type requires a different behavior of an operation, it is required to provide its
24
 * own implementation of the operation.
25
 *
26
 * @since 1.10
27
 * @author Jan Lahoda
28
 */
29
public final class DefaultProjectOperations {
30
    
31
    /**
32
     * Creates a new instance of DefaultProjectOperations
33
     */
34
    private DefaultProjectOperations() {
35
    }
36
    
37
    /**Perform default delete operation. Gathers all necessary data, shows a confirmation
38
     * dialog and deletes the project (if confirmed by the user).
39
     *
40
     * @since 1.10
41
     *
42
     * @param p project to delete
43
     * @throws IllegalArgumentException if
44
     * <code>p == null</code> or
45
     * if {@link org.netbeans.api.projects.ProjectOperations.isDeleteOperationSupported}
46
     * returns false for this project.
47
     */
48
    public static void performDefaultDeleteOperation(Project p) throws IllegalArgumentException {
49
        if (p == null) {
50
            throw new IllegalArgumentException("Project is null");
51
        }
52
        
53
        if (!ProjectOperations.isDeleteOperationSupported(p)) {
54
            throw new IllegalStateException("Attempt to delete project that does not support deletion.");
55
        }
56
        
57
        DefaultProjectOperationsImplementation.deleteProject(p);
58
    }
59
    
60
    /**Perform default copy operation. Gathers all necessary data, shows a confirmation
61
     * dialog and copies the project (if confirmed by the user).
62
     *
63
     * @since 1.10
64
     *
65
     * @param p project to copy
66
     * @throws IllegalArgumentException if
67
     * <code>p == null</code> or
68
     * {@link org.netbeans.api.projects.ProjectOperations.isCopyOperationSupported}
69
     * returns false for this project.
70
     */
71
    public static void performDefaultCopyOperation(Project p) throws IllegalArgumentException {
72
        if (p == null) {
73
            throw new IllegalArgumentException("Project is null");
74
        }
75
        
76
        if (!ProjectOperations.isCopyOperationSupported(p)) {
77
            throw new IllegalStateException("Attempt to delete project that does not support copy.");
78
        }
79
        
80
        DefaultProjectOperationsImplementation.copyProject(p);
81
    }
82
    
83
    /**Perform default move operation. Gathers all necessary data, shows a confirmation
84
     * dialog and moves the project (if confirmed by the user).
85
     *
86
     * @since 1.10
87
     *
88
     * @param p project to move
89
     * @throws IllegalArgumentException if
90
     * <code>p == null</code> or
91
     * {@link org.netbeans.api.projects.ProjectOperations.ismoveOperationSupported}
92
     * returns false for this project.
93
     */
94
    public static void performDefaultMoveOperation(Project p) throws IllegalArgumentException {
95
        if (p == null) {
96
            throw new IllegalArgumentException("Project is null");
97
        }
98
        
99
        if (!ProjectOperations.isMoveOperationSupported(p)) {
100
            throw new IllegalStateException("Attempt to delete project that does not support move.");
101
        }
102
        
103
        DefaultProjectOperationsImplementation.moveProject(p);
104
    }
105
    
106
    /**Perform default rename operation. Gathers all necessary data, shows a confirmation
107
     * dialog and renames the project (if confirmed by the user).
108
     *
109
     * @since 1.10
110
     *
111
     * @param p project to move
112
     * @param newName new project's name or null
113
     * @throws IllegalArgumentException if
114
     * <code>p == null</code> or
115
     * {@link org.netbeans.api.projects.ProjectOperations.ismoveOperationSupported}
116
     * returns false for this project.
117
     */
118
    public static void performDefaultRenameOperation(Project p, String newName) throws IllegalStateException {
119
        if (p == null) {
120
            throw new IllegalArgumentException("Project is null");
121
        }
122
        
123
        if (!ProjectOperations.isMoveOperationSupported(p)) {
124
            throw new IllegalStateException("Attempt to delete project that does not support move.");
125
        }
126
        
127
        DefaultProjectOperationsImplementation.renameProject(p, newName);
128
    }
129
    
130
}
(-)ant/project/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java (-22 / +1 lines)
Lines 29-35 Link Here
29
import org.netbeans.api.project.ProjectManager;
29
import org.netbeans.api.project.ProjectManager;
30
import org.netbeans.api.project.ant.AntArtifact;
30
import org.netbeans.api.project.ant.AntArtifact;
31
import org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton;
31
import org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton;
32
import org.netbeans.modules.project.ant.DefaultAntProjectOperations;
33
import org.netbeans.modules.project.ant.FileChangeSupport;
32
import org.netbeans.modules.project.ant.FileChangeSupport;
34
import org.netbeans.modules.project.ant.FileChangeSupportEvent;
33
import org.netbeans.modules.project.ant.FileChangeSupportEvent;
35
import org.netbeans.modules.project.ant.FileChangeSupportListener;
34
import org.netbeans.modules.project.ant.FileChangeSupportListener;
Lines 38-44 Link Here
38
import org.netbeans.spi.project.AuxiliaryConfiguration;
37
import org.netbeans.spi.project.AuxiliaryConfiguration;
39
import org.netbeans.spi.project.CacheDirectoryProvider;
38
import org.netbeans.spi.project.CacheDirectoryProvider;
40
import org.netbeans.spi.project.ProjectState;
39
import org.netbeans.spi.project.ProjectState;
41
import org.netbeans.api.project.ProjectOperations;
40
import org.netbeans.spi.project.support.ProjectOperations;
42
import org.netbeans.spi.queries.FileBuiltQueryImplementation;
41
import org.netbeans.spi.queries.FileBuiltQueryImplementation;
43
import org.netbeans.spi.queries.SharabilityQueryImplementation;
42
import org.netbeans.spi.queries.SharabilityQueryImplementation;
44
import org.openide.ErrorManager;
43
import org.openide.ErrorManager;
Lines 482-507 Link Here
482
        state.notifyDeleted();
481
        state.notifyDeleted();
483
    }
482
    }
484
    
483
    
485
    /**Perform default delete operation. Gathers all necessary data, shows a confirmation
486
     * dialog and deletes the project (if confirmed by the user).
487
     *
488
     * @since 1.8
489
     *
490
     * @throws IllegalStateException if
491
     * {@link org.netbeans.api.projects.ProjectOperations.getDefault().isDeleteOperationSupported}
492
     * returns false for this project.
493
     */
494
    public void performDefaultDeleteOperation() throws IllegalStateException {
495
        Project p = AntBasedProjectFactorySingleton.getProjectFor(this);
496
        
497
        assert p != null;
498
        
499
        if (!ProjectOperations.getDefault().isDeleteOperationSupported(p)) {
500
            throw new IllegalStateException("Attempt to delete project that does not support deletion.");
501
        }
502
        
503
        DefaultAntProjectOperations.deleteProject(p);
504
    }
505
    
484
    
506
    /**
485
    /**
507
     * Mark this project as being modified without actually changing anything in it.
486
     * Mark this project as being modified without actually changing anything in it.
(-)ant/project/src/org/netbeans/spi/project/support/ant/ReferenceHelper.java (+87 lines)
Lines 19-25 Link Here
19
import java.net.URISyntaxException;
19
import java.net.URISyntaxException;
20
import java.util.ArrayList;
20
import java.util.ArrayList;
21
import java.util.Arrays;
21
import java.util.Arrays;
22
import java.util.Collection;
22
import java.util.Collections;
23
import java.util.Collections;
24
import java.util.HashMap;
23
import java.util.HashSet;
25
import java.util.HashSet;
24
import java.util.Iterator;
26
import java.util.Iterator;
25
import java.util.List;
27
import java.util.List;
Lines 1229-1234 Link Here
1229
     */
1231
     */
1230
    AntProjectHelper getAntProjectHelper() {
1232
    AntProjectHelper getAntProjectHelper() {
1231
        return h;
1233
        return h;
1234
    }
1235
    
1236
    /**Tries to fix references after copy/rename/move operation on the project.
1237
     * Handles relative/absolute paths.
1238
     *
1239
     * @param originalPath the project folder of the original project
1240
     * @see org.netbeans.spi.project.CopyOperationImplementation
1241
     * @see org.netbeans.spi.project.MoveOperationImplementation
1242
     * @since 1.9
1243
     */
1244
    public void fixReferences(File originalPath) {
1245
        String[] prefixesToFix = new String[] {"file.reference.", "project."};
1246
        EditableProperties pub  = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
1247
        EditableProperties priv = h.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
1248
        
1249
        File projectDir = FileUtil.toFile(h.getProjectDirectory());
1250
        
1251
        List pubRemove = new ArrayList();
1252
        List privRemove = new ArrayList();
1253
        Map pubAdd = new HashMap();
1254
        Map privAdd = new HashMap();
1255
        
1256
        for (Iterator i = pub.entrySet().iterator(); i.hasNext(); ) {
1257
            Map.Entry e    = (Map.Entry) i.next();
1258
            String    key  = (String) e.getKey();
1259
            boolean   cont = false;
1260
            
1261
            for (int cntr = 0; cntr < prefixesToFix.length; cntr++) {
1262
                if (key.startsWith(prefixesToFix[cntr])) {
1263
                    cont = true;
1264
                    break;
1265
                }
1266
            }
1267
            if (!cont)
1268
                continue;
1269
            
1270
            String    value = (String) e.getValue();
1271
            
1272
            File absolutePath = FileUtil.normalizeFile(PropertyUtils.resolveFile(originalPath, value));
1273
            
1274
            //TODO: extra base dir relativization:
1275
            if (!CollocationQuery.areCollocated(absolutePath, projectDir)) {
1276
                pubRemove.add(key);
1277
                privAdd.put(key, absolutePath.getAbsolutePath());
1278
            }
1279
        }
1280
        
1281
        for (Iterator i = priv.entrySet().iterator(); i.hasNext(); ) {
1282
            Map.Entry e    = (Map.Entry) i.next();
1283
            String    key  = (String) e.getKey();
1284
            boolean   cont = false;
1285
            
1286
            for (int cntr = 0; cntr < prefixesToFix.length; cntr++) {
1287
                if (key.startsWith(prefixesToFix[cntr])) {
1288
                    cont = true;
1289
                    break;
1290
                }
1291
            }
1292
            if (!cont)
1293
                continue;
1294
            
1295
            String    value = (String) e.getValue();
1296
            
1297
            File absolutePath = FileUtil.normalizeFile(PropertyUtils.resolveFile(originalPath, value));
1298
            
1299
            //TODO: extra base dir relativization:
1300
            if (CollocationQuery.areCollocated(absolutePath, projectDir)) {
1301
                privRemove.add(key);
1302
                pubAdd.put(key, PropertyUtils.relativizeFile(projectDir, absolutePath));
1303
            }
1304
        }
1305
        
1306
        for (Iterator i = pubRemove.iterator(); i.hasNext(); ) {
1307
            pub.remove(i.next());
1308
        }
1309
        
1310
        for (Iterator i = privRemove.iterator(); i.hasNext(); ) {
1311
            priv.remove(i.next());
1312
        }
1313
        
1314
        pub.putAll(pubAdd);
1315
        priv.putAll(privAdd);
1316
        
1317
        h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, pub);
1318
        h.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, priv);
1232
    }
1319
    }
1233
    
1320
    
1234
    /**
1321
    /**
(-)ant/project/apichanges.xml (-4 / +3 lines)
Lines 78-91 Link Here
78
78
79
        <change id="delete-support">
79
        <change id="delete-support">
80
            <api name="general"/>
80
            <api name="general"/>
81
            <summary>Basic Support SPI for Project Delete</summary>
81
            <summary>Basic Support SPI for Project Delete/Copy/Rename/Move</summary>
82
            <version major="1" minor="8"/>
82
            <version major="1" minor="9"/>
83
            <date day="11" month="7" year="2005"/>
83
            <date day="11" month="7" year="2005"/>
84
            <author login="jlahoda"/>
84
            <author login="jlahoda"/>
85
            <compatibility addition="yes"/>
85
            <compatibility addition="yes"/>
86
            <description>
86
            <description>
87
                <code>AntProjectHelper.notifyDeleted()</code> and <code>AntProjectHelper.performDefaultDeleteOperation()</code>
87
                Added <code>AntProjectHelper.notifyDeleted()</code>. Added <code>ReferenceHelper.fixReferences</code>.
88
                added.
89
            </description>
88
            </description>
90
            <issue number="51468"/>
89
            <issue number="51468"/>
91
        </change>
90
        </change>
(-)ant/project/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.project.ant/1
2
OpenIDE-Module: org.netbeans.modules.project.ant/1
3
OpenIDE-Module-Specification-Version: 1.8
3
OpenIDE-Module-Specification-Version: 1.9
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/ant/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/ant/Bundle.properties
5
5
(-)projects/projectapi/apichanges.xml (-18 / +19 lines)
Lines 76-106 Link Here
76
76
77
    <changes>
77
    <changes>
78
78
79
        <change id="delete-support">
79
        <change id="copy-move-support">
80
            <api name="general"/>
80
            <api name="general"/>
81
            <summary>Support for project delete</summary>
81
            <summary>Added support for project delete/copy/rename/move</summary>
82
            <version major="1" minor="6"/>
82
            <version major="1" minor="7"/>
83
            <date day="11" month="7" year="2005"/>
83
            <date day="26" month="7" year="2005"/>
84
            <author login="jlahoda"/>
84
            <author login="jlahoda"/>
85
            <compatibility>
85
            <compatibility addition="true" binary="true" deletion="false" deprecation="false" modification="false" semantic="false" source="true">
86
                <p>
87
                    As only the ProjectManager is allowed to implement ProjectState interface,
88
                    this change should not directly affect any clients.
89
                </p>
90
            </compatibility>
86
            </compatibility>
91
            <description>
87
            <description>
92
                <p>
88
                <p>
93
                    The <code>notifyDeleted</code> action is added to the <code>ProjectState</code>,
89
                    Introduced:
94
                    allowing the project implmentation to let the <code>ProjectManager</code>
90
                    <ul>
95
                    know that the project has been deleted. <code>ProjectManager.isValid(Project)</code> added
91
                        <li>
96
		    to detect deleted projects.
92
                            New method <code>notifyDeleted</code> added to <code>ProjectState</code>.
97
                </p>
93
                        </li>
98
                <p>
94
                        <li>
99
                    <code>ProjectOperations</code> and <code>ProjectOperationsImplementation</code> added to support
95
                            Interfaces DataFilesProviderImplementation, DeleteOperationImplementation, CopyOperationImplementation, MoveOperationImplementation has
100
                    project delete operation.
96
                            been added to support project delete/copy/rename/move.
97
                        </li>
98
                        <li>
99
                            Support class ProjectOperations has been added to simplify operations on compound projects.
100
                        </li>
101
                    </ul>
101
                </p>
102
                </p>
102
            </description>
103
            </description>
103
            <issue number="51468"/>
104
            <issue number="TODO"/>
104
        </change>
105
        </change>
105
        
106
        
106
        <change id="markExternal-for-file-and-URIs">
107
        <change id="markExternal-for-file-and-URIs">
(-)projects/projectapi/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.projectapi/1
2
OpenIDE-Module: org.netbeans.modules.projectapi/1
3
OpenIDE-Module-Specification-Version: 1.6
3
OpenIDE-Module-Specification-Version: 1.7
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/projectapi/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/projectapi/Bundle.properties
5
5
(-)projects/projectapi/src/org/netbeans/api/project/ProjectOperations.java (-134 lines)
Removed 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-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.api.project;
15
16
import java.io.IOException;
17
import java.util.ArrayList;
18
import java.util.Collection;
19
import java.util.Iterator;
20
import java.util.List;
21
import org.netbeans.spi.project.ProjectOperationsImplementation.DataFilesProviderImplementation;
22
import org.netbeans.spi.project.ProjectOperationsImplementation.DeleteOperationImplementation;
23
import org.openide.util.Lookup;
24
25
/**Allows gathering information for vaious project operations (currently only project delete, but will
26
 * be extended in the future).
27
 *
28
 * <p><b><font size=+1>Project Delete Operation</font></b>
29
 *
30
 * Consists of {@link #getMetadataFiles(Project) getMetadataFiles},
31
 * {@link #getDataFiles(Project) getDataFiles}, {@link #performClean(Project) performClean}
32
 * and {@link #notifyDeleted(Project) notifyDeleted}.
33
 *
34
 * The delete operation should run in two phases: preparation, when
35
 * {@link #getMetadataFiles(Project) getMetadataFiles} and {@link #getDataFiles(Project) getDataFiles}
36
 * (any number of times,
37
 * in any order) are called and performing, when {@link #performClean(Project) performClean} should be called,
38
 * then the files previously returned should be deleted (as required by the user)
39
 * and finally {@link #notifyDeleted(Project) notifyDeleted} should be called.
40
 *
41
 * @since  1.6
42
 * @author Jan Lahoda
43
 */
44
public final class ProjectOperations {
45
    
46
    private static ProjectOperations INSTANCE = null;
47
    
48
    public static synchronized ProjectOperations getDefault() {
49
        if (INSTANCE == null) {
50
            INSTANCE = new ProjectOperations();
51
        }
52
        
53
        return INSTANCE;
54
    }
55
    
56
    private ProjectOperations() {
57
    }
58
    
59
    /**Return list of files that are considered metadata files and folders for the given project.
60
     * Returns meaningfull values only if some of the <code>is*Supported</code> methods
61
     * return <code>true</code>.
62
     *
63
     * @param prj project to test
64
     * @return list of metadata files/folders
65
     */
66
    public List/*<FileObject>*/ getMetadataFiles(Project prj) {
67
        List/*<FileObject>*/ result = new ArrayList();
68
        
69
        for (Iterator i = getProjectsOperationsImplementation(prj).iterator(); i.hasNext(); ) {
70
            result.addAll(((DataFilesProviderImplementation) i.next()).getMetadataFiles());
71
        }
72
        
73
        return result;
74
    }
75
            
76
    /**Return list of files that are considered source files and folders for the given project.
77
     * Returns meaningfull values only if some of the <code>is*Supported</code> methods
78
     * return <code>true</code>.
79
     *
80
     * @param prj project to test
81
     * @return list of data files/folders
82
     */
83
    public List/*<FileObject>*/ getDataFiles(Project prj) {
84
        List/*<FileObject>*/ result = new ArrayList();
85
        
86
        for (Iterator i = getProjectsOperationsImplementation(prj).iterator(); i.hasNext(); ) {
87
            result.addAll(((DataFilesProviderImplementation) i.next()).getDataFiles());
88
        }
89
        
90
        return result;
91
    }
92
    
93
    /**Test whether the delete operation is supported on the given project.
94
     *
95
     * 
96
     * @param prj project to test
97
     * @return <code>true</code> if the project supports delete operation,
98
     *         <code>false</code> otherwise
99
     */
100
    public boolean isDeleteOperationSupported(Project prj) {
101
        return !getDeleteOperationImplementation(prj).isEmpty();
102
    }
103
    
104
    /**Performs pre-delete clean of the project. Should be called immediatelly before
105
     * the project is deleted.
106
     *
107
     * @param prj project to clean
108
     */
109
    public void performClean(Project prj) throws IOException {
110
        for (Iterator i = getDeleteOperationImplementation(prj).iterator(); i.hasNext(); ) {
111
            ((DeleteOperationImplementation) i.next()).performClean();
112
        }
113
    }
114
    
115
    /**Post-delete notification that the project has been deleted.. Should be called immediatelly after
116
     * the project is deleted.
117
     *
118
     * @param prj deleted project
119
     */
120
    public void notifyDeleted(Project prj) throws IOException {
121
        for (Iterator i = getDeleteOperationImplementation(prj).iterator(); i.hasNext(); ) {
122
            ((DeleteOperationImplementation) i.next()).notifyDeleted();
123
        }
124
    }
125
    
126
    private Collection/*<DeleteOperationImplementation>*/ getDeleteOperationImplementation(Project prj) {
127
        return prj.getLookup().lookup(new Lookup.Template(DeleteOperationImplementation.class)).allInstances();
128
    }
129
    
130
    private Collection/*<DataFilesProviderImplementation>*/ getProjectsOperationsImplementation(Project prj) {
131
        return prj.getLookup().lookup(new Lookup.Template(DataFilesProviderImplementation.class)).allInstances();
132
    }
133
    
134
}
(-)projects/projectapi/src/org/netbeans/spi/project/ActionProvider.java (+21 lines)
Lines 94-99 Link Here
94
    String COMMAND_DELETE = "delete"; // NOI18N
94
    String COMMAND_DELETE = "delete"; // NOI18N
95
    
95
    
96
    /**
96
    /**
97
     * Standard command for deleting the project.
98
     *
99
     * @since 1.7
100
     */
101
    String COMMAND_COPY = "copy"; // NOI18N
102
    
103
    /**
104
     * Standard command for deleting the project.
105
     *
106
     * @since 1.7
107
     */
108
    String COMMAND_MOVE = "move"; // NOI18N
109
110
    /**
111
     * Standard command for deleting the project.
112
     *
113
     * @since 1.7
114
     */
115
    String COMMAND_RENAME = "rename"; // NOI18N
116
    
117
    /**
97
     * Get a list of all commands which this project supports.
118
     * Get a list of all commands which this project supports.
98
     * @return a list of command names suitable for {@link #invokeAction}
119
     * @return a list of command names suitable for {@link #invokeAction}
99
     * @see #COMMAND_BUILD
120
     * @see #COMMAND_BUILD
(-)projects/projectapi/src/org/netbeans/spi/project/CopyOperationImplementation.java (+64 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-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
package org.netbeans.spi.project;
14
15
import java.io.File;
16
import java.io.IOException;
17
import org.netbeans.api.project.Project;
18
19
/**
20
 * Project Copy Operation. Allows to gather information necessary for project
21
 * copy and also provides callbacks to the project type to handle special
22
 * checkpoints during the copy process.
23
 *
24
 * An implementation of this interface may be registered in the project's lookup to support
25
 * copy operation in the following cases:
26
 * <ul>
27
 *     <li>The project type wants to use the {@link org.netbeans.spi.project.ui.support DefaultProjectOperationsImplementation}
28
 *         to perform the copy operation.
29
 *    </li>
30
 *    <li>If this project may be part of of a compound project (like EJB project is a part of a J2EE project),
31
 *        and the compound project wants to copy all the sub-projects.
32
 *    </li>
33
 * </ul>
34
 *
35
 * The project type is not required to put an implementation of this interface into the project's
36
 * lookup if the above two cases should not be supported.
37
 *
38
 * @author Jan Lahoda
39
 * @since 1.7
40
 */
41
public interface CopyOperationImplementation extends DataFilesProviderImplementation {
42
    
43
    /**Pre-copy notification. The exact meaning is left on the project implementors, but
44
     * typically this means to undeloy the application and remove all artifacts
45
     * created by the build project.
46
     *
47
     * @throws IOException if an I/O operation fails.
48
     */
49
    public void notifyCopying() throws IOException;
50
    
51
    /**Notification that the copy operation has finished. Is supposed to fix the
52
     * newly created (copied) project into the correct state (including changing its display name
53
     * to nueName). Should be called on both original and newly created project (in this order).
54
     *
55
     * @param original the original project
56
     * @param originalPath the project folder of the original project (for consistency
57
     *                     with MoveOperationImplementation.notifyMoved)
58
     * @param nueName new name for the newly created project.
59
     *
60
     * @throws IOException if an I/O operation fails.
61
     */
62
    public void notifyCopied(Project original, File originalPath, String nueName)  throws IOException;
63
    
64
}
(-)projects/projectapi/src/org/netbeans/spi/project/DataFilesProviderImplementation.java (+45 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-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
package org.netbeans.spi.project;
14
15
import java.util.List;
16
import org.openide.filesystems.FileObject;
17
18
/**
19
 * Base for various Project Operations, allows to gather metadata and data files
20
 * for a project.
21
 *
22
 * @author Jan Lahoda
23
 * @since 1.7
24
 */
25
public interface DataFilesProviderImplementation {
26
    
27
    /**
28
     * Returns list of {@link FileObject}s the are considered to be metadata files
29
     * and folders belonging into this project.
30
     * See {@link ProjectOperations#getMetadataFiles()} for more information.
31
     *
32
     * @return list of {@link FileObject}s that are considered metadata files and folders.
33
     */
34
    public List/*<FileObject>*/ getMetadataFiles();
35
    
36
    /**
37
     * Returns list of {@link FileObject}s the are considered to be data files and folders
38
     * belonging into this project.
39
     * See {@link ProjectOperations#getDataFiles()} for more information.
40
     *
41
     * @return list of {@link FileObject}s that are considered data files and folders.
42
     */
43
    public List/*<FileObject>*/ getDataFiles();
44
    
45
}
(-)projects/projectapi/src/org/netbeans/spi/project/DeleteOperationImplementation.java (+56 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-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
package org.netbeans.spi.project;
14
15
import java.io.IOException;
16
17
/**
18
 * Project Delete Operation. Allows to gather information necessary for project
19
 * delete and also provides callbacks to the project type to handle special
20
 * checkpoints during the delete.
21
 *
22
 * An implementation of this interface may be registered in the project's lookup to support
23
 * delete operation in the following cases:
24
 * <ul>
25
 *     <li>The project type wants to use the {@link org.netbeans.spi.project.ui.support.DefaultProjectOperationsImplementation}
26
 *         to perform the delete operation.
27
 *    </li>
28
 *    <li>If this project may be part of of a compound project (like EJB project is a part of a J2EE project),
29
 *        and the compound project wants to delete all the sub-projects.
30
 *    </li>
31
 * </ul>
32
 *
33
 * The project type is not required to put an implementation of this interface into the project's
34
 * lookup if the above two cases should not be supported.
35
 *
36
 * @author Jan Lahoda
37
 * @since 1.7
38
 */
39
public interface DeleteOperationImplementation extends DataFilesProviderImplementation {
40
    
41
    /**Pre-delete notification. The exact meaning is left on the project implementors, but
42
     * typically this means to undeloy the application and remove all artifacts
43
     * created by the build project.
44
     *
45
     * @throws IOException if an I/O operation fails.
46
     */
47
    public void notifyDeleting() throws IOException;
48
    
49
    /**Notification that the delete operation has finished. Is supposed to perform
50
     * final cleanup and to call {@link ProjectState#notifyDeleted}.
51
     *
52
     * @throws IOException if an I/O operation fails.
53
     */
54
    public void notifyDeleted() throws IOException;
55
56
}
(-)projects/projectapi/src/org/netbeans/spi/project/MoveOperationImplementation.java (+64 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-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
package org.netbeans.spi.project;
14
15
import java.io.File;
16
import java.io.IOException;
17
import org.netbeans.api.project.Project;
18
19
/**
20
 * Project Rename/Move Operation. Allows to gather information necessary for project
21
 * move and also provides callbacks to the project type to handle special
22
 * checkpoints during the delete.
23
 *
24
 * An implementation of this interface may be registered in the project's lookup to support
25
 * move operation in the following cases:
26
 * <ul>
27
 *     <li>The project type wants to use the {@link org.netbeans.spi.project.ui.support.DefaultProjectOperationsImplementation}
28
 *         to perform the rename/move operation.
29
 *    </li>
30
 *    <li>If this project may be part of of a compound project (like EJB project is a part of a J2EE project),
31
 *        and the compound project wants to rename/move all the sub-projects.
32
 *    </li>
33
 * </ul>
34
 *
35
 * The project type is not required to put an implementation of this interface into the project's
36
 * lookup if the above two cases should not be supported.
37
 *
38
 * @author Jan Lahoda
39
 * @since 1.7
40
 */
41
public interface MoveOperationImplementation extends DataFilesProviderImplementation {
42
    
43
    /**Pre-move notification. The exact meaning is left on the project implementors, but
44
     * typically this means to undeloy the application and remove all artifacts
45
     * created by the build project.
46
     *
47
     * @throws IOException if an I/O operation fails.
48
     */
49
    public void notifyMoving() throws IOException;
50
    
51
    /**Notification that the move operation has finished. Is supposed to fix the
52
     * newly created (moved) project into the correct state (including changing its display name
53
     * to nueName) and call {@link ProjectState#notifyDeleted} on the original project.
54
     * Should be called on both original and newly created project (in this order).
55
     *
56
     * @param original the original project
57
     * @param originalPath the project folder of the original project
58
     * @param nueName new name for the newly created project.
59
     *
60
     * @throws IOException if an I/O operation fails.
61
     */
62
    public void notifyMoved(Project original, File originalPath, String nueName) throws IOException;
63
    
64
}
(-)projects/projectapi/src/org/netbeans/spi/project/ProjectOperationsImplementation.java (-84 lines)
Removed 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-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.spi.project;
15
16
import java.io.IOException;
17
import java.util.List;
18
import org.netbeans.api.project.ProjectOperations;
19
20
/**This is only a scope class that holds several project operation interfaces.
21
 * See particular interface for more information:
22
 * <li>
23
 *     <ul>{@link DeleteOperationImplementation DeleteOperationImplementation}</ul>
24
 * </li>
25
 *
26
 * @since 1.6
27
 * @author Jan Lahoda
28
 */
29
public final class ProjectOperationsImplementation {
30
    
31
    /**
32
     * Base for various Project Operations, allows to gather metadata and data files
33
     * for a project.
34
     */
35
    public interface DataFilesProviderImplementation {
36
        
37
        /**
38
         * Returns list of {@link FileObject}s the are considered to be metadata files
39
         * and folders belonging into this project.
40
         * See {@link ProjectOperations#getMetadataFiles()} for more information.
41
         *
42
         * @return list of {@link FileObject}s that are considered metadata files and folders.
43
         */
44
        public List/*<FileObject>*/ getMetadataFiles();
45
        
46
        /**
47
         * Returns list of {@link FileObject}s the are considered to be data files and folders
48
         * belonging into this project.
49
         * See {@link ProjectOperations#getDataFiles()} for more information.
50
         *
51
         * @return list of {@link FileObject}s that are considered data files and folders.
52
         */
53
        public List/*<FileObject>*/ getDataFiles();
54
        
55
    }
56
    
57
    /**
58
     * Project Delete Operation. Allows to gather information necessary for project
59
     * delete and also provides callbacks to the project type to handle special
60
     * checkpoints during the delete.
61
     * 
62
     * An implementation of this interface should be registered in the project to support
63
     * delete operation.
64
     */
65
    public interface DeleteOperationImplementation extends DataFilesProviderImplementation {
66
        
67
        /**Pre-delete clean. The exact meaning is left on the project implementors, but
68
         * typically this means to undeloy the application and remove all artifacts
69
         * created by the build project.
70
         *
71
         * @throws IOException if an I/O operation fails.
72
         */
73
        public void performClean() throws IOException;
74
        
75
        /**Notification that the delete operation has finished. Is supposed to perform
76
         * final cleanup and to call {@link ProjectState#notifyDeleted}.
77
         *
78
         * @throws IOException if an I/O operation fails.
79
         */
80
        public void notifyDeleted() throws IOException;
81
        
82
    }
83
    
84
}
(-)projects/projectapi/src/org/netbeans/spi/project/support/ProjectOperations.java (+220 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-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.spi.project.support;
15
16
import java.io.File;
17
import java.io.IOException;
18
import java.util.ArrayList;
19
import java.util.Collection;
20
import java.util.Iterator;
21
import java.util.List;
22
import org.netbeans.api.project.Project;
23
import org.netbeans.spi.project.CopyOperationImplementation;
24
import org.netbeans.spi.project.DataFilesProviderImplementation;
25
import org.netbeans.spi.project.DeleteOperationImplementation;
26
import org.netbeans.spi.project.MoveOperationImplementation;
27
import org.openide.util.Lookup;
28
29
/**
30
 * Allows gathering information for various project operations.
31
 * 
32
 * @author Jan Lahoda
33
 * @since 1.7
34
 */
35
public final class ProjectOperations {
36
    
37
    private ProjectOperations() {
38
    }
39
    
40
    /**Return list of files that are considered metadata files and folders for the given project.
41
     * Returns meaningfull values only if some of the <code>is*Supported</code> methods
42
     * return <code>true</code>.
43
     *
44
     * @param prj project to test
45
     * @return list of metadata files/folders
46
     */
47
    public static List/*<FileObject>*/ getMetadataFiles(Project prj) {
48
        List/*<FileObject>*/ result = new ArrayList();
49
        
50
        for (Iterator i = getProjectsOperationsImplementation(prj).iterator(); i.hasNext(); ) {
51
            result.addAll(((DataFilesProviderImplementation) i.next()).getMetadataFiles());
52
        }
53
        
54
        return result;
55
    }
56
            
57
    /**Return list of files that are considered source files and folders for the given project.
58
     * Returns meaningfull values only if some of the <code>is*Supported</code> methods
59
     * return <code>true</code>.
60
     *
61
     * @param prj project to test
62
     * @return list of data files/folders
63
     */
64
    public static List/*<FileObject>*/ getDataFiles(Project prj) {
65
        List/*<FileObject>*/ result = new ArrayList();
66
        
67
        for (Iterator i = getProjectsOperationsImplementation(prj).iterator(); i.hasNext(); ) {
68
            result.addAll(((DataFilesProviderImplementation) i.next()).getDataFiles());
69
        }
70
        
71
        return result;
72
    }
73
    
74
    /**Test whether the delete operation is supported on the given project.
75
     * 
76
     * @param prj project to test
77
     * @return <code>true</code> if the project supports delete operation,
78
     *         <code>false</code> otherwise
79
     */
80
    public static boolean isDeleteOperationSupported(Project prj) {
81
        return !getDeleteOperationImplementation(prj).isEmpty();
82
    }
83
    
84
    /**Notification that the project is about to be deleted.
85
     * Should be called immediatelly before the project is deleted.
86
     *
87
     * The project is supposed to do all required cleanup to allow the project to be deleted.
88
     *
89
     * @param prj project to notify
90
     * @throws IOException is some error occurs
91
     */
92
    public static void notifyDeleting(Project prj) throws IOException {
93
        for (Iterator i = getDeleteOperationImplementation(prj).iterator(); i.hasNext(); ) {
94
            ((DeleteOperationImplementation) i.next()).notifyDeleting();
95
        }
96
    }
97
    
98
    /**Notification that the project has been deleted.
99
     * Should be called immediatelly after the project is deleted.
100
     *
101
     * @param prj project to notify
102
     * @throws IOException is some error occurs
103
     */
104
    public static void notifyDeleted(Project prj) throws IOException {
105
        for (Iterator i = getDeleteOperationImplementation(prj).iterator(); i.hasNext(); ) {
106
            ((DeleteOperationImplementation) i.next()).notifyDeleted();
107
        }
108
    }
109
    
110
    /**Test whether the copy operation is supported on the given project.
111
     * 
112
     * @param prj project to test
113
     * @return <code>true</code> if the project supports the copy operation,
114
     *         <code>false</code> otherwise
115
     */
116
    public static boolean isCopyOperationSupported(Project prj) {
117
        return !getCopyOperationImplementation(prj).isEmpty();
118
    }
119
    
120
    /**Notification that the project is about to be copyied.
121
     * Should be called immediatelly before the project is copied.
122
     *
123
     * The project is supposed to do all required cleanup to allow the project to be copied.
124
     *
125
     * @param prj project to notify
126
     * @throws IOException is some error occurs
127
     */
128
    public static void notifyCopying(Project prj) throws IOException {
129
        for (Iterator i = getCopyOperationImplementation(prj).iterator(); i.hasNext(); ) {
130
            ((CopyOperationImplementation) i.next()).notifyCopying();
131
        }
132
    }
133
    
134
    /**Notification that the project has been copied.
135
     * Should be called immediatelly after the project is copied.
136
     *
137
     * The project is supposed to do all necessary fixes to the project's structure to
138
     * form a valid project.
139
     *
140
     * Both original and newly created project (copy) are notified, in this order.
141
     *
142
     * @param original original project
143
     * @param nue      new project (copy)
144
     * @param originalPath the project folder of the original project (for consistency with notifyMoved)
145
     * @param name     new name of the project
146
     * @throws IOException is some error occurs
147
     */
148
    public static void notifyCopied(Project original, Project nue, File originalPath, String name) throws IOException {
149
        for (Iterator i = getCopyOperationImplementation(original).iterator(); i.hasNext(); ) {
150
            ((CopyOperationImplementation) i.next()).notifyCopied(original, originalPath, name);
151
        }
152
        for (Iterator i = getCopyOperationImplementation(nue).iterator(); i.hasNext(); ) {
153
            ((CopyOperationImplementation) i.next()).notifyCopied(original, originalPath, name);
154
        }
155
    }
156
    
157
    /**Notification that the project is about to be moved.
158
     * Should be called immediatelly before the project is moved.
159
     *
160
     * The project is supposed to do all required cleanup to allow the project to be moved.
161
     *
162
     * @param prj project to notify
163
     * @throws IOException is some error occurs
164
     */
165
    public static void notifyMoving(Project prj) throws IOException {
166
        for (Iterator i = getMoveOperationImplementation(prj).iterator(); i.hasNext(); ) {
167
            ((MoveOperationImplementation) i.next()).notifyMoving();
168
        }
169
    }
170
    
171
    /**Notification that the project has been moved.
172
     * Should be called immediatelly after the project is moved.
173
     *
174
     * The project is supposed to do all necessary fixes to the project's structure to
175
     * form a valid project.
176
     *
177
     * Both original and moved project are notified, in this order.
178
     *
179
     * @param original original project
180
     * @param nue      moved project
181
     * @param originalPath the project folder of the original project
182
     * @param name     new name of the project
183
     * @throws IOException is some error occurs
184
     */
185
    public static void notifyMoved(Project original, Project nue, File originalPath, String name) throws IOException {
186
        for (Iterator i = getMoveOperationImplementation(original).iterator(); i.hasNext(); ) {
187
            ((MoveOperationImplementation) i.next()).notifyMoved(original, originalPath, name);
188
        }
189
        for (Iterator i = getMoveOperationImplementation(nue).iterator(); i.hasNext(); ) {
190
            ((MoveOperationImplementation) i.next()).notifyMoved(original, originalPath, name);
191
        }
192
    }
193
    
194
    /**Test whether the move operation is supported on the given project.
195
     * 
196
     * @param prj project to test
197
     * @return <code>true</code> if the project supports the move operation,
198
     *         <code>false</code> otherwise
199
     */
200
    public static boolean isMoveOperationSupported(Project prj) {
201
        return true;
202
    }
203
    
204
    private static Collection/*<DeleteOperationImplementation>*/ getDeleteOperationImplementation(Project prj) {
205
        return prj.getLookup().lookup(new Lookup.Template(DeleteOperationImplementation.class)).allInstances();
206
    }
207
    
208
    private static Collection/*<DataFilesProviderImplementation>*/ getProjectsOperationsImplementation(Project prj) {
209
        return prj.getLookup().lookup(new Lookup.Template(DataFilesProviderImplementation.class)).allInstances();
210
    }
211
    
212
    private static Collection/*<CopyOperationImplementation>*/ getCopyOperationImplementation(Project prj) {
213
        return prj.getLookup().lookup(new Lookup.Template(CopyOperationImplementation.class)).allInstances();
214
    }
215
    
216
    private static Collection/*<MoveOperationImplementation>*/ getMoveOperationImplementation(Project prj) {
217
        return prj.getLookup().lookup(new Lookup.Template(MoveOperationImplementation.class)).allInstances();
218
    }
219
    
220
}

Return to bug 61546