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 java.io.File;
\r
16 import org.simantics.browsing.ui.common.node.AbstractNode;
\r
17 import org.simantics.browsing.ui.common.node.DeleteException;
\r
18 import org.simantics.browsing.ui.common.node.IDeletableNode;
\r
19 import org.simantics.browsing.ui.common.node.IDoubleClickableNode;
\r
20 import org.simantics.browsing.ui.common.node.IModifiableNode;
\r
21 import org.simantics.browsing.ui.content.Labeler.Modifier;
\r
22 import org.simantics.browsing.ui.graph.impl.LabelModifier;
\r
23 import org.simantics.db.Resource;
\r
24 import org.simantics.db.WriteGraph;
\r
25 import org.simantics.db.common.request.WriteRequest;
\r
26 import org.simantics.db.exception.CancelTransactionException;
\r
27 import org.simantics.db.exception.DatabaseException;
\r
28 import org.simantics.db.layer0.util.RemoverUtil;
\r
29 import org.simantics.sysdyn.SysdynResource;
\r
30 import org.simantics.sysdyn.ui.handlers.ToggleResultActivation;
\r
31 import org.simantics.ui.SimanticsUI;
\r
32 import org.simantics.utils.ui.ExceptionUtils;
\r
34 public class SimulationResultNode<T> extends AbstractNode<Resource> implements IDoubleClickableNode, IDeletableNode, IModifiableNode {
\r
36 public SimulationResultNode(Resource resource) {
\r
42 public Modifier getModifier(String columnId) {
\r
43 LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), data) {
\r
45 public String isValid(String label) {
\r
46 if (label.isEmpty())
\r
47 return "Empty label not allowed";
\r
56 public void delete() throws DeleteException {
\r
58 SimanticsUI.getSession().syncRequest(new WriteRequest() {
\r
60 public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {
\r
61 unlinkResult(graph, data);
\r
64 } catch (DatabaseException e) {
\r
65 ExceptionUtils.logAndShowError(e);
\r
71 public static void unlinkResult(WriteGraph graph, Resource result) throws DatabaseException {
\r
72 deleteResultFiles(graph, result);
\r
73 RemoverUtil.remove(graph, result);
\r
76 public static void deleteResultFiles(WriteGraph graph, Resource result) throws DatabaseException {
\r
78 path = graph.getPossibleRelatedValue(result, SysdynResource.getInstance(graph).Result_resultFile);
\r
80 File file = new File(path);
\r
82 File parent = file.getParentFile();
\r
83 if(parent.listFiles() != null && parent.listFiles().length == 0)
\r
90 public boolean handleDoubleClick() {
\r
91 Resource[] resources = {data};
\r
92 ToggleResultActivation.toggleActivation(resources);
\r