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 org.simantics.db.ReadGraph;
\r
15 import org.simantics.db.Resource;
\r
16 import org.simantics.db.WriteGraph;
\r
17 import org.simantics.db.common.request.WriteRequest;
\r
18 import org.simantics.db.common.utils.NameUtils;
\r
19 import org.simantics.db.exception.DatabaseException;
\r
20 import org.simantics.db.layer0.adapter.ActionFactory;
\r
21 import org.simantics.layer0.Layer0;
\r
22 import org.simantics.layer0.utils.direct.GraphUtils;
\r
23 import org.simantics.sysdyn.SysdynResource;
\r
24 import org.simantics.ui.SimanticsUI;
\r
27 * Creates a new basic experiment
\r
28 * @author Teemu Lempinen
\r
31 public class NewExperimentAction implements ActionFactory{
\r
34 public Runnable create(Object target) {
\r
35 if(!(target instanceof Resource))
\r
37 final Resource model = (Resource)target;
\r
39 return new Runnable() {
\r
44 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
\r
47 public void perform(WriteGraph graph) throws DatabaseException {
\r
48 Layer0 l0 = Layer0.getInstance(graph);
\r
49 String name = NameUtils.findFreshName(graph, getNameSuggestion(), model, l0.ConsistsOf, "%s%d");
\r
51 Resource experiment = GraphUtils.create2(graph, getExperimentType(graph),
\r
56 configureExperiment(graph, experiment);
\r
64 * Override to do experiment-specific alterations
\r
66 protected void configureExperiment(WriteGraph graph, Resource experiment) throws DatabaseException {
\r
71 * Get the type of this experiment.
\r
73 * @param g ReadGraph
\r
74 * @return The type resource of this experiment
\r
76 protected Resource getExperimentType(ReadGraph g) {
\r
77 return SysdynResource.getInstance(g).BasicExperiment;
\r
81 * Returns the suggested name for this experiment.
\r
82 * If the name has already been taken, appropriate prefix needs to be added.
\r
84 * @return Suggested name for this experiment.
\r
86 protected String getNameSuggestion() {
\r
87 return "Experiment";
\r