1 /*******************************************************************************
\r
2 * Copyright (c) 2013 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.graphfile.hack;
\r
14 import java.io.File;
\r
15 import java.util.ArrayList;
\r
16 import java.util.List;
\r
18 import org.eclipse.core.runtime.IPath;
\r
19 import org.simantics.Simantics;
\r
20 import org.simantics.db.ReadGraph;
\r
21 import org.simantics.db.Resource;
\r
22 import org.simantics.db.common.request.ReadRequest;
\r
23 import org.simantics.db.exception.DatabaseException;
\r
24 import org.simantics.graphfile.ontology.GraphFileResource;
\r
25 import org.simantics.layer0.Layer0;
\r
27 public class GraphPath implements IPath {
\r
29 private GraphFile file;
\r
30 List<String> path = new ArrayList<String>();
\r
32 public GraphPath(GraphFile f) {
\r
35 Simantics.getSession().syncRequest(new ReadRequest() {
\r
38 public void run(ReadGraph graph) throws DatabaseException {
\r
39 Layer0 l0 = Layer0.getInstance(graph);
\r
40 GraphFileResource gf = GraphFileResource.getInstance(graph);
\r
41 Resource fileResource = file.getFileResource();
\r
42 Resource t = fileResource;
\r
44 t = graph.getPossibleObject(t, gf.PartOfSystemResource);
\r
46 path.add(0, (String)graph.getRelatedValue(t, l0.HasName));
\r
54 } catch (DatabaseException e) {
\r
55 throw new RuntimeException("Could not evaluate graph path",e);
\r
60 public IPath addFileExtension(String extension) {
\r
61 // TODO Auto-generated method stub
\r
66 public IPath addTrailingSeparator() {
\r
67 // TODO Auto-generated method stub
\r
72 public IPath append(String path) {
\r
73 // TODO Auto-generated method stub
\r
78 public IPath append(IPath path) {
\r
79 // TODO Auto-generated method stub
\r
84 public String getDevice() {
\r
85 return "SimanticsGraph";
\r
89 public String getFileExtension() {
\r
90 // TODO Auto-generated method stub
\r
95 public boolean hasTrailingSeparator() {
\r
96 // TODO Auto-generated method stub
\r
101 public boolean isAbsolute() {
\r
102 // TODO Auto-generated method stub
\r
107 public boolean isEmpty() {
\r
108 // TODO Auto-generated method stub
\r
113 public boolean isPrefixOf(IPath anotherPath) {
\r
114 // TODO Auto-generated method stub
\r
119 public boolean isRoot() {
\r
120 // TODO Auto-generated method stub
\r
125 public boolean isUNC() {
\r
126 // TODO Auto-generated method stub
\r
131 public boolean isValidPath(String path) {
\r
132 // TODO Auto-generated method stub
\r
137 public boolean isValidSegment(String segment) {
\r
138 // TODO Auto-generated method stub
\r
143 public String lastSegment() {
\r
144 // TODO Auto-generated method stub
\r
149 public IPath makeAbsolute() {
\r
154 public IPath makeRelative() {
\r
159 public IPath makeRelativeTo(IPath base) {
\r
160 // TODO Auto-generated method stub
\r
165 public IPath makeUNC(boolean toUNC) {
\r
166 // TODO Auto-generated method stub
\r
171 public int matchingFirstSegments(IPath anotherPath) {
\r
172 // TODO Auto-generated method stub
\r
177 public IPath removeFileExtension() {
\r
178 // TODO Auto-generated method stub
\r
183 public IPath removeFirstSegments(int count) {
\r
184 // TODO Auto-generated method stub
\r
189 public IPath removeLastSegments(int count) {
\r
190 // TODO Auto-generated method stub
\r
195 public IPath removeTrailingSeparator() {
\r
196 // TODO Auto-generated method stub
\r
201 public String segment(int index) {
\r
202 // TODO Auto-generated method stub
\r
207 public int segmentCount() {
\r
208 // TODO Auto-generated method stub
\r
213 public String[] segments() {
\r
214 // TODO Auto-generated method stub
\r
219 public IPath setDevice(String device) {
\r
220 // TODO Auto-generated method stub
\r
225 public File toFile() {
\r
226 // TODO Auto-generated method stub
\r
227 return new GraphJavaFile(file.getFileResource());
\r
231 public String toOSString() {
\r
232 // TODO Auto-generated method stub
\r
237 public String toPortableString() {
\r
238 // TODO Auto-generated method stub
\r
243 public IPath uptoSegment(int count) {
\r
244 // TODO Auto-generated method stub
\r
249 public Object clone() {
\r
254 public String toString() {
\r
256 for (String s : path) {
\r
257 name+= s + SEPARATOR;
\r
259 name += file.getName();
\r