]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.ui/src/org/simantics/ui/SimanticsUI.java
Remove usage of deprecated SimanticsUI-methods
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / SimanticsUI.java
index 4b1554c864c19c0fd68477276d70c97859d2718f..18019c9fd4d0ad4eed71192fca063468a2edb619 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2010, 2018 Association for Decentralized Information Management
  * in Industry THTH ry.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -17,6 +17,7 @@ import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Widget;
 import org.eclipse.ui.PlatformUI;
 import org.simantics.DatabaseJob;
+import org.simantics.Simantics;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.common.primitiverequest.Adapter;
@@ -226,16 +227,6 @@ public class SimanticsUI {
 //        return null;
 //    }
 
-    /**
-     * Returns the session context provider of the curretly active workbench
-     * window. This method will always return a valid session context provider.
-     * 
-     * @return a valid ISessionContextProvider
-     */
-    public static ISessionContextProvider getSessionContextProvider() {
-        return getProviderSource().getActive();
-    }
-
     /**
      * Returns the session context provider for the specified handle if one
      * exists. Workbench windows (IWorkbenchWindow) are currently used as
@@ -265,9 +256,9 @@ public class SimanticsUI {
      *         workbench window or <code>null</code> if the active window has no
      *         session context
      */
+    @Deprecated
     public static ISessionContext getSessionContext() {
-        ISessionContextProvider provider = getSessionContextProvider();
-        return provider != null ? provider.getSessionContext() : null;
+        return Simantics.getSessionContext();
     }
 
     /**
@@ -305,7 +296,7 @@ public class SimanticsUI {
      *         done.
      */
     public static synchronized ISessionContext setSessionContext(ISessionContext ctx) {
-        return getSessionContextProvider().setSessionContext(ctx);
+        return Simantics.getSessionContextProvider().setSessionContext(ctx);
     }
 
     /**
@@ -337,87 +328,17 @@ public class SimanticsUI {
         return null;
     }
 
-    /**
-     * Returns the database Session bound to the currently active workbench
-     * window.
-     * 
-     * <p>
-     * This method should only be invoked in cases where it is certain that the
-     * correct workbench window has focus or it is the latest of all workbench
-     * windows to have had focus. Basically any invocation from the SWT UI
-     * thread is safe, since because in those cases the currently active
-     * workbench window is generally known. Instead invocations from any other
-     * thread should be carefully considered. The rule of thumb is that if you
-     * cannot be sure that the correct workbench window has focus, you should
-     * always get a hold of the Session to be used in some other manner.
-     * </p>
-     * 
-     * <p>
-     * The method always returns a non-null Session or produces an
-     * IllegalStateException if a Session was not attainable.
-     * </p>
-     * 
-     * @return the Session bound to the currently active workbench window
-     * @throws IllegalStateException if no Session was available
-     */
-    public static Session getSession() {
-        ISessionContext ctx = getSessionContext();
-        if (ctx == null)
-            throw new IllegalStateException("Session unavailable, no database session open");
-        return ctx.getSession();
-    }
-       
-    /**
-     * Returns the database Session bound to the currently active workbench
-     * window. Differently from {@link #getSession()}, this method returns
-     * <code>null</code> if there is no current Session available.
-     * 
-     * <p>
-     * This method should only be invoked from the SWT UI thread. Check the
-     * explanations given in {@link #getSession()}. The same applies to this
-     * method also.
-     * </p>
-     * 
-     * @return the Session bound to the currently active workbench window or
-     *         <code>null</code>
-     */
-    public static Session peekSession() {
-        ISessionContext ctx = getSessionContext();
-        return ctx == null ? null : ctx.peekSession();
-    }
-
-    /**
-     * @return the currently open and active project as an IProject or
-     *         <code>null</code> if there is no active session or project
-     */
-    public static IProject peekProject() {
-        ISessionContext ctx = getSessionContext();
-        return ctx == null ? null : (org.simantics.project.IProject) ctx.getHint(ProjectKeys.KEY_PROJECT);
-    }
-
     /**
      * @return the currently open and active project for the specified database
      *         session or <code>null</code> if there is no current project
      */
+    @Deprecated
     public static IProject peekProject(ISessionContext ctx) {
         if (ctx == null)
             return null;
         return ctx.getHint(ProjectKeys.KEY_PROJECT);
     }
 
-    /**
-     * @return the currently open and active project as an IProject
-     * @throws IllegalStateException if there is no currently active database
-     *         session, which also means there is no active project at the
-     *         moment
-     */
-    public static IProject getProject() {
-        ISessionContext ctx = getSessionContext();
-        if (ctx == null)
-            throw new IllegalStateException("No current database session");
-        return ctx.getHint(ProjectKeys.KEY_PROJECT);
-    }
-
     /**
      * TODO: refactor this out of here
      * 
@@ -446,7 +367,7 @@ public class SimanticsUI {
        if(resource == null) return null;
        
         try {
-            return getSession().syncRequest(new Adapter<T>(resource, assignableFrom));
+            return Simantics.getSession().syncRequest(new Adapter<T>(resource, assignableFrom));
         } catch (DatabaseException e) {
             Logger.defaultLogError(e);
             return null;