1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 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.selectionview;
14 import java.util.List;
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;
26 * @author Tuukka Lehtonen
28 public class VariablePropertyModifierRule implements ModifierRule {
31 public boolean isCompatible(Class<?> contentType) {
32 return contentType.equals(Variable.class);
36 public Modifier getModifier(ReadGraph graph, Object _content, String columnKey_) throws DatabaseException {
38 if (!(_content instanceof Variable))
41 Variable content = (Variable)_content;
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))
48 String columnKey = columnKey_;
49 if(columnKey.startsWith("#")) columnKey = columnKey.substring(1);
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))
59 for (Variable property : content.getProperties(graph)) {
60 String column = property.getPossiblePropertyValue(graph, Variables.DISPLAY_COLUMN);
62 if (columnKey.equals(column)) {
64 if(columnKey_.startsWith("#"))
65 return new VariableModifier2(graph, property);
67 Modifier custom = property.getPossiblePropertyValue(graph, Variables.CUSTOM_MODIFIER);
68 if (custom != null) return custom;
70 List<String> enumeration = property.getPossiblePropertyValue(graph, Variables.ENUMERATION_VALUES);
71 if (enumeration != null) {
72 return new EnumerationVariableModifier3(graph, property, enumeration);
74 return new VariableModifier2(graph, property);