public void gotoOther() {
   Object target = getTarget();
   if (target instanceof MAssociationEnd) {
     MAssociationEnd end = (MAssociationEnd) target;
     MAssociation assoc = end.getAssociation();
     Collection connections = assoc.getConnections();
     Iterator iter = connections.iterator();
     Object other = null;
     Object item = null;
     //
     //    always go to the one before match or to end
     //
     while (iter.hasNext()) {
       item = iter.next();
       if (item == end) {
         if (other != null) {
           navigateTo(other);
           return;
         }
       } else {
         other = item;
       }
     }
     //
     //   if previous end was the first, then navigate to the last
     navigateTo(other);
   }
 }
 /**
  * Deletes the association end. If the associationend's owner (the association) has one
  * associationend left after this delete, it is also deleted.
  */
 public void removeElement() {
   MAssociationEnd end = (MAssociationEnd) getTarget();
   MAssociation assoc = end.getAssociation();
   Collection ends = assoc.getConnections();
   if (ends.size() > 2) {
     Iterator it =
         ProjectBrowser.TheInstance.getProject()
             .findFigsForMember(end.getAssociation())
             .iterator();
     while (it.hasNext()) {
       // should do here something if the association end is shown
     }
     UmlFactory.getFactory().delete(end);
     navigateTo(assoc);
   } else {
     ProjectBrowser.TheInstance.setDetailsTarget(assoc);
     ActionRemoveFromModel.SINGLETON.actionPerformed(new ActionEvent(this, 0, null));
   }
 }
 protected MNamespace getDisplayNamespace(Object target) {
   MNamespace ns = null;
   if (target instanceof MAssociationEnd) {
     MAssociationEnd end = (MAssociationEnd) target;
     MAssociation assoc = end.getAssociation();
     if (assoc != null) {
       ns = assoc.getNamespace();
     }
   }
   return ns;
 }
 /**
  * Gets the associations between the classifiers from and to. Returns null if from or to is null
  * or if there is no association between them.
  *
  * @param from
  * @param to
  * @return MAssociation
  */
 public Collection getAssociations(MClassifier from, MClassifier to) {
   Set ret = new HashSet();
   if (from == null || to == null) return ret;
   Iterator it = from.getAssociationEnds().iterator();
   while (it.hasNext()) {
     MAssociationEnd end = (MAssociationEnd) it.next();
     MAssociation assoc = end.getAssociation();
     Iterator it2 = assoc.getConnections().iterator();
     while (it2.hasNext()) {
       MAssociationEnd end2 = (MAssociationEnd) it2.next();
       if (end2.getType() == to) {
         ret.add(assoc);
       }
     }
   }
   return ret;
 }
 /**
  * Gets all classifiers that are associated to the given classifier (have an association
  * relationship with the classifier).
  *
  * @param classifier
  * @return Collection
  */
 public Collection getAssociatedClassifiers(MClassifier classifier) {
   if (classifier == null) return new ArrayList();
   List list = new ArrayList();
   Iterator it = classifier.getAssociationEnds().iterator();
   while (it.hasNext()) {
     MAssociationEnd end = (MAssociationEnd) it.next();
     MAssociation assoc = end.getAssociation();
     Iterator it2 = assoc.getConnections().iterator();
     while (it2.hasNext()) {
       MAssociationEnd end2 = (MAssociationEnd) it2.next();
       if (end2 != end) {
         list.add(end2.getType());
       }
     }
   }
   return list;
 }
Example #6
0
  public Enumeration gen(Object o) {
      Vector res = new Vector();
    if (!(o instanceof MClassifier)) return res.elements();
    MClassifier cls = (MClassifier) o;
    Vector ends = new Vector(cls.getAssociationEnds());
    if (ends == null) return res.elements();
    Iterator enum = ends.iterator();
    while (enum.hasNext()) {
      MAssociationEnd ae = (MAssociationEnd) enum.next();
      if (MAggregationKind.COMPOSITE.equals(ae.getAggregation())) {
	MAssociation asc = ae.getAssociation();
	List conn = asc.getConnections();
	if (conn == null || conn.size() != 2) continue;
	Object otherEnd = (ae == conn.get(0)) ?
	  conn.get(1) : conn.get(0);
	MClassifier componentClass = ((MAssociationEnd)otherEnd).getType();
	res.add(componentClass);
      }
    }
    return res.elements();
  }
  public Vector getChildren(Object parent) {
    if (!(parent instanceof MClass)) return null;
    Vector res = new Vector();
    Vector ends = new Vector(((MClass)parent).getAssociationEnds());
    if (ends == null) return null;
    java.util.Enumeration enum = ends.elements();
    while (enum.hasMoreElements()) {
      MAssociationEnd ae = (MAssociationEnd) enum.nextElement();
      MAssociation asc = ae.getAssociation();
      Vector allEnds = new Vector( asc.getConnections());
      MAssociationEnd otherEnd = null;
      if (ae == allEnds.elementAt(0))
	otherEnd = (MAssociationEnd) allEnds.elementAt(1);
      if (ae == allEnds.elementAt(1))
	otherEnd = (MAssociationEnd) allEnds.elementAt(0);
      if (otherEnd == null) continue;
      if (!otherEnd.isNavigable()) continue;
      if (res.contains(otherEnd.getType())) continue;
      res.addElement(otherEnd.getType());
      // needs-more-work: handle n-way Associations
    }
    return res;
  }