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/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
}
(-)projects/projectui/src/org/netbeans/modules/project/ui/actions/Actions.java (+54 lines)
Lines 51-56 Link Here
51
    private static Action OPEN_SUBPROJECTS;
51
    private static Action OPEN_SUBPROJECTS;
52
    private static Action CLOSE_PROJECT;
52
    private static Action CLOSE_PROJECT;
53
    private static Action NEW_FILE;
53
    private static Action NEW_FILE;
54
    private static Action COPY_PROJECT;
55
    private static Action MOVE_PROJECT;
56
    private static Action RENAME_PROJECT;
54
            
57
            
55
    public synchronized Action setAsMainProjectAction() {
58
    public synchronized Action setAsMainProjectAction() {
56
        if ( SET_AS_MAIN_PROJECT == null ) {
59
        if ( SET_AS_MAIN_PROJECT == null ) {
Lines 91-96 Link Here
91
        return deleteProject();
94
        return deleteProject();
92
    }
95
    }
93
96
97
    public Action copyProjectAction() {
98
        return copyProject();
99
    }
100
    
101
    public Action moveProjectAction() {
102
        return moveProject();
103
    }
104
    
105
    public Action renameProjectAction() {
106
        return renameProject();
107
    }
108
    
94
    public synchronized Action newProjectAction() {
109
    public synchronized Action newProjectAction() {
95
        return new NewProject();
110
        return new NewProject();
96
    }
111
    }
Lines 178-183 Link Here
178
        a.putValue(Action.ACCELERATOR_KEY, DeleteAction.get(DeleteAction.class).getValue(Action.ACCELERATOR_KEY));
193
        a.putValue(Action.ACCELERATOR_KEY, DeleteAction.get(DeleteAction.class).getValue(Action.ACCELERATOR_KEY));
179
        
194
        
180
        return a;
195
        return a;
196
    }
197
    
198
    public static synchronized Action copyProject() {
199
        if (COPY_PROJECT == null) {
200
            Action a = new ProjectAction(
201
                    ActionProvider.COMMAND_COPY,
202
                    "Copy Project", // NO18N
203
                    null, //NOI18N
204
                    null );
205
            COPY_PROJECT = a;
206
        }
207
        
208
        return COPY_PROJECT;
209
    }
210
    
211
    public static synchronized Action moveProject() {
212
        if (MOVE_PROJECT == null) {
213
            Action a = new ProjectAction(
214
                    ActionProvider.COMMAND_MOVE,
215
                    "Move Project", // NO18N
216
                    null, //NOI18N
217
                    null );
218
            MOVE_PROJECT = a;
219
        }
220
        
221
        return MOVE_PROJECT;
222
    }
223
    
224
    public static synchronized Action renameProject() {
225
        if (RENAME_PROJECT == null) {
226
            Action a = new ProjectAction(
227
                    ActionProvider.COMMAND_RENAME,
228
                    "Rename Project", // NO18N
229
                    null, //NOI18N
230
                    null );
231
            RENAME_PROJECT = a;
232
        }
233
        
234
        return RENAME_PROJECT;
181
    }
235
    }
182
    
236
    
183
    // 1-off actions -----------------------------------------------------------
237
    // 1-off actions -----------------------------------------------------------
(-)projects/projectuiapi/apichanges.xml (-16 / +18 lines)
Lines 76-81 Link Here
76
76
77
    <changes>
77
    <changes>
78
        
78
        
79
        <change id="delete-copy-move-support">
80
            <api name="general"/>
81
            <summary>Project Delete/Copy/Rename/Move Support Added, Support for Default Project Delete/Copy/Rename/Move Added</summary>
82
            <version major="1" minor="10"/>
83
            <date day="26" month="7" year="2005"/>
84
            <author login="jlahoda"/>
85
            <compatibility addition="yes" />
86
            <description>
87
                Introduced:
88
                <ul>
89
                    <li><code>CommonProjectActions.deleteProjectAction</code>, <code>CommonProjectActions.copyProjectAction</code>,
90
                        <code>CommonProjectActions.moveProjectAction</code>, <code>CommonProjectActions.removeProjectAction</code> methods.</li>
91
                    <li><code>DefaultProjectOperations</code> support to simplify implementation of project delete/copy/rename/move for simple projects.</li>
92
                </ul>
93
            </description>
94
            <issue number="TODO" />            
95
        </change>
96
        
79
        <change id="ProjectCustomizer.Category.errorMessage">
97
        <change id="ProjectCustomizer.Category.errorMessage">
80
            <api name="general"/>
98
            <api name="general"/>
81
            <summary>Added ability to set an error message for project customizer's categories.</summary>
99
            <summary>Added ability to set an error message for project customizer's categories.</summary>
Lines 137-158 Link Here
137
            <issue number="57874"/>
155
            <issue number="57874"/>
138
        </change>
156
        </change>
139
157
140
        <change id="action-delete-added">
141
            <api name="general"/>
142
            <summary>Delete Action Added</summary>
143
            <version major="1" minor="8"/>
144
            <date day="11" month="7" year="2005"/>
145
            <author login="jlahoda"/>
146
            <compatibility addition="yes" />
147
            <description>            
148
                Introduced:
149
                <ul>
150
                    <li><code>CommonProjectActions.deleteProjectAction</code> method</li>
151
                </ul>                
152
            </description>
153
            <issue number="51468" />            
154
        </change>
155
        
156
        <change id="CommonProjectActions.EXISTING_SOURCES_FOLDER">
158
        <change id="CommonProjectActions.EXISTING_SOURCES_FOLDER">
157
            <api name="general"/>
159
            <api name="general"/>
158
            <summary>New Project Wizard Action</summary>
160
            <summary>New Project Wizard Action</summary>
(-)projects/projectuiapi/nbproject/project.properties (-1 / +9 lines)
Lines 9-15 Link Here
9
# Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
9
# Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
10
# Microsystems, Inc. All Rights Reserved.
10
# Microsystems, Inc. All Rights Reserved.
11
11
12
spec.version.base=1.9.0
12
spec.version.base=1.10.0
13
is.autoload=true
13
is.autoload=true
14
javadoc.title=Project UI API
14
javadoc.title=Project UI API
15
javadoc.arch=${basedir}/arch.xml
15
javadoc.arch=${basedir}/arch.xml
Lines 17-20 Link Here
17
# copy paste magic to enable unit tests
17
# copy paste magic to enable unit tests
18
test.unit.src.dir=${basedir}/test/unit/src
18
test.unit.src.dir=${basedir}/test/unit/src
19
test-unit-sys-prop.test.junit.jar=${junit.dir}/modules/ext/junit-3.8.1.jar
19
test-unit-sys-prop.test.junit.jar=${junit.dir}/modules/ext/junit-3.8.1.jar
20
test.unit.cp.extra=\
21
    ${nb_all}/projects/projectapi/build/test/unit/classes
22
test.unit.run.cp.extra=\
23
    ${openide/masterfs.dir}/modules/org-netbeans-modules-masterfs.jar:\
24
    ${openide/options.dir}/modules/org-openide-options.jar:\
25
    ${projects/projectui.dir}/modules/org-netbeans-modules-projectui.jar
20
26
27
#    ${libs/xerces.dir}/modules/ext/xerces-2.6.2.jar:\
28
#    ${libs/xerces.dir}/modules/ext/xml-commons-dom-ranges-1.0.b2.jar:\
(-)projects/projectuiapi/nbproject/project.xml (-8 / +26 lines)
Lines 18-23 Link Here
18
            <code-name-base>org.netbeans.modules.projectuiapi</code-name-base>
18
            <code-name-base>org.netbeans.modules.projectuiapi</code-name-base>
19
            <module-dependencies>
19
            <module-dependencies>
20
                <dependency>
20
                <dependency>
21
                    <code-name-base>org.netbeans.api.progress</code-name-base>
22
                    <build-prerequisite/>
23
                    <compile-dependency/>
24
                    <run-dependency>
25
                        <release-version>1</release-version>
26
                        <specification-version>1.0</specification-version>
27
                    </run-dependency>
28
                </dependency>
29
                <dependency>
21
                    <code-name-base>org.netbeans.modules.projectapi</code-name-base>
30
                    <code-name-base>org.netbeans.modules.projectapi</code-name-base>
22
                    <build-prerequisite/>
31
                    <build-prerequisite/>
23
                    <compile-dependency/>
32
                    <compile-dependency/>
Lines 27-41 Link Here
27
                    </run-dependency>
36
                    </run-dependency>
28
                </dependency>
37
                </dependency>
29
                <dependency>
38
                <dependency>
30
                    <code-name-base>org.openide.filesystems</code-name-base>
39
                    <code-name-base>org.netbeans.modules.queries</code-name-base>
31
                    <build-prerequisite/>
40
                    <build-prerequisite/>
32
                    <compile-dependency/>
41
                    <compile-dependency/>
33
                    <run-dependency>
42
                    <run-dependency>
34
                        <specification-version>6.2</specification-version>
43
                        <release-version>1</release-version>
44
                        <specification-version>1.5</specification-version>
35
                    </run-dependency>
45
                    </run-dependency>
36
                </dependency>
46
                </dependency>
37
                <dependency>
47
                <dependency>
38
                    <code-name-base>org.openide.util</code-name-base>
48
                    <code-name-base>org.openide.awt</code-name-base>
39
                    <build-prerequisite/>
49
                    <build-prerequisite/>
40
                    <compile-dependency/>
50
                    <compile-dependency/>
41
                    <run-dependency>
51
                    <run-dependency>
Lines 43-49 Link Here
43
                    </run-dependency>
53
                    </run-dependency>
44
                </dependency>
54
                </dependency>
45
                <dependency>
55
                <dependency>
46
                    <code-name-base>org.openide.nodes</code-name-base>
56
                    <code-name-base>org.openide.dialogs</code-name-base>
47
                    <build-prerequisite/>
57
                    <build-prerequisite/>
48
                    <compile-dependency/>
58
                    <compile-dependency/>
49
                    <run-dependency>
59
                    <run-dependency>
Lines 59-65 Link Here
59
                    </run-dependency>
69
                    </run-dependency>
60
                </dependency>
70
                </dependency>
61
                <dependency>
71
                <dependency>
62
                    <code-name-base>org.openide.awt</code-name-base>
72
                    <code-name-base>org.openide.filesystems</code-name-base>
63
                    <build-prerequisite/>
73
                    <build-prerequisite/>
64
                    <compile-dependency/>
74
                    <compile-dependency/>
65
                    <run-dependency>
75
                    <run-dependency>
Lines 67-73 Link Here
67
                    </run-dependency>
77
                    </run-dependency>
68
                </dependency>
78
                </dependency>
69
                <dependency>
79
                <dependency>
70
                    <code-name-base>org.openide.dialogs</code-name-base>
80
                    <code-name-base>org.openide.loaders</code-name-base>
81
                    <build-prerequisite/>
82
                    <compile-dependency/>
83
                    <run-dependency/>
84
                </dependency>
85
                <dependency>
86
                    <code-name-base>org.openide.nodes</code-name-base>
71
                    <build-prerequisite/>
87
                    <build-prerequisite/>
72
                    <compile-dependency/>
88
                    <compile-dependency/>
73
                    <run-dependency>
89
                    <run-dependency>
Lines 75-84 Link Here
75
                    </run-dependency>
91
                    </run-dependency>
76
                </dependency>
92
                </dependency>
77
                <dependency>
93
                <dependency>
78
                    <code-name-base>org.openide.loaders</code-name-base>
94
                    <code-name-base>org.openide.util</code-name-base>
79
                    <build-prerequisite/>
95
                    <build-prerequisite/>
80
                    <compile-dependency/>
96
                    <compile-dependency/>
81
                    <run-dependency/>
97
                    <run-dependency>
98
                        <specification-version>6.2</specification-version>
99
                    </run-dependency>
82
                </dependency>
100
                </dependency>
83
            </module-dependencies>
101
            </module-dependencies>
84
            <public-packages>
102
            <public-packages>
(-)projects/projectuiapi/src/org/netbeans/modules/project/uiapi/ActionsFactory.java (+6 lines)
Lines 37-42 Link Here
37
    
37
    
38
    public Action deleteProjectAction();
38
    public Action deleteProjectAction();
39
    
39
    
40
    public Action copyProjectAction();
41
    
42
    public Action moveProjectAction();
43
    
40
    public Action newProjectAction();
44
    public Action newProjectAction();
41
            
45
            
42
    // Actions sensitive to project selection
46
    // Actions sensitive to project selection
Lines 54-58 Link Here
54
    // Actions sensitive to file
58
    // Actions sensitive to file
55
    
59
    
56
    public Action fileCommandAction( String command, String name, Icon icon );
60
    public Action fileCommandAction( String command, String name, Icon icon );
61
62
    public Action renameProjectAction();
57
    
63
    
