1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2013 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\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 * Semantum Oy - issue #4262
\r
12 *******************************************************************************/
\r
13 package org.simantics.charts.ui;
\r
15 import org.eclipse.core.runtime.IStatus;
\r
16 import org.eclipse.core.runtime.Status;
\r
17 import org.simantics.Simantics;
\r
18 import org.simantics.charts.Activator;
\r
19 import org.simantics.charts.ontology.ChartResource;
\r
20 import org.simantics.databoard.Bindings;
\r
21 import org.simantics.db.Resource;
\r
22 import org.simantics.db.WriteGraph;
\r
23 import org.simantics.db.common.request.WriteResultRequest;
\r
24 import org.simantics.db.common.utils.NameUtils;
\r
25 import org.simantics.db.exception.DatabaseException;
\r
26 import org.simantics.db.layer0.adapter.ActionFactory;
\r
27 import org.simantics.layer0.Layer0;
\r
30 * @author Tuukka Lehtonen
\r
32 public class NewChartGroup implements ActionFactory {
\r
35 public Runnable create(Object target) {
\r
36 if(!(target instanceof Resource))
\r
38 final Resource parent = (Resource)target;
\r
40 return new Runnable() {
\r
44 createChartGroup(parent);
\r
45 } catch (DatabaseException e) {
\r
46 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to create chart group.", e));
\r
52 public static Resource createChartGroup (final Resource target) throws DatabaseException {
\r
54 return Simantics.getSession().syncRequest(new WriteResultRequest<Resource>() {
\r
56 public Resource perform(WriteGraph g) throws DatabaseException {
\r
58 Layer0 l0 = Layer0.getInstance(g);
\r
59 ChartResource wr = ChartResource.getInstance(g);
\r
60 String freshName = NameUtils.findFreshName(g, "Chart Group", target);
\r
61 Resource chart = g.newResource();
\r
62 g.claim(chart, l0.InstanceOf, null, wr.ChartGroup);
\r
63 g.claimLiteral(chart, l0.HasName, freshName, Bindings.STRING);
\r
64 g.claim(chart, l0.PartOf, target);
\r