|
Lines 4-11
Link Here
|
| 4 |
*/ |
4 |
*/ |
| 5 |
package org.eclipse.jdt.internal.ui.packageview; |
5 |
package org.eclipse.jdt.internal.ui.packageview; |
| 6 |
|
6 |
|
|
|
7 |
import java.util.ArrayList; |
| 8 |
import java.util.List; |
| 9 |
|
| 7 |
import org.eclipse.core.resources.IResource; |
10 |
import org.eclipse.core.resources.IResource; |
| 8 |
import org.eclipse.core.resources.IResourceDelta; |
11 |
import org.eclipse.core.resources.IResourceDelta; |
|
|
12 |
import org.eclipse.core.runtime.IPath; |
| 13 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 9 |
|
14 |
|
| 10 |
import org.eclipse.swt.widgets.Control; |
15 |
import org.eclipse.swt.widgets.Control; |
| 11 |
|
16 |
|
|
Lines 16-27
Link Here
|
| 16 |
import org.eclipse.jface.viewers.Viewer; |
21 |
import org.eclipse.jface.viewers.Viewer; |
| 17 |
|
22 |
|
| 18 |
import org.eclipse.jdt.core.ElementChangedEvent; |
23 |
import org.eclipse.jdt.core.ElementChangedEvent; |
|
|
24 |
import org.eclipse.jdt.core.IBuffer; |
| 19 |
import org.eclipse.jdt.core.IClassFile; |
25 |
import org.eclipse.jdt.core.IClassFile; |
| 20 |
import org.eclipse.jdt.core.ICompilationUnit; |
26 |
import org.eclipse.jdt.core.ICompilationUnit; |
| 21 |
import org.eclipse.jdt.core.IElementChangedListener; |
27 |
import org.eclipse.jdt.core.IElementChangedListener; |
| 22 |
import org.eclipse.jdt.core.IJavaElement; |
28 |
import org.eclipse.jdt.core.IJavaElement; |
| 23 |
import org.eclipse.jdt.core.IJavaElementDelta; |
29 |
import org.eclipse.jdt.core.IJavaElementDelta; |
|
|
30 |
import org.eclipse.jdt.core.IJavaModel; |
| 24 |
import org.eclipse.jdt.core.IJavaProject; |
31 |
import org.eclipse.jdt.core.IJavaProject; |
|
|
32 |
import org.eclipse.jdt.core.IOpenable; |
| 25 |
import org.eclipse.jdt.core.IPackageFragment; |
33 |
import org.eclipse.jdt.core.IPackageFragment; |
| 26 |
import org.eclipse.jdt.core.IPackageFragmentRoot; |
34 |
import org.eclipse.jdt.core.IPackageFragmentRoot; |
| 27 |
import org.eclipse.jdt.core.IWorkingCopy; |
35 |
import org.eclipse.jdt.core.IWorkingCopy; |
|
Lines 41-46
Link Here
|
| 41 |
|
49 |
|
| 42 |
protected TreeViewer fViewer; |
50 |
protected TreeViewer fViewer; |
| 43 |
protected Object fInput; |
51 |
protected Object fInput; |
|
|
52 |
protected boolean fHierarchy; |
| 44 |
|
53 |
|
| 45 |
/* (non-Javadoc) |
54 |
/* (non-Javadoc) |
| 46 |
* Method declared on IContentProvider. |
55 |
* Method declared on IContentProvider. |
|
Lines 364-367
Link Here
|
| 364 |
ctrl.getDisplay().asyncExec(r); |
373 |
ctrl.getDisplay().asyncExec(r); |
| 365 |
} |
374 |
} |
| 366 |
} |
375 |
} |
|
|
376 |
|
| 377 |
/** |
| 378 |
* Returns the set of top-level packages fragments for a fragement root. |
| 379 |
*
* @param root the root to get the package of
* @return an array of top-level packages (IPackageFragement)
* @throws JavaModelException
*/ |
| 380 |
protected Object[] getTopPackages(IPackageFragmentRoot root) throws JavaModelException { |
| 381 |
IJavaElement[] fragments= root.getChildren(); |
| 382 |
List rootPkgs = new ArrayList(); |
| 383 |
for (int i = 0; i < fragments.length; i++) { |
| 384 |
String name = fragments[i].getElementName(); |
| 385 |
// top-level includes the default and any without a dot |
| 386 |
if (name.indexOf('.') == -1 || name.equals("")) { |
| 387 |
rootPkgs.add(new PackageNode((IPackageFragment)fragments[i])); |
| 388 |
} |
| 389 |
} |
| 390 |
Object[] nonJavaResources= root.getNonJavaResources(); |
| 391 |
if (nonJavaResources == null) |
| 392 |
return rootPkgs.toArray(); |
| 393 |
return concatenate(rootPkgs.toArray(), nonJavaResources); |
| 394 |
} |
| 395 |
|
| 396 |
/* (non-Javadoc) |
| 397 |
* Method declared on ITreeContentProvider. |
| 398 |
*/ |
| 399 |
public Object[] getChildren(Object element) { |
| 400 |
if (!exists(element)) |
| 401 |
return NO_CHILDREN; |
| 402 |
|
| 403 |
if (fHierarchy && element instanceof IPackageFragmentRoot) |
| 404 |
{ |
| 405 |
try { |
| 406 |
return getTopPackages((IPackageFragmentRoot)element); |
| 407 |
} catch (JavaModelException e) { |
| 408 |
return NO_CHILDREN; |
| 409 |
} |
| 410 |
} // if |
| 411 |
return super.getChildren(element); |
| 412 |
} |
| 413 |
|
| 414 |
/** |
| 415 |
* A wrapper around an IPackageFragment that treats the package |
| 416 |
* hierarchically (sub-packages are children). |
| 417 |
*/ |
| 418 |
private static class PackageNode implements IPackageFragment { |
| 419 |
|
| 420 |
private IPackageFragment pkg; |
| 421 |
|
| 422 |
/** |
| 423 |
* |
| 424 |
*/ |
| 425 |
public PackageNode(IPackageFragment pkg) { |
| 426 |
this.pkg = pkg; |
| 427 |
} |
| 428 |
|
| 429 |
/* (non-Javadoc) |
| 430 |
* @see org.eclipse.jdt.core.IJavaElement#exists() |
| 431 |
*/ |
| 432 |
public boolean exists() { |
| 433 |
return pkg.exists(); |
| 434 |
} |
| 435 |
|
| 436 |
/* (non-Javadoc) |
| 437 |
* @see org.eclipse.jdt.core.IJavaElement#getAncestor(int) |
| 438 |
*/ |
| 439 |
public IJavaElement getAncestor(int ancestorType) { |
| 440 |
return pkg.getAncestor(ancestorType); |
| 441 |
} |
| 442 |
|
| 443 |
/* (non-Javadoc) |
| 444 |
* @see org.eclipse.jdt.core.IJavaElement#getCorrespondingResource() |
| 445 |
*/ |
| 446 |
public IResource getCorrespondingResource() throws JavaModelException { |
| 447 |
return pkg.getCorrespondingResource(); |
| 448 |
} |
| 449 |
|
| 450 |
/* (non-Javadoc) |
| 451 |
* @see org.eclipse.jdt.core.IJavaElement#getElementName() |
| 452 |
*/ |
| 453 |
public String getElementName() { |
| 454 |
String name = pkg.getElementName(); |
| 455 |
// returns just the node name, but breaks the children somehow |
| 456 |
// int dotIdx = name.lastIndexOf('.'); |
| 457 |
// if (dotIdx != -1) { |
| 458 |
// return name.substring(dotIdx); |
| 459 |
// } |
| 460 |
return name; |
| 461 |
} |
| 462 |
|
| 463 |
/* (non-Javadoc) |
| 464 |
* @see org.eclipse.jdt.core.IJavaElement#getElementType() |
| 465 |
*/ |
| 466 |
public int getElementType() { |
| 467 |
return pkg.getElementType(); |
| 468 |
} |
| 469 |
|
| 470 |
/* (non-Javadoc) |
| 471 |
* @see org.eclipse.jdt.core.IJavaElement#getHandleIdentifier() |
| 472 |
*/ |
| 473 |
public String getHandleIdentifier() { |
| 474 |
return pkg.getHandleIdentifier(); |
| 475 |
} |
| 476 |
|
| 477 |
/* (non-Javadoc) |
| 478 |
* @see org.eclipse.jdt.core.IJavaElement#getJavaModel() |
| 479 |
*/ |
| 480 |
public IJavaModel getJavaModel() { |
| 481 |
return pkg.getJavaModel(); |
| 482 |
} |
| 483 |
|
| 484 |
/* (non-Javadoc) |
| 485 |
* @see org.eclipse.jdt.core.IJavaElement#getJavaProject() |
| 486 |
*/ |
| 487 |
public IJavaProject getJavaProject() { |
| 488 |
return pkg.getJavaProject(); |
| 489 |
} |
| 490 |
|
| 491 |
/* (non-Javadoc) |
| 492 |
* @see org.eclipse.jdt.core.IJavaElement#getOpenable() |
| 493 |
*/ |
| 494 |
public IOpenable getOpenable() { |
| 495 |
return pkg.getOpenable(); |
| 496 |
} |
| 497 |
|
| 498 |
/* (non-Javadoc) |
| 499 |
* @see org.eclipse.jdt.core.IJavaElement#getParent() |
| 500 |
*/ |
| 501 |
public IJavaElement getParent() { |
| 502 |
return pkg.getParent(); |
| 503 |
} |
| 504 |
|
| 505 |
/* (non-Javadoc) |
| 506 |
* @see org.eclipse.jdt.core.IJavaElement#getPath() |
| 507 |
*/ |
| 508 |
public IPath getPath() { |
| 509 |
return pkg.getPath(); |
| 510 |
} |
| 511 |
|
| 512 |
/* (non-Javadoc) |
| 513 |
* @see org.eclipse.jdt.core.IJavaElement#getResource() |
| 514 |
*/ |
| 515 |
public IResource getResource() { |
| 516 |
return pkg.getResource(); |
| 517 |
} |
| 518 |
|
| 519 |
/* (non-Javadoc) |
| 520 |
* @see org.eclipse.jdt.core.IJavaElement#getUnderlyingResource() |
| 521 |
*/ |
| 522 |
public IResource getUnderlyingResource() throws JavaModelException { |
| 523 |
return pkg.getUnderlyingResource(); |
| 524 |
} |
| 525 |
|
| 526 |
/* (non-Javadoc) |
| 527 |
* @see org.eclipse.jdt.core.IJavaElement#isReadOnly() |
| 528 |
*/ |
| 529 |
public boolean isReadOnly() { |
| 530 |
return pkg.isReadOnly(); |
| 531 |
} |
| 532 |
|
| 533 |
/* (non-Javadoc) |
| 534 |
* @see org.eclipse.jdt.core.IJavaElement#isStructureKnown() |
| 535 |
*/ |
| 536 |
public boolean isStructureKnown() throws JavaModelException { |
| 537 |
return pkg.isStructureKnown(); |
| 538 |
} |
| 539 |
|
| 540 |
/* (non-Javadoc) |
| 541 |
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) |
| 542 |
*/ |
| 543 |
public Object getAdapter(Class adapter) { |
| 544 |
return pkg.getAdapter(adapter); |
| 545 |
} |
| 546 |
/* (non-Javadoc) |
| 547 |
* @see org.eclipse.jdt.core.IPackageFragment#containsJavaResources() |
| 548 |
*/ |
| 549 |
public boolean containsJavaResources() throws JavaModelException { |
| 550 |
return pkg.containsJavaResources(); |
| 551 |
} |
| 552 |
|
| 553 |
/* (non-Javadoc) |
| 554 |
* @see org.eclipse.jdt.core.IPackageFragment#createCompilationUnit(java.lang.String, java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor) |
| 555 |
*/ |
| 556 |
public ICompilationUnit createCompilationUnit( |
| 557 |
String name, |
| 558 |
String contents, |
| 559 |
boolean force, |
| 560 |
IProgressMonitor monitor) |
| 561 |
throws JavaModelException { |
| 562 |
return pkg.createCompilationUnit(name, contents, force, monitor); |
| 563 |
} |
| 564 |
|
| 565 |
/* (non-Javadoc) |
| 566 |
* @see org.eclipse.jdt.core.IPackageFragment#getClassFile(java.lang.String) |
| 567 |
*/ |
| 568 |
public IClassFile getClassFile(String name) { |
| 569 |
return pkg.getClassFile(name); |
| 570 |
} |
| 571 |
|
| 572 |
/* (non-Javadoc) |
| 573 |
* @see org.eclipse.jdt.core.IPackageFragment#getClassFiles() |
| 574 |
*/ |
| 575 |
public IClassFile[] getClassFiles() throws JavaModelException { |
| 576 |
return pkg.getClassFiles(); |
| 577 |
} |
| 578 |
|
| 579 |
/* (non-Javadoc) |
| 580 |
* @see org.eclipse.jdt.core.IPackageFragment#getCompilationUnit(java.lang.String) |
| 581 |
*/ |
| 582 |
public ICompilationUnit getCompilationUnit(String name) { |
| 583 |
return pkg.getCompilationUnit(name); |
| 584 |
} |
| 585 |
|
| 586 |
/* (non-Javadoc) |
| 587 |
* @see org.eclipse.jdt.core.IPackageFragment#getCompilationUnits() |
| 588 |
*/ |
| 589 |
public ICompilationUnit[] getCompilationUnits() throws JavaModelException { |
| 590 |
return pkg.getCompilationUnits(); |
| 591 |
} |
| 592 |
|
| 593 |
/* (non-Javadoc) |
| 594 |
* @see org.eclipse.jdt.core.IPackageFragment#getKind() |
| 595 |
*/ |
| 596 |
public int getKind() throws JavaModelException { |
| 597 |
return pkg.getKind(); |
| 598 |
} |
| 599 |
|
| 600 |
/* (non-Javadoc) |
| 601 |
* @see org.eclipse.jdt.core.IPackageFragment#getNonJavaResources() |
| 602 |
*/ |
| 603 |
public Object[] getNonJavaResources() throws JavaModelException { |
| 604 |
// concatenate nonjava with sub-packages |
| 605 |
Object[] subPkgs = getSubpackages(); |
| 606 |
Object[] nonJava = pkg.getNonJavaResources(); |
| 607 |
return concatenate(nonJava,subPkgs); |
| 608 |
} |
| 609 |
|
| 610 |
/** |
| 611 |
* Returns the list of sub-packages. |
| 612 |
*
* @return an array of IJavaElements consisting of the sub-packages
* @throws JavaModelException
*/ |
| 613 |
public IJavaElement[] getSubpackages() throws JavaModelException { |
| 614 |
if (isDefaultPackage()) { |
| 615 |
return new IJavaElement[0]; |
| 616 |
} |
| 617 |
List subPkgs = new ArrayList(); |
| 618 |
IJavaElement[] packages= ((IPackageFragmentRoot)getParent()).getChildren(); |
| 619 |
String name = pkg.getElementName(); |
| 620 |
for (int i = 0; i < packages.length; i++) { |
| 621 |
if (packages[i] == pkg) |
| 622 |
continue; |
| 623 |
|
| 624 |
String subPkgName = packages[i].getElementName(); |
| 625 |
if (subPkgName.startsWith(name) && |
| 626 |
subPkgName.lastIndexOf('.') == name.length()) { |
| 627 |
subPkgs.add(new PackageNode((IPackageFragment)packages[i])); |
| 628 |
} |
| 629 |
} |
| 630 |
|
| 631 |
return (IJavaElement[]) subPkgs.toArray(new IJavaElement[subPkgs.size()]); |
| 632 |
} |
| 633 |
|
| 634 |
/* (non-Javadoc) |
| 635 |
* @see org.eclipse.jdt.core.IPackageFragment#hasSubpackages() |
| 636 |
*/ |
| 637 |
public boolean hasSubpackages() throws JavaModelException { |
| 638 |
return pkg.hasSubpackages(); |
| 639 |
} |
| 640 |
|
| 641 |
/* (non-Javadoc) |
| 642 |
* @see org.eclipse.jdt.core.IPackageFragment#isDefaultPackage() |
| 643 |
*/ |
| 644 |
public boolean isDefaultPackage() { |
| 645 |
return pkg.isDefaultPackage(); |
| 646 |
} |
| 647 |
|
| 648 |
/* (non-Javadoc) |
| 649 |
* @see org.eclipse.jdt.core.IParent#getChildren() |
| 650 |
*/ |
| 651 |
public IJavaElement[] getChildren() throws JavaModelException { |
| 652 |
IJavaElement[] children = pkg.getChildren(); |
| 653 |
IJavaElement[] pkgs = getSubpackages(); |
| 654 |
IJavaElement[] both = new IJavaElement[children.length + pkgs.length]; |
| 655 |
System.arraycopy(children, 0, both, 0, children.length); |
| 656 |
System.arraycopy(pkgs, 0, both, children.length, pkgs.length); |
| 657 |
return both; |
| 658 |
} |
| 659 |
|
| 660 |
/* (non-Javadoc) |
| 661 |
* @see org.eclipse.jdt.core.IParent#hasChildren() |
| 662 |
*/ |
| 663 |
public boolean hasChildren() throws JavaModelException { |
| 664 |
return pkg.hasChildren() || hasSubpackages(); |
| 665 |
} |
| 666 |
|
| 667 |
/* (non-Javadoc) |
| 668 |
* @see org.eclipse.jdt.core.IOpenable#close() |
| 669 |
*/ |
| 670 |
public void close() throws JavaModelException { |
| 671 |
pkg.close(); |
| 672 |
} |
| 673 |
|
| 674 |
/* (non-Javadoc) |
| 675 |
* @see org.eclipse.jdt.core.IOpenable#getBuffer() |
| 676 |
*/ |
| 677 |
public IBuffer getBuffer() throws JavaModelException { |
| 678 |
return pkg.getBuffer(); |
| 679 |
} |
| 680 |
|
| 681 |
/* (non-Javadoc) |
| 682 |
* @see org.eclipse.jdt.core.IOpenable#hasUnsavedChanges() |
| 683 |
*/ |
| 684 |
public boolean hasUnsavedChanges() throws JavaModelException { |
| 685 |
return pkg.hasUnsavedChanges(); |
| 686 |
} |
| 687 |
|
| 688 |
/* (non-Javadoc) |
| 689 |
* @see org.eclipse.jdt.core.IOpenable#isConsistent() |
| 690 |
*/ |
| 691 |
public boolean isConsistent() throws JavaModelException { |
| 692 |
return pkg.isConsistent(); |
| 693 |
} |
| 694 |
|
| 695 |
/* (non-Javadoc) |
| 696 |
* @see org.eclipse.jdt.core.IOpenable#isOpen() |
| 697 |
*/ |
| 698 |
public boolean isOpen() { |
| 699 |
return pkg.isOpen(); |
| 700 |
} |
| 701 |
|
| 702 |
/* (non-Javadoc) |
| 703 |
* @see org.eclipse.jdt.core.IOpenable#makeConsistent(org.eclipse.core.runtime.IProgressMonitor) |
| 704 |
*/ |
| 705 |
public void makeConsistent(IProgressMonitor progress) throws JavaModelException { |
| 706 |
pkg.makeConsistent(progress); |
| 707 |
} |
| 708 |
|
| 709 |
/* (non-Javadoc) |
| 710 |
* @see org.eclipse.jdt.core.IOpenable#open(org.eclipse.core.runtime.IProgressMonitor) |
| 711 |
*/ |
| 712 |
public void open(IProgressMonitor progress) throws JavaModelException { |
| 713 |
pkg.open(progress); |
| 714 |
} |
| 715 |
|
| 716 |
/* (non-Javadoc) |
| 717 |
* @see org.eclipse.jdt.core.IOpenable#save(org.eclipse.core.runtime.IProgressMonitor, boolean) |
| 718 |
*/ |
| 719 |
public void save(IProgressMonitor progress, boolean force) throws JavaModelException { |
| 720 |
pkg.save(progress, force); |
| 721 |
} |
| 722 |
|
| 723 |
/* (non-Javadoc) |
| 724 |
* @see org.eclipse.jdt.core.ISourceManipulation#copy(org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.IJavaElement, java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor) |
| 725 |
*/ |
| 726 |
public void copy( |
| 727 |
IJavaElement container, |
| 728 |
IJavaElement sibling, |
| 729 |
String rename, |
| 730 |
boolean replace, |
| 731 |
IProgressMonitor monitor) |
| 732 |
throws JavaModelException { |
| 733 |
pkg.copy(container, sibling, rename, replace, monitor); |
| 734 |
} |
| 735 |
|
| 736 |
/* (non-Javadoc) |
| 737 |
* @see org.eclipse.jdt.core.ISourceManipulation#delete(boolean, org.eclipse.core.runtime.IProgressMonitor) |
| 738 |
*/ |
| 739 |
public void delete(boolean force, IProgressMonitor monitor) throws JavaModelException { |
| 740 |
pkg.delete(force, monitor); |
| 741 |
} |
| 742 |
|
| 743 |
/* (non-Javadoc) |
| 744 |
* @see org.eclipse.jdt.core.ISourceManipulation#move(org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.IJavaElement, java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor) |
| 745 |
*/ |
| 746 |
public void move( |
| 747 |
IJavaElement container, |
| 748 |
IJavaElement sibling, |
| 749 |
String rename, |
| 750 |
boolean replace, |
| 751 |
IProgressMonitor monitor) |
| 752 |
throws JavaModelException { |
| 753 |
pkg.move(container, sibling, rename, replace, monitor); |
| 754 |
} |
| 755 |
|
| 756 |
/* (non-Javadoc) |
| 757 |
* @see org.eclipse.jdt.core.ISourceManipulation#rename(java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor) |
| 758 |
*/ |
| 759 |
public void rename(String name, boolean replace, IProgressMonitor monitor) throws JavaModelException { |
| 760 |
pkg.rename(name, replace, monitor); |
| 761 |
} |
| 762 |
|
| 763 |
} |
| 367 |
} |
764 |
} |