58
}
64
}
(-)projects/projectuiapi/src/org/netbeans/modules/project/uiapi/Bundle.properties (+31 lines)
Lines 34-36 Link Here
34
34
35
35
36
LBL_Customizer_Categories=Categories\:
36
LBL_Customizer_Categories=Categories\:
37
38
#DefaultAntProjectOperations:
39
LBL_Progress_Cleaning_Project=Cleaning Project
40
LBL_Progress_Deleting_File=Deleting {0}
41
LBL_Project_cannot_be_deleted.=Project {0} cannot be deleted.
42
LBL_Delete_Project_Caption=Delete Project
43
LBL_Deleting_Project=Deleting Project\:
44
#currently not used:
45
#LBL_Project_Deletion_in_Progress_Caption=Project Deletion in Progress
46
47
#DefaultAntProjectDeletePanel:
48
LBL_Pre_Delete_Warning=Are you sure you want to delete project "{0}"?
49
LBL_Delete_Also_Sources=&Also Delete Sources Under "{0}" folder.
50
51
#ProjectCopyPanel:
52
#{0}: Integer 0 or 1. 0 for copy project dialog, 1 for move project dialog
53
#{1}: project's display name
54
LBL_Copy_Move_Dialog_Text={0,choice,0#Copy|1#Move} "{1}" To:
55
LBL_Project_Folder=Project Fol&der\:
56
LBL_Project_Location=Project &Location\:
57
LBL_Project_Name=Project &Name\:
58
#ProjectCopyPanel's error messages:
59
ERR_Location_Does_Not_Exist=Location Does Not Exist
60
ERR_Project_Folder_Exists=Project Folder Already Exists
61
#ProjectCopyPanel's warning message:
62
WRN_External_Sources=The project has one or more external source roots, which cannot be copied.
63
64
#DefaultRenamePanel:
65
#{0}: project's display name
66
LBL_Rename_Dialog_Text=Rename "{1}":
67
LBL_Also_Rename_Project_Folder=&Also Rename Project Folder
(-)projects/projectuiapi/src/org/netbeans/modules/project/uiapi/DefaultProjectDeletePanel.form (+50 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.0" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AuxValues>
5
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
6
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
7
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
8
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
9
    <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,46,0,0,1,-112"/>
10
  </AuxValues>
11
12
  <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
13
  <SubComponents>
14
    <Component class="javax.swing.JTextArea" name="warningText">
15
      <Properties>
16
        <Property name="editable" type="boolean" value="false"/>
17
        <Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
18
          <Connection code="javax.swing.UIManager.getFont(&quot;Label.font&quot;)" type="code"/>
19
        </Property>
20
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
21
          <Connection code="getWarningText()" type="code"/>
22
        </Property>
23
        <Property name="disabledTextColor" type="java.awt.Color" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
24
          <Connection code="javax.swing.UIManager.getColor(&quot;Label.foreground&quot;)" type="code"/>
25
        </Property>
26
        <Property name="opaque" type="boolean" value="false"/>
27
      </Properties>
28
      <Constraints>
29
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
30
          <GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="12" insetsLeft="12" insetsBottom="0" insetsRight="12" anchor="18" weightX="1.0" weightY="0.0"/>
31
        </Constraint>
32
      </Constraints>
33
    </Component>
34
    <Component class="javax.swing.JCheckBox" name="deleteSourcesCheckBox">
35
      <Properties>
36
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
37
          <Connection code="getCheckboxText()" type="code"/>
38
        </Property>
39
        <Property name="enabled" type="boolean" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
40
          <Connection code="enableCheckbox" type="code"/>
41
        </Property>
42
      </Properties>
43
      <Constraints>
44
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
45
          <GridBagConstraints gridX="0" gridY="3" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="12" insetsLeft="12" insetsBottom="0" insetsRight="12" anchor="17" weightX="0.0" weightY="0.0"/>
46
        </Constraint>
47
      </Constraints>
48
    </Component>
49
  </SubComponents>
50
</Form>
(-)projects/projectuiapi/src/org/netbeans/modules/project/uiapi/DefaultProjectDeletePanel.java (+101 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.modules.project.uiapi;
15
16
import java.awt.Component;
17
import java.awt.Window;
18
import java.text.MessageFormat;
19
import java.util.Iterator;
20
import java.util.List;
21
import org.openide.filesystems.FileObject;
22
import org.openide.filesystems.FileUtil;
23
import org.openide.util.NbBundle;
24
25
/**
26
 *
27
 * @author Jan Lahoda
28
 */
29
final class DefaultProjectDeletePanel extends javax.swing.JPanel {
30
    
31
    private String projectDisplaName;
32
    private String projectFolder;
33
    private boolean enableCheckbox;
34
    
35
    /**
36
     * Creates new form DefaultProjectDeletePanel
37
     */
38
    public DefaultProjectDeletePanel(String projectDisplaName, String projectFolder, boolean enableCheckbox) {
39
        this.projectDisplaName = projectDisplaName;
40
        this.projectFolder = projectFolder;
41
        this.enableCheckbox = enableCheckbox;
42
        initComponents();
43
    }
44
    
45
    /** This method is called from within the constructor to
46
     * initialize the form.
47
     * WARNING: Do NOT modify this code. The content of this method is
48
     * always regenerated by the Form Editor.
49
     */
50
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
51
    private void initComponents() {
52
        java.awt.GridBagConstraints gridBagConstraints;
53
54
        warningText = new javax.swing.JTextArea();
55
        deleteSourcesCheckBox = new javax.swing.JCheckBox();
56
57
        setLayout(new java.awt.GridBagLayout());
58
59
        warningText.setEditable(false);
60
        warningText.setFont(javax.swing.UIManager.getFont("Label.font"));
61
        warningText.setText(getWarningText());
62
        warningText.setDisabledTextColor(javax.swing.UIManager.getColor("Label.foreground"));
63
        warningText.setOpaque(false);
64
        gridBagConstraints = new java.awt.GridBagConstraints();
65
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
66
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
67
        gridBagConstraints.weightx = 1.0;
68
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 12);
69
        add(warningText, gridBagConstraints);
70
71
        org.openide.awt.Mnemonics.setLocalizedText(deleteSourcesCheckBox, getCheckboxText());
72
        deleteSourcesCheckBox.setEnabled(enableCheckbox);
73
        gridBagConstraints = new java.awt.GridBagConstraints();
74
        gridBagConstraints.gridx = 0;
75
        gridBagConstraints.gridy = 3;
76
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
77
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 12);
78
        add(deleteSourcesCheckBox, gridBagConstraints);
79
80
    }
81
    // </editor-fold>//GEN-END:initComponents
82
    
83
    
84
    // Variables declaration - do not modify//GEN-BEGIN:variables
85
    private javax.swing.JCheckBox deleteSourcesCheckBox;
86
    private javax.swing.JTextArea warningText;
87
    // End of variables declaration//GEN-END:variables
88
    
89
    public boolean isDeleteSources() {
90
        return deleteSourcesCheckBox.isSelected();
91
    }
92
93
    private String getWarningText() {
94
        return NbBundle.getMessage(DefaultProjectDeletePanel.class, "LBL_Pre_Delete_Warning", new Object[] {projectDisplaName});
95
    }
96
    
97
    private String getCheckboxText() {
98
        return NbBundle.getMessage(DefaultProjectDeletePanel.class, "LBL_Delete_Also_Sources", new Object[] {projectFolder});
99
    }
100
    
101
}
(-)projects/projectuiapi/src/org/netbeans/modules/project/uiapi/DefaultProjectOperationsImplementation.java (+540 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.modules.project.uiapi;
15
16
import java.awt.Component;
17
import java.awt.Dialog;
18
import java.awt.GridBagConstraints;
19
import java.awt.Insets;
20
import java.awt.Window;
21
import java.awt.event.ActionEvent;
22
import java.awt.event.ActionListener;
23
import java.io.File;
24
import java.io.FileOutputStream;
25
import java.io.IOException;
26
import java.io.InputStream;
27
import java.io.OutputStream;
28
import java.util.ArrayList;
29
import java.util.Arrays;
30
import java.util.Iterator;
31
import java.util.List;
32
import javax.swing.JButton;
33
import javax.swing.JComponent;
34
import javax.swing.JLabel;
35
import javax.swing.JPanel;
36
import javax.swing.SwingUtilities;
37
import javax.swing.event.ChangeEvent;
38
import javax.swing.event.ChangeListener;
39
import org.netbeans.api.progress.ProgressHandle;
40
import org.netbeans.api.progress.ProgressHandleFactory;
41
import org.netbeans.api.project.FileOwnerQuery;
42
import org.netbeans.api.project.Project;
43
import org.netbeans.api.project.ProjectManager;
44
import org.netbeans.api.project.ProjectUtils;
45
import org.netbeans.api.project.ui.OpenProjects;
46
import org.netbeans.spi.project.support.ProjectOperations;
47
import org.netbeans.api.queries.VisibilityQuery;
48
import org.openide.DialogDescriptor;
49
import org.openide.DialogDisplayer;
50
import org.openide.ErrorManager;
51
import org.openide.NotifyDescriptor;
52
import org.openide.filesystems.FileObject;
53
import org.openide.filesystems.FileUtil;
54
import org.openide.util.NbBundle;
55
import org.openide.util.RequestProcessor;
56
57
58
/**
59
 *
60
 * @author Jan Lahoda
61
 */
62
public final class DefaultProjectOperationsImplementation {
63
    
64
    private static final ErrorManager ERR = ErrorManager.getDefault(); // NOI18N
65
    
66
    private DefaultProjectOperationsImplementation() {
67
    }
68
    
69
    private static String getDisplayName(Project project) {
70
        return ProjectUtils.getInformation(project).getDisplayName();
71
    }
72
 
73
    //<editor-fold defaultstate="collapsed" desc="Delete Operation">
74
    /**
75
     * @return true if success
76
     */
77
    private static boolean performDelete(Project project, List/*FileObject>*/ toDelete, ProgressHandle handle) {
78
        try {
79
            handle.start(toDelete.size() + 1 /*clean*/);
80
            
81
            int done = 0;
82
            
83
            handle.progress(NbBundle.getMessage(DefaultProjectOperationsImplementation.class, "LBL_Progress_Cleaning_Project"));
84
            
85
            ProjectOperations.notifyDeleting(project);
86
            
87
            handle.progress(++done);
88
            
89
            for (Iterator i = toDelete.iterator(); i.hasNext(); ) {
90
                FileObject f = (FileObject) i.next();
91
                
92
                handle.progress(NbBundle.getMessage(DefaultProjectOperationsImplementation.class, "LBL_Progress_Deleting_File", new Object[] {FileUtil.getFileDisplayName(f)}));
93
                
94
                if (f != null)
95
                    f.delete();
96
                
97
                handle.progress(++done);
98
            }
99
            
100
            FileObject projectFolder = project.getProjectDirectory();
101
            
102
            if (projectFolder.getChildren().length == 0) {
103
                //empty, delete:
104
                projectFolder.delete();
105
            }
106
            
107
            handle.finish();
108
            
109
            ProjectOperations.notifyDeleted(project);
110
            return true;
111
        } catch (IOException e) {
112
            String displayName = getDisplayName(project);
113
            String message     = NbBundle.getMessage(DefaultProjectOperationsImplementation.class, "LBL_Project_cannot_be_deleted.", new Object[] {displayName});
114
            
115
            ErrorManager.getDefault().annotate(e, message);
116
            ErrorManager.getDefault().notify(ErrorManager.USER, e);
117
            
118
            return false;
119
        }
120
    }
121
    
122
    public static void deleteProject(final Project project) {
123
        Runnable r = new Runnable() {
124
            public void run() {
125
                deleteProject(project, new GUIUserInputHandler());
126
            }
127
        };
128
        
129
        if (SwingUtilities.isEventDispatchThread()) {
130
            r.run();
131
        } else {
132
            SwingUtilities.invokeLater(r);
133
        }
134
    }
135
    
136
    /*package private*/static void deleteProject(final Project project, final UserInputHandler handler) {
137
        String displayName = getDisplayName(project);
138
        FileObject projectFolder = project.getProjectDirectory();
139
        
140
        if (ERR.isLoggable(ErrorManager.INFORMATIONAL)) {
141
            ERR.log(ErrorManager.INFORMATIONAL, "delete started: " + displayName); // NOI18N
142
        }
143
        
144
        List/*<FileObject>*/ metadataFiles = ProjectOperations.getMetadataFiles(project);
145
        List/*<FileObject>*/ dataFiles = ProjectOperations.getDataFiles(project);
146
        List/*<FileObject>*/ allFiles = new ArrayList/*<FileObject>*/();
147
        
148
        allFiles.addAll(metadataFiles);
149
        allFiles.addAll(dataFiles);
150
        
151
        for (Iterator i = allFiles.iterator(); i.hasNext(); ) {
152
            FileObject f = (FileObject) i.next();
153
            
154
            if (!FileUtil.isParentOf(projectFolder, f)) {
155
                i.remove();
156
            }
157
        }
158
        
159
        int userAnswer = handler.userConfirmation(displayName, FileUtil.getFileDisplayName(projectFolder), !dataFiles.isEmpty());
160
        List/*<FileObject>*/ toDeleteImpl = null;
161
        
162
        switch (userAnswer) {
163
            case UserInputHandler.USER_CANCEL:
164
                return ;
165
            case UserInputHandler.USER_OK_METADATA:
166
                toDeleteImpl = metadataFiles;
167
                break;
168
            case UserInputHandler.USER_OK_ALL:
169
                toDeleteImpl = allFiles;
170
                break;
171
            default:
172
                throw new IllegalStateException("Invalid user answer: " + userAnswer);
173
        }
174
        
175
        final ProgressHandle handle = handler.getProgressHandle();
176
        final List/*<FileObject>*/ toDelete = toDeleteImpl;
177
        final boolean[] result = new boolean[1];
178
        
179
        OpenProjects.getDefault().close(new Project[] {project});
180
        
181
        handler.delete(new Runnable() {
182
            public void run() {
183
                result[0] = performDelete(project, toDelete, handle);
184
            }
185
        });
186
        
187
        if (ERR.isLoggable(ErrorManager.INFORMATIONAL)) {
188
            ERR.log(ErrorManager.INFORMATIONAL, "delete done: " + displayName); // NOI18N
189
        }
190
    }
191
    
192
    /*package private*/interface UserInputHandler {
193
        
194
        public int USER_CANCEL = 1;
195
        public int USER_OK_METADATA = 2;
196
        public int USER_OK_ALL = 3;
197
        
198
        public abstract int userConfirmation(String displayName, String projectFolder, boolean enableData);
199
        
200
        public abstract ProgressHandle getProgressHandle();
201
        
202
        public abstract void delete(Runnable r);
203
        
204
    }
205
    
206
    private static final class GUIUserInputHandler implements UserInputHandler {
207
        
208
        public int userConfirmation(String displayName, String projectFolder, boolean enableData) {
209
            DefaultProjectDeletePanel deletePanel = new DefaultProjectDeletePanel(displayName, projectFolder, enableData);
210
            
211
            String caption = NbBundle.getMessage(DefaultProjectOperationsImplementation.class, "LBL_Delete_Project_Caption");
212
            
213
            NotifyDescriptor nd = new NotifyDescriptor.Confirmation(deletePanel, caption, NotifyDescriptor.YES_NO_OPTION);
214
            
215
            if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.YES_OPTION) {
216
                if (deletePanel.isDeleteSources()) {
217
                    return USER_OK_ALL;
218
                } else {
219
                    return USER_OK_METADATA;
220
                }
221
            } else {
222
                return USER_CANCEL;
223
            }
224
        }
225
        
226
        private ProgressHandle handle = null;
227
        
228
        public synchronized ProgressHandle getProgressHandle() {
229
            if (handle == null) {
230
                handle = ProgressHandleFactory.createHandle(NbBundle.getMessage(DefaultProjectOperationsImplementation.class, "LBL_Delete_Project_Caption"));
231
            }
232
            
233
            return handle;
234
        }
235
        
236
        public void delete(final Runnable r) {
237
            RequestProcessor.getDefault().post(new Runnable() {
238
                public void run() {
239
                    r.run();
240
		    
241
                    if (ERR.isLoggable(ErrorManager.INFORMATIONAL)) {
242
                        ERR.log(ErrorManager.INFORMATIONAL, "delete finished"); // NOI18N
243
                    }
244
                }
245
            });
246
        }
247
        
248
    }
249
    
250
    private static JComponent createProgressDialog(ProgressHandle handle) {
251
        JPanel dialog = new JPanel();
252
        
253
        GridBagConstraints gridBagConstraints;
254
        
255
        JLabel jLabel1 = new JLabel();
256
        JComponent progress = ProgressHandleFactory.createProgressComponent(handle);
257
        JPanel padding = new JPanel();
258
        
259
        dialog.setLayout(new java.awt.GridBagLayout());
260
        
261
        jLabel1.setText(NbBundle.getMessage(DefaultProjectOperationsImplementation.class, "LBL_Deleting_Project"));
262
        gridBagConstraints = new GridBagConstraints();
263
        gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
264
        gridBagConstraints.insets = new Insets(12, 12, 0, 12);
265
        dialog.add(jLabel1, gridBagConstraints);
266
        
267
        gridBagConstraints = new GridBagConstraints();
268
        gridBagConstraints.gridx = 0;
269
        gridBagConstraints.gridy = 1;
270
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
271
        gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
272
        gridBagConstraints.weightx = 1.0;
273
        gridBagConstraints.insets = new Insets(12, 12, 0, 12);
274
        dialog.add(progress, gridBagConstraints);
275
276
        gridBagConstraints = new GridBagConstraints();
277
        gridBagConstraints.gridx = 0;
278
        gridBagConstraints.gridy = 2;
279
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL | GridBagConstraints.VERTICAL;
280
        gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
281
        gridBagConstraints.weightx = 1.0;
282
        gridBagConstraints.weighty = 1.0;
283
        gridBagConstraints.insets = new Insets(12, 12, 12, 12);
284
        dialog.add(padding, gridBagConstraints);
285
        
286
        return dialog;
287
    }
288
    //</editor-fold>
289
    
290
    //<editor-fold defaultstate="collapsed" desc="Copy Operation">
291
    public static void copyProject(final Project project) {
292
        final ProgressHandle handle = ProgressHandleFactory.createHandle("Copy Project");
293
        final ProjectCopyPanel panel = new ProjectCopyPanel(handle, project, false);
294
        
295
        showConfirmationDialog(panel, project, "Copy Project", "Copy", new Executor() {
296
            public void execute() {
297
                String nueName = panel.getNewName();
298
                File newTarget = panel.getNewDirectory();
299
                
300
                doCopyProject(handle, project, nueName, newTarget);
301
            }
302
        });
303
    }
304
    
305
    /*package private for tests*/ static void doCopyProject(ProgressHandle handle, Project project, String nueName, File newTarget) {
306
        try {
307
            File target = new File(newTarget, nueName);
308
            
309
            assert !target.exists();
310
            
311
            ProjectOperations.notifyCopying(project);
312
            
313
            target.mkdirs();
314
            
315
            FileObject projectDirectory = project.getProjectDirectory();
316
            List/*<FileObject>*/ toCopyList = Arrays.asList(projectDirectory.getChildren());
317
            
318
            handle.start(toCopyList.size());
319
            
320
            int workDone = 0;
321
            
322
            for (Iterator i = toCopyList.iterator(); i.hasNext(); ) {
323
                FileObject toCopy = (FileObject) i.next();
324
                File       toCopyFile = FileUtil.toFile(toCopy);
325
                
326
                doCopy(project, toCopy, new File(target, toCopy.getNameExt()));
327
                handle.progress(++workDone);
328
            }
329
            
330
            Project nue = ProjectManager.getDefault().findProject(FileUtil.toFileObject(target));
331
            
332
            assert nue != null;
333
            
334
            ProjectOperations.notifyCopied(project, nue, FileUtil.toFile(project.getProjectDirectory()), nueName);
335
            
336
            ProjectManager.getDefault().saveProject(nue);
337
            
338
            OpenProjects.getDefault().open(new Project[] {nue}, false);
339
            
340
            handle.finish();
341
        } catch (IOException e) {
342
            ErrorManager.getDefault().notify(e);
343
            e.printStackTrace();
344
        }
345
    }
346
    //</editor-fold>
347
    
348
    //<editor-fold defaultstate="collapsed" desc="Move Operation">
349
    public static void moveProject(final Project project) {
350
        final ProgressHandle handle = ProgressHandleFactory.createHandle("Move Project");
351
        final ProjectCopyPanel panel = new ProjectCopyPanel(handle, project, true);
352
        
353
        showConfirmationDialog(panel, project, "Move Project", "Move", new Executor() {
354
            public void execute() {
355
                String nueName = panel.getNewName();
356
                File newTarget = panel.getNewDirectory();
357
                
358
                doMoveProject(handle, project, nueName, newTarget);
359
            }
360
        });
361
    }
362
    
363
    public static void renameProject(Project project) {
364
        renameProject(project, null);
365
    }
366
    
367
    public static void renameProject(final Project project, final String nueName) {
368
        final ProgressHandle handle = ProgressHandleFactory.createHandle("Copy Project");
369
        final DefaultProjectRenamePanel panel = new DefaultProjectRenamePanel(project, nueName);
370
        
371
        showConfirmationDialog(panel, project, "Rename Project", "Rename", new Executor() {
372
            
373
            public void execute() {
374
                String nueName = panel.getNewName();
375
                
376
                doMoveProject(handle, project, nueName, FileUtil.toFile(project.getProjectDirectory().getParent()));
377
            }
378
        });
379
    }
380
    
381
    /*package private for tests*/ static void doMoveProject(ProgressHandle handle, Project project, String nueName, File newTarget) {
382
        try {
383
            File target = new File(newTarget, nueName);
384
            
385
            assert !target.exists();
386
            
387
            ProjectOperations.notifyMoving(project);
388
            
389
            OpenProjects.getDefault().close(new Project[] {project});
390
            
391
            FileObject projectDirectory = project.getProjectDirectory();
392
            List/*<FileObject>*/ toMoveList = Arrays.asList(projectDirectory.getChildren());
393
            
394
            target.mkdirs();
395
            
396
            for (Iterator i = toMoveList.iterator(); i.hasNext(); ) {
397
                FileObject toCopy = (FileObject) i.next();
398
                File       toCopyFile = FileUtil.toFile(toCopy);
399
                
400
                doCopy(project, toCopy, new File(target, toCopy.getNameExt()));
401
                delete(toCopyFile);
402
            }
403
            
404
            projectDirectory.refresh();//TODO: better way.
405
            projectDirectory.refresh();
406
            
407
            if (projectDirectory.getChildren().length == 0) {
408
                projectDirectory.delete();
409
            }
410
                
411
            ProjectOperations.notifyDeleted(project);
412
            
413
            Project nue = ProjectManager.getDefault().findProject(FileUtil.toFileObject(target));
414
            
415
            assert nue != null;
416
            
417
            ProjectOperations.notifyMoved(project, nue, FileUtil.toFile(project.getProjectDirectory()), nueName);
418
            
419
            ProjectManager.getDefault().saveProject(nue);
420
            
421
            OpenProjects.getDefault().open(new Project[] {nue}, false);
422
        } catch (IOException e) {
423
            ErrorManager.getDefault().notify(e);
424
        }
425
    }
426
    //</editor-fold>
427
    
428
    //<editor-fold defaultstate="collapsed" desc="Copy Move Utilities">
429
    private static void doCopy(Project original, FileObject from, File to) throws IOException {
430
        if (!VisibilityQuery.getDefault().isVisible(from)) {
431
            //Do not copy invisible files/folders.
432
            return ;
433
        }
434
        
435
        if (!original.getProjectDirectory().equals(FileOwnerQuery.getOwner(from).getProjectDirectory())) {
436
            return ;
437
        }
438
        
439
        if (from.isFolder()) {
440
            to.mkdir();
441
            FileObject[] kids = from.getChildren();
442
            for (int i = 0; i < kids.length; i++) {
443
                doCopy(original, kids[i], new File(to, kids[i].getNameExt()));
444
            }
445
        } else {
446
            assert from.isData();
447
            InputStream is = from.getInputStream();
448
            try {
449
                OutputStream os = new FileOutputStream(to);
450
                try {
451
                    FileUtil.copy(is, os);
452
                } finally {
453
                    os.close();
454
                }
455
            } finally {
456
                is.close();
457
            }
458
        }
459
    }
460
    
461
    private static void delete(File f) throws IOException {
462
        if (f.isDirectory()) {
463
            File[] children = f.listFiles();
464
            
465
            for (int cntr = 0; cntr < children.length; cntr++) {
466
                delete(children[cntr]);
467
            }
468
        }
469
        
470
        f.delete();
471
    }
472
    
473
    private static void showConfirmationDialog(final JComponent panel, Project project, String caption, String confirmButton, final Executor executor) {
474
        final JButton confirm = new JButton(confirmButton);
475
        final JButton cancel  = new JButton("Cancel");
476
        
477
        assert panel instanceof InvalidablePanel;
478
        
479
        ((InvalidablePanel) panel).addChangeListener(new ChangeListener() {
480
            public void stateChanged(ChangeEvent e) {
481
                confirm.setEnabled(((InvalidablePanel) panel).isValid());
482
            }
483
        });
484
        
485
        confirm.setEnabled(panel.isValid());
486
        
487
        final Dialog[] dialog = new Dialog[1];
488
        
489
        DialogDescriptor dd = new DialogDescriptor(panel, caption, true, new Object[] {confirm, cancel}, confirm, DialogDescriptor.DEFAULT_ALIGN, null, new ActionListener() {
490
            public void actionPerformed(ActionEvent e) {
491
                if (e.getSource() == confirm) {
492
                    confirm.setEnabled(false);
493
                    cancel.setEnabled(false);
494
                    ((InvalidablePanel) panel).showProgress();
495
                    
496
                    Component findParent = panel;
497
                    
498
                    while (findParent != null && !(findParent instanceof Window)) {
499
                        findParent = findParent.getParent();
500
                    }
501
                    
502
                    if (findParent != null) {
503
                        ((Window) findParent).pack();
504
                    }
505
                    
506
                    RequestProcessor.getDefault().post(new Runnable() {
507
                        public void run() {
508
                            executor.execute();
509
                            
510
                            SwingUtilities.invokeLater(new Runnable() {
511
                                public void run() {
512
                                    dialog[0].setVisible(false);
513
                                }
514
                            });
515
                        }
516
                    });
517
                }
518
            }
519
        });
520
        
521
        dialog[0] = DialogDisplayer.getDefault().createDialog(dd);
522
        
523
        dialog[0].setVisible(true);
524
        
525
        dialog[0] = null;
526
    }
527
    
528
    private static interface Executor {
529
        public void execute();
530
    }
531
    
532
    public static interface InvalidablePanel {
533
        public void addChangeListener(ChangeListener l);
534
        public void removeChangeListener(ChangeListener l);
535
        public boolean isValid();
536
        public void showProgress();
537
    }
538
    //</editor-fold>
539
    
540
}
(-)projects/projectuiapi/src/org/netbeans/modules/project/uiapi/DefaultProjectRenamePanel.form (+97 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.0" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AuxValues>
5
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
6
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
7
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
8
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
9
  </AuxValues>
10
11
  <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
12
  <SubComponents>
13
    <Component class="javax.swing.JLabel" name="jLabel1">
14
      <Properties>
15
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
16
          <ResourceString bundle="org/netbeans/modules/project/ant/Bundle.properties" key="LBL_Project_Name" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
17
        </Property>
18
      </Properties>
19
      <Constraints>
20
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
21
          <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
22
        </Constraint>
23
      </Constraints>
24
    </Component>
25
    <Component class="javax.swing.JLabel" name="projectFolderLabel">
26
      <Properties>
27
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
28
          <ResourceString bundle="org/netbeans/modules/project/ant/Bundle.properties" key="LBL_Project_Folder" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
29
        </Property>
30
      </Properties>
31
      <Constraints>
32
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
33
          <GridBagConstraints gridX="0" gridY="3" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
34
        </Constraint>
35
      </Constraints>
36
    </Component>
37
    <Component class="javax.swing.JTextField" name="projectName">
38
      <Properties>
39
        <Property name="columns" type="int" value="20"/>
40
      </Properties>
41
      <Constraints>
42
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
43
          <GridBagConstraints gridX="1" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
44
        </Constraint>
45
      </Constraints>
46
    </Component>
47
    <Component class="javax.swing.JTextField" name="projectFolder">
48
      <Properties>
49
        <Property name="editable" type="boolean" value="false"/>
50
      </Properties>
51
      <Constraints>
52
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
53
          <GridBagConstraints gridX="1" gridY="3" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
54
        </Constraint>
55
      </Constraints>
56
    </Component>
57
    <Component class="javax.swing.JCheckBox" name="alsoRenameFolder">
58
      <Properties>
59
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
60
          <ResourceString bundle="org/netbeans/modules/project/uiapi/Bundle.properties" key="LBL_Also_Rename_Project_Folder" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
61
        </Property>
62
        <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
63
          <Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
64
            <EmptyBorder bottom="0" left="0" right="0" top="0"/>
65
          </Border>
66
        </Property>
67
        <Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
68
          <Insets value="[0, 0, 0, 0]"/>
69
        </Property>
70
      </Properties>
71
      <Constraints>
72
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
73
          <GridBagConstraints gridX="0" gridY="2" gridWidth="2" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
74
        </Constraint>
75
      </Constraints>
76
    </Component>
77
    <Component class="javax.swing.JLabel" name="jLabel3">
78
      <Properties>
79
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
80
          <Connection code="NbBundle.getMessage(DefaultProjectRenamePanel.class, &quot;LBL_Rename_Dialog_Text&quot;, ProjectUtils.getInformation(project).getDisplayName())" type="code"/>
81
        </Property>
82
      </Properties>
83
      <Constraints>
84
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
85
          <GridBagConstraints gridX="-1" gridY="-1" gridWidth="2" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
86
        </Constraint>
87
      </Constraints>
88
    </Component>
89
    <Component class="javax.swing.JLabel" name="errorMessage">
90
      <Constraints>
91
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
92
          <GridBagConstraints gridX="0" gridY="4" gridWidth="2" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
93
        </Constraint>
94
      </Constraints>
95
    </Component>
96
  </SubComponents>
97
</Form>
(-)projects/projectuiapi/src/org/netbeans/modules/project/uiapi/DefaultProjectRenamePanel.java (+208 lines)
Added Link Here
1
/*
2
 * DefaultRenamePanel.java
3
 *
4
 * Created on July 13, 2005, 10:03 PM
5
 */
6
7
package org.netbeans.modules.project.uiapi;
8
9
import java.io.File;
10
import java.util.ArrayList;
11
import java.util.List;
12
import javax.swing.event.ChangeEvent;
13
import javax.swing.event.ChangeListener;
14
import javax.swing.event.DocumentEvent;
15
import javax.swing.event.DocumentListener;
16
import org.netbeans.api.project.Project;
17
import org.netbeans.api.project.ProjectUtils;
18
import org.netbeans.modules.project.uiapi.DefaultProjectOperationsImplementation.InvalidablePanel;
19
import org.openide.filesystems.FileUtil;
20
import org.openide.util.NbBundle;
21
22
/**
23
 *
24
 * @author  lahvac
25
 */
26
public class DefaultProjectRenamePanel extends javax.swing.JPanel implements DocumentListener, InvalidablePanel {
27
    
28
    private Project project;
29
    private List listeners;
30
    
31
    /**
32
     * Creates new form DefaultProjectRenamePanel
33
     */
34
    public DefaultProjectRenamePanel(Project project, String name) {
35
        this.project = project;
36
        
37
        if (name == null) {
38
            name = ProjectUtils.getInformation(project).getDisplayName();
39
        }
40
        
41
        this.listeners = new ArrayList();
42
        
43
        initComponents();
44
        
45
        projectName.setText(name);
46
        projectName.getDocument().addDocumentListener(this);
47
        updateProjectFolder();
48
        validateDialog();
49
    }
50
    
51
    public synchronized void addChangeListener(ChangeListener l) {
52
        listeners.add(l);
53
    }
54
    
55
    public synchronized void removeChangeListener(ChangeListener l) {
56
        listeners.remove(l);
57
    }
58
    
59
    /** This method is called from within the constructor to
60
     * initialize the form.
61
     * WARNING: Do NOT modify this code. The content of this method is
62
     * always regenerated by the Form Editor.
63
     */
64
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
65
    private void initComponents() {
66
        java.awt.GridBagConstraints gridBagConstraints;
67
68
        jLabel1 = new javax.swing.JLabel();
69
        projectFolderLabel = new javax.swing.JLabel();
70
        projectName = new javax.swing.JTextField();
71
        projectFolder = new javax.swing.JTextField();
72
        alsoRenameFolder = new javax.swing.JCheckBox();
73
        jLabel3 = new javax.swing.JLabel();
74
        errorMessage = new javax.swing.JLabel();
75
76
        setLayout(new java.awt.GridBagLayout());
77
78
        gridBagConstraints = new java.awt.GridBagConstraints();
79
        gridBagConstraints.gridx = 0;
80
        gridBagConstraints.gridy = 1;
81
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
82
        add(jLabel1, gridBagConstraints);
83
84
        gridBagConstraints = new java.awt.GridBagConstraints();
85
        gridBagConstraints.gridx = 0;
86
        gridBagConstraints.gridy = 3;
87
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
88
        add(projectFolderLabel, gridBagConstraints);
89
90
        projectName.setColumns(20);
91
        gridBagConstraints = new java.awt.GridBagConstraints();
92
        gridBagConstraints.gridx = 1;
93
        gridBagConstraints.gridy = 1;
94
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
95
        add(projectName, gridBagConstraints);
96
97
        projectFolder.setEditable(false);
98
        gridBagConstraints = new java.awt.GridBagConstraints();
99
        gridBagConstraints.gridx = 1;
100
        gridBagConstraints.gridy = 3;
101
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
102
        add(projectFolder, gridBagConstraints);
103
104
        org.openide.awt.Mnemonics.setLocalizedText(alsoRenameFolder, org.openide.util.NbBundle.getMessage(DefaultProjectRenamePanel.class, "LBL_Also_Rename_Project_Folder"));
105
        alsoRenameFolder.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(0, 0, 0, 0)));
106
        alsoRenameFolder.setMargin(new java.awt.Insets(0, 0, 0, 0));
107
        gridBagConstraints = new java.awt.GridBagConstraints();
108
        gridBagConstraints.gridx = 0;
109
        gridBagConstraints.gridy = 2;
110
        gridBagConstraints.gridwidth = 2;
111
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
112
        add(alsoRenameFolder, gridBagConstraints);
113
114
        org.openide.awt.Mnemonics.setLocalizedText(jLabel3, NbBundle.getMessage(DefaultProjectRenamePanel.class, "LBL_Rename_Dialog_Text", ProjectUtils.getInformation(project).getDisplayName()));
115
        gridBagConstraints = new java.awt.GridBagConstraints();
116
        gridBagConstraints.gridwidth = 2;
117
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
118
        add(jLabel3, gridBagConstraints);
119
120
        gridBagConstraints = new java.awt.GridBagConstraints();
121
        gridBagConstraints.gridx = 0;
122
        gridBagConstraints.gridy = 4;
123
        gridBagConstraints.gridwidth = 2;
124
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
125
        add(errorMessage, gridBagConstraints);
126
127
    }
128
    // </editor-fold>//GEN-END:initComponents
129
    
130
    
131
    // Variables declaration - do not modify//GEN-BEGIN:variables
132
    private javax.swing.JCheckBox alsoRenameFolder;
133
    private javax.swing.JLabel errorMessage;
134
    private javax.swing.JLabel jLabel1;
135
    private javax.swing.JLabel jLabel3;
136
    private javax.swing.JTextField projectFolder;
137
    private javax.swing.JLabel projectFolderLabel;
138
    private javax.swing.JTextField projectName;
139
    // End of variables declaration//GEN-END:variables
140
    
141
    public String getNewName() {
142
        return projectName.getText();
143
    }
144
    
145
    public void changedUpdate(DocumentEvent e) {
146
        //ignored
147
    }
148
    
149
    public void insertUpdate(DocumentEvent e) {
150
        updateProjectFolder();
151
        validateDialog();
152
    }
153
    
154
    public void removeUpdate(DocumentEvent e) {
155
        updateProjectFolder();
156
        validateDialog();
157
    }
158
    
159
    private void updateProjectFolder() {
160
        File location = FileUtil.toFile(project.getProjectDirectory().getParent());
161
        File projectFolderFile = new File(location, projectName.getText());
162
        
163
        projectFolder.setText(projectFolderFile.getAbsolutePath());
164
    }
165
    
166
    public boolean isValid() {
167
        return " ".equals(errorMessage.getText());
168
    }
169
170
    private void validateDialog() {
171
        String newError = computeError();
172
        boolean changed = false;
173
        String currentError = errorMessage.getText();
174
        
175
        newError = newError != null ? newError : " ";
176
        changed = !currentError.equals(newError);
177
        
178
        errorMessage.setText(newError);
179
        
180
        if (changed) {
181
            ChangeListener[] listenersCopy;
182
                    
183
            synchronized (this) {
184
                listenersCopy = (ChangeListener[] ) listeners.toArray(new ChangeListener[0]);
185
            }
186
            ChangeEvent evt = new ChangeEvent(this);
187
            
188
            for (int cntr = 0; cntr < listenersCopy.length; cntr++) {
189
                listenersCopy[cntr].stateChanged(evt);
190
            }
191
        }
192
    }
193
    
194
    private String computeError() {
195
        File location = FileUtil.toFile(project.getProjectDirectory().getParent());
196
        File projectFolderFile = new File(location, projectName.getText());
197
        
198
        if (projectFolderFile.exists()) {
199
            return NbBundle.getMessage(ProjectCopyPanel.class, "ERR_Project_Folder_Exists");
200
        }
201
        
202
        return null;
203
    }
204
    
205
    public void showProgress() {
206
    }
207
    
208
}
(-)projects/projectuiapi/src/org/netbeans/modules/project/uiapi/ProjectCopyPanel.form (+162 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.0" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AuxValues>
5
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
6
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
7
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
8
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
9
    <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
10
  </AuxValues>
11
12
  <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
13
  <SubComponents>
14
    <Component class="javax.swing.JLabel" name="jLabel1">
15
      <Properties>
16
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
17
          <Connection code="NbBundle.getMessage(ProjectCopyPanel.class, &quot;LBL_Copy_Move_Dialog_Text&quot;, new Integer(isMove ? 1 : 0), ProjectUtils.getInformation(project).getDisplayName())" type="code"/>
18
        </Property>
19
      </Properties>
20
      <Constraints>
21
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
22
          <GridBagConstraints gridX="-1" gridY="-1" gridWidth="2" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="0.0"/>
23
        </Constraint>
24
      </Constraints>
25
    </Component>
26
    <Component class="javax.swing.JLabel" name="jLabel2">
27
      <Properties>
28
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
29
          <ResourceString bundle="org/netbeans/modules/project/ant/Bundle.properties" key="LBL_Project_Location" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
30
        </Property>
31
      </Properties>
32
      <Constraints>
33
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
34
          <GridBagConstraints gridX="0" gridY="2" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="12" insetsLeft="0" insetsBottom="0" insetsRight="12" anchor="17" weightX="0.0" weightY="0.0"/>
35
        </Constraint>
36
      </Constraints>
37
    </Component>
38
    <Component class="javax.swing.JTextField" name="projectLocation">
39
      <Properties>
40
        <Property name="columns" type="int" value="20"/>
41
      </Properties>
42
      <Constraints>
43
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
44
          <GridBagConstraints gridX="1" gridY="2" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="12" insetsLeft="0" insetsBottom="0" insetsRight="12" anchor="10" weightX="1.0" weightY="0.0"/>
45
        </Constraint>
46
      </Constraints>
47
    </Component>
48
    <Component class="javax.swing.JLabel" name="nameLabel">
49
      <Properties>
50
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
51
          <ResourceString bundle="org/netbeans/modules/project/ant/Bundle.properties" key="LBL_Project_Name" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
52
        </Property>
53
      </Properties>
54
      <Constraints>
55
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
56
          <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="12" insetsLeft="0" insetsBottom="0" insetsRight="12" anchor="17" weightX="0.0" weightY="0.0"/>
57
        </Constraint>
58
      </Constraints>
59
    </Component>
60
    <Component class="javax.swing.JTextField" name="projectName">
61
      <Properties>
62
        <Property name="columns" type="int" value="20"/>
63
      </Properties>
64
      <Constraints>
65
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
66
          <GridBagConstraints gridX="1" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="12" insetsLeft="0" insetsBottom="0" insetsRight="12" anchor="10" weightX="1.0" weightY="0.0"/>
67
        </Constraint>
68
      </Constraints>
69
    </Component>
70
    <Component class="javax.swing.JButton" name="browse">
71
      <Properties>
72
        <Property name="text" type="java.lang.String" value="..."/>
73
      </Properties>
74
      <Events>
75
        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="browseActionPerformed"/>
76
      </Events>
77
      <Constraints>
78
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
79
          <GridBagConstraints gridX="2" gridY="2" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="12" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
80
        </Constraint>
81
      </Constraints>
82
    </Component>
83
    <Component class="javax.swing.JLabel" name="jLabel4">
84
      <Properties>
85
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
86
          <ResourceString bundle="org/netbeans/modules/project/ant/Bundle.properties" key="LBL_Project_Folder" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
87
        </Property>
88
      </Properties>
89
      <Constraints>
90
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
91
          <GridBagConstraints gridX="0" gridY="3" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="12" insetsLeft="0" insetsBottom="0" insetsRight="12" anchor="17" weightX="0.0" weightY="0.0"/>
92
        </Constraint>
93
      </Constraints>
94
    </Component>
95
    <Component class="javax.swing.JTextField" name="projectFolder">
96
      <Properties>
97
        <Property name="editable" type="boolean" value="false"/>
98
      </Properties>
99
      <Constraints>
100
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
101
          <GridBagConstraints gridX="1" gridY="3" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="12" insetsLeft="0" insetsBottom="0" insetsRight="12" anchor="10" weightX="0.0" weightY="0.0"/>
102
        </Constraint>
103
      </Constraints>
104
    </Component>
105
    <Component class="javax.swing.JLabel" name="extSourcesWarning">
106
      <Constraints>
107
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
108
          <GridBagConstraints gridX="0" gridY="4" gridWidth="3" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="12" insetsLeft="0" insetsBottom="0" insetsRight="12" anchor="17" weightX="0.0" weightY="0.0"/>
109
        </Constraint>
110
      </Constraints>
111
    </Component>
112
    <Component class="javax.swing.JLabel" name="errorMessage">
113
      <Constraints>
114
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
115
          <GridBagConstraints gridX="0" gridY="5" gridWidth="3" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="12" insetsLeft="0" insetsBottom="0" insetsRight="12" anchor="17" weightX="0.0" weightY="0.0"/>
116
        </Constraint>
117
      </Constraints>
118
    </Component>
119
    <Container class="javax.swing.JPanel" name="jPanel1">
120
      <Constraints>
121
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
122
          <GridBagConstraints gridX="0" gridY="6" gridWidth="3" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="1.0"/>
123
        </Constraint>
124
      </Constraints>
125
126
      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
127
    </Container>
128
    <Container class="javax.swing.JPanel" name="progress">
129
      <Constraints>
130
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
131
          <GridBagConstraints gridX="0" gridY="7" gridWidth="3" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
132
        </Constraint>
133
      </Constraints>
134
135
      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
136
      <SubComponents>
137
        <Component class="javax.swing.JLabel" name="jLabel5">
138
          <Properties>
139
            <Property name="text" type="java.lang.String" value="Copying the project:"/>
140
          </Properties>
141
          <Constraints>
142
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
143
              <GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="0.0"/>
144
            </Constraint>
145
          </Constraints>
146
        </Component>
147
        <Container class="javax.swing.JPanel" name="jPanel3">
148
          <AuxValues>
149
            <AuxValue name="JavaCodeGenerator_InitCodePost" type="java.lang.String" value="jPanel3.add(ProgressHandleFactory.createProgressComponent(handle));"/>
150
          </AuxValues>
151
          <Constraints>
152
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
153
              <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="0.0"/>
154
            </Constraint>
155
          </Constraints>
156
157
          <Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
158
        </Container>
159
      </SubComponents>
160
    </Container>
161
  </SubComponents>
162
</Form>
(-)projects/projectuiapi/src/org/netbeans/modules/project/uiapi/ProjectCopyPanel.java (+360 lines)
Added Link Here
1
/*
2
 * J2SEProjectCopyTemporaryPanel.java
3
 *
4
 * Created on June 13, 2005, 4:43 PM
5
 */
6
7
package org.netbeans.modules.project.uiapi;
8
9
import java.io.File;
10
import java.util.ArrayList;
11
import java.util.Iterator;
12
import java.util.List;
13
import javax.swing.JFileChooser;
14
import javax.swing.event.ChangeEvent;
15
import javax.swing.event.ChangeListener;
16
import javax.swing.event.DocumentListener;
17
import javax.swing.event.DocumentEvent;
18
import org.netbeans.api.progress.ProgressHandle;
19
import org.netbeans.api.progress.ProgressHandleFactory;
20
import org.netbeans.api.project.Project;
21
import org.netbeans.spi.project.support.ProjectOperations;
22
import org.netbeans.api.project.ProjectUtils;
23
import org.openide.filesystems.FileObject;
24
import org.openide.filesystems.FileUtil;
25
import org.openide.util.NbBundle;
26
27
/**
28
 *
29
 * @author Jan Lahoda
30
 */
31
public class ProjectCopyPanel extends javax.swing.JPanel implements DocumentListener, DefaultProjectOperationsImplementation.InvalidablePanel {
32
    
33
    private Project project;
34
    private boolean isMove;
35
    
36
    private List listeners;
37
    private ProgressHandle handle;
38
    
39
    /**
40
     * Creates new form ProjectCopyPanel
41
     */
42
    public ProjectCopyPanel(ProgressHandle handle, Project project, boolean isMove) {
43
        this.project = project;
44
        this.isMove = isMove;
45
        this.listeners = new ArrayList();
46
        this.handle = handle;
47
        
48
        
49
        initComponents();
50
        setProject();
51
        projectName.getDocument().addDocumentListener(this);
52
        projectLocation.getDocument().addDocumentListener(this);
53
        
54
        progress.setVisible(false);
55
        
56
        if (isMove) {
57
            nameLabel.setVisible(false);
58
            projectName.setVisible(false);
59
        }
60
    }
61
    
62
    public synchronized void addChangeListener(ChangeListener l) {
63
        listeners.add(l);
64
    }
65
    
66
    public synchronized void removeChangeListener(ChangeListener l) {
67
        listeners.remove(l);
68
    }
69
    
70
    /** This method is called from within the constructor to
71
     * initialize the form.
72
     * WARNING: Do NOT modify this code. The content of this method is
73
     * always regenerated by the Form Editor.
74
     */
75
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
76
    private void initComponents() {
77
        java.awt.GridBagConstraints gridBagConstraints;
78
79
        jLabel1 = new javax.swing.JLabel();
80
        jLabel2 = new javax.swing.JLabel();
81
        projectLocation = new javax.swing.JTextField();
82
        nameLabel = new javax.swing.JLabel();
83
        projectName = new javax.swing.JTextField();
84
        browse = new javax.swing.JButton();
85
        jLabel4 = new javax.swing.JLabel();
86
        projectFolder = new javax.swing.JTextField();
87
        extSourcesWarning = new javax.swing.JLabel();
88
        errorMessage = new javax.swing.JLabel();
89
        jPanel1 = new javax.swing.JPanel();
90
        progress = new javax.swing.JPanel();
91
        jLabel5 = new javax.swing.JLabel();
92
        jPanel3 = new javax.swing.JPanel();
93
94
        setLayout(new java.awt.GridBagLayout());
95
96
        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, NbBundle.getMessage(ProjectCopyPanel.class, "LBL_Copy_Move_Dialog_Text", new Integer(isMove ? 1 : 0), ProjectUtils.getInformation(project).getDisplayName()));
97
        gridBagConstraints = new java.awt.GridBagConstraints();
98
        gridBagConstraints.gridwidth = 2;
99
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
100
        gridBagConstraints.weightx = 1.0;
101
        add(jLabel1, gridBagConstraints);
102
103
        org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(ProjectCopyPanel.class, "LBL_Project_Location"));
104
        gridBagConstraints = new java.awt.GridBagConstraints();
105
        gridBagConstraints.gridx = 0;
106
        gridBagConstraints.gridy = 2;
107
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
108
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 12);
109
        add(jLabel2, gridBagConstraints);
