1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\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 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.browser.nodes;
\r
14 import org.simantics.browsing.ui.common.node.AbstractNode;
\r
15 import org.simantics.browsing.ui.common.node.DeleteException;
\r
16 import org.simantics.browsing.ui.common.node.IDeletableNode;
\r
17 import org.simantics.browsing.ui.common.node.IDropTargetNode;
\r
18 import org.simantics.browsing.ui.common.node.IModifiableNode;
\r
19 import org.simantics.browsing.ui.content.Labeler.Modifier;
\r
20 import org.simantics.browsing.ui.graph.impl.LabelModifier;
\r
21 import org.simantics.db.Resource;
\r
22 import org.simantics.db.WriteGraph;
\r
23 import org.simantics.db.common.request.WriteRequest;
\r
24 import org.simantics.db.exception.DatabaseException;
\r
25 import org.simantics.db.layer0.util.RemoverUtil;
\r
26 import org.simantics.layer0.Layer0;
\r
27 import org.simantics.sysdyn.SysdynResource;
\r
28 import org.simantics.sysdyn.ui.utils.FunctionLibraryNameValidator;
\r
29 import org.simantics.ui.SimanticsUI;
\r
30 import org.simantics.ui.utils.ResourceAdaptionUtils;
\r
32 public class FunctionLibraryNode<T> extends AbstractNode<Resource> implements IDeletableNode, IModifiableNode, IDropTargetNode {
\r
35 public FunctionLibraryNode(Resource resource) {
\r
40 public Modifier getModifier(String columnId) {
\r
42 Resource hasName = Layer0.getInstance(SimanticsUI.getSession()).HasName;
\r
43 LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), data, hasName) {
\r
45 public String isValid(String label) {
\r
46 if (!new FunctionLibraryNameValidator().isValid(data, label))
\r
53 } catch (DatabaseException e) {
\r
54 e.printStackTrace();
\r
60 public void delete() throws DeleteException {
\r
61 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
\r
64 public void perform(WriteGraph graph) throws DatabaseException {
\r
65 RemoverUtil.remove(graph, data);
\r
71 public void drop(Object data) {
\r
72 final Resource[] resources = ResourceAdaptionUtils.toResources(data);
\r
73 final Resource library = this.data;
\r
74 if(resources.length > 0) {
\r
75 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
\r
78 public void perform(WriteGraph graph) throws DatabaseException {
\r
79 SysdynResource sr = SysdynResource.getInstance(graph);
\r
80 Layer0 l0 = Layer0.getInstance(graph);
\r
81 for(Resource tobeMoved : resources) {
\r
82 if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) ||
\r
83 graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) {
\r
84 graph.deny(tobeMoved, l0.PartOf);
\r
85 graph.claim(tobeMoved, l0.PartOf, library);
\r