]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.selectionview/src/org/simantics/selectionview/VariablePropertyModifierRule.java
Diagram to SVG to support selection cycling
[simantics/platform.git] / bundles / org.simantics.selectionview / src / org / simantics / selectionview / 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.selectionview;
13
14 import java.util.List;
15
16 import org.simantics.browsing.ui.content.Labeler.Modifier;
17 import org.simantics.browsing.ui.graph.impl.EnumerationVariableModifier3;
18 import org.simantics.browsing.ui.model.modifiers.ModifierRule;
19 import org.simantics.browsing.ui.model.modifiers.VariableModifier2;
20 import org.simantics.db.ReadGraph;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.layer0.variable.Variable;
23 import org.simantics.db.layer0.variable.Variables;
24
25 /**
26  * @author Tuukka Lehtonen
27  */
28 public class VariablePropertyModifierRule implements ModifierRule {
29
30     @Override
31     public boolean isCompatible(Class<?> contentType) {
32         return contentType.equals(Variable.class);
33     }
34
35     @Override
36     public Modifier getModifier(ReadGraph graph, Object _content, String columnKey_) throws DatabaseException {
37
38         if (!(_content instanceof Variable))
39             return null;
40
41         Variable content = (Variable)_content;
42
43         // If the whole property is considered read-only, don't allow modification.
44         Boolean readOnly = content.getPossiblePropertyValue(graph, Variables.READONLY);
45         if (Boolean.TRUE.equals(readOnly))
46             return null;
47         
48         String columnKey = columnKey_;
49         if(columnKey.startsWith("#")) columnKey = columnKey.substring(1);
50
51         // If the specified column of the property is considered read-only, don't allow modification.
52         Variable columnVariable = content.getPossibleProperty(graph, columnKey);
53         if (columnVariable != null) {
54             readOnly = columnVariable.getPossiblePropertyValue(graph, Variables.READONLY);
55             if (Boolean.TRUE.equals(readOnly))
56                 return null;
57         }
58
59         for (Variable property : content.getProperties(graph)) {
60             String column = property.getPossiblePropertyValue(graph, Variables.DISPLAY_COLUMN);
61             if (column != null) {
62                 if (columnKey.equals(column)) {
63                         
64                         if(columnKey_.startsWith("#"))
65                         return new VariableModifier2(graph, property);
66
67                     Modifier custom = property.getPossiblePropertyValue(graph, Variables.CUSTOM_MODIFIER);
68                     if (custom != null) return custom;
69
70                     List<String> enumeration = property.getPossiblePropertyValue(graph, Variables.ENUMERATION_VALUES);
71                     if (enumeration != null) {
72                         return new EnumerationVariableModifier3(graph, property, enumeration);
73                     } else {
74                         return new VariableModifier2(graph, property);
75                     }
76
77                 }
78             }
79         }
80
81         return null;
82
83     }
84
85 }