예제 #1
0
 /**
  * Utility function to create a collaboration.
  *
  * @return a new collaboration
  * @param namespace the back-up namespace to put the collaboration in
  */
 protected static Object createCollaboration(Object namespace) {
   Object target = TargetManager.getInstance().getModelTarget();
   if (Model.getFacade().isAUMLElement(target)
       && Model.getModelManagementHelper().isReadOnly(target)) {
     target = namespace;
   }
   Object collaboration = null;
   if (Model.getFacade().isAOperation(target)) {
     Object ns = Model.getFacade().getNamespace(Model.getFacade().getOwner(target));
     collaboration = Model.getCollaborationsFactory().buildCollaboration(ns, target);
   } else if (Model.getFacade().isAClassifier(target)) {
     Object ns = Model.getFacade().getNamespace(target);
     collaboration = Model.getCollaborationsFactory().buildCollaboration(ns, target);
   } else {
     collaboration = Model.getCollaborationsFactory().createCollaboration();
     if (Model.getFacade().isANamespace(target)) {
       /* TODO: Not all namespaces are useful here - any WFRs? */
       namespace = target;
     } else {
       if (Model.getFacade().isAModelElement(target)) {
         Object ns = Model.getFacade().getNamespace(target);
         if (Model.getFacade().isANamespace(ns)) {
           namespace = ns;
         }
       }
     }
     Model.getCoreHelper().setNamespace(collaboration, namespace);
     Model.getCoreHelper().setName(collaboration, "unattachedCollaboration");
   }
   return collaboration;
 }
  /**
   * Finds a type in a model by name
   *
   * <p>FIXME: duplicated from the method with the same name in
   * org.argouml.profile.internal.ModelUtils.
   *
   * @param s the type name
   * @param model the model
   * @return the type or <code>null</code> if the type has not been found.
   */
  public static Object findTypeInModel(String s, Object model) {

    if (!Model.getFacade().isANamespace(model)) {
      throw new IllegalArgumentException(
          "Looking for the classifier "
              + s
              + " in a non-namespace object of "
              + model
              + ". A namespace was expected.");
    }

    Collection allClassifiers =
        Model.getModelManagementHelper()
            .getAllModelElementsOfKind(model, Model.getMetaTypes().getClassifier());

    Object[] classifiers = allClassifiers.toArray();
    Object classifier = null;

    for (int i = 0; i < classifiers.length; i++) {

      classifier = classifiers[i];
      if (Model.getFacade().getName(classifier) != null
          && Model.getFacade().getName(classifier).equals(s)) {
        return classifier;
      }
    }

    return null;
  }
예제 #3
0
파일: FigComment.java 프로젝트: kopl/misc
  /**
   * If the user double clicks on any part of this FigNode, pass it down to one of the internal
   * Figs. This allows the user to initiate direct text editing.
   *
   * <p>{@inheritDoc}
   */
  @Override
  public void mouseClicked(MouseEvent me) {
    if (!readyToEdit) {
      Object owner = getOwner();
      if (Model.getFacade().isAModelElement(owner)
          && !Model.getModelManagementHelper().isReadOnly(owner)) {
        readyToEdit = true;
      } else {

        return;
      }
    }
    if (me.isConsumed()) {
      return;
    }
    if (me.getClickCount() >= 2
        && !(me.isPopupTrigger() || me.getModifiers() == InputEvent.BUTTON3_MASK)) {
      if (getOwner() == null) {
        return;
      }
      Fig f = hitFig(new Rectangle(me.getX() - 2, me.getY() - 2, 4, 4));
      if (f instanceof MouseListener) {
        ((MouseListener) f).mouseClicked(me);
      }
    }
    me.consume();
  }
  private Collection getApplicableTagDefinitions(Object t) {
    Set<List<String>> paths = new HashSet<List<String>>();
    Set<Object> availableTagDefs = new TreeSet<Object>(new PathComparator());
    Collection stereotypes = Model.getFacade().getStereotypes(t);
    Project project = ProjectManager.getManager().getCurrentProject();
    for (Object model : project.getModels()) {
      addAllUniqueModelElementsFrom(
          availableTagDefs,
          paths,
          Model.getModelManagementHelper()
              .getAllModelElementsOfKind(model, Model.getMetaTypes().getTagDefinition()));
    }
    addAllUniqueModelElementsFrom(
        availableTagDefs,
        paths,
        project.getProfileConfiguration().findByMetaType(Model.getMetaTypes().getTagDefinition()));

    List notValids = new ArrayList();
    for (Object tagDef : availableTagDefs) {
      Object owner = Model.getFacade().getOwner(tagDef);
      if (owner != null && !stereotypes.contains(owner)) {
        notValids.add(tagDef);
      }
    }
    int size = availableTagDefs.size();
    availableTagDefs.removeAll(notValids);
    int delta = size - availableTagDefs.size();
    return availableTagDefs;
  }
 protected List getChoices() {
   List vec = new ArrayList();
   /* TODO: correctly implement next function
    * in the model subsystem for
    * issue 1942: */
   vec.addAll(Model.getModelManagementHelper().getAllPossibleImports(getTarget()));
   return vec;
 }
