Overview | Package | Class | Use | Tree | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.togethersoft.openapi.rwi
Interface RwiDiagram

public interface RwiDiagram
extends RwiContainer

`RwiDiagram` is a set of `RwiReference` derivatives referencing the model's elements. Diagrams are kept in packages. Examples of diagrams are class diagrams, use case diagrams, sequence diagrams, collaboration diagrams etc.

It is recommended to read description of the RwiPackage interface first.

The `RwiReference`s containing in this diagram are used as shortcuts in Windows - they are only pointers to the real `RwiElement`s. If you have read the RwiPackage description you know that each `RwiDiagram` has one or two (for physical package diagrams) associated `RwiPackage`s. If the `RwiReference` points an element belonging to this diagram's associated `RwiPackage` this `RwiReference` is called a primary reference. Otherwise it is called an imported reference. `RwiReference` can be examined on whether it is an imported or a primary reference using the method RwiReference.isImported - for imported references it will return `true`.

When this `RwiDiagram` is displayed, elements referenced by imported references are shown as shortcuts.

To add to this diagram a reference to an existing model's element, `addReference` method can be used (the same happens when the user adds a shortcut to an element using the "Add shortcut" dialog). In this case only a reference to an element will be added to this diagram's reference set, but the referenced element will not be moved or copied.

This interface provides methods for creating new `RwiElement`s. Basically they are similar to the creational methods in the `RwiPackage` interface. The difference is that methods in this interface automatically add a reference (primary or imported) to this diagram's reference set. This is convenient when you would like to create a new element in the model and to add a shortcut to this element to this diagram.

The methods in this interface for creating new elements are useful only for non-physical package diagrams (see `RwiPackage`), because if you create something in a package, its physical package diagram automatically reflects such a change. For example, if this `RwiDiagram` is a use case diagram and you would like to create a new class in the package containing this diagram and to add a reference (a shortcut) to that class to this diagram, you would use method `createNodeByPattern` for this diagram.

The `RwiReference` has a useful method setVisible(boolean) controlling the visibility of the referenced element in the diagram (when the user invokes "Hide" command from the popup menu Together uses this method for the corresponding `RwiReference`).

