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

(-)a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProjectOperations.java (-5 / +22 lines)
Lines 59-65 Link Here
59
import org.netbeans.spi.project.ActionProvider;
59
import org.netbeans.spi.project.ActionProvider;
60
import org.netbeans.spi.project.CopyOperationImplementation;
60
import org.netbeans.spi.project.CopyOperationImplementation;
61
import org.netbeans.spi.project.DeleteOperationImplementation;
61
import org.netbeans.spi.project.DeleteOperationImplementation;
62
import org.netbeans.spi.project.MoveOperationImplementation;
62
import org.netbeans.spi.project.MoveOrRenameOperationImplementation;
63
import org.netbeans.spi.project.support.ant.AntProjectHelper;
63
import org.netbeans.spi.project.support.ant.AntProjectHelper;
64
import org.netbeans.spi.project.support.ant.EditableProperties;
64
import org.netbeans.spi.project.support.ant.EditableProperties;
65
import org.netbeans.spi.project.support.ant.PropertyUtils;
65
import org.netbeans.spi.project.support.ant.PropertyUtils;
Lines 74-80 Link Here
74
 *
74
 *
75
 * @author Jan Lahoda
75
 * @author Jan Lahoda
76
 */
76
 */
77
public class J2SEProjectOperations implements DeleteOperationImplementation, CopyOperationImplementation, MoveOperationImplementation {
77
public class J2SEProjectOperations implements DeleteOperationImplementation, CopyOperationImplementation, MoveOrRenameOperationImplementation {
78
    
78
    
79
    private final J2SEProject project;
79
    private final J2SEProject project;
80
    private final J2SEActionProvider actionProvider;
80
    private final J2SEActionProvider actionProvider;
Lines 143-149 Link Here
143
        return files;
143
        return files;
144
    }
144
    }
145
    
145
    
146
    public void notifyDeleting() throws IOException {                
146
    public @Override void notifyDeleting() throws IOException {
147
        clean();
148
    }
149
150
    private void clean() throws IOException {
147
        Properties p = new Properties();
151
        Properties p = new Properties();
148
        String[] targetNames = this.actionProvider.getTargetNames(ActionProvider.COMMAND_CLEAN, Lookup.EMPTY, p, false);
152
        String[] targetNames = this.actionProvider.getTargetNames(ActionProvider.COMMAND_CLEAN, Lookup.EMPTY, p, false);
149
        FileObject buildXML = J2SEProjectUtil.getBuildXml(project);
153
        FileObject buildXML = J2SEProjectUtil.getBuildXml(project);
Lines 187-193 Link Here
187
        rememberLibraryLocation();
191
        rememberLibraryLocation();
188
        readPrivateProperties ();
192
        readPrivateProperties ();
189
        rememberConfigurations();
193
        rememberConfigurations();
190
        notifyDeleting();
194
        clean();
191
    }
195
    }
192
            
196
            
193
    public void notifyMoved(Project original, File originalPath, String nueName) {        
197
    public void notifyMoved(Project original, File originalPath, String nueName) {        
Lines 205-210 Link Here
205
        restoreConfigurations(origOperations);
209
        restoreConfigurations(origOperations);
206
    }
210
    }
207
211
212
    public @Override void notifyRenaming() throws IOException {
213
        if (!this.project.getUpdateHelper().requestUpdate()) {
214
            throw new IOException(NbBundle.getMessage(J2SEProjectOperations.class, "MSG_OldProjectMetadata"));
215
        }
216
        clean();
217
    }
218
219
    public @Override void notifyRenamed(String nueName) throws IOException {
220
        fixDistJarProperty(nueName);
221
        fixApplicationTitle(nueName);
222
        project.setName(nueName);
223
    }
224
208
    private void fixLibraryLocation(J2SEProjectOperations original) throws IllegalArgumentException {
225
    private void fixLibraryLocation(J2SEProjectOperations original) throws IllegalArgumentException {
209
        String libPath = original.libraryPath;
226
        String libPath = original.libraryPath;
210
        if (libPath != null) {
227
        if (libPath != null) {
Lines 386-390 Link Here
386
            }
403
            }
387
        }
404
        }
388
    }
405
    }
389
    