예제 #6
0
 protected List getChoices() {
   List ret = new ArrayList();
   Object model = ProjectManager.getManager().getCurrentProject().getModel();
   if (getTarget() != null) {
     ret.addAll(
         Model.getModelManagementHelper()
             .getAllModelElementsOfKind(model, Model.getMetaTypes().getReception()));
   }
   return ret;
 }
  /**
   * Helper method for buildModelList.
   *
   * <p>Adds those elements from source that do not have the same path as any path in paths to
   * elements, and its path to paths. Thus elements will never contain two objects with the same
   * path, unless they are added by other means.
   */
  private static void addAllUniqueModelElementsFrom(
      Set elements, Set<List<String>> paths, Collection sources) {

    for (Object source : sources) {
      List<String> path = Model.getModelManagementHelper().getPathList(source);
      if (!paths.contains(path)) {
        paths.add(path);
        elements.add(source);
      }
    }
  }
  /**
   * Find all the model elements in the configured {@link Profile}s of the given meta type.
   *
   * @param metaType the meta type of the model elements to find
   * @return a {@link Collection} containing the model elements that are of the given meta type
   */
  @SuppressWarnings("unchecked")
  public Collection findByMetaType(Object metaType) {
    Set elements = new HashSet();

    Iterator it = getProfileModels().iterator();
    while (it.hasNext()) {
      Object model = it.next();
      elements.addAll(Model.getModelManagementHelper().getAllModelElementsOfKind(model, metaType));
    }
    return elements;
  }
 /*
  * @see org.argouml.ui.explorer.rules.PerspectiveRule#getChildren(java.lang.Object)
  */
 public Collection getChildren(Object parent) {
   Collection col = new ArrayList();
   if (parent instanceof Project) {
     for (Object model : ((Project) parent).getUserDefinedModelList()) {
       col.addAll(
           Model.getModelManagementHelper()
               .getAllModelElementsOfKind(model, Model.getMetaTypes().getStateMachine()));
     }
   }
   return col;
 }
 protected List getChoices() {
   List ret = new ArrayList();
   if (getTarget() != null) {
     Project p = ProjectManager.getManager().getCurrentProject();
     Object model = p.getRoot();
     ret.addAll(
         Model.getModelManagementHelper()
             .getAllModelElementsOfKindWithModel(model, Model.getMetaTypes().getClassifier()));
   }
   return ret;
 }
 /*
  * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
  */
 @Override
 public void mouseClicked(MouseEvent e) {
   if (e.isPopupTrigger() && !Model.getModelManagementHelper().isReadOnly(getTarget())) {
     JPopupMenu popup = getPopupMenu();
     if (popup.getComponentCount() > 0) {
       initActions();
       LOG.info("Showing popup at " + e.getX() + "," + e.getY());
       getPopupMenu().show(this, e.getX(), e.getY());
     }
     e.consume();
   }
 }
 /*
  * @see org.argouml.ui.explorer.rules.PerspectiveRule#getChildren(java.lang.Object)
  */
 public Collection getChildren(Object parent) {
   Collection col = new ArrayList();
   if (parent instanceof Project) {
     Iterator it = ((Project) parent).getUserDefinedModels().iterator();
     while (it.hasNext()) {
       col.addAll(
           Model.getModelManagementHelper()
               .getAllModelElementsOfKind(it.next(), Model.getMetaTypes().getCollaboration()));
     }
   }
   return col;
 }
  /*
   * @see org.argouml.uml.ui.UMLComboBoxModel2#buildModelList()
   */
  protected void buildModelList() {
    Set<Object> elements = new TreeSet<Object>(new PathComparator());
    Project p = ProjectManager.getManager().getCurrentProject();
    for (Object model : p.getUserDefinedModelList()) {
      elements.addAll(
          Model.getModelManagementHelper()
              .getAllModelElementsOfKind(model, Model.getMetaTypes().getClassifier()));
    }

    elements.addAll(
        p.getProfileConfiguration().findByMetaType(Model.getMetaTypes().getClassifier()));
    removeAllElements();
    addAll(elements);
  }
 @SuppressWarnings("unchecked")
 private Collection<Object> getAllCommentsInModel(Collection objs) {
   Collection<Object> col = new ArrayList<Object>();
   for (Object obj : objs) {
     if (Model.getFacade().isAComment(obj)) {
       col.add(obj);
     } else if (Model.getFacade().isANamespace(obj)) {
       Collection contents = Model.getModelManagementHelper().getAllContents(obj);
       if (contents != null) {
         col.addAll(contents);
       }
     }
   }
   return col;
 }
