Difference between revisions of "Project Development"

From Developer Documents
Jump to navigation Jump to search
Line 22: Line 22:
 
= Creating a new project type =
 
= Creating a new project type =
  
== (Optional) Step 1: model your project features ==
+
== Step 1: define extensions for your project features ==
  
This step is not absolutely necessary but recommended nevertheless. This example only shows how to make a project type advertise ontology dependencies of projects which is necessary for example if dependency indexing is desired.
+
First add a plug-in dependency on [[org.simantics.project]].
 
 
Following the instructions at [[org.simantics.graph]] create a project to contain Simantics ontologies and add a new <code>.pgraph</code> file into it. You can fill the .pgraph with something like the following:
 
 
 
<blockquote>
 
<source lang="python">
 
L0 = <http://www.simantics.org/Layer0-1.0>
 
PROJ = <http://www.simantics.org/Project-1.0>
 
 
 
MY_ONTOLOGY = <http://www.example.org/MyOntology-1.0> : L0.Ontology
 
    @L0.new
 
 
 
MY_ONTOLOGY.ImportedOntologies : PROJ.NamespaceRequirement
 
    L0.HasDescription "Specifies the ontologies required by a this project. Used e.g. for indexing the database."
 
    PROJ.RequiresNamespace
 
        "http://www.simantics.org/G2D-1.0" : L0.URI
 
        "http://www.simantics.org/Diagram-2.0" : L0.URI
 
</source>
 
</blockquote>
 
 
 
== Step 2: define extensions for your project features ==
 
  
 
Extensions are defined using the <code>org.simantics.project.feature</code> extension point. See the extensions point's own reference document for detailed information (currently only viewable by opening the EP in eclipse).
 
Extensions are defined using the <code>org.simantics.project.feature</code> extension point. See the extensions point's own reference document for detailed information (currently only viewable by opening the EP in eclipse).
  
The following example demonstrates the use of all current features of the extension point, namely project features, dependencies between project features and bindings between project features and platform features. This example assumes that you have a plug-in <code>myplugin</code> and a feature project <code>myplugin.feature (feature id=myplugin)</code> for it.
+
The following example demonstrates the use of all current features of the extension point, namely project features, dependencies between project features (''requires'') and bindings between project features and Eclipse platform features (''installGroup''). This example assumes that you have a plug-in <code>myplugin</code> and a feature project <code>myplugin.feature (feature id=myplugin)</code> for it.
  
 
<blockquote>
 
<blockquote>
Line 60: Line 40:
 
             label="My project"
 
             label="My project"
 
             published="true">
 
             published="true">
         <requires id="myplugin.dependencies"/>
+
         <requires id="myplugin.dummy"/>
 
         <installGroup id="myplugin.feature.group"/>
 
         <installGroup id="myplugin.feature.group"/>
 
       </feature>
 
       </feature>
 
       <feature
 
       <feature
             class="org.simantics.project.features.DependencyValidationFeature:http://www.example.org/MyOntology-1.0/ImportedOntologies"
+
             class="myplugin.MyDummyFeature"
             id="myplugin.dependencies"
+
             id="myplugin.dummy"
             label="My plugin dependencies">
+
             label="My dummy feature">
 
       </feature>
 
       </feature>
 
   </extension>
 
   </extension>
Line 72: Line 52:
 
</blockquote>
 
</blockquote>
  
== Step 3: define the code for the project features ==
+
The above contains two project features, the first one is published and requires the second one. This means that when loading a project that uses the '''myplugin.project''' feature, '''myplugin.dummy''' feature will be configured before '''myplugin.project'''.
 +
 
 +
== Step 2: define the code for the project features ==
  
* Add dependency on plug-in org.simantics.project.
 
 
* Copy the following classes into corresponding source files:
 
* Copy the following classes into corresponding source files:
 
<blockquote>
 
<blockquote>
Line 123: Line 104:
 
     }
 
     }
 
}
 
}
 +
</source>
 +
</blockquote>
 +
 +
== Optional Step: using ready-made project features ==
 +
 +
 +
This step is not necessary but is here both for information and educational value. This example shows how to add a feature to your project that advertises ontology dependencies for your project which is necessary for example if (full-text) indexing of ontology dependencies is desired.
 +
 +
Following the instructions at [[org.simantics.graph]] create a project to contain Simantics ontologies and add a new <code>.pgraph</code> file into it. You can fill the .pgraph with something like the following:
 +
 +
