Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Snippet: Work with Model Artifacts

Revision as of 22:33, 17 February 2008 by Erdillon.cisco.com (Talk | contribs) (New page: __TOC__ {{backlink|Tigerstripe_APIs}} This snippet illustrates how to work with model artifacts. === EMF-Based API === '''Note: the EMF-Based API is still under construction and is not f...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

< To: Tigerstripe_APIs

This snippet illustrates how to work with model artifacts.

EMF-Based API

Note: the EMF-Based API is still under construction and is not fully implemented

// Start by getting the Model Manager of the project
ITigerstripeModelProject project = ...
IModelManager mMgr = project.getModelManager();
//
// For now the default repository is hardcoded to be a PojoModelRepository,
// This should be configurable in the future.
IModelRepository repo = mMgr.getDefaultRepository();
//
// Use the EMF-generated factory to create a new artifact
IManagedEntityArtifact nMea = MetamodelFactory.eINSTANCE.createIManagedEntityArtifact();
// Name & Package are required before a Repository can store an Artifact
nMea.setName("Mea");
nMea.setPackage("com.mycompany.testNO");
// The pojo is created in a transaction
repo.store(nMea, true);
//
// To change an attribute on the Mea once it belongs to a repository,
// A transaction is needed:
final IManagedEntityArtifact fMea = nMea;
TransactionalEditingDomain editingDomain = repo.getEditingDomain();
//
editingDomain.getCommandStack().execute(new AbstractCommand() {
      @Override
      public boolean canExecute() {
        return true;
      }
      @Override
      public void execute() {
        fMea.setName("newName");
        fMea.setAbstract(true);
        fMea.setPackage("com.moo");
      }
      @Override
      public void redo() {
      }
});

Note that as this command is executed and commits, the POJO is renamed accordingly.

Old API

Note: the Old API is soon going to be deprecated

Copyright © Eclipse Foundation, Inc. All Rights Reserved.