1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 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.actions.newActions;
\r
14 import java.util.UUID;
\r
16 import org.simantics.db.Resource;
\r
17 import org.simantics.db.WriteGraph;
\r
18 import org.simantics.db.common.request.WriteRequest;
\r
19 import org.simantics.db.common.utils.NameUtils;
\r
20 import org.simantics.db.exception.DatabaseException;
\r
21 import org.simantics.db.layer0.adapter.ActionFactory;
\r
22 import org.simantics.layer0.Layer0;
\r
23 import org.simantics.layer0.utils.direct.GraphUtils;
\r
24 import org.simantics.sysdyn.SysdynResource;
\r
25 import org.simantics.ui.SimanticsUI;
\r
28 * Create a new history data
\r
30 * @author Teemu Lempinen
\r
33 public class NewHistoryDataAction implements ActionFactory{
\r
36 public Runnable create(Object target) {
\r
37 if(!(target instanceof Resource))
\r
39 final Resource experiment = (Resource)target;
\r
41 return new Runnable() {
\r
45 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
\r
48 public void perform(WriteGraph graph) throws DatabaseException {
\r
49 SysdynResource sr = SysdynResource.getInstance(graph);
\r
50 Layer0 l0 = Layer0.getInstance(graph);
\r
51 if(!graph.isInstanceOf(experiment, sr.Experiment))
\r
52 return; // Not called from an experiment
\r
54 Resource model = graph.getPossibleObject(experiment, l0.PartOf);
\r
55 // Create the history dataset
\r
56 GraphUtils.create2(graph,
\r
58 l0.HasName, "HistoryDataset" + UUID.randomUUID().toString(),
\r
59 l0.HasLabel, NameUtils.findFreshLabel(graph, "History Dataset", experiment),
\r
60 sr.Experiment_result_Inverse, experiment,
\r
61 sr.HistoryDataset_columns, Boolean.TRUE,
\r