1 /*******************************************************************************
\r
2 * Copyright (c) 2010, 2011 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.browsing.ui.model.sorters;
\r
14 import org.simantics.browsing.ui.BuiltinKeys;
\r
15 import org.simantics.browsing.ui.NodeContext;
\r
16 import org.simantics.browsing.ui.model.InvalidContribution;
\r
17 import org.simantics.browsing.ui.model.nodetypes.NodeType;
\r
18 import org.simantics.browsing.ui.model.tests.Test;
\r
19 import org.simantics.browsing.ui.model.visuals.VisualsContribution;
\r
20 import org.simantics.db.ReadGraph;
\r
21 import org.simantics.db.exception.DatabaseException;
\r
23 public class SorterContribution extends VisualsContribution {
\r
24 SorterRule modifierRule;
\r
26 public SorterContribution(NodeType nodeType, Test test, SorterRule modifierRule, double priority) throws InvalidContribution {
\r
27 super(nodeType, test, priority);
\r
28 if(!modifierRule.isCompatible(
\r
29 nodeType.getContentType()
\r
31 throw new InvalidContribution("Sorter rule is not compatible with the content type.");
\r
32 this.modifierRule = modifierRule;
\r
35 public Sorter getSorter(ReadGraph graph, NodeContext context) {
\r
36 Object content = context.getConstant(BuiltinKeys.INPUT);
\r
38 if(test == null || test.test(graph, content))
\r
39 return modifierRule.getSorter(graph, content);
\r
42 } catch(DatabaseException e) {
\r