|
Lines 12-17
Link Here
|
| 12 |
package org.eclipse.ui.internal; |
12 |
package org.eclipse.ui.internal; |
| 13 |
|
13 |
|
| 14 |
import java.util.ArrayList; |
14 |
import java.util.ArrayList; |
|
|
15 |
import java.util.Collections; |
| 15 |
import java.util.Enumeration; |
16 |
import java.util.Enumeration; |
| 16 |
import java.util.List; |
17 |
import java.util.List; |
| 17 |
import java.util.StringTokenizer; |
18 |
import java.util.StringTokenizer; |
|
Lines 754-762
Link Here
|
| 754 |
*/ |
755 |
*/ |
| 755 |
private LayoutPart findPart(String primaryId, String secondaryId) { |
756 |
private LayoutPart findPart(String primaryId, String secondaryId) { |
| 756 |
// check main window. |
757 |
// check main window. |
|
|
758 |
ArrayList matchingParts = new ArrayList(); |
| 757 |
LayoutPart part = (secondaryId != null) ? |
759 |
LayoutPart part = (secondaryId != null) ? |
| 758 |
findPart(primaryId, secondaryId, mainLayout.getChildren()) : |
760 |
findPart(primaryId, secondaryId, mainLayout.getChildren(), matchingParts) : |
| 759 |
findPart(primaryId, mainLayout.getChildren()); |
761 |
findPart(primaryId, mainLayout.getChildren(), matchingParts); |
| 760 |
if (part != null) |
762 |
if (part != null) |
| 761 |
return part; |
763 |
return part; |
| 762 |
|
764 |
|
|
Lines 764-771
Link Here
|
| 764 |
for (int i = 0, length = detachedWindowList.size(); i < length; i++) { |
766 |
for (int i = 0, length = detachedWindowList.size(); i < length; i++) { |
| 765 |
DetachedWindow window = (DetachedWindow) detachedWindowList.get(i); |
767 |
DetachedWindow window = (DetachedWindow) detachedWindowList.get(i); |
| 766 |
part = (secondaryId != null) ? |
768 |
part = (secondaryId != null) ? |
| 767 |
findPart(primaryId, secondaryId, window.getChildren()) : |
769 |
findPart(primaryId, secondaryId, window.getChildren(), matchingParts) : |
| 768 |
findPart(primaryId, window.getChildren()); |
770 |
findPart(primaryId, window.getChildren(), matchingParts); |
| 769 |
if (part != null) |
771 |
if (part != null) |
| 770 |
return part; |
772 |
return part; |
| 771 |
} |
773 |
} |
|
Lines 773-800
Link Here
|
| 773 |
DetachedPlaceHolder holder = |
775 |
DetachedPlaceHolder holder = |
| 774 |
(DetachedPlaceHolder) detachedPlaceHolderList.get(i); |
776 |
(DetachedPlaceHolder) detachedPlaceHolderList.get(i); |
| 775 |
part = (secondaryId != null) ? |
777 |
part = (secondaryId != null) ? |
| 776 |
findPart(primaryId, secondaryId, holder.getChildren()) : |
778 |
findPart(primaryId, secondaryId, holder.getChildren(), matchingParts) : |
| 777 |
findPart(primaryId, holder.getChildren()) ; |
779 |
findPart(primaryId, holder.getChildren(), matchingParts) ; |
| 778 |
if (part != null) |
780 |
if (part != null) |
| 779 |
return part; |
781 |
return part; |
| 780 |
} |
782 |
} |
| 781 |
|
783 |
|
|
|
784 |
// sort the matching parts |
| 785 |
if (matchingParts.size() > 0) { |
| 786 |
Collections.sort(matchingParts); |
| 787 |
MatchingPart mostSignificantPart = (MatchingPart)matchingParts.get(0); |
| 788 |
if (mostSignificantPart != null) |
| 789 |
return mostSignificantPart.part; |
| 790 |
} |
| 791 |
|
| 782 |
// Not found. |
792 |
// Not found. |
| 783 |
return null; |
793 |
return null; |
| 784 |
} |
794 |
} |
| 785 |
private class MatchingPart { |
795 |
private class MatchingPart implements Comparable { |
| 786 |
String pid; |
796 |
String pid; |
| 787 |
String sid; |
797 |
String sid; |
| 788 |
LayoutPart part; |
798 |
LayoutPart part; |
| 789 |
MatchingPart (String pid, String sid, LayoutPart part) { |
799 |
MatchingPart (String pid, String sid, LayoutPart part) { |
| 790 |
this.pid = pid; this.sid = sid; this.part = part; |
800 |
this.pid = pid; |
|
|
801 |
this.sid = sid; |
| 802 |
this.part = part; |
| 803 |
} |
| 804 |
public int compareTo(Object a) { |
| 805 |
int difference = 0; |
| 806 |
MatchingPart ma = ((MatchingPart)a); |
| 807 |
difference += new String(ma.pid+ma.sid).length() - |
| 808 |
new String(this.pid+this.sid).length(); |
| 809 |
if (difference < 0) return -1; |
| 810 |
if (difference > 0) return 1; |
| 811 |
return 0; |
| 791 |
} |
812 |
} |
| 792 |
} |
813 |
} |
| 793 |
/** |
814 |
/** |
| 794 |
* Find the first part with a given ID in the presentation. |
815 |
* Find the first part with a given ID in the presentation. |
| 795 |
*/ |
816 |
*/ |
| 796 |
private LayoutPart findPart(String id, LayoutPart[] parts) { |
817 |
private LayoutPart findPart(String id, LayoutPart[] parts, ArrayList matchingParts) { |
| 797 |
MatchingPart currentMatchingPart = null; |
|
|
| 798 |
for (int i = 0, length = parts.length; i < length; i++) { |
818 |
for (int i = 0, length = parts.length; i < length; i++) { |
| 799 |
LayoutPart part = parts[i]; |
819 |
LayoutPart part = parts[i]; |
| 800 |
// check for part equality, parts with secondary ids fail |
820 |
// check for part equality, parts with secondary ids fail |
|
Lines 810-835
Link Here
|
| 810 |
// check pattern matching placeholders |
830 |
// check pattern matching placeholders |
| 811 |
else if (part instanceof PartPlaceholder && ((PartPlaceholder) part).hasWildCard()) { |
831 |
else if (part instanceof PartPlaceholder && ((PartPlaceholder) part).hasWildCard()) { |
| 812 |
StringMatcher sm = new StringMatcher(part.getID(), true, false); |
832 |
StringMatcher sm = new StringMatcher(part.getID(), true, false); |
| 813 |
MatchingPart matchingPart; |
833 |
if (sm.match(id)) |
| 814 |
if (sm.match(id)) { |
834 |
matchingParts.add(new MatchingPart(part.getID(), null, part)); |
| 815 |
matchingPart = new MatchingPart(part.getID(), null, part); |
|
|
| 816 |
if (currentMatchingPart == null) |
| 817 |
currentMatchingPart = matchingPart; |
| 818 |
else if (matchingPart.pid.length() > currentMatchingPart.pid.length()) |
| 819 |
currentMatchingPart = matchingPart; |
| 820 |
} |
| 821 |
} |
835 |
} |
| 822 |
else if (part instanceof EditorArea) { |
836 |
else if (part instanceof EditorArea) { |
| 823 |
// Skip. |
837 |
// Skip. |
| 824 |
} |
838 |
} |
| 825 |
else if (part instanceof ILayoutContainer) { |
839 |
else if (part instanceof ILayoutContainer) { |
| 826 |
part = findPart(id, ((ILayoutContainer) part).getChildren()); |
840 |
part = findPart(id, ((ILayoutContainer) part).getChildren(), matchingParts); |
| 827 |
if (part != null) |
841 |
if (part != null) |
| 828 |
return part; |
842 |
return part; |
| 829 |
} |
843 |
} |
| 830 |
} |
844 |
} |
| 831 |
if (currentMatchingPart != null) |
|
|
| 832 |
return currentMatchingPart.part; |
| 833 |
return null; |
845 |
return null; |
| 834 |
} |
846 |
} |
| 835 |
/** |
847 |
/** |
|
Lines 837-851
Link Here
|
| 837 |
* primary and secondary id pair. Wild cards |
849 |
* primary and secondary id pair. Wild cards |
| 838 |
* are supported. |
850 |
* are supported. |
| 839 |
*/ |
851 |
*/ |
| 840 |
private LayoutPart findPart(String primaryId, String secondaryId, LayoutPart[] parts) { |
852 |
private LayoutPart findPart(String primaryId, String secondaryId, LayoutPart[] parts, ArrayList matchingParts) { |
| 841 |
MatchingPart currentMatchingPart = null; |
|
|
| 842 |
LayoutPart wildCard = null; |
| 843 |
for (int i = 0, length = parts.length; i < length; i++) { |
853 |
for (int i = 0, length = parts.length; i < length; i++) { |
| 844 |
LayoutPart part = parts[i]; |
854 |
LayoutPart part = parts[i]; |
| 845 |
// check containers first |
855 |
// check containers first |
| 846 |
if (part instanceof ILayoutContainer) { |
856 |
if (part instanceof ILayoutContainer) { |
| 847 |
LayoutPart testPart = findPart(primaryId, secondaryId, |
857 |
LayoutPart testPart = findPart(primaryId, secondaryId, |
| 848 |
((ILayoutContainer) part).getChildren()); |
858 |
((ILayoutContainer) part).getChildren(), matchingParts); |
| 849 |
if (testPart != null) |
859 |
if (testPart != null) |
| 850 |
return testPart; |
860 |
return testPart; |
| 851 |
} |
861 |
} |
|
Lines 863-872
Link Here
|
| 863 |
String id = part.getID(); |
873 |
String id = part.getID(); |
| 864 |
|
874 |
|
| 865 |
// optimization: don't bother parsing id if it has no separator -- it can't match |
875 |
// optimization: don't bother parsing id if it has no separator -- it can't match |
| 866 |
if (id.indexOf(ViewFactory.ID_SEP) == -1) { //$NON-NLS-1$ |
876 |
if (id.indexOf(ViewFactory.ID_SEP) == -1) { |
| 867 |
// but still need to check for wildcard case |
877 |
// but still need to check for wildcard case |
| 868 |
if (id.equals(PartPlaceholder.WILD_CARD)) |
878 |
if (id.equals(PartPlaceholder.WILD_CARD)) |
| 869 |
wildCard = part; |
879 |
matchingParts.add(new MatchingPart(id, null, part)); |
| 870 |
continue; |
880 |
continue; |
| 871 |
} |
881 |
} |
| 872 |
|
882 |
|
|
Lines 884-912
Link Here
|
| 884 |
if (sm.match(primaryId)) { |
894 |
if (sm.match(primaryId)) { |
| 885 |
sm = new StringMatcher(phSecondaryId, true, false); |
895 |
sm = new StringMatcher(phSecondaryId, true, false); |
| 886 |
if (sm.match(secondaryId)) { |
896 |
if (sm.match(secondaryId)) { |
| 887 |
matchingPart = new MatchingPart(phPrimaryId, phSecondaryId, part); |
897 |
matchingParts.add(new MatchingPart(phPrimaryId, phSecondaryId, part)); |
| 888 |
// check for most specific |
|
|
| 889 |
if (currentMatchingPart != null) { |
| 890 |
if (matchingPart.pid.length() > currentMatchingPart.pid.length()) |
| 891 |
currentMatchingPart = matchingPart; |
| 892 |
else if (matchingPart.pid.length() == currentMatchingPart.pid.length()) { |
| 893 |
if (matchingPart.sid.length() > currentMatchingPart.sid.length()) |
| 894 |
currentMatchingPart = matchingPart; |
| 895 |
} |
| 896 |
} |
| 897 |
else |
| 898 |
currentMatchingPart = matchingPart; |
| 899 |
} |
898 |
} |
| 900 |
} |
899 |
} |
| 901 |
|
|
|
| 902 |
} |
900 |
} |
| 903 |
else if (part instanceof EditorArea) { |
901 |
else if (part instanceof EditorArea) { |
| 904 |
// Skip. |
902 |
// Skip. |
| 905 |
} |
903 |
} |
| 906 |
} |
904 |
} |
| 907 |
if (currentMatchingPart != null) |
905 |
return null; |
| 908 |
return currentMatchingPart.part; |
|
|
| 909 |
return wildCard; |
| 910 |
} |
906 |
} |
| 911 |
/** |
907 |
/** |
| 912 |
* Returns true if a placeholder exists for a given ID. |
908 |
* Returns true if a placeholder exists for a given ID. |