]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/internal/SimanticsInternal.java
DB and Layer0 modifications for related issues
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / internal / SimanticsInternal.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.layer0.internal;
13
14 import java.io.File;
15
16 import org.eclipse.core.runtime.Platform;
17 import org.simantics.db.Resource;
18 import org.simantics.db.layer0.util.SimanticsClipboard;
19 import org.simantics.db.layer0.util.SimanticsKeys;
20 import org.simantics.db.management.ISessionContext;
21
22 /**
23  * An internal facade for accessing basic Simantics platform services.
24  * Usable without a graphical UI, i.e. in headless contexts.
25  * 
26  * Use org.simantics.Simantics instead where ever possible.
27  */
28 public class SimanticsInternal extends org.simantics.db.common.SimanticsInternal {
29
30     /**
31      * @return the currently open and active project as an IProject
32      * @throws IllegalStateException if there is no currently active database
33      *         session, which also means there is no active project at the
34      *         moment
35      */
36     public static Resource getProject() {
37         ISessionContext ctx = getSessionContext();
38         if (ctx == null)
39             throw new IllegalStateException("No current database session");
40         return ctx.getHint(SimanticsKeys.KEY_PROJECT);
41     }
42
43     /**
44      * @return the currently open and active project as an IProject or null if
45      *         there is either no project or no active database session
46      */
47     public static Resource peekProject() {
48         ISessionContext ctx = getSessionContext();
49         return ctx != null ? (Resource) ctx.getHint(SimanticsKeys.KEY_PROJECT) : null;
50     }
51
52     private static SimanticsClipboard clipboard = SimanticsClipboard.EMPTY;
53
54     /**
55      * @param content
56      */
57     public static void setClipboard(SimanticsClipboard content) {
58         if (content == null)
59             throw new NullPointerException("null clipboard content");
60         clipboard = content;
61     }
62
63     public static SimanticsClipboard getClipboard() {
64         return clipboard;
65     }
66
67     public static File getTemporaryDirectory() {
68         File workspace = Platform.getLocation().toFile();
69         File temp = new File(workspace, "tempFiles");
70         temp.mkdirs();
71         return temp;
72     }
73     
74 }