1 /*******************************************************************************
\r
2 * Copyright (c) 2010, 2012 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.browser.nodes;
\r
14 import org.simantics.browsing.ui.common.node.AbstractNode;
\r
15 import org.simantics.browsing.ui.common.node.DeleteException;
\r
16 import org.simantics.browsing.ui.common.node.IDeletableNode;
\r
17 import org.simantics.browsing.ui.common.node.IDoubleClickableNode;
\r
18 import org.simantics.browsing.ui.common.node.IModifiableNode;
\r
19 import org.simantics.browsing.ui.content.Labeler.Modifier;
\r
20 import org.simantics.browsing.ui.graph.impl.LabelModifier;
\r
21 import org.simantics.db.Resource;
\r
22 import org.simantics.db.WriteGraph;
\r
23 import org.simantics.db.common.request.ObjectsWithType;
\r
24 import org.simantics.db.common.request.WriteRequest;
\r
25 import org.simantics.db.exception.CancelTransactionException;
\r
26 import org.simantics.db.exception.DatabaseException;
\r
27 import org.simantics.db.layer0.util.RemoverUtil;
\r
28 import org.simantics.sysdyn.SysdynResource;
\r
29 import org.simantics.sysdyn.ui.handlers.ToggleResultSetActivation;
\r
30 import org.simantics.ui.SimanticsUI;
\r
31 import org.simantics.utils.ui.ExceptionUtils;
\r
33 public class SimulationResultSetNode extends AbstractNode<Resource> implements IDoubleClickableNode, IDeletableNode, IModifiableNode {
\r
35 public SimulationResultSetNode(Resource resource) {
\r
41 public Modifier getModifier(String columnId) {
\r
42 LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), data) {
\r
44 public String isValid(String label) {
\r
45 if (label.isEmpty())
\r
46 return "Empty label not allowed";
\r
55 public void delete() throws DeleteException {
\r
57 SimanticsUI.getSession().syncRequest(new WriteRequest() {
\r
59 public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {
\r
60 unlinkResultSet(graph, data);
\r
63 } catch (DatabaseException e) {
\r
64 ExceptionUtils.logAndShowError(e);
\r
70 public static void unlinkResultSet(WriteGraph graph, Resource resultSet) throws DatabaseException {
\r
71 SysdynResource sr = SysdynResource.getInstance(graph);
\r
72 for (Resource result : graph.syncRequest(new ObjectsWithType(resultSet, sr.Experiment_result, sr.Result))) {
\r
73 SimulationResultNode.unlinkResult(graph, result);
\r
75 RemoverUtil.remove(graph, resultSet);
\r
79 public boolean handleDoubleClick() {
\r
80 Resource[] resources = {data};
\r
81 ToggleResultSetActivation.toggleActivation(resources);
\r