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.handlers.newComponents;
\r
14 import java.util.UUID;
\r
16 import org.eclipse.core.commands.AbstractHandler;
\r
17 import org.eclipse.core.commands.ExecutionEvent;
\r
18 import org.eclipse.core.commands.ExecutionException;
\r
19 import org.eclipse.jface.viewers.ISelection;
\r
20 import org.eclipse.ui.handlers.HandlerUtil;
\r
21 import org.simantics.db.Resource;
\r
22 import org.simantics.db.WriteGraph;
\r
23 import org.simantics.db.common.request.WriteRequest;
\r
24 import org.simantics.db.common.utils.NameUtils;
\r
25 import org.simantics.db.exception.DatabaseException;
\r
26 import org.simantics.layer0.Layer0;
\r
27 import org.simantics.layer0.utils.direct.GraphUtils;
\r
28 import org.simantics.sysdyn.SysdynResource;
\r
29 import org.simantics.ui.SimanticsUI;
\r
30 import org.simantics.ui.utils.AdaptionUtils;
\r
33 * Handler for creating new history dataset
\r
34 * @author Teemu Lempinen
\r
37 public class NewHistoryDataHandler extends AbstractHandler {
\r
40 public Object execute(ExecutionEvent event) throws ExecutionException {
\r
42 ISelection sel = HandlerUtil.getCurrentSelection(event);
\r
44 final Resource experiment = AdaptionUtils.adaptToSingle(sel, Resource.class);
\r
46 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
\r
49 public void perform(WriteGraph g) throws DatabaseException {
\r
50 SysdynResource sr = SysdynResource.getInstance(g);
\r
51 Layer0 l0 = Layer0.getInstance(g);
\r
52 if(!g.isInstanceOf(experiment, sr.Experiment))
\r
53 return; // Not called from an experiment
\r
55 Resource model = g.getPossibleObject(experiment, l0.PartOf);
\r
56 // Create the history dataset
\r
57 GraphUtils.create2(g,
\r
59 l0.HasName, "HistoryDataset" + UUID.randomUUID().toString(),
\r
60 l0.HasLabel, NameUtils.findFreshLabel(g, "History Dataset", experiment),
\r
61 sr.Experiment_result_Inverse, experiment,
\r
62 sr.HistoryDataset_columns, Boolean.TRUE,
\r