406
390
}
407
}
(-)a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/J2SELogicalViewProvider.java (-2 / +15 lines)
Lines 57-62 Link Here
57
import org.netbeans.api.java.platform.JavaPlatformManager;
57
import org.netbeans.api.java.platform.JavaPlatformManager;
58
import org.netbeans.api.project.FileOwnerQuery;
58
import org.netbeans.api.project.FileOwnerQuery;
59
import org.netbeans.api.project.Project;
59
import org.netbeans.api.project.Project;
60
import org.netbeans.api.project.ProjectInformation;
60
import org.netbeans.api.project.ProjectUtils;
61
import org.netbeans.api.project.ProjectUtils;
61
import org.netbeans.modules.java.api.common.SourceRoots;
62
import org.netbeans.modules.java.api.common.SourceRoots;
62
import org.netbeans.modules.java.api.common.ant.UpdateHelper;
63
import org.netbeans.modules.java.api.common.ant.UpdateHelper;
Lines 272-285 Link Here
272
        compileOnSaveDisabledBadge = ImageUtilities.assignToolTipToImage(ImageUtilities.loadImage(COMPILE_ON_SAVE_DISABLED_BADGE_PATH), compileOnSaveDisabledTP); // NOI18N
273
        compileOnSaveDisabledBadge = ImageUtilities.assignToolTipToImage(ImageUtilities.loadImage(COMPILE_ON_SAVE_DISABLED_BADGE_PATH), compileOnSaveDisabledTP); // NOI18N
273
    }
274
    }
274
275
275
    private final class J2SELogicalViewRootNode extends AbstractNode implements ChangeListener {
276
    private final class J2SELogicalViewRootNode extends AbstractNode implements ChangeListener, PropertyChangeListener {
277
278
        private final ProjectInformation info = ProjectUtils.getInformation(project);
276
        
279
        
277
        @SuppressWarnings("LeakingThisInConstructor")
280
        @SuppressWarnings("LeakingThisInConstructor")
278
        public J2SELogicalViewRootNode() {
281
        public J2SELogicalViewRootNode() {
279
            super(NodeFactorySupport.createCompositeChildren(project, "Projects/org-netbeans-modules-java-j2seproject/Nodes"), 
282
            super(NodeFactorySupport.createCompositeChildren(project, "Projects/org-netbeans-modules-java-j2seproject/Nodes"), 
280
                  Lookups.singleton(project));
283
                  Lookups.singleton(project));
281
            setIconBaseWithExtension("org/netbeans/modules/java/j2seproject/ui/resources/j2seProject.png");
284
            setIconBaseWithExtension("org/netbeans/modules/java/j2seproject/ui/resources/j2seProject.png");
282
            super.setName( ProjectUtils.getInformation( project ).getDisplayName() );
283
            if (hasBrokenLinks()) {
285
            if (hasBrokenLinks()) {
284
                broken = true;
286
                broken = true;
285
            }
287
            }
Lines 288-293 Link Here
288
            }
290
            }
289
            compileOnSaveDisabled = isCompileOnSaveDisabled();
291
            compileOnSaveDisabled = isCompileOnSaveDisabled();
290
            addChangeListener(WeakListeners.change(this, J2SELogicalViewProvider.this));
292
            addChangeListener(WeakListeners.change(this, J2SELogicalViewProvider.this));
293
            info.addPropertyChangeListener(WeakListeners.propertyChange(this, info));
291
        }
294
        }
292
295
293
        @Override
296
        @Override
Lines 337-342 Link Here
337
        }
340
        }
338
341
339
        @Override
342
        @Override
343
        public void propertyChange(PropertyChangeEvent evt) {
344
            fireNameChange(null, null);
345
            fireDisplayNameChange(null, null);
346
        }
347
348
        @Override
340
        public Action[] getActions( boolean context ) {
349
        public Action[] getActions( boolean context ) {
341
            return CommonProjectActions.forType("org-netbeans-modules-java-j2seproject"); // NOI18N
350
            return CommonProjectActions.forType("org-netbeans-modules-java-j2seproject"); // NOI18N
342
        }
351
        }
Lines 346-351 Link Here
346
            return true;
355
            return true;
347
        }
356
        }