110
111
        projectLocation.setColumns(20);
112
        gridBagConstraints = new java.awt.GridBagConstraints();
113
        gridBagConstraints.gridx = 1;
114
        gridBagConstraints.gridy = 2;
115
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
116
        gridBagConstraints.weightx = 1.0;
117
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 12);
118
        add(projectLocation, gridBagConstraints);
119
120
        org.openide.awt.Mnemonics.setLocalizedText(nameLabel, org.openide.util.NbBundle.getMessage(ProjectCopyPanel.class, "LBL_Project_Name"));
121
        gridBagConstraints = new java.awt.GridBagConstraints();
122
        gridBagConstraints.gridx = 0;
123
        gridBagConstraints.gridy = 1;
124
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
125
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 12);
126
        add(nameLabel, gridBagConstraints);
127
128
        projectName.setColumns(20);
129
        gridBagConstraints = new java.awt.GridBagConstraints();
130
        gridBagConstraints.gridx = 1;
131
        gridBagConstraints.gridy = 1;
132
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
133
        gridBagConstraints.weightx = 1.0;
134
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 12);
135
        add(projectName, gridBagConstraints);
136
137
        org.openide.awt.Mnemonics.setLocalizedText(browse, "...");
138
        browse.addActionListener(new java.awt.event.ActionListener() {
139
            public void actionPerformed(java.awt.event.ActionEvent evt) {
140
                browseActionPerformed(evt);
141
            }
142
        });
