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.properties.widgets.externalFiles;
\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.IModifiableNode;
\r
18 import org.simantics.browsing.ui.content.Labeler.Modifier;
\r
19 import org.simantics.browsing.ui.graph.impl.LabelModifier;
\r
20 import org.simantics.db.Resource;
\r
21 import org.simantics.db.WriteGraph;
\r
22 import org.simantics.db.common.request.WriteRequest;
\r
23 import org.simantics.db.exception.DatabaseException;
\r
24 import org.simantics.db.layer0.util.RemoverUtil;
\r
25 import org.simantics.db.request.Write;
\r
26 import org.simantics.layer0.Layer0;
\r
27 import org.simantics.sysdyn.manager.FunctionUtils;
\r
28 import org.simantics.ui.SimanticsUI;
\r
30 public class ExternalFileNode extends AbstractNode<Resource> implements IModifiableNode, IDeletableNode {
\r
32 public ExternalFileNode(Resource data) {
\r
37 public Modifier getModifier(String columnId) {
\r
39 final Resource hasName = Layer0.getInstance(SimanticsUI.getSession()).HasName;
\r
40 LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), data, hasName) {
\r
42 public String isValid(String label) {
\r
43 if (label.isEmpty())
\r
44 return "Empty label not allowed";
\r
45 if (label.contains(" "))
\r
46 return "Spaces are not allowed";
\r
51 protected Write getWriteRequest(final String label) {
\r
52 return new WriteRequest() {
\r
54 public void perform(WriteGraph g) throws DatabaseException {
\r
55 FunctionUtils.removeExternalFunctionFile(g, data);
\r
56 g.claimLiteral(data, hasName, label);
\r
57 FunctionUtils.createExternalFunctionFile(g, data);
\r
63 } catch (DatabaseException e) {
\r
64 e.printStackTrace();
\r
70 public void delete() throws DeleteException {
\r
71 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
\r
74 public void perform(WriteGraph graph) throws DatabaseException {
\r
75 FunctionUtils.removeExternalFunctionFile(graph, data);
\r
76 RemoverUtil.remove(graph, data);
\r