1 11 12 package org.eclipse.ui.internal.commands; 13 14 import java.util.ArrayList ; 15 import java.util.Collection ; 16 import java.util.HashMap ; 17 import java.util.HashSet ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Map ; 21 import java.util.Set ; 22 import java.util.SortedSet ; 23 import java.util.TreeSet ; 24 25 import org.eclipse.ui.internal.WorkbenchPlugin; 26 import org.eclipse.ui.internal.util.Util; 27 import org.eclipse.ui.keys.KeySequence; 28 import org.eclipse.ui.keys.KeyStroke; 29 30 final class KeySequenceBindingNode { 31 32 final static class Assignment implements Comparable { 33 boolean hasPluginCommandIdInFirstKeyConfiguration; 34 boolean hasPluginCommandIdInInheritedKeyConfiguration; 35 36 boolean hasPreferenceCommandIdInFirstKeyConfiguration; 37 boolean hasPreferenceCommandIdInInheritedKeyConfiguration; 38 String pluginCommandIdInFirstKeyConfiguration; 39 String pluginCommandIdInInheritedKeyConfiguration; 40 String preferenceCommandIdInFirstKeyConfiguration; 41 String preferenceCommandIdInInheritedKeyConfiguration; 42 43 public int compareTo(Object object) { 44 Assignment castedObject = (Assignment) object; 45 int compareTo = 46 hasPreferenceCommandIdInFirstKeyConfiguration == false 47 ? (castedObject.hasPreferenceCommandIdInFirstKeyConfiguration 48 == true 49 ? -1 50 : 0) 51 : 1; 52 53 if (compareTo == 0) { 54 compareTo = 55 hasPreferenceCommandIdInInheritedKeyConfiguration == false 56 ? (castedObject 57 .hasPreferenceCommandIdInInheritedKeyConfiguration 58 == true 59 ? -1 60 : 0) 61 : 1; 62 63 if (compareTo == 0) { 64 compareTo = 65 hasPluginCommandIdInFirstKeyConfiguration == false 66 ? (castedObject 67 .hasPluginCommandIdInFirstKeyConfiguration 68 == true 69 ? -1 70 : 0) 71 : 1; 72 73 if (compareTo == 0) { 74 compareTo = 75 hasPluginCommandIdInInheritedKeyConfiguration 76 == false 77 ? (castedObject 78 .hasPluginCommandIdInInheritedKeyConfiguration 79 == true 80 ? -1 81 : 0) 82 : 1; 83 84 if (compareTo == 0) { 85 compareTo = 86 Util.compare( 87 preferenceCommandIdInFirstKeyConfiguration, 88 castedObject 89 .preferenceCommandIdInFirstKeyConfiguration); 90 91 if (compareTo == 0) { 92 compareTo = 93 Util.compare( 94 preferenceCommandIdInInheritedKeyConfiguration, 95 castedObject 96 .preferenceCommandIdInInheritedKeyConfiguration); 97 98 if (compareTo == 0) { 99 compareTo = 100 Util.compare( 101 pluginCommandIdInFirstKeyConfiguration, 102 castedObject 103 .pluginCommandIdInFirstKeyConfiguration); 104 105 if (compareTo == 0) 106 compareTo = 107 Util.compare( 108 pluginCommandIdInInheritedKeyConfiguration, 109 castedObject 110 .pluginCommandIdInInheritedKeyConfiguration); 111 } 112 } 113 } 114 } 115 } 116 } 117 118 return compareTo; 119 } 120 121 boolean contains(String commandId) { 122 return Util.equals( 123 commandId, 124 preferenceCommandIdInFirstKeyConfiguration) 125 || Util.equals( 126 commandId, 127 preferenceCommandIdInInheritedKeyConfiguration) 128 || Util.equals(commandId, pluginCommandIdInFirstKeyConfiguration) 129 || Util.equals( 130 commandId, 131 pluginCommandIdInInheritedKeyConfiguration); 132 } 133 134 public boolean equals(Object object) { 135 if (!(object instanceof Assignment)) 136 return false; 137 138 Assignment castedObject = (Assignment) object; 139 boolean equals = true; 140 equals &= hasPreferenceCommandIdInFirstKeyConfiguration 141 == castedObject.hasPreferenceCommandIdInFirstKeyConfiguration; 142 equals &= hasPreferenceCommandIdInInheritedKeyConfiguration 143 == castedObject.hasPreferenceCommandIdInInheritedKeyConfiguration; 144 equals &= hasPluginCommandIdInFirstKeyConfiguration 145 == castedObject.hasPluginCommandIdInFirstKeyConfiguration; 146 equals &= hasPluginCommandIdInInheritedKeyConfiguration 147 == castedObject.hasPluginCommandIdInInheritedKeyConfiguration; 148 equals &= preferenceCommandIdInFirstKeyConfiguration 149 == castedObject.preferenceCommandIdInFirstKeyConfiguration; 150 equals &= preferenceCommandIdInInheritedKeyConfiguration 151 == castedObject.preferenceCommandIdInInheritedKeyConfiguration; 152 equals &= pluginCommandIdInFirstKeyConfiguration 153 == castedObject.pluginCommandIdInFirstKeyConfiguration; 154 equals &= pluginCommandIdInInheritedKeyConfiguration 155 == castedObject.pluginCommandIdInInheritedKeyConfiguration; 156 return equals; 157 } 158 } 159 160 static void add( 161 Map keyStrokeNodeByKeyStrokeMap, 162 KeySequence keySequence, 163 String contextId, 164 String keyConfigurationId, 165 int rank, 166 String platform, 167 String locale, 168 String commandId) { 169 List keyStrokes = keySequence.getKeyStrokes(); 170 Map root = keyStrokeNodeByKeyStrokeMap; 171 KeySequenceBindingNode keySequenceBindingNode = null; 172 173 for (int i = 0; i < keyStrokes.size(); i++) { 174 KeyStroke keyStroke = (KeyStroke) keyStrokes.get(i); 175 keySequenceBindingNode = 176 (KeySequenceBindingNode) root.get(keyStroke); 177 178 if (keySequenceBindingNode == null) { 179 keySequenceBindingNode = new KeySequenceBindingNode(); 180 root.put(keyStroke, keySequenceBindingNode); 181 } 182 183 root = keySequenceBindingNode.childKeyStrokeNodeByKeyStrokeMap; 184 } 185 186 if (keySequenceBindingNode != null) 187 keySequenceBindingNode.add( 188 contextId, 189 keyConfigurationId, 190 rank, 191 platform, 192 locale, 193 commandId); 194 } 195 196 static Map find(Map keyStrokeNodeByKeyStrokeMap, KeySequence keySequence) { 197 Iterator iterator = keySequence.getKeyStrokes().iterator(); 198 KeySequenceBindingNode keySequenceBindingNode = null; 199 200 while (iterator.hasNext()) { 201 keySequenceBindingNode = 202 (KeySequenceBindingNode) keyStrokeNodeByKeyStrokeMap.get( 203 iterator.next()); 204 205 if (keySequenceBindingNode == null) 206 return null; 207 208 keyStrokeNodeByKeyStrokeMap = 209 keySequenceBindingNode.childKeyStrokeNodeByKeyStrokeMap; 210 } 211 212 return keyStrokeNodeByKeyStrokeMap; 213 } 214 215 static Map getAssignmentsByContextIdKeySequence( 216 Map keyStrokeNodeByKeyStrokeMap, 217 KeySequence prefix) { 218 Map assignmentsByContextIdByKeySequence = new HashMap (); 219 Iterator iterator = keyStrokeNodeByKeyStrokeMap.entrySet().iterator(); 220 221 while (iterator.hasNext()) { 222 Map.Entry entry = (Map.Entry ) iterator.next(); 223 KeyStroke keyStroke = (KeyStroke) entry.getKey(); 224 KeySequenceBindingNode keySequenceBindingNode = 225 (KeySequenceBindingNode) entry.getValue(); 226 List keyStrokes = new ArrayList (prefix.getKeyStrokes()); 227 keyStrokes.add(keyStroke); 228 KeySequence keySequence = KeySequence.getInstance(keyStrokes); 229 Map childAssignmentsByContextIdByKeySequence = 230 getAssignmentsByContextIdKeySequence( 231 keySequenceBindingNode.childKeyStrokeNodeByKeyStrokeMap, 232 keySequence); 233 234 if (childAssignmentsByContextIdByKeySequence.size() >= 1) 235 assignmentsByContextIdByKeySequence.putAll( 236 childAssignmentsByContextIdByKeySequence); 237 238 assignmentsByContextIdByKeySequence.put( 239 keySequence, 240 keySequenceBindingNode.assignmentsByContextId); 241 } 242 243 return assignmentsByContextIdByKeySequence; 244 } 245 246 static void getKeySequenceBindingDefinitions( 247 Map keyStrokeNodeByKeyStrokeMap, 248 KeySequence prefix, 249 int rank, 250 List keySequenceBindingDefinitions) { 251 Iterator iterator = keyStrokeNodeByKeyStrokeMap.entrySet().iterator(); 252 253 while (iterator.hasNext()) { 254 Map.Entry entry = (Map.Entry ) iterator.next(); 255 KeyStroke keyStroke = (KeyStroke) entry.getKey(); 256 KeySequenceBindingNode keySequenceBindingNode = 257 (KeySequenceBindingNode) entry.getValue(); 258 List keyStrokes = new ArrayList (prefix.getKeyStrokes()); 259 keyStrokes.add(keyStroke); 260 KeySequence keySequence = KeySequence.getInstance(keyStrokes); 261 Map contextMap = keySequenceBindingNode.contextMap; 262 Iterator iterator2 = contextMap.entrySet().iterator(); 263 264 while (iterator2.hasNext()) { 265 Map.Entry entry2 = (Map.Entry ) iterator2.next(); 266 String contextId = (String ) entry2.getKey(); 267 Map keyConfigurationMap = (Map ) entry2.getValue(); 268 Iterator iterator3 = keyConfigurationMap.entrySet().iterator(); 269 270 while (iterator3.hasNext()) { 271 Map.Entry entry3 = (Map.Entry ) iterator3.next(); 272 String keyConfigurationId = (String ) entry3.getKey(); 273 Map rankMap = (Map ) entry3.getValue(); 274 Map platformMap = (Map ) rankMap.get(new Integer (rank)); 275 276 if (platformMap != null) { 277 Iterator iterator4 = platformMap.entrySet().iterator(); 278 279 while (iterator4.hasNext()) { 280 Map.Entry entry4 = (Map.Entry ) iterator4.next(); 281 String platform = (String ) entry4.getKey(); 282 Map localeMap = (Map ) entry4.getValue(); 283 Iterator iterator5 = 284 localeMap.entrySet().iterator(); 285 286 while (iterator5.hasNext()) { 287 Map.Entry entry5 = (Map.Entry ) iterator5.next(); 288 String locale = (String ) entry5.getKey(); 289 Set commandIds = (Set ) entry5.getValue(); 290 Iterator iterator6 = commandIds.iterator(); 291 292 while (iterator6.hasNext()) { 293 String commandId = 294 (String ) iterator6.next(); 295 keySequenceBindingDefinitions.add( 296 new KeySequenceBindingDefinition( 297 contextId, 298 commandId, 299 keyConfigurationId, 300 keySequence, 301 locale, 302 platform, 303 null)); 304 } 305 } 306 } 307 } 308 } 309 } 310 311 getKeySequenceBindingDefinitions( 312 keySequenceBindingNode.childKeyStrokeNodeByKeyStrokeMap, 313 keySequence, 314 rank, 315 keySequenceBindingDefinitions); 316 } 317 } 318 319 static Map getKeySequenceBindingsByCommandId(Map keySequenceMap) { 320 Map commandMap = new HashMap (); 321 Iterator iterator = keySequenceMap.entrySet().iterator(); 322 323 while (iterator.hasNext()) { 324 Map.Entry entry = (Map.Entry ) iterator.next(); 325 KeySequence keySequence = (KeySequence) entry.getKey(); 326 Match match = (Match) entry.getValue(); 327 String commandId = match.getCommandId(); 328 int value = match.getValue(); 329 SortedSet keySequenceBindings = 330 (SortedSet ) commandMap.get(commandId); 331 332 if (keySequenceBindings == null) { 333 keySequenceBindings = new TreeSet (); 334 commandMap.put(commandId, keySequenceBindings); 335 } 336 337 keySequenceBindings.add(new KeySequenceBinding(keySequence, value)); 338 } 339 340 return commandMap; 341 } 342 343 static Map getMatchesByKeySequence( 344 Map keyStrokeNodeByKeyStrokeMap, 345 KeySequence prefix) { 346 Map keySequenceMap = new HashMap (); 347 Iterator iterator = keyStrokeNodeByKeyStrokeMap.entrySet().iterator(); 348 349 while (iterator.hasNext()) { 350 Map.Entry entry = (Map.Entry ) iterator.next(); 351 KeyStroke keyStroke = (KeyStroke) entry.getKey(); 352 KeySequenceBindingNode keySequenceBindingNode = 353 (KeySequenceBindingNode) entry.getValue(); 354 List keyStrokes = new ArrayList (prefix.getKeyStrokes()); 355 keyStrokes.add(keyStroke); 356 KeySequence keySequence = KeySequence.getInstance(keyStrokes); 357 Map childMatchesByKeySequence = 358 getMatchesByKeySequence( 359 keySequenceBindingNode.childKeyStrokeNodeByKeyStrokeMap, 360 keySequence); 361 362 if (childMatchesByKeySequence.size() >= 1) 363 keySequenceMap.putAll(childMatchesByKeySequence); 364 else if ( 365 keySequenceBindingNode.match != null 366 && keySequenceBindingNode.match.getCommandId() != null) 367 keySequenceMap.put(keySequence, keySequenceBindingNode.match); 368 } 369 370 return keySequenceMap; 371 } 372 373 static void remove( 374 Map keyStrokeNodeByKeyStrokeMap, 375 KeySequence keySequence, 376 String contextId, 377 String keyConfigurationId, 378 int rank, 379 String platform, 380 String locale) { 381 Iterator iterator = keySequence.getKeyStrokes().iterator(); 382 KeySequenceBindingNode keySequenceBindingNode = null; 383 384 while (iterator.hasNext()) { 385 keySequenceBindingNode = 386 (KeySequenceBindingNode) keyStrokeNodeByKeyStrokeMap.get( 387 iterator.next()); 388 389 if (keySequenceBindingNode == null) 390 return; 391 392 keyStrokeNodeByKeyStrokeMap = 393 keySequenceBindingNode.childKeyStrokeNodeByKeyStrokeMap; 394 } 395 396 keySequenceBindingNode.remove( 397 contextId, 398 keyConfigurationId, 399 rank, 400 platform, 401 locale); 402 } 403 404 static void remove( 405 Map keyStrokeNodeByKeyStrokeMap, 406 KeySequence keySequence, 407 String contextId, 408 String keyConfigurationId, 409 int rank, 410 String platform, 411 String locale, 412 String commandId) { 413 Iterator iterator = keySequence.getKeyStrokes().iterator(); 414 KeySequenceBindingNode keySequenceBindingNode = null; 415 416 while (iterator.hasNext()) { 417 keySequenceBindingNode = 418 (KeySequenceBindingNode) keyStrokeNodeByKeyStrokeMap.get( 419 iterator.next()); 420 421 if (keySequenceBindingNode == null) 422 return; 423 424 keyStrokeNodeByKeyStrokeMap = 425 keySequenceBindingNode.childKeyStrokeNodeByKeyStrokeMap; 426 } 427 428 keySequenceBindingNode.remove( 429 contextId, 430 keyConfigurationId, 431 rank, 432 platform, 433 locale, 434 commandId); 435 } 436 437 static void solve( 438 Map keyStrokeNodeByKeyStrokeMap, 439 String [] keyConfigurationIds, 440 String [] platforms, 441 String [] locales) { 442 for (Iterator iterator = 443 keyStrokeNodeByKeyStrokeMap.values().iterator(); 444 iterator.hasNext(); 445 ) { 446 KeySequenceBindingNode keySequenceBindingNode = 447 (KeySequenceBindingNode) iterator.next(); 448 keySequenceBindingNode.solveAssignmentsByContextId( 449 keyConfigurationIds, 450 platforms, 451 locales); 452 solve( 453 keySequenceBindingNode.childKeyStrokeNodeByKeyStrokeMap, 454 keyConfigurationIds, 455 platforms, 456 locales); 457 } 458 } 459 460 static void solve( 461 Map keyStrokeNodeByKeyStrokeMap, 462 Map contextIds, 463 String [] keyConfigurationIds, 464 String [] platforms, 465 String [] locales) { 466 for (Iterator iterator = 467 keyStrokeNodeByKeyStrokeMap.values().iterator(); 468 iterator.hasNext(); 469 ) { 470 KeySequenceBindingNode keySequenceBindingNode = 471 (KeySequenceBindingNode) iterator.next(); 472 keySequenceBindingNode.solveMatch( 473 contextIds, 474 keyConfigurationIds, 475 platforms, 476 locales); 477 solve( 478 keySequenceBindingNode.childKeyStrokeNodeByKeyStrokeMap, 479 contextIds, 480 keyConfigurationIds, 481 platforms, 482 locales); 483 } 484 } 485 private Map contextMap = new HashMap (); 486 487 private Map assignmentsByContextId = new HashMap (); 488 private Map childKeyStrokeNodeByKeyStrokeMap = new HashMap (); 489 private Match match = null; 490 491 private KeySequenceBindingNode() { 492 } 493 494 private void add( 495 String contextId, 496 String keyConfigurationId, 497 int rank, 498 String platform, 499 String locale, 500 String commandId) { 501 Map keyConfigurationMap = (Map ) contextMap.get(contextId); 502 503 if (keyConfigurationMap == null) { 504 keyConfigurationMap = new HashMap (); 505 contextMap.put(contextId, keyConfigurationMap); 506 } 507 508 Map rankMap = (Map ) keyConfigurationMap.get(keyConfigurationId); 509 510 if (rankMap == null) { 511 rankMap = new HashMap (); 512 keyConfigurationMap.put(keyConfigurationId, rankMap); 513 } 514 515 Map platformMap = (Map ) rankMap.get(new Integer (rank)); 516 517 if (platformMap == null) { 518 platformMap = new HashMap (); 519 rankMap.put(new Integer (rank), platformMap); 520 } 521 522 Map localeMap = (Map ) platformMap.get(platform); 523 524 if (localeMap == null) { 525 localeMap = new HashMap (); 526 platformMap.put(platform, localeMap); 527 } 528 529 Set commandIds = (Set ) localeMap.get(locale); 530 531 if (commandIds == null) { 532 commandIds = new HashSet (); 533 localeMap.put(locale, commandIds); 534 } 535 536 commandIds.add(commandId); 537 } 538 539 private void remove( 540 String contextId, 541 String keyConfigurationId, 542 int rank, 543 String platform, 544 String locale) { 545 Map keyConfigurationMap = (Map ) contextMap.get(contextId); 546 547 if (keyConfigurationMap != null) { 548 Map rankMap = (Map ) keyConfigurationMap.get(keyConfigurationId); 549 550 if (rankMap != null) { 551 Map platformMap = (Map ) rankMap.get(new Integer (rank)); 552 553 if (platformMap != null) { 554 Map localeMap = (Map ) platformMap.get(platform); 555 556 if (localeMap != null) { 557 localeMap.remove(locale); 558 559 if (localeMap.isEmpty()) { 560 platformMap.remove(platform); 561 562 if (platformMap.isEmpty()) { 563 rankMap.remove(new Integer (rank)); 564 565 if (rankMap.isEmpty()) { 566 keyConfigurationMap.remove( 567 keyConfigurationId); 568 569 if (keyConfigurationMap.isEmpty()) 570 contextMap.remove(contextId); 571 } 572 } 573 } 574 } 575 } 576 } 577 } 578 } 579 580 private void remove( 581 String contextId, 582 String keyConfigurationId, 583 int rank, 584 String platform, 585 String locale, 586 String commandId) { 587 Map keyConfigurationMap = (Map ) contextMap.get(contextId); 588 589 if (keyConfigurationMap != null) { 590 Map rankMap = (Map ) keyConfigurationMap.get(keyConfigurationId); 591 592 if (rankMap != null) { 593 Map platformMap = (Map ) rankMap.get(new Integer (rank)); 594 595 if (platformMap != null) { 596 Map localeMap = (Map ) platformMap.get(platform); 597 598 if (localeMap != null) { 599 Set commandIds = (Set ) localeMap.get(locale); 600 601 if (commandIds != null) { 602 commandIds.remove(commandId); 603 604 if (commandIds.isEmpty()) { 605 localeMap.remove(locale); 606 607 if (localeMap.isEmpty()) { 608 platformMap.remove(platform); 609 610 if (platformMap.isEmpty()) { 611 rankMap.remove(new Integer (rank)); 612 613 if (rankMap.isEmpty()) { 614 keyConfigurationMap.remove( 615 keyConfigurationId); 616 617 if (keyConfigurationMap.isEmpty()) 618 contextMap.remove(contextId); 619 } 620 } 621 } 622 } 623 } 624 } 625 } 626 } 627 } 628 } 629 630 private void solveAssignmentsByContextId( 631 String [] keyConfigurationIds, 632 String [] platforms, 633 String [] locales) { 634 assignmentsByContextId.clear(); 635 636 for (Iterator iterator = contextMap.entrySet().iterator(); 637 iterator.hasNext(); 638 ) { 639 Map.Entry entry = (Map.Entry ) iterator.next(); 640 String contextId = (String ) entry.getKey(); 641 Map keyConfigurationMap = (Map ) entry.getValue(); 642 KeySequenceBindingNode.Assignment assignment = null; 643 644 if (keyConfigurationMap != null) 645 for (int keyConfiguration = 0; 646 keyConfiguration < keyConfigurationIds.length 647 && keyConfiguration < 0xFF; 648 keyConfiguration++) { 649 Map rankMap = 650 (Map ) keyConfigurationMap.get( 651 keyConfigurationIds[keyConfiguration]); 652 653 if (rankMap != null) 654 for (int rank = 0; rank <= 1; rank++) { 655 Map platformMap = 656 (Map ) rankMap.get(new Integer (rank)); 657 658 if (platformMap != null) 659 for (int platform = 0; 660 platform < platforms.length 661 && platform < 0xFF; 662 platform++) { 663 Map localeMap = 664 (Map ) platformMap.get( 665 platforms[platform]); 666 667 if (localeMap != null) 668 for (int locale = 0; 669 locale < locales.length 670 && locale < 0xFF; 671 locale++) { 672 Set commandIds = 673 (Set ) localeMap.get( 674 locales[locale]); 675 676 if (commandIds != null) { 677 String commandId = 678 commandIds.size() == 1 679 ? (String ) commandIds 680 .iterator() 681 .next() 682 : null; 683 684 if (assignment == null) 685 assignment = 686 new Assignment(); 687 688 switch (rank) { 689 case 0 : 690 if (keyConfiguration 691 == 0 692 && !assignment 693 .hasPreferenceCommandIdInFirstKeyConfiguration) { 694 assignment 695 .hasPreferenceCommandIdInFirstKeyConfiguration = 696 true; 697 assignment 698 .preferenceCommandIdInFirstKeyConfiguration = 699 commandId; 700 } else if ( 701 !assignment 702 .hasPreferenceCommandIdInInheritedKeyConfiguration) { 703 assignment 704 .hasPreferenceCommandIdInInheritedKeyConfiguration = 705 true; 706 assignment 707 .preferenceCommandIdInInheritedKeyConfiguration = 708 commandId; 709 } 710 711 break; 712 713 case 1 : 714 if (keyConfiguration 715 == 0 716 && !assignment 717 .hasPluginCommandIdInFirstKeyConfiguration) { 718 assignment 719 .hasPluginCommandIdInFirstKeyConfiguration = 720 true; 721 assignment 722 .pluginCommandIdInFirstKeyConfiguration = 723 commandId; 724 } else if ( 725 !assignment 726 .hasPluginCommandIdInInheritedKeyConfiguration) { 727 assignment 728 .hasPluginCommandIdInInheritedKeyConfiguration = 729 true; 730 assignment 731 .pluginCommandIdInInheritedKeyConfiguration = 732 commandId; 733 } 734 735 break; 736 } 737 } 738 } 739 } 740 741 } 742 743 } 744 745 if (assignment != null) 746 assignmentsByContextId.put(contextId, assignment); 747 } 748 } 749 750 817 private void solveMatch(Map contextTree, 818 String [] keyConfigurationIds, String [] platforms, String [] locales) { 819 match = null; 821 822 final String [] contextIds = (String []) contextTree.keySet().toArray( 824 new String [contextTree.size()]); 825 826 final int maxContext = (contextIds.length > 0xFF) ? 0xFF 828 : contextIds.length; 829 int maxKeyConfiguration = (keyConfigurationIds.length > 0xFF) ? 0xFF 830 : keyConfigurationIds.length; 831 final int maxPlatform = (platforms.length > 0xFF) ? 0xFF 832 : platforms.length; 833 final int maxLocale = (locales.length > 0xFF) ? 0xFF : locales.length; 834 835 final Collection contextIdsNotToConsider = new HashSet (); 837 for (int context = 0; context < maxContext; context++) { 838 boolean matchFoundForThisContext = false; 839 840 845 final String contextId = contextIds[context]; 846 if (contextIdsNotToConsider.contains(contextId)) { 847 continue; 848 } 849 850 final Map keyConfigurationMap = (Map ) contextMap.get(contextId); 851 if (keyConfigurationMap != null) 852 for (int keyConfiguration = 0; keyConfiguration < maxKeyConfiguration 853 && !matchFoundForThisContext; keyConfiguration++) { 854 final Map rankMap = (Map ) keyConfigurationMap 855 .get(keyConfigurationIds[keyConfiguration]); 856 857 if (rankMap != null) { 858 for (int rank = 0; rank <= 1; rank++) { 859 final Map platformMap = (Map ) rankMap 860 .get(new Integer (rank)); 861 862 if (platformMap != null) 863 for (int platform = 0; platform < maxPlatform 864 && !matchFoundForThisContext; platform++) { 865 final Map localeMap = (Map ) platformMap 866 .get(platforms[platform]); 867 868 if (localeMap != null) 869 for (int locale = 0; locale < maxLocale 870 && !matchFoundForThisContext; locale++) { 871 final Set commandIds = (Set ) localeMap 872 .get(locales[locale]); 873 874 if (commandIds != null) { 875 879 matchFoundForThisContext = true; 880 881 885 final String commandId = commandIds 886 .size() == 1 ? (String ) commandIds 887 .iterator() 888 .next() 889 : null; 890 891 898 maxKeyConfiguration = keyConfiguration + 1; 899 900 909 if (commandId != null) { 910 String parentContext = (String ) contextTree 911 .get(contextId); 912 while (parentContext != null) { 913 contextIdsNotToConsider 914 .add(parentContext); 915 parentContext = (String ) contextTree 916 .get(parentContext); 917 } 918 919 923 if ((match != null) 924 && (!contextIdsNotToConsider 925 .contains(contextIds[match 926 .getValue() >> 24]))) { 927 WorkbenchPlugin 928 .log("Conflicting key binding for '" + commandId 930 + "' and '" + match 932 .getCommandId() 933 + "'"); match = null; 935 936 } else { 937 match = new Match( 938 commandId, 939 (context << 24) 940 + (keyConfiguration << 16) 941 + (platform << 8) 942 + locale); 943 } 944 } 945 } 946 } 947 } 948 } 949 } 950 } 951 } 952 } 953 } 954 | Popular Tags |