Only imported references can be deleted from this diagram (because if it would be possible to delete primary references as well, the element could be "lost"). It can be done using the `RwiReference.delete` method. (Note that this doesn't delete a referenced element - only a reference to it from this diagram)

If you have a reference to some `RwiElement`, the method findDiagramFor can be used to find a diagram containing a primary reference to this element (the diagram in whose associated package the element is stored).

`RwiDiagram`s are not directly displayed by Together on the screen. Together uses IdeDiagrams to visualize `RwiDiagram`s in order to be able to work with the selection, to switch between active diagrams etc. It is possible to get `IdeDiagram` corresponding to the `RwiDiagram` using methods of IdeDiagramManager. For example, let's find and display a diagram containing `someRwiElement`:

     import com.togethersoft.openapi.rwi.RwiModel;
     import com.togethersoft.openapi.rwi.RwiModelAccess;
     import com.togethersoft.openapi.rwi.RwiDiagram;
     import com.togethersoft.openapi.ide.diagram.IdeDiagramManager;
     import com.togethersoft.openapi.ide.diagram.IdeDiagramManagerAccess;
     import com.togethersoft.openapi.ide.diagram.IdeDiagram;
      ...
     public void showDiagram(RwiElement someRwiElement){
      RwiModel model = RwiModelAccess.getModel();
      RwiDiagram rwiDiagram = model.findDiagramFor(someRwiElement);
      if (rwiDiagram==null) return;
      IdeDiagramManager diagramManager= IdeDiagramManagerAccess.getDiagramManager();
      IdeDiagram ideDiagram = diagramManager.openDiagram(rwiDiagram,true);
      diagramManager.setActiveDiagram(ideDiagram);
     }

Important thing to know about `RwiDiagram`s is that Together uses `RwiDiagram`s to represent packages in a class diagram. For example, when you select a package icon in a class diagram, the selected element is `RwiDiagram` representing the physical package diagram for that package (not `RwiPackage` as you might expect). To get the `RwiPackage` corresponding to the selected package icon, use the getContainingPackage method for the selected `RwiDiagram`.

Author:
  TogetherSoft
See Also: RwiReference, addReference(com.togethersoft.openapi.rwi.RwiElement), RwiModel.findDiagramFor(com.togethersoft.openapi.rwi.RwiElement), findReference(com.togethersoft.openapi.rwi.RwiElement)

Method Summary
`RwiReference` | `addReference(RwiElement element)` Creates a reference to model's element in this diagram.
`boolean` | `canAddReference(RwiElement element)` Checks whether it is possible to create a reference to model's element in this diagram.
`boolean` | `canCreateDiagram(String shapeType)` Checks whether it is possible to create a new diagram with the specified value of `RwiProperty.SHAPE_TYPE` property.
`boolean` | `canCreateNode(String shapeType)` Checks whether it is possible to create a new node with the specified value of `RwiProperty.SHAPE_TYPE` property.
`boolean` | `canCreateNodeByPattern(String language, String patternName)` Checks whether it is possible to create a new node using the specified pattern.
`boolean` | `canCreatePackage()` Checks whether it is possible to create a new package.
`RwiDiagramReference` | `createDiagram(String shapeType)` Creates a new diagram with the specified value of `RwiProperty.SHAPE_TYPE` property and returns an imported reference to that diagram.
`RwiNodeReference` | `createNode(String shapeType)` Creates a new node with the specified value of `RwiProperty.SHAPE_TYPE` property and returns a primary reference to this node.
`RwiNodeReference` | `createNodeByPattern(String language, String patternName)` Creates a new node using the specified pattern and returns a reference to this node.
`RwiDiagramReference` | `createPackage()` Creates a new package and returns a reference to its physical package diagram.
`RwiDiagramReferenceEnumeration` | `diagramReferences()` Returns an enumeration of references to other diagrams this diagram has.
`RwiReference` | `findReference(RwiElement element)` Given the `RwiElement` returns a reference to it in this diagram.
`RwiReference` | `findReference(String uniqueName)` Given the unique name of the `RwiElement` returns a reference to it in this diagram.
`RwiPackage` | `getDesignPackage()` Returns the `RwiPackage` containing design elements for this diagram.
`String` | `getOption(String name)` For this diagram, returns a string with the value of the specified string option.
`boolean` | `hasOption(String name)` For this diagram, returns a boolean value of the specified bolean option.
`RwiNodeReferenceEnumeration` | `nodeReferences()` Returns an enumeration of references to nodes this diagram has.
`RwiReferenceEnumeration` | `references()` Returns an enumeration of all the references this diagram has.

Methods inherited from interface com.togethersoft.openapi.rwi.RwiContainer
`canPaste, elements, getContainingPackage, paste`

Methods inherited from interface com.togethersoft.openapi.rwi.RwiElement
`accept, canCreateIncomingLink, canCreateOutgoingLink, canCreateOutgoingLink, canCreateOutgoingLinkByPattern, canCut, canDelete, codeElements, copy, createOutgoingLink, createOutgoingLinkByPattern, cut, delete, getCodeElement, getTimeStamp, getUniqueName, isDeleted, outgoingLinks`

Methods inherited from interface com.togethersoft.openapi.rwi.RwiPropertyMap
`addProperty, canAddProperty, canSetProperty, canSetProperty, getProperty, hasProperty, isPropertyReadable, isPropertyWritable, properties, properties, setProperty, setProperty`

Method Detail

### addReference

    public RwiReference addReference(RwiElement element)

  Creates a reference to model's element in this diagram. This method also automatically adds this reference to this diagram's reference set.

  The returned reference is an imported reference (but if the `element` belongs to this diagram (located in this diagram's associated package) this method will return an existing primary reference to that element).

  Parameters:
    element - the element to which a reference is being created
  Returns: just created reference to an element

### canAddReference

    public boolean canAddReference(RwiElement element)

  Checks whether it is possible to create a reference to model's element in this diagram.
  Parameters:
    element - the element to which a reference is being created
  Returns: `true` if it is possible to create a reference, `false` otherwise.

### canCreateDiagram

    public boolean canCreateDiagram(String shapeType)

  Checks whether it is possible to create a new diagram with the specified value of `RwiProperty.SHAPE_TYPE` property.
  Parameters:
    shapeType - the string value which needs to be assigned to the diagram's `SHAPE_TYPE` property. Cannot be `null`.
  Returns: `true` if it is possible to create a new diagram, `false` otherwise
  See Also:
    RwiProperty.SHAPE_TYPE

### canCreateNode

    public boolean canCreateNode(String shapeType)

  Checks whether it is possible to create a new node with the specified value of `RwiProperty.SHAPE_TYPE` property.
  Parameters:
    shapeType - the string value which needs to be assigned to the node's `SHAPE_TYPE` property. Cannot be `null`.
  Returns: `true` if it is possible to create a new node, `false` otherwise
  See Also:
    RwiProperty.SHAPE_TYPE

### canCreateNodeByPattern

    public boolean canCreateNodeByPattern(String language, String patternName)

  Checks whether it is possible to create a new node using the specified pattern.
  Parameters:
    language - string with the name of the language for source code generation
    patternName - string with the name of the pattern being used. Some pattern names are defined in the `RwiPattern` interface.
  Returns: `true` if it is possible to create a new node
  See Also:
    RwiLanguage, RwiPattern

### canCreatePackage

    public boolean canCreatePackage()

  Checks whether it is possible to create a new package.
  Returns: `true` if it is possible to create a new package.
  See Also:
    RwiPackage

### createDiagram

    public RwiDiagramReference createDiagram(String shapeType)

  Creates a new diagram with the specified value of `RwiProperty.SHAPE_TYPE` property and returns an imported reference to that diagram. This method also automatically adds that reference to this diagram's reference set (when this diagram is displayed the referenced diagram will be shown as a shortcut).

  Note that the created reference is not a primary reference.

  The created diagram will be placed in the package containing this diagram. This method works just like the method RwiPackage.createDiagram but it automatically creates a shortcut to the newly created diagram in this diagram.

  For example, here is a script which creates a new use case diagram named "MyUseCase" in the package containing the selected diagram: ``

        public void run(IdeContext context){
          RwiElement[] selectedRwiElements = context.getRwiElements();
          RwiElement element  = selectedRwiElements[0];
          if ( ! (element instanceof RwiDiagram) ) {
            return;
          }
          RwiDiagram diagram = (RwiDiagram)element;
          RwiDiagramReference newDiagramReference = diagram.createDiagram(RwiShapeType.USE_CASE_DIAGRAM);
          RwiDiagram newDiagram = newDiagramReference.getDiagram();
          newDiagram.setProperty(RwiProperty.NAME, "MyUseCase");
          ... //here you can add actors etc.
        }

  Note that if you select a package icon and run this script it will create a use case diagram in that package, not in the package the currently visible diagram belongs to (remember, package icons are `RwiDiagram`s - see `RwiDiagram`).
  Parameters:
    shapeType - the string value which needs to be assigned to the diagram's `SHAPE_TYPE` property. Cannot be `null`.
  Returns: reference to the new just created diagram
  See Also:
    RwiPackage.createDiagram(java.lang.String), RwiProperty.SHAPE_TYPE

### createNode

    public RwiNodeReference createNode(String shapeType)

  Creates a new node with the specified value of `RwiProperty.SHAPE_TYPE` property and returns a primary reference to this node. This method also automatically adds that reference to this diagram's reference set (when this diagram is displayed the referenced element will not be shown as a shortcut).

  Note that this method should not be used for creation of source code-based elements (classes, interfaces). For that purposes the method `createNodeByPattern` is used.

  The created node will be kept in the package containing design elements for this diagram (returned by the getDesignPackage method).

  For example, this script creates a new actor named "CEO" in the selected diagram: ``

         public void run(IdeContext context){
           RwiElement[] selectedRwiElements = context.getRwiElements();
           RwiElement element  = selectedRwiElements[0];
           if ( ! (element instanceof RwiDiagram) ) {
             return;
           }
           RwiDiagram diagram = (RwiDiagram)element;
           RwiNodeReference actorReference = diagram.createNode(RwiShapeType.ACTOR);
           RwiNode actor = actorReference.getNode();
           actor.setProperty(RwiProperty.NAME, "CEO");
         }

  Parameters:
    shapeType - the string value which needs to be assigned to the node's `SHAPE_TYPE` property. Cannot be `null`.
  Returns: a reference to the new just created node
  See Also:
    RwiProperty.SHAPE_TYPE, createNodeByPattern(java.lang.String,java.lang.String)

### createNodeByPattern

    public RwiNodeReference createNodeByPattern(String language, String patternName)

  Creates a new node using the specified pattern and returns a reference to this node. This method also automatically adds that reference to this diagram's reference set.

  Node is created in the same package where this diagram is stored. This package can be obtained using the `getContainingPackage` method.

  If this diagram is a physical package diagram then the returned reference will be a primary reference (the class/interface icon will not be shown as a shortcut), imported otherwise (the class/interface icon will be shown as a shortcut).

  For example, this script creates a new class named "MyNewClass" and a new interface named "MyNewInterface" in the package containing the selected diagram: ``

        public void run(IdeContext context){
          RwiElement[] selectedRwiElements = context.getRwiElements();
          RwiElement element  = selectedRwiElements[0];
          if ( ! (element instanceof RwiDiagram) ) {
            return;
          }
          RwiDiagram diagram = (RwiDiagram)element;
          RwiNodeReference newClassReference = diagram.createNodeByPattern(RwiLanguage.JAVA, RwiPattern.DEFAULT_CLASS); //creates a public class
          RwiNode newClass = newClassReference.getNode();
          newClass.setProperty(RwiProperty.NAME, "MyNewClass");
          RwiNodeReference newInterfaceReference = diagram.createNodeByPattern(RwiLanguage.JAVA, RwiPattern.DEFAULT_INTERFACE); //creates a public interface
          RwiNode newInterface = newInterfaceReference.getNode();
          newInterface.setProperty(RwiProperty.NAME, "MyNewInterface");
        }

  Note that if you select a package icon and run this script it will create a class and interface in that package, not in the package the currently visible diagram belongs to (remember, package icons are `RwiDiagram`s - see `RwiDiagram`).
  Parameters:
    language - string with the name of the language for source code generation
    patternName - string with the name of the pattern being used. Some pattern names are defined in the `RwiPattern` interface.
  Returns: reference to the new just created node
  See Also:
    RwiPackage.createNodeByPattern(java.lang.String,java.lang.String), RwiLanguage, RwiPattern, createNode(java.lang.String)

### createPackage

    public RwiDiagramReference createPackage()

  Creates a new package and returns a reference to its physical package diagram. This method also automatically adds that reference to this diagram's reference set. The created subpackage will be a subpackage of this diagram's package (this diagram's package can be obtained using the `getContainingPackage` method).

  If this diagram is a physical package diagram itself then the returned reference will be a primary reference (the package icon will not be shown as a shortcut), imported otherwise (the package icon will be shown as a shortcut).

  For example, this script creates a new package "myNewPackage" in the package containing the selected diagram: ``

        public void run(IdeContext context){
          RwiElement[] selectedRwiElements = context.getRwiElements();
          RwiElement element  = selectedRwiElements[0];
          if ( ! (element instanceof RwiDiagram) ) {
            return;
          }
          RwiDiagram diagram = (RwiDiagram)element;
          RwiDiagramReference newPackagePhysicalDiagramReference = diagram.createPackage();
          RwiPackage newPackage = newPackagePhysicalDiagramReference.getDiagram().getContainingPackage();
          newPackage.setProperty(RwiProperty.NAME, "myNewPackage");
        }

  Note that if you select a package icon and run this script it will create a subpackage in that package, not in the package the currently visible diagram belongs to (remember, package icons are `RwiDiagram`s - see `RwiDiagram`).

  It is better to use RwiPackage.createSubpackage method for creation of packages.

  Returns: reference to the physical package diagram of just created package
  See Also:
    RwiPackage

### diagramReferences

    public RwiDiagramReferenceEnumeration diagramReferences()

  Returns an enumeration of references to other diagrams this diagram has.
  Returns: an enumeration of references to other diagrams this diagram has
  See Also:
    references(), nodeReferences()

### findReference

    public RwiReference findReference(RwiElement element)

  Given the `RwiElement` returns a reference to it in this diagram.
  Parameters:
    element - the element the reference to which is being searched for.
  Returns: a reference to `element`, `null` if this diagram doesn't have a reference to this element
  See Also:
    findReference(java.lang.String)

### findReference

    public RwiReference findReference(String uniqueName)

  Given the unique name of the `RwiElement` returns a reference to it in this diagram.
  Parameters:
    uniqueName - unique name string for the element
  Returns: a reference to the element by its unique name, `null` if this diagram doesn't have a reference to this element
  See Also:
    RwiElement.getUniqueName(), findReference(com.togethersoft.openapi.rwi.RwiElement)

### getDesignPackage

    public RwiPackage getDesignPackage()

  Returns the `RwiPackage` containing design elements for this diagram. See the `RwiPackage` interface description.
  See Also:
    RwiPackage

### getOption

    public String getOption(String name)

  For this diagram, returns a string with the value of the specified string option. If there is no such an option, this method returns `null`.
  Parameters:
    name - The string with the name of a string option. Some options are available for editing via "Diagram options" popup menu for a diagram. For example,

         getOption("option.detail")

    will return the value of the `option.detail` option (defined in a config file).
  Returns: a string with the value of the specified string option

### hasOption

    public boolean hasOption(String name)

  For this diagram, returns a boolean value of the specified bolean option. If there is no such an option, this method returns `false`.
  Parameters:
    name - The string with the name of a string option. Some options are available for editing via "Diagram options" popup menu for a diagram. For example,

         getOption("option.associationLinks.directed")

    will return the value of the `option.associationLinks.directed` option (defined in a config file).
  Returns: a boolean value of the specified boolean option

### nodeReferences

    public RwiNodeReferenceEnumeration nodeReferences()

  Returns an enumeration of references to nodes this diagram has.
  Returns: an enumeration of references to nodes this diagram has
  See Also:
    references(), diagramReferences()

### references

    public RwiReferenceEnumeration references()

  Returns an enumeration of all the references this diagram has.
  Returns: an enumeration of all the references this diagram has
  See Also:
    diagramReferences(), nodeReferences()

Overview | Package | Class | Use | Tree | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD