1 /*******************************************************************************
2 * Copyright (c) 2012 Association for Decentralized Information Management in
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 *******************************************************************************/
12 package org.simantics.modeling.template2d.ui.actions;
14 import java.util.Arrays;
16 import org.simantics.databoard.Bindings;
17 import org.simantics.datatypes.DatatypeResource;
18 import org.simantics.datatypes.literal.Font;
19 import org.simantics.datatypes.literal.RGB;
20 import org.simantics.db.Resource;
21 import org.simantics.db.WriteGraph;
22 import org.simantics.db.common.request.WriteRequest;
23 import org.simantics.db.common.utils.ListUtils;
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.diagram.stubs.DiagramResource;
28 import org.simantics.diagram.stubs.G2DResource;
29 import org.simantics.layer0.Layer0;
30 import org.simantics.modeling.template2d.ontology.Template2dResource;
31 import org.simantics.scenegraph.ontology.ScenegraphResources;
32 import org.simantics.ui.SimanticsUI;
35 * @author Teemu Matasniemi
37 public class NewFlagTableColumnData implements ActionFactory {
40 public Runnable create(Object target) {
41 if(!(target instanceof Resource))
43 final Resource parent = (Resource)target;
45 return new Runnable() {
48 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
50 public void perform(WriteGraph g) throws DatabaseException {
53 Layer0 L0 = Layer0.getInstance(g);
54 Template2dResource TEMPLATE2D = Template2dResource.getInstance(g);
55 DiagramResource DIA = DiagramResource.getInstance(g);
56 DatatypeResource DATA = DatatypeResource.getInstance(g);
57 G2DResource G2D = G2DResource.getInstance(g);
58 ScenegraphResources SG = ScenegraphResources.getInstance(g);
60 Resource monitor = g.newResource();
61 // g.claim(monitor, L0.InstanceOf, null, DIA.Scenegraph_Monitor);
62 g.claim(monitor, L0.InstanceOf, null, TEMPLATE2D.FlagTable_Column_Data);
63 g.claim(monitor, L0.InstanceOf, null, TEMPLATE2D.FlagTableUI_ColumnUI_DataUI);
64 String name = NameUtils.findFreshName(g, "Data", parent, L0.ConsistsOf);
65 g.addLiteral(monitor, L0.HasName, L0.NameOf, L0.String, name, Bindings.STRING);
66 g.addLiteral(monitor, DIA.Scenegraph_Monitor_reference, DIA.Scenegraph_Monitor_reference_Inverse, "#HasLabel", Bindings.STRING);
67 g.addLiteral(monitor, DIA.Scenegraph_AbstractText_color, DIA.Scenegraph_AbstractText_color_Inverse, DATA.RGB_Integer, new RGB.Integer(0,0,0), Bindings.getBindingUnchecked(RGB.Integer.class));
68 g.addLiteral(monitor, DIA.Scenegraph_AbstractText_font, DIA.Scenegraph_AbstractText_font_Inverse, DATA.Font, new Font("Arial", 3, "Normal"), Bindings.getBindingUnchecked(Font.class));
69 g.addLiteral(monitor, DIA.Scenegraph_AbstractText_transform, DIA.Scenegraph_AbstractText_transform_Inverse, G2D.Transform, new Double[] { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, Bindings.getBindingUnchecked(Double[].class));
70 g.claim(monitor, L0.PartOf, parent);
71 Resource list = g.getPossibleObject(parent, SG.Node_children);
73 ListUtils.insertBack(g, list, Arrays.asList(monitor));