X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.charts%2Fsrc%2Forg%2Fsimantics%2Fcharts%2Fui%2FNewChartGroup.java;fp=bundles%2Forg.simantics.charts%2Fsrc%2Forg%2Fsimantics%2Fcharts%2Fui%2FNewChartGroup.java;h=f2dfbcd5b529abf7e4343d1cdb5bcb380f7bf94e;hp=8072df28d820d55b55da1bd9d001246a79b2ec28;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.charts/src/org/simantics/charts/ui/NewChartGroup.java b/bundles/org.simantics.charts/src/org/simantics/charts/ui/NewChartGroup.java index 8072df28d..f2dfbcd5b 100644 --- a/bundles/org.simantics.charts/src/org/simantics/charts/ui/NewChartGroup.java +++ b/bundles/org.simantics.charts/src/org/simantics/charts/ui/NewChartGroup.java @@ -1,71 +1,71 @@ -/******************************************************************************* - * Copyright (c) 2007, 2013 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - * Semantum Oy - issue #4262 - *******************************************************************************/ -package org.simantics.charts.ui; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.simantics.Simantics; -import org.simantics.charts.Activator; -import org.simantics.charts.ontology.ChartResource; -import org.simantics.databoard.Bindings; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteResultRequest; -import org.simantics.db.common.utils.NameUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.adapter.ActionFactory; -import org.simantics.layer0.Layer0; - -/** - * @author Tuukka Lehtonen - */ -public class NewChartGroup implements ActionFactory { - - @Override - public Runnable create(Object target) { - if(!(target instanceof Resource)) - return null; - final Resource parent = (Resource)target; - - return new Runnable() { - @Override - public void run() { - try { - createChartGroup(parent); - } catch (DatabaseException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to create chart group.", e)); - } - } - }; - } - - public static Resource createChartGroup (final Resource target) throws DatabaseException { - - return Simantics.getSession().syncRequest(new WriteResultRequest() { - @Override - public Resource perform(WriteGraph g) throws DatabaseException { - g.markUndoPoint(); - Layer0 l0 = Layer0.getInstance(g); - ChartResource wr = ChartResource.getInstance(g); - String freshName = NameUtils.findFreshName(g, "Chart Group", target); - Resource chart = g.newResource(); - g.claim(chart, l0.InstanceOf, null, wr.ChartGroup); - g.claimLiteral(chart, l0.HasName, freshName, Bindings.STRING); - g.claim(chart, l0.PartOf, target); - return chart; - } - }); - - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2013 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + * Semantum Oy - issue #4262 + *******************************************************************************/ +package org.simantics.charts.ui; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.simantics.Simantics; +import org.simantics.charts.Activator; +import org.simantics.charts.ontology.ChartResource; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.layer0.Layer0; + +/** + * @author Tuukka Lehtonen + */ +public class NewChartGroup implements ActionFactory { + + @Override + public Runnable create(Object target) { + if(!(target instanceof Resource)) + return null; + final Resource parent = (Resource)target; + + return new Runnable() { + @Override + public void run() { + try { + createChartGroup(parent); + } catch (DatabaseException e) { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to create chart group.", e)); + } + } + }; + } + + public static Resource createChartGroup (final Resource target) throws DatabaseException { + + return Simantics.getSession().syncRequest(new WriteResultRequest() { + @Override + public Resource perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); + Layer0 l0 = Layer0.getInstance(g); + ChartResource wr = ChartResource.getInstance(g); + String freshName = NameUtils.findFreshName(g, "Chart Group", target); + Resource chart = g.newResource(); + g.claim(chart, l0.InstanceOf, null, wr.ChartGroup); + g.claimLiteral(chart, l0.HasName, freshName, Bindings.STRING); + g.claim(chart, l0.PartOf, target); + return chart; + } + }); + + } + +}