com.togethersoft.openapi.rwi
Interface RwiModel


public interface RwiModel

RwiModel interface provides a set of starting-point methods for working with the model.

The RwiModel instance can be obtained only via static RwiModelAccess.getModel method.


 RwiModel model = RwiModelAccess.getModel();
 RwiPackageEnumeration roots = model.rootPackages(RwiProperty.MODEL);
 while (roots.hasMoreElements()) {
     RwiPackage rootPackage=roots.nextRwiPackage();
     packageProcessing(rootPackage);
 }
Once the model object is obtained, it can be used for accessing the model's data: This interface also provides methods for finding an RwiElement by its low-level API object representation. This is useful when you have gotten a low-level API object ( via RwiElement.getCodeElement method) representing some RwiElement, performed some actions using low-level API techniques, obtained the result in the form of the low-level API object, and finally wish to return to the RWI API and to get the RWI equivalent of that low-level object:

 import com.togethersoft.openapi.sci.SciClass;
 ...
 public RwiNode findClassWithTheSameNumberOfMethods(RwiNode rwiNodeRepresentingAClass){
   if (rwiNodeRepresentingAClass.getCodeElement() instanceof SciClass){
      SciClass sciClass = (SciClass)rwiNodeRepresentingAClass.getCodeElement();
      SciClass resultSciClass = findSciClassWithTheSameNumberOfMethods(sciClass);
      RwiModel model = RwiModelAccess.getModel();
      return model.findNode(resultSciClass);
   }
   return null;
 }
 private SciClass findSciClassWithTheSameNumberOfMethods(SciClass theTemplateSciClass){
   ...
 }

The findDiagramFor(RwiElement) method returns RwiDiagram containing the primary reference to the specified RwiElement.

Author:
TogetherSoft
See Also: RwiPropertyMap, RwiPackage, RwiDiagram, RwiElement

Method Summary
 RwiElementapplyPattern(RwiElement element, String patternName)
           Applies the specified pattern to the given RwiElement.
 booleancanApplyPattern(RwiElement element, String patternName)
           Checks whether it is possible to apply the specified pattern to the given RwiElement.
 RwiDiagramEnumerationdiagramPrototypes()
           Returns an enumeration of all possible RwiDiagrams valid for this project.
 StringEnumerationdiagramTypes()
           Returns an enumeration of shape types of the diagrams in the model.
 RwiDiagramfindDiagramFor(RwiElement rwiElement)
           Finds RwiDiagram containing the primary reference to the specified RwiElement.
 RwiElementfindElement(String uniqueName)
           Finds an element by its unique name.
 RwiLinkfindLink(Object codeElement)
           Returns RwiLink by given low-level API object representation.
 RwiLinkfindLink(Enumeration codeElements)
           Returns RwiLink by given enumeration of low-level API objects representing RwiLink.
 RwiMemberfindMember(Object codeElement)
           Returns RwiMember by given low-level API object representation.
 RwiMemberfindMember(Enumeration codeElements)
           Returns RwiMember by given enumeration of low-level API objects representing RwiMember.
 RwiNodefindNode(Object codeElement)
           Returns RwiNode by given low-level API object representation.
 RwiPackagefindPackage(Object codeElement)
           Returns RwiPackage by given low-level API object representation.
 RwiExtensionManagergetExtensionManager()
           Returns RwiExtensionManager object used by internal scripts.
 voidmarkElementAsChanged(RwiElement element)
           Mark specified element as changed in order to it will repainted during next diagram update.
 RwiPackageEnumerationrootPackages(String modelPart)
           Returns an enumeration of the root packages of the specific kind.

Method Detail

applyPattern

public RwiElement applyPattern(RwiElement element, String patternName)
Applies the specified pattern to the given RwiElement. After applying, this method returns the modified RwiElement.
Parameters:
element - the RwiElement
patternName - string with the name of the pattern being used. Some pattern names are defined in the RwiPattern interface.
Returns: the modified RwiElement

canApplyPattern

public boolean canApplyPattern(RwiElement element, String patternName)
Checks whether it is possible to apply the specified pattern to the given RwiElement.
Parameters:
element - the RwiElement
patternName - string with the name of the pattern being used. Some pattern names are defined in the RwiPattern interface.
Returns: true if the specified pattern can by applied to the given RwiElement, false otherwise

diagramPrototypes

