This page shows how you to edit models and diagram presentations by using Astah SysML API.
To learn a difference between models and presentations, please read this page.
Transaction processing is required before you edit models.
Sample: Edit block name and its definition
try { TransactionManager.beginTransaction(); SysmlModelEditor bme = ModelEditorFactory.getSysmlModelEditor(); // Create a block IBlock block0 = bme.createBlock(project, "block0"); // Set name block0.setName("new block0 name"); // Set definition block0.setDefinition("Definition of the block0"); TransactionManager.endTransaction(); } catch (InvalidEditingException e) { TransactionManager.abortTransaction(); }
This page shows you how to edit diagram presentations by using Astah SysML API.
To learn a difference between models and presentations, please read this page.
The transaction processsing is required before you start editing presentations.
IPresentation is a base interface of presentation. INodePresentation and ILinkPresentation are derived from IPresentation.
Name of presentation interface | Description | Presentations |
---|---|---|
INodePresentation | Interface for Rectangular presentation | Package, Frame, Note, Block, Part, UseCase, State, Partition, Action, Lifeline, ConstraintProperty, Port, Requirement, TestCase, Topic, Boundary and etc. |
ILinkPresentation | Interface for Line presentation | Nest, NoteAnchor, Association, Generalization, Realization, Usage, Dependency, Connector, Extend, Include, Binding Connector, Message, Anchor, DeriveReqt, Copy, Satisfy, Verify, Refine, Trace and etc. |
We’ll give you some sample codes for editing INodePresentations such as setting location, width, and height, adding a label and background color.
public void setLocation(INodePresentation ps, Point2D location) { try { TransactionManager.beginTransaction(); ps.setLocation(location); TransactionManager.endTransaction(); } catch (InvalidEditingException e) { e.printStackTrace(); TransactionManager.abortTransaction(); } }
public void setWidth(INodePresentation ps, double width) { try { TransactionManager.beginTransaction(); ps.setWidth(width); TransactionManager.endTransaction(); } catch (InvalidEditingException e) { e.printStackTrace(); TransactionManager.abortTransaction(); } }
public void setHeight(INodePresentation ps, double height) { try { TransactionManager.beginTransaction(); ps.setHeight(height); TransactionManager.endTransaction(); } catch (InvalidEditingException e) { e.printStackTrace(); TransactionManager.abortTransaction(); } }
public void setLabel(INodePresentation ps, String label) { try { TransactionManager.beginTransaction(); ps.setLabel(label); TransactionManager.endTransaction(); } catch (InvalidEditingException e) { e.printStackTrace(); TransactionManager.abortTransaction(); } }
//(EX)red:color="#FF0000" green:color="#00FF00" blue:color="#0000FF" public void setColor(INodePresentation ps, String color) { try { TransactionManager.beginTransaction(); ps.setProperty("fill.color", color); TransactionManager.endTransaction(); } catch (InvalidEditingException e) { e.printStackTrace(); TransactionManager.abortTransaction(); } }
This is an example code to modify ILinkPresentations such as Association, Dependency, Generalization, Realization, Include, Extension, Binding Connector and etc.
public void setPoints(ILinkPresentation ps, Point2D[] points) { try { TransactionManager.beginTransaction(); ps.setPoints(points); TransactionManager.endTransaction(); } catch (InvalidEditingException e) { e.printStackTrace(); TransactionManager.abortTransaction(); } }