A new project feature, here '''myplugin.dependencies''', must also be added to the previous example:
 +
 +
<source lang="xml">
 +
  <extension
 +
        point="org.simantics.project.feature">
 +
      <feature
 +
            description="My project type's main project feature."
 +
            class="myplugin.MyProjectFeature"
 +
            id="myplugin.project"
 +
            label="My project"
 +
            published="true">
 +
        <requires id="myplugin.dummy"/>
 +
        <!-- Added project feature dependency--->
 +
        <requires id="myplugin.dependencies"/>
 +
        <installGroup id="myplugin.feature.group"/>
 +
      </feature>
 +
      <feature
 +
            class="myplugin.MyDummyFeature"
 +
            id="myplugin.dummy"
 +
            label="My dummy feature">
 +
      </feature>
 +
      <!-- --->
 +
      <feature
 +
            class="org.simantics.project.features.DependencyValidationFeature:http://www.example.org/MyOntology-1.0/ImportedOntologies"
 +
            id="myplugin.dependencies"
 +
            label="My plugin dependencies">
 +
      </feature>
 +
  </extension>
 +
</source>
 +
</blockquote>
 +
 +
 +
<blockquote>
 +
<source lang="python">
 +
L0 = <http://www.simantics.org/Layer0-1.0>
 +
PROJ = <http://www.simantics.org/Project-1.0>
 +
 +
MY_ONTOLOGY = <http://www.example.org/MyOntology-1.0> : L0.Ontology
 +
    @L0.new
 +
 +
MY_ONTOLOGY.ImportedOntologies : PROJ.NamespaceRequirement
 +
    L0.HasDescription "Specifies the ontologies required by a this project. Used e.g. for indexing the database."
 +
    PROJ.RequiresNamespace
 +
        "http://www.simantics.org/G2D-1.0" : L0.URI
 +
        "http://www.simantics.org/Diagram-2.0" : L0.URI
 
</source>
 
</source>
 
</blockquote>
 
</blockquote>

Revision as of 13:52, 29 September 2010

Overview

In Simantics, a semantic database is conceptually broken into projects and database configuration. A database can contain any number of projects but there are single parts of the database containing configuration data that is global for all projects.

The database uses the following structure:

Root Library : L0.Library (=http:/)
  • A common entry point that always exists (see Builtins.URIs.RootLibrary)
