X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.template2d.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Ftemplate2d%2Fui%2Factions%2FNewDrawingTemplate.java;h=f917bf25f8014f841e95e912e3ad8285c4610a71;hb=e88be95edf1f80781646cfdf717ec1b663264179;hp=62f0cbf9b887fcb35a576506c0b966d2ba5a3e14;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/actions/NewDrawingTemplate.java b/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/actions/NewDrawingTemplate.java index 62f0cbf9b..f917bf25f 100644 --- a/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/actions/NewDrawingTemplate.java +++ b/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/actions/NewDrawingTemplate.java @@ -1,113 +1,113 @@ -/******************************************************************************* - * Copyright (c) 2012 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 - *******************************************************************************/ -package org.simantics.modeling.template2d.ui.actions; - -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.CommentMetadata; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.common.utils.NameUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.adapter.ActionFactory; -import org.simantics.diagram.stubs.G2DResource; -import org.simantics.layer0.Layer0; -import org.simantics.modeling.template2d.ontology.Template2dResource; -import org.simantics.ui.SimanticsUI; - -public class NewDrawingTemplate 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() { - SimanticsUI.getSession().asyncRequest(new WriteRequest() { - @Override - public void perform(WriteGraph g) throws DatabaseException { - g.markUndoPoint(); - - createDrawingTemplate(g, parent); - } - }); - } - }; - } - - public static Resource createDrawingTemplate (WriteGraph g, Resource parent) throws DatabaseException { - - Layer0 L0 = Layer0.getInstance(g); - Template2dResource TEMPLATE2D = Template2dResource.getInstance(g); - G2DResource G2D = G2DResource.getInstance(g); - - Resource template = g.newResource(); - String name = NameUtils.findFreshName(g, "Template", parent, L0.ConsistsOf); - g.claim(template, L0.InstanceOf, null, TEMPLATE2D.DrawingTemplate); - g.claim(template, L0.InstanceOf, null, TEMPLATE2D.DrawingTemplateUI); - g.addLiteral(template, L0.HasName, L0.NameOf, L0.String, name, Bindings.STRING); - g.addLiteral(template, L0.HasLabel, L0.HasLabel_Inverse, L0.String, name, Bindings.STRING); - g.claim(template, L0.PartOf, parent); - - Resource page = g.newResource(); - name = NameUtils.findFreshName(g, "Page", template, L0.ConsistsOf); - g.claim(page, L0.InstanceOf, null, TEMPLATE2D.Page); - g.claim(page, L0.InstanceOf, null, TEMPLATE2D.BrowseNode); - g.addLiteral(page, L0.HasName, L0.NameOf, L0.String, name, Bindings.STRING); - g.addLiteral(page, L0.HasLabel, L0.HasLabel_Inverse, L0.String, name, Bindings.STRING); - g.claim(page, L0.PartOf, template); - //OrderedSetUtils.add(g, template, page); - g.claim(template, TEMPLATE2D.HasPage, page); - - g.claimLiteral(template, TEMPLATE2D.HasMargin, new float[]{10.0f, 10.0f, 10.0f, 10.0f}, Bindings.FLOAT_ARRAY); - - g.claim(template, TEMPLATE2D.HasPageOrientation, TEMPLATE2D.PageOrientation_Landscape); - - // Border is deprecated. -// Resource border = g.newResource(); -// name = NameUtils.findFreshName(g, "Border", template, L0.ConsistsOf); -// g.claim(border, L0.InstanceOf, null, TEMPLATE2D.Border); -// g.claim(border, L0.InstanceOf, null, TEMPLATE2D.BorderUI); -// g.addLiteral(border, L0.HasName, L0.NameOf, L0.String, name, Bindings.STRING); -// g.addLiteral(border, L0.HasLabel, L0.HasLabel_Inverse, L0.String, name, Bindings.STRING); -// g.claim(border, L0.PartOf, template); -// g.claim(template, TEMPLATE2D.HasBorder, border); -// g.claimLiteral(border, TEMPLATE2D.HasSize, new float[]{0.3f, 0.3f, 0.3f, 0.3f}, Bindings.FLOAT_ARRAY); -// -// Resource color = G2DUtils.createColor(g, new Color(0.0f, 0.0f, 0.0f, 1.0f)); -// g.claim(border, G2D.HasColor, color);//new RGB.Integer(255,255,255), RGB.Integer.BINDING); - -// ViewsResources VIEW = ViewsResources.getInstance(g); -// Resource sg = g.newResource(); -// g.claim(sg, L0.InstanceOf, null, VIEW.Text); -// g.addLiteral(sg, L0.HasName, L0.NameOf, L0.String, "SG", Bindings.STRING); -// g.claimLiteral(sg, VIEW.TextContainer_text, "SG", Bindings.STRING); -// g.claim(template, TEMPLATE2D.HasScenegraph, sg); -// g.claim(template, L0.ConsistsOf, sg); - - CommentMetadata cm = g.getMetadata(CommentMetadata.class); - g.addMetadata(cm.add("Create New Diagram Template.")); - - return template; - } - - public static Resource getDrawingTemplateLibrary(ReadGraph graph, Resource model) throws DatabaseException { - - Template2dResource TEMPLATE2D = Template2dResource.getInstance(graph); - Resource library = graph.getSingleObject(model, TEMPLATE2D.HasDrawingTemplateRoot); - return library; - } -} +/******************************************************************************* + * Copyright (c) 2012 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 + *******************************************************************************/ +package org.simantics.modeling.template2d.ui.actions; + +import org.simantics.Simantics; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.CommentMetadata; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.template2d.ontology.Template2dResource; + +public class NewDrawingTemplate 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() { + Simantics.getSession().asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); + + createDrawingTemplate(g, parent); + } + }); + } + }; + } + + public static Resource createDrawingTemplate (WriteGraph g, Resource parent) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(g); + Template2dResource TEMPLATE2D = Template2dResource.getInstance(g); + G2DResource G2D = G2DResource.getInstance(g); + + Resource template = g.newResource(); + String name = NameUtils.findFreshName(g, "Template", parent, L0.ConsistsOf); + g.claim(template, L0.InstanceOf, null, TEMPLATE2D.DrawingTemplate); + g.claim(template, L0.InstanceOf, null, TEMPLATE2D.DrawingTemplateUI); + g.addLiteral(template, L0.HasName, L0.NameOf, L0.String, name, Bindings.STRING); + g.addLiteral(template, L0.HasLabel, L0.HasLabel_Inverse, L0.String, name, Bindings.STRING); + g.claim(template, L0.PartOf, parent); + + Resource page = g.newResource(); + name = NameUtils.findFreshName(g, "Page", template, L0.ConsistsOf); + g.claim(page, L0.InstanceOf, null, TEMPLATE2D.Page); + g.claim(page, L0.InstanceOf, null, TEMPLATE2D.BrowseNode); + g.addLiteral(page, L0.HasName, L0.NameOf, L0.String, name, Bindings.STRING); + g.addLiteral(page, L0.HasLabel, L0.HasLabel_Inverse, L0.String, name, Bindings.STRING); + g.claim(page, L0.PartOf, template); + //OrderedSetUtils.add(g, template, page); + g.claim(template, TEMPLATE2D.HasPage, page); + + g.claimLiteral(template, TEMPLATE2D.HasMargin, new float[]{10.0f, 10.0f, 10.0f, 10.0f}, Bindings.FLOAT_ARRAY); + + g.claim(template, TEMPLATE2D.HasPageOrientation, TEMPLATE2D.PageOrientation_Landscape); + + // Border is deprecated. +// Resource border = g.newResource(); +// name = NameUtils.findFreshName(g, "Border", template, L0.ConsistsOf); +// g.claim(border, L0.InstanceOf, null, TEMPLATE2D.Border); +// g.claim(border, L0.InstanceOf, null, TEMPLATE2D.BorderUI); +// g.addLiteral(border, L0.HasName, L0.NameOf, L0.String, name, Bindings.STRING); +// g.addLiteral(border, L0.HasLabel, L0.HasLabel_Inverse, L0.String, name, Bindings.STRING); +// g.claim(border, L0.PartOf, template); +// g.claim(template, TEMPLATE2D.HasBorder, border); +// g.claimLiteral(border, TEMPLATE2D.HasSize, new float[]{0.3f, 0.3f, 0.3f, 0.3f}, Bindings.FLOAT_ARRAY); +// +// Resource color = G2DUtils.createColor(g, new Color(0.0f, 0.0f, 0.0f, 1.0f)); +// g.claim(border, G2D.HasColor, color);//new RGB.Integer(255,255,255), RGB.Integer.BINDING); + +// ViewsResources VIEW = ViewsResources.getInstance(g); +// Resource sg = g.newResource(); +// g.claim(sg, L0.InstanceOf, null, VIEW.Text); +// g.addLiteral(sg, L0.HasName, L0.NameOf, L0.String, "SG", Bindings.STRING); +// g.claimLiteral(sg, VIEW.TextContainer_text, "SG", Bindings.STRING); +// g.claim(template, TEMPLATE2D.HasScenegraph, sg); +// g.claim(template, L0.ConsistsOf, sg); + + CommentMetadata cm = g.getMetadata(CommentMetadata.class); + g.addMetadata(cm.add("Create New Diagram Template.")); + + return template; + } + + public static Resource getDrawingTemplateLibrary(ReadGraph graph, Resource model) throws DatabaseException { + + Template2dResource TEMPLATE2D = Template2dResource.getInstance(graph); + Resource library = graph.getSingleObject(model, TEMPLATE2D.HasDrawingTemplateRoot); + return library; + } +}