1 /*******************************************************************************
2 * Copyright (c) 2007, 2013 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 * Semantum Oy - issue #4262
12 *******************************************************************************/
13 package org.simantics.charts.ui;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17 import org.simantics.Simantics;
18 import org.simantics.charts.Activator;
19 import org.simantics.charts.ontology.ChartResource;
20 import org.simantics.databoard.Bindings;
21 import org.simantics.db.Resource;
22 import org.simantics.db.WriteGraph;
23 import org.simantics.db.common.request.WriteResultRequest;
24 import org.simantics.db.common.utils.NameUtils;
25 import org.simantics.db.exception.DatabaseException;
26 import org.simantics.db.layer0.adapter.ActionFactory;
27 import org.simantics.layer0.Layer0;
30 * @author Tuukka Lehtonen
32 public class NewChartGroup implements ActionFactory {
35 public Runnable create(Object target) {
36 if(!(target instanceof Resource))
38 final Resource parent = (Resource)target;
40 return new Runnable() {
44 createChartGroup(parent);
45 } catch (DatabaseException e) {
46 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to create chart group.", e));
52 public static Resource createChartGroup (final Resource target) throws DatabaseException {
54 return Simantics.getSession().syncRequest(new WriteResultRequest<Resource>() {
56 public Resource perform(WriteGraph g) throws DatabaseException {
58 Layer0 l0 = Layer0.getInstance(g);
59 ChartResource wr = ChartResource.getInstance(g);
60 String freshName = NameUtils.findFreshName(g, "Chart Group", target);
61 Resource chart = g.newResource();
62 g.claim(chart, l0.InstanceOf, null, wr.ChartGroup);
63 g.claimLiteral(chart, l0.HasName, freshName, Bindings.STRING);
64 g.claim(chart, l0.PartOf, target);