143
144
        gridBagConstraints = new java.awt.GridBagConstraints();
145
        gridBagConstraints.gridx = 2;
146
        gridBagConstraints.gridy = 2;
147
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
148
        add(browse, gridBagConstraints);
149
150
        org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(ProjectCopyPanel.class, "LBL_Project_Folder"));
151
        gridBagConstraints = new java.awt.GridBagConstraints();
152
        gridBagConstraints.gridx = 0;
153
        gridBagConstraints.gridy = 3;
154
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
155
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 12);
156
        add(jLabel4, gridBagConstraints);
157
158
        projectFolder.setEditable(false);
159
        gridBagConstraints = new java.awt.GridBagConstraints();
160
        gridBagConstraints.gridx = 1;
161
        gridBagConstraints.gridy = 3;
162
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
163
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 12);
164
        add(projectFolder, gridBagConstraints);
165
166
        gridBagConstraints = new java.awt.GridBagConstraints();
167
        gridBagConstraints.gridx = 0;
168
        gridBagConstraints.gridy = 4;
169
        gridBagConstraints.gridwidth = 3;
170
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
171
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 12);
172
        add(extSourcesWarning, gridBagConstraints);
173
174
        gridBagConstraints = new java.awt.GridBagConstraints();
175
        gridBagConstraints.gridx = 0;