348
        
357
        
358
        public @Override String getName() {
359
            return info.getDisplayName();
360
        }
361
349
        @Override
362
        @Override
350
        public void setName(String s) {
363
        public void setName(String s) {
351
            DefaultProjectOperations.performDefaultRenameOperation(project, s);
364
            DefaultProjectOperations.performDefaultRenameOperation(project, s);
(-)a/projectapi/src/org/netbeans/spi/project/MoveOperationImplementation.java (-1 / +5 lines)
Lines 64-79 Link Here
64
 * The project type is not required to put an implementation of this interface into the project's
64
 * The project type is not required to put an implementation of this interface into the project's
65
 * lookup if the above two cases should not be supported.
65
 * lookup if the above two cases should not be supported.
66
 *
66
 *
67
 * <p>Implementations are encouraged to implement {@link MoveOrRenameOperationImplementation} instead.
68
 *
67
 * @author Jan Lahoda
69
 * @author Jan Lahoda
68
 * @since 1.7
70
 * @since 1.7
69
 */
71
 */
70
public interface MoveOperationImplementation extends DataFilesProviderImplementation {
72
public interface MoveOperationImplementation extends DataFilesProviderImplementation {
71
    
73
    
72
    /**Pre-move notification. The exact meaning is left on the project implementors, but
74
    /**Pre-move notification. The exact meaning is left on the project implementors, but
73
     * typically this means to undeloy the application and remove all artifacts
75
     * typically this means to undeploy the application and remove all artifacts
74
     * created by the build project.
76
     * created by the build project.
75
     *
77
     *
76
     * @throws IOException if an I/O operation fails.
78
     * @throws IOException if an I/O operation fails.
79
     * @see MoveOrRenameOperationImplementation#notifyRenaming
77
     */
80
     */
78
    public void notifyMoving() throws IOException;
81
    public void notifyMoving() throws IOException;
79
    
82
    
Lines 87-92 Link Here
87
     * @param nueName new name for the newly created project.
90
     * @param nueName new name for the newly created project.
88
     *
91
     *
89
     * @throws IOException if an I/O operation fails.
92
     * @throws IOException if an I/O operation fails.
93
     * @see MoveOrRenameOperationImplementation#notifyRenamed
90
     */
94
     */
91
    public void notifyMoved(Project original, File originalPath, String nueName) throws IOException;
95
    public void notifyMoved(Project original, File originalPath, String nueName) throws IOException;
92
    
96
    
(-)a/projectapi/src/org/netbeans/spi/project/MoveOrRenameOperationImplementation.java (+70 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.spi.project;
41
42
import java.io.IOException;
43
44
/**
45
 * A preferred substitute for {@code MoveOperationImplementation} to be used when
46
 * the project can behave more simply, efficiently, and robustly when it is simply
47
 * being renamed (code and/or display name) without actually being moved to a new location.
48
 * In this case, {@link #notifyMoving} and {@link #notifyMoved} will not be called.
49
 * @since XXX
50
 */
51
public interface MoveOrRenameOperationImplementation extends MoveOperationImplementation {
52
53
    /**
54
    /* Pre-rename notification.
55
     * The exact meaning is left to the project's implementation;
56
     * it might for example undeploy an application and remove all artifacts
57
     * created by the build, in case they used the old name.
58
     * @throws IOException if an I/O operation fails
59
     */
60
    void notifyRenaming() throws IOException;
61
62
    /**
63
     * Notification that the rename operation has finished.
64
     * The project might for example change its display name in metadata.
65
     * @param nueName new name for the project
66
     * @throws IOException if an I/O operation fails
67
     */
68
    void notifyRenamed(String nueName) throws IOException;
69
70
}
(-)a/projectuiapi/src/org/netbeans/modules/project/uiapi/DefaultProjectOperationsImplementation.java (-1 / +36 lines)
Lines 53-58 Link Here
53
import java.util.Collection;
53
import java.util.Collection;
54
import java.util.Iterator;
54
import java.util.Iterator;
55
import java.util.List;
55
import java.util.List;
56
import java.util.logging.Level;
57
import java.util.logging.Logger;
56
import javax.swing.Action;
58
import javax.swing.Action;
57
import javax.swing.JButton;
59
import javax.swing.JButton;
58
import javax.swing.JComponent;
60
import javax.swing.JComponent;
Lines 73-78 Link Here
73
import org.netbeans.spi.project.MoveOperationImplementation;
75
import org.netbeans.spi.project.MoveOperationImplementation;
74
import org.netbeans.spi.project.support.ProjectOperations;
76
import org.netbeans.spi.project.support.ProjectOperations;
75
import org.netbeans.api.queries.VisibilityQuery;
77
import org.netbeans.api.queries.VisibilityQuery;
78
import org.netbeans.spi.project.MoveOrRenameOperationImplementation;
76
import org.netbeans.spi.project.ui.support.CommonProjectActions;
79
import org.netbeans.spi.project.ui.support.CommonProjectActions;
77
import org.openide.DialogDescriptor;
80
import org.openide.DialogDescriptor;
78
import org.openide.DialogDisplayer;
81
import org.openide.DialogDisplayer;
Lines 372-377 Link Here
372
    }
375
    }
373
376
374
    private static void doRenameProject(ProgressHandle handle, Project project, String nueName) throws Exception {
377
    private static void doRenameProject(ProgressHandle handle, Project project, String nueName) throws Exception {
378
        Collection<? extends MoveOperationImplementation> operations = project.getLookup().lookupAll(MoveOperationImplementation.class);
379
        for (MoveOperationImplementation o : operations) {
380
            if (!(o instanceof MoveOrRenameOperationImplementation)) {
381
                Logger.getLogger(DefaultProjectOperationsImplementation.class.getName()).log(Level.WARNING,
382
                        "{0} should implement MoveOrRenameOperationImplementation", o.getClass().getName());
383
                doRenameProjectOld(handle, project, nueName, operations);
384
                return;
385
            }
386
        }
387
        // Better new style.
388
        try {
389
            handle.switchToDeterminate(4);
390
            int currentWorkDone = 0;
391
            handle.progress(++currentWorkDone);
392
            for (MoveOperationImplementation o : operations) {
393
                ((MoveOrRenameOperationImplementation) o).notifyRenaming();
394
            }
395
            handle.progress(++currentWorkDone);
396
            for (MoveOperationImplementation o : operations) {
397
                ((MoveOrRenameOperationImplementation) o).notifyRenamed(nueName);
398
            }
399
            handle.progress(++currentWorkDone);
400
            ProjectManager.getDefault().saveProject(project);
401
            handle.progress(++currentWorkDone);
402
            handle.finish();
403
        } catch (Exception e) {
404
            ErrorManager.getDefault().annotate(e, NbBundle.getMessage(DefaultProjectOperationsImplementation.class, "ERR_Cannot_Rename", e.getLocalizedMessage()));
405
            throw e;
406
        }
407
    }
408
409
    private static void doRenameProjectOld(ProgressHandle handle, Project project, String nueName,
410
            Collection<? extends MoveOperationImplementation> operations) throws Exception {
375
        boolean originalOK = true;
411
        boolean originalOK = true;
376
        Project main = OpenProjects.getDefault().getMainProject();
412
        Project main = OpenProjects.getDefault().getMainProject();
377
        boolean wasMain = main != null && project.getProjectDirectory().equals(main.getProjectDirectory());
413
        boolean wasMain = main != null && project.getProjectDirectory().equals(main.getProjectDirectory());
Lines 382-388 Link Here
382
            int currentWorkDone = 0;
418
            int currentWorkDone = 0;
383
            FileObject projectDirectory = project.getProjectDirectory();
419
            FileObject projectDirectory = project.getProjectDirectory();
384
            File projectDirectoryFile = FileUtil.toFile(project.getProjectDirectory());
420
            File projectDirectoryFile = FileUtil.toFile(project.getProjectDirectory());
385
            Collection<? extends MoveOperationImplementation> operations = project.getLookup().lookupAll(MoveOperationImplementation.class);
386
            close(project);
421
            close(project);
387
            handle.progress(++currentWorkDone);
422
            handle.progress(++currentWorkDone);
388
            for (MoveOperationImplementation o : operations) {
423
            for (MoveOperationImplementation o : operations) {

Return to bug 183680