1 11 package org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage; 12 13 import java.util.List ; 14 15 import org.eclipse.core.runtime.IPath; 16 import org.eclipse.core.runtime.Path; 17 18 import org.eclipse.core.resources.IFolder; 19 import org.eclipse.core.resources.IResource; 20 21 import org.eclipse.swt.widgets.Display; 22 import org.eclipse.swt.widgets.Shell; 23 24 import org.eclipse.jface.dialogs.MessageDialog; 25 import org.eclipse.jface.window.Window; 26 27 import org.eclipse.ui.dialogs.NewFolderDialog; 28 29 import org.eclipse.jdt.core.IClasspathEntry; 30 import org.eclipse.jdt.core.IJavaProject; 31 import org.eclipse.jdt.core.JavaModelException; 32 33 import org.eclipse.jdt.internal.corext.util.Messages; 34 35 import org.eclipse.jdt.ui.PreferenceConstants; 36 import org.eclipse.jdt.ui.wizards.BuildPathDialogAccess; 37 38 import org.eclipse.jdt.internal.ui.JavaPlugin; 39 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages; 40 import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElement; 41 import org.eclipse.jdt.internal.ui.wizards.buildpaths.ExclusionInclusionDialog; 42 43 48 public class ClasspathModifierQueries { 49 50 55 public static abstract class OutputFolderValidator { 56 protected IClasspathEntry[] fEntries; 57 protected List fElements; 58 59 70 public OutputFolderValidator(List newElements, IJavaProject project) throws JavaModelException { 71 fEntries= project.getRawClasspath(); 72 fElements= newElements; 73 } 74 75 84 public abstract boolean validate(IPath outputLocation); 85 } 86 87 92 public static interface ILinkToQuery { 93 103 public boolean doQuery(); 104 105 113 public IFolder getCreatedFolder(); 114 115 122 public OutputFolderQuery getOutputFolderQuery(); 123 } 124 128 public static abstract class OutputFolderQuery { 129 protected IPath fDesiredOutputLocation; 130 131 140 public OutputFolderQuery(IPath outputLocation) { 141 if (outputLocation != null) 142 fDesiredOutputLocation= outputLocation.makeAbsolute(); 143 } 144 145 150 public IPath getDesiredOutputLocation() { 151 return fDesiredOutputLocation; 152 } 153 154 166 public abstract IPath getOutputLocation(); 167 168 179 public abstract boolean removeProjectFromClasspath(); 180 181 206 public abstract boolean doQuery(final boolean editingOutputFolder, final OutputFolderValidator validator, final IJavaProject project) throws JavaModelException; 207 208 } 209 210 214 public static interface IInclusionExclusionQuery { 215 236 public boolean doQuery(CPListElement element, boolean focusOnExcluded); 237 238 245 public IPath[] getInclusionPattern(); 246 247 254 public IPath[] getExclusionPattern(); 255 } 256 257 261 public static interface IOutputLocationQuery { 262 273 public boolean doQuery(CPListElement element); 274 275 284 public IPath getOutputLocation(); 285 286 296 public OutputFolderQuery getOutputFolderQuery(IPath outputLocation) throws JavaModelException; 297 } 298 299 302 public static interface IRemoveLinkedFolderQuery { 303 304 305 public static final int REMOVE_CANCEL= 0; 306 307 308 public static final int REMOVE_BUILD_PATH= 1; 309 310 311 public static final int REMOVE_BUILD_PATH_AND_FOLDER= 2; 312 313 319 public int doQuery(IFolder folder); 320 } 321 322 325 public static interface ICreateFolderQuery { 326 333 public boolean doQuery(); 334 335 350 public boolean isSourceFolder(); 351 352 360 public IFolder getCreatedFolder(); 361 } 362 363 366 public static interface IAddArchivesQuery { 367 373 public IPath[] doQuery(); 374 } 375 376 379 public static interface IAddLibrariesQuery { 380 388 public IClasspathEntry[] doQuery(final IJavaProject project, final IClasspathEntry[] entries); 389 } 390 391 401 public static OutputFolderQuery getDefaultFolderQuery(final Shell shell, IPath outputLocation) { 402 403 return new OutputFolderQuery(outputLocation) { 404 protected IPath fOutputLocation; 405 protected boolean fRemoveProject; 406 407 public boolean doQuery(final boolean editingOutputFolder, final OutputFolderValidator validator, final IJavaProject project) throws JavaModelException { 408 final boolean[] result= { false }; 409 fRemoveProject= false; 410 fOutputLocation= project.getOutputLocation(); 411 Display.getDefault().syncExec(new Runnable () { 412 public void run() { 413 Shell sh= shell != null ? shell : JavaPlugin.getActiveWorkbenchShell(); 414 415 String title= NewWizardMessages.ClasspathModifier_ChangeOutputLocationDialog_title; 416 417 if (fDesiredOutputLocation.segmentCount() == 1) { 418 String outputFolderName= PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME); 419 IPath newOutputFolder= fDesiredOutputLocation.append(outputFolderName); 420 newOutputFolder= getValidPath(newOutputFolder, validator); 421 String message= Messages.format(NewWizardMessages.ClasspathModifier_ChangeOutputLocationDialog_project_outputLocation, newOutputFolder); 422 fRemoveProject= true; 423 if (MessageDialog.openConfirm(sh, title, message)) { 424 fOutputLocation= newOutputFolder; 425 result[0]= true; 426 } 427 } else { 428 IPath newOutputFolder= fDesiredOutputLocation; 429 newOutputFolder= getValidPath(newOutputFolder, validator); 430 if (editingOutputFolder) { 431 fOutputLocation= newOutputFolder; 432 result[0]= true; 433 return; } 435 String message= NewWizardMessages.ClasspathModifier_ChangeOutputLocationDialog_project_message; 436 fRemoveProject= true; 437 if (MessageDialog.openQuestion(sh, title, message)) { 438 fOutputLocation= newOutputFolder; 439 result[0]= true; 440 } 441 } 442 } 443 }); 444 return result[0]; 445 } 446 447 public IPath getOutputLocation() { 448 return fOutputLocation; 449 } 450 451 public boolean removeProjectFromClasspath() { 452 return fRemoveProject; 453 } 454 455 private IPath getValidPath(IPath newOutputFolder, OutputFolderValidator validator) { 456 int i= 1; 457 IPath path= newOutputFolder; 458 while (!validator.validate(path)) { 459 path= new Path(newOutputFolder.toString() + i); 460 i++; 461 } 462 return path; 463 } 464 }; 465 } 466 467 477 public static IInclusionExclusionQuery getDefaultInclusionExclusionQuery(final Shell shell) { 478 return new IInclusionExclusionQuery() { 479 480 protected IPath[] fInclusionPattern; 481 protected IPath[] fExclusionPattern; 482 483 public boolean doQuery(final CPListElement element, final boolean focusOnExcluded) { 484 final boolean[] result= { false }; 485 Display.getDefault().syncExec(new Runnable () { 486 public void run() { 487 Shell sh= shell != null ? shell : JavaPlugin.getActiveWorkbenchShell(); 488 ExclusionInclusionDialog dialog= new ExclusionInclusionDialog(sh, element, focusOnExcluded); 489 result[0]= dialog.open() == Window.OK; 490 fInclusionPattern= dialog.getInclusionPattern(); 491 fExclusionPattern= dialog.getExclusionPattern(); 492 } 493 }); 494 return result[0]; 495 } 496 497 public IPath[] getInclusionPattern() { 498 return fInclusionPattern; 499 } 500 501 public IPath[] getExclusionPattern() { 502 return fExclusionPattern; 503 } 504 }; 505 } 506 507 522 public static ILinkToQuery getDefaultLinkQuery(final Shell shell, final IJavaProject project, final IPath desiredOutputLocation) { 523 return new ILinkToQuery() { 524 protected IFolder fFolder; 525 526 public boolean doQuery() { 527 final boolean[] isOK= {false}; 528 Display.getDefault().syncExec(new Runnable () { 529 public void run() { 530 Shell sh= shell != null ? shell : JavaPlugin.getActiveWorkbenchShell(); 531 532 LinkFolderDialog dialog= new LinkFolderDialog(sh, project.getProject()); 533 isOK[0]= dialog.open() == Window.OK; 534 if (isOK[0]) 535 fFolder= dialog.getCreatedFolder(); 536 } 537 }); 538 return isOK[0]; 539 } 540 541 public IFolder getCreatedFolder() { 542 return fFolder; 543 } 544 545 public OutputFolderQuery getOutputFolderQuery() { 546 return getDefaultFolderQuery(shell, desiredOutputLocation); 547 } 548 549 }; 550 } 551 552 562 public static IAddArchivesQuery getDefaultArchivesQuery(final Shell shell) { 563 return new IAddArchivesQuery() { 564 565 public IPath[] doQuery() { 566 final IPath[][] selected= {null}; 567 Display.getDefault().syncExec(new Runnable () { 568 public void run() { 569 Shell sh= shell != null ? shell : JavaPlugin.getActiveWorkbenchShell(); 570 selected[0]= BuildPathDialogAccess.chooseExternalJAREntries(sh); 571 } 572 }); 573 if(selected[0] == null) 574 return new IPath[0]; 575 return selected[0]; 576 } 577 }; 578 } 579 580 588 public static IRemoveLinkedFolderQuery getDefaultRemoveLinkedFolderQuery(final Shell shell) { 589 return new IRemoveLinkedFolderQuery() { 590 591 public final int doQuery(final IFolder folder) { 592 final int[] result= { IRemoveLinkedFolderQuery.REMOVE_BUILD_PATH}; 593 Display.getDefault().syncExec(new Runnable () { 594 595 public final void run() { 596 final RemoveLinkedFolderDialog dialog= new RemoveLinkedFolderDialog((shell != null ? shell : JavaPlugin.getActiveWorkbenchShell()), folder); 597 final int status= dialog.open(); 598 if (status == 0) 599 result[0]= dialog.getRemoveStatus(); 600 else 601 result[0]= IRemoveLinkedFolderQuery.REMOVE_CANCEL; 602 } 603 }); 604 return result[0]; 605 } 606 }; 607 } 608 609 619 public static IAddLibrariesQuery getDefaultLibrariesQuery(final Shell shell) { 620 return new IAddLibrariesQuery() { 621 622 public IClasspathEntry[] doQuery(final IJavaProject project, final IClasspathEntry[] entries) { 623 final IClasspathEntry[][] selected= {null}; 624 Display.getDefault().syncExec(new Runnable () { 625 public void run() { 626 Shell sh= shell != null ? shell : JavaPlugin.getActiveWorkbenchShell(); 627 selected[0]= BuildPathDialogAccess.chooseContainerEntries(sh, project, entries); 628 } 629 }); 630 if(selected[0] == null) 631 return new IClasspathEntry[0]; 632 return selected[0]; 633 } 634 }; 635 } 636 637 644 public static ICreateFolderQuery getDefaultCreateFolderQuery(final Shell shell, final IJavaProject project) { 645 return new ICreateFolderQuery() { 646 647 private IFolder fNewFolder; 648 649 public boolean doQuery() { 650 final boolean[] isOK= {false}; 651 Display.getDefault().syncExec(new Runnable () { 652 public void run() { 653 Shell sh= shell != null ? shell : JavaPlugin.getActiveWorkbenchShell(); 654 655 NewFolderDialog dialog= new NewFolderDialog(sh, project.getProject()); 656 isOK[0]= dialog.open() == Window.OK; 657 if (isOK[0]) { 658 IResource sourceContainer= (IResource) dialog.getResult()[0]; 659 if (sourceContainer instanceof IFolder) { 660 fNewFolder= (IFolder)sourceContainer; 661 } else { 662 fNewFolder= null; 663 } 664 } 665 } 666 }); 667 return isOK[0]; 668 } 669 670 671 public boolean isSourceFolder() { 672 return true; 673 } 674 675 public IFolder getCreatedFolder() { 676 return fNewFolder; 677 } 678 679 }; 680 } 681 } 682 | Popular Tags |