176
        gridBagConstraints.gridy = 5;
177
        gridBagConstraints.gridwidth = 3;
178
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
179
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 12);
180
        add(errorMessage, gridBagConstraints);
181
182
        gridBagConstraints = new java.awt.GridBagConstraints();
183
        gridBagConstraints.gridx = 0;
184
        gridBagConstraints.gridy = 6;
185
        gridBagConstraints.gridwidth = 3;
186
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
187
        gridBagConstraints.weightx = 1.0;
188
        gridBagConstraints.weighty = 1.0;
189
        add(jPanel1, gridBagConstraints);
190
191
        progress.setLayout(new java.awt.GridBagLayout());
192
193
        org.openide.awt.Mnemonics.setLocalizedText(jLabel5, "Copying the project:");
194
        gridBagConstraints = new java.awt.GridBagConstraints();
195
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
196
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
197
        gridBagConstraints.weightx = 1.0;
198
        progress.add(jLabel5, gridBagConstraints);
199
200
        jPanel3.add(ProgressHandleFactory.createProgressComponent(handle));
201
        gridBagConstraints = new java.awt.GridBagConstraints();
202
        gridBagConstraints.gridx = 0;
203
        gridBagConstraints.gridy = 1;
204
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
205
        gridBagConstraints.weightx = 1.0;
206
        progress.add(jPanel3, gridBagConstraints);
207
208
        gridBagConstraints = new java.awt.GridBagConstraints();
209
        gridBagConstraints.gridx = 0;
210
        gridBagConstraints.gridy = 7;
211
        gridBagConstraints.gridwidth = 3;
212
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
213
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
214
        add(progress, gridBagConstraints);
215
216
    }
217
    // </editor-fold>//GEN-END:initComponents
218
219
    private void browseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseActionPerformed
220
// TODO add your handling code here:
221
        File current = new File(projectFolder.getText());
222
        JFileChooser chooser = new JFileChooser(current);
223
        
224
        chooser.setMultiSelectionEnabled(false);
225
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
226
        
227
        if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
228
            projectLocation.setText(chooser.getSelectedFile().getAbsolutePath());
229
        }
230
    }//GEN-LAST:event_browseActionPerformed
231
    
232
    
233
    // Variables declaration - do not modify//GEN-BEGIN:variables
234
    private javax.swing.JButton browse;
235
    private javax.swing.JLabel errorMessage;
236
    private javax.swing.JLabel extSourcesWarning;
237
    private javax.swing.JLabel jLabel1;
238
    private javax.swing.JLabel jLabel2;
239
    private javax.swing.JLabel jLabel4;
240
    private javax.swing.JLabel jLabel5;
241
    private javax.swing.JPanel jPanel1;
242
    private javax.swing.JPanel jPanel3;
243
    private javax.swing.JLabel nameLabel;
244
    private javax.swing.JPanel progress;
245
    private javax.swing.JTextField projectFolder;
246
    private javax.swing.JTextField projectLocation;
247
    private javax.swing.JTextField projectName;
248
    // End of variables declaration//GEN-END:variables
249
    
250
    private void setProject() {
251
        FileObject parent = project.getProjectDirectory().getParent();
252
        File parentFile = FileUtil.toFile(parent);
253
        
254
        projectLocation.setText(parentFile.getAbsolutePath());
255
        projectName.setText(isMove ? project.getProjectDirectory().getNameExt() : project.getProjectDirectory().getNameExt() + "Copy");
256
        updateProjectFolder();
257
        validateDialog();
258
        
259
        if (hasExternalSources() && !isMove) {
260
            extSourcesWarning.setText(NbBundle.getMessage(ProjectCopyPanel.class, "WRN_External_Sources"));
261
        }
262
    }
263
    
264
    private boolean hasExternalSources() {
265
        List/*<FileObject>*/ files = ProjectOperations.getDataFiles(project);
266
        
267
        for (Iterator i = files.iterator(); i.hasNext(); ) {
268
            FileObject file = (FileObject) i.next();
269
            
270
            if (!FileUtil.isParentOf(project.getProjectDirectory(), file))
271
                return true;
272
        }
273
        
274
        return false;
275
    }
276
    
277
    public String getNewName() {
278
        return projectName.getText();
279
    }
280
    
281
    public File getNewDirectory() {
282
        return new File(projectLocation.getText());
283
    }
284
    
285
    public void changedUpdate(DocumentEvent e) {
286
        //ignored
287
    }
288
    
289
    public void insertUpdate(DocumentEvent e) {
290
        updateProjectFolder();
291
        validateDialog();
292
    }
293
    
294
    public void removeUpdate(DocumentEvent e) {
295
        updateProjectFolder();
296
        validateDialog();
297
    }
298
    
299
    private void updateProjectFolder() {
300
        File location = new File(projectLocation.getText());
301
        File projectFolderFile = new File(location, projectName.getText());
302
        
303
        projectFolder.setText(projectFolderFile.getAbsolutePath());
304
    }
305
    
306
    public boolean isValid() {
307
        return " ".equals(errorMessage.getText());
308
    }
309
310
    private void validateDialog() {
311
        String newError = computeError();
312
        boolean changed = false;
313
        String currentError = errorMessage.getText();
314
        
315
        newError = newError != null ? newError : " ";
316
        changed = !currentError.equals(newError);
317
        
318
        errorMessage.setText(newError);
319
        
320
        if (changed) {
321
            ChangeListener[] listenersCopy;
322
                    
323
            synchronized (this) {
324
                listenersCopy = (ChangeListener[] ) listeners.toArray(new ChangeListener[0]);
325
            }
326
            ChangeEvent evt = new ChangeEvent(this);
327
            
328
            for (int cntr = 0; cntr < listenersCopy.length; cntr++) {
329
                listenersCopy[cntr].stateChanged(evt);
330
            }
331
        }
332
    }
333
    
334
    private String computeError() {
335
        File location = new File(projectLocation.getText());
336
        
337
        System.err.println("location = " + location );
338
        if (!location.exists()) {
339
            return NbBundle.getMessage(ProjectCopyPanel.class, "ERR_Location_Does_Not_Exist");
340
        }
341
        
342
        File projectFolderFile = new File(location, projectName.getText());
343
        
344
        System.err.println("projectFolderFile = " + projectFolderFile );
345
        System.err.println("projectFolderFile.exists()=" + projectFolderFile.exists());
346
        if (projectFolderFile.exists()) {
347
            return NbBundle.getMessage(ProjectCopyPanel.class, "ERR_Project_Folder_Exists");
348
        }
349
        
350
        return null;
351
    }
352
    
353
    public void showProgress() {
354
        projectFolder.setEnabled(false);
355
        projectLocation.setEnabled(false);
356
        projectName.setEnabled(false);
357
        progress.setVisible(true);
358
        browse.setEnabled(false);
359
    }
360
}
(-)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/freeform/src/org/netbeans/modules/ant/freeform/Actions.java (-1 / +2 lines)
Lines 40-45 Link Here
40
import org.netbeans.spi.project.ActionProvider;
40
import org.netbeans.spi.project.ActionProvider;
41
import org.netbeans.spi.project.support.ant.AntProjectHelper;
41
import org.netbeans.spi.project.support.ant.AntProjectHelper;
42
import org.netbeans.spi.project.ui.support.CommonProjectActions;
42
import org.netbeans.spi.project.ui.support.CommonProjectActions;
43
import org.netbeans.spi.project.ui.support.DefaultProjectOperations;
43
import org.netbeans.spi.project.ui.support.ProjectSensitiveActions;
44
import org.netbeans.spi.project.ui.support.ProjectSensitiveActions;
44
import org.openide.DialogDisplayer;
45
import org.openide.DialogDisplayer;
45
import org.openide.ErrorManager;
46
import org.openide.ErrorManager;
Lines 173-179 Link Here
173
    
174
    
174
    public void invokeAction(String command, Lookup context) throws IllegalArgumentException {
175
    public void invokeAction(String command, Lookup context) throws IllegalArgumentException {
175
        if (COMMAND_DELETE.equals(command)) {
176
        if (COMMAND_DELETE.equals(command)) {
176
            project.helper().performDefaultDeleteOperation();
177
            DefaultProjectOperations.performDefaultDeleteOperation(project);
177
            return ;
178
            return ;
178
        }
179
        }
179
        Element genldata = project.helper().getPrimaryConfigurationData(true);
180
        Element genldata = project.helper().getPrimaryConfigurationData(true);
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/FreeformProjectOperations.java (-3 / +2 lines)
Lines 16-26 Link Here
16
import java.io.File;
16
import java.io.File;
17
import java.io.IOException;
17
import java.io.IOException;
18
import java.util.ArrayList;
18
import java.util.ArrayList;
19
import java.util.Collections;
20
import java.util.Iterator;
19
import java.util.Iterator;
21
import java.util.List;
20
import java.util.List;
22
import org.netbeans.modules.ant.freeform.spi.support.Util;
21
import org.netbeans.modules.ant.freeform.spi.support.Util;
23
import org.netbeans.spi.project.ProjectOperationsImplementation.DeleteOperationImplementation;
22
import org.netbeans.spi.project.DeleteOperationImplementation;
24
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
23
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
25
import org.openide.filesystems.FileObject;
24
import org.openide.filesystems.FileObject;
26
import org.openide.filesystems.FileUtil;
25
import org.openide.filesystems.FileUtil;
Lines 101-107 Link Here
101
        }
100
        }
102
    }
101
    }
103
    
102
    
104
    public void performClean() throws IOException {
103
    public void notifyDeleting() throws IOException {
105
        //TODO: invoke clean action if bound.
104
        //TODO: invoke clean action if bound.
106
    }
105
    }
107
    
106
    
(-)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
(-)ant/project/src/org/netbeans/modules/project/ant/AntBasedProjectFactorySingleton.java (-1 / +1 lines)
Lines 138-144 Link Here
138
            return null;
138
            return null;
139
        }
139
        }
140
        File projectDiskFile = FileUtil.toFile(projectFile);
140
        File projectDiskFile = FileUtil.toFile(projectFile);
141
        assert projectDiskFile != null && projectDiskFile.exists();
141
        assert projectDiskFile != null && projectDiskFile.exists() : "projectDiskFile=" + String.valueOf(projectDiskFile) + ", projectDirectory=" + FileUtil.getFileDisplayName(projectDirectory);
142
        Document projectXml;
142
        Document projectXml;
