1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.common.comparators;
14 import org.simantics.browsing.ui.BuiltinKeys;
15 import org.simantics.browsing.ui.NodeContext;
16 import org.simantics.browsing.ui.NodeQueryManager;
17 import org.simantics.browsing.ui.content.ComparableContext;
18 import org.simantics.browsing.ui.content.ComparableContextFactory;
19 import org.simantics.browsing.ui.content.Labeler;
21 public class ReverseLexicalComparatorFactory implements ComparableContextFactory {
23 private final String column;
24 private final String label;
26 public ReverseLexicalComparatorFactory(String column) {
31 public ReverseLexicalComparatorFactory(String column, String label) {
37 public ComparableContext[] create(NodeQueryManager manager, NodeContext parent, NodeContext[] children) {
38 ComparableContext[] result = new ComparableContext[children.length];
39 for (int i = 0; i < children.length; i++) {
40 NodeContext child = children[i];
41 Labeler labeler = manager.query(child, BuiltinKeys.SELECTED_LABELER);
43 int category = (labeler != null) ? labeler.getCategory() : 0;
44 String label = (labeler != null) ? labeler.getLabels().get(column) : "";
48 result[i] = new ImmutableLexicalComparable(category, label, child) {
50 public int compareTo(ComparableContext arg0) {
51 ImmutableLexicalComparable other = (ImmutableLexicalComparable) arg0;
53 int catDelta = other.getCategory() - getCategory();
57 String label1 = getLabel();
58 String label2 = other.getLabel();
60 return label2.compareToIgnoreCase(label1);
68 public String toString() {
69 return label != null ? label : "Reverse alphabetical";