Consists Of
Projects : L0.Library (=http://Projects)
  • Consists of all projects contained by the database
InstalledGraphBundles : L0.Entity (=http://InstalledGraphBundles)
  • Consists of the ontology bundles (.tg files) imported into this database. This is part of database configuration. See DatabaseManagement.pgraph for the related ontology.
File:Projects.png
The conceptual foundation of the project framework. (File:Projects.graphml)

The project system of Simantics is based on features. A feature in this context is simply an abstract means for configuring an IProject object. An IProject is an IHintContext. The hint context aspect of IProject is used for runtime storage of all project-related attributes, such as the currently selected model or services that can be used to perform project-type specific actions on the project in an abstract fashion. Implementing IHintContext allows for other parties to listen to changes in project attributes.

Project features can depend on (require) other features. This information is used to construct the order in which features configure/deconfigure a project, which is resolved through topological sorting.

Project features can be marked as published. This property is intended to be used for top-level features that configure a certain complete piece of functionality for a project. Top-level features are also intended to be presented to users in the Simantics Project Manager application (SPM, in development). Features can also be marked with installGroup definitions that are intended to be used to inform SPM of the Eclipse features that need to be installed into a provisioned workbench application in order for it to work with the particular project feature.

Creating a new project type

Step 1: define extensions for your project features

First add a plug-in dependency on org.simantics.project.

Extensions are defined using the org.simantics.project.feature extension point. See the extensions point's own reference document for detailed information (currently only viewable by opening the EP in eclipse).

The following example demonstrates the use of all current features of the extension point, namely project features, dependencies between project features (requires) and bindings between project features and Eclipse platform features (installGroup). This example assumes that you have a plug-in myplugin and a feature project myplugin.feature (feature id=myplugin) for it.

<source lang="xml"> <extension point="org.simantics.project.feature"> <feature description="My project type's main project feature." class="myplugin.MyProjectFeature" id="myplugin.project" label="My project" published="true"> <requires id="myplugin.dummy"/> <installGroup id="myplugin.feature.group"/> </feature> <feature class="myplugin.MyDummyFeature" id="myplugin.dummy" label="My dummy feature"> </feature> </extension> </source>

The above contains two project features, the first one is published and requires the second one. This means that when loading a project that uses the myplugin.project feature, myplugin.dummy feature will be configured before myplugin.project.

Step 2: define the code for the project features

  • Copy the following classes into corresponding source files:

<source lang="java"> package myplugin; class MyProjectFeature extends AbstractProjectFeature {

private static final String DEFAULT_PERSPECTIVE = "myplugin.myperspective";

@Override public void configure() throws ProjectException { Collection<String> perspectives = new ArrayList<String>(); perspectives.add(DEFAULT_PERSPECTIVE);

getProject().setHint(ProjectKeys.DEFAULT_PERSPECTIVE, DEFAULT_PERSPECTIVE); getProject().setHint(ProjectKeys.PERSPECTIVES, perspectives); }

@Override public void deconfigure() throws ProjectException { // Dispose of anything that needs to be disposed of within the project's // hint context which can be accessed through getProjectElement(). } } </source>


<source lang="java"> package myplugin; class MyDummyFeature extends AbstractProjectFeature {

@Override public void configure() throws ProjectException { // Setup some hints if you need to // Do something with the database getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException { //... } }); }

@Override public void deconfigure() throws ProjectException { // Dispose of anything that needs to be disposed of within the project's // hint context which can be accessed through getProjectElement(). } } </source>

Optional Step: using ready-made project features

This step is not necessary but is here both for information and educational value. This example shows how to add a feature to your project that advertises ontology dependencies for your project which is necessary for example if (full-text) indexing of ontology dependencies is desired.

Following the instructions at org.simantics.graph create a project to contain Simantics ontologies and add a new .pgraph file into it. You can fill the .pgraph with something like the following:

A new project feature, here myplugin.dependencies, must also be added to the previous example:

<source lang="xml">

  <extension
        point="org.simantics.project.feature">
     <feature
           description="My project type's main project feature."
           class="myplugin.MyProjectFeature"
           id="myplugin.project"
           label="My project"
           published="true">
        <requires id="myplugin.dummy"/>
        <requires id="myplugin.dependencies"/>
        <installGroup id="myplugin.feature.group"/>
     </feature>
     <feature
           class="myplugin.MyDummyFeature"
           id="myplugin.dummy"
           label="My dummy feature">
     </feature>
     <feature
           class="org.simantics.project.features.DependencyValidationFeature:http://www.example.org/MyOntology-1.0/ImportedOntologies"
           id="myplugin.dependencies"
           label="My plugin dependencies">
     </feature>
  </extension>

</source>


<source lang="python"> L0 = <http://www.simantics.org/Layer0-1.0> PROJ = <http://www.simantics.org/Project-1.0>

MY_ONTOLOGY = <http://www.example.org/MyOntology-1.0> : L0.Ontology @L0.new

MY_ONTOLOGY.ImportedOntologies : PROJ.NamespaceRequirement L0.HasDescription "Specifies the ontologies required by a this project. Used e.g. for indexing the database." PROJ.RequiresNamespace "http://www.simantics.org/G2D-1.0" : L0.URI "http://www.simantics.org/Diagram-2.0" : L0.URI </source>

Development

Interfaces

Project framework API and internals. (File:Project-api.graphml)

Scenarios

Load project from database and activate it

<source lang="java">

   public IProject loadAndActivateProject(Session session, Resource project) throws DatabaseException, ProjectException {
       IProject project = Projects.loadProject(session, project);
       project.activate();
       return project;
   }

</source>

Retrieving the active project

The Simantics Workbench UI is built so that always when the user is working on a project, the UI will have both an active database session and an active project. The active project can be used to store any project-related services and data using the IHintContext interface it implements.

SimanticsUI (SVN) is the class for retrieving both the active database session and the active project using these:

<source lang="java"> public class SimanticsUI {

   ...
   /**
    * Returns the database session context associated with the currently active
    * workbench window. This method should be used to retrieve session contexts
    * only when the client is sure that the correct workbench window has focus.
    * 

*

* If the client knows the workbench window it is working with, but it isn't * sure that the correct workbench window has focus, use * {@link #getSessionContext(Object)} instead. *

    * 
    * @return the session context associated with the currently active
    *         workbench window or null if the active window has no
    *         session context
    */
   public static ISessionContext getSessionContext() { ... }
   /**
    * @return the currently open and active project as an IProject or
    *         null if there is no active session or project
    */
   public static IProject peekProject() { ... }
   /**
    * @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() { ... }
   ...

} </source>