143
        try {
143
        try {
144
            projectXml = XMLUtil.parse(new InputSource(projectDiskFile.toURI().toString()), false, true, Util.defaultErrorHandler(), null);
144
            projectXml = XMLUtil.parse(new InputSource(projectDiskFile.toURI().toString()), false, true, Util.defaultErrorHandler(), null);
(-)ant/project/src/org/netbeans/modules/project/ant/Bundle.properties (-13 lines)
Lines 18-33 Link Here
18
18
19
# UserQuestionHandler
19
# UserQuestionHandler
20
TITLE_CannotWriteFile=Cannot Write to File
20
TITLE_CannotWriteFile=Cannot Write to File
21
22
#DefaultAntProjectOperations:
23
LBL_Progress_Cleaning_Project=Cleaning Project
24
LBL_Progress_Deleting_File=Deleting {0}
25
LBL_Project_cannot_be_deleted.=Project {0} cannot be deleted.
26
LBL_Delete_Project_Caption=Delete Project
27
LBL_Deleting_Project=Deleting Project\:
28
#currently not used:
29
#LBL_Project_Deletion_in_Progress_Caption=Project Deletion in Progress
30
31
#DefaultAntProjectDeletePanel:
32
LBL_Pre_Delete_Warning=Are you sure you want to delete project "{0}"?
33
LBL_Delete_Also_Sources=&Also Delete Sources Under "{0}" folder.
(-)ant/project/src/org/netbeans/modules/project/ant/DefaultAntProjectDeletePanel.form (-50 lines)
Removed Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.0" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AuxValues>
5
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
6
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
7
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
8
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
9
    <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,46,0,0,1,-112"/>
10
  </AuxValues>
11
12
  <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
13
  <SubComponents>
14
    <Component class="javax.swing.JTextArea" name="warningText">
15
      <Properties>
16
        <Property name="editable" type="boolean" value="false"/>
17
        <Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
18
          <Connection code="javax.swing.UIManager.getFont(&quot;Label.font&quot;)" type="code"/>
19
        </Property>
20
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
21
          <Connection code="getWarningText()" type="code"/>
22
        </Property>
23
        <Property name="disabledTextColor" type="java.awt.Color" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
24
          <Connection code="javax.swing.UIManager.getColor(&quot;Label.foreground&quot;)" type="code"/>
25
        </Property>
26
        <Property name="opaque" type="boolean" value="false"/>
27
      </Properties>
28
      <Constraints>
29
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
30
          <GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="12" insetsLeft="12" insetsBottom="0" insetsRight="12" anchor="18" weightX="1.0" weightY="0.0"/>
31
        </Constraint>
32
      </Constraints>
33
    </Component>
34
    <Component class="javax.swing.JCheckBox" name="deleteSourcesCheckBox">
35
      <Properties>
36
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
37
          <Connection code="getCheckboxText()" type="code"/>
38
        </Property>
39
        <Property name="enabled" type="boolean" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
40
          <Connection code="enableCheckbox" type="code"/>
41
        </Property>
42
      </Properties>
43
      <Constraints>
44
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
45
          <GridBagConstraints gridX="0" gridY="3" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="12" insetsLeft="12" insetsBottom="0" insetsRight="12" anchor="17" weightX="0.0" weightY="0.0"/>
46
        </Constraint>
47
      </Constraints>
48
    </Component>
49
  </SubComponents>
50
</Form>
(-)ant/project/src/org/netbeans/modules/project/ant/DefaultAntProjectDeletePanel.java (-101 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.modules.project.ant;
15
16
import java.awt.Component;
17
import java.awt.Window;
18
import java.text.MessageFormat;
19
import java.util.Iterator;
20
import java.util.List;
21
import org.openide.filesystems.FileObject;
22
import org.openide.filesystems.FileUtil;
23
import org.openide.util.NbBundle;
24
25
/**
26
 *
27
 * @author Jan Lahoda
28
 */
29
final class DefaultAntProjectDeletePanel extends javax.swing.JPanel {
30
    
31
    private String projectDisplaName;
32
    private String projectFolder;
33
    private boolean enableCheckbox;
34
    
35
    /**
36
     * Creates new form DefaultAntProjectDeletePanel
37
     */
38
    public DefaultAntProjectDeletePanel(String projectDisplaName, String projectFolder, boolean enableCheckbox) {
39
        this.projectDisplaName = projectDisplaName;
40
        this.projectFolder = projectFolder;
41
        this.enableCheckbox = enableCheckbox;
42
        initComponents();
43
    }
44
    
45
    /** This method is called from within the constructor to
46
     * initialize the form.
47
     * WARNING: Do NOT modify this code. The content of this method is
48
     * always regenerated by the Form Editor.
49
     */
50
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
51
    private void initComponents() {
52
        java.awt.GridBagConstraints gridBagConstraints;
53
54
        warningText = new javax.swing.JTextArea();
55
        deleteSourcesCheckBox = new javax.swing.JCheckBox();
56
57
        setLayout(new java.awt.GridBagLayout());
58
59
        warningText.setEditable(false);
60
        warningText.setFont(javax.swing.UIManager.getFont("Label.font"));
61
        warningText.setText(getWarningText());
62
        warningText.setDisabledTextColor(javax.swing.UIManager.getColor("Label.foreground"));
63
        warningText.setOpaque(false);
64
        gridBagConstraints = new java.awt.GridBagConstraints();
65
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
66
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
67
        gridBagConstraints.weightx = 1.0;
68
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 12);
69
        add(warningText, gridBagConstraints);
70
71
        org.openide.awt.Mnemonics.setLocalizedText(deleteSourcesCheckBox, getCheckboxText());
72
        deleteSourcesCheckBox.setEnabled(enableCheckbox);
73
        gridBagConstraints = new java.awt.GridBagConstraints();
74
        gridBagConstraints.gridx = 0;
75
        gridBagConstraints.gridy = 3;
76
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
77
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 12);
78
        add(deleteSourcesCheckBox, gridBagConstraints);
79
80
    }
81
    // </editor-fold>//GEN-END:initComponents
82
    
83
    
84
    // Variables declaration - do not modify//GEN-BEGIN:variables
85
    private javax.swing.JCheckBox deleteSourcesCheckBox;
86
    private javax.swing.JTextArea warningText;
87
    // End of variables declaration//GEN-END:variables
88
    
89
    public boolean isDeleteSources() {
90
        return deleteSourcesCheckBox.isSelected();
91
    }
92
93
    private String getWarningText() {
94
        return NbBundle.getMessage(DefaultAntProjectDeletePanel.class, "LBL_Pre_Delete_Warning", new Object[] {projectDisplaName});
95
    }
96
    
97
    private String getCheckboxText() {
98
        return NbBundle.getMessage(DefaultAntProjectDeletePanel.class, "LBL_Delete_Also_Sources", new Object[] {projectFolder});
99
    }
100
    
101
}
(-)ant/project/src/org/netbeans/modules/project/ant/DefaultAntProjectOperations.java (-283 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.modules.project.ant;
15
16
import java.awt.Dialog;
17
import java.awt.GridBagConstraints;
18
import java.awt.Insets;
19
import java.io.IOException;
20
import java.text.MessageFormat;
21
import java.util.ArrayList;
22
import java.util.Collections;
23
import java.util.Iterator;
24
import java.util.List;
25
import javax.swing.JComponent;
26
import javax.swing.JLabel;
27
import javax.swing.JPanel;
28
import javax.swing.SwingUtilities;
29
import org.netbeans.api.progress.ProgressHandle;
30
import org.netbeans.api.progress.ProgressHandleFactory;
31
import org.netbeans.api.project.Project;
32
import org.netbeans.api.project.ProjectUtils;
33
import org.netbeans.api.project.ui.OpenProjects;
34
import org.netbeans.api.project.ProjectOperations;
35
import org.netbeans.spi.project.support.ant.AntProjectHelper;
36
import org.openide.DialogDescriptor;
37
import org.openide.DialogDisplayer;
38
import org.openide.ErrorManager;
39
import org.openide.NotifyDescriptor;
40
import org.openide.filesystems.FileObject;
41
import org.openide.filesystems.FileUtil;
42
import org.openide.util.HelpCtx;
43
import org.openide.util.NbBundle;
44
import org.openide.util.RequestProcessor;
45
46
47
/**
48
 *
49
 * @author Jan Lahoda
50
 */
51
public final class DefaultAntProjectOperations {
52
    
53
    private static final ErrorManager ERR = ErrorManager.getDefault(); // NOI18N
54
    
55
    private DefaultAntProjectOperations() {
56
    }
57
    
58
    private static String getDisplayName(Project project) {
59
        return ProjectUtils.getInformation(project).getDisplayName();
60
    }
61
 
62
    //<editor-fold defaultstate="collapsed" desc="Delete Operation">
63
    /**
64
     * @return true if success
65
     */
66
    private static boolean performDelete(AntProjectHelper helper, Project project, List/*FileObject>*/ toDelete, ProgressHandle handle) {
67
        try {
68
            handle.start(toDelete.size() + 1 /*clean*/);
69
            
70
            int done = 0;
71
            
72
            handle.progress(NbBundle.getMessage(DefaultAntProjectOperations.class, "LBL_Progress_Cleaning_Project"));
73
            
74
            ProjectOperations.getDefault().performClean(project);
75
            
76
            handle.progress(++done);
77
            
78
            for (Iterator i = toDelete.iterator(); i.hasNext(); ) {
79
                FileObject f = (FileObject) i.next();
80
                
81
                handle.progress(NbBundle.getMessage(DefaultAntProjectOperations.class, "LBL_Progress_Deleting_File", new Object[] {FileUtil.getFileDisplayName(f)}));
82
                
83
                if (f != null)
84
                    f.delete();
85
                
86
                handle.progress(++done);
87
            }
88
            
89
            FileObject projectFolder = project.getProjectDirectory();
90
            
91
            if (projectFolder.getChildren().length == 0) {
92
                //empty, delete:
93
                projectFolder.delete();
94
            }
95
            
96
            handle.finish();
97
            
98
            ProjectOperations.getDefault().notifyDeleted(project);
99
            return true;
100
        } catch (IOException e) {
101
            String displayName = getDisplayName(project);
102
            String message     = NbBundle.getMessage(DefaultAntProjectOperations.class, "LBL_Project_cannot_be_deleted.", new Object[] {displayName});
103
            
104
            ErrorManager.getDefault().annotate(e, message);
105
            ErrorManager.getDefault().notify(ErrorManager.USER, e);
106
            
107
            return false;
108
        }
109
    }
110
    
111
    public static void deleteProject(final Project project) {
112
        Runnable r = new Runnable() {
113
            public void run() {
114
                deleteProject(project, new GUIUserInputHandler());
115
            }
116
        };
117
        
118
        if (SwingUtilities.isEventDispatchThread()) {
119
            r.run();
120
        } else {
121
            SwingUtilities.invokeLater(r);
122
        }
123
    }
124
    
125
    /*package private*/static void deleteProject(final Project project, final UserInputHandler handler) {
126
        String displayName = getDisplayName(project);
127
        FileObject projectFolder = project.getProjectDirectory();
128
        
129
        final AntProjectHelper helper = AntBasedProjectFactorySingleton.getHelperFor(project);
130
        
131
        assert helper != null;
132
        
133
        if (ERR.isLoggable(ErrorManager.INFORMATIONAL)) {
134
            ERR.log(ErrorManager.INFORMATIONAL, "delete started: " + displayName); // NOI18N
135
        }
136
        
137
        List/*<FileObject>*/ metadataFiles = ProjectOperations.getDefault().getMetadataFiles(project);
138
        List/*<FileObject>*/ dataFiles = ProjectOperations.getDefault().getDataFiles(project);
139
        List/*<FileObject>*/ allFiles = new ArrayList/*<FileObject>*/();
140
        
141
        allFiles.addAll(metadataFiles);
142
        allFiles.addAll(dataFiles);
143
        
144
        for (Iterator i = allFiles.iterator(); i.hasNext(); ) {
145
            FileObject f = (FileObject) i.next();
146
            
147
            if (!FileUtil.isParentOf(projectFolder, f)) {
148
                i.remove();
149
            }
150
        }
151
        
152
        int userAnswer = handler.userConfirmation(displayName, FileUtil.getFileDisplayName(projectFolder), !dataFiles.isEmpty());
153
        List/*<FileObject>*/ toDeleteImpl = null;
154
        
155
        switch (userAnswer) {
156
            case UserInputHandler.USER_CANCEL:
157
                return ;
158
            case UserInputHandler.USER_OK_METADATA:
159
                toDeleteImpl = metadataFiles;
160
                break;
161
            case UserInputHandler.USER_OK_ALL:
162
                toDeleteImpl = allFiles;
163
                break;
164
            default:
165
                throw new IllegalStateException("Invalid user answer: " + userAnswer);
166
        }
167
        
168
        final ProgressHandle handle = handler.getProgressHandle();
169
        final List/*<FileObject>*/ toDelete = toDeleteImpl;
170
        final boolean[] result = new boolean[1];
171
        
172
        OpenProjects.getDefault().close(new Project[] {project});
173
        
174
        handler.delete(new Runnable() {
175
            public void run() {
176
                result[0] = performDelete(helper, project, toDelete, handle);
177
            }
178
        });
179
        
180
        if (ERR.isLoggable(ErrorManager.INFORMATIONAL)) {
181
            ERR.log(ErrorManager.INFORMATIONAL, "delete done: " + displayName); // NOI18N
182
        }
183
    }
184
    
185
    /*package private*/interface UserInputHandler {
186
        
187
        public int USER_CANCEL = 1;
188
        public int USER_OK_METADATA = 2;
189
        public int USER_OK_ALL = 3;
190
        
191
        public abstract int userConfirmation(String displayName, String projectFolder, boolean enableData);
192
        
193
        public abstract ProgressHandle getProgressHandle();
194
        
195
        public abstract void delete(Runnable r);
196
        
197
    }
198
    
199
    private static final class GUIUserInputHandler implements UserInputHandler {
200
        
201
        public int userConfirmation(String displayName, String projectFolder, boolean enableData) {
202
            DefaultAntProjectDeletePanel deletePanel = new DefaultAntProjectDeletePanel(displayName, projectFolder, enableData);
203
            
204
            String caption = NbBundle.getMessage(DefaultAntProjectOperations.class, "LBL_Delete_Project_Caption");
205
            
206
            NotifyDescriptor nd = new NotifyDescriptor.Confirmation(deletePanel, caption, NotifyDescriptor.YES_NO_OPTION);
207
            
208
            if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.YES_OPTION) {
209
                if (deletePanel.isDeleteSources()) {
210
                    return USER_OK_ALL;
211
                } else {
212
                    return USER_OK_METADATA;
213
                }
214
            } else {
215
                return USER_CANCEL;
216
            }
217
        }
218
        
219
        private ProgressHandle handle = null;
220
        
221
        public synchronized ProgressHandle getProgressHandle() {
222
            if (handle == null) {
223
                handle = ProgressHandleFactory.createHandle(NbBundle.getMessage(DefaultAntProjectOperations.class, "LBL_Delete_Project_Caption"));
224
            }
225
            
226
            return handle;
227
        }
228
        
229
        public void delete(final Runnable r) {
230
            RequestProcessor.getDefault().post(new Runnable() {
231
                public void run() {
232
                    r.run();
233
		    
234
                    if (ERR.isLoggable(ErrorManager.INFORMATIONAL)) {
235
                        ERR.log(ErrorManager.INFORMATIONAL, "delete finished"); // NOI18N
236
                    }
237
                }
238
            });
239
        }
240
        
241
    }
242
    
243
    private static JComponent createProgressDialog(ProgressHandle handle) {
244
        JPanel dialog = new JPanel();
245
        
246
        GridBagConstraints gridBagConstraints;
247
        
248
        JLabel jLabel1 = new JLabel();
249
        JComponent progress = ProgressHandleFactory.createProgressComponent(handle);
250
        JPanel padding = new JPanel();
251
        
252
        dialog.setLayout(new java.awt.GridBagLayout());
253
        
254
        jLabel1.setText(NbBundle.getMessage(DefaultAntProjectOperations.class, "LBL_Deleting_Project"));
255
        gridBagConstraints = new GridBagConstraints();
256
        gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
257
        gridBagConstraints.insets = new Insets(12, 12, 0, 12);
258
        dialog.add(jLabel1, gridBagConstraints);
259
        
260
        gridBagConstraints = new GridBagConstraints();
261
        gridBagConstraints.gridx = 0;
262
        gridBagConstraints.gridy = 1;
263
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
264
        gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
265
        gridBagConstraints.weightx = 1.0;
266
        gridBagConstraints.insets = new Insets(12, 12, 0, 12);
267
        dialog.add(progress, gridBagConstraints);
268
269
        gridBagConstraints = new GridBagConstraints();
270
        gridBagConstraints.gridx = 0;
271
        gridBagConstraints.gridy = 2;
272
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL | GridBagConstraints.VERTICAL;
273
        gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
274
        gridBagConstraints.weightx = 1.0;
275
        gridBagConstraints.weighty = 1.0;
276
        gridBagConstraints.insets = new Insets(12, 12, 12, 12);
277
        dialog.add(padding, gridBagConstraints);
278
        
279
        return dialog;
280
    }
281
    //</editor-fold>
282
    
283
}
(-)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/test/unit/src/org/netbeans/modules/project/ant/DefaultAntProjectOperationsTest.java (-195 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.modules.project.ant;
15
16
import java.io.File;
17
import java.util.Arrays;
18
import java.util.Collections;
19
import java.util.List;
20
import org.netbeans.api.progress.ProgressHandle;
21
import org.netbeans.api.progress.ProgressHandleFactory;
22
import org.netbeans.api.project.Project;
23
import org.netbeans.api.project.ProjectManager;
24
import org.netbeans.api.project.TestUtil;
25
import org.netbeans.junit.NbTestCase;
26
import org.netbeans.modules.project.ant.DefaultAntProjectOperations.UserInputHandler;
27
import org.netbeans.modules.project.ui.OpenProjectsTrampolineImpl;
28
import org.netbeans.spi.project.support.ant.AntBasedTestUtil;
29
import org.netbeans.spi.project.support.ant.AntBasedTestUtil.DeleteProjectOperationImpl;
30
import org.netbeans.spi.project.support.ant.AntProjectHelperTest;
31
import org.openide.filesystems.FileObject;
32
import org.openide.filesystems.FileUtil;
33
34
35
/**
36
 *
37
 * @author Jan Lahoda
38
 */
39
public class DefaultAntProjectOperationsTest extends NbTestCase {
40
    
41
    public DefaultAntProjectOperationsTest(String testName) {
42
        super(testName);
43
    }
44
45
    private FileObject scratch;
46
    private FileObject projdir;
47
    private Project prj;
48
    private File projectDirectory;
49
    
50
    private void createProject(FileObject projdir) throws Exception {
51
        TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/project.xml"), projdir, "nbproject/project.xml");
52
        TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/private.xml"), projdir, "nbproject/private/private.xml");
53
        TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/project.properties"), projdir, "nbproject/project.properties");
54
        TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/private.properties"), projdir, "nbproject/private/private.properties");
55
        TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/test.txt"), projdir, "src/test/test.txt");
56
        TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/global.properties"), scratch, "userdir/build.properties");
57
    }
58
    
59
    protected void setUp() throws Exception {
60
        scratch = TestUtil.makeScratchDir(this);
61
        projdir = scratch.createFolder("proj");
62
        
63
        createProject(projdir);
64
        
65
        TestUtil.setLookup(new Object[] {
66
            AntBasedTestUtil.testAntBasedProjectType(),
67
                    new OpenProjectsTrampolineImpl(),
68
        });
69
        
70
        prj = ProjectManager.getDefault().findProject(projdir);
71
        
72
        assertNotNull(prj);
73
        
74
        projectDirectory = FileUtil.toFile(projdir);
75
        
76
        assertNotNull(projectDirectory);
77
    }
78
79
    public void testDeleteProjectDeleteAll() throws Exception {
80
        TestUserInputHandler handler = new TestUserInputHandler(UserInputHandler.USER_OK_ALL);
81
        
82
        DefaultAntProjectOperations.deleteProject(prj, handler);
83
        
84
        assertTrue(handler.userConfirmationCalled);
85
        assertTrue(handler.enableData);
86
        assertTrue(handler.getProgressHandleCalled);
87
        assertTrue(handler.deleteCalled);
88
        
89
        assertFalse(projectDirectory.exists());
90
    }
91
92
    public void testDeleteProjectDeleteMetadata() throws Exception {
93
        TestUserInputHandler handler = new TestUserInputHandler(UserInputHandler.USER_OK_METADATA);
94
        
95
        DefaultAntProjectOperations.deleteProject(prj, handler);
96
        
97
        assertTrue(handler.userConfirmationCalled);
98
        assertTrue(handler.enableData);
99
        assertTrue(handler.getProgressHandleCalled);
100
        assertTrue(handler.deleteCalled);
101
        
102
        assertTrue(projectDirectory.exists());
103
        assertTrue(Arrays.equals(new String[] {"src"}, projectDirectory.list()));
104
    }
105
    
106
    public void testDeleteProjectDoNotDelete() throws Exception {
107
        TestUserInputHandler handler = new TestUserInputHandler(UserInputHandler.USER_CANCEL);
108
        
109
        DefaultAntProjectOperations.deleteProject(prj, handler);
110
        
111
        assertTrue(handler.userConfirmationCalled);
112
        assertTrue(handler.enableData);
113
        assertFalse(handler.getProgressHandleCalled);
114
        assertFalse(handler.deleteCalled);
115
        
116
        assertTrue(projectDirectory.exists());
117
        List/*<String>*/ items = Arrays.asList(projectDirectory.list());
118
        Collections.sort(items);
119
        assertEquals(Arrays.asList(new String[] {"nbproject", "src"}), items);
120
    }
121
    
122
    public void testDeleteProjectNestedProject() throws Exception {
123
        FileObject projdir2 = projdir.createFolder("proj2");
124
        
125
        createProject(projdir2);
126
        
127
        TestUserInputHandler handler = new TestUserInputHandler(UserInputHandler.USER_OK_ALL);
128
        
129
        DefaultAntProjectOperations.deleteProject(prj, handler);
130
        
131
        assertTrue(handler.userConfirmationCalled);
132
        assertTrue(handler.enableData);
133
        assertTrue(handler.getProgressHandleCalled);
134
        assertTrue(handler.deleteCalled);
135
        
136
        assertTrue(projectDirectory.exists());
137
        assertTrue(Arrays.equals(new String[] {"proj2"}, projectDirectory.list()));
138
    }
139
    
140
    public void testDeleteProjectExternalSources() throws Exception {
141
        FileObject extDir = scratch.createFolder("external");
142
        File extDirFile = FileUtil.toFile(extDir);
143
        
144
        assertNotNull(extDirFile);
145
        
146
        ((DeleteProjectOperationImpl) prj.getLookup().lookup(DeleteProjectOperationImpl.class)).setExternalFile(extDir);
147
        
148
        TestUserInputHandler handler = new TestUserInputHandler(UserInputHandler.USER_OK_ALL);
149
        
150
        DefaultAntProjectOperations.deleteProject(prj, handler);
151
        
152
        assertTrue(handler.userConfirmationCalled);
153
        assertTrue(handler.enableData);
154
        assertTrue(handler.getProgressHandleCalled);
155
        assertTrue(handler.deleteCalled);
156
        
157
        assertFalse(projectDirectory.exists());
158
        
159
        assertTrue(extDirFile.exists());
160
    }
161
    
162
    private static final class TestUserInputHandler implements UserInputHandler {
163
        
164
        private int answer;
165
        private ProgressHandle handle;
166
        
167
        private boolean userConfirmationCalled;
168
        private boolean enableData;
169
        private boolean getProgressHandleCalled;
170
        private boolean deleteCalled;
171
        
172
        public TestUserInputHandler(int answer) {
173
            this.answer = answer;
174
            this.handle = ProgressHandleFactory.createHandle("test");
175
        }
176
        
177
        public int userConfirmation(String displayName, String projectFolder, boolean enableData) {
178
            userConfirmationCalled = true;
179
            this.enableData = enableData;
180
            return answer;
181
        }
182
        
183
        public ProgressHandle getProgressHandle() {
184
            getProgressHandleCalled = true;
185
            return handle;
186
        }
187
        
188
        public void delete(Runnable r) {
189
            deleteCalled = true;
190
            r.run();
191
        }
192
        
193
    }
194
    
195
}
(-)ant/project/test/unit/src/org/netbeans/spi/project/support/ant/AntBasedTestUtil.java (-52 lines)
Lines 29-36 Link Here
29
import java.net.URISyntaxException;
29
import java.net.URISyntaxException;
30
import java.net.URL;
30
import java.net.URL;
31
import java.util.ArrayList;
31
import java.util.ArrayList;
32
import java.util.Arrays;
33
import java.util.Collections;
34
import java.util.HashMap;
32
import java.util.HashMap;
35
import java.util.HashSet;
33
import java.util.HashSet;
36
import java.util.List;
34
import java.util.List;
Lines 52-59 Link Here
52
import org.netbeans.spi.project.AuxiliaryConfiguration;
50
import org.netbeans.spi.project.AuxiliaryConfiguration;
53
import org.netbeans.api.project.ProjectInformation;
51
import org.netbeans.api.project.ProjectInformation;
54
import org.netbeans.api.project.ProjectManager;
52
import org.netbeans.api.project.ProjectManager;
55
import org.netbeans.spi.project.ProjectOperationsImplementation;
56
import org.netbeans.spi.project.ProjectOperationsImplementation.DeleteOperationImplementation;
57
import org.netbeans.spi.project.ant.AntArtifactProvider;
53
import org.netbeans.spi.project.ant.AntArtifactProvider;
58
import org.netbeans.spi.queries.CollocationQueryImplementation;
54
import org.netbeans.spi.queries.CollocationQueryImplementation;
59
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileObject;
Lines 164-170 Link Here
164
                    }
160
                    }
