1 11 package org.eclipse.ui.views.markers.internal; 12 13 import java.util.Comparator ; 14 15 import org.eclipse.jface.dialogs.IDialogSettings; 16 import org.eclipse.jface.viewers.Viewer; 17 import org.eclipse.jface.viewers.ViewerComparator; 18 19 24 public class CategoryComparator extends ViewerComparator implements Comparator { 25 TableComparator innerSorter; 26 27 IField categoryField; 28 29 private final String TAG_FIELD = "categoryField"; 31 36 CategoryComparator(TableComparator sorter) { 37 innerSorter = sorter; 38 } 39 40 50 int compare(Object obj1, Object obj2, int depth, boolean continueSearching) { 51 52 if (obj1 == null || obj2 == null || !(obj1 instanceof MarkerNode) 53 || !(obj2 instanceof MarkerNode)) { 54 return 0; 55 } 56 57 MarkerNode marker1; 58 MarkerNode marker2; 59 60 marker1 = (MarkerNode) obj1; 61 marker2 = (MarkerNode) obj2; 62 63 if (categoryField == null) { 64 return innerSorter.compare(marker1, marker2, depth, 65 continueSearching); 66 } 67 68 int result = categoryField.compare(marker1, marker2); 69 if (continueSearching && result == 0) { 70 return innerSorter.compare(marker1, marker2, 0, continueSearching); 71 } 72 return result; 73 } 74 75 81 public int compare(Viewer viewer, Object e1, Object e2) { 82 return compare(e1, e2, 0, true); 83 } 84 85 90 public int compare(Object arg0, Object arg1) { 91 return compare(arg0, arg1, 0, true); 92 } 93 94 99 public IField getCategoryField() { 100 return categoryField; 101 } 102 103 108 public void setCategoryField(IField field) { 109 this.categoryField = field; 110 } 111 112 117 public void setTableSorter(TableComparator sorter2) { 118 innerSorter = sorter2; 119 120 } 121 122 127 public void saveState(IDialogSettings dialogSettings) { 128 if (dialogSettings == null) { 129 return; 130 } 131 132 IDialogSettings settings = dialogSettings 133 .getSection(TableComparator.TAG_DIALOG_SECTION); 134 if (settings == null) { 135 settings = dialogSettings 136 .addNewSection(TableComparator.TAG_DIALOG_SECTION); 137 } 138 139 String description = Util.EMPTY_STRING; 140 if (categoryField != null) { 141 description = categoryField.getDescription(); 142 } 143 144 settings.put(TAG_FIELD, description); 145 146 } 147 148 154 public void restoreState(IDialogSettings dialogSettings, ProblemView view) { 155 if (dialogSettings == null) { 156 selectDefaultGrouping(view); 157 return; 158 } 159 160 IDialogSettings settings = dialogSettings 161 .getSection(TableComparator.TAG_DIALOG_SECTION); 162 if (settings == null) { 163 selectDefaultGrouping(view); 164 return; 165 } 166 167 String description = settings.get(TAG_FIELD); 168 view.selectCategory(description, this); 169 } 170 171 175 private void selectDefaultGrouping(ProblemView view) { 176 view.selectCategoryField(MarkerSupportRegistry.getInstance() 177 .getDefaultGroup(), this); 178 } 179 } 180 | Popular Tags |