1 11 12 package org.eclipse.ui.internal.commands; 13 14 import java.io.IOException ; 15 import java.text.Collator ; 16 import java.text.MessageFormat ; 17 import java.util.ArrayList ; 18 import java.util.Collection ; 19 import java.util.Collections ; 20 import java.util.HashMap ; 21 import java.util.HashSet ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.Map ; 25 import java.util.ResourceBundle ; 26 import java.util.Set ; 27 import java.util.SortedMap ; 28 import java.util.TreeMap ; 29 import java.util.TreeSet ; 30 31 import org.eclipse.jface.dialogs.IDialogConstants; 32 import org.eclipse.jface.dialogs.MessageDialog; 33 import org.eclipse.jface.preference.FieldEditor; 34 import org.eclipse.jface.preference.IPreferenceStore; 35 import org.eclipse.jface.preference.IntegerFieldEditor; 36 import org.eclipse.jface.preference.StringFieldEditor; 37 import org.eclipse.jface.util.IPropertyChangeListener; 38 import org.eclipse.jface.util.PropertyChangeEvent; 39 import org.eclipse.swt.SWT; 40 import org.eclipse.swt.events.FocusEvent; 41 import org.eclipse.swt.events.FocusListener; 42 import org.eclipse.swt.events.ModifyEvent; 43 import org.eclipse.swt.events.ModifyListener; 44 import org.eclipse.swt.events.MouseAdapter; 45 import org.eclipse.swt.events.MouseEvent; 46 import org.eclipse.swt.events.SelectionAdapter; 47 import org.eclipse.swt.events.SelectionEvent; 48 import org.eclipse.swt.graphics.Color; 49 import org.eclipse.swt.graphics.Image; 50 import org.eclipse.swt.graphics.Point; 51 import org.eclipse.swt.layout.GridData; 52 import org.eclipse.swt.layout.GridLayout; 53 import org.eclipse.swt.widgets.Button; 54 import org.eclipse.swt.widgets.Combo; 55 import org.eclipse.swt.widgets.Composite; 56 import org.eclipse.swt.widgets.Control; 57 import org.eclipse.swt.widgets.Group; 58 import org.eclipse.swt.widgets.Label; 59 import org.eclipse.swt.widgets.Menu; 60 import org.eclipse.swt.widgets.MenuItem; 61 import org.eclipse.swt.widgets.TabFolder; 62 import org.eclipse.swt.widgets.TabItem; 63 import org.eclipse.swt.widgets.Table; 64 import org.eclipse.swt.widgets.TableColumn; 65 import org.eclipse.swt.widgets.TableItem; 66 import org.eclipse.swt.widgets.Text; 67 import org.eclipse.ui.IWorkbench; 68 import org.eclipse.ui.IWorkbenchPreferencePage; 69 import org.eclipse.ui.PlatformUI; 70 import org.eclipse.ui.commands.ICategory; 71 import org.eclipse.ui.commands.ICommand; 72 import org.eclipse.ui.commands.IKeyConfiguration; 73 import org.eclipse.ui.contexts.IContext; 74 import org.eclipse.ui.contexts.IContextManager; 75 import org.eclipse.ui.contexts.IWorkbenchContextSupport; 76 import org.eclipse.ui.internal.IPreferenceConstants; 77 import org.eclipse.ui.internal.IWorkbenchConstants; 78 import org.eclipse.ui.internal.WorkbenchPlugin; 79 import org.eclipse.ui.internal.keys.KeySequenceText; 80 import org.eclipse.ui.internal.util.Util; 81 import org.eclipse.ui.keys.KeySequence; 82 import org.eclipse.ui.keys.KeyStroke; 83 84 public class KeysPreferencePage extends 85 org.eclipse.jface.preference.PreferencePage implements 86 IWorkbenchPreferencePage { 87 88 private final static class CommandAssignment implements Comparable { 89 90 private KeySequenceBindingNode.Assignment assignment; 91 92 private String contextId; 93 94 private KeySequence keySequence; 95 96 public int compareTo(Object object) { 97 CommandAssignment castedObject = (CommandAssignment) object; 98 int compareTo = Util.compare(contextId, castedObject.contextId); 99 100 if (compareTo == 0) { 101 compareTo = Util.compare(keySequence, castedObject.keySequence); 102 103 if (compareTo == 0) 104 compareTo = Util.compare(assignment, 105 castedObject.assignment); 106 } 107 108 return compareTo; 109 } 110 111 public boolean equals(Object object) { 112 if (!(object instanceof CommandAssignment)) return false; 113 114 CommandAssignment castedObject = (CommandAssignment) object; 115 boolean equals = true; 116 equals &= Util.equals(assignment, castedObject.assignment); 117 equals &= Util.equals(contextId, castedObject.contextId); 118 equals &= Util.equals(keySequence, castedObject.keySequence); 119 return equals; 120 } 121 } 122 123 private final static class KeySequenceAssignment implements Comparable { 124 125 private KeySequenceBindingNode.Assignment assignment; 126 127 private String contextId; 128 129 public int compareTo(Object object) { 130 KeySequenceAssignment castedObject = (KeySequenceAssignment) object; 131 int compareTo = Util.compare(contextId, castedObject.contextId); 132 133 if (compareTo == 0) 134 compareTo = Util.compare(assignment, 135 castedObject.assignment); 136 137 return compareTo; 138 } 139 140 public boolean equals(Object object) { 141 if (!(object instanceof CommandAssignment)) return false; 142 143 KeySequenceAssignment castedObject = (KeySequenceAssignment) object; 144 boolean equals = true; 145 equals &= Util.equals(assignment, castedObject.assignment); 146 equals &= Util.equals(contextId, castedObject.contextId); 147 return equals; 148 } 149 } 150 151 private final static int DIFFERENCE_ADD = 0; 152 153 private final static int DIFFERENCE_CHANGE = 1; 154 155 private final static int DIFFERENCE_MINUS = 2; 156 157 private final static int DIFFERENCE_NONE = 3; 158 159 private final static Image IMAGE_BLANK = ImageFactory.getImage("blank"); 161 private final static Image IMAGE_CHANGE = ImageFactory.getImage("change"); 163 private final static Image IMAGE_MINUS = ImageFactory.getImage("minus"); 165 private final static Image IMAGE_PLUS = ImageFactory.getImage("plus"); 167 private final static ResourceBundle RESOURCE_BUNDLE = ResourceBundle 168 .getBundle(KeysPreferencePage.class.getName()); 169 170 private Map assignmentsByContextIdByKeySequence; 171 172 private Button buttonAdd; 173 174 private Button buttonAddKey; 175 176 private Button buttonRemove; 177 178 private Button buttonRestore; 179 180 private Map categoryIdsByUniqueName; 181 182 private Map categoryUniqueNamesById; 183 184 private Button checkBoxMultiKeyAssist; 185 186 private Combo comboCategory; 187 188 private Combo comboCommand; 189 190 private Combo comboContext; 191 192 private Combo comboKeyConfiguration; 193 194 private Set commandAssignments; 195 196 private Map commandIdsByCategoryId; 197 198 private Map commandIdsByUniqueName; 199 200 private MutableCommandManager commandManager; 201 202 private Map commandUniqueNamesById; 203 204 private Map contextIdsByUniqueName; 205 206 private IContextManager contextManager; 207 208 private Map contextUniqueNamesById; 209 210 private Group groupCommand; 211 212 private Group groupKeySequence; 213 214 private Map keyConfigurationIdsByUniqueName; 215 216 private Map keyConfigurationUniqueNamesById; 217 218 private Set keySequenceAssignments; 219 220 private Label labelAssignmentsForCommand; 221 222 private Label labelAssignmentsForKeySequence; 223 224 private Label labelCategory; 225 226 private Label labelCommand; 227 228 private Label labelContext; 229 230 private Label labelContextExtends; 231 232 private Label labelKeyConfiguration; 233 234 private Label labelKeyConfigurationExtends; 235 236 private Label labelKeySequence; 237 238 private Menu menuButtonAddKey; 239 240 private Color minusColour; 241 242 private Table tableAssignmentsForCommand; 243 244 private Table tableAssignmentsForKeySequence; 245 246 private Text textKeySequence; 247 248 private KeySequenceText textKeySequenceManager; 249 250 private IntegerFieldEditor textMultiKeyAssistTime; 251 252 private SortedMap tree; 253 254 private void buildCommandAssignmentsTable() { 255 tableAssignmentsForCommand.removeAll(); 256 boolean matchFoundInFirstKeyConfiguration = false; 257 258 for (Iterator iterator = commandAssignments.iterator(); iterator 259 .hasNext();) { 260 boolean createTableItem = true; 261 CommandAssignment commandAssignment = (CommandAssignment) iterator 262 .next(); 263 KeySequenceBindingNode.Assignment assignment = commandAssignment.assignment; 264 KeySequence keySequence = commandAssignment.keySequence; 265 String commandString = null; 266 int difference = DIFFERENCE_NONE; 267 268 if (assignment.hasPreferenceCommandIdInFirstKeyConfiguration 269 || assignment.hasPreferenceCommandIdInInheritedKeyConfiguration) { 270 String preferenceCommandId; 271 272 if (assignment.hasPreferenceCommandIdInFirstKeyConfiguration) 273 preferenceCommandId = assignment.preferenceCommandIdInFirstKeyConfiguration; 274 else 275 preferenceCommandId = assignment.preferenceCommandIdInInheritedKeyConfiguration; 276 277 if (assignment.hasPluginCommandIdInFirstKeyConfiguration 278 || assignment.hasPluginCommandIdInInheritedKeyConfiguration) { 279 String pluginCommandId; 280 281 if (assignment.hasPluginCommandIdInFirstKeyConfiguration) 282 pluginCommandId = assignment.pluginCommandIdInFirstKeyConfiguration; 283 else 284 pluginCommandId = assignment.pluginCommandIdInInheritedKeyConfiguration; 285 if (preferenceCommandId != null) { 286 difference = DIFFERENCE_CHANGE; 287 commandString = 288 289 keySequence.format() + ""; } else { 291 difference = DIFFERENCE_MINUS; 292 commandString = 293 keySequence.format(); 294 } 295 296 if (pluginCommandId != null) 297 commandString += " (was: " + commandUniqueNamesById.get(pluginCommandId) 299 + ")"; else 301 commandString += " (was: " + "Unassigned" + ")"; } else { 303 if (preferenceCommandId != null) { 304 difference = DIFFERENCE_ADD; 305 commandString = 306 307 keySequence.format() + ""; } else { 309 difference = DIFFERENCE_MINUS; 310 commandString = 311 keySequence.format(); 312 } 313 } 314 } else { 315 String pluginCommandId = null; 316 if (assignment.hasPluginCommandIdInFirstKeyConfiguration) { 317 pluginCommandId = assignment.pluginCommandIdInFirstKeyConfiguration; 318 if (pluginCommandId != null) { 319 matchFoundInFirstKeyConfiguration = true; 320 } 321 } else if (!matchFoundInFirstKeyConfiguration) { 322 pluginCommandId = assignment.pluginCommandIdInInheritedKeyConfiguration; 323 } else { 324 createTableItem = false; 325 iterator.remove(); 326 } 327 328 if (pluginCommandId != null) { 329 difference = DIFFERENCE_NONE; 330 commandString = 331 332 keySequence.format() + ""; } else { 334 difference = DIFFERENCE_MINUS; 335 commandString = 336 keySequence.format(); 337 } 338 } 339 340 if (createTableItem) { 341 TableItem tableItem = new TableItem(tableAssignmentsForCommand, 342 SWT.NULL); 343 344 switch (difference) { 345 case DIFFERENCE_ADD: 346 tableItem.setImage(0, IMAGE_PLUS); 347 break; 348 349 case DIFFERENCE_CHANGE: 350 tableItem.setImage(0, IMAGE_CHANGE); 351 break; 352 353 case DIFFERENCE_MINUS: 354 tableItem.setImage(0, IMAGE_MINUS); 355 break; 356 357 case DIFFERENCE_NONE: 358 tableItem.setImage(0, IMAGE_BLANK); 359 break; 360 } 361 362 String contextId = commandAssignment.contextId; 363 364 if (contextId == null) { 365 tableItem.setText(1, Util.ZERO_LENGTH_STRING); 367 } else 368 tableItem.setText(1, (String ) contextUniqueNamesById 369 .get(contextId)); 371 tableItem.setText(2, commandString); 372 373 if (difference == DIFFERENCE_MINUS) { 374 tableItem.setForeground(minusColour); 375 } 376 } 377 } 378 } 379 380 private void buildKeySequenceAssignmentsTable() { 381 tableAssignmentsForKeySequence.removeAll(); 382 boolean matchFoundInFirstKeyConfiguration = false; 383 384 for (Iterator iterator = keySequenceAssignments.iterator(); iterator 385 .hasNext();) { 386 boolean createTableItem = true; 387 KeySequenceAssignment keySequenceAssignment = (KeySequenceAssignment) iterator 388 .next(); 389 KeySequenceBindingNode.Assignment assignment = keySequenceAssignment.assignment; 390 String commandString = null; 391 int difference = DIFFERENCE_NONE; 392 393 if (assignment.hasPreferenceCommandIdInFirstKeyConfiguration 394 || assignment.hasPreferenceCommandIdInInheritedKeyConfiguration) { 395 String preferenceCommandId; 396 397 if (assignment.hasPreferenceCommandIdInFirstKeyConfiguration) 398 preferenceCommandId = assignment.preferenceCommandIdInFirstKeyConfiguration; 399 else 400 preferenceCommandId = assignment.preferenceCommandIdInInheritedKeyConfiguration; 401 402 if (assignment.hasPluginCommandIdInFirstKeyConfiguration 403 || assignment.hasPluginCommandIdInInheritedKeyConfiguration) { 404 String pluginCommandId; 405 406 if (assignment.hasPluginCommandIdInFirstKeyConfiguration) 407 pluginCommandId = assignment.pluginCommandIdInFirstKeyConfiguration; 408 else 409 pluginCommandId = assignment.pluginCommandIdInInheritedKeyConfiguration; 410 411 if (preferenceCommandId != null) { 412 difference = DIFFERENCE_CHANGE; 413 commandString = commandUniqueNamesById 414 .get(preferenceCommandId) 415 + ""; } else { 417 difference = DIFFERENCE_MINUS; 418 commandString = "Unassigned"; } 420 421 if (pluginCommandId != null) 422 commandString += " (was: " + commandUniqueNamesById.get(pluginCommandId) 424 + ")"; else 426 commandString += " (was: " + "Unassigned" + ")"; } else { 428 if (preferenceCommandId != null) { 429 difference = DIFFERENCE_ADD; 430 commandString = commandUniqueNamesById 431 .get(preferenceCommandId) 432 + ""; } else { 434 difference = DIFFERENCE_MINUS; 435 commandString = "Unassigned"; } 437 } 438 } else { 439 String pluginCommandId = null; 440 441 if (assignment.hasPluginCommandIdInFirstKeyConfiguration) { 442 pluginCommandId = assignment.pluginCommandIdInFirstKeyConfiguration; 443 if (pluginCommandId != null) { 444 matchFoundInFirstKeyConfiguration = true; 445 } 446 } else if (!matchFoundInFirstKeyConfiguration) { 447 pluginCommandId = assignment.pluginCommandIdInInheritedKeyConfiguration; 448 } else { 449 createTableItem = false; 450 iterator.remove(); 451 } 452 453 if (pluginCommandId != null) { 454 difference = DIFFERENCE_NONE; 455 commandString = commandUniqueNamesById.get(pluginCommandId) 456 + ""; } else { 458 difference = DIFFERENCE_MINUS; 459 commandString = "Unassigned"; } 461 } 462 463 if (createTableItem) { 464 TableItem tableItem = new TableItem( 465 tableAssignmentsForKeySequence, SWT.NULL); 466 467 switch (difference) { 468 case DIFFERENCE_ADD: 469 tableItem.setImage(0, IMAGE_PLUS); 470 break; 471 472 case DIFFERENCE_CHANGE: 473 tableItem.setImage(0, IMAGE_CHANGE); 474 break; 475 476 case DIFFERENCE_MINUS: 477 tableItem.setImage(0, IMAGE_MINUS); 478 break; 479 480 case DIFFERENCE_NONE: 481 tableItem.setImage(0, IMAGE_BLANK); 482 break; 483 } 484 485 String contextId = keySequenceAssignment.contextId; 486 487 if (contextId == null) { 488 tableItem.setText(1, Util.ZERO_LENGTH_STRING); 490 } else { 491 tableItem.setText(1, (String ) contextUniqueNamesById 492 .get(contextId)); } 494 495 tableItem.setText(2, commandString); 496 497 if (difference == DIFFERENCE_MINUS) { 498 tableItem.setForeground(minusColour); 499 } 500 } 501 } 502 } 503 504 private Composite createAdvancedTab(TabFolder parent) { 505 GridData gridData = null; 506 507 final Composite composite = new Composite(parent, SWT.NULL); 509 composite.setLayoutData(new GridData(GridData.FILL_BOTH)); 510 511 checkBoxMultiKeyAssist = new Button(composite, SWT.CHECK); 513 checkBoxMultiKeyAssist.setText(Util.translateString(RESOURCE_BUNDLE, 514 "checkBoxMultiKeyAssist.Text")); checkBoxMultiKeyAssist.setToolTipText(Util.translateString( 516 RESOURCE_BUNDLE, "checkBoxMultiKeyAssist.ToolTipText")); checkBoxMultiKeyAssist.setSelection(getPreferenceStore().getBoolean( 518 IPreferenceConstants.MULTI_KEY_ASSIST)); 519 gridData = new GridData(GridData.FILL_HORIZONTAL); 520 gridData.horizontalSpan = 2; 521 checkBoxMultiKeyAssist.setLayoutData(gridData); 522 523 final IPreferenceStore store = WorkbenchPlugin.getDefault() 525 .getPreferenceStore(); 526 textMultiKeyAssistTime = new IntegerFieldEditor( 527 IPreferenceConstants.MULTI_KEY_ASSIST_TIME, Util 528 .translateString(RESOURCE_BUNDLE, 529 "textMultiKeyAssistTime.Text"), composite); textMultiKeyAssistTime.setPreferenceStore(store); 531 textMultiKeyAssistTime.setPreferencePage(this); 532 textMultiKeyAssistTime.setTextLimit(9); 533 textMultiKeyAssistTime.setErrorMessage(Util.translateString( 534 RESOURCE_BUNDLE, "textMultiKeyAssistTime.ErrorMessage")); textMultiKeyAssistTime 536 .setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE); 537 textMultiKeyAssistTime.setValidRange(1, Integer.MAX_VALUE); 538 textMultiKeyAssistTime.setStringValue(Integer.toString(store 539 .getInt(IPreferenceConstants.MULTI_KEY_ASSIST_TIME))); 540 textMultiKeyAssistTime 541 .setPropertyChangeListener(new IPropertyChangeListener() { 542 543 public void propertyChange(PropertyChangeEvent event) { 544 if (event.getProperty().equals(FieldEditor.IS_VALID)) 545 setValid(textMultiKeyAssistTime.isValid()); 546 } 547 }); 548 549 final GridLayout gridLayout = new GridLayout(); 551 gridLayout.marginHeight = 5; 552 gridLayout.marginWidth = 5; 553 gridLayout.numColumns = 2; 554 composite.setLayout(gridLayout); 555 556 return composite; 557 } 558 559 private Composite createBasicTab(TabFolder parent) { 560 Composite composite = new Composite(parent, SWT.NULL); 561 composite.setLayout(new GridLayout()); 562 GridData gridData = new GridData(GridData.FILL_BOTH); 563 composite.setLayoutData(gridData); 564 Composite compositeKeyConfiguration = new Composite(composite, SWT.NULL); 565 GridLayout gridLayout = new GridLayout(); 566 gridLayout.numColumns = 3; 567 compositeKeyConfiguration.setLayout(gridLayout); 568 gridData = new GridData(GridData.FILL_HORIZONTAL); 569 compositeKeyConfiguration.setLayoutData(gridData); 570 labelKeyConfiguration = new Label(compositeKeyConfiguration, SWT.LEFT); 571 labelKeyConfiguration.setText(Util.translateString(RESOURCE_BUNDLE, 572 "labelKeyConfiguration")); comboKeyConfiguration = new Combo(compositeKeyConfiguration, 574 SWT.READ_ONLY); 575 gridData = new GridData(); 576 gridData.widthHint = 200; 577 comboKeyConfiguration.setLayoutData(gridData); 578 579 comboKeyConfiguration.addSelectionListener(new SelectionAdapter() { 580 581 public void widgetSelected(SelectionEvent selectionEvent) { 582 selectedComboKeyConfiguration(); 583 } 584 }); 585 586 labelKeyConfigurationExtends = new Label(compositeKeyConfiguration, 587 SWT.LEFT); 588 gridData = new GridData(GridData.FILL_HORIZONTAL); 589 labelKeyConfigurationExtends.setLayoutData(gridData); 590 Control spacer = new Composite(composite, SWT.NULL); 591 gridData = new GridData(); 592 gridData.heightHint = 10; 593 gridData.widthHint = 10; 594 spacer.setLayoutData(gridData); 595 groupCommand = new Group(composite, SWT.SHADOW_NONE); 596 gridLayout = new GridLayout(); 597 gridLayout.numColumns = 3; 598 groupCommand.setLayout(gridLayout); 599 gridData = new GridData(GridData.FILL_BOTH); 600 groupCommand.setLayoutData(gridData); 601 groupCommand.setText(Util.translateString(RESOURCE_BUNDLE, 602 "groupCommand")); labelCategory = new Label(groupCommand, SWT.LEFT); 604 gridData = new GridData(); 605 labelCategory.setLayoutData(gridData); 606 labelCategory.setText(Util.translateString(RESOURCE_BUNDLE, 607 "labelCategory")); comboCategory = new Combo(groupCommand, SWT.READ_ONLY); 609 gridData = new GridData(); 610 gridData.horizontalSpan = 2; 611 gridData.widthHint = 200; 612 comboCategory.setLayoutData(gridData); 613 614 comboCategory.addSelectionListener(new SelectionAdapter() { 615 616 public void widgetSelected(SelectionEvent selectionEvent) { 617 selectedComboCategory(); 618 } 619 }); 620 621 labelCommand = new Label(groupCommand, SWT.LEFT); 622 gridData = new GridData(); 623 labelCommand.setLayoutData(gridData); 624 labelCommand.setText(Util.translateString(RESOURCE_BUNDLE, 625 "labelCommand")); comboCommand = new Combo(groupCommand, SWT.READ_ONLY); 627 gridData = new GridData(); 628 gridData.horizontalSpan = 2; 629 gridData.widthHint = 300; 630 comboCommand.setLayoutData(gridData); 631 632 comboCommand.addSelectionListener(new SelectionAdapter() { 633 634 public void widgetSelected(SelectionEvent selectionEvent) { 635 selectedComboCommand(); 636 } 637 }); 638 639 labelAssignmentsForCommand = new Label(groupCommand, SWT.LEFT); 640 gridData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); 641 gridData.verticalAlignment = GridData.FILL_VERTICAL; 642 labelAssignmentsForCommand.setLayoutData(gridData); 643 labelAssignmentsForCommand.setText(Util.translateString( 644 RESOURCE_BUNDLE, "labelAssignmentsForCommand")); tableAssignmentsForCommand = new Table(groupCommand, SWT.BORDER 646 | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); 647 tableAssignmentsForCommand.setHeaderVisible(true); 648 gridData = new GridData(GridData.FILL_BOTH); 649 gridData.heightHint = 60; 650 gridData.horizontalSpan = 2; 651 gridData.widthHint = "carbon".equals(SWT.getPlatform()) ? 620 : 520; tableAssignmentsForCommand.setLayoutData(gridData); 653 TableColumn tableColumnDelta = new TableColumn( 654 tableAssignmentsForCommand, SWT.NULL, 0); 655 tableColumnDelta.setResizable(false); 656 tableColumnDelta.setText(Util.ZERO_LENGTH_STRING); 657 tableColumnDelta.setWidth(20); 658 TableColumn tableColumnContext = new TableColumn( 659 tableAssignmentsForCommand, SWT.NULL, 1); 660 tableColumnContext.setResizable(true); 661 tableColumnContext.setText(Util.translateString(RESOURCE_BUNDLE, 662 "tableColumnContext")); tableColumnContext.pack(); 664 tableColumnContext.setWidth(200); 665 TableColumn tableColumnKeySequence = new TableColumn( 666 tableAssignmentsForCommand, SWT.NULL, 2); 667 tableColumnKeySequence.setResizable(true); 668 tableColumnKeySequence.setText(Util.translateString(RESOURCE_BUNDLE, 669 "tableColumnKeySequence")); tableColumnKeySequence.pack(); 671 tableColumnKeySequence.setWidth(300); 672 673 tableAssignmentsForCommand.addMouseListener(new MouseAdapter() { 674 675 public void mouseDoubleClick(MouseEvent mouseEvent) { 676 doubleClickedAssignmentsForCommand(); 677 } 678 }); 679 680 tableAssignmentsForCommand.addSelectionListener(new SelectionAdapter() { 681 682 public void widgetSelected(SelectionEvent selectionEvent) { 683 selectedTableAssignmentsForCommand(); 684 } 685 }); 686 687 groupKeySequence = new Group(composite, SWT.SHADOW_NONE); 688 gridLayout = new GridLayout(); 689 gridLayout.numColumns = 4; 690 groupKeySequence.setLayout(gridLayout); 691 gridData = new GridData(GridData.FILL_BOTH); 692 groupKeySequence.setLayoutData(gridData); 693 groupKeySequence.setText(Util.translateString(RESOURCE_BUNDLE, 694 "groupKeySequence")); labelKeySequence = new Label(groupKeySequence, SWT.LEFT); 696 gridData = new GridData(); 697 labelKeySequence.setLayoutData(gridData); 698 labelKeySequence.setText(Util.translateString(RESOURCE_BUNDLE, 699 "labelKeySequence")); 701 textKeySequence = new Text(groupKeySequence, SWT.BORDER); 703 textKeySequence.setFont(groupKeySequence.getFont()); 705 gridData = new GridData(); 706 gridData.horizontalSpan = 2; 707 gridData.widthHint = 300; 708 textKeySequence.setLayoutData(gridData); 709 textKeySequence.addModifyListener(new ModifyListener() { 710 711 public void modifyText(ModifyEvent e) { 712 modifiedTextKeySequence(); 713 } 714 }); 715 textKeySequence.addFocusListener(new FocusListener() { 716 717 722 public void focusGained(FocusEvent e) { 723 PlatformUI.getWorkbench().getContextSupport() 724 .setKeyFilterEnabled(false); 725 } 726 727 732 public void focusLost(FocusEvent e) { 733 PlatformUI.getWorkbench().getContextSupport() 734 .setKeyFilterEnabled(true); 735 } 736 }); 737 738 textKeySequenceManager = new KeySequenceText(textKeySequence); 740 textKeySequenceManager.setKeyStrokeLimit(4); 741 742 buttonAddKey = new Button(groupKeySequence, SWT.LEFT | SWT.ARROW); 744 buttonAddKey.setToolTipText(Util.translateString(RESOURCE_BUNDLE, 745 "buttonAddKey.ToolTipText")); gridData = new GridData(); 747 gridData.heightHint = comboCategory.getTextHeight(); 748 buttonAddKey.setLayoutData(gridData); 749 buttonAddKey.addSelectionListener(new SelectionAdapter() { 750 751 public void widgetSelected(SelectionEvent selectionEvent) { 752 Point buttonLocation = buttonAddKey.getLocation(); 753 buttonLocation = groupKeySequence.toDisplay(buttonLocation.x, 754 buttonLocation.y); 755 Point buttonSize = buttonAddKey.getSize(); 756 menuButtonAddKey.setLocation(buttonLocation.x, buttonLocation.y 757 + buttonSize.y); 758 menuButtonAddKey.setVisible(true); 759 } 760 }); 761 762 Control[] tabStops = groupKeySequence.getTabList(); 764 ArrayList newTabStops = new ArrayList (); 765 for (int i = 0; i < tabStops.length; i++) { 766 Control tabStop = tabStops[i]; 767 newTabStops.add(tabStop); 768 if (textKeySequence.equals(tabStop)) { 769 newTabStops.add(buttonAddKey); 770 } 771 } 772 Control[] newTabStopArray = (Control[]) newTabStops 773 .toArray(new Control[newTabStops.size()]); 774 groupKeySequence.setTabList(newTabStopArray); 775 776 menuButtonAddKey = new Menu(buttonAddKey); 778 Iterator trappedKeyItr = KeySequenceText.TRAPPED_KEYS.iterator(); 779 while (trappedKeyItr.hasNext()) { 780 final KeyStroke trappedKey = (KeyStroke) trappedKeyItr.next(); 781 MenuItem menuItem = new MenuItem(menuButtonAddKey, SWT.PUSH); 782 menuItem.setText(trappedKey.format()); 783 menuItem.addSelectionListener(new SelectionAdapter() { 784 785 public void widgetSelected(SelectionEvent e) { 786 textKeySequenceManager.insert(trappedKey); 787 textKeySequence.setFocus(); 788 textKeySequence 789 .setSelection(textKeySequence.getTextLimit()); 790 } 791 }); 792 } 793 794 labelAssignmentsForKeySequence = new Label(groupKeySequence, SWT.LEFT); 795 gridData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); 796 gridData.verticalAlignment = GridData.FILL_VERTICAL; 797 labelAssignmentsForKeySequence.setLayoutData(gridData); 798 labelAssignmentsForKeySequence.setText(Util.translateString( 799 RESOURCE_BUNDLE, "labelAssignmentsForKeySequence")); tableAssignmentsForKeySequence = new Table(groupKeySequence, SWT.BORDER 801 | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); 802 tableAssignmentsForKeySequence.setHeaderVisible(true); 803 gridData = new GridData(GridData.FILL_BOTH); 804 gridData.heightHint = 60; 805 gridData.horizontalSpan = 3; 806 gridData.widthHint = "carbon".equals(SWT.getPlatform()) ? 620 : 520; tableAssignmentsForKeySequence.setLayoutData(gridData); 808 tableColumnDelta = new TableColumn(tableAssignmentsForKeySequence, 809 SWT.NULL, 0); 810 tableColumnDelta.setResizable(false); 811 tableColumnDelta.setText(Util.ZERO_LENGTH_STRING); 812 tableColumnDelta.setWidth(20); 813 tableColumnContext = new TableColumn(tableAssignmentsForKeySequence, 814 SWT.NULL, 1); 815 tableColumnContext.setResizable(true); 816 tableColumnContext.setText(Util.translateString(RESOURCE_BUNDLE, 817 "tableColumnContext")); tableColumnContext.pack(); 819 tableColumnContext.setWidth(200); 820 TableColumn tableColumnCommand = new TableColumn( 821 tableAssignmentsForKeySequence, SWT.NULL, 2); 822 tableColumnCommand.setResizable(true); 823 tableColumnCommand.setText(Util.translateString(RESOURCE_BUNDLE, 824 "tableColumnCommand")); tableColumnCommand.pack(); 826 tableColumnCommand.setWidth(300); 827 828 tableAssignmentsForKeySequence.addMouseListener(new MouseAdapter() { 829 830 public void mouseDoubleClick(MouseEvent mouseEvent) { 831 doubleClickedTableAssignmentsForKeySequence(); 832 } 833 }); 834 835 tableAssignmentsForKeySequence 836 .addSelectionListener(new SelectionAdapter() { 837 838 public void widgetSelected(SelectionEvent selectionEvent) { 839 selectedTableAssignmentsForKeySequence(); 840 } 841 }); 842 843 Composite compositeContext = new Composite(composite, SWT.NULL); 844 gridLayout = new GridLayout(); 845 gridLayout.numColumns = 3; 846 compositeContext.setLayout(gridLayout); 847 gridData = new GridData(GridData.FILL_HORIZONTAL); 848 compositeContext.setLayoutData(gridData); 849 labelContext = new Label(compositeContext, SWT.LEFT); 850 labelContext.setText(Util.translateString(RESOURCE_BUNDLE, 851 "labelContext")); comboContext = new Combo(compositeContext, SWT.READ_ONLY); 853 gridData = new GridData(); 854 gridData.widthHint = 250; 855 comboContext.setLayoutData(gridData); 856 857 comboContext.addSelectionListener(new SelectionAdapter() { 858 859 public void widgetSelected(SelectionEvent selectionEvent) { 860 selectedComboContext(); 861 } 862 }); 863 864 labelContextExtends = new Label(compositeContext, SWT.LEFT); 865 gridData = new GridData(GridData.FILL_HORIZONTAL); 866 labelContextExtends.setLayoutData(gridData); 867 Composite compositeButton = new Composite(composite, SWT.NULL); 868 gridLayout = new GridLayout(); 869 gridLayout.marginHeight = 20; 870 gridLayout.marginWidth = 0; 871 gridLayout.numColumns = 3; 872 compositeButton.setLayout(gridLayout); 873 gridData = new GridData(); 874 compositeButton.setLayoutData(gridData); 875 buttonAdd = new Button(compositeButton, SWT.CENTER | SWT.PUSH); 876 gridData = new GridData(); 877 gridData.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); 878 int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); 879 buttonAdd.setText(Util.translateString(RESOURCE_BUNDLE, "buttonAdd")); gridData.widthHint = Math.max(widthHint, buttonAdd.computeSize( 881 SWT.DEFAULT, SWT.DEFAULT, true).x) + 5; 882 buttonAdd.setLayoutData(gridData); 883 884 buttonAdd.addSelectionListener(new SelectionAdapter() { 885 886 public void widgetSelected(SelectionEvent selectionEvent) { 887 selectedButtonAdd(); 888 } 889 }); 890 891 buttonRemove = new Button(compositeButton, SWT.CENTER | SWT.PUSH); 892 gridData = new GridData(); 893 gridData.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); 894 widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); 895 buttonRemove.setText(Util.translateString(RESOURCE_BUNDLE, 896 "buttonRemove")); gridData.widthHint = Math.max(widthHint, buttonRemove.computeSize( 898 SWT.DEFAULT, SWT.DEFAULT, true).x) + 5; 899 buttonRemove.setLayoutData(gridData); 900 901 buttonRemove.addSelectionListener(new SelectionAdapter() { 902 903 public void widgetSelected(SelectionEvent selectionEvent) { 904 selectedButtonRemove(); 905 } 906 }); 907 908 buttonRestore = new Button(compositeButton, SWT.CENTER | SWT.PUSH); 909 gridData = new GridData(); 910 gridData.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); 911 widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); 912 buttonRestore.setText(Util.translateString(RESOURCE_BUNDLE, 913 "buttonRestore")); gridData.widthHint = Math.max(widthHint, buttonRestore.computeSize( 915 SWT.DEFAULT, SWT.DEFAULT, true).x) + 5; 916 buttonRestore.setLayoutData(gridData); 917 918 buttonRestore.addSelectionListener(new SelectionAdapter() { 919 920 public void widgetSelected(SelectionEvent selectionEvent) { 921 selectedButtonRestore(); 922 } 923 }); 924 925 return composite; 928 } 929 930 protected Control createContents(Composite parent) { 931 minusColour = getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW); 933 934 final TabFolder tabFolder = new TabFolder(parent, SWT.NULL); 935 936 final TabItem basicTab = new TabItem(tabFolder, SWT.NULL); 938 basicTab 939 .setText(Util.translateString(RESOURCE_BUNDLE, "basicTab.Text")); basicTab.setControl(createBasicTab(tabFolder)); 941 942 final TabItem advancedTab = new TabItem(tabFolder, SWT.NULL); 944 advancedTab.setText(Util.translateString(RESOURCE_BUNDLE, 945 "advancedTab.Text")); advancedTab.setControl(createAdvancedTab(tabFolder)); 947 948 applyDialogFont(tabFolder); 949 return tabFolder; 950 } 951 952 protected IPreferenceStore doGetPreferenceStore() { 953 return PlatformUI.getWorkbench().getPreferenceStore(); 954 } 955 956 private void doubleClickedAssignmentsForCommand() { 957 update(); 958 } 959 960 private void doubleClickedTableAssignmentsForKeySequence() { 961 update(); 962 } 963 964 private String getCategoryId() { 965 return !commandIdsByCategoryId.containsKey(null) 966 || comboCategory.getSelectionIndex() > 0 ? (String ) categoryIdsByUniqueName 967 .get(comboCategory.getText()) 968 : null; 969 } 970 971 private String getCommandId() { 972 return (String ) commandIdsByUniqueName.get(comboCommand.getText()); 973 } 974 975 private String getContextId() { 976 return comboContext.getSelectionIndex() >= 0 ? (String ) contextIdsByUniqueName 977 .get(comboContext.getText()) 978 : null; 979 } 980 981 private String getKeyConfigurationId() { 982 return comboKeyConfiguration.getSelectionIndex() >= 0 ? (String ) keyConfigurationIdsByUniqueName 983 .get(comboKeyConfiguration.getText()) 984 : null; 985 } 986 987 private KeySequence getKeySequence() { 988 return textKeySequenceManager.getKeySequence(); 989 } 990 991 public void init(IWorkbench workbench) { 992 IWorkbenchContextSupport workbenchContextSupport = workbench 993 .getContextSupport(); 994 contextManager = workbenchContextSupport.getContextManager(); 995 commandManager = (MutableCommandManager) workbench.getCommandSupport() 997 .getCommandManager(); 998 commandAssignments = new TreeSet (); 999 keySequenceAssignments = new TreeSet (); 1000 } 1001 1002 private void modifiedTextKeySequence() { 1003 update(); 1004 } 1005 1006 protected void performDefaults() { 1007 String activeKeyConfigurationId = getKeyConfigurationId(); 1008 List preferenceKeySequenceBindingDefinitions = new ArrayList (); 1009 KeySequenceBindingNode.getKeySequenceBindingDefinitions(tree, 1010 KeySequence.getInstance(), 0, 1011 preferenceKeySequenceBindingDefinitions); 1012 1013 if (activeKeyConfigurationId != null 1014 || !preferenceKeySequenceBindingDefinitions.isEmpty()) { 1015 final String title = Util.translateString(RESOURCE_BUNDLE, 1016 "restoreDefaultsMessageBoxText"); final String message = Util.translateString(RESOURCE_BUNDLE, 1018 "restoreDefaultsMessageBoxMessage"); final boolean confirmed = MessageDialog.openConfirm(getShell(), 1020 title, message); 1021 1022 if (confirmed) { 1023 setKeyConfigurationId(IWorkbenchConstants.DEFAULT_ACCELERATOR_CONFIGURATION_ID); 1024 Iterator iterator = preferenceKeySequenceBindingDefinitions 1025 .iterator(); 1026 1027 while (iterator.hasNext()) { 1028 KeySequenceBindingDefinition keySequenceBindingDefinition = (KeySequenceBindingDefinition) iterator 1029 .next(); 1030 KeySequenceBindingNode.remove(tree, 1031 keySequenceBindingDefinition.getKeySequence(), 1032 keySequenceBindingDefinition.getContextId(), 1033 keySequenceBindingDefinition 1034 .getKeyConfigurationId(), 0, 1035 keySequenceBindingDefinition.getPlatform(), 1036 keySequenceBindingDefinition.getLocale(), 1037 keySequenceBindingDefinition.getCommandId()); 1038 } 1039 } 1040 } 1041 1042 IPreferenceStore store = getPreferenceStore(); 1044 checkBoxMultiKeyAssist.setSelection(store 1045 .getDefaultBoolean(IPreferenceConstants.MULTI_KEY_ASSIST)); 1046 textMultiKeyAssistTime.setStringValue(Integer.toString(store 1047 .getDefaultInt(IPreferenceConstants.MULTI_KEY_ASSIST_TIME))); 1048 1049 update(); 1050 } 1051 1052 public boolean performOk() { 1053 List preferenceActiveKeyConfigurationDefinitions = new ArrayList (); 1054 preferenceActiveKeyConfigurationDefinitions 1055 .add(new ActiveKeyConfigurationDefinition( 1056 getKeyConfigurationId(), null)); 1057 PreferenceCommandRegistry preferenceCommandRegistry = (PreferenceCommandRegistry) commandManager 1058 .getMutableCommandRegistry(); 1059 preferenceCommandRegistry 1060 .setActiveKeyConfigurationDefinitions(preferenceActiveKeyConfigurationDefinitions); 1061 List preferenceKeySequenceBindingDefinitions = new ArrayList (); 1062 KeySequenceBindingNode.getKeySequenceBindingDefinitions(tree, 1063 KeySequence.getInstance(), 0, 1064 preferenceKeySequenceBindingDefinitions); 1065 preferenceCommandRegistry 1066 .setKeySequenceBindingDefinitions(preferenceKeySequenceBindingDefinitions); 1067 1068 try { 1069 preferenceCommandRegistry.save(); 1070 } catch (IOException eIO) { 1071 } 1073 1074 IPreferenceStore store = getPreferenceStore(); 1076 store.setValue(IPreferenceConstants.MULTI_KEY_ASSIST, 1077 checkBoxMultiKeyAssist.getSelection()); 1078 store.setValue(IPreferenceConstants.MULTI_KEY_ASSIST_TIME, 1079 textMultiKeyAssistTime.getIntValue()); 1080 return super.performOk(); 1081 } 1082 1083 private void selectAssignmentForCommand(String contextId) { 1084 if (tableAssignmentsForCommand.getSelectionCount() > 1) 1085 tableAssignmentsForCommand.deselectAll(); 1086 1087 int i = 0; 1088 int selection = -1; 1089 KeySequence keySequence = getKeySequence(); 1090 1091 for (Iterator iterator = commandAssignments.iterator(); iterator 1092 .hasNext(); i++) { 1093 CommandAssignment commandAssignment = (CommandAssignment) iterator 1094 .next(); 1095 1096 if (Util.equals(contextId, commandAssignment.contextId) 1097 && Util.equals(keySequence, commandAssignment.keySequence)) { 1098 selection = i; 1099 break; 1100 } 1101 } 1102 1103 if (selection != tableAssignmentsForCommand.getSelectionIndex()) { 1104 if (selection == -1 1105 || selection >= tableAssignmentsForCommand.getItemCount()) 1106 tableAssignmentsForCommand.deselectAll(); 1107 else 1108 tableAssignmentsForCommand.select(selection); 1109 } 1110 } 1111 1112 private void selectAssignmentForKeySequence(String contextId) { 1113 if (tableAssignmentsForKeySequence.getSelectionCount() > 1) 1114 tableAssignmentsForKeySequence.deselectAll(); 1115 1116 int i = 0; 1117 int selection = -1; 1118 1119 for (Iterator iterator = keySequenceAssignments.iterator(); iterator 1120 .hasNext(); i++) { 1121 KeySequenceAssignment keySequenceAssignment = (KeySequenceAssignment) iterator 1122 .next(); 1123 1124 if (Util.equals(contextId, keySequenceAssignment.contextId)) { 1125 selection = i; 1126 break; 1127 } 1128 } 1129 1130 if (selection != tableAssignmentsForKeySequence.getSelectionIndex()) { 1131 if (selection == -1 1132 || selection >= tableAssignmentsForKeySequence 1133 .getItemCount()) 1134 tableAssignmentsForKeySequence.deselectAll(); 1135 else 1136 tableAssignmentsForKeySequence.select(selection); 1137 } 1138 } 1139 1140 private void selectedButtonAdd() { 1141 String commandId = getCommandId(); 1142 String contextId = getContextId(); 1143 String keyConfigurationId = getKeyConfigurationId(); 1144 KeySequence keySequence = getKeySequence(); 1145 KeySequenceBindingNode.remove(tree, keySequence, contextId, 1146 keyConfigurationId, 0, null, null); 1147 KeySequenceBindingNode.add(tree, keySequence, contextId, 1148 keyConfigurationId, 0, null, null, commandId); 1149 List preferenceKeySequenceBindingDefinitions = new ArrayList (); 1150 KeySequenceBindingNode.getKeySequenceBindingDefinitions(tree, 1151 KeySequence.getInstance(), 0, 1152 preferenceKeySequenceBindingDefinitions); 1153 update(); 1154 } 1155 1156 private void selectedButtonRemove() { 1157 String contextId = getContextId(); 1158 String keyConfigurationId = getKeyConfigurationId(); 1159 KeySequence keySequence = getKeySequence(); 1160 KeySequenceBindingNode.remove(tree, keySequence, contextId, 1161 keyConfigurationId, 0, null, null); 1162 KeySequenceBindingNode.add(tree, keySequence, contextId, 1163 keyConfigurationId, 0, null, null, null); 1164 List preferenceKeySequenceBindingDefinitions = new ArrayList (); 1165 KeySequenceBindingNode.getKeySequenceBindingDefinitions(tree, 1166 KeySequence.getInstance(), 0, 1167 preferenceKeySequenceBindingDefinitions); 1168 update(); 1169 } 1170 1171 private void selectedButtonRestore() { 1172 String contextId = getContextId(); 1173 String keyConfigurationId = getKeyConfigurationId(); 1174 KeySequence keySequence = getKeySequence(); 1175 KeySequenceBindingNode.remove(tree, keySequence, contextId, 1176 keyConfigurationId, 0, null, null); 1177 List preferenceKeySequenceBindingDefinitions = new ArrayList (); 1178 KeySequenceBindingNode.getKeySequenceBindingDefinitions(tree, 1179 KeySequence.getInstance(), 0, 1180 preferenceKeySequenceBindingDefinitions); 1181 update(); 1182 } 1183 1184 private void selectedComboCategory() { 1185 update(); 1186 } 1187 1188 private void selectedComboCommand() { 1189 update(); 1190 } 1191 1192 private void selectedComboContext() { 1193 update(); 1194 } 1195 1196 private void selectedComboKeyConfiguration() { 1197 update(); 1198 } 1199 1200 private void selectedTableAssignmentsForCommand() { 1201 int selection = tableAssignmentsForCommand.getSelectionIndex(); 1202 List commandAssignmentsAsList = new ArrayList (commandAssignments); 1203 1204 if (selection >= 0 && selection < commandAssignmentsAsList.size() 1205 && tableAssignmentsForCommand.getSelectionCount() == 1) { 1206 CommandAssignment commandAssignment = (CommandAssignment) commandAssignmentsAsList 1207 .get(selection); 1208 String contextId = commandAssignment.contextId; 1209 KeySequence keySequence = commandAssignment.keySequence; 1210 setContextId(contextId); 1211 setKeySequence(keySequence); 1212 } 1213 1214 update(); 1215 } 1216 1217 private void selectedTableAssignmentsForKeySequence() { 1218 int selection = tableAssignmentsForKeySequence.getSelectionIndex(); 1219 List keySequenceAssignmentsAsList = new ArrayList ( 1220 keySequenceAssignments); 1221 1222 if (selection >= 0 && selection < keySequenceAssignmentsAsList.size() 1223 && tableAssignmentsForKeySequence.getSelectionCount() == 1) { 1224 KeySequenceAssignment keySequenceAssignment = (KeySequenceAssignment) keySequenceAssignmentsAsList 1225 .get(selection); 1226 String contextId = keySequenceAssignment.contextId; 1227 setContextId(contextId); 1228 } 1229 1230 update(); 1231 } 1232 1233 private void setAssignmentsForCommand() { 1234 commandAssignments.clear(); 1235 String commandId = getCommandId(); 1236 1237 for (Iterator iterator = assignmentsByContextIdByKeySequence.entrySet() 1238 .iterator(); iterator.hasNext();) { 1239 Map.Entry entry = (Map.Entry ) iterator.next(); 1240 KeySequence keySequence = (KeySequence) entry.getKey(); 1241 Map assignmentsByContextId = (Map ) entry.getValue(); 1242 1243 if (assignmentsByContextId != null) 1244 for (Iterator iterator2 = assignmentsByContextId.entrySet() 1245 .iterator(); iterator2.hasNext();) { 1246 Map.Entry entry2 = (Map.Entry ) iterator2.next(); 1247 CommandAssignment commandAssignment = new CommandAssignment(); 1248 commandAssignment.assignment = (KeySequenceBindingNode.Assignment) entry2 1249 .getValue(); 1250 commandAssignment.contextId = (String ) entry2.getKey(); 1251 commandAssignment.keySequence = keySequence; 1252 1253 if (commandAssignment.assignment.contains(commandId)) 1254 commandAssignments.add(commandAssignment); 1255 } 1256 } 1257 1258 buildCommandAssignmentsTable(); 1259 } 1260 1261 private void setAssignmentsForKeySequence() { 1262 keySequenceAssignments.clear(); 1263 KeySequence keySequence = getKeySequence(); 1264 Map assignmentsByContextId = (Map ) assignmentsByContextIdByKeySequence 1265 .get(keySequence); 1266 1267 if (assignmentsByContextId != null) 1268 for (Iterator iterator = assignmentsByContextId.entrySet() 1269 .iterator(); iterator.hasNext();) { 1270 Map.Entry entry = (Map.Entry ) iterator.next(); 1271 KeySequenceAssignment keySequenceAssignment = new KeySequenceAssignment(); 1272 keySequenceAssignment.assignment = (KeySequenceBindingNode.Assignment) entry 1273 .getValue(); 1274 keySequenceAssignment.contextId = (String ) entry.getKey(); 1275 keySequenceAssignments.add(keySequenceAssignment); 1276 } 1277 1278 buildKeySequenceAssignmentsTable(); 1279 } 1280 1281 private void setCommandId(String commandId) { 1282 comboCommand.clearSelection(); 1283 comboCommand.deselectAll(); 1284 String commandUniqueName = (String ) commandUniqueNamesById 1285 .get(commandId); 1286 1287 if (commandUniqueName != null) { 1288 String items[] = comboCommand.getItems(); 1289 1290 for (int i = 0; i < items.length; i++) 1291 if (commandUniqueName.equals(items[i])) { 1292 comboCommand.select(i); 1293 break; 1294 } 1295 } 1296 } 1297 1298 private void setCommandsForCategory() { 1299 String categoryId = getCategoryId(); 1300 String commandId = getCommandId(); 1301 Set commandIds = (Set ) commandIdsByCategoryId.get(categoryId); 1302 Map commandIdsByName = new HashMap (commandIdsByUniqueName); 1303 if (commandIds == null) { 1304 commandIdsByName = new HashMap (); 1305 } else { 1306 commandIdsByName.values().retainAll(commandIds); 1307 } 1308 List commandNames = new ArrayList (commandIdsByName.keySet()); 1309 Collections.sort(commandNames, Collator.getInstance()); 1310 comboCommand.setItems((String []) commandNames 1311 .toArray(new String [commandNames.size()])); 1312 setCommandId(commandId); 1313 1314 if (comboCommand.getSelectionIndex() == -1 && !commandNames.isEmpty()) 1315 comboCommand.select(0); 1316 } 1317 1318 1328 private void setContextId(String contextId) { 1329 comboContext.clearSelection(); 1331 comboContext.deselectAll(); 1332 1333 String contextName = (String ) contextUniqueNamesById.get(contextId); 1335 if (contextName == null) { 1336 contextName = (String ) contextUniqueNamesById 1337 .get(KeySequenceBinding.DEFAULT_CONTEXT_ID); 1338 } 1339 if (contextName == null) { 1340 contextName = Util.ZERO_LENGTH_STRING; 1341 } 1342 1343 final String [] items = comboContext.getItems(); 1345 boolean found = false; 1346 for (int i = 0; i < items.length; i++) { 1347 if (contextName.equals(items[i])) { 1348 comboContext.select(i); 1349 found = true; 1350 break; 1351 } 1352 } 1353 1354 if ((!found) && (items.length > 0)) { 1356 comboContext.select(0); 1357 } 1358 } 1359 1360 private void setContextsForCommand() { 1361 String commandId = getCommandId(); 1362 String contextId = getContextId(); 1363 Map contextIdsByName = new HashMap (contextIdsByUniqueName); 1364 1365 List contextNames = new ArrayList (contextIdsByName.keySet()); 1366 Collections.sort(contextNames, Collator.getInstance()); 1367 1368 comboContext.setItems((String []) contextNames 1369 .toArray(new String [contextNames.size()])); 1370 setContextId(contextId); 1371 1372 if (comboContext.getSelectionIndex() == -1 && !contextNames.isEmpty()) 1373 comboContext.select(0); 1374 } 1375 1376 private void setKeyConfigurationId(String keyConfigurationId) { 1377 comboKeyConfiguration.clearSelection(); 1378 comboKeyConfiguration.deselectAll(); 1379 String keyConfigurationUniqueName = (String ) keyConfigurationUniqueNamesById 1380 .get(keyConfigurationId); 1381 1382 if (keyConfigurationUniqueName != null) { 1383 String items[] = comboKeyConfiguration.getItems(); 1384 1385 for (int i = 0; i < items.length; i++) 1386 if (keyConfigurationUniqueName.equals(items[i])) { 1387 comboKeyConfiguration.select(i); 1388 break; 1389 } 1390 } 1391 } 1392 1393 private void setKeySequence(KeySequence keySequence) { 1394 textKeySequenceManager.setKeySequence(keySequence); 1395 } 1396 1397 public void setVisible(boolean visible) { 1398 if (visible == true) { 1399 Map contextsByName = new HashMap (); 1400 1401 for (Iterator iterator = contextManager.getDefinedContextIds() 1402 .iterator(); iterator.hasNext();) { 1403 IContext context = contextManager.getContext((String ) iterator 1404 .next()); 1405 1406 try { 1407 String name = context.getName(); 1408 Collection contexts = (Collection ) contextsByName.get(name); 1409 1410 if (contexts == null) { 1411 contexts = new HashSet (); 1412 contextsByName.put(name, contexts); 1413 } 1414 1415 contexts.add(context); 1416 } catch (org.eclipse.ui.contexts.NotDefinedException eNotDefined) { 1417 } 1419 } 1420 1421 Map categoriesByName = new HashMap (); 1422 1423 for (Iterator iterator = commandManager.getDefinedCategoryIds() 1424 .iterator(); iterator.hasNext();) { 1425 ICategory category = commandManager 1426 .getCategory((String ) iterator.next()); 1427 1428 try { 1429 String name = category.getName(); 1430 Collection categories = (Collection ) categoriesByName 1431 .get(name); 1432 1433 if (categories == null) { 1434 categories = new HashSet (); 1435 categoriesByName.put(name, categories); 1436 } 1437 1438 categories.add(category); 1439 } catch (org.eclipse.ui.commands.NotDefinedException eNotDefined) { 1440 } 1442 } 1443 1444 Map commandsByName = new HashMap (); 1445 1446 for (Iterator iterator = commandManager.getDefinedCommandIds() 1447 .iterator(); iterator.hasNext();) { 1448 ICommand command = commandManager.getCommand((String ) iterator 1449 .next()); 1450 1451 try { 1452 String name = command.getName(); 1453 Collection commands = (Collection ) commandsByName.get(name); 1454 1455 if (commands == null) { 1456 commands = new HashSet (); 1457 commandsByName.put(name, commands); 1458 } 1459 1460 commands.add(command); 1461 } catch (org.eclipse.ui.commands.NotDefinedException eNotDefined) { 1462 } 1464 } 1465 1466 Map keyConfigurationsByName = new HashMap (); 1467 1468 for (Iterator iterator = commandManager 1469 .getDefinedKeyConfigurationIds().iterator(); iterator 1470 .hasNext();) { 1471 IKeyConfiguration keyConfiguration = commandManager 1472 .getKeyConfiguration((String ) iterator.next()); 1473 1474 try { 1475 String name = keyConfiguration.getName(); 1476 Collection keyConfigurations = (Collection ) keyConfigurationsByName 1477 .get(name); 1478 1479 if (keyConfigurations == null) { 1480 keyConfigurations = new HashSet (); 1481 keyConfigurationsByName.put(name, keyConfigurations); 1482 } 1483 1484 keyConfigurations.add(keyConfiguration); 1485 } catch (org.eclipse.ui.commands.NotDefinedException eNotDefined) { 1486 } 1488 } 1489 1490 contextIdsByUniqueName = new HashMap (); 1491 contextUniqueNamesById = new HashMap (); 1492 1493 for (Iterator iterator = contextsByName.entrySet().iterator(); iterator 1494 .hasNext();) { 1495 Map.Entry entry = (Map.Entry ) iterator.next(); 1496 String name = (String ) entry.getKey(); 1497 Set contexts = (Set ) entry.getValue(); 1498 Iterator iterator2 = contexts.iterator(); 1499 1500 if (contexts.size() == 1) { 1501 IContext context = (IContext) iterator2.next(); 1502 contextIdsByUniqueName.put(name, context.getId()); 1503 contextUniqueNamesById.put(context.getId(), name); 1504 } else 1505 while (iterator2.hasNext()) { 1506 IContext context = (IContext) iterator2.next(); 1507 String uniqueName = MessageFormat.format( 1508 Util.translateString(RESOURCE_BUNDLE, 1509 "uniqueName"), new Object [] { name, context.getId()}); 1511 contextIdsByUniqueName.put(uniqueName, context.getId()); 1512 contextUniqueNamesById.put(context.getId(), uniqueName); 1513 } 1514 } 1515 1516 categoryIdsByUniqueName = new HashMap (); 1517 categoryUniqueNamesById = new HashMap (); 1518 1519 for (Iterator iterator = categoriesByName.entrySet().iterator(); iterator 1520 .hasNext();) { 1521 Map.Entry entry = (Map.Entry ) iterator.next(); 1522 String name = (String ) entry.getKey(); 1523 Set categories = (Set ) entry.getValue(); 1524 Iterator iterator2 = categories.iterator(); 1525 1526 if (categories.size() == 1) { 1527 ICategory category = (ICategory) iterator2.next(); 1528 categoryIdsByUniqueName.put(name, category.getId()); 1529 categoryUniqueNamesById.put(category.getId(), name); 1530 } else 1531 while (iterator2.hasNext()) { 1532 ICategory category = (ICategory) iterator2.next(); 1533 String uniqueName = MessageFormat.format( 1534 Util.translateString(RESOURCE_BUNDLE, 1535 "uniqueName"), new Object [] { name, category.getId()}); 1537 categoryIdsByUniqueName.put(uniqueName, category 1538 .getId()); 1539 categoryUniqueNamesById.put(category.getId(), 1540 uniqueName); 1541 } 1542 } 1543 1544 commandIdsByUniqueName = new HashMap (); 1545 commandUniqueNamesById = new HashMap (); 1546 1547 for (Iterator iterator = commandsByName.entrySet().iterator(); iterator 1548 .hasNext();) { 1549 Map.Entry entry = (Map.Entry ) iterator.next(); 1550 String name = (String ) entry.getKey(); 1551 Set commands = (Set ) entry.getValue(); 1552 Iterator iterator2 = commands.iterator(); 1553 1554 if (commands.size() == 1) { 1555 ICommand command = (ICommand) iterator2.next(); 1556 commandIdsByUniqueName.put(name, command.getId()); 1557 commandUniqueNamesById.put(command.getId(), name); 1558 } else 1559 while (iterator2.hasNext()) { 1560 ICommand command = (ICommand) iterator2.next(); 1561 String uniqueName = MessageFormat.format( 1562 Util.translateString(RESOURCE_BUNDLE, 1563 "uniqueName"), new Object [] { name, command.getId()}); 1565 commandIdsByUniqueName.put(uniqueName, command.getId()); 1566 commandUniqueNamesById.put(command.getId(), uniqueName); 1567 } 1568 } 1569 1570 keyConfigurationIdsByUniqueName = new HashMap (); 1571 keyConfigurationUniqueNamesById = new HashMap (); 1572 1573 for (Iterator iterator = keyConfigurationsByName.entrySet() 1574 .iterator(); iterator.hasNext();) { 1575 Map.Entry entry = (Map.Entry ) iterator.next(); 1576 String name = (String ) entry.getKey(); 1577 Set keyConfigurations = (Set ) entry.getValue(); 1578 Iterator iterator2 = keyConfigurations.iterator(); 1579 1580 if (keyConfigurations.size() == 1) { 1581 IKeyConfiguration keyConfiguration = (IKeyConfiguration) iterator2 1582 .next(); 1583 keyConfigurationIdsByUniqueName.put(name, keyConfiguration 1584 .getId()); 1585 keyConfigurationUniqueNamesById.put(keyConfiguration 1586 .getId(), name); 1587 } else 1588 while (iterator2.hasNext()) { 1589 IKeyConfiguration keyConfiguration = (IKeyConfiguration) iterator2 1590 .next(); 1591 String uniqueName = MessageFormat.format( 1592 Util.translateString(RESOURCE_BUNDLE, 1593 "uniqueName"), new Object [] { name, keyConfiguration.getId()}); 1595 keyConfigurationIdsByUniqueName.put(uniqueName, 1596 keyConfiguration.getId()); 1597 keyConfigurationUniqueNamesById.put(keyConfiguration 1598 .getId(), uniqueName); 1599 } 1600 } 1601 1602 String activeKeyConfigurationId = commandManager 1603 .getActiveKeyConfigurationId(); 1604 commandIdsByCategoryId = new HashMap (); 1605 1606 for (Iterator iterator = commandManager.getDefinedCommandIds() 1607 .iterator(); iterator.hasNext();) { 1608 ICommand command = commandManager.getCommand((String ) iterator 1609 .next()); 1610 1611 try { 1612 String categoryId = command.getCategoryId(); 1613 Collection commandIds = (Collection ) commandIdsByCategoryId 1614 .get(categoryId); 1615 1616 if (commandIds == null) { 1617 commandIds = new HashSet (); 1618 commandIdsByCategoryId.put(categoryId, commandIds); 1619 } 1620 1621 commandIds.add(command.getId()); 1622 } catch (org.eclipse.ui.commands.NotDefinedException eNotDefined) { 1623 } 1625 } 1626 1627 ICommandRegistry commandRegistry = commandManager 1628 .getCommandRegistry(); 1629 ICommandRegistry mutableCommandRegistry = commandManager 1630 .getMutableCommandRegistry(); 1631 1632 List pluginKeySequenceBindingDefinitions = new ArrayList ( 1633 commandRegistry.getKeySequenceBindingDefinitions()); 1634 1635 for (Iterator iterator = pluginKeySequenceBindingDefinitions 1636 .iterator(); iterator.hasNext();) { 1637 KeySequenceBindingDefinition keySequenceBindingDefinition = (KeySequenceBindingDefinition) iterator 1638 .next(); 1639 KeySequence keySequence = keySequenceBindingDefinition 1640 .getKeySequence(); 1641 String commandId = keySequenceBindingDefinition.getCommandId(); 1642 String contextId = keySequenceBindingDefinition.getContextId(); 1643 String keyConfigurationId = keySequenceBindingDefinition 1644 .getKeyConfigurationId(); 1645 boolean validKeySequence = keySequence != null 1646 && MutableCommandManager.validateKeySequence(keySequence); 1647 boolean validContextId = contextId == null 1648 || contextManager.getDefinedContextIds().contains( 1649 contextId); 1650 boolean validCommandId = commandId == null 1651 || commandManager.getDefinedCommandIds().contains( 1652 commandId); 1653 boolean validKeyConfigurationId = keyConfigurationId == null 1654 || commandManager.getDefinedKeyConfigurationIds() 1655 .contains(keyConfigurationId); 1656 1657 if (!validKeySequence || !validCommandId || !validContextId 1658 || !validKeyConfigurationId) iterator.remove(); 1659 } 1660 1661 List preferenceKeySequenceBindingDefinitions = new ArrayList ( 1662 mutableCommandRegistry.getKeySequenceBindingDefinitions()); 1663 1664 for (Iterator iterator = preferenceKeySequenceBindingDefinitions 1665 .iterator(); iterator.hasNext();) { 1666 KeySequenceBindingDefinition keySequenceBindingDefinition = (KeySequenceBindingDefinition) iterator 1667 .next(); 1668 KeySequence keySequence = keySequenceBindingDefinition 1669 .getKeySequence(); 1670 String commandId = keySequenceBindingDefinition.getCommandId(); 1671 String contextId = keySequenceBindingDefinition.getContextId(); 1672 String keyConfigurationId = keySequenceBindingDefinition 1673 .getKeyConfigurationId(); 1674 boolean validKeySequence = keySequence != null 1675 && MutableCommandManager.validateKeySequence(keySequence); 1676 boolean validContextId = contextId == null 1677 || contextManager.getDefinedContextIds().contains( 1678 contextId); 1679 boolean validCommandId = commandId == null 1680 || commandManager.getDefinedCommandIds().contains( 1681 commandId); 1682 boolean validKeyConfigurationId = keyConfigurationId == null 1683 || commandManager.getDefinedKeyConfigurationIds() 1684 .contains(keyConfigurationId); 1685 1686 if (!validKeySequence || !validCommandId || !validContextId 1687 || !validKeyConfigurationId) iterator.remove(); 1688 } 1689 1690 tree = new TreeMap (); 1691 1692 for (Iterator iterator = pluginKeySequenceBindingDefinitions 1693 .iterator(); iterator.hasNext();) { 1694 KeySequenceBindingDefinition keySequenceBindingDefinition = (KeySequenceBindingDefinition) iterator 1695 .next(); 1696 KeySequenceBindingNode.add(tree, keySequenceBindingDefinition 1697 .getKeySequence(), keySequenceBindingDefinition 1698 .getContextId(), keySequenceBindingDefinition 1699 .getKeyConfigurationId(), 1, 1700 keySequenceBindingDefinition.getPlatform(), 1701 keySequenceBindingDefinition.getLocale(), 1702 keySequenceBindingDefinition.getCommandId()); 1703 } 1704 1705 for (Iterator iterator = preferenceKeySequenceBindingDefinitions 1706 .iterator(); iterator.hasNext();) { 1707 KeySequenceBindingDefinition keySequenceBindingDefinition = (KeySequenceBindingDefinition) iterator 1708 .next(); 1709 KeySequenceBindingNode.add(tree, keySequenceBindingDefinition 1710 .getKeySequence(), keySequenceBindingDefinition 1711 .getContextId(), keySequenceBindingDefinition 1712 .getKeyConfigurationId(), 0, 1713 keySequenceBindingDefinition.getPlatform(), 1714 keySequenceBindingDefinition.getLocale(), 1715 keySequenceBindingDefinition.getCommandId()); 1716 } 1717 1718 1723 1738 1739 List categoryNames = new ArrayList (categoryIdsByUniqueName.keySet()); 1740 Collections.sort(categoryNames, Collator.getInstance()); 1741 1742 if (commandIdsByCategoryId.containsKey(null)) 1743 categoryNames.add(0, Util.translateString(RESOURCE_BUNDLE, 1744 "other")); 1746 comboCategory.setItems((String []) categoryNames 1747 .toArray(new String [categoryNames.size()])); 1748 comboCategory.clearSelection(); 1749 comboCategory.deselectAll(); 1750 1751 if (commandIdsByCategoryId.containsKey(null) 1752 || !categoryNames.isEmpty()) comboCategory.select(0); 1753 1754 List keyConfigurationNames = new ArrayList ( 1755 keyConfigurationIdsByUniqueName.keySet()); 1756 Collections.sort(keyConfigurationNames, Collator.getInstance()); 1757 comboKeyConfiguration.setItems((String []) keyConfigurationNames 1758 .toArray(new String [keyConfigurationNames.size()])); 1759 setKeyConfigurationId(activeKeyConfigurationId); 1760 update(); 1761 } 1762 1763 super.setVisible(visible); 1764 } 1765 1766 private void update() { 1767 setCommandsForCategory(); 1768 setContextsForCommand(); 1769 String keyConfigurationId = getKeyConfigurationId(); 1770 KeySequence keySequence = getKeySequence(); 1771 String [] activeKeyConfigurationIds = MutableCommandManager 1772 .extend(commandManager 1773 .getKeyConfigurationIds(keyConfigurationId)); 1774 String [] activeLocales = MutableCommandManager.extend(MutableCommandManager.getPath( 1775 commandManager.getActiveLocale(), MutableCommandManager.SEPARATOR)); 1776 String [] activePlatforms = MutableCommandManager.extend(MutableCommandManager 1777 .getPath(commandManager.getActivePlatform(), 1778 MutableCommandManager.SEPARATOR)); 1779 KeySequenceBindingNode.solve(tree, activeKeyConfigurationIds, 1780 activePlatforms, activeLocales); 1781 assignmentsByContextIdByKeySequence = KeySequenceBindingNode 1782 .getAssignmentsByContextIdKeySequence(tree, KeySequence 1783 .getInstance()); 1784 setAssignmentsForKeySequence(); 1785 setAssignmentsForCommand(); 1786 String commandId = getCommandId(); 1787 String contextId = getContextId(); 1788 selectAssignmentForKeySequence(contextId); 1789 selectAssignmentForCommand(contextId); 1790 updateLabelKeyConfigurationExtends(); 1791 updateLabelContextExtends(); 1792 labelAssignmentsForKeySequence.setEnabled(keySequence != null 1793 && !keySequence.getKeyStrokes().isEmpty()); 1794 tableAssignmentsForKeySequence.setEnabled(keySequence != null 1795 && !keySequence.getKeyStrokes().isEmpty()); 1796 labelAssignmentsForCommand.setEnabled(commandId != null); 1797 tableAssignmentsForCommand.setEnabled(commandId != null); 1798 boolean buttonsEnabled = commandId != null && keySequence != null 1799 && !keySequence.getKeyStrokes().isEmpty(); 1800 boolean buttonAddEnabled = buttonsEnabled; 1801 boolean buttonRemoveEnabled = buttonsEnabled; 1802 boolean buttonRestoreEnabled = buttonsEnabled; 1803 buttonAdd.setEnabled(buttonAddEnabled); 1805 buttonRemove.setEnabled(buttonRemoveEnabled); 1806 buttonRestore.setEnabled(buttonRestoreEnabled); 1807 } 1808 1809 private void updateLabelContextExtends() { 1810 String contextId = getContextId(); 1811 1812 if (contextId != null) { 1813 IContext context = contextManager.getContext(getContextId()); 1814 1815 if (context.isDefined()) { 1816 try { 1817 String parentId = context.getParentId(); 1818 if (parentId != null) { 1819 String name = (String ) contextUniqueNamesById 1820 .get(parentId); 1821 1822 if (name != null) { 1823 labelContextExtends.setText(MessageFormat.format( 1824 Util.translateString(RESOURCE_BUNDLE, 1825 "extends"), new Object [] { name})); 1827 1828 return; 1829 } 1830 } 1831 } catch (org.eclipse.ui.contexts.NotDefinedException eNotDefined) { 1832 } 1834 } 1835 } 1836 1837 labelContextExtends.setText(Util.ZERO_LENGTH_STRING); 1838 } 1839 1840 private void updateLabelKeyConfigurationExtends() { 1841 String keyConfigurationId = getKeyConfigurationId(); 1842 1843 if (keyConfigurationId != null) { 1844 IKeyConfiguration keyConfiguration = commandManager 1845 .getKeyConfiguration(keyConfigurationId); 1846 1847 try { 1848 String name = (String ) keyConfigurationUniqueNamesById 1849 .get(keyConfiguration.getParentId()); 1850 1851 if (name != null) { 1852 labelKeyConfigurationExtends.setText(MessageFormat.format( 1853 Util.translateString(RESOURCE_BUNDLE, "extends"), new Object [] { name})); 1855 return; 1856 } 1857 } catch (org.eclipse.ui.commands.NotDefinedException eNotDefined) { 1858 } 1860 } 1861 1862 labelKeyConfigurationExtends.setText(Util.ZERO_LENGTH_STRING); 1863 } 1864 1865 2004} 2005 | Popular Tags |