예제 #15
0
 /** @see org.argouml.uml.ui.UMLComboBoxModel2#buildModelList() */
 protected void buildModelList() {
   Object target = TargetManager.getInstance().getModelTarget();
   Collection ops = new ArrayList();
   if (Model.getFacade().isACallEvent(target)) {
     Object ns = Model.getFacade().getNamespace(target);
     if (Model.getFacade().isANamespace(ns)) {
       Collection c =
           Model.getModelManagementHelper()
               .getAllModelElementsOfKind(ns, Model.getMetaTypes().getClassifier());
       Iterator i = c.iterator();
       while (i.hasNext()) {
         ops.addAll(Model.getFacade().getOperations(i.next()));
       }
     }
   }
   setElements(ops);
 }
 /*
  * @see java.awt.event.MouseListener#mouseReleased(
  *      java.awt.event.MouseEvent)
  */
 @Override
 public void mouseReleased(MouseEvent e) {
   if (e.isPopupTrigger() && !Model.getModelManagementHelper().isReadOnly(getTarget())) {
     Point point = e.getPoint();
     int index = locationToIndex(point);
     JPopupMenu popup = getPopupMenu();
     Object model = getModel();
     if (model instanceof UMLModelElementListModel) {
       ((UMLModelElementListModel) model).buildPopup(popup, index);
     }
     if (popup.getComponentCount() > 0) {
       initActions();
       LOG.info("Showing popup at " + e.getX() + "," + e.getY());
       popup.show(this, e.getX(), e.getY());
     }
     e.consume();
   }
 }
예제 #17
0
파일: FigComment.java 프로젝트: kopl/misc
  /*
   * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
   */
  @Override
  public void keyTyped(KeyEvent ke) {
    if (Character.isISOControl(ke.getKeyChar())) {
      return;
    }
    if (!readyToEdit) {
      Object owner = getOwner();
      if (Model.getFacade().isAModelElement(owner)
          && !Model.getModelManagementHelper().isReadOnly(owner)) {
        storeBody("");
        readyToEdit = true;
      } else {

        return;
      }
    }
    if (ke.isConsumed()) {
      return;
    }
    if (getOwner() == null) {
      return;
    }
    bodyTextFig.keyTyped(ke);
  }
