]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/modifiers/VariablePropertyModifierRule.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.model / src / org / simantics / browsing / ui / model / modifiers / VariablePropertyModifierRule.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.browsing.ui.model.modifiers;
13
14 import org.simantics.browsing.ui.common.ColumnKeys;
15 import org.simantics.browsing.ui.content.Labeler.Modifier;
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.db.layer0.variable.Variable;
19
20 /**
21  * @author Tuukka Lehtonen
22  */
23 public class VariablePropertyModifierRule implements ModifierRule {
24
25         String propertyName;
26
27     public VariablePropertyModifierRule(ReadGraph graph, String propertyName) throws DatabaseException {
28         this.propertyName = propertyName;
29     }
30
31     @Override
32     public boolean isCompatible(Class<?> contentType) {
33         return contentType.equals(Variable.class);
34     }
35
36     @Override
37     public Modifier getModifier(ReadGraph graph, Object content,
38             String columnKey) throws DatabaseException {
39         if(!ColumnKeys.SINGLE.equals(columnKey))
40             return null;
41         if(!(content instanceof Variable))
42             return null;
43         Variable variable = (Variable)content;
44         Variable propertyVariable = variable.getProperty(graph, propertyName);
45         return new VariableModifier2(graph, propertyVariable);
46     }
47
48 }