Lines 80-91
Link Here
|
80 |
import org.openide.LifecycleManager; |
80 |
import org.openide.LifecycleManager; |
81 |
import org.openide.NotifyDescriptor; |
81 |
import org.openide.NotifyDescriptor; |
82 |
import org.openide.awt.Mnemonics; |
82 |
import org.openide.awt.Mnemonics; |
|
|
83 |
import org.openide.filesystems.FileLock; |
83 |
import org.openide.filesystems.FileObject; |
84 |
import org.openide.filesystems.FileObject; |
84 |
import org.openide.filesystems.FileSystem; |
85 |
import org.openide.filesystems.FileSystem; |
85 |
import org.openide.filesystems.FileUtil; |
86 |
import org.openide.filesystems.FileUtil; |
86 |
import org.openide.loaders.DataFolder; |
|
|
87 |
import org.openide.loaders.DataObject; |
88 |
import org.openide.loaders.DataObjectNotFoundException; |
89 |
import org.openide.util.ContextAwareAction; |
87 |
import org.openide.util.ContextAwareAction; |
90 |
import org.openide.util.Mutex; |
88 |
import org.openide.util.Mutex; |
91 |
import org.openide.util.NbBundle; |
89 |
import org.openide.util.NbBundle; |
Lines 334-350
Link Here
|
334 |
newTargetFO = createFolder(newTarget.getParentFile(), newTarget.getName()); |
332 |
newTargetFO = createFolder(newTarget.getParentFile(), newTarget.getName()); |
335 |
} |
333 |
} |
336 |
final FileObject newTgtFO = newTargetFO; |
334 |
final FileObject newTgtFO = newTargetFO; |
337 |
project.getProjectDirectory().getFileSystem().runAtomicAction(new FileSystem.AtomicAction() { |
335 |
doMoveProject(handle, project, nueFolderName, nueProjectName, newTgtFO, "ERR_Cannot_Move"); |
338 |
public void run() throws IOException { |
|
|
339 |
try { |
340 |
doMoveProject(handle, project, nueFolderName, nueProjectName, newTgtFO, "ERR_Cannot_Move"); |
341 |
} catch (IOException x) { |
342 |
throw x; |
343 |
} catch (Exception x) { |
344 |
throw new IOException(x); |
345 |
} |
346 |
} |
347 |
}); |
348 |
} |
336 |
} |
349 |
}); |
337 |
}); |
350 |
} |
338 |
} |
Lines 365-390
Link Here
|
365 |
final String nueName = panel.getNewName(); |
353 |
final String nueName = panel.getNewName(); |
366 |
|
354 |
|
367 |
if (panel.getRenameProjectFolder()) { |
355 |
if (panel.getRenameProjectFolder()) { |
368 |
project.getProjectDirectory().getFileSystem().runAtomicAction(new FileSystem.AtomicAction() { |
356 |
doMoveProject(handle, project, nueName, nueName, project.getProjectDirectory().getParent(), "ERR_Cannot_Rename"); |
369 |
public void run() throws IOException { |
|
|
370 |
try { |
371 |
doMoveProject(handle, project, nueName, nueName, project.getProjectDirectory().getParent(), "ERR_Cannot_Rename"); |
372 |
} catch (IOException x) { |
373 |
throw x; |
374 |
} catch (Exception x) { |
375 |
throw new IOException(x); |
376 |
} |
377 |
} |
378 |
}); |
379 |
} else { |
357 |
} else { |
380 |
project.getProjectDirectory().getFileSystem().runAtomicAction(new FileSystem.AtomicAction() { |
358 |
project.getProjectDirectory().getFileSystem().runAtomicAction(new FileSystem.AtomicAction() { |
381 |
public void run() throws IOException { |
359 |
public void run() throws IOException { |
382 |
try { |
360 |
try { |
383 |
doRenameProject(handle, project, nueName); |
361 |
doRenameProject(handle, project, nueName); |
384 |
} catch (IOException x) { |
362 |
} catch (IOException x) { |
385 |
throw x; |
363 |
throw x; |
386 |
} catch (Exception x) { |
364 |
} catch (Exception x) { |
387 |
throw new IOException(x); |
365 |
throw new IOException(x); |
388 |
} |
366 |
} |
389 |
} |
367 |
} |
390 |
}); |
368 |
}); |
Lines 462-508
Link Here
|
462 |
handle.progress((int) (currentWorkDone = totalWork * NOTIFY_WORK)); |
440 |
handle.progress((int) (currentWorkDone = totalWork * NOTIFY_WORK)); |
463 |
|
441 |
|
464 |
FileObject projectDirectory = project.getProjectDirectory(); |
442 |
FileObject projectDirectory = project.getProjectDirectory(); |
465 |
List<FileObject> toMoveList = new ArrayList<FileObject>(); |
443 |
|
466 |
for (FileObject child : projectDirectory.getChildren()) { |
444 |
double workPerFileAndOperation = totalWork * (1.0 - 2 * NOTIFY_WORK - FIND_PROJECT_WORK); |
467 |
if (child.isValid()) { |
445 |
|
468 |
toMoveList.add(child); |
446 |
FileLock lock = projectDirectory.lock(); |
469 |
} |
447 |
try { |
|
|
448 |
target = projectDirectory.move(lock, newTarget, nueFolderName, null); |
449 |
} finally { |
450 |
lock.releaseLock(); |
470 |
} |
451 |
} |
471 |
|
452 |
// TBD if #109580 matters here: do we need to delete nbproject/private? probably not |
472 |
double workPerFileAndOperation = (totalWork * (1.0 - 2 * NOTIFY_WORK - FIND_PROJECT_WORK) / toMoveList.size()) / 2; |
453 |
int lastWorkDone = (int) currentWorkDone; |
473 |
|
|
|
474 |
target = newTarget.createFolder(nueFolderName); |
475 |
|
454 |
|
476 |
for (FileObject toCopy : toMoveList) { |
455 |
currentWorkDone += workPerFileAndOperation; |
477 |
doCopy(project, toCopy, target); |
456 |
|
478 |
|
457 |
if (lastWorkDone < (int) currentWorkDone) { |
479 |
int lastWorkDone = (int) currentWorkDone; |
458 |
handle.progress((int) currentWorkDone); |
480 |
|
|
|
481 |
currentWorkDone += workPerFileAndOperation; |
482 |
|
483 |
if (lastWorkDone < (int) currentWorkDone) { |
484 |
handle.progress((int) currentWorkDone); |
485 |
} |
486 |
} |
459 |
} |
487 |
|
460 |
|
488 |
originalOK = false; |
461 |
originalOK = false; |
489 |
|
462 |
|
490 |
for (FileObject toCopy : toMoveList) { |
|
|
491 |
doDelete(project, toCopy); |
492 |
|
493 |
int lastWorkDone = (int) currentWorkDone; |
494 |
|
495 |
currentWorkDone += workPerFileAndOperation; |
496 |
|
497 |
if (lastWorkDone < (int) currentWorkDone) { |
498 |
handle.progress((int) currentWorkDone); |
499 |
} |
500 |
} |
501 |
|
502 |
if (projectDirectory.getChildren().length == 0) { |
503 |
projectDirectory.delete(); |
504 |
} |
505 |
|
506 |
//#64264: the non-project cache can be filled with incorrect data (gathered during the project copy phase), clear it: |
463 |
//#64264: the non-project cache can be filled with incorrect data (gathered during the project copy phase), clear it: |
507 |
ProjectManager.getDefault().clearNonProjectCache(); |
464 |
ProjectManager.getDefault().clearNonProjectCache(); |
508 |
Project nue = ProjectManager.getDefault().findProject(target); |
465 |
Project nue = ProjectManager.getDefault().findProject(target); |
Lines 510-516
Link Here
|
510 |
handle.progress((int) (currentWorkDone += totalWork * FIND_PROJECT_WORK)); |
467 |
handle.progress((int) (currentWorkDone += totalWork * FIND_PROJECT_WORK)); |
511 |
|
468 |
|
512 |
assert nue != null; |
469 |
assert nue != null; |
513 |
|
470 |
assert nue != project : "got same Project for " + projectDirectory + " and " + target; |
|
|
471 |
|
514 |
ProjectOperations.notifyMoved(project, nue, FileUtil.toFile(project.getProjectDirectory()), nueProjectName); |
472 |
ProjectOperations.notifyMoved(project, nue, FileUtil.toFile(project.getProjectDirectory()), nueProjectName); |
515 |
|
473 |
|
516 |
handle.progress((int) (currentWorkDone += totalWork * NOTIFY_WORK)); |
474 |
handle.progress((int) (currentWorkDone += totalWork * NOTIFY_WORK)); |
Lines 577-616
Link Here
|
577 |
} |
535 |
} |
578 |
} |
536 |
} |
579 |
|
537 |
|
580 |
private static boolean doDelete(Project original, FileObject toDelete) throws IOException { |
|
|
581 |
if (!original.getProjectDirectory().equals(FileOwnerQuery.getOwner(toDelete).getProjectDirectory())) { |
582 |
return false; |
583 |
} |
584 |
|
585 |
if (toDelete.isFolder()) { |
586 |
boolean delete = true; |
587 |
|
588 |
for (FileObject kid : toDelete.getChildren()) { |
589 |
delete &= doDelete(original, kid); |
590 |
} |
591 |
|
592 |
if (delete) { |
593 |
//#83958 |
594 |
DataFolder.findFolder(toDelete).delete(); |
595 |
} |
596 |
|
597 |
return delete; |
598 |
} else { |
599 |
assert toDelete.isData(); |
600 |
try { |
601 |
//#83958 |
602 |
DataObject dobj = DataObject.find(toDelete); |
603 |
dobj.delete(); |
604 |
} catch (DataObjectNotFoundException ex) { |
605 |
//In case of MultiDataObjects the file may be laready deleted |
606 |
if (toDelete.isValid()) { |
607 |
toDelete.delete(); |
608 |
} |
609 |
} |
610 |
return true; |
611 |
} |
612 |
} |
613 |
|
614 |
private static JComponent wrapPanel(JComponent component) { |
538 |
private static JComponent wrapPanel(JComponent component) { |
615 |
component.setBorder(new EmptyBorder(12, 12, 12, 12)); |
539 |
component.setBorder(new EmptyBorder(12, 12, 12, 12)); |
616 |
|
540 |
|