165
                },
161
                },
166
                "hello",
162
                "hello",
167
                new DeleteProjectOperationImpl(this),
168
            });
163
            });
169
        }
164
        }
170
        
165
        
Lines 249-301 Link Here
249
        
244
        
250
    }
245
    }
251
    
246
    
252
    public static final class DeleteProjectOperationImpl implements DeleteOperationImplementation {
253
        
254
        private boolean wasCleaned = false;
255
        private boolean wasNotified = false;
256
        
257
        private FileObject externalFile = null;
258
        
259
        private TestAntBasedProject project;
260
        
261
        public DeleteProjectOperationImpl(TestAntBasedProject project) {
262
            this.project = project;
263
        }
264
        
265
        public List getMetadataFiles() {
266
            return Collections.singletonList(project.getProjectDirectory().getFileObject("nbproject"));
267
        }
268
        
269
        public List getDataFiles() {
270
            if (externalFile == null) {
271
                return Collections.singletonList(project.getProjectDirectory().getFileObject("src"));
272
            } else {
273
                return Arrays.asList(new FileObject[] {project.getProjectDirectory().getFileObject("src"), externalFile});
274
            }
275
        }
276
        
277
        public void setExternalFile(FileObject externalFile) {
278
            this.externalFile = externalFile;
279
        }
280
        
281
        public synchronized boolean getWasCleaned() {
282
            return wasCleaned;
283
        }
284
        
285
        public synchronized void performClean() throws IOException {
286
            wasCleaned = true;
287
        }
288
        
289
        public synchronized boolean getWasNotified() {
290
            return wasNotified;
291
        }
292
        
293
        public synchronized void notifyDeleted() throws IOException {
294
            wasNotified = true;
295
        }
296
        
297
    }
298
        
