|
Lines 51-62
Link Here
|
| 51 |
|
51 |
|
| 52 |
private ViewSashContainer mainLayout; |
52 |
private ViewSashContainer mainLayout; |
| 53 |
|
53 |
|
|
|
54 |
private Perspective perspective; |
| 55 |
|
| 54 |
private IWorkbenchPartReference zoomPart; |
56 |
private IWorkbenchPartReference zoomPart; |
| 55 |
|
57 |
|
| 56 |
private ArrayList detachedWindowList = new ArrayList(1); |
58 |
private ArrayList detachedWindowList = new ArrayList(1); |
| 57 |
|
59 |
|
| 58 |
private ArrayList detachedPlaceHolderList = new ArrayList(1); |
|
|
| 59 |
|
| 60 |
private boolean detachable = false; |
60 |
private boolean detachable = false; |
| 61 |
|
61 |
|
| 62 |
private boolean active = false; |
62 |
private boolean active = false; |
|
Lines 75-80
Link Here
|
| 75 |
public IDropTarget drag(Control currentControl, Object draggedObject, |
75 |
public IDropTarget drag(Control currentControl, Object draggedObject, |
| 76 |
Point position, final Rectangle dragRectangle) { |
76 |
Point position, final Rectangle dragRectangle) { |
| 77 |
|
77 |
|
|
|
78 |
// If we're dragging a floating detached window |
| 79 |
if (draggedObject instanceof DetachedWindow) { |
| 80 |
final DetachedWindow window = (DetachedWindow)draggedObject; |
| 81 |
return new AbstractDropTarget() { |
| 82 |
public void drop() { |
| 83 |
window.getShell().setLocation(dragRectangle.x, |
| 84 |
dragRectangle.y); |
| 85 |
} |
| 86 |
|
| 87 |
public Cursor getCursor() { |
| 88 |
return DragCursors.getCursor(DragCursors.OFFSCREEN); |
| 89 |
} |
| 90 |
}; |
| 91 |
} |
| 92 |
|
| 78 |
if (!(draggedObject instanceof ViewPane || draggedObject instanceof ViewStack)) { |
93 |
if (!(draggedObject instanceof ViewPane || draggedObject instanceof ViewStack)) { |
| 79 |
return null; |
94 |
return null; |
| 80 |
} |
95 |
} |
|
Lines 190-199
Link Here
|
| 190 |
* Constructs a new object. |
205 |
* Constructs a new object. |
| 191 |
*/ |
206 |
*/ |
| 192 |
public PerspectiveHelper(WorkbenchPage workbenchPage, |
207 |
public PerspectiveHelper(WorkbenchPage workbenchPage, |
| 193 |
ViewSashContainer mainLayout) { |
208 |
ViewSashContainer mainLayout, Perspective perspective) { |
| 194 |
this.page = workbenchPage; |
209 |
this.page = workbenchPage; |
| 195 |
this.mainLayout = mainLayout; |
210 |
this.mainLayout = mainLayout; |
| 196 |
|
211 |
this.perspective = perspective; |
| 197 |
// Determine if reparenting is allowed by checking if some arbitrary |
212 |
// Determine if reparenting is allowed by checking if some arbitrary |
| 198 |
// Composite supports reparenting. This is used to determine if |
213 |
// Composite supports reparenting. This is used to determine if |
| 199 |
// detached views should be enabled. |
214 |
// detached views should be enabled. |
|
Lines 227-239
Link Here
|
| 227 |
part.reparent(parent); |
242 |
part.reparent(parent); |
| 228 |
} |
243 |
} |
| 229 |
mainLayout.createControl(parent); |
244 |
mainLayout.createControl(parent); |
| 230 |
|
245 |
|
| 231 |
// Open the detached windows. |
246 |
// Open the detached windows. |
| 232 |
for (int i = 0, length = detachedWindowList.size(); i < length; i++) { |
247 |
for (int i = 0, length = detachedWindowList.size(); i < length; i++) { |
| 233 |
DetachedWindow dwindow = (DetachedWindow) detachedWindowList.get(i); |
248 |
DetachedWindow dwindow = (DetachedWindow) detachedWindowList.get(i); |
| 234 |
dwindow.open(); |
249 |
if(dwindow.shouldOpenOnActivate()) { |
|
|
250 |
dwindow.open(); |
| 251 |
} |
| 252 |
dwindow.allowShellCreation(true); |
| 235 |
} |
253 |
} |
| 236 |
|
254 |
|
| 237 |
enableAllDrag(); |
255 |
enableAllDrag(); |
| 238 |
//enableAllDrop(); |
256 |
//enableAllDrop(); |
| 239 |
|
257 |
|
|
Lines 251-348
Link Here
|
| 251 |
zoomOut(); |
269 |
zoomOut(); |
| 252 |
|
270 |
|
| 253 |
// Look for a placeholder. |
271 |
// Look for a placeholder. |
| 254 |
PartPlaceholder placeholder = null; |
272 |
ILayoutContainer newPlaceholder = (ILayoutContainer)( |
| 255 |
LayoutPart testPart = null; |
273 |
perspective.findContainer(part.getCompoundId())); |
| 256 |
String primaryId = part.getID(); |
274 |
|
| 257 |
String secondaryId = null; |
275 |
if (newPlaceholder == null) { |
| 258 |
|
276 |
part.reparent(mainLayout.getParent()); |
| 259 |
if (part instanceof ViewPane) { |
277 |
newPlaceholder = mainLayout; |
| 260 |
ViewPane pane = (ViewPane) part; |
|
|
| 261 |
IViewReference ref = (IViewReference) pane.getPartReference(); |
| 262 |
secondaryId = ref.getSecondaryId(); |
| 263 |
} |
| 264 |
if (secondaryId != null) |
| 265 |
testPart = findPart(primaryId, secondaryId); |
| 266 |
else |
| 267 |
testPart = findPart(primaryId); |
| 268 |
|
| 269 |
// validate the testPart |
| 270 |
if (testPart != null && testPart instanceof PartPlaceholder) |
| 271 |
placeholder = (PartPlaceholder) testPart; |
| 272 |
|
| 273 |
// If there is no placeholder do a simple add. Otherwise, replace the |
| 274 |
// placeholder if its not a pattern matching placholder |
| 275 |
if (placeholder == null) { |
| 276 |
part.reparent(mainLayout.getParent()); |
| 277 |
LayoutPart relative = mainLayout.findBottomRight(); |
| 278 |
if (relative != null && relative instanceof PartStack) { |
| 279 |
mainLayout.stack(part, (PartStack) relative); |
| 280 |
} else { |
| 281 |
mainLayout.add(part); |
| 282 |
} |
| 283 |
} else { |
| 284 |
ILayoutContainer container = placeholder.getContainer(); |
| 285 |
if (container != null) { |
| 286 |
|
| 287 |
if (container instanceof DetachedPlaceHolder) { |
| 288 |
//Create a detached window add the part on it. |
| 289 |
DetachedPlaceHolder holder = (DetachedPlaceHolder) container; |
| 290 |
detachedPlaceHolderList.remove(holder); |
| 291 |
container.remove(testPart); |
| 292 |
DetachedWindow window = new DetachedWindow(page); |
| 293 |
detachedWindowList.add(window); |
| 294 |
window.create(); |
| 295 |
part.createControl(window.getShell()); |
| 296 |
// Open window. |
| 297 |
window.getShell().setBounds(holder.getBounds()); |
| 298 |
window.open(); |
| 299 |
// add part to detached window. |
| 300 |
ViewPane pane = (ViewPane) part; |
| 301 |
window.getShell().setText( |
| 302 |
pane.getPartReference().getTitle()); |
| 303 |
window.add(pane); |
| 304 |
LayoutPart otherChildren[] = holder.getChildren(); |
| 305 |
for (int i = 0; i < otherChildren.length; i++) |
| 306 |
part.getContainer().add(otherChildren[i]); |
| 307 |
} else { |
| 308 |
|
| 309 |
// reconsistute parent if necessary |
| 310 |
if (container instanceof ContainerPlaceholder) { |
| 311 |
ContainerPlaceholder containerPlaceholder = (ContainerPlaceholder) container; |
| 312 |
ILayoutContainer parentContainer = containerPlaceholder |
| 313 |
.getContainer(); |
| 314 |
container = (ILayoutContainer) containerPlaceholder |
| 315 |
.getRealContainer(); |
| 316 |
if (container instanceof LayoutPart) { |
| 317 |
parentContainer.replace(containerPlaceholder, |
| 318 |
(LayoutPart) container); |
| 319 |
} |
| 320 |
containerPlaceholder.setRealContainer(null); |
| 321 |
} |
| 322 |
|
| 323 |
// reparent part. |
| 324 |
if (!(container instanceof ViewStack)) { |
| 325 |
// We don't need to reparent children of PartTabFolders since they will automatically |
| 326 |
// reparent their children when they become visible. This if statement used to be |
| 327 |
// part of an else branch. Investigate if it is still necessary. |
| 328 |
part.reparent(mainLayout.getParent()); |
| 329 |
} |
| 330 |
|
| 331 |
// see if we should replace the placeholder |
| 332 |
if (placeholder.hasWildCard()) { |
| 333 |
if (container instanceof PartSashContainer) |
| 334 |
((PartSashContainer) container) |
| 335 |
.addChildForPlaceholder(part, placeholder); |
| 336 |
else |
| 337 |
container.add(part); |
| 338 |
} else |
| 339 |
container.replace(placeholder, part); |
| 340 |
} |
| 341 |
} |
| 342 |
} |
278 |
} |
| 343 |
|
279 |
|
| 344 |
// enable direct manipulation |
280 |
newPlaceholder.add(part); |
| 345 |
//enableDrop(part); |
281 |
} |
|
|
282 |
|
| 283 |
|
| 284 |
/** |
| 285 |
* Attaches a part that was previously detached to the mainLayout. |
| 286 |
* |
| 287 |
* @param ref |
| 288 |
*/ |
| 289 |
public void attachPart(IViewReference ref) { |
| 290 |
if(isZoomed()) |
| 291 |
zoomOut(); |
| 292 |
ViewPane pane = (ViewPane)((WorkbenchPartReference)ref).getPane(); |
| 293 |
derefPart(pane); |
| 294 |
perspective.addPlaceholder(pane.getCompoundId(), mainLayout); |
| 295 |
addPart(pane); |
| 296 |
bringPartToTop(pane); |
| 297 |
pane.setFocus(); |
| 346 |
} |
298 |
} |
| 347 |
|
299 |
|
| 348 |
/** |
300 |
/** |
|
Lines 385-392
Link Here
|
| 385 |
return false; |
337 |
return false; |
| 386 |
|
338 |
|
| 387 |
ILayoutContainer container = part.getContainer(); |
339 |
ILayoutContainer container = part.getContainer(); |
| 388 |
if (container != null && container instanceof ContainerPlaceholder) |
|
|
| 389 |
return false; |
| 390 |
|
340 |
|
| 391 |
if (container != null && container instanceof ViewStack) { |
341 |
if (container != null && container instanceof ViewStack) { |
| 392 |
ViewStack folder = (ViewStack) container; |
342 |
ViewStack folder = (ViewStack) container; |
|
Lines 398-430
Link Here
|
| 398 |
} |
348 |
} |
| 399 |
|
349 |
|
| 400 |
/** |
350 |
/** |
| 401 |
* Returns true is not in a tab folder or if it is the top one in a tab |
|
|
| 402 |
* folder. |
| 403 |
*/ |
| 404 |
public boolean willPartBeVisible(String partId) { |
| 405 |
return willPartBeVisible(partId, null); |
| 406 |
} |
| 407 |
|
| 408 |
public boolean willPartBeVisible(String partId, String secondaryId) { |
| 409 |
LayoutPart part = findPart(partId, secondaryId); |
| 410 |
if (part == null) |
| 411 |
return false; |
| 412 |
ILayoutContainer container = part.getContainer(); |
| 413 |
if (container != null && container instanceof ContainerPlaceholder) |
| 414 |
container = (ILayoutContainer) ((ContainerPlaceholder) container) |
| 415 |
.getRealContainer(); |
| 416 |
|
| 417 |
if (container != null && container instanceof ViewStack) { |
| 418 |
ViewStack folder = (ViewStack) container; |
| 419 |
if (folder.getVisiblePart() == null) |
| 420 |
return false; |
| 421 |
return part.getCompoundId().equals( |
| 422 |
folder.getVisiblePart().getCompoundId()); |
| 423 |
} |
| 424 |
return true; |
| 425 |
} |
| 426 |
|
| 427 |
/** |
| 428 |
* Open the tracker to allow the user to move the specified part using |
351 |
* Open the tracker to allow the user to move the specified part using |
| 429 |
* keyboard. |
352 |
* keyboard. |
| 430 |
*/ |
353 |
*/ |
|
Lines 434-495
Link Here
|
| 434 |
} |
357 |
} |
| 435 |
|
358 |
|
| 436 |
/** |
359 |
/** |
| 437 |
* Answer a list of the PartPlaceholder objects. |
|
|
| 438 |
*/ |
| 439 |
private PartPlaceholder[] collectPlaceholders() { |
| 440 |
// Scan the main window. |
| 441 |
PartPlaceholder[] results = collectPlaceholders(mainLayout |
| 442 |
.getChildren()); |
| 443 |
|
| 444 |
// Scan each detached window. |
| 445 |
if (detachable) { |
| 446 |
for (int i = 0, length = detachedWindowList.size(); i < length; i++) { |
| 447 |
DetachedWindow win = (DetachedWindow) detachedWindowList.get(i); |
| 448 |
PartPlaceholder[] moreResults = collectPlaceholders(win |
| 449 |
.getChildren()); |
| 450 |
if (moreResults.length > 0) { |
| 451 |
int newLength = results.length + moreResults.length; |
| 452 |
PartPlaceholder[] newResults = new PartPlaceholder[newLength]; |
| 453 |
System.arraycopy(results, 0, newResults, 0, results.length); |
| 454 |
System.arraycopy(moreResults, 0, newResults, |
| 455 |
results.length, moreResults.length); |
| 456 |
results = newResults; |
| 457 |
} |
| 458 |
} |
| 459 |
} |
| 460 |
return results; |
| 461 |
} |
| 462 |
|
| 463 |
/** |
| 464 |
* Answer a list of the PartPlaceholder objects. |
| 465 |
*/ |
| 466 |
private PartPlaceholder[] collectPlaceholders(LayoutPart[] parts) { |
| 467 |
PartPlaceholder[] result = new PartPlaceholder[0]; |
| 468 |
|
| 469 |
for (int i = 0, length = parts.length; i < length; i++) { |
| 470 |
LayoutPart part = parts[i]; |
| 471 |
if (part instanceof ILayoutContainer) { |
| 472 |
// iterate through sub containers to find sub-parts |
| 473 |
PartPlaceholder[] newParts = collectPlaceholders(((ILayoutContainer) part) |
| 474 |
.getChildren()); |
| 475 |
PartPlaceholder[] newResult = new PartPlaceholder[result.length |
| 476 |
+ newParts.length]; |
| 477 |
System.arraycopy(result, 0, newResult, 0, result.length); |
| 478 |
System.arraycopy(newParts, 0, newResult, result.length, |
| 479 |
newParts.length); |
| 480 |
result = newResult; |
| 481 |
} else if (part instanceof PartPlaceholder) { |
| 482 |
PartPlaceholder[] newResult = new PartPlaceholder[result.length + 1]; |
| 483 |
System.arraycopy(result, 0, newResult, 0, result.length); |
| 484 |
newResult[result.length] = (PartPlaceholder) part; |
| 485 |
result = newResult; |
| 486 |
} |
| 487 |
} |
| 488 |
|
| 489 |
return result; |
| 490 |
} |
| 491 |
|
| 492 |
/** |
| 493 |
* Answer a list of the view panes. |
360 |
* Answer a list of the view panes. |
| 494 |
*/ |
361 |
*/ |
| 495 |
public void collectViewPanes(List result) { |
362 |
public void collectViewPanes(List result) { |
|
Lines 552-557
Link Here
|
| 552 |
// Dispose the detached windows |
419 |
// Dispose the detached windows |
| 553 |
for (int i = 0, length = detachedWindowList.size(); i < length; i++) { |
420 |
for (int i = 0, length = detachedWindowList.size(); i < length; i++) { |
| 554 |
DetachedWindow window = (DetachedWindow) detachedWindowList.get(i); |
421 |
DetachedWindow window = (DetachedWindow) detachedWindowList.get(i); |
|
|
422 |
window.allowShellCreation(false); |
| 555 |
window.close(); |
423 |
window.close(); |
| 556 |
} |
424 |
} |
| 557 |
|
425 |
|
|
Lines 604-616
Link Here
|
| 604 |
*/ |
472 |
*/ |
| 605 |
/* package */void derefPart(LayoutPart part) { |
473 |
/* package */void derefPart(LayoutPart part) { |
| 606 |
|
474 |
|
| 607 |
if (part instanceof ViewPane) { |
|
|
| 608 |
page.removeFastView(((ViewPane) part).getViewReference()); |
| 609 |
} |
| 610 |
|
| 611 |
// Get vital part stats before reparenting. |
475 |
// Get vital part stats before reparenting. |
| 612 |
Window oldWindow = part.getWindow(); |
476 |
Window oldWindow = part.getWindow(); |
| 613 |
ILayoutContainer oldContainer = part.getContainer(); |
477 |
ILayoutContainer oldContainer = part.getContainer(); |
|
|
478 |
|
| 479 |
if (part instanceof ViewPane) { |
| 480 |
if(page.isFastView(((ViewPane) part).getViewReference())) { |
| 481 |
page.removeFastView(((ViewPane) part).getViewReference()); |
| 482 |
oldWindow = part.getWindow(); |
| 483 |
oldContainer = part.getContainer(); |
| 484 |
} |
| 485 |
} |
| 614 |
|
486 |
|
| 615 |
// Reparent the part back to the main window |
487 |
// Reparent the part back to the main window |
| 616 |
part.reparent(mainLayout.getParent()); |
488 |
part.reparent(mainLayout.getParent()); |
|
Lines 620-699
Link Here
|
| 620 |
return; |
492 |
return; |
| 621 |
|
493 |
|
| 622 |
oldContainer.remove(part); |
494 |
oldContainer.remove(part); |
| 623 |
|
495 |
|
| 624 |
LayoutPart[] children = oldContainer.getChildren(); |
496 |
if (part instanceof ViewPane && oldContainer instanceof ViewStack) { |
| 625 |
if (oldWindow instanceof WorkbenchWindow) { |
497 |
LayoutPart parent = (LayoutPart) oldContainer; |
| 626 |
boolean hasChildren = (children != null) && (children.length > 0); |
498 |
if (parent.getContainer() == mainLayout) { |
| 627 |
if (hasChildren) { |
499 |
mainLayout.removePlaceholder(part.getCompoundId()); |
| 628 |
// make sure one is at least visible |
500 |
} |
| 629 |
int childVisible = 0; |
|
|
| 630 |
for (int i = 0; i < children.length; i++) |
| 631 |
if (children[i].getControl() != null) |
| 632 |
childVisible++; |
| 633 |
|
| 634 |
// none visible, then reprarent and remove container |
| 635 |
if (oldContainer instanceof ViewStack) { |
| 636 |
ViewStack folder = (ViewStack) oldContainer; |
| 637 |
if (childVisible == 0) { |
| 638 |
ILayoutContainer parentContainer = folder |
| 639 |
.getContainer(); |
| 640 |
for (int i = 0; i < children.length; i++) { |
| 641 |
folder.remove(children[i]); |
| 642 |
parentContainer.add(children[i]); |
| 643 |
} |
| 644 |
hasChildren = false; |
| 645 |
} else if (childVisible == 1) { |
| 646 |
LayoutTree layout = mainLayout.getLayoutTree(); |
| 647 |
layout = layout.find(folder); |
| 648 |
layout.setBounds(layout.getBounds()); |
| 649 |
} |
| 650 |
} |
| 651 |
} |
| 652 |
|
| 653 |
if (!hasChildren) { |
| 654 |
// There are no more children in this container, so get rid of |
| 655 |
// it |
| 656 |
if (oldContainer instanceof LayoutPart) { |
| 657 |
LayoutPart parent = (LayoutPart) oldContainer; |
| 658 |
ILayoutContainer parentContainer = parent.getContainer(); |
| 659 |
if (parentContainer != null) { |
| 660 |
parentContainer.remove(parent); |
| 661 |
parent.dispose(); |
| 662 |
} |
| 663 |
} |
| 664 |
} |
| 665 |
} else if (oldWindow instanceof DetachedWindow) { |
| 666 |
if (children == null || children.length == 0) { |
| 667 |
// There are no more children in this container, so get rid of |
| 668 |
// it |
| 669 |
// Turn on redraw again just in case it was off. |
| 670 |
oldWindow.getShell().setRedraw(true); |
| 671 |
oldWindow.close(); |
| 672 |
detachedWindowList.remove(oldWindow); |
| 673 |
} else { |
| 674 |
// There are children. If none are visible hide detached |
| 675 |
// window. |
| 676 |
boolean allInvisible = true; |
| 677 |
for (int i = 0, length = children.length; i < length; i++) { |
| 678 |
if (!(children[i] instanceof PartPlaceholder)) { |
| 679 |
allInvisible = false; |
| 680 |
break; |
| 681 |
} |
| 682 |
} |
| 683 |
if (allInvisible) { |
| 684 |
DetachedPlaceHolder placeholder = new DetachedPlaceHolder( |
| 685 |
"", //$NON-NLS-1$ |
| 686 |
oldWindow.getShell().getBounds()); |
| 687 |
for (int i = 0, length = children.length; i < length; i++) { |
| 688 |
oldContainer.remove(children[i]); |
| 689 |
children[i].setContainer(placeholder); |
| 690 |
placeholder.add(children[i]); |
| 691 |
} |
| 692 |
detachedPlaceHolderList.add(placeholder); |
| 693 |
oldWindow.close(); |
| 694 |
detachedWindowList.remove(oldWindow); |
| 695 |
} |
| 696 |
} |
| 697 |
} |
501 |
} |
| 698 |
|
502 |
|
| 699 |
} |
503 |
} |
|
Lines 736-742
Link Here
|
| 736 |
for (int i = 0; i < children.length; i++) { |
540 |
for (int i = 0; i < children.length; i++) { |
| 737 |
if (children[i] instanceof ViewPane) { |
541 |
if (children[i] instanceof ViewPane) { |
| 738 |
// remove the part from its current container |
542 |
// remove the part from its current container |
| 739 |
derefPart(children[i]); |
543 |
removePart(children[i]); |
| 740 |
// add part to detached window. |
544 |
// add part to detached window. |
| 741 |
ViewPane pane = (ViewPane) children[i]; |
545 |
ViewPane pane = (ViewPane) children[i]; |
| 742 |
window.getShell().setText( |
546 |
window.getShell().setText( |
|
Lines 752-784
Link Here
|
| 752 |
parentWidget.setRedraw(true); |
556 |
parentWidget.setRedraw(true); |
| 753 |
} else { |
557 |
} else { |
| 754 |
// remove the part from its current container |
558 |
// remove the part from its current container |
| 755 |
derefPart(part); |
559 |
removePart(part); |
| 756 |
// add part to detached window. |
560 |
// add part to detached window. |
| 757 |
ViewPane pane = (ViewPane) part; |
561 |
ViewPane pane = (ViewPane) part; |
| 758 |
window.getShell().setText(pane.getPartReference().getTitle()); |
562 |
window.getShell().setText(pane.getPartReference().getTitle()); |
| 759 |
window.add(pane); |
563 |
window.add(part); |
| 760 |
part.setFocus(); |
564 |
part.setFocus(); |
| 761 |
} |
565 |
} |
| 762 |
|
566 |
|
| 763 |
} |
567 |
} |
|
|
568 |
|
| 569 |
/** |
| 570 |
* Detached a part from the mainLayout. Presently this does not use placeholders |
| 571 |
* since the current implementation is not robust enough to remember a view's position |
| 572 |
* in more than one root container. For now the view is simply derefed and will dock |
| 573 |
* in the default position when attachPart is called. |
| 574 |
* |
| 575 |
* By default parts detached this way are set to float on top of the workbench |
| 576 |
* without docking. It is assumed that people that want to drag a part back onto |
| 577 |
* the WorkbenchWindow will detach it via drag and drop. |
| 578 |
* |
| 579 |
* @param ref |
| 580 |
*/ |
| 581 |
public void detachPart(IViewReference ref) { |
| 582 |
ViewPane pane = (ViewPane)((WorkbenchPartReference)ref).getPane(); |
| 583 |
if (canDetach() && pane != null) { |
| 584 |
Rectangle bounds = pane.getParentBounds(); |
| 585 |
detach(pane, bounds.x ,bounds.y); |
| 586 |
((DetachedWindow)pane.getWindow()).setFloatingState(true); |
| 587 |
} |
| 588 |
} |
| 764 |
|
589 |
|
| 765 |
/** |
590 |
/** |
| 766 |
* Create a detached window containing a part. |
591 |
* Create a detached window containing a part. |
| 767 |
*/ |
592 |
*/ |
| 768 |
public void addDetachedPart(LayoutPart part) { |
593 |
public void addDetachedPart(LayoutPart part) { |
|
|
594 |
// Calculate detached window size. |
| 595 |
Rectangle bounds = parentWidget.getShell().getBounds(); |
| 596 |
bounds.x = bounds.x + (bounds.width - 300) / 2; |
| 597 |
bounds.y = bounds.y + (bounds.height - 300) / 2; |
| 598 |
|
| 599 |
addDetachedPart(part, bounds); |
| 600 |
|
| 601 |
// enable direct manipulation |
| 602 |
//enableDrop(part); |
| 603 |
} |
| 604 |
|
| 605 |
public void addDetachedPart(LayoutPart part, Rectangle bounds) { |
| 769 |
// Detaching is disabled on some platforms .. |
606 |
// Detaching is disabled on some platforms .. |
| 770 |
if (!detachable) { |
607 |
if (!detachable) { |
| 771 |
addPart(part); |
608 |
addPart(part); |
| 772 |
return; |
609 |
return; |
| 773 |
} |
610 |
} |
| 774 |
|
611 |
|
| 775 |
// Calculate detached window size. |
|
|
| 776 |
int width = 300; |
| 777 |
int height = 300; |
| 778 |
Rectangle bounds = parentWidget.getShell().getBounds(); |
| 779 |
int x = bounds.x + (bounds.width - width) / 2; |
| 780 |
int y = bounds.y + (bounds.height - height) / 2; |
| 781 |
|
| 782 |
// Create detached window. |
612 |
// Create detached window. |
| 783 |
DetachedWindow window = new DetachedWindow(page); |
613 |
DetachedWindow window = new DetachedWindow(page); |
| 784 |
detachedWindowList.add(window); |
614 |
detachedWindowList.add(window); |
|
Lines 791-805
Link Here
|
| 791 |
window.add(pane); |
621 |
window.add(pane); |
| 792 |
|
622 |
|
| 793 |
// Open window. |
623 |
// Open window. |
| 794 |
window.getShell().setBounds(x, y, width, height); |
624 |
window.getShell().setBounds(bounds.x, bounds.y, bounds.width, bounds.height); |
| 795 |
window.open(); |
625 |
window.open(); |
| 796 |
|
626 |
|
| 797 |
part.setFocus(); |
627 |
part.setFocus(); |
| 798 |
|
628 |
|
| 799 |
// enable direct manipulation |
|
|
| 800 |
//enableDrop(part); |
| 801 |
} |
629 |
} |
| 802 |
|
630 |
|
| 803 |
/** |
631 |
/** |
| 804 |
* disableDragging. |
632 |
* disableDragging. |
| 805 |
*/ |
633 |
*/ |
|
Lines 852-866
Link Here
|
| 852 |
if (part != null) |
680 |
if (part != null) |
| 853 |
return part; |
681 |
return part; |
| 854 |
} |
682 |
} |
| 855 |
for (int i = 0; i < detachedPlaceHolderList.size(); i++) { |
|
|
| 856 |
DetachedPlaceHolder holder = (DetachedPlaceHolder) detachedPlaceHolderList |
| 857 |
.get(i); |
| 858 |
part = (secondaryId != null) ? findPart(primaryId, secondaryId, |
| 859 |
holder.getChildren(), matchingParts) : findPart(primaryId, |
| 860 |
holder.getChildren(), matchingParts); |
| 861 |
if (part != null) |
| 862 |
return part; |
| 863 |
} |
| 864 |
|
683 |
|
| 865 |
// sort the matching parts |
684 |
// sort the matching parts |
| 866 |
if (matchingParts.size() > 0) { |
685 |
if (matchingParts.size() > 0) { |
|
Lines 985-996
Link Here
|
| 985 |
* @since 3.0 |
804 |
* @since 3.0 |
| 986 |
*/ |
805 |
*/ |
| 987 |
public boolean hasPlaceholder(String primaryId, String secondaryId) { |
806 |
public boolean hasPlaceholder(String primaryId, String secondaryId) { |
| 988 |
LayoutPart testPart; |
807 |
ILayoutContainer testCont; |
| 989 |
if (secondaryId == null) |
808 |
if (secondaryId == null) |
| 990 |
testPart = findPart(primaryId); |
809 |
testCont = perspective.findContainer(primaryId); |
| 991 |
else |
810 |
else |
| 992 |
testPart = findPart(primaryId, secondaryId); |
811 |
testCont = perspective |
| 993 |
return (testPart != null && testPart instanceof PartPlaceholder); |
812 |
.findContainer(primaryId + ViewFactory.ID_SEP + secondaryId); |
|
|
813 |
return (testCont != null); |
| 994 |
} |
814 |
} |
| 995 |
|
815 |
|
| 996 |
/** |
816 |
/** |
|
Lines 1000-1018
Link Here
|
| 1000 |
return mainLayout; |
820 |
return mainLayout; |
| 1001 |
} |
821 |
} |
| 1002 |
|
822 |
|
| 1003 |
///** |
|
|
| 1004 |
// * Returns the zoomed part. |
| 1005 |
// * <p> |
| 1006 |
// * If the zoomed part is an editor, it will be the |
| 1007 |
// * editor which caused the workbook it is in to be zoomed. It may not be |
| 1008 |
// the |
| 1009 |
// * visible editor. The zoomed part will always be an editor in the zoomed |
| 1010 |
// * workbench. |
| 1011 |
// * </p> |
| 1012 |
// */ |
| 1013 |
///*package*/ IWorkbenchPart getZoomPart() { |
| 1014 |
// return zoomPart; |
| 1015 |
//} |
| 1016 |
/** |
823 |
/** |
| 1017 |
* Gets the active state. |
824 |
* Gets the active state. |
| 1018 |
*/ |
825 |
*/ |
|
Lines 1082-1087
Link Here
|
| 1082 |
} |
889 |
} |
| 1083 |
|
890 |
|
| 1084 |
/** |
891 |
/** |
|
|
892 |
* Returns an immediate child of this perspective helper that directly or indirectly |
| 893 |
* contains the given pane. Returns null if none. |
| 894 |
* |
| 895 |
* @param toFind |
| 896 |
* @return |
| 897 |
*/ |
| 898 |
protected ILayoutContainer getLocation(PartPane toFind) { |
| 899 |
ILayoutContainer container; |
| 900 |
if(toFind == null || toFind.getContainer() == null) { |
| 901 |
return mainLayout; |
| 902 |
} |
| 903 |
for (container = toFind.getContainer(); container.getContainer() != null; |
| 904 |
container = container.getContainer()) { |
| 905 |
//do nothing |
| 906 |
} |
| 907 |
|
| 908 |
return container; |
| 909 |
} |
| 910 |
|
| 911 |
/** |
| 1085 |
* Remove all references to a part. |
912 |
* Remove all references to a part. |
| 1086 |
*/ |
913 |
*/ |
| 1087 |
public void removePart(LayoutPart part) { |
914 |
public void removePart(LayoutPart part) { |
|
Lines 1096-1199
Link Here
|
| 1096 |
// Replace part with a placeholder |
923 |
// Replace part with a placeholder |
| 1097 |
ILayoutContainer container = part.getContainer(); |
924 |
ILayoutContainer container = part.getContainer(); |
| 1098 |
if (container != null) { |
925 |
if (container != null) { |
| 1099 |
String placeHolderId = part.getPlaceHolderId(); |
926 |
if(container instanceof PartStack && part instanceof PartPane) { |
| 1100 |
container.replace(part, new PartPlaceholder(placeHolderId)); |
927 |
ILayoutContainer rootContainer = getLocation((PartPane)part); |
| 1101 |
|
928 |
if (rootContainer != null) { |
| 1102 |
// If the parent is root we're done. Do not try to replace |
929 |
perspective.addPlaceholder(part.getCompoundId(), rootContainer); |
| 1103 |
// it with placeholder. |
930 |
rootContainer.remove(part); |
| 1104 |
if (container == mainLayout) |
931 |
} |
| 1105 |
return; |
932 |
} |
| 1106 |
|
933 |
|
| 1107 |
// If the parent is empty replace it with a placeholder. |
934 |
if(container instanceof FastViewBar) { |
| 1108 |
LayoutPart[] children = container.getChildren(); |
935 |
container.remove(part); |
| 1109 |
if (children != null) { |
936 |
} |
| 1110 |
boolean allInvisible = true; |
|
|
| 1111 |
for (int i = 0, length = children.length; i < length; i++) { |
| 1112 |
if (!(children[i] instanceof PartPlaceholder)) { |
| 1113 |
allInvisible = false; |
| 1114 |
break; |
| 1115 |
} |
| 1116 |
} |
| 1117 |
if (allInvisible && (container instanceof LayoutPart)) { |
| 1118 |
// what type of window are we in? |
| 1119 |
LayoutPart cPart = (LayoutPart) container; |
| 1120 |
Window oldWindow = cPart.getWindow(); |
| 1121 |
if (oldWindow instanceof WorkbenchWindow) { |
| 1122 |
// PR 1GDFVBY: ViewStack not disposed when page |
| 1123 |
// closed. |
| 1124 |
if (container instanceof ViewStack) |
| 1125 |
((ViewStack) container).dispose(); |
| 1126 |
|
| 1127 |
// replace the real container with a |
| 1128 |
// ContainerPlaceholder |
| 1129 |
ILayoutContainer parentContainer = cPart.getContainer(); |
| 1130 |
ContainerPlaceholder placeholder = new ContainerPlaceholder( |
| 1131 |
cPart.getID()); |
| 1132 |
placeholder.setRealContainer(container); |
| 1133 |
parentContainer.replace(cPart, placeholder); |
| 1134 |
} else if (oldWindow instanceof DetachedWindow) { |
| 1135 |
DetachedPlaceHolder placeholder = new DetachedPlaceHolder( |
| 1136 |
"", oldWindow.getShell().getBounds()); //$NON-NLS-1$ |
| 1137 |
for (int i = 0, length = children.length; i < length; i++) { |
| 1138 |
children[i].getContainer().remove(children[i]); |
| 1139 |
children[i].setContainer(placeholder); |
| 1140 |
placeholder.add(children[i]); |
| 1141 |
} |
| 1142 |
detachedPlaceHolderList.add(placeholder); |
| 1143 |
oldWindow.close(); |
| 1144 |
detachedWindowList.remove(oldWindow); |
| 1145 |
} |
| 1146 |
} |
| 1147 |
} |
| 1148 |
} |
937 |
} |
| 1149 |
} |
938 |
} |
| 1150 |
|
939 |
|
| 1151 |
/** |
|
|
| 1152 |
* Add a part to the presentation. |
| 1153 |
* |
| 1154 |
* Note: unlike all other LayoutParts, PartPlaceholders will still point to |
| 1155 |
* their parent container even when it is inactive. This method relies on this |
| 1156 |
* fact to locate the parent. |
| 1157 |
*/ |
| 1158 |
public void replacePlaceholderWithPart(LayoutPart part) { |
| 1159 |
// If part added / removed always zoom out. |
| 1160 |
if (isZoomed()) |
| 1161 |
zoomOut(); |
| 1162 |
|
940 |
|
| 1163 |
// Look for a PartPlaceholder that will tell us how to position this |
941 |
private void restorePlaceholderBranch(IMemento rootMemento, ILayoutContainer container) { |
| 1164 |
// object |
942 |
IMemento placeholders = rootMemento.getChild(IWorkbenchConstants.TAG_PLACEHOLDERS); |
| 1165 |
PartPlaceholder[] placeholders = collectPlaceholders(); |
943 |
if(placeholders != null) { |
| 1166 |
for (int i = 0, length = placeholders.length; i < length; i++) { |
944 |
IMemento[] fPlaceholders = placeholders.getChildren(IWorkbenchConstants.TAG_PAGE); |
| 1167 |
if (placeholders[i].getCompoundId().equals(part.getCompoundId())) { |
945 |
for(int i = 0; i < fPlaceholders.length; i++){ |
| 1168 |
// found a matching placeholder which we can replace with the |
946 |
perspective.addPlaceholder(fPlaceholders[i].getString |
| 1169 |
// new View |
947 |
(IWorkbenchConstants.TAG_CONTENT), container); |
| 1170 |
ILayoutContainer container = placeholders[i].getContainer(); |
948 |
} |
| 1171 |
if (container != null) { |
|
|
| 1172 |
if (container instanceof ContainerPlaceholder) { |
| 1173 |
// One of the children is now visible so replace the |
| 1174 |
// ContainerPlaceholder with the real container |
| 1175 |
ContainerPlaceholder containerPlaceholder = (ContainerPlaceholder) container; |
| 1176 |
ILayoutContainer parentContainer = containerPlaceholder |
| 1177 |
.getContainer(); |
| 1178 |
container = (ILayoutContainer) containerPlaceholder |
| 1179 |
.getRealContainer(); |
| 1180 |
if (container instanceof LayoutPart) { |
| 1181 |
parentContainer.replace(containerPlaceholder, |
| 1182 |
(LayoutPart) container); |
| 1183 |
} |
| 1184 |
containerPlaceholder.setRealContainer(null); |
| 1185 |
} |
| 1186 |
container.replace(placeholders[i], part); |
| 1187 |
return; |
| 1188 |
} |
| 1189 |
} |
| 1190 |
} |
949 |
} |
| 1191 |
|
|
|
| 1192 |
// If there was no placeholder then the editor workbook is not in the |
| 1193 |
// workbench. |
| 1194 |
// That's OK. Just return. |
| 1195 |
} |
950 |
} |
| 1196 |
|
951 |
|
| 1197 |
/** |
952 |
/** |
| 1198 |
* @see IPersistablePart |
953 |
* @see IPersistablePart |
| 1199 |
*/ |
954 |
*/ |
|
Lines 1202-1208
Link Here
|
| 1202 |
IMemento childMem = memento |
957 |
IMemento childMem = memento |
| 1203 |
.getChild(IWorkbenchConstants.TAG_MAIN_WINDOW); |
958 |
.getChild(IWorkbenchConstants.TAG_MAIN_WINDOW); |
| 1204 |
IStatus r = mainLayout.restoreState(childMem); |
959 |
IStatus r = mainLayout.restoreState(childMem); |
| 1205 |
|
960 |
restorePlaceholderBranch(childMem, mainLayout); |
|
|
961 |
|
| 1206 |
// Restore each floating window. |
962 |
// Restore each floating window. |
| 1207 |
if (detachable) { |
963 |
if (detachable) { |
| 1208 |
IMemento detachedWindows[] = memento |
964 |
IMemento detachedWindows[] = memento |
|
Lines 1211-1229
Link Here
|
| 1211 |
DetachedWindow win = new DetachedWindow(page); |
967 |
DetachedWindow win = new DetachedWindow(page); |
| 1212 |
detachedWindowList.add(win); |
968 |
detachedWindowList.add(win); |
| 1213 |
win.restoreState(detachedWindows[nX]); |
969 |
win.restoreState(detachedWindows[nX]); |
| 1214 |
} |
970 |
restorePlaceholderBranch(detachedWindows[nX], win); |
| 1215 |
IMemento childrenMem[] = memento |
|
|
| 1216 |
.getChildren(IWorkbenchConstants.TAG_HIDDEN_WINDOW); |
| 1217 |
for (int i = 0, length = childrenMem.length; i < length; i++) { |
| 1218 |
DetachedPlaceHolder holder = new DetachedPlaceHolder( |
| 1219 |
"", new Rectangle(0, 0, 0, 0)); //$NON-NLS-1$ |
| 1220 |
holder.restoreState(childrenMem[i]); |
| 1221 |
detachedPlaceHolderList.add(holder); |
| 1222 |
} |
971 |
} |
| 1223 |
} |
972 |
} |
|
|
973 |
|
| 974 |
// restore the fast view bar placeholders |
| 975 |
childMem = memento |
| 976 |
.getChild(IWorkbenchConstants.TAG_FASTVIEWBAR); |
| 977 |
if(childMem != null) { |
| 978 |
restorePlaceholderBranch(childMem, ((WorkbenchWindow)page.getWorkbenchWindow()).getFastViewBar()); |
| 979 |
} |
| 1224 |
return r; |
980 |
return r; |
| 1225 |
|
981 |
|
| 1226 |
} |
982 |
} |
|
|
983 |
|
| 984 |
private void savePlaceholderBranch(IMemento rootMemento, ILayoutContainer container) { |
| 985 |
//make placeholders for all the visible views |
| 986 |
LayoutPart[] parts = container.getChildren(); |
| 987 |
for(int n = 0; n < parts.length; n++) { |
| 988 |
if(parts[n] instanceof ViewStack) { |
| 989 |
LayoutPart[] folderParts = ((ViewStack)parts[n]).getChildren(); |
| 990 |
for(int m = 0; m < folderParts.length; m++) { |
| 991 |
perspective.addPlaceholder(folderParts[m].getCompoundId(), container); |
| 992 |
} |
| 993 |
} |
| 994 |
else if (container instanceof DetachedWindow) { |
| 995 |
perspective.addPlaceholder(parts[n].getCompoundId(), container); |
| 996 |
} |
| 997 |
} |
| 998 |
|
| 999 |
String[] placeholders = perspective.getAssociatedParts(container); |
| 1000 |
IMemento placeholderMem = rootMemento.createChild(IWorkbenchConstants.TAG_PLACEHOLDERS); |
| 1001 |
for(int i = 0; i < placeholders.length; i++){ |
| 1002 |
IMemento phChild = placeholderMem.createChild(IWorkbenchConstants.TAG_PAGE); |
| 1003 |
phChild.putString(IWorkbenchConstants.TAG_CONTENT, placeholders[i]); |
| 1004 |
} |
| 1005 |
} |
| 1227 |
|
1006 |
|
| 1228 |
/** |
1007 |
/** |
| 1229 |
* @see IPersistablePart |
1008 |
* @see IPersistablePart |
|
Lines 1233-1238
Link Here
|
| 1233 |
IMemento childMem = memento |
1012 |
IMemento childMem = memento |
| 1234 |
.createChild(IWorkbenchConstants.TAG_MAIN_WINDOW); |
1013 |
.createChild(IWorkbenchConstants.TAG_MAIN_WINDOW); |
| 1235 |
IStatus r = mainLayout.saveState(childMem); |
1014 |
IStatus r = mainLayout.saveState(childMem); |
|
|
1015 |
savePlaceholderBranch(childMem, mainLayout); |
| 1236 |
|
1016 |
|
| 1237 |
if (detachable) { |
1017 |
if (detachable) { |
| 1238 |
// Persist each detached window. |
1018 |
// Persist each detached window. |
|
Lines 1242-1256
Link Here
|
| 1242 |
childMem = memento |
1022 |
childMem = memento |
| 1243 |
.createChild(IWorkbenchConstants.TAG_DETACHED_WINDOW); |
1023 |
.createChild(IWorkbenchConstants.TAG_DETACHED_WINDOW); |
| 1244 |
window.saveState(childMem); |
1024 |
window.saveState(childMem); |
| 1245 |
} |
1025 |
savePlaceholderBranch(childMem, window); |
| 1246 |
for (int i = 0, length = detachedPlaceHolderList.size(); i < length; i++) { |
|
|
| 1247 |
DetachedPlaceHolder holder = (DetachedPlaceHolder) detachedPlaceHolderList |
| 1248 |
.get(i); |
| 1249 |
childMem = memento |
| 1250 |
.createChild(IWorkbenchConstants.TAG_HIDDEN_WINDOW); |
| 1251 |
holder.saveState(childMem); |
| 1252 |
} |
1026 |
} |
| 1253 |
} |
1027 |
} |
|
|
1028 |
|
| 1029 |
//Save the fastviewbar |
| 1030 |
childMem = memento |
| 1031 |
.createChild(IWorkbenchConstants.TAG_FASTVIEWBAR); |
| 1032 |
savePlaceholderBranch(childMem, ((WorkbenchWindow)page.getWorkbenchWindow()).getFastViewBar()); |
| 1033 |
|
| 1254 |
return r; |
1034 |
return r; |
| 1255 |
} |
1035 |
} |
| 1256 |
|
1036 |
|
|
Lines 1275-1284
Link Here
|
| 1275 |
//TODO: Remove once all views are in ViewStack |
1055 |
//TODO: Remove once all views are in ViewStack |
| 1276 |
//TODO: See Bug 48794 |
1056 |
//TODO: See Bug 48794 |
| 1277 |
ViewStack parent = (ViewStack) parentContainer; |
1057 |
ViewStack parent = (ViewStack) parentContainer; |
| 1278 |
Perspective persp = page.getActivePerspective(); |
1058 |
if (perspective != null && ref instanceof IViewReference |
| 1279 |
if (persp != null && ref instanceof IViewReference |
|
|
| 1280 |
&& page.isFastView((IViewReference) ref)) { |
1059 |
&& page.isFastView((IViewReference) ref)) { |
| 1281 |
persp.hideFastViewSash(); |
1060 |
perspective.hideFastViewSash(); |
| 1282 |
} |
1061 |
} |
| 1283 |
mainLayout.zoomIn(parent); |
1062 |
mainLayout.zoomIn(parent); |
| 1284 |
pane.setZoomed(true); |
1063 |
pane.setZoomed(true); |
|
Lines 1324-1333
Link Here
|
| 1324 |
parentWidget.setRedraw(false); |
1103 |
parentWidget.setRedraw(false); |
| 1325 |
mainLayout.zoomOut(); |
1104 |
mainLayout.zoomOut(); |
| 1326 |
pane.setZoomed(false); |
1105 |
pane.setZoomed(false); |
| 1327 |
Perspective persp = page.getActivePerspective(); |
1106 |
if (perspective != null && zoomPart instanceof IViewReference |
| 1328 |
if (persp != null && zoomPart instanceof IViewReference |
|
|
| 1329 |
&& page.isFastView((IViewReference) zoomPart)) { |
1107 |
&& page.isFastView((IViewReference) zoomPart)) { |
| 1330 |
persp.showFastView((IViewReference) zoomPart); |
1108 |
perspective.showFastView((IViewReference) zoomPart); |
| 1331 |
} |
1109 |
} |
| 1332 |
parentWidget.setRedraw(true); |
1110 |
parentWidget.setRedraw(true); |
| 1333 |
} else if (pane instanceof EditorPane) { |
1111 |
} else if (pane instanceof EditorPane) { |