예제 #18
0
 /**
  * The list of operations shall contain all operations of all classifiers contained in the same
  * package as the callaction itself.
  *
  * <p>TODO: In fact, we also should include operations of imported clasifiers.
  *
  * @see org.argouml.uml.ui.UMLComboBoxModel2#buildModelList()
  */
 protected void buildModelList() {
   Object target = TargetManager.getInstance().getModelTarget();
   Collection ops = new ArrayList();
   if (Model.getFacade().isACallAction(target)) {
     Object ns = Model.getFacade().getModelElementContainer(target);
     while (!Model.getFacade().isAPackage(ns)) {
       ns = Model.getFacade().getModelElementContainer(ns);
       if (ns == null) {
         break;
       }
     }
     if (Model.getFacade().isANamespace(ns)) {
       Collection c =
           Model.getModelManagementHelper()
               .getAllModelElementsOfKind(ns, Model.getMetaTypes().getClassifier());
       Iterator i = c.iterator();
       while (i.hasNext()) {
         ops.addAll(Model.getFacade().getOperations(i.next()));
       }
     }
     /* To be really sure, let's add the operation
      * that is linked to the action in the model,
      * too - if it is not listed yet.
      * We need this, incase an operation is moved
      * out of the package,
      * or maybe with imported XMI...
      */
     Object current = Model.getFacade().getOperation(target);
     if (Model.getFacade().isAOperation(current)) {
       if (!ops.contains(current)) {
         ops.add(current);
       }
     }
   }
   setElements(ops);
 }
 @Override
 protected void doIt(Collection selected) {
   Object pack = getTarget();
   Model.getModelManagementHelper().setImportedElements(pack, selected);
 }
예제 #20
0
  /*
   * Compare path of two elements in reverse order (inner to outer)
   * using a primary strength text collator.
   * This will collate e, E, é, É together, but not eliminate non-identical
   * strings which collate in the same place.
   *
   * @return equivalent of list1.compareTo(list2)
   */
  private int comparePaths(Object o1, Object o2) {

    List<String> path1 = Model.getModelManagementHelper().getPathList(o1);
    Collections.reverse(path1);
    List<String> path2 = Model.getModelManagementHelper().getPathList(o2);
    Collections.reverse(path2);

    Iterator<String> i2 = path2.iterator();
    Iterator<String> i1 = path1.iterator();
    int caseSensitiveComparison = 0;
    while (i2.hasNext()) {
      String name2 = i2.next();
      if (!i1.hasNext()) {
        return -1;
      }
      String name1 = i1.next();
      int comparison;
      if (name1 == null) {
        if (name2 == null) {
          comparison = 0;
        } else {
          comparison = -1;
        }
      } else if (name2 == null) {
        comparison = 1;
      } else {
        comparison = collator.compare(name1, name2);
      }
      if (comparison != 0) {
        return comparison;
      }
      // Keep track of first non-equal comparison to use in case the
      // case-insensitive comparisons all end up equal
      if (caseSensitiveComparison == 0) {
        if (name1 == null) {
          if (name2 == null) {
            caseSensitiveComparison = 0;
          } else {
            caseSensitiveComparison = -1;
          }
        } else if (name2 == null) {
          caseSensitiveComparison = 1;
        } else {
          caseSensitiveComparison = name1.compareTo(name2);
        }
      }
    }
    if (i2.hasNext()) {
      return 1;
    }
    // If the strings differed only in non-primary characteristics at
    // some point (case, accent, etc) pick an arbitrary, but stable,
    // collating order.
    if (caseSensitiveComparison != 0) {
      return caseSensitiveComparison;
    }
    // It's illegal in UML to have multiple elements in a namespace with
    // the same name, but if it happens, keep them distinct so the user
    // has a chance of catching the error.  Pick an arbitrary, but stable,
    // collating order.
    // We don't call them equal because otherwise one will get eliminated
    // from the TreeSet where this comparator is used.
    return o1.toString().compareTo(o2.toString());
  }