1 12 package org.eclipse.ui.internal.presentations; 13 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 18 import org.eclipse.core.runtime.Assert; 19 import org.eclipse.jface.action.GroupMarker; 20 import org.eclipse.jface.action.IMenuManager; 21 import org.eclipse.jface.action.MenuManager; 22 import org.eclipse.jface.action.Separator; 23 import org.eclipse.jface.util.Geometry; 24 import org.eclipse.jface.window.Window; 25 import org.eclipse.swt.SWT; 26 import org.eclipse.swt.custom.CLabel; 27 import org.eclipse.swt.events.DisposeEvent; 28 import org.eclipse.swt.events.DisposeListener; 29 import org.eclipse.swt.events.MouseAdapter; 30 import org.eclipse.swt.events.MouseEvent; 31 import org.eclipse.swt.events.MouseListener; 32 import org.eclipse.swt.events.SelectionAdapter; 33 import org.eclipse.swt.events.SelectionEvent; 34 import org.eclipse.swt.events.ShellAdapter; 35 import org.eclipse.swt.events.ShellEvent; 36 import org.eclipse.swt.graphics.Color; 37 import org.eclipse.swt.graphics.Image; 38 import org.eclipse.swt.graphics.Point; 39 import org.eclipse.swt.graphics.Rectangle; 40 import org.eclipse.swt.widgets.Control; 41 import org.eclipse.swt.widgets.Event; 42 import org.eclipse.swt.widgets.Listener; 43 import org.eclipse.swt.widgets.Menu; 44 import org.eclipse.swt.widgets.Shell; 45 import org.eclipse.swt.widgets.ToolBar; 46 import org.eclipse.swt.widgets.ToolItem; 47 import org.eclipse.ui.IMemento; 48 import org.eclipse.ui.IPropertyListener; 49 import org.eclipse.ui.internal.IWorkbenchConstants; 50 import org.eclipse.ui.internal.IWorkbenchGraphicConstants; 51 import org.eclipse.ui.internal.WorkbenchImages; 52 import org.eclipse.ui.internal.dnd.DragUtil; 53 import org.eclipse.ui.internal.presentations.r21.R21Colors; 54 import org.eclipse.ui.internal.presentations.r21.R21PresentationMessages; 55 import org.eclipse.ui.internal.presentations.r21.widgets.CTabItem; 56 import org.eclipse.ui.internal.presentations.r21.widgets.R21PaneFolder; 57 import org.eclipse.ui.internal.util.Util; 58 import org.eclipse.ui.presentations.IPartMenu; 59 import org.eclipse.ui.presentations.IPresentablePart; 60 import org.eclipse.ui.presentations.IPresentationSerializer; 61 import org.eclipse.ui.presentations.IStackPresentationSite; 62 import org.eclipse.ui.presentations.PresentationUtil; 63 import org.eclipse.ui.presentations.StackDropResult; 64 import org.eclipse.ui.presentations.StackPresentation; 65 66 72 public class R21BasicStackPresentation extends StackPresentation { 73 74 private R21PaneFolder paneFolder; 75 76 private IPresentablePart current; 77 78 private boolean activeState = false; 79 80 private MenuManager systemMenuManager = new MenuManager(); 81 82 private CLabel titleLabel; 83 84 private boolean shellActive = true; 85 86 private final static String TAB_DATA = R21BasicStackPresentation.class 87 .getName() 88 + ".partId"; 90 private MouseListener mouseListener = new MouseAdapter() { 104 public void mouseDown(MouseEvent e) { 105 if (e.widget instanceof Control) { 106 Control ctrl = (Control) e.widget; 107 Point globalPos = ctrl.toDisplay(new Point(e.x, e.y)); 108 109 CTabItem newItem = paneFolder.getItem(paneFolder.getControl() 113 .toControl(globalPos)); 114 if (newItem != null) { 115 CTabItem oldItem = paneFolder.getSelection(); 116 if (newItem != oldItem) { 117 return; 118 } 119 } 120 if (current != null) { 121 current.setFocus(); 122 } 123 } 124 } 125 126 public void mouseDoubleClick(MouseEvent e) { 127 if (getSite().getState() == IStackPresentationSite.STATE_MAXIMIZED) { 128 getSite().setState(IStackPresentationSite.STATE_RESTORED); 129 } else { 130 getSite().setState(IStackPresentationSite.STATE_MAXIMIZED); 131 } 132 } 133 }; 134 135 private MouseListener titleMouseListener = new MouseAdapter() { 136 public void mouseDown(MouseEvent e) { 137 if (e.widget instanceof Control) { 138 Control ctrl = (Control) e.widget; 139 Point globalPos = ctrl.toDisplay(new Point(0, titleLabel 140 .getBounds().height)); 141 142 if ((e.button == 1) && overImage(e.x)) { 143 showSystemMenu(globalPos); 144 } 145 } 146 } 147 }; 148 149 private Listener menuListener = new Listener() { 150 155 public void handleEvent(Event event) { 156 Point pos = new Point(event.x, event.y); 157 158 showSystemMenu(pos); 159 } 160 }; 161 162 private Listener dragListener = new Listener() { 163 public void handleEvent(Event event) { 164 165 Point localPos = new Point(event.x, event.y); 166 CTabItem tabUnderPointer = paneFolder.getItem(localPos); 167 168 if (tabUnderPointer == null) { 170 if (paneFolder.getTabPosition() == SWT.BOTTOM 171 && localPos.y < paneFolder.getControl().getBounds().height 172 - paneFolder.getTabHeight()) { 173 tabUnderPointer = paneFolder.getSelection(); 174 } else if (paneFolder.getTabPosition() == SWT.TOP 175 && localPos.y > paneFolder.getTabHeight()) { 176 tabUnderPointer = paneFolder.getSelection(); 177 } 178 } 179 180 if (tabUnderPointer == null) { 183 getSite().dragStart( 184 paneFolder.getControl().toDisplay(localPos), false); 185 return; 186 } 187 188 IPresentablePart part = getPartForTab(tabUnderPointer); 189 190 if (getSite().isPartMoveable(part)) { 191 getSite().dragStart(part, 192 paneFolder.getControl().toDisplay(localPos), false); 193 } 194 } 195 }; 196 197 private Listener selectionListener = new Listener() { 198 public void handleEvent(Event e) { 199 IPresentablePart item = getPartForTab((CTabItem) e.item); 200 201 if (item != null) { 202 getSite().selectPart(item); 203 } 204 } 205 }; 206 207 private Listener resizeListener = new Listener() { 208 public void handleEvent(Event e) { 209 setControlSize(); 210 } 211 }; 212 213 private IPropertyListener childPropertyChangeListener = new IPropertyListener() { 214 public void propertyChanged(Object source, int property) { 215 if (source instanceof IPresentablePart) { 216 IPresentablePart part = (IPresentablePart) source; 217 childPropertyChanged(part, property); 218 } 219 } 220 }; 221 222 private DisposeListener tabDisposeListener = new DisposeListener() { 223 public void widgetDisposed(DisposeEvent e) { 224 if (e.widget instanceof CTabItem) { 225 CTabItem item = (CTabItem) e.widget; 226 227 IPresentablePart part = getPartForTab(item); 228 229 part.removePropertyListener(childPropertyChangeListener); 230 } 231 } 232 }; 233 234 235 private ShellAdapter shellListener = new ShellAdapter() { 236 237 public void shellActivated(ShellEvent event) { 238 shellActive = true; 239 updateGradient(); 240 } 241 242 public void shellDeactivated(ShellEvent event) { 243 shellActive = false; 244 updateGradient(); 245 } 246 }; 247 248 private ToolBar viewToolBar; 249 250 private ToolItem pullDownButton; 251 252 private ToolItem closeButton; 253 254 public R21BasicStackPresentation(R21PaneFolder control, 255 IStackPresentationSite stackSite) { 256 super(stackSite); 257 paneFolder = control; 258 259 shellActive = paneFolder.getControl().getShell().equals( 260 control.getControl().getDisplay().getActiveShell()); 261 262 titleLabel = new CLabel(paneFolder.getControl(), SWT.SHADOW_NONE); 266 titleLabel.setVisible(false); 267 titleLabel.moveAbove(null); 268 titleLabel.addMouseListener(titleMouseListener); 269 titleLabel.addMouseListener(mouseListener); 270 titleLabel.addListener(SWT.MenuDetect, menuListener); 271 PresentationUtil.addDragListener(titleLabel, dragListener); 272 273 275 viewToolBar = new ToolBar(control.getControl(), SWT.HORIZONTAL 276 | SWT.FLAT); 277 viewToolBar.moveAbove(null); 278 279 pullDownButton = new ToolItem(viewToolBar, SWT.PUSH); 280 Image hoverImage = WorkbenchImages 283 .getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU); 284 pullDownButton.setDisabledImage(null); pullDownButton.setImage(hoverImage); 287 pullDownButton.setToolTipText(R21PresentationMessages 288 .getString("BasicStackPresentation.menu.tooltip")); pullDownButton.addSelectionListener(new SelectionAdapter() { 290 public void widgetSelected(SelectionEvent e) { 291 showPaneMenu(); 292 } 293 }); 294 295 paneFolder.getControl().addListener(SWT.Selection, selectionListener); 297 298 paneFolder.getControl().addListener(SWT.Resize, resizeListener); 300 301 paneFolder.getControl().addMouseListener(mouseListener); 303 304 paneFolder.getControl().addListener(SWT.MenuDetect, menuListener); 305 306 308 PresentationUtil.addDragListener(paneFolder.getControl(), dragListener); 309 310 paneFolder.getControl().getShell().addShellListener(shellListener); 313 314 324 populateSystemMenu(systemMenuManager); 334 } 335 336 339 private boolean overImage(int x) { 340 return x < titleLabel.getImage().getBounds().width; 341 } 342 343 346 private void populateSystemMenu(IMenuManager systemMenuManager) { 347 348 systemMenuManager.add(new GroupMarker("misc")); systemMenuManager.add(new GroupMarker("restore")); systemMenuManager.add(new UpdatingActionContributionItem( 351 new SystemMenuRestore(getSite()))); 352 353 systemMenuManager.add(new SystemMenuMove(getSite(), getPaneName())); 354 systemMenuManager.add(new GroupMarker("size")); systemMenuManager.add(new GroupMarker("state")); systemMenuManager.add(new UpdatingActionContributionItem( 357 new SystemMenuMinimize(getSite()))); 358 359 systemMenuManager.add(new UpdatingActionContributionItem( 360 new SystemMenuMaximize(getSite()))); 361 systemMenuManager.add(new Separator("close")); systemMenuManager.add(new UpdatingActionContributionItem( 363 new SystemMenuClose(getSite()))); 364 365 getSite().addSystemActions(systemMenuManager); 366 } 367 368 protected String getPaneName() { 369 return R21PresentationMessages.getString("BasicStackPresentation.pane"); } 371 372 375 public void showPaneMenu() { 376 IPartMenu menu = getPartMenu(); 377 378 if (menu != null) { 379 Rectangle bounds = DragUtil.getDisplayBounds(viewToolBar); 380 menu.showMenu(new Point(bounds.x, bounds.y + bounds.height)); 381 } 382 } 383 384 389 protected IPresentablePart getCurrent() { 390 return current; 391 } 392 393 402 private final int indexOf(IPresentablePart part) { 403 if (part == null) { 404 return paneFolder.getItemCount(); 405 } 406 407 CTabItem[] items = paneFolder.getItems(); 408 409 for (int idx = 0; idx < items.length; idx++) { 410 IPresentablePart tabPart = getPartForTab(items[idx]); 411 412 if (part == tabPart) { 413 return idx; 414 } 415 } 416 417 return items.length; 418 } 419 420 427 protected final CTabItem getTab(IPresentablePart part) { 428 CTabItem[] items = paneFolder.getItems(); 429 430 int idx = indexOf(part); 431 432 if (idx < items.length) { 433 return items[idx]; 434 } 435 436 return null; 437 } 438 439 443 protected void childPropertyChanged(IPresentablePart part, int property) { 444 445 CTabItem tab = getTab(part); 446 initTab(tab, part); 447 448 switch (property) { 449 case IPresentablePart.PROP_BUSY: 450 break; 451 case IPresentablePart.PROP_HIGHLIGHT_IF_BACK: 452 case IPresentablePart.PROP_TOOLBAR: 462 case IPresentablePart.PROP_PANE_MENU: 463 case IPresentablePart.PROP_TITLE: 464 setControlSize(); 465 break; 466 } 467 } 468 469 protected final IPresentablePart getPartForTab(CTabItem item) { 470 IPresentablePart part = (IPresentablePart) item.getData(TAB_DATA); 471 472 return part; 473 } 474 475 480 protected R21PaneFolder getPaneFolder() { 481 return paneFolder; 482 } 483 484 489 public boolean isDisposed() { 490 return paneFolder == null || paneFolder.isDisposed(); 491 } 492 493 497 protected void updateGradient() { 498 499 if (isDisposed()) { 500 return; 501 } 502 503 Color fgColor; 504 Color[] bgColors; 505 int[] bgPercents; 506 boolean vertical = false; 507 if (isActive()) { 508 if (getShellActivated()) { 509 fgColor = R21Colors.getSystemColor(SWT.COLOR_TITLE_FOREGROUND); 510 bgColors = R21Colors.getActiveViewGradient(); 511 bgPercents = R21Colors.getActiveViewGradientPercents(); 512 } else { 513 fgColor = R21Colors 514 .getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND); 515 bgColors = R21Colors.getDeactivatedViewGradient(); 516 bgPercents = R21Colors.getDeactivatedViewGradientPercents(); 517 } 518 519 } else { 520 fgColor = R21Colors.getSystemColor(SWT.COLOR_LIST_FOREGROUND); 521 bgColors = null; 522 bgPercents = null; 523 } 524 525 drawGradient(fgColor, bgColors, bgPercents, vertical); 526 527 536 } 571 572 580 public void drawGradient(Color fgColor, Color[] bgColors, 581 int[] percentages, boolean vertical) { 582 585 if (titleLabel == null || viewToolBar == null) { 586 return; 587 } 588 589 titleLabel.setBackground(bgColors, percentages, vertical); 590 titleLabel.setForeground(fgColor); 591 592 titleLabel.update(); 593 } 594 595 public boolean isActive() { 596 return activeState; 597 } 598 599 606 public void setControlSize() { 607 610 if (current != null) { 611 paneFolder.setTopLeft(titleLabel); 612 titleLabel.setText(current.getTitle()); 613 titleLabel.setImage(current.getTitleImage()); 614 titleLabel.setVisible(true); 615 616 String toolTipText = current.getTitleToolTip(); 618 titleLabel.setToolTipText(toolTipText 619 .equals(Util.ZERO_LENGTH_STRING) ? null : toolTipText); 620 621 } 622 623 Control currentToolbar = getCurrentToolbar(); 624 paneFolder.setTopCenter(currentToolbar); 625 626 IPartMenu partMenu = getPartMenu(); 627 628 if (partMenu != null) { 629 pullDownButton.setEnabled(true); 630 } else { 631 pullDownButton.setEnabled(false); 632 } 633 paneFolder.setTopRight(viewToolBar); 634 viewToolBar.setVisible(true); 635 636 paneFolder.layout(true); 637 638 if (current != null) { 639 Rectangle clientArea = paneFolder.getClientArea(); 640 Rectangle bounds = paneFolder.getControl().getBounds(); 641 clientArea.x += bounds.x; 642 clientArea.y += bounds.y; 643 644 current.setBounds(clientArea); 645 } 646 647 } 648 649 655 protected IPartMenu getPartMenu() { 656 IPresentablePart part = getCurrentPart(); 657 if (part == null) { 658 return null; 659 } 660 661 return part.getMenu(); 662 } 663 664 669 public void dispose() { 670 if (isDisposed()) { 671 return; 672 } 673 674 paneFolder.getControl().getShell().removeShellListener(shellListener); 676 677 PresentationUtil.removeDragListener(paneFolder.getControl(), 678 dragListener); 679 PresentationUtil.removeDragListener(titleLabel, dragListener); 680 681 systemMenuManager.dispose(); 682 systemMenuManager.removeAll(); 683 paneFolder.getControl().dispose(); 684 paneFolder = null; 685 686 titleLabel.dispose(); 687 titleLabel = null; 688 689 viewToolBar.dispose(); 690 } 691 692 697 public void setActive(boolean isActive) { 698 activeState = isActive; 699 updateGradient(); 700 } 701 702 705 boolean getShellActivated() { 706 return shellActive; 707 } 708 709 712 public Window getWindow() { 713 Control ctrl = getControl(); 714 if (ctrl != null) { 715 Object data = ctrl.getShell().getData(); 716 if (data instanceof Window) { 717 return (Window) data; 718 } 719 } 720 return null; 721 } 722 723 private CTabItem createPartTab(IPresentablePart part, int tabIndex) { 724 CTabItem tabItem; 725 726 int style = SWT.NONE; 727 728 if (getSite().isCloseable(part)) { 729 style |= SWT.CLOSE; 730 } 731 732 tabItem = paneFolder.createItem(style, tabIndex); 733 734 tabItem.setData(TAB_DATA, part); 735 736 part.addPropertyListener(childPropertyChangeListener); 737 tabItem.addDisposeListener(tabDisposeListener); 738 739 initTab(tabItem, part); 740 741 return tabItem; 742 } 743 744 private void updateCloseButton() { 746 if (current == null || !getSite().isCloseable(current)) { 748 if (closeButton != null) { 749 closeButton.dispose(); 750 closeButton = null; 751 752 paneFolder.flush(); 753 } 754 return; 755 } 756 757 if (closeButton != null) { 759 return; 760 } 761 762 closeButton = new ToolItem(viewToolBar, SWT.PUSH); 764 closeButton.setDisabledImage(null); 765 closeButton.setImage(WorkbenchImages 766 .getImage(IWorkbenchGraphicConstants.IMG_LCL_CLOSE_VIEW)); 767 closeButton.setToolTipText(R21PresentationMessages 768 .getString("BasicStackPresentation.close.tooltip")); closeButton.addSelectionListener(new SelectionAdapter() { 770 public void widgetSelected(SelectionEvent e) { 771 close(getCurrent()); 772 } 773 }); 774 775 paneFolder.flush(); 776 } 777 778 789 protected void initTab(CTabItem tabItem, IPresentablePart part) { 790 tabItem.setText(part.getName()); 791 792 794 799 810 } 811 812 818 public void addPart(IPresentablePart newPart, Object cookie) { 819 820 int idx; 821 822 if (cookie instanceof Integer ) { 823 idx = ((Integer ) cookie).intValue(); 824 } else { 825 idx = paneFolder.getItemCount(); 827 } 828 829 addPart(newPart, idx); 830 } 831 832 839 public void addPart(IPresentablePart newPart, int index) { 840 if (getTab(newPart) != null) { 842 return; 843 } 844 createPartTab(newPart, index); 845 846 setControlSize(); 847 } 848 849 854 public void removePart(IPresentablePart oldPart) { 855 if (current == oldPart) { 856 titleLabel.setImage(null); 857 current = null; 858 } 859 860 CTabItem item = getTab(oldPart); 861 if (item == null) { 862 return; 863 } 864 oldPart.setVisible(false); 865 866 item.dispose(); 867 868 setControlSize(); 870 } 871 872 877 public void selectPart(IPresentablePart toSelect) { 878 if (toSelect == current) { 879 return; 880 } 881 882 IPresentablePart oldPart = current; 883 884 current = toSelect; 885 886 if (current != null) { 887 paneFolder.setSelection(indexOf(current)); 888 current.setVisible(true); 889 updateCloseButton(); 890 setControlSize(); 891 } 892 893 if (oldPart != null) { 894 oldPart.setVisible(false); 895 } 896 } 897 898 public IPresentablePart getCurrentPart() { 899 return current; 900 } 901 902 907 public void setBounds(Rectangle bounds) { 908 if (getSite().getState() == IStackPresentationSite.STATE_MINIMIZED) { 909 bounds = Geometry.copy(bounds); 910 bounds.height = computePreferredSize(false, Integer.MAX_VALUE, 911 bounds.width, Integer.MAX_VALUE); 912 } 913 914 paneFolder.getControl().setBounds(bounds); 915 setControlSize(); 916 } 917 918 923 public Point computeMinimumSize() { 924 Point result = Geometry.getSize(paneFolder.computeTrim(0, 0, 0, 0)); 925 926 result.x += 100; 927 928 return result; 929 } 930 931 936 public void setVisible(boolean isVisible) { 937 if (current != null) { 938 current.setVisible(isVisible); 939 } 940 paneFolder.getControl().setVisible(isVisible); 941 } 942 943 948 public void setState(int state) { 949 } 951 952 957 public IMenuManager getSystemMenuManager() { 958 return systemMenuManager; 959 } 960 961 964 protected void showSystemMenu(Point point) { 965 Menu aMenu = systemMenuManager.createContextMenu(paneFolder 966 .getControl().getParent()); 967 systemMenuManager.update(true); 968 aMenu.setLocation(point.x, point.y); 969 aMenu.setVisible(true); 970 } 971 972 977 public Control getControl() { 978 return paneFolder.getControl(); 979 } 980 981 987 public StackDropResult dragOver(Control currentControl, Point location) { 988 989 Point localPos = paneFolder.getControl().toControl(location); 991 final CTabItem tabUnderPointer = paneFolder.getItem(localPos); 992 993 if (tabUnderPointer == null) { 996 return null; 997 } 998 999 int dragOverIndex = paneFolder.indexOf(tabUnderPointer); 1001 1002 return new StackDropResult(Geometry.toDisplay(paneFolder.getControl(), 1003 tabUnderPointer.getBounds()), new Integer (dragOverIndex)); 1004 } 1005 1006 1012 protected Control getCurrentToolbar() { 1013 IPresentablePart part = getCurrentPart(); 1014 if (part == null) { 1015 return null; 1016 } 1017 1018 return part.getToolBar(); 1019 } 1020 1021 1026 public void showSystemMenu() { 1027 IPresentablePart part = getCurrentPart(); 1028 if (part != null) { 1029 Rectangle bounds = DragUtil.getDisplayBounds(paneFolder 1030 .getControl()); 1031 1032 int idx = paneFolder.getSelectionIndex(); 1033 if (idx > -1) { 1034 CTabItem item = paneFolder.getItem(idx); 1035 Rectangle itemBounds = item.getBounds(); 1036 1037 bounds.x += itemBounds.x; 1038 bounds.y += itemBounds.y; 1039 } 1040 1041 Point location = new Point(bounds.x, bounds.y 1042 + paneFolder.getTabHeight()); 1043 showSystemMenu(location); 1044 } 1045 } 1046 1047 1052 public Control[] getTabList(IPresentablePart part) { 1053 ArrayList list = new ArrayList (); 1054 if (paneFolder.getTabPosition() == SWT.BOTTOM) { 1055 if (part.getToolBar() != null) { 1056 list.add(part.getToolBar()); 1057 } 1058 if (part.getControl() != null) { 1059 list.add(part.getControl()); 1060 } 1061 if (getPaneFolder() != null) { 1062 list.add(getPaneFolder().getControl()); 1063 } 1064 } else { 1065 if (getPaneFolder() != null) { 1066 list.add(getPaneFolder().getControl()); 1067 } 1068 if (part.getToolBar() != null) { 1069 list.add(part.getToolBar()); 1070 } 1071 if (part.getControl() != null) { 1072 list.add(part.getControl()); 1073 } 1074 } 1075 return (Control[]) list.toArray(new Control[list.size()]); 1076 } 1077 1078 protected void showList(Shell parentShell, int x, int y) { 1079 } 1103 1104 1107 protected void showListDefaultLocation() { 1108 R21PaneFolder tabFolder = getPaneFolder(); 1109 Shell shell = tabFolder.getControl().getShell(); 1110 Rectangle clientArea = tabFolder.getClientArea(); 1111 Point location = tabFolder.getControl().getDisplay().map( 1112 tabFolder.getControl(), null, clientArea.x, clientArea.y); 1113 showList(shell, location.x, location.y); 1114 } 1115 1116 void setSelection(CTabItem tabItem) { 1117 getSite().selectPart(getPartForTab(tabItem)); 1118 } 1119 1120 void close(IPresentablePart presentablePart) { 1121 getSite().close(new IPresentablePart[] { presentablePart }); 1122 } 1123 1124 Image getLabelImage(IPresentablePart presentablePart) { 1125 return presentablePart.getTitleImage(); 1126 } 1127 1128 String getLabelText(IPresentablePart presentablePart, boolean includePath) { 1129 String title = presentablePart.getTitle().trim(); 1130 return title; 1131 } 1132 1133 1138 public void setActive(int newState) { 1139 setActive(newState == AS_ACTIVE_FOCUS); 1140 } 1141 1142 1148 public void restoreState(IPresentationSerializer serializer, 1149 IMemento savedState) { 1150 IMemento[] parts = savedState.getChildren(IWorkbenchConstants.TAG_PART); 1151 1152 for (int idx = 0; idx < parts.length; idx++) { 1153 String id = parts[idx].getString(IWorkbenchConstants.TAG_ID); 1154 1155 if (id != null) { 1156 IPresentablePart part = serializer.getPart(id); 1157 1158 if (part != null) { 1159 addPart(part, getPaneFolder().getItemCount()); 1160 } 1161 } 1162 } 1163 } 1164 1165 1171 public void saveState(IPresentationSerializer context, IMemento memento) { 1172 super.saveState(context, memento); 1173 1174 List parts = getPresentableParts(); 1175 1176 Iterator iter = parts.iterator(); 1177 while (iter.hasNext()) { 1178 IPresentablePart next = (IPresentablePart) iter.next(); 1179 1180 IMemento childMem = memento 1181 .createChild(IWorkbenchConstants.TAG_PART); 1182 childMem.putString(IWorkbenchConstants.TAG_ID, context.getId(next)); 1183 } 1184 } 1185 1186 1189 private List getPresentableParts() { 1190 Assert.isTrue(!isDisposed()); 1191 1192 CTabItem[] items = getPaneFolder().getItems(); 1193 List result = new ArrayList (items.length); 1194 1195 for (int idx = 0; idx < getPaneFolder().getItemCount(); idx++) { 1196 result.add(getPartForTab(items[idx])); 1197 } 1198 1199 return result; 1200 } 1201} 1202 | Popular Tags |