/* * (non-Javadoc) * * @see * org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface * .viewers.Viewer, java.lang.Object, java.lang.Object) */ @Override public int compare(Viewer viewer, Object e1, Object e2) { ReportTemplateMetaData data1 = (ReportTemplateMetaData) e1; ReportTemplateMetaData data2 = (ReportTemplateMetaData) e2; int rc = 0; if (e1 == null) { if (e2 != null) { rc = 1; } } else if (e2 == null) { rc = -1; } else { // e1 and e2 != null switch (propertyIndex) { case 0: rc = comporeToLowerCase(data1.getDecoratedOutputname(), data2.getDecoratedOutputname()); break; case 1: // implement a sorted list here that needs to be compared String s1 = getSortedOutputFormatsString(data1.getOutputFormats()); String s2 = getSortedOutputFormatsString(data2.getOutputFormats()); if (s1 != null && s2 != null) { rc = s1.compareTo(s2); } break; case 2: rc = comporeToLowerCase(data1.getFilename(), data2.getFilename()); break; default: rc = 0; } } // If descending order, flip the direction if (direction == DESCENDING) { rc = -rc; } return rc; }
/** * adds decorators ( "(L)" or "(S)" ) as a prefix to the report names, sorts alphabetically: * (locally stored templates before server-sided templates) adds sorted name list to the * reportCombo * * @return sorted Array (for access later on) */ @SuppressWarnings("unchecked") private ReportTemplateMetaData[] fillReportCombo() { Arrays.sort( reportTemplates, new Comparator() { @Override public int compare(Object template1, Object template2) { return comparator.compare( ((ReportTemplateMetaData) template1).getDecoratedOutputname(), ((ReportTemplateMetaData) template2).getDecoratedOutputname()); } }); for (ReportTemplateMetaData data : reportTemplates) { comboReportType.add(data.getDecoratedOutputname()); } return reportTemplates; }