public RwiDiagramEnumeration diagramPrototypes()
Returns an enumeration of all possible RwiDiagrams valid for this project. The returned diagrams are not model diagrams - they can be used only to get some information about different types of diagrams via methods of IdeResourceManager. For example, it is possible to get an icon of a class diagram:

 import com.togethersoft.openapi.ide.resource.IdeResourceManager;
 import com.togethersoft.openapi.ide.resource.IdeResourceManagerAccess;
 import com.togethersoft.openapi.ide.resource.IdeResourceIconType;
 import com.togethersoft.openapi.rwi.RwiModel;
 import com.togethersoft.openapi.rwi.RwiModelAccess;
 import com.togethersoft.openapi.rwi.RwiDiagram;
 import com.togethersoft.openapi.rwi.enum.*;
 import javax.swing.Icon;
 ...
 public Icon getClassDiagramIcon(){
   RwiModel model = RwiModelAccess.getModel();
   RwiDiagramEnumeration fakeDiagrams = model.diagramPrototypes();
   while (fakeDiagrams.hasMoreElements()){
      RwiDiagram nextDiagram= fakeDiagrams.nextRwiDiagram();
      if (!RwiShapeType.CLASS_DIAGRAM.equals(nextDiagram.getProperty(RwiProperty.SHAPE_TYPE))) continue;
      return IdeResourceManagerAccess.getResourceManager().getIcon(nextDiagram, IdeResourceIconType.SMALL);
   }
   return null;
 }
Returns: RwiDiagramEnumeration consisting of fake RwiDiagrams
See Also:
IdeResourceManager

diagramTypes

public StringEnumeration diagramTypes()
Returns an enumeration of shape types of the diagrams in the model.
Returns: an enumeration of shape types of the diagrams in the model.
See Also:
RwiProperty.SHAPE_TYPE

findDiagramFor

public RwiDiagram findDiagramFor(RwiElement rwiElement)
Finds RwiDiagram containing the primary reference to the specified RwiElement. The word "primary" means a non-imported reference, since several RwiDiagrams can have references to the same RwiElement, but only one will contain a non-imported reference. See the description of RwiDiagram interface for an explanation about primary and imported references.

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);
 }
Parameters:
rwiElement - RwiElement
Returns: RwiDiagram, or null if it is not possible to find RwiDiagram containing the primary reference to the specified RwiElement

findElement

public RwiElement findElement(String uniqueName)
Finds an element by its unique name. If there is no such element in the model, returns null.
Parameters:
uniqueName - the string with the unique name of an element which needs to be found
Returns: an element by its unique name
See Also:
RwiDiagram.findReference(com.togethersoft.openapi.rwi.RwiElement), RwiElement.getUniqueName(), findDiagramFor(com.togethersoft.openapi.rwi.RwiElement)

findLink

public RwiLink findLink(Object codeElement)
Returns RwiLink by given low-level API object representation. If it is not possible to find such a link, returns null.
Parameters:
codeElement - a low-level API object
Returns: RwiLink, or null

findLink

public RwiLink findLink(Enumeration codeElements)
Returns RwiLink by given enumeration of low-level API objects representing RwiLink. If it is not possible to find such a link, returns null.
Parameters:
codeElement - a low-level API object
Returns: RwiLink, or null

findMember

public RwiMember findMember(Object codeElement)
Returns RwiMember by given low-level API object representation. If it is not possible to find such a member, returns null.
Parameters:
codeElement - a low-level API object
Returns: RwiMember, or null

findMember

public RwiMember findMember(Enumeration codeElements)
Returns RwiMember by given enumeration of low-level API objects representing RwiMember. If it is not possible to find such a member, returns null.
Parameters:
codeElements - the enumeration of low-level API objects
Returns: RwiMember, or null

findNode

public RwiNode findNode(Object codeElement)
Returns RwiNode by given low-level API object representation. If it is not possible to find such a node, returns null.
Parameters:
codeElement - a low-level API object
Returns: RwiNode, or null

findPackage

public RwiPackage findPackage(Object codeElement)
Returns RwiPackage by given low-level API object representation. If it is not possible to find such a package, returns null.
Parameters:
codeElement - a low-level API object
Returns: RwiMember, or null

getExtensionManager

public RwiExtensionManager getExtensionManager()
Returns RwiExtensionManager object used by internal scripts.
Returns: RwiExtensionManager

markElementAsChanged

public void markElementAsChanged(RwiElement element)
Mark specified element as changed in order to it will repainted during next diagram update.
Parameters:
element - RwiElement to be marked.

rootPackages

public RwiPackageEnumeration rootPackages(String modelPart)
Returns an enumeration of the root packages of the specific kind. For example:
 RwiModel model = RwiModelAccess.getModel();
 RwiPackageEnumeration roots = model.rootPackages(RwiProperty.MODEL);
 while (roots.hasMoreElements()) {
     RwiPackage rootPackage=roots.nextRwiPackage();
     packageProcessing(rootPackage);
 }
Parameters:
modelPart - the string whose value can be either RwiProperty.MODEL, RwiProperty.IMPORT, RwiProperty.COMPONENT or null
Returns: an enumeration of the root packages
See Also:
RwiProperty.MODEL, RwiProperty.IMPORT, RwiProperty.COMPONENT