1 11 package org.eclipse.ui.internal.dialogs; 12 13 import java.net.URL ; 14 import java.util.ArrayList ; 15 import java.util.Arrays ; 16 import java.util.Hashtable ; 17 import java.util.Iterator ; 18 import java.util.List ; 19 import java.util.Map ; 20 21 import org.eclipse.core.runtime.CoreException; 22 import org.eclipse.jface.action.ContributionManager; 23 import org.eclipse.jface.action.CoolBarManager; 24 import org.eclipse.jface.action.IAction; 25 import org.eclipse.jface.action.IContributionItem; 26 import org.eclipse.jface.action.ICoolBarManager; 27 import org.eclipse.jface.action.IMenuManager; 28 import org.eclipse.jface.action.IStatusLineManager; 29 import org.eclipse.jface.action.IToolBarManager; 30 import org.eclipse.jface.action.MenuManager; 31 import org.eclipse.jface.action.StatusLineManager; 32 import org.eclipse.jface.action.ToolBarManager; 33 import org.eclipse.jface.dialogs.TrayDialog; 34 import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem; 35 import org.eclipse.jface.internal.provisional.action.ToolBarContributionItem2; 36 import org.eclipse.jface.resource.ImageDescriptor; 37 import org.eclipse.jface.viewers.AbstractTreeViewer; 38 import org.eclipse.jface.viewers.ArrayContentProvider; 39 import org.eclipse.jface.viewers.CheckStateChangedEvent; 40 import org.eclipse.jface.viewers.CheckboxTableViewer; 41 import org.eclipse.jface.viewers.CheckboxTreeViewer; 42 import org.eclipse.jface.viewers.ICheckStateListener; 43 import org.eclipse.jface.viewers.ISelectionChangedListener; 44 import org.eclipse.jface.viewers.IStructuredContentProvider; 45 import org.eclipse.jface.viewers.IStructuredSelection; 46 import org.eclipse.jface.viewers.ITableLabelProvider; 47 import org.eclipse.jface.viewers.ITreeContentProvider; 48 import org.eclipse.jface.viewers.LabelProvider; 49 import org.eclipse.jface.viewers.SelectionChangedEvent; 50 import org.eclipse.jface.viewers.StructuredSelection; 51 import org.eclipse.jface.viewers.TreeViewer; 52 import org.eclipse.jface.viewers.Viewer; 53 import org.eclipse.jface.window.DefaultToolTip; 54 import org.eclipse.jface.window.ToolTip; 55 import org.eclipse.osgi.util.NLS; 56 import org.eclipse.swt.SWT; 57 import org.eclipse.swt.custom.SashForm; 58 import org.eclipse.swt.events.KeyEvent; 59 import org.eclipse.swt.events.KeyListener; 60 import org.eclipse.swt.events.ModifyEvent; 61 import org.eclipse.swt.events.ModifyListener; 62 import org.eclipse.swt.events.SelectionAdapter; 63 import org.eclipse.swt.events.SelectionEvent; 64 import org.eclipse.swt.events.SelectionListener; 65 import org.eclipse.swt.graphics.Image; 66 import org.eclipse.swt.graphics.Point; 67 import org.eclipse.swt.layout.GridData; 68 import org.eclipse.swt.layout.GridLayout; 69 import org.eclipse.swt.widgets.Combo; 70 import org.eclipse.swt.widgets.Composite; 71 import org.eclipse.swt.widgets.Control; 72 import org.eclipse.swt.widgets.Event; 73 import org.eclipse.swt.widgets.Label; 74 import org.eclipse.swt.widgets.Shell; 75 import org.eclipse.swt.widgets.TabFolder; 76 import org.eclipse.swt.widgets.TabItem; 77 import org.eclipse.swt.widgets.Table; 78 import org.eclipse.swt.widgets.TableColumn; 79 import org.eclipse.ui.IActionBars2; 80 import org.eclipse.ui.IPerspectiveDescriptor; 81 import org.eclipse.ui.IPerspectiveRegistry; 82 import org.eclipse.ui.PlatformUI; 83 import org.eclipse.ui.activities.WorkbenchActivityHelper; 84 import org.eclipse.ui.application.ActionBarAdvisor; 85 import org.eclipse.ui.application.IWorkbenchWindowConfigurer; 86 import org.eclipse.ui.internal.ActionSetActionBars; 87 import org.eclipse.ui.internal.ActionSetContributionItem; 88 import org.eclipse.ui.internal.ActionSetMenuManager; 89 import org.eclipse.ui.internal.IWorkbenchHelpContextIds; 90 import org.eclipse.ui.internal.Perspective; 91 import org.eclipse.ui.internal.PluginActionContributionItem; 92 import org.eclipse.ui.internal.PluginActionCoolBarContributionItem; 93 import org.eclipse.ui.internal.PluginActionSet; 94 import org.eclipse.ui.internal.PluginActionSetBuilder; 95 import org.eclipse.ui.internal.WorkbenchMessages; 96 import org.eclipse.ui.internal.WorkbenchPage; 97 import org.eclipse.ui.internal.WorkbenchPlugin; 98 import org.eclipse.ui.internal.WorkbenchWindow; 99 import org.eclipse.ui.internal.intro.IIntroConstants; 100 import org.eclipse.ui.internal.provisional.application.IActionBarConfigurer2; 101 import org.eclipse.ui.internal.registry.ActionSetDescriptor; 102 import org.eclipse.ui.internal.registry.ActionSetRegistry; 103 import org.eclipse.ui.internal.registry.IActionSetDescriptor; 104 import org.eclipse.ui.internal.util.BundleUtility; 105 import org.eclipse.ui.model.WorkbenchLabelProvider; 106 import org.eclipse.ui.model.WorkbenchViewerComparator; 107 import org.eclipse.ui.services.IServiceLocator; 108 import org.eclipse.ui.views.IViewCategory; 109 import org.eclipse.ui.views.IViewDescriptor; 110 import org.eclipse.ui.views.IViewRegistry; 111 import org.eclipse.ui.wizards.IWizardCategory; 112 113 119 public class CustomizePerspectiveDialog extends TrayDialog { 121 private DefaultToolTip actionSetMenuViewerTooltip; 122 123 private DefaultToolTip actionSetToolbarViewerTooltip; 124 125 private DefaultToolTip actionSetsViewerTooltip; 126 127 private Perspective perspective; 128 129 WorkbenchWindow window; 130 131 private TabFolder tabFolder; 132 133 private CheckboxTableViewer actionSetsViewer; 134 135 private TreeViewer actionSetMenuViewer; 136 137 private TreeViewer actionSetToolbarViewer; 138 139 private Combo menusCombo; 140 141 private CheckboxTreeViewer menuCategoriesViewer; 142 143 private CheckboxTableViewer menuItemsViewer; 144 145 private static int lastSelectedTab = -1; 146 147 private static int lastSelectedMenuIndex = 0; 148 149 private static String lastSelectedActionSetId = null; 150 151 private final static int TAB_WIDTH_IN_DLUS = 490; 152 153 private final static int TAB_HEIGHT_IN_DLUS = 230; 154 155 private final String shortcutMenuColumnHeaders[] = { 156 WorkbenchMessages.ActionSetSelection_menuColumnHeader, 157 WorkbenchMessages.ActionSetSelection_descriptionColumnHeader }; 158 159 private int[] shortcutMenuColumnWidths = { 125, 300 }; 160 161 private ActionSetDescriptor selectedActionSet = null; 162 163 private ShortcutMenu selectedMenuCategory = null; 164 165 ImageDescriptor menuImageDescriptor = null; 166 167 ImageDescriptor submenuImageDescriptor = null; 168 169 ImageDescriptor toolbarImageDescriptor = null; 170 171 ShortcutMenu rootMenu; 172 173 private ArrayList actionSets = new ArrayList (); 174 175 private Hashtable actionSetStructures = new Hashtable (); 176 177 private IWorkbenchWindowConfigurer configurer; 178 179 private List initiallyActive = new ArrayList (); 180 181 class ActionSetDisplayItem extends Object { 182 185 ArrayList children = new ArrayList (); 186 187 ActionSetDisplayItem parent = null; 188 189 private String id = null; 190 191 private String text = ""; 193 String description = ""; 195 ImageDescriptor imageDescriptor; 196 197 int type = MENUITEM; 198 199 private final static int MENUITEM = 0; 200 201 private final static int TOOLITEM = 1; 202 203 ActionSetDisplayItem(String id) { 204 this(null, id, "", MENUITEM); } 206 207 private ActionSetDisplayItem(ActionSetDisplayItem parent, String id, 208 String text, int type) { 209 if (parent != null) { 210 parent.children.add(this); 211 this.parent = parent; 212 } 213 this.id = id; 214 this.type = type; 215 this.text = removeShortcut(text); 216 this.text = DialogUtil.removeAccel(this.text); 217 } 218 219 private ActionSetDisplayItem find(String itemId) { 220 for (int i = 0; i < children.size(); i++) { 221 ActionSetDisplayItem child = (ActionSetDisplayItem) children 222 .get(i); 223 if (itemId.equals(child.id)) { 224 return child; 225 } 226 } 227 return null; 228 } 229 230 234 public void fillMenusFor(String actionSetId, IContributionItem item) { 235 if (item instanceof ContributionManager) { 236 ContributionManager mgr = (ContributionManager) item; 237 IContributionItem[] items = mgr.getItems(); 238 for (int i = 0; i < items.length; i++) { 239 IContributionItem mgrItem = items[i]; 240 if (mgrItem instanceof ActionSetContributionItem) { 241 ActionSetContributionItem actionSetItem = (ActionSetContributionItem) mgrItem; 242 if (actionSetItem.getActionSetId().equals(actionSetId)) { 243 IContributionItem innerItem = actionSetItem 244 .getInnerItem(); 245 if (innerItem instanceof MenuManager) { 246 MenuManager inner = (MenuManager) actionSetItem 247 .getInnerItem(); 248 ActionSetDisplayItem node = new ActionSetDisplayItem( 249 this, inner.getId(), inner 250 .getMenuText(), MENUITEM); 251 node.fillMenusFor(actionSetId, inner); 252 } else if (innerItem instanceof ActionSetMenuManager) { 253 ActionSetMenuManager inner = (ActionSetMenuManager) actionSetItem 254 .getInnerItem(); 255 MenuManager parentMgr = (MenuManager) inner 256 .getParent(); 257 ActionSetDisplayItem node = new ActionSetDisplayItem( 258 this, inner.getId(), parentMgr 259 .getMenuText(), MENUITEM); 260 node.fillMenusFor(actionSetId, parentMgr); 261 } else if (innerItem instanceof PluginActionContributionItem) { 262 PluginActionContributionItem inner = (PluginActionContributionItem) actionSetItem 263 .getInnerItem(); 264 ActionSetDisplayItem node = new ActionSetDisplayItem( 265 this, inner.getId(), inner.getAction() 266 .getText(), MENUITEM); 267 IAction action = inner.getAction(); 268 if (action != null) { 269 node.imageDescriptor = action 270 .getImageDescriptor(); 271 node.description = action.getDescription(); 272 } 273 } 274 } 275 } else if (mgrItem instanceof MenuManager) { 276 MenuManager menuMgr = (MenuManager) mgrItem; 277 boolean found = containsActionSet(menuMgr, actionSetId); 278 if (found) { 279 ActionSetDisplayItem node = new ActionSetDisplayItem( 280 this, menuMgr.getId(), menuMgr 281 .getMenuText(), MENUITEM); 282 node.fillMenusFor(actionSetId, menuMgr); 283 } 284 } 285 } 286 } 287 } 288 289 293 public void fillToolsFor(String actionSetId, CoolBarManager mgr) { 294 IContributionItem[] items = mgr.getItems(); 295 for (int i = 0; i < items.length; i++) { 296 if (items[i] instanceof IToolBarContributionItem) { 297 IToolBarContributionItem cbItem = (IToolBarContributionItem) items[i]; 298 IContributionItem[] subItems = cbItem.getToolBarManager() 299 .getItems(); 300 for (int j = 0; j < subItems.length; j++) { 301 IContributionItem subItem = subItems[j]; 302 if (subItem instanceof PluginActionCoolBarContributionItem) { 303 PluginActionCoolBarContributionItem actionItem = (PluginActionCoolBarContributionItem) subItem; 304 if (actionItem.getActionSetId().equals(actionSetId)) { 305 String toolbarId = cbItem.getId(); 306 ActionSetDisplayItem toolbar = find(toolbarId); 307 if (toolbar == null) { 308 String toolbarText = window 309 .getToolbarLabel(toolbarId); 310 toolbar = new ActionSetDisplayItem(this, 311 toolbarId, toolbarText, TOOLITEM); 312 } 313 IAction action = actionItem.getAction(); 314 String toolItemText = action.getToolTipText(); 315 if (toolItemText == null) { 316 toolItemText = action.getText(); 317 } 318 ActionSetDisplayItem toolItem = new ActionSetDisplayItem( 319 toolbar, action.getId(), toolItemText, 320 TOOLITEM); 321 toolItem.imageDescriptor = action 322 .getImageDescriptor(); 323 toolItem.description = action.getDescription(); 324 } 325 } 326 } 327 } 328 } 329 } 330 331 int getDepth() { 332 if (parent == null) { 333 return 0; 334 } 335 return parent.getDepth() + 1; 336 } 337 338 String getDisplayText() { 339 if (type == MENUITEM) { 340 if (children.size() > 0) { 341 if (parent.id.equals("Root")) { return NLS.bind(WorkbenchMessages.ActionSetSelection_menubarLocation, text ); 343 } 344 } 345 return text; 346 } 347 if (children.size() > 0) { 348 return NLS.bind(WorkbenchMessages.ActionSetSelection_toolbarLocation, text ); 349 } 350 351 return text; 352 } 353 354 protected boolean isTopLevelMenu() { 355 if (parent == null) { 356 return false; 357 } 358 return parent.parent == null; 359 } 360 361 public String toString() { 362 StringBuffer sb = new StringBuffer (); 363 for (int i = getDepth(); --i >= 0;) { 364 sb.append(" "); } 366 sb.append("id: "); sb.append(id); 368 sb.append(" text: "); sb.append(text); 370 sb.append('\n'); 371 for (int i = 0; i < children.size(); ++i) { 372 sb.append(children.get(i)); 373 } 374 return sb.toString(); 375 376 } 377 } 378 379 385 public class CustomizeActionBars implements IActionBarConfigurer2, 386 IActionBars2 { 387 388 IWorkbenchWindowConfigurer configurer; 389 390 395 MenuManager menuManager = new MenuManager(); 396 CoolBarManager coolBarManager = new CoolBarManager(); 397 StatusLineManager statusLineManager = new StatusLineManager(); 398 399 404 public CustomizeActionBars(IWorkbenchWindowConfigurer configurer) { 405 this.configurer = configurer; 406 } 407 408 409 412 public IWorkbenchWindowConfigurer getWindowConfigurer() { 413 return configurer; 414 } 415 416 420 public IMenuManager getMenuManager() { 421 return menuManager; 422 } 423 424 428 public IStatusLineManager getStatusLineManager() { 429 return statusLineManager; 430 } 431 432 435 public ICoolBarManager getCoolBarManager() { 436 return coolBarManager; 437 } 438 439 442 public IToolBarManager getToolBarManager() { 443 return null; 444 } 445 446 public void setGlobalActionHandler(String actionID, IAction handler) { 447 } 448 449 public void updateActionBars() { 450 } 451 452 455 public void clearGlobalActionHandlers() { 456 } 457 458 461 public IAction getGlobalActionHandler(String actionId) { 462 return null; 463 } 464 465 468 public void registerGlobalAction(IAction action) { 469 } 470 471 474 public void dispose() { 475 coolBarManager.dispose(); 476 menuManager.dispose(); 477 statusLineManager.dispose(); 478 } 479 480 public final IServiceLocator getServiceLocator() { 481 return configurer.getWindow(); 482 } 483 484 487 public IToolBarContributionItem createToolBarContributionItem(IToolBarManager toolBarManager, String id) { 488 return new ToolBarContributionItem2(toolBarManager, id); 489 } 490 491 494 public IToolBarManager createToolBarManager() { 495 return new ToolBarManager(); 496 } 497 } 498 499 class ShortcutMenuItemContentProvider implements IStructuredContentProvider { 500 501 ShortcutMenuItemContentProvider() { 502 } 503 504 public Object [] getElements(Object input) { 505 if (input instanceof ShortcutMenu) { 506 return ((ShortcutMenu) input).getItems().toArray(); 507 } 508 return new Object [0]; 509 } 510 511 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 512 } 513 514 public void dispose() { 515 } 516 } 517 518 class ShortcutMenuItemLabelProvider extends LabelProvider implements 519 ITableLabelProvider { 520 private Map imageTable = new Hashtable (); 521 522 private final static int COLUMN_ID = 0; 523 524 private final static int COLUMN_DESCRIPTION = 1; 525 526 ShortcutMenuItemLabelProvider() { 527 } 528 529 public final void dispose() { 530 for (Iterator i = imageTable.values().iterator(); i.hasNext();) { 531 ((Image) i.next()).dispose(); 532 } 533 imageTable = null; 534 } 535 536 public Image getColumnImage(Object element, int index) { 537 if (index != COLUMN_ID) { 538 return null; 539 } 540 ImageDescriptor descriptor = null; 541 if (element instanceof IPerspectiveDescriptor) { 542 descriptor = ((IPerspectiveDescriptor) element) 543 .getImageDescriptor(); 544 } else if (element instanceof IViewDescriptor) { 545 descriptor = ((IViewDescriptor) element).getImageDescriptor(); 546 } else if (element instanceof WorkbenchWizardElement) { 547 descriptor = ((WorkbenchWizardElement) element) 548 .getImageDescriptor(); 549 } 550 if (descriptor == null) { 551 return null; 552 } 553 if (imageTable == null) { 555 imageTable = new Hashtable (40); 556 } 557 Image image = (Image) imageTable.get(descriptor); 558 if (image == null) { 559 image = descriptor.createImage(); 560 imageTable.put(descriptor, image); 561 } 562 return image; 563 } 564 565 public String getColumnText(Object element, int columnIndex) { 566 String text = null; 567 switch (columnIndex) { 568 case COLUMN_ID: 569 text = getText(element); 570 break; 571 case COLUMN_DESCRIPTION: 572 if (element instanceof IPerspectiveDescriptor) { 573 text = ((IPerspectiveDescriptor) element).getDescription(); 574 } else if (element instanceof IViewDescriptor) { 575 text = ((IViewDescriptor) element).getDescription(); 576 } else if (element instanceof WorkbenchWizardElement) { 577 text = ((WorkbenchWizardElement) element).getDescription(); 578 } 579 break; 580 } 581 if (text == null) { 582 text = ""; } 584 return text; 585 } 586 587 public String getText(Object element) { 588 String text = null; 589 if (element instanceof IPerspectiveDescriptor) { 590 text = ((IPerspectiveDescriptor) element).getLabel(); 591 } else if (element instanceof IViewDescriptor) { 592 text = ((IViewDescriptor) element).getLabel(); 593 } else if (element instanceof WorkbenchWizardElement) { 594 text = ((WorkbenchWizardElement) element).getLabel(element); 595 } 596 if (text == null) { 597 text = ""; } 599 return text; 600 } 601 } 602 603 class ShortcutMenu extends Object { 604 607 private final static String ID_VIEW = "org.eclipse.ui.views"; 609 private final static String ID_WIZARD = "org.eclipse.ui.wizards"; 611 private final static String ID_PERSP = "org.eclipse.ui.perspectives"; 613 String id; 614 615 String label; 616 617 private ArrayList items = new ArrayList (); 618 619 private ArrayList checkedItems = new ArrayList (); 620 621 ArrayList children = new ArrayList (); 622 623 ShortcutMenu parent = null; 624 625 ShortcutMenu(ShortcutMenu parent, String id, String label) { 626 super(); 627 this.id = id; 628 this.parent = parent; 629 this.label = removeShortcut(label); 630 this.label = DialogUtil.removeAccel(this.label); 631 if (parent != null) { 632 parent.children.add(this); 633 } 634 } 635 636 void addItem(Object item) { 637 items.add(item); 638 } 639 640 void addCheckedItem(Object item) { 641 checkedItems.add(item); 642 } 643 644 public String toString() { 645 return label; 646 } 647 648 ArrayList getCheckedItems() { 649 return checkedItems; 650 } 651 652 ArrayList getCheckedItemIds() { 653 ArrayList ids = new ArrayList (); 654 if (getMenuId() == ID_PERSP) { 655 for (int i = 0; i < checkedItems.size(); i++) { 656 IPerspectiveDescriptor item = (IPerspectiveDescriptor) checkedItems 657 .get(i); 658 ids.add(item.getId()); 659 } 660 } else if (getMenuId() == ID_VIEW) { 661 for (int i = 0; i < checkedItems.size(); i++) { 662 IViewDescriptor item = (IViewDescriptor) checkedItems 663 .get(i); 664 ids.add(item.getId()); 665 } 666 } else if (getMenuId() == ID_WIZARD) { 667 for (int i = 0; i < checkedItems.size(); i++) { 668 WorkbenchWizardElement item = (WorkbenchWizardElement) checkedItems 669 .get(i); 670 ids.add(item.getId()); 671 } 672 } 673 for (int i = 0; i < children.size(); i++) { 674 ShortcutMenu menu = (ShortcutMenu) children.get(i); 675 ids.addAll(menu.getCheckedItemIds()); 676 } 677 return ids; 678 } 679 680 ArrayList getChildren() { 681 return children; 682 } 683 684 ArrayList getItems() { 685 return items; 686 } 687 688 private String getMenuId() { 689 if (parent == rootMenu) { 690 return id; 691 } 692 693 return parent.getMenuId(); 694 } 695 696 ArrayList getSubtreeItems() { 697 ArrayList subtreeItems = new ArrayList (); 698 subtreeItems.add(this); 699 for (int i = 0; i < children.size(); i++) { 700 ShortcutMenu child = (ShortcutMenu) children.get(i); 701 subtreeItems.addAll(child.getSubtreeItems()); 702 } 703 return subtreeItems; 704 } 705 706 Object getItem(String menuItemId) { 707 for (int i = 0; i < items.size(); i++) { 708 Object item = items.get(i); 709 String itemId = null; 710 if (id == ID_PERSP) { 711 itemId = ((IPerspectiveDescriptor) item).getId(); 712 } else if (id == ID_VIEW) { 713 itemId = ((IViewDescriptor) item).getId(); 714 } else if (id == ID_WIZARD) { 715 itemId = ((WorkbenchWizardElement) item).getId(); 716 } 717 if (menuItemId.equals(itemId)) { 718 return item; 719 } 720 } 721 return null; 722 } 723 724 boolean isFullyChecked() { 725 if (getItems().size() != getCheckedItems().size()) { 726 return false; 727 } 728 for (int i = 0; i < children.size(); i++) { 729 ShortcutMenu child = (ShortcutMenu) children.get(i); 730 if (!child.isFullyChecked()) { 731 return false; 732 } 733 } 734 return true; 735 } 736 737 boolean isFullyUnchecked() { 738 if (getCheckedItems().size() != 0) { 739 return false; 740 } 741 for (int i = 0; i < children.size(); i++) { 742 ShortcutMenu child = (ShortcutMenu) children.get(i); 743 if (!child.isFullyUnchecked()) { 744 return false; 745 } 746 } 747 return true; 748 } 749 750 void removeCheckedItem(Object item) { 751 checkedItems.remove(item); 752 } 753 754 void checked(boolean checked) { 755 checkedItems = new ArrayList (); 756 if (checked) { 757 checkedItems.addAll(items); 758 } 759 for (int i = 0; i < children.size(); i++) { 760 ShortcutMenu child = (ShortcutMenu) children.get(i); 761 child.checked(checked); 762 } 763 } 764 } 765 766 class TreeContentProvider implements ITreeContentProvider { 767 public void dispose() { 768 } 769 770 public Object [] getChildren(Object element) { 771 if (element instanceof ActionSetDisplayItem) { 772 ActionSetDisplayItem node = (ActionSetDisplayItem) element; 773 return node.children.toArray(); 774 } else if (element instanceof ShortcutMenu) { 775 ShortcutMenu node = (ShortcutMenu) element; 776 return node.children.toArray(); 777 } else if (element instanceof ArrayList ) { 778 return ((ArrayList ) element).toArray(); 779 } 780 return new Object [0]; 781 } 782 783 public Object [] getElements(Object element) { 784 return getChildren(element); 785 } 786 787 public Object getParent(Object element) { 788 if (element instanceof ActionSetDisplayItem) { 789 ActionSetDisplayItem node = (ActionSetDisplayItem) element; 790 return node.parent; 791 } else if (element instanceof ShortcutMenu) { 792 ShortcutMenu node = (ShortcutMenu) element; 793 return node.parent; 794 } 795 return null; 796 } 797 798 public boolean hasChildren(Object element) { 799 if (element instanceof ActionSetDisplayItem) { 800 ActionSetDisplayItem node = (ActionSetDisplayItem) element; 801 return node.children.size() > 0; 802 } else if (element instanceof ShortcutMenu) { 803 ShortcutMenu node = (ShortcutMenu) element; 804 return node.children.size() > 0; 805 } 806 return false; 807 } 808 809 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 810 } 811 } 812 813 class ActionSetLabelProvider extends LabelProvider { 814 private Map imageTable = new Hashtable (); 815 816 public void dispose() { 817 for (Iterator i = imageTable.values().iterator(); i.hasNext();) { 818 ((Image) i.next()).dispose(); 819 } 820 imageTable = null; 821 } 822 823 public Image getImage(Object element) { 824 ActionSetDisplayItem item = (ActionSetDisplayItem) element; 825 ImageDescriptor descriptor = item.imageDescriptor; 826 if (descriptor == null) { 827 if (item.type == ActionSetDisplayItem.MENUITEM) { 828 if (item.children.size() > 0) { 829 if (item.isTopLevelMenu()) { 830 descriptor = menuImageDescriptor; 831 } else { 832 descriptor = submenuImageDescriptor; 833 } 834 } else { 835 return null; 836 } 837 } else if (item.type == ActionSetDisplayItem.TOOLITEM) { 838 if (item.children.size() > 0) { 839 descriptor = toolbarImageDescriptor; 840 } else { 841 return null; 842 } 843 } else { 844 return null; 845 } 846 } 847 if (imageTable == null) { 849 imageTable = new Hashtable (40); 850 } 851 Image image = (Image) imageTable.get(descriptor); 852 if (image == null) { 853 image = descriptor.createImage(); 854 imageTable.put(descriptor, image); 855 } 856 return image; 857 } 858 859 public String getText(Object element) { 860 if (element instanceof ActionSetDisplayItem) { 861 ActionSetDisplayItem item = (ActionSetDisplayItem) element; 862 String text = item.getDisplayText(); 863 if ((item.type == ActionSetDisplayItem.MENUITEM) 864 && (item.children.size() > 0)) { 865 text = text + " >"; } 867 return text; 868 } 869 return ""; } 871 } 872 873 879 public CustomizePerspectiveDialog(IWorkbenchWindowConfigurer configurer, Perspective persp) { 880 super(configurer.getWindow().getShell()); 881 setShellStyle(SWT.MAX | SWT.RESIZE | getShellStyle()); 882 883 this.configurer = configurer; 884 perspective = persp; 885 window = (WorkbenchWindow) configurer.getWindow(); 886 887 initializeActionSetInput(); 888 initializeShortcutMenuInput(); 889 } 890 891 896 private void addActionSetsListeners() { 897 tabFolder.addSelectionListener(new SelectionAdapter() { 898 public void widgetSelected(SelectionEvent event) { 899 handleTabSelected(event); 900 } 901 }); 902 actionSetsViewer 903 .addSelectionChangedListener(new ISelectionChangedListener() { 904 public void selectionChanged(SelectionChangedEvent event) { 905 handleActionSetSelected(event); 906 } 907 }); 908 actionSetsViewer.getControl().addKeyListener(new KeyListener() { 909 public void keyPressed(KeyEvent e) { 910 handleActionSetViewerKeyPressed(e); 911 } 912 913 public void keyReleased(KeyEvent e) { 914 } 915 }); 916 actionSetMenuViewer.getControl().addKeyListener(new KeyListener() { 917 public void keyPressed(KeyEvent e) { 918 handleActionSetMenuViewerKeyPressed(e); 919 } 920 921 public void keyReleased(KeyEvent e) { 922 } 923 }); 924 actionSetToolbarViewer.getControl().addKeyListener(new KeyListener() { 925 public void keyPressed(KeyEvent e) { 926 handleActionSetToolbarViewerKeyPressed(e); 927 } 928 929 public void keyReleased(KeyEvent e) { 930 } 931 }); 932 } 933 934 939 private void addShortcutListeners() { 940 menusCombo.addSelectionListener(new SelectionListener() { 941 public void widgetDefaultSelected(SelectionEvent e) { 942 } 944 945 public void widgetSelected(SelectionEvent e) { 946 handleMenuSelected(); 947 } 948 }); 949 menusCombo.addModifyListener(new ModifyListener() { 950 public void modifyText(ModifyEvent e) { 951 handleMenuModified(); 952 } 953 }); 954 menuCategoriesViewer 955 .addSelectionChangedListener(new ISelectionChangedListener() { 956 public void selectionChanged(SelectionChangedEvent event) { 957 handleMenuCategorySelected(event); 958 } 959 }); 960 menuCategoriesViewer.addCheckStateListener(new ICheckStateListener() { 961 public void checkStateChanged(CheckStateChangedEvent event) { 962 handleMenuCategoryChecked(event); 963 } 964 }); 965 menuItemsViewer.addCheckStateListener(new ICheckStateListener() { 966 public void checkStateChanged(CheckStateChangedEvent event) { 967 handleMenuItemChecked(event); 968 } 969 }); 970 } 971 972 private void buildMenusAndToolbarsFor(CustomizeActionBars customizeActionBars, ActionSetDescriptor actionSetDesc) { 973 String id = actionSetDesc.getId(); 974 ActionSetActionBars bars = new ActionSetActionBars( 975 customizeActionBars, window, customizeActionBars, id); 976 PluginActionSetBuilder builder = new PluginActionSetBuilder(); 977 PluginActionSet actionSet = null; 978 try { 979 actionSet = (PluginActionSet) actionSetDesc.createActionSet(); 980 actionSet.init(null, bars); 981 } catch (CoreException ex) { 982 WorkbenchPlugin 983 .log("Unable to create action set " + actionSetDesc.getId(), ex); return; 985 } 986 builder.buildMenuAndToolBarStructure(actionSet, window); 987 } 988 989 private void checkInitialActionSetSelections() { 990 IActionSetDescriptor[] actionSetDescriptors = ((WorkbenchPage)window.getActivePage()).getActionSets(); 992 initiallyActive = Arrays.asList(actionSetDescriptors); 993 if (actionSets != null) { 994 for (int i = 0; i < actionSetDescriptors.length; i++) { 995 actionSetsViewer.setChecked(actionSetDescriptors[i], true); 996 } 997 } 998 } 999 1000 private void checkInitialMenuCategorySelections(ShortcutMenu menu) { 1001 if (menu.children.size() == 0) { 1003 updateMenuCategoryCheckedState(menu); 1004 } else { 1005 for (int i = 0; i < menu.children.size(); i++) { 1006 ShortcutMenu child = (ShortcutMenu) menu.children.get(i); 1007 checkInitialMenuCategorySelections(child); 1008 } 1009 } 1010 } 1011 1012 public boolean close() { 1013 if (showShortcutTab()) { 1014 lastSelectedMenuIndex = menusCombo.getSelectionIndex(); 1015 } 1016 lastSelectedTab = tabFolder.getSelectionIndex(); 1017 IStructuredSelection selection = (IStructuredSelection) actionSetsViewer 1018 .getSelection(); 1019 if (selection.isEmpty()) { 1020 lastSelectedActionSetId = null; 1021 } else { 1022 lastSelectedActionSetId = ((ActionSetDescriptor) selection 1023 .getFirstElement()).getId(); 1024 } 1025 return super.close(); 1026 } 1027 1028 protected void configureShell(Shell shell) { 1029 super.configureShell(shell); 1030 String title=perspective.getDesc().getLabel(); 1031 1032 title = NLS.bind(WorkbenchMessages.ActionSetSelection_customize,title); 1033 shell.setText(title); 1034 window.getWorkbench().getHelpSystem().setHelp(shell, 1035 IWorkbenchHelpContextIds.ACTION_SET_SELECTION_DIALOG); 1036 } 1037 1038 boolean containsActionSet(MenuManager mgr, String actionSetId) { 1039 IContributionItem[] menuItems = mgr.getItems(); 1042 for (int j = 0; j < menuItems.length; j++) { 1043 IContributionItem menuItem = menuItems[j]; 1044 if (menuItem instanceof ActionSetContributionItem) { 1045 ActionSetContributionItem actionSetItem = (ActionSetContributionItem) menuItem; 1046 if (actionSetItem.getActionSetId().equals(actionSetId)) { 1047 return true; 1048 } 1049 } else if (menuItem instanceof MenuManager) { 1050 MenuManager childMgr = (MenuManager) menuItem; 1051 boolean found = containsActionSet(childMgr, actionSetId); 1052 if (found) { 1053 return true; 1054 } 1055 } 1056 } 1057 return false; 1058 } 1059 1060 private Composite createActionSetsPage(Composite parent) { 1061 GridData data; 1062 1063 Composite actionSetsComposite = new Composite(parent, SWT.NONE); 1064 GridLayout layout = new GridLayout(); 1065 actionSetsComposite.setLayout(layout); 1066 1067 Label label = new Label(actionSetsComposite, SWT.WRAP); 1069 label 1070 .setText(NLS.bind(WorkbenchMessages.ActionSetSelection_selectActionSetsLabel,perspective.getDesc().getLabel() )); 1071 data = new GridData(SWT.FILL, SWT.CENTER, true, false); 1072 label.setLayoutData(data); 1073 1074 Label sep = new Label(actionSetsComposite, SWT.HORIZONTAL 1075 | SWT.SEPARATOR); 1076 sep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); 1077 1078 SashForm sashComposite = new SashForm(actionSetsComposite, 1079 SWT.HORIZONTAL); 1080 data = new GridData(SWT.FILL, SWT.FILL, true, true); 1081 sashComposite.setLayoutData(data); 1082 1083 Composite actionSetGroup = new Composite(sashComposite, SWT.NONE); 1085 layout = new GridLayout(); 1086 layout.marginHeight = 0; 1087 layout.marginWidth = 0; 1088 actionSetGroup.setLayout(layout); 1089 actionSetGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 1090 1091 label = new Label(actionSetGroup, SWT.WRAP); 1092 label.setText(WorkbenchMessages.ActionSetSelection_availableActionSets); 1093 label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); 1094 1095 actionSetsViewer = CheckboxTableViewer.newCheckList(actionSetGroup, 1096 SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); 1097 actionSetsViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 1098 actionSetsViewer.setLabelProvider(new WorkbenchLabelProvider()); 1099 actionSetsViewer.setContentProvider(new ArrayContentProvider()); 1100 actionSetsViewer.setComparator(new ActionSetComparator()); 1101 actionSetsViewerTooltip = new DefaultToolTip(actionSetsViewer.getControl(),ToolTip.RECREATE,true){ 1102 1103 public Point getLocation(Point tipSize, Event event) { 1104 return getShell().getDisplay().getCursorLocation(); 1105 } 1106 1107 }; 1108 1109 Composite actionGroup = new Composite(sashComposite, SWT.NONE); 1111 layout = new GridLayout(); 1112 layout.numColumns = 2; 1113 layout.makeColumnsEqualWidth = true; 1114 layout.marginHeight = 0; 1115 layout.marginWidth = 0; 1116 layout.horizontalSpacing = 0; 1117 actionGroup.setLayout(layout); 1118 actionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 1119 1120 Composite menubarGroup = new Composite(actionGroup, SWT.NONE); 1121 layout = new GridLayout(); 1122 layout.marginHeight = 0; 1123 layout.marginWidth = 0; 1124 menubarGroup.setLayout(layout); 1125 menubarGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 1126 1127 label = new Label(menubarGroup, SWT.WRAP); 1128 label.setText(WorkbenchMessages.ActionSetSelection_menubarActions); 1129 label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); 1130 1131 actionSetMenuViewer = new TreeViewer(menubarGroup); 1132 actionSetMenuViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); 1133 actionSetMenuViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 1134 actionSetMenuViewer.setLabelProvider(new ActionSetLabelProvider()); 1135 actionSetMenuViewer.setContentProvider(new TreeContentProvider()); 1136 actionSetMenuViewerTooltip = new DefaultToolTip(actionSetMenuViewer.getControl(),ToolTip.RECREATE, true) { 1137 1138 public Point getLocation(Point tipSize, Event event) { 1139 return getShell().getDisplay().getCursorLocation(); 1140 } 1141 1142 }; 1143 1144 Composite toolbarGroup = new Composite(actionGroup, SWT.NONE); 1145 layout = new GridLayout(); 1146 layout.marginHeight = 0; 1147 layout.marginWidth = 0; 1148 toolbarGroup.setLayout(layout); 1149 toolbarGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 1150 1151 label = new Label(toolbarGroup, SWT.WRAP); 1152 label.setText(WorkbenchMessages.ActionSetSelection_toolbarActions); 1153 label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); 1154 1155 actionSetToolbarViewer = new TreeViewer(toolbarGroup); 1156 actionSetToolbarViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); 1157 actionSetToolbarViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 1158 actionSetToolbarViewer 1159 .setLabelProvider(new ActionSetLabelProvider()); 1160 actionSetToolbarViewer.setContentProvider(new TreeContentProvider()); 1161 actionSetToolbarViewerTooltip = new DefaultToolTip(actionSetToolbarViewer.getControl(),ToolTip.RECREATE,true){ 1162 1163 public Point getLocation(Point tipSize, Event event) { 1164 return getShell().getDisplay().getCursorLocation(); 1165 } 1166 1167 }; 1168 1169 sashComposite.setWeights(new int[] { 30, 70 }); 1170 1171 label = new Label(actionSetsComposite, SWT.WRAP); 1173 label.setText(WorkbenchMessages.ActionSetSelection_selectActionSetsHelp); 1174 label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); 1175 1176 return actionSetsComposite; 1177 } 1178 1179 1186 private boolean showShortcutTab() { 1187 return window.containsSubmenu(WorkbenchWindow.NEW_WIZARD_SUBMENU) 1188 || window 1189 .containsSubmenu(WorkbenchWindow.OPEN_PERSPECTIVE_SUBMENU) 1190 || window.containsSubmenu(WorkbenchWindow.SHOW_VIEW_SUBMENU); 1191 } 1192 1193 protected Control createDialogArea(Composite parent) { 1194 Composite composite = (Composite) super.createDialogArea(parent); 1195 1196 tabFolder = new TabFolder(composite, SWT.NONE); 1198 1199 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); 1200 gd.widthHint = convertHorizontalDLUsToPixels(TAB_WIDTH_IN_DLUS); 1201 gd.heightHint = convertVerticalDLUsToPixels(TAB_HEIGHT_IN_DLUS); 1202 tabFolder.setLayoutData(gd); 1203 1204 if (showShortcutTab()) { 1206 TabItem item1 = new TabItem(tabFolder, SWT.NONE); 1207 item1.setText(WorkbenchMessages.ActionSetSelection_menuTab); 1208 item1.setControl(createMenusPage(tabFolder)); 1209 addShortcutListeners(); 1210 ArrayList children = rootMenu.getChildren(); 1211 String [] itemNames = new String [children.size()]; 1212 for (int i = 0; i < children.size(); i++) { 1213 itemNames[i] = ((ShortcutMenu) children.get(i)).label; 1214 } 1215 menusCombo.setItems(itemNames); 1216 } 1217 1218 TabItem item = new TabItem(tabFolder, SWT.NONE); 1220 item.setText(WorkbenchMessages.ActionSetSelection_actionSetsTab); 1221 item.setControl(createActionSetsPage(tabFolder)); 1222 applyDialogFont(tabFolder); 1223 addActionSetsListeners(); 1224 actionSetsViewer.setInput(actionSets); 1225 checkInitialActionSetSelections(); 1226 1227 setInitialSelections(); 1229 1230 return composite; 1231 } 1232 1233 private Composite createMenusPage(Composite parent) { 1234 GridData data; 1235 1236 Composite menusComposite = new Composite(parent, SWT.NONE); 1237 GridLayout layout = new GridLayout(); 1238 menusComposite.setLayout(layout); 1239 1240 Label label = new Label(menusComposite, SWT.WRAP); 1242 label.setText(NLS.bind(WorkbenchMessages.ActionSetSelection_selectMenusLabel, perspective.getDesc().getLabel() )); 1243 data = new GridData(SWT.FILL, SWT.CENTER, true, false); 1244 label.setLayoutData(data); 1245 1246 Label sep = new Label(menusComposite, SWT.HORIZONTAL | SWT.SEPARATOR); 1247 sep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); 1248 1249 SashForm sashComposite = new SashForm(menusComposite, SWT.HORIZONTAL); 1250 data = new GridData(SWT.FILL, SWT.FILL, true, true); 1251 sashComposite.setLayoutData(data); 1252 1253 Composite menusGroup = new Composite(sashComposite, SWT.NONE); 1255 layout = new GridLayout(); 1256 layout.marginHeight = 0; 1257 layout.marginWidth = 0; 1258 menusGroup.setLayout(layout); 1259 menusGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 1260 1261 label = new Label(menusGroup, SWT.WRAP); 1262 label.setText(WorkbenchMessages.ActionSetSelection_availableMenus); 1263 label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); 1264 1265 menusCombo = new Combo(menusGroup, SWT.READ_ONLY); 1266 menusCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); 1267 1268 label = new Label(menusGroup, SWT.WRAP); 1270 label.setText(WorkbenchMessages.ActionSetSelection_availableCategories); 1271 label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); 1272 1273 menuCategoriesViewer = new CheckboxTreeViewer(menusGroup); 1274 menuCategoriesViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 1275 menuCategoriesViewer.setLabelProvider(new LabelProvider()); 1276 menuCategoriesViewer.setContentProvider(new TreeContentProvider()); 1277 menuCategoriesViewer.setComparator(new WorkbenchViewerComparator()); 1278 1279 Composite menuItemsGroup = new Composite(sashComposite, SWT.NONE); 1281 layout = new GridLayout(); 1282 layout.marginHeight = 0; 1283 layout.marginWidth = 0; 1284 menuItemsGroup.setLayout(layout); 1285 menuItemsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 1286 1287 label = new Label(menuItemsGroup, SWT.WRAP); 1288 label.setText(WorkbenchMessages.ActionSetSelection_menuItems); 1289 label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); 1290 1291 menuItemsViewer = CheckboxTableViewer.newCheckList(menuItemsGroup, 1292 SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); 1293 Table menuTable = menuItemsViewer.getTable(); 1294 menuTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 1295 menuItemsViewer.setLabelProvider(new ShortcutMenuItemLabelProvider()); 1296 menuItemsViewer 1297 .setContentProvider(new ShortcutMenuItemContentProvider()); 1298 menuItemsViewer.setComparator(new WorkbenchViewerComparator()); 1299 1300 menuTable.setHeaderVisible(true); 1301 int[] columnWidths = new int[shortcutMenuColumnWidths.length]; 1302 for (int i = 0; i < shortcutMenuColumnWidths.length; i++) { 1303 columnWidths[i] = convertHorizontalDLUsToPixels(shortcutMenuColumnWidths[i]); 1304 } 1305 for (int i = 0; i < shortcutMenuColumnHeaders.length; i++) { 1306 TableColumn tc = new TableColumn(menuTable, SWT.NONE, i); 1307 tc.setResizable(true); 1308 tc.setText(shortcutMenuColumnHeaders[i]); 1309 tc.setWidth(columnWidths[i]); 1310 } 1311 sashComposite.setWeights(new int[] { 30, 70 }); 1312 return menusComposite; 1313 } 1314 1315 void handleActionSetMenuViewerKeyPressed(KeyEvent event) { 1316 if (event.keyCode == SWT.F2 && event.stateMask == 0) { 1318 IStructuredSelection sel = (IStructuredSelection) actionSetMenuViewer 1319 .getSelection(); 1320 ActionSetDisplayItem element = (ActionSetDisplayItem) sel 1321 .getFirstElement(); 1322 if (element != null) { 1323 String desc = element.description; 1324 if (desc == null || desc.equals("")) { desc = WorkbenchMessages.ActionSetSelection_noDesc; 1326 } 1327 actionSetMenuViewerTooltip.setText(desc); 1328 actionSetMenuViewerTooltip.show(new Point(0,0)); 1330 } 1331 } 1332 } 1333 1334 void handleActionSetSelected(SelectionChangedEvent event) { 1335 IStructuredSelection sel = (IStructuredSelection) event.getSelection(); 1336 ActionSetDescriptor element = (ActionSetDescriptor) sel 1337 .getFirstElement(); 1338 if (element == selectedActionSet) { 1339 return; 1340 } 1341 String actionSetId = element.getId(); 1342 ArrayList structures = (ArrayList ) actionSetStructures.get(actionSetId); 1344 ActionSetDisplayItem menubarStructure = null; 1345 ActionSetDisplayItem toolbarStructure = null; 1346 if (structures == null) { 1348 structures = new ArrayList (2); 1349 menubarStructure = new ActionSetDisplayItem("Menubar"); toolbarStructure = new ActionSetDisplayItem("Toolbar"); 1352 CustomizeActionBars customizeActionBars = new CustomizeActionBars(configurer); 1355 window.fillActionBars(customizeActionBars, 1357 ActionBarAdvisor.FILL_PROXY | ActionBarAdvisor.FILL_MENU_BAR 1358 | ActionBarAdvisor.FILL_COOL_BAR); 1359 buildMenusAndToolbarsFor(customizeActionBars, element); 1361 menubarStructure.fillMenusFor(actionSetId, 1363 customizeActionBars.menuManager); 1364 toolbarStructure.fillToolsFor(actionSetId, 1365 customizeActionBars.coolBarManager); 1366 customizeActionBars.dispose(); 1368 1369 structures.add(menubarStructure); 1371 structures.add(toolbarStructure); 1372 actionSetStructures.put(actionSetId, structures); 1374 } 1375 if (menubarStructure == null) { 1377 menubarStructure = (ActionSetDisplayItem) structures.get(0); 1378 } 1379 if (toolbarStructure == null) { 1380 toolbarStructure = (ActionSetDisplayItem) structures.get(1); 1381 } 1382 1383 actionSetMenuViewer.setInput(menubarStructure); 1385 if (menubarStructure.children.size() > 0) { 1386 actionSetMenuViewer 1387 .reveal(menubarStructure.children.get(0)); 1388 } 1389 1390 actionSetToolbarViewer.setInput(toolbarStructure); 1392 if (toolbarStructure.children.size() > 0) { 1393 actionSetToolbarViewer.reveal(toolbarStructure.children 1394 .get(0)); 1395 } 1396 selectedActionSet = element; 1397 } 1398 1399 void handleActionSetToolbarViewerKeyPressed(KeyEvent event) { 1400 if (event.keyCode == SWT.F2 && event.stateMask == 0) { 1402 IStructuredSelection sel = (IStructuredSelection) actionSetToolbarViewer 1403 .getSelection(); 1404 ActionSetDisplayItem element = (ActionSetDisplayItem) sel 1405 .getFirstElement(); 1406 if (element != null) { 1407 String desc = element.description; 1408 if (desc == null || desc.equals("")) { desc = WorkbenchMessages.ActionSetSelection_noDesc; 1410 } 1411 actionSetToolbarViewerTooltip.setText(desc); 1412 actionSetToolbarViewerTooltip.show(new Point(0,0)); 1414 } 1415 } 1416 } 1417 1418 void handleActionSetViewerKeyPressed(KeyEvent event) { 1419 if (event.keyCode == SWT.F2 && event.stateMask == 0) { 1421 IStructuredSelection sel = (IStructuredSelection) actionSetsViewer 1422 .getSelection(); 1423 ActionSetDescriptor element = (ActionSetDescriptor) sel 1424 .getFirstElement(); 1425 if (element != null) { 1426 String desc = element.getDescription(); 1427 if (desc == null || desc.equals("")) { desc = WorkbenchMessages.ActionSetSelection_noDesc; 1429 } 1430 actionSetsViewerTooltip.setText(desc); 1431 actionSetsViewerTooltip.show(new Point(0,0)); 1433 } 1434 } 1435 } 1436 1437 void handleMenuCategoryChecked(CheckStateChangedEvent event) { 1438 ShortcutMenu checkedCategory = (ShortcutMenu) event.getElement(); 1439 boolean checked = event.getChecked(); 1440 checkedCategory.checked(checked); 1441 menuCategoriesViewer.setSubtreeChecked(checkedCategory, checked); 1443 ArrayList subtree = checkedCategory.getSubtreeItems(); 1446 ShortcutMenu menuItemInput = (ShortcutMenu) menuItemsViewer.getInput(); 1447 for (int i = 0; i < subtree.size(); i++) { 1448 Object child = subtree.get(i); 1449 menuCategoriesViewer.setGrayed(child, false); 1450 if (child == menuItemInput) { 1451 menuItemsViewer.setAllChecked(checked); 1452 } 1453 } 1454 menuCategoriesViewer.setGrayed(checkedCategory, false); 1455 updateMenuCategoryCheckedState(checkedCategory.parent); 1456 } 1457 1458 void handleMenuCategorySelected(SelectionChangedEvent event) { 1459 IStructuredSelection sel = (IStructuredSelection) event.getSelection(); 1460 ShortcutMenu element = (ShortcutMenu) sel.getFirstElement(); 1461 if (element == selectedMenuCategory) { 1462 return; 1463 } 1464 if (element != menuItemsViewer.getInput()) { 1465 menuItemsViewer.setInput(element); 1466 } 1467 if (element != null) { 1468 menuItemsViewer.setCheckedElements(element.getCheckedItems() 1469 .toArray()); 1470 } 1471 } 1472 1473 void handleMenuItemChecked(CheckStateChangedEvent event) { 1474 ShortcutMenu selectedMenu = (ShortcutMenu) menuItemsViewer.getInput(); 1475 boolean itemChecked = event.getChecked(); 1476 Object item = event.getElement(); 1477 if (itemChecked) { 1478 selectedMenu.addCheckedItem(item); 1479 } else { 1480 selectedMenu.removeCheckedItem(item); 1481 } 1482 updateMenuCategoryCheckedState(selectedMenu); 1483 } 1484 1485 void handleMenuModified() { 1486 String text = menusCombo.getText(); 1487 String [] items = menusCombo.getItems(); 1488 int itemIndex = -1; 1489 for (int i = 0; i < items.length; i++) { 1490 if (items[i].equals(text)) { 1491 itemIndex = i; 1492 break; 1493 } 1494 } 1495 if (itemIndex == -1) { 1496 return; 1497 } 1498 ShortcutMenu element = (ShortcutMenu) rootMenu.children.get(itemIndex); 1499 handleMenuSelected(element); 1500 } 1501 1502 void handleMenuSelected() { 1503 int i = menusCombo.getSelectionIndex(); 1504 ShortcutMenu element = (ShortcutMenu) rootMenu.children.get(i); 1505 handleMenuSelected(element); 1506 } 1507 1508 void handleMenuSelected(ShortcutMenu element) { 1509 if (element != menuCategoriesViewer.getInput()) { 1510 menuCategoriesViewer.setInput(element); 1511 menuCategoriesViewer.expandAll(); 1512 if (element != null) { 1513 if (element.getChildren().size() > 0) { 1514 StructuredSelection sel = new StructuredSelection(element 1515 .getChildren().get(0)); 1516 menuCategoriesViewer.setSelection(sel, true); 1517 } else { 1518 menuItemsViewer.setInput(element); 1519 menuItemsViewer.setCheckedElements(element 1520 .getCheckedItems().toArray()); 1521 } 1522 } else { 1523 menuCategoriesViewer.setInput(element); 1524 menuItemsViewer.setInput(element); 1525 } 1526 checkInitialMenuCategorySelections(rootMenu); 1527 } 1528 } 1529 1530 void handleTabSelected(SelectionEvent event) { 1531 TabItem item = (TabItem) event.item; 1532 Control control = item.getControl(); 1533 if (control != null) { 1534 control.setFocus(); 1535 } 1536 } 1537 1538 private void initializeActionSetInput() { 1539 ActionSetRegistry reg = WorkbenchPlugin.getDefault() 1542 .getActionSetRegistry(); 1543 IActionSetDescriptor[] sets = reg.getActionSets(); 1544 for (int i = 0; i < sets.length; i++) { 1545 ActionSetDescriptor actionSetDesc = (ActionSetDescriptor) sets[i]; 1546 if (WorkbenchActivityHelper.filterItem(actionSetDesc)) { 1547 continue; 1548 } 1549 actionSets.add(actionSetDesc); 1550 } 1551 String iconPath = "$nl$/icons/full/obj16/menu.gif"; URL url = BundleUtility.find(PlatformUI.PLUGIN_ID, iconPath); 1553 menuImageDescriptor = ImageDescriptor.createFromURL(url); 1554 1555 iconPath = "$nl$/icons/full/obj16/submenu.gif"; url = BundleUtility.find(PlatformUI.PLUGIN_ID, iconPath); 1557 submenuImageDescriptor = ImageDescriptor.createFromURL(url); 1558 1559 iconPath = "$nl$/icons/full/obj16/toolbar.gif"; url = BundleUtility.find(PlatformUI.PLUGIN_ID, iconPath); 1561 toolbarImageDescriptor = ImageDescriptor.createFromURL(url); 1562 } 1563 1564 private void initializeShortCutMenu(ShortcutMenu menu, 1565 IWizardCategory element, List activeIds) { 1566 ShortcutMenu category = new ShortcutMenu(menu, element.getId(), element 1567 .getLabel()); 1568 Object [] wizards = element.getWizards(); 1569 for (int i = 0; i < wizards.length; i++) { 1570 WorkbenchWizardElement wizard = (WorkbenchWizardElement) wizards[i]; 1571 category.addItem(wizard); 1572 if (activeIds.contains(wizard.getId())) { 1573 category.addCheckedItem(wizard); 1574 } 1575 } 1576 IWizardCategory [] children = element.getCategories(); 1578 for (int i = 0; i < children.length; i++) { 1579 initializeShortCutMenu(category, children[i], activeIds); 1580 } 1581 } 1582 1583 private void initializeShortcutMenuInput() { 1584 rootMenu = new ShortcutMenu(null, "Root", ""); List activeIds; 1586 1587 if (window.containsSubmenu(WorkbenchWindow.NEW_WIZARD_SUBMENU)) { 1588 ShortcutMenu wizardMenu = new ShortcutMenu(rootMenu, 1589 ShortcutMenu.ID_WIZARD, WorkbenchMessages.ActionSetDialogInput_wizardCategory); 1590 1591 IWizardCategory wizardCollection = WorkbenchPlugin.getDefault().getNewWizardRegistry().getRootCategory(); 1592 1593 IWizardCategory [] wizardCategories = wizardCollection.getCategories(); 1594 activeIds = Arrays.asList(perspective.getNewWizardShortcuts()); 1595 for (int i = 0; i < wizardCategories.length; i++) { 1596 IWizardCategory element = wizardCategories[i]; 1597 if (WorkbenchActivityHelper.filterItem(element)) { 1598 continue; 1599 } 1600 initializeShortCutMenu(wizardMenu, element, activeIds); 1601 } 1602 } 1603 1604 if (window.containsSubmenu(WorkbenchWindow.OPEN_PERSPECTIVE_SUBMENU)) { 1605 ShortcutMenu perspMenu = new ShortcutMenu( 1606 rootMenu, 1607 ShortcutMenu.ID_PERSP, 1608 WorkbenchMessages.ActionSetDialogInput_perspectiveCategory); 1609 IPerspectiveRegistry perspReg = WorkbenchPlugin.getDefault() 1610 .getPerspectiveRegistry(); 1611 IPerspectiveDescriptor[] persps = perspReg.getPerspectives(); 1612 for (int i = 0; i < persps.length; i++) { 1613 if (WorkbenchActivityHelper.filterItem(persps[i])) { 1614 continue; 1615 } 1616 perspMenu.addItem(persps[i]); 1617 } 1618 activeIds = Arrays.asList(perspective.getPerspectiveShortcuts()); 1619 for (int i = 0; i < activeIds.size(); i++) { 1620 String id = (String ) activeIds.get(i); 1621 Object item = perspMenu.getItem(id); 1622 if (item != null) { 1623 perspMenu.addCheckedItem(item); 1624 } 1625 } 1626 } 1627 1628 if (window.containsSubmenu(WorkbenchWindow.SHOW_VIEW_SUBMENU)) { 1629 ShortcutMenu viewMenu = new ShortcutMenu(rootMenu, 1630 ShortcutMenu.ID_VIEW, WorkbenchMessages.ActionSetDialogInput_viewCategory); 1631 IViewRegistry viewReg = WorkbenchPlugin.getDefault() 1632 .getViewRegistry(); 1633 IViewCategory [] categories = viewReg.getCategories(); 1634 activeIds = Arrays.asList(perspective.getShowViewShortcuts()); 1635 for (int i = 0; i < categories.length; i++) { 1636 IViewCategory category = categories[i]; 1637 if (WorkbenchActivityHelper.filterItem(category)) { 1638 continue; 1639 } 1640 ShortcutMenu viewCategory = new ShortcutMenu(viewMenu, category 1641 .getId(), category.getLabel()); 1642 IViewDescriptor [] views = category.getViews(); 1643 if (views != null) { 1644 for (int j = 0; j < views.length; j++) { 1645 IViewDescriptor view = views[j]; 1646 if (view.getId().equals(IIntroConstants.INTRO_VIEW_ID)) { 1647 continue; 1648 } 1649 if (WorkbenchActivityHelper.filterItem(view)) { 1650 continue; 1651 } 1652 viewCategory.addItem(view); 1653 if (activeIds.contains(view.getId())) { 1654 viewCategory.addCheckedItem(view); 1655 } 1656 } 1657 } 1658 } 1659 } 1660 } 1661 1662 protected void okPressed() { 1663 if (showShortcutTab()) { 1664 ArrayList menus = rootMenu.children; 1665 for (int i = 0; i < menus.size(); i++) { 1666 ShortcutMenu menu = (ShortcutMenu) menus.get(i); 1667 if (ShortcutMenu.ID_VIEW.equals(menu.id)) { 1668 perspective.setShowViewActionIds(menu.getCheckedItemIds()); 1669 } else if (ShortcutMenu.ID_PERSP.equals(menu.id)) { 1670 perspective.setPerspectiveActionIds(menu 1671 .getCheckedItemIds()); 1672 } else if (ShortcutMenu.ID_WIZARD.equals(menu.id)) { 1673 perspective.setNewWizardActionIds(menu.getCheckedItemIds()); 1674 } 1675 } 1676 } 1677 1678 ArrayList toAdd = new ArrayList (); 1679 ArrayList toRemove = new ArrayList (); 1680 toRemove.addAll(initiallyActive); 1681 1682 Object [] selected = actionSetsViewer.getCheckedElements(); 1683 for (int i = 0; i < selected.length; i++) { 1684 Object obj = selected[i]; 1685 toRemove.remove(obj); 1686 if (!initiallyActive.contains(toRemove)) { 1687 toAdd.add(obj); 1688 } 1689 } 1690 1691 perspective.turnOnActionSets((IActionSetDescriptor[]) toAdd.toArray(new IActionSetDescriptor[toAdd.size()])); 1692 perspective.turnOffActionSets((IActionSetDescriptor[]) toRemove.toArray(new IActionSetDescriptor[toAdd.size()])); 1693 1694 super.okPressed(); 1695 } 1696 1697 String removeShortcut(String label) { 1698 if (label == null) { 1699 return label; 1700 } 1701 int end = label.lastIndexOf('@'); 1702 if (end >= 0) { 1703 label = label.substring(0, end); 1704 } 1705 return label; 1706 } 1707 1708 private void setInitialSelections() { 1709 Object item = actionSetsViewer.getElementAt(0); 1710 if (lastSelectedActionSetId != null) { 1711 for (int i = 0; i < actionSets.size(); i++) { 1712 ActionSetDescriptor actionSet = (ActionSetDescriptor) actionSets 1713 .get(i); 1714 if (actionSet.getId().equals(lastSelectedActionSetId)) { 1715 item = actionSet; 1716 break; 1717 } 1718 } 1719 } 1720 if (item != null) { 1721 StructuredSelection sel = new StructuredSelection(item); 1722 actionSetsViewer.setSelection(sel, true); 1723 } 1724 1725 if (showShortcutTab()) { 1726 menusCombo.select(lastSelectedMenuIndex); 1727 } 1728 1729 if (lastSelectedTab != -1) { 1730 tabFolder.setSelection(lastSelectedTab); 1731 } 1732 1733 if ((tabFolder.getSelectionIndex() == 0) && showShortcutTab()) { 1734 menusCombo.setFocus(); 1735 } else { 1736 actionSetsViewer.getControl().setFocus(); 1737 } 1738 } 1739 1740 private void updateMenuCategoryCheckedState(ShortcutMenu menu) { 1741 if (menu == rootMenu) { 1742 return; 1743 } 1744 if (menu.isFullyChecked()) { 1745 menuCategoriesViewer.setParentsGrayed(menu, false); 1746 menuCategoriesViewer.setChecked(menu, true); 1747 } else if (menu.isFullyUnchecked()) { 1748 menuCategoriesViewer.setParentsGrayed(menu, false); 1749 menuCategoriesViewer.setChecked(menu, false); 1750 } else { 1751 menuCategoriesViewer.setParentsGrayed(menu, true); 1752 menuCategoriesViewer.setChecked(menu, true); 1753 } 1754 updateMenuCategoryCheckedState(menu.parent); 1755 } 1756 1757 1760 protected boolean applyDialogFont() { 1761 return false; 1762 } 1763 1764} 1765 | Popular Tags |