1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\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.document.ui.actions;
\r
14 import org.simantics.db.ReadGraph;
\r
15 import org.simantics.db.Resource;
\r
16 import org.simantics.db.WriteGraph;
\r
17 import org.simantics.db.exception.DatabaseException;
\r
18 import org.simantics.db.layer0.adapter.ActionFactory;
\r
19 import org.simantics.document.DocumentResource;
\r
20 import org.simantics.document.ui.graphfile.DocumentVersionUtils;
\r
21 import org.simantics.document.ui.graphfile.FileDocumentUtil;
\r
24 * Abstract base class for adding documents.
\r
26 * If import target is an document, a new version of a document is created.
\r
28 * Document version creation has two modes:
\r
29 * FLAT: new version is added to the same library as the old document.
\r
30 * TREE: new version replaces the old document in the library, and old document is moved under the new document.
\r
33 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
\r
36 public abstract class AddDocumentAction implements ActionFactory {
\r
41 private Resource relation;
\r
43 public AddDocumentAction(ReadGraph graph, String relationUri) throws DatabaseException {
\r
44 relation = graph.getResource(relationUri);
\r
48 protected Resource getRelation() {
\r
52 protected void linkDocument(WriteGraph graph, Resource target, Resource newDocument) throws DatabaseException{
\r
53 DocumentResource doc = DocumentResource.getInstance(graph);
\r
55 if (graph.isInstanceOf(target, doc.Document)) {
\r
56 // adding a new revision
\r
57 DocumentVersionUtils.createNewVersion(graph, target, newDocument, relation);
\r
61 graph.claim(target, relation, newDocument);
\r
62 FileDocumentUtil.createUniqueName(graph, newDocument);
\r