1 11 12 package org.eclipse.ui.internal.quickaccess; 13 14 15 import org.eclipse.jface.resource.ImageDescriptor; 16 17 21 public abstract class QuickAccessElement { 22 23 private static final int[][] EMPTY_INDICES = new int[0][0]; 24 private QuickAccessProvider provider; 25 26 29 public QuickAccessElement(QuickAccessProvider provider) { 30 super(); 31 this.provider = provider; 32 } 33 34 39 public abstract String getLabel(); 40 41 46 public abstract ImageDescriptor getImageDescriptor(); 47 48 54 public abstract String getId(); 55 56 59 public abstract void execute(); 60 61 66 public String getSortLabel() { 67 return getLabel(); 68 } 69 70 73 public QuickAccessProvider getProvider() { 74 return provider; 75 } 76 77 81 public QuickAccessEntry match(String filter, 82 QuickAccessProvider providerForMatching) { 83 String sortLabel = getLabel(); 84 int index = sortLabel.toLowerCase().indexOf(filter); 85 if (index != -1) { 86 return new QuickAccessEntry(this, providerForMatching, 87 new int[][] { { index, index + filter.length() - 1 } }, 88 EMPTY_INDICES); 89 } 90 String combinedLabel = (providerForMatching.getName() + " " + getLabel()); index = combinedLabel.toLowerCase().indexOf(filter); 92 if (index != -1) { 93 int lengthOfElementMatch = index + filter.length() 94 - providerForMatching.getName().length() - 1; 95 if (lengthOfElementMatch > 0) { 96 return new QuickAccessEntry(this, providerForMatching, 97 new int[][] { { 0, lengthOfElementMatch - 1 } }, 98 new int[][] { { index, index + filter.length() - 1 } }); 99 } 100 return new QuickAccessEntry(this, providerForMatching, 101 EMPTY_INDICES, new int[][] { { index, 102 index + filter.length() - 1 } }); 103 } 104 String camelCase = CamelUtil.getCamelCase(sortLabel); 105 index = camelCase.indexOf(filter); 106 if (index != -1) { 107 int[][] indices = CamelUtil.getCamelCaseIndices(sortLabel, index, filter 108 .length()); 109 return new QuickAccessEntry(this, providerForMatching, indices, 110 EMPTY_INDICES); 111 } 112 String combinedCamelCase = CamelUtil.getCamelCase(combinedLabel); 113 index = combinedCamelCase.indexOf(filter); 114 if (index != -1) { 115 String providerCamelCase = CamelUtil.getCamelCase(providerForMatching 116 .getName()); 117 int lengthOfElementMatch = index + filter.length() 118 - providerCamelCase.length(); 119 if (lengthOfElementMatch > 0) { 120 return new QuickAccessEntry( 121 this, 122 providerForMatching, 123 CamelUtil.getCamelCaseIndices(sortLabel, 0, lengthOfElementMatch), 124 CamelUtil.getCamelCaseIndices(providerForMatching.getName(), 125 index, filter.length() - lengthOfElementMatch)); 126 } 127 return new QuickAccessEntry(this, providerForMatching, 128 EMPTY_INDICES, CamelUtil.getCamelCaseIndices(providerForMatching 129 .getName(), index, filter.length())); 130 } 131 return null; 132 } 133 } 134 | Popular Tags |