|
Lines 14-19
Link Here
|
| 14 |
import java.util.ArrayList; |
14 |
import java.util.ArrayList; |
| 15 |
import java.util.Enumeration; |
15 |
import java.util.Enumeration; |
| 16 |
import java.util.List; |
16 |
import java.util.List; |
|
|
17 |
import java.util.StringTokenizer; |
| 17 |
import java.util.Vector; |
18 |
import java.util.Vector; |
| 18 |
|
19 |
|
| 19 |
import org.eclipse.core.runtime.IStatus; |
20 |
import org.eclipse.core.runtime.IStatus; |
|
Lines 31-36
Link Here
|
| 31 |
import org.eclipse.ui.internal.dnd.DragUtil; |
32 |
import org.eclipse.ui.internal.dnd.DragUtil; |
| 32 |
import org.eclipse.ui.internal.dnd.IDragOverListener; |
33 |
import org.eclipse.ui.internal.dnd.IDragOverListener; |
| 33 |
import org.eclipse.ui.internal.dnd.IDropTarget; |
34 |
import org.eclipse.ui.internal.dnd.IDropTarget; |
|
|
35 |
import org.eclipse.ui.internal.misc.StringMatcher; |
| 34 |
|
36 |
|
| 35 |
/** |
37 |
/** |
| 36 |
* A perspective presentation is a collection of parts with a layout. Each part |
38 |
* A perspective presentation is a collection of parts with a layout. Each part |
|
Lines 51-63
Link Here
|
| 51 |
private ArrayList detachedWindowList = new ArrayList(1); |
53 |
private ArrayList detachedWindowList = new ArrayList(1); |
| 52 |
private ArrayList detachedPlaceHolderList = new ArrayList(1); |
54 |
private ArrayList detachedPlaceHolderList = new ArrayList(1); |
| 53 |
private boolean detachable = false; |
55 |
private boolean detachable = false; |
| 54 |
|
56 |
|
| 55 |
private boolean active = false; |
57 |
private boolean active = false; |
| 56 |
// key is the LayoutPart object, value is the PartDragDrop object |
58 |
// key is the LayoutPart object, value is the PartDragDrop object |
| 57 |
//private IPartDropListener partDropListener; |
59 |
//private IPartDropListener partDropListener; |
| 58 |
|
60 |
|
| 59 |
private static final int MIN_DETACH_WIDTH = 150; |
61 |
private static final int MIN_DETACH_WIDTH = 150; |
| 60 |
private static final int MIN_DETACH_HEIGHT = 250; |
62 |
private static final int MIN_DETACH_HEIGHT = 250; |
|
|
63 |
private static final String singleWildCard= new String(new char[] {'*'}); |
| 64 |
|
| 61 |
private IDragOverListener dragTarget = new IDragOverListener() { |
65 |
private IDragOverListener dragTarget = new IDragOverListener() { |
| 62 |
|
66 |
|
| 63 |
public IDropTarget drag(Control currentControl, Object draggedObject, Point position, final Rectangle dragRectangle) { |
67 |
public IDropTarget drag(Control currentControl, Object draggedObject, Point position, final Rectangle dragRectangle) { |
|
Lines 171-183
Link Here
|
| 171 |
// If part added / removed always zoom out. |
175 |
// If part added / removed always zoom out. |
| 172 |
if (isZoomed()) |
176 |
if (isZoomed()) |
| 173 |
zoomOut(); |
177 |
zoomOut(); |
| 174 |
|
178 |
|
| 175 |
// Look for a placeholder. |
179 |
// Look for a placeholder. |
| 176 |
PartPlaceholder placeholder = null; |
180 |
PartPlaceholder placeholder = null; |
| 177 |
LayoutPart testPart = findPart(part.getID()); |
181 |
LayoutPart testPart = null; |
|
|
182 |
String primaryId = part.getID(); |
| 183 |
String secondaryId = null; |
| 184 |
|
| 185 |
// @issue - do we need this check |
| 186 |
if (part instanceof ViewPane) { |
| 187 |
ViewPane pane = (ViewPane) part; |
| 188 |
IViewReference ref = (IViewReference)pane.getPartReference(); |
| 189 |
secondaryId = ref.getSecondaryId(); |
| 190 |
if (secondaryId != null) |
| 191 |
testPart = findPart(ref.getId(), secondaryId); |
| 192 |
else |
| 193 |
testPart = findPart(part.getID()); |
| 194 |
} |
| 195 |
else { |
| 196 |
testPart = findPart(part.getID()); |
| 197 |
} |
| 198 |
|
| 199 |
// validate the testPart |
| 178 |
if (testPart != null && testPart instanceof PartPlaceholder) |
200 |
if (testPart != null && testPart instanceof PartPlaceholder) |
| 179 |
placeholder = (PartPlaceholder) testPart; |
201 |
placeholder = (PartPlaceholder) testPart; |
| 180 |
|
202 |
|
| 181 |
// If there is no placeholder do a simple add. Otherwise, replace the |
203 |
// If there is no placeholder do a simple add. Otherwise, replace the |
| 182 |
// placeholder. |
204 |
// placeholder. |
| 183 |
if (placeholder == null) { |
205 |
if (placeholder == null) { |
|
Lines 240-247
Link Here
|
| 240 |
part.reparent(mainLayout.getParent()); |
262 |
part.reparent(mainLayout.getParent()); |
| 241 |
} |
263 |
} |
| 242 |
|
264 |
|
| 243 |
// replace placeholder with real part |
265 |
// see if we should replace the placeholder |
| 244 |
container.replace(placeholder, part); |
266 |
// TODO: need to restore placeholders with secondaryIDs |
|
|
267 |
// TODO: XXX.* is not working |
| 268 |
// TODO: duplicate test for xxx.*:xxx |
| 269 |
if (placeholder != null) { |
| 270 |
System.out.println("found placeholder - "+placeholder.getID()); |
| 271 |
if (placeholder.getID().indexOf(singleWildCard)!=-1) { |
| 272 |
if (container instanceof PartSashContainer) |
| 273 |
((PartSashContainer)container).addEnhanced(part, SWT.RIGHT, 0.0f, placeholder); |
| 274 |
else |
| 275 |
container.add(part); |
| 276 |
} |
| 277 |
else |
| 278 |
container.replace(placeholder, part); |
| 279 |
} |
| 280 |
else |
| 281 |
container.add(part); |
| 282 |
|
| 245 |
} |
283 |
} |
| 246 |
} |
284 |
} |
| 247 |
} |
285 |
} |
|
Lines 710-715
Link Here
|
| 710 |
// } |
748 |
// } |
| 711 |
/** |
749 |
/** |
| 712 |
* Find the first part with a given ID in the presentation. |
750 |
* Find the first part with a given ID in the presentation. |
|
|
751 |
* Wild cards now supported. |
| 713 |
*/ |
752 |
*/ |
| 714 |
private LayoutPart findPart(String id) { |
753 |
private LayoutPart findPart(String id) { |
| 715 |
// Check main window. |
754 |
// Check main window. |
|
Lines 731-737
Link Here
|
| 731 |
if (part != null) |
770 |
if (part != null) |
| 732 |
return part; |
771 |
return part; |
| 733 |
} |
772 |
} |
|
|
773 |
|
| 774 |
// check for a wild card placeholder |
| 775 |
part = findPart(singleWildCard, mainLayout.getChildren()); |
| 776 |
if (part != null) |
| 777 |
return part; |
| 778 |
|
| 779 |
// Not found. |
| 780 |
return null; |
| 781 |
} |
| 782 |
/** |
| 783 |
* Find the first part that matches the specified |
| 784 |
* primary and secondary id pair. Wild cards |
| 785 |
* are supported. |
| 786 |
*/ |
| 787 |
private LayoutPart findPart(String primaryId, String secondaryId) { |
| 788 |
// check main window. |
| 789 |
LayoutPart part = findPart(primaryId, secondaryId, mainLayout.getChildren()); |
| 790 |
if (part != null) |
| 791 |
return part; |
| 734 |
|
792 |
|
|
|
793 |
// check each detached windows. |
| 794 |
for (int i = 0, length = detachedWindowList.size(); i < length; i++) { |
| 795 |
DetachedWindow window = (DetachedWindow) detachedWindowList.get(i); |
| 796 |
part = findPart(primaryId, secondaryId, window.getChildren()); |
| 797 |
if (part != null) |
| 798 |
return part; |
| 799 |
} |
| 800 |
for (int i = 0; i < detachedPlaceHolderList.size(); i++) { |
| 801 |
DetachedPlaceHolder holder = |
| 802 |
(DetachedPlaceHolder) detachedPlaceHolderList.get(i); |
| 803 |
part = findPart(primaryId, secondaryId, holder.getChildren()); |
| 804 |
if (part != null) |
| 805 |
return part; |
| 806 |
} |
| 807 |
|
| 808 |
// check for a wild card placeholder |
| 809 |
part = findPart(singleWildCard, mainLayout.getChildren()); |
| 810 |
if (part != null) |
| 811 |
return part; |
| 812 |
|
| 735 |
// Not found. |
813 |
// Not found. |
| 736 |
return null; |
814 |
return null; |
| 737 |
} |
815 |
} |
|
Lines 739-757
Link Here
|
| 739 |
* Find the first part with a given ID in the presentation. |
817 |
* Find the first part with a given ID in the presentation. |
| 740 |
*/ |
818 |
*/ |
| 741 |
private LayoutPart findPart(String id, LayoutPart[] parts) { |
819 |
private LayoutPart findPart(String id, LayoutPart[] parts) { |
|
|
820 |
LayoutPart wildCard = null; |
| 821 |
MatchingPart currentMatchingPart = null; |
| 742 |
for (int i = 0, length = parts.length; i < length; i++) { |
822 |
for (int i = 0, length = parts.length; i < length; i++) { |
| 743 |
LayoutPart part = parts[i]; |
823 |
LayoutPart part = parts[i]; |
| 744 |
if (part.getID().equals(id)) { |
824 |
if (part.getID().equals(id)) { |
| 745 |
return part; |
825 |
return part; |
| 746 |
} else if (part instanceof EditorArea) { |
826 |
} |
|
|
827 |
else if (part.getID().equals(singleWildCard)) |
| 828 |
wildCard = part; |
| 829 |
else if (part.getID().indexOf(singleWildCard) != -1) { |
| 830 |
StringMatcher sm = new StringMatcher(part.getID(), true, false); |
| 831 |
MatchingPart matchingPart; |
| 832 |
if (sm.match(id)) { |
| 833 |
matchingPart = new MatchingPart(part.getID(), null, part); |
| 834 |
if (currentMatchingPart != null && |
| 835 |
matchingPart.pid.length() > currentMatchingPart.pid.length()) |
| 836 |
currentMatchingPart = matchingPart; |
| 837 |
else |
| 838 |
currentMatchingPart = matchingPart; |
| 839 |
} |
| 840 |
} |
| 841 |
else if (part instanceof EditorArea) { |
| 747 |
// Skip. |
842 |
// Skip. |
| 748 |
} else if (part instanceof ILayoutContainer) { |
843 |
} else if (part instanceof ILayoutContainer) { |
| 749 |
part = findPart(id, ((ILayoutContainer) part).getChildren()); |
844 |
part = findPart(id, ((ILayoutContainer) part).getChildren()); |
| 750 |
if (part != null) |
845 |
if (part != null) |
| 751 |
return part; |
846 |
return part; |
| 752 |
} |
847 |
} |
| 753 |
} |
848 |
} |
| 754 |
return null; |
849 |
if (currentMatchingPart != null) |
|
|
850 |
return currentMatchingPart.part; |
| 851 |
return wildCard; |
| 852 |
} |
| 853 |
/** |
| 854 |
* Find the first part that matches the specified |
| 855 |
* primary and secondary id pair. Wild cards |
| 856 |
* are supported. |
| 857 |
*/ |
| 858 |
private class MatchingPart { |
| 859 |
String pid; |
| 860 |
String sid; |
| 861 |
LayoutPart part; |
| 862 |
MatchingPart (String pid, String sid, LayoutPart part) { |
| 863 |
this.pid = pid; this.sid = sid; this.part = part; |
| 864 |
} |
| 865 |
} |
| 866 |
private LayoutPart findPart(String primaryId, String secondaryId, LayoutPart[] parts) { |
| 867 |
LayoutPart wildCard = null; |
| 868 |
MatchingPart currentMatchingPart = null; |
| 869 |
for (int i = 0, length = parts.length; i < length; i++) { |
| 870 |
LayoutPart part = parts[i]; |
| 871 |
if ((parts[i] instanceof PartPlaceholder)) { |
| 872 |
String id = part.getID(); |
| 873 |
if (id.indexOf(":") == -1) continue; |
| 874 |
|
| 875 |
StringTokenizer st = new StringTokenizer(part.getID(), ":"); |
| 876 |
String phPrimaryId = st.nextToken(); |
| 877 |
String phSecondaryId = st.nextToken(); |
| 878 |
|
| 879 |
// perfect matching pair |
| 880 |
if (phPrimaryId.equals(primaryId) && |
| 881 |
phSecondaryId.equals(secondaryId)) { |
| 882 |
return part; |
| 883 |
} |
| 884 |
|
| 885 |
// check for partial matching pair |
| 886 |
MatchingPart matchingPart; |
| 887 |
StringMatcher sm = new StringMatcher(phPrimaryId, true, false); |
| 888 |
if (sm.match(primaryId)) { |
| 889 |
sm = new StringMatcher(phSecondaryId, true, false); |
| 890 |
if (sm.match(secondaryId)) { |
| 891 |
matchingPart = new MatchingPart(phPrimaryId, phSecondaryId, part); |
| 892 |
// check for most specific |
| 893 |
if (currentMatchingPart != null) { |
| 894 |
if (matchingPart.pid.length() > currentMatchingPart.pid.length()) |
| 895 |
currentMatchingPart = matchingPart; |
| 896 |
else if (matchingPart.pid.length() == currentMatchingPart.pid.length()) { |
| 897 |
if (matchingPart.sid.length() > currentMatchingPart.sid.length()) |
| 898 |
currentMatchingPart = matchingPart; |
| 899 |
} |
| 900 |
} |
| 901 |
else |
| 902 |
currentMatchingPart = matchingPart; |
| 903 |
} |
| 904 |
} |
| 905 |
|
| 906 |
} else if (part instanceof EditorArea) { |
| 907 |
// Skip. |
| 908 |
} else if (part instanceof ILayoutContainer) { |
| 909 |
part = findPart(primaryId, secondaryId, ((ILayoutContainer) part).getChildren()); |
| 910 |
if (part != null) |
| 911 |
return part; |
| 912 |
} else if (part.getID().equals(singleWildCard)) |
| 913 |
wildCard = part; |
| 914 |
} |
| 915 |
if (currentMatchingPart != null) |
| 916 |
return currentMatchingPart.part; |
| 917 |
return wildCard; |
| 755 |
} |
918 |
} |
| 756 |
/** |
919 |
/** |
| 757 |
* Returns true if a placeholder exists for a given ID. |
920 |
* Returns true if a placeholder exists for a given ID. |