299
    /**
247
    /**
300
     * Load a properties file from disk.
248
     * Load a properties file from disk.
301
     * @param h a project reference
249
     * @param h a project reference
(-)ant/src/org/apache/tools/ant/module/xml/AntProjectSupport.java (-1 / +1 lines)
Lines 66-72 Link Here
66
import org.xml.sax.SAXParseException;
66
import org.xml.sax.SAXParseException;
67
67
68
public class AntProjectSupport implements AntProjectCookie.ParseStatus, javax.swing.event.DocumentListener,
68
public class AntProjectSupport implements AntProjectCookie.ParseStatus, javax.swing.event.DocumentListener,
69
    FileChangeListener, PropertyChangeListener {
69
    /*FileChangeListener,*/ PropertyChangeListener {
70
    
70
    
71
    private FileObject fo;
71
    private FileObject fo;
72
72
(-)java/freeform/src/org/netbeans/modules/java/freeform/SourceLevelQueryImpl.java (-20 / +25 lines)
Lines 7-18 Link Here
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 * 
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
12
 */
13
13
14
package org.netbeans.modules.java.freeform;
14
package org.netbeans.modules.java.freeform;
15
15
16
import java.util.Collections;
16
import java.util.Iterator;
17
import java.util.Iterator;
17
import java.util.List;
18
import java.util.List;
18
import java.util.Map;
19
import java.util.Map;
Lines 33-41 Link Here
33
 */
34
 */
34
final class SourceLevelQueryImpl implements SourceLevelQueryImplementation, AntProjectListener {
35
final class SourceLevelQueryImpl implements SourceLevelQueryImplementation, AntProjectListener {
35
    
36
    
36
    private AntProjectHelper helper;
37
    private final AntProjectHelper helper;
37
    private PropertyEvaluator evaluator;
38
    private final PropertyEvaluator evaluator;
38
    private AuxiliaryConfiguration aux;
39
    private final AuxiliaryConfiguration aux;
39
    
40
    
40
    /**
41
    /**
41
     * Map from package roots to source levels.
42
     * Map from package roots to source levels.
Lines 49-63 Link Here
49
        this.helper.addAntProjectListener(this);
50
        this.helper.addAntProjectListener(this);
50
    }
51
    }
51
    
52
    
52
    public synchronized String getSourceLevel(FileObject file) {
53
    public String getSourceLevel(FileObject file) {
53
        // Check for cached value.
54
        // Check for cached value.
54
        Iterator it = sourceLevels.entrySet().iterator();
55
        synchronized (this) {
55
        while (it.hasNext()) {
56
            Iterator it = sourceLevels.entrySet().iterator();
56
            Map.Entry entry = (Map.Entry)it.next();
57
            while (it.hasNext()) {
57
            FileObject root = (FileObject)entry.getKey();
58
                Map.Entry entry = (Map.Entry)it.next();
58
            if (root == file || FileUtil.isParentOf(root, file)) {
59
                FileObject root = (FileObject)entry.getKey();
59
                // Already have it.
60
                if (root == file || FileUtil.isParentOf(root, file)) {
60
                return (String)entry.getValue();
61
                    // Already have it.
62
                    return (String)entry.getValue();
63
                }
61
            }
64
            }
62
        }
65
        }
63
        // Need to compute it.
66
        // Need to compute it.
Lines 66-72 Link Here
66
            return null;
69
            return null;
67
        }
70
        }
68
        List/*<Element>*/ compilationUnits = Util.findSubElements(java);
71
        List/*<Element>*/ compilationUnits = Util.findSubElements(java);
69
        it = compilationUnits.iterator();
72
        Iterator it = compilationUnits.iterator();
70
        while (it.hasNext()) {
73
        while (it.hasNext()) {
71
            Element compilationUnitEl = (Element)it.next();
74
            Element compilationUnitEl = (Element)it.next();
72
            assert compilationUnitEl.getLocalName().equals("compilation-unit") : compilationUnitEl;
75
            assert compilationUnitEl.getLocalName().equals("compilation-unit") : compilationUnitEl;
Lines 75-88 Link Here
75
            while (it2.hasNext()) {
78
            while (it2.hasNext()) {
76
                FileObject root = (FileObject)it2.next();
79
                FileObject root = (FileObject)it2.next();
77
                if (root == file || FileUtil.isParentOf(root, file)) {
80
                if (root == file || FileUtil.isParentOf(root, file)) {
78
                    // Got it. Retrieve source level and cache it (for each root).
81
                    synchronized (this) {
79
                    String lvl = getLevel(compilationUnitEl);
82
                        // Got it. Retrieve source level and cache it (for each root).
80
                    it2 = packageRoots.iterator();
83
                        String lvl = getLevel(compilationUnitEl);
81
                    while (it2.hasNext()) {
84
                        it2 = packageRoots.iterator();
82
                        FileObject root2 = (FileObject)it2.next();
85
                        while (it2.hasNext()) {
83
                        sourceLevels.put(root2, lvl);
86
                            FileObject root2 = (FileObject)it2.next();
87
                            sourceLevels.put(root2, lvl);
88
                        }
89
                        return lvl;
84
                    }
90
                    }
85
                    return lvl;
86
                }
91
                }
87
            }
92
            }
88
        }
93
        }
(-)java/j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEActionProvider.java (-5 / +20 lines)
Lines 18-29 Link Here
18
import java.io.IOException;
18
import java.io.IOException;
19
import java.net.URL;
19
import java.net.URL;
20
import java.text.MessageFormat;
20
import java.text.MessageFormat;
21
import java.util.ArrayList;
22
import java.util.Arrays;
21
import java.util.Arrays;
23
import java.util.HashMap;
22
import java.util.HashMap;
24
import java.util.HashSet;
23
import java.util.HashSet;
25
import java.util.Iterator;
26
import java.util.List;
27
import java.util.Map;
24
import java.util.Map;
28
import java.util.Properties;
25
import java.util.Properties;
29
import java.util.Set;
26
import java.util.Set;
Lines 35-41 Link Here
35
import org.netbeans.api.fileinfo.NonRecursiveFolder;
32
import org.netbeans.api.fileinfo.NonRecursiveFolder;
36
import org.netbeans.api.java.classpath.ClassPath;
33
import org.netbeans.api.java.classpath.ClassPath;
37
import org.netbeans.api.java.project.JavaProjectConstants;
34
import org.netbeans.api.java.project.JavaProjectConstants;
38
import org.netbeans.api.java.queries.SourceForBinaryQuery;
39
import org.netbeans.api.project.ProjectManager;
35
import org.netbeans.api.project.ProjectManager;
40
import org.netbeans.api.project.ProjectUtils;
36
import org.netbeans.api.project.ProjectUtils;
41
import org.netbeans.modules.java.j2seproject.applet.AppletSupport;
37
import org.netbeans.modules.java.j2seproject.applet.AppletSupport;
Lines 46-51 Link Here
46
import org.netbeans.spi.project.support.ant.AntProjectHelper;
42
import org.netbeans.spi.project.support.ant.AntProjectHelper;
47
import org.netbeans.spi.project.support.ant.EditableProperties;
43
import org.netbeans.spi.project.support.ant.EditableProperties;
48
import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
44
import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
45
import org.netbeans.spi.project.ui.support.DefaultProjectOperations;
49
import org.openide.DialogDescriptor;
46
import org.openide.DialogDescriptor;
50
import org.openide.DialogDisplayer;
47
import org.openide.DialogDisplayer;
51
import org.openide.ErrorManager;
48
import org.openide.ErrorManager;
Lines 84-89 Link Here
84
        JavaProjectConstants.COMMAND_DEBUG_FIX,
81
        JavaProjectConstants.COMMAND_DEBUG_FIX,
85
        COMMAND_DEBUG_STEP_INTO,
82
        COMMAND_DEBUG_STEP_INTO,
86
        COMMAND_DELETE,
83
        COMMAND_DELETE,
84
        COMMAND_COPY,
85
        COMMAND_MOVE,
86
        COMMAND_RENAME,
87
    };
87
    };
88
    
88
    
89
    // Project
89
    // Project
Lines 140-146 Link Here
140
    
140
    
141
    public void invokeAction( final String command, final Lookup context ) throws IllegalArgumentException {
141
    public void invokeAction( final String command, final Lookup context ) throws IllegalArgumentException {
142
        if (COMMAND_DELETE.equals(command)) {
142
        if (COMMAND_DELETE.equals(command)) {
143
            project.getAntProjectHelper().performDefaultDeleteOperation();
143
            DefaultProjectOperations.performDefaultDeleteOperation(project);
144
            return ;
145
        }
146
        
147
        if (COMMAND_COPY.equals(command)) {
148
            DefaultProjectOperations.performDefaultCopyOperation(project);
149
            return ;
150
        }
151
        
152
        if (COMMAND_MOVE.equals(command)) {
153
            DefaultProjectOperations.performDefaultMoveOperation(project);
154
            return ;
155
        }
156
        
157
        if (COMMAND_RENAME.equals(command)) {
158
            DefaultProjectOperations.performDefaultRenameOperation(project, null);
144
            return ;
159
            return ;
145
        }
160
        }
146
        
161
        
(-)java/j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java (-3 / +6 lines)
Lines 119-124 Link Here
119
        return this.refHelper;
119
        return this.refHelper;
120
    }
120
    }
121
121
122
    UpdateHelper getUpdateHelper() {
123
        return this.updateHelper;
124
    }
125
    
122
    public Lookup getLookup() {
126
    public Lookup getLookup() {
123
        return lookup;
127
        return lookup;
124
    }
128
    }
Lines 198-204 Link Here
198
    }
202
    }
199
    
203
    
200
    // Currently unused (but see #47230):
204
    // Currently unused (but see #47230):
201
    /** Store configured project name. * /
205
    /** Store configured project name. */
202
    public void setName(final String name) {
206
    public void setName(final String name) {
203
        ProjectManager.mutex().writeAccess(new Mutex.Action() {
207
        ProjectManager.mutex().writeAccess(new Mutex.Action() {
204
            public Object run() {
208
            public Object run() {
Lines 214-220 Link Here
214
                    }
218
                    }
215
                } else {
219
                } else {
216
                    nameEl = data.getOwnerDocument().createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name");
220
                    nameEl = data.getOwnerDocument().createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name");
217
                    data.insertBefore(nameEl, / * OK if null * /data.getChildNodes().item(0));
221
                    data.insertBefore(nameEl, /* OK if null */data.getChildNodes().item(0));
218
                }
222
                }
219
                nameEl.appendChild(data.getOwnerDocument().createTextNode(name));
223
                nameEl.appendChild(data.getOwnerDocument().createTextNode(name));
220
                helper.putPrimaryConfigurationData(data, true);
224
                helper.putPrimaryConfigurationData(data, true);
Lines 222-228 Link Here
222
            }
226
            }
223
        });
227
        });
224
    }
228
    }
225
     */
226
229
227
230
228
231
(-)java/j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProjectOperations.java (-3 / +98 lines)
Lines 13-37 Link Here
13
13
14
package org.netbeans.modules.java.j2seproject;
14
package org.netbeans.modules.java.j2seproject;
15
15
16
import java.io.File;
16
import java.io.IOException;
17
import java.io.IOException;
18
import java.net.URL;
17
import java.util.ArrayList;
19
import java.util.ArrayList;
18
import java.util.List;
20
import java.util.List;
19
import java.util.Properties;
21
import java.util.Properties;
20
import org.apache.tools.ant.module.api.support.ActionUtils;
22
import org.apache.tools.ant.module.api.support.ActionUtils;
23
import org.netbeans.api.project.Project;
24
import org.netbeans.api.project.ProjectManager;
21
import org.netbeans.spi.project.ActionProvider;
25
import org.netbeans.spi.project.ActionProvider;
22
import org.netbeans.spi.project.ProjectOperationsImplementation.DeleteOperationImplementation;
26
import org.netbeans.spi.project.CopyOperationImplementation;
27
import org.netbeans.spi.project.DeleteOperationImplementation;
28
import org.netbeans.spi.project.MoveOperationImplementation;
23
import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
29
import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
30
import org.netbeans.spi.project.support.ant.PropertyUtils;
24
import org.openide.ErrorManager;
31
import org.openide.ErrorManager;
25
import org.openide.filesystems.FileObject;
32
import org.openide.filesystems.FileObject;
26
import org.openide.filesystems.FileUtil;
33
import org.openide.filesystems.FileUtil;
27
import org.openide.util.Lookup;
34
import org.openide.util.Lookup;
35
import org.openide.util.Mutex;
36
import org.openide.util.MutexException;
28
import org.openide.util.lookup.Lookups;
37
import org.openide.util.lookup.Lookups;
29
38
39
30
/**
40
/**
31
 *
41
 *
32
 * @author Jan Lahoda
42
 * @author Jan Lahoda
33
 */
43
 */
34
public class J2SEProjectOperations implements DeleteOperationImplementation {
44
public class J2SEProjectOperations implements DeleteOperationImplementation, CopyOperationImplementation, MoveOperationImplementation {
35
    
45
    
36
    private J2SEProject project;
46
    private J2SEProject project;
37
    
47
    
Lines 80-86 Link Here
80
        return files;
90
        return files;
81
    }
91
    }
82
    
92
    
83
    public void performClean() throws IOException {
93
    public void notifyDeleting() throws IOException {
84
        J2SEActionProvider ap = (J2SEActionProvider) project.getLookup().lookup(J2SEActionProvider.class);
94
        J2SEActionProvider ap = (J2SEActionProvider) project.getLookup().lookup(J2SEActionProvider.class);
85
        
95
        
86
        assert ap != null;
96
        assert ap != null;
Lines 98-103 Link Here
98
    
108
    
99
    public void notifyDeleted() throws IOException {
109
    public void notifyDeleted() throws IOException {
100
        project.getAntProjectHelper().notifyDeleted();
110
        project.getAntProjectHelper().notifyDeleted();
111
    }
112
    
113
    public void notifyCopying() {
114
        //nothing.
115
    }
116
    
117
    public void notifyCopied(Project original, File originalPath, String nueName) {
118
        if (project == original) { //TODO: this is illegal
119
            //do nothing for the original project.
120
            return ;
121
        }
122
        
123
        project.getReferenceHelper().fixReferences(originalPath);
124
        
125
        project.setName(nueName);
126
    }
127
    
128
    public void notifyMoving() throws IOException {
129
        notifyDeleting();
130
    }
131
    
132
    public void notifyMoved(Project original, File originalPath, String nueName) {
133
        if (project == original) { //TODO: this is illegal
134
            //do nothing for the original project.
135
            return ;
136
        }
137
        
138
        project.setName(nueName);
139
        fixExternalSources(originalPath, project.getSourceRoots());
140
        fixExternalSources(originalPath, project.getTestSourceRoots());
141
    }
142
    
143
    private void fixExternalSources(final File originalPath, final SourceRoots sr) {
144
        try {
145
            ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() {
146
                public Object run() throws IOException {
147
                    File projectDirectory = FileUtil.toFile(project.getProjectDirectory());
148
                    String[] srcProps = sr.getRootProperties();
149
                    String[] names = sr.getRootNames();
150
                    List/*<URL>*/ roots = new ArrayList();
151
                    List/*<String>*/ displayNames = new ArrayList();
152
                    for (int i = 0; i < srcProps.length; i++) {
153
                        String prop = project.evaluator().getProperty(srcProps[i]);
154
                        if (prop != null) {
155
                            FileObject nueFile = null;
156
                            File originalFile = PropertyUtils.resolveFile(originalPath, prop);
157
                            
158
                            if (isParent(originalPath, originalFile)) {
159
                                nueFile = FileUtil.toFileObject(PropertyUtils.resolveFile(projectDirectory, prop));
160
                            } else {
161
                                nueFile = FileUtil.toFileObject(originalFile);
162
                            }
163
                            
164
                            if (nueFile == null) {
165
                                continue;
166
                            }
167
                            if (FileUtil.isArchiveFile(nueFile)) {
168
                                nueFile = FileUtil.getArchiveRoot(nueFile);
169
                            }
170
                            roots.add(nueFile.getURL());
171
                            displayNames.add(sr.getRootDisplayName(names[i], srcProps[i]));
172
                        }
173
                    }
174
                    
175
                    sr.putRoots((URL[] ) roots.toArray(new URL[0]), (String[] ) displayNames.toArray(new String[0])); //XXX
176
                    return null;
177
                }
178
            });
179
        } catch (MutexException e) {
180
            ErrorManager.getDefault().notify(e);
181
        }
182
    }
183
    
184
    private static boolean isParent(File folder, File fo) {
185
        if (folder.equals(fo))
186
            return false;
187
        
188
        while (fo != null) {
189
            if (fo.equals(folder))
190
                return true;
191
            
192
            fo = fo.getParentFile();
193
        }
194
        
195
        return false;
101
    }
196
    }
102
    
197
    
103
}
198
}
(-)java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/J2SELogicalViewProvider.java (-2 / +10 lines)
Lines 60-65 Link Here
60
import org.netbeans.spi.project.support.ant.ReferenceHelper;
60
import org.netbeans.spi.project.support.ant.ReferenceHelper;
61
import org.netbeans.spi.project.ui.LogicalViewProvider;
61
import org.netbeans.spi.project.ui.LogicalViewProvider;
62
import org.netbeans.spi.project.ui.support.CommonProjectActions;
62
import org.netbeans.spi.project.ui.support.CommonProjectActions;
63
import org.netbeans.spi.project.ui.support.DefaultProjectOperations;
63
import org.netbeans.spi.project.ui.support.ProjectSensitiveActions;
64
import org.netbeans.spi.project.ui.support.ProjectSensitiveActions;
64
import org.openide.ErrorManager;
65
import org.openide.ErrorManager;
65
import org.openide.actions.FindAction;
66
import org.openide.actions.FindAction;
Lines 241-247 Link Here
241
        public J2SELogicalViewRootNode() {
242
        public J2SELogicalViewRootNode() {
242
            super(new LogicalViewChildren(project, evaluator, helper, resolver), Lookups.singleton(project));
243
            super(new LogicalViewChildren(project, evaluator, helper, resolver), Lookups.singleton(project));
243
            setIconBaseWithExtension("org/netbeans/modules/java/j2seproject/ui/resources/j2seProject.gif");
244
            setIconBaseWithExtension("org/netbeans/modules/java/j2seproject/ui/resources/j2seProject.gif");
244
            setName(ProjectUtils.getInformation(project).getDisplayName());
245
            super.setName( ProjectUtils.getInformation( project ).getDisplayName() );
245
            if (hasBrokenLinks()) {
246
            if (hasBrokenLinks()) {
246
                broken = true;
247
                broken = true;
247
            }
248
            }
Lines 463-469 Link Here
463
        }
464
        }
464
        
465
        
465
        public boolean canRename() {
466
        public boolean canRename() {
466
            return false;
467
            return true;
468
        }
469
        
470
        public void setName(String s) {
471
            DefaultProjectOperations.performDefaultRenameOperation(project, s);
467
        }
472
        }
468
        
473
        
469
        /*
474
        /*
Lines 501-506 Link Here
501
            actions.add(CommonProjectActions.openSubprojectsAction());
506
            actions.add(CommonProjectActions.openSubprojectsAction());
502
            actions.add(CommonProjectActions.closeProjectAction());
507
            actions.add(CommonProjectActions.closeProjectAction());
503
            actions.add(null);
508
            actions.add(null);
509
            actions.add(CommonProjectActions.renameProjectAction());
510
            actions.add(CommonProjectActions.moveProjectAction());
511
            actions.add(CommonProjectActions.copyProjectAction());
504
            actions.add(CommonProjectActions.deleteProjectAction());
512
            actions.add(CommonProjectActions.deleteProjectAction());
505
            actions.add(null);
513
            actions.add(null);
506
            actions.add(SystemAction.get(FindAction.class));
514
            actions.add(SystemAction.get(FindAction.class));

Return to bug 61546