1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 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.sysdyn.ui.trend.chart.properties;
\r
14 import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;
\r
15 import org.simantics.databoard.Bindings;
\r
16 import org.simantics.db.Resource;
\r
17 import org.simantics.db.WriteGraph;
\r
18 import org.simantics.db.common.request.ObjectsWithType;
\r
19 import org.simantics.db.exception.DatabaseException;
\r
20 import org.simantics.db.management.ISessionContext;
\r
21 import org.simantics.layer0.Layer0;
\r
24 * Class for setting a boolean value when a selection occurs. (check box buttons)
\r
26 * @author Teemu Lempinen
\r
29 public class BooleanSelectionListener extends SelectionListenerImpl<Resource> {
\r
31 final private String propertyURI;
\r
32 final private String typeUri;
\r
35 * Boolean selection listener for property with propertyURI
\r
37 * @param context ISessionContext
\r
38 * @param propertyURI uri of the boolean property
\r
40 public BooleanSelectionListener(ISessionContext context, String propertyURI) {
\r
41 this(context, null, propertyURI);
\r
45 * Boolean selection listener for property with propertyURI
\r
46 * Sets the property for all ObjectWithType(resource, L0.ConsistsOf, type)
\r
48 * @param context ISessionContext
\r
49 * @param typeUri URI for a resource (resource ConsistsOf type) (null allowed -> not used)
\r
50 * @param propertyURI uri of the boolean property
\r
52 public BooleanSelectionListener(ISessionContext context, String typeUri, String propertyURI) {
\r
54 this.propertyURI = propertyURI;
\r
55 this.typeUri = typeUri;
\r
59 public void apply(WriteGraph graph, Resource chart) throws DatabaseException {
\r
60 if(typeUri == null) {
\r
61 setValue(graph, chart);
\r
63 Resource type = graph.getResource(typeUri);
\r
64 for(Resource object : graph.syncRequest(new ObjectsWithType(chart, Layer0.getInstance(graph).ConsistsOf, type))) {
\r
65 setValue(graph, object);
\r
72 * Set boolean value for Boolean literal resource (inverts the current value).
\r
73 * @param graph ReadGraph
\r
74 * @param resource Boolean literal resource
\r
75 * @throws DatabaseException
\r
77 private void setValue(WriteGraph graph, Resource resource) throws DatabaseException {
\r
78 Resource property = graph.getResource(propertyURI);
\r
79 Boolean value = graph.getPossibleRelatedValue(resource, property, Bindings.BOOLEAN);
\r
80 graph.claimLiteral(resource, property, Boolean.FALSE.equals(value));
\r