/**
  * Build a returnparameter. Removes all current return parameters from the operation and adds the
  * supplied parameter. The directionkind of the parameter will be return. The name will be equal
  * to the name of the last found return parameter or the default value "return" if no return
  * parameter was present in the operation.
  *
  * @param operation
  * @param newReturnParameter
  */
 public void setReturnParameter(MOperation operation, MParameter newReturnParameter) {
   Iterator params = operation.getParameters().iterator();
   String name = "return";
   while (params.hasNext()) {
     MParameter parameter = (MParameter) params.next();
     if ((parameter.getKind()).equals(MParameterDirectionKind.RETURN)) {
       operation.removeParameter(parameter);
       if (parameter.getName() != null || parameter.getName() == "") {
         name = parameter.getName();
       }
     }
   }
   newReturnParameter.setName(name);
   newReturnParameter.setKind(MParameterDirectionKind.RETURN);
   operation.addParameter(0, newReturnParameter);
   // we set the listeners to the figs here too
   // it would be better to do that in the figs themselves
   Project p = ProjectBrowser.TheInstance.getProject();
   Iterator it = p.findFigsForMember(operation).iterator();
   while (it.hasNext()) {
     MElementListener listener = (MElementListener) it.next();
     // UmlModelEventPump.getPump().removeModelEventListener(listener, newReturnParameter);
     UmlModelEventPump.getPump().addModelEventListener(listener, newReturnParameter);
   }
 }
Example #2
0
  private static void update_method_signature(
      Operation operation,
      String method_name,
      String method_return_type,
      String[] s_param_names,
      String[] s_return_types) {
    Project project = ProjectManager.getManager().getCurrentProject();
    List<Parameter> param_list = operation.getParameter();

    operation.setName(method_name);
    Object data_type = project.findType(method_return_type, false);
    if (data_type == null) {
      data_type = project.findType(method_return_type, true);
    }

    Parameter return_param = param_list.get(0);
    return_param.setType((Classifier) data_type);

    for (int i = 1; i < param_list.size(); i++) {
      Parameter param = param_list.get(i);
      param.setName(s_param_names[i - 1]);

      data_type = project.findType(s_return_types[i - 1], false);
      if (data_type == null) {
        data_type = project.findType(s_return_types[i - 1], true);
      }

      param.setType((Classifier) data_type);
    }
  }
  // TODO: Move to different class?
  public static void jumpToDiagramShowing(List targets) {

    if (targets == null || targets.size() == 0) {
      return;
    }
    Object first = targets.get(0);
    if (first instanceof ArgoDiagram && targets.size() > 1) {
      setTarget(first);
      setTarget(targets.get(1));
      return;
    }
    if (first instanceof ArgoDiagram && targets.size() == 1) {
      setTarget(first);
      return;
    }

    // TODO: This should get the containing project from the list of
    // targets, not from some global
    Project project = ProjectManager.getManager().getCurrentProject();
    if (project == null) {
      return;
    }

    List<ArgoDiagram> diagrams = project.getDiagramList();
    Object target = TargetManager.getInstance().getTarget();
    if ((target instanceof ArgoDiagram)
        && ((ArgoDiagram) target).countContained(targets) == targets.size()) {
      setTarget(first);
      return;
    }

    ArgoDiagram bestDiagram = null;
    int bestNumContained = 0;
    for (ArgoDiagram d : diagrams) {
      int nc = d.countContained(targets);
      if (nc > bestNumContained) {
        bestNumContained = nc;
        bestDiagram = d;
      }
      if (nc == targets.size()) {
        break;
      }
    }
    if (bestDiagram != null) {
      if (!DiagramUtils.getActiveDiagram().equals(bestDiagram)) {
        setTarget(bestDiagram);
      }
      setTarget(first);
    }
    // making it possible to jump to the modelroots
    if (project.getRoots().contains(first)) {
      setTarget(first);
    }

    // and finally, adjust the scrollbars to show the Fig
    Object f = TargetManager.getInstance().getFigTarget();
    if (f instanceof Fig) {
      Globals.curEditor().scrollToShow((Fig) f);
    }
  }
 @Override
 public boolean isGenerateMementos() {
   // TODO: This shouldn't depend on the current project, but for now
   // just make sure it's defined and that we have an undo manager
   Project p = ProjectManager.getManager().getCurrentProject();
   return super.isGenerateMementos() && p != null && p.getUndoManager() != null;
 }
Example #5
0
 /** @see java.lang.Runnable#run() */
 public void run() {
   Designer dsgr = Designer.theDesigner();
   org.argouml.uml.cognitive.critics.Init.init();
   org.argouml.uml.cognitive.checklist.Init.init();
   Project p = ProjectManager.getManager().getCurrentProject();
   // set the icon for this poster
   dsgr.setClarifier(ResourceLoaderWrapper.lookupIconResource("PostItD0"));
   dsgr.setDesignerName(Configuration.getString(Argo.KEY_USER_FULLNAME));
   Configuration.addListener(Argo.KEY_USER_FULLNAME, dsgr); // MVW
   dsgr.spawnCritiquer(p);
   dsgr.setChildGenerator(new ChildGenUML());
   java.util.Enumeration models = (p.getUserDefinedModels()).elements();
   while (models.hasMoreElements()) {
     Object o = models.nextElement();
     Model.getPump().addModelEventListener(dsgr, o);
   }
   LOG.info("spawned critiquing thread");
   dsgr.getDecisionModel().startConsidering(UMLDecision.CLASS_SELECTION);
   dsgr.getDecisionModel().startConsidering(UMLDecision.BEHAVIOR);
   dsgr.getDecisionModel().startConsidering(UMLDecision.NAMING);
   dsgr.getDecisionModel().startConsidering(UMLDecision.STORAGE);
   dsgr.getDecisionModel().startConsidering(UMLDecision.INHERITANCE);
   dsgr.getDecisionModel().startConsidering(UMLDecision.CONTAINMENT);
   dsgr.getDecisionModel().startConsidering(UMLDecision.PLANNED_EXTENSIONS);
   dsgr.getDecisionModel().startConsidering(UMLDecision.STATE_MACHINES);
   dsgr.getDecisionModel().startConsidering(UMLDecision.PATTERNS);
   dsgr.getDecisionModel().startConsidering(UMLDecision.RELATIONSHIPS);
   dsgr.getDecisionModel().startConsidering(UMLDecision.INSTANCIATION);
   dsgr.getDecisionModel().startConsidering(UMLDecision.MODULARITY);
   dsgr.getDecisionModel().startConsidering(UMLDecision.EXPECTED_USAGE);
   dsgr.getDecisionModel().startConsidering(UMLDecision.METHODS);
   dsgr.getDecisionModel().startConsidering(UMLDecision.CODE_GEN);
   dsgr.getDecisionModel().startConsidering(UMLDecision.STEREOTYPES);
   Designer.setUserWorking(true);
 }
  /*
   * @see java.awt.event.ActionListener#actionPerformed(
   *      java.awt.event.ActionEvent)
   */
  @Override
  public void actionPerformed(ActionEvent e) {

    // TODO: Get Project or other necessary context from source??
    // e.getSource();

    // TODO: Since there may be multiple top level elements in
    // a project, this should be using the default Namespace (currently
    // undefined) or something similar
    Project p = ProjectManager.getManager().getCurrentProject();
    Object ns = findNamespace();

    if (ns != null && isValidNamespace(ns)) {
      super.actionPerformed(e);
      DiagramSettings settings = p.getProjectSettings().getDefaultDiagramSettings();
      ArgoDiagram diagram = createDiagram(ns, settings);
      assert (diagram != null) : "No diagram was returned by the concrete class";

      p.addMember(diagram);
      // TODO: make the explorer listen to project member property
      // changes...  to eliminate coupling on gui.
      ExplorerEventAdaptor.getInstance().modelElementAdded(diagram.getNamespace());
      TargetManager.getInstance().setTarget(diagram);
    } else {
      LOG.error("No valid namespace found");
      throw new IllegalStateException("No valid namespace found");
    }
  }
  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;
  }
  /**
   * Test loading a native UML 1.4 zargo.
   *
   * @throws Exception when e.g. the file is not found
   */
  public void testDoLoadUml14() throws Exception {
    Project p = doLoad("/testmodels/uml14/Alittlebitofeverything.zargo");
    p.remove();

    p = doLoad("/testmodels/uml14/SequenceDiagram.zargo");
    p.remove();
  }
 /*
  * @see org.argouml.ui.GUISettingsTabInterface#handleSettingsTabRefresh()
  */
 public void handleSettingsTabRefresh() {
   assert p != null;
   userFullname.setText(p.getAuthorname());
   userEmail.setText(p.getAuthoremail());
   description.setText(p.getDescription());
   description.setCaretPosition(0);
   version.setText(p.getVersion());
 }
Example #10
0
 /**
  * @param n the new project name
  * @param p the project that receives the name
  * @throws URISyntaxException if the URI is malformed
  */
 public void setProjectName(final String n, Project p) throws URISyntaxException {
   String s = "";
   if (p.getURI() != null) {
     s = p.getURI().toString();
   }
   s = s.substring(0, s.lastIndexOf("/") + 1) + n;
   setProjectURI(new URI(s), p);
 }
  /**
   * Parse a string representing one or more ";" separated enumeration literals.
   *
   * @param enumeration the enumeration that the literal belongs to
   * @param literal the literal on which the editing will happen
   * @param text the string to parse
   * @throws ParseException for invalid input - so that the right message may be shown to the user
   */
  protected void parseEnumerationLiteralFig(Object enumeration, Object literal, String text)
      throws ParseException {

    if (enumeration == null || literal == null) {
      return;
    }
    Project project = ProjectManager.getManager().getCurrentProject();

    ParseException pex = null;
    int start = 0;
    int end = NotationUtilityUml.indexOfNextCheckedSemicolon(text, start);

    if (end == -1) {
      /* No text. We may remove the literal. */
      project.moveToTrash(literal);
      return;
    }
    String s = text.substring(start, end).trim();
    if (s.length() == 0) {
      /* No non-white chars in text? remove literal! */
      project.moveToTrash(literal);
      return;
    }
    parseEnumerationLiteral(s, literal);

    int i = Model.getFacade().getEnumerationLiterals(enumeration).indexOf(literal);
    // check for more literals (';' separated):
    start = end + 1;
    end = NotationUtilityUml.indexOfNextCheckedSemicolon(text, start);
    while (end > start && end <= text.length()) {
      s = text.substring(start, end).trim();
      if (s.length() > 0) {
        // yes, there are more:
        Object newLiteral = Model.getCoreFactory().createEnumerationLiteral();
        if (newLiteral != null) {
          try {
            if (i != -1) {
              Model.getCoreHelper().addLiteral(enumeration, ++i, newLiteral);
            } else {
              Model.getCoreHelper().addLiteral(enumeration, 0, newLiteral);
            }
            parseEnumerationLiteral(s, newLiteral);
          } catch (ParseException ex) {
            if (pex == null) {
              pex = ex;
            }
          }
        }
      }
      start = end + 1;
      end = NotationUtilityUml.indexOfNextCheckedSemicolon(text, start);
    }
    if (pex != null) {
      throw pex;
    }
  }
  public static JMenu getJMenu() {
    JMenu menu = new JMenu("copy to DeploymentDiagram as ComponentInstance");
    Project p = ProjectBrowser.TheInstance.getProject();
    for (Iterator it = p.getDiagrams().iterator(); it.hasNext(); ) {
      Object d = it.next();
      if (d instanceof UMLDeploymentDiagram) menu.add(new CopyAction((UMLDeploymentDiagram) d));
    }

    return menu;
  }
 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.ActionListener#actionPerformed(java.awt.event.ActionEvent)
  */
 public void actionPerformed(ActionEvent ae) {
   super.actionPerformed(ae);
   Project p = ProjectManager.getManager().getCurrentProject();
   int numPacks = p.getUserDefinedModelList().size();
   String nameStr = "package_" + (numPacks + 1);
   Object model = Model.getModelManagementFactory().createModel();
   Model.getCoreHelper().setName(model, nameStr);
   p.addMember(model);
   super.actionPerformed(ae);
   new ActionClassDiagram().actionPerformed(ae);
 }
  /** @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */
  public void actionPerformed(ActionEvent ae) {
    super.actionPerformed(ae);
    try {
      /*Here the actions to delete a region.
      We assume the only figs enclosed in a concurrent composite state
      are concurrent region figs*/
      Fig f = (Fig) TargetManager.getInstance().getFigTarget();
      Fig encloser = null;

      int height = 0;
      Rectangle encBound;
      Project p = ProjectManager.getManager().getCurrentProject();

      if (Model.getFacade().isAConcurrentRegion(f.getOwner())) encloser = f.getEnclosingFig();

      Vector nodesInside;
      nodesInside = ((Vector) encloser.getEnclosedFigs().clone());
      int index = nodesInside.indexOf(f);
      Rectangle r = f.getBounds();
      encBound = encloser.getBounds();
      if (Model.getFacade().isAConcurrentRegion(f.getOwner())) p.moveToTrash(f.getOwner());
      // It wasnt the last region
      if (index < nodesInside.size() - 1) {
        Rectangle rFig = ((Fig) nodesInside.elementAt(index + 1)).getBounds();
        height = rFig.y - r.y;
        for (int i = ++index; i < nodesInside.size(); i++)
          ((FigNodeModelElement) nodesInside.elementAt(i)).displace(0, -height);
      }
      // It was the last region
      else height = r.height + 4;

      /*When only one concurrent region remains it must be erased and the
      composite state sets non concurent*/
      if (((Vector) encloser.getEnclosedFigs()).size() == 1) {
        f = ((Fig) encloser.getEnclosedFigs().elementAt(0));
        nodesInside = ((Vector) f.getEnclosedFigs());
        Model.getStateMachinesHelper().setConcurrent(encloser.getOwner(), false);
        if (!nodesInside.isEmpty()) {
          for (int i = 0; i < nodesInside.size(); i++) {
            FigStateVertex curFig = (FigStateVertex) nodesInside.elementAt(i);
            curFig.setEnclosingFig(encloser);
          }
        }
        p.moveToTrash(f.getOwner());
      }

    } catch (Exception ex) {
      LOG.error(ex);
    }
  }
  /*
   * @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);
  }
  /**
   * Add a new class diagram for a package to the project.
   *
   * @param ns The namespace to contain the diagram. If null, the root model will be used.
   * @param name The fully qualified name of the package, which is used to generate the diagram name
   *     from.
   */
  public void addClassDiagram(Object ns, String name) {
    Project p = ProjectManager.getManager().getCurrentProject();

    ArgoDiagram d =
        DiagramFactory.getInstance()
            .createDiagram(UMLClassDiagram.class, ns == null ? p.getRoot() : ns, null);

    try {
      d.setName(getDiagramName(name));
    } catch (PropertyVetoException pve) {
      LOG.error("Failed to set diagram name.", pve);
    }
    p.addMember(d);
    setCurrentDiagram(d);
  }
Example #18
0
  /*
   * @see tudresden.ocl.check.types.ModelFacade#getClassifier(java.lang.String)
   */
  public Any getClassifier(String name) {
    Project p = ProjectManager.getManager().getCurrentProject();

    if (target != null && Model.getFacade().getName(target).equals(name)) {
      return new ArgoAny(target);
    }
    Object classifier = p.findTypeInModel(name, p.getModel());
    if (classifier == null) {
      /** Added search in defined types 2001-10-18 STEFFEN ZSCHALER. */
      classifier = p.findType(name, false);
      if (classifier == null) {
        throw new OclTypeException("cannot find classifier: " + name);
      }
    }
    return new ArgoAny(classifier);
  }
 /*
  * @see org.argouml.ui.explorer.rules.PerspectiveRule#getChildren(java.lang.Object)
  */
 public Collection getChildren(Object parent) {
   if (Model.getFacade().isAOperation(parent)) {
     Object operation = parent;
     Collection col = Model.getFacade().getCollaborations(operation);
     Set<ArgoDiagram> ret = new HashSet<ArgoDiagram>();
     Project p = ProjectManager.getManager().getCurrentProject();
     for (ArgoDiagram diagram : p.getDiagramList()) {
       if (diagram instanceof UMLCollaborationDiagram
           && col.contains(((UMLCollaborationDiagram) diagram).getNamespace())) {
         ret.add(diagram);
       }
     }
     return ret;
   }
   return Collections.EMPTY_SET;
 }
Example #20
0
 /**
  * @param p the project
  * @return the basename of the project
  */
 public String getProjectBaseName(Project p) {
   URI uri = p.getUri();
   String name = Translator.localize("label.projectbrowser-title");
   if (uri != null) {
     name = new File(uri).getName();
   }
   return getBaseName(name);
 }
  private ProjectActions() {
    super();

    undoAction =
        new ActionUndo(
            Translator.localize("action.undo"), ResourceLoaderWrapper.lookupIcon("Undo"));
    undoAction.setEnabled(false);

    redoAction =
        new ActionRedo(
            Translator.localize("action.redo"), ResourceLoaderWrapper.lookupIcon("Redo"));
    redoAction.setEnabled(false);

    TargetManager.getInstance().addTargetListener(this);
    Project p = ProjectManager.getManager().getCurrentProject();
    if (p != null) {
      p.getUndoManager().addPropertyChangeListener(this);
    }
  }
  /**
   * @see org.argouml.persistence.MemberFilePersister#load(org.argouml.kernel.Project,
   *     java.io.InputStream)
   */
  public void load(Project project, InputStream inputStream) throws OpenException {

    // If the model repository doesn't manage a DI model
    // then we must generate our Figs by inspecting PGML
    try {
      // Give the parser a map of model elements
      // keyed by their UUID. This is used to allocate
      // figs to their owner using the "href" attribute
      // in PGML.
      PGMLStackParser parser = new PGMLStackParser(project.getUUIDRefs());
      Diagram d = parser.readDiagram(inputStream, false);
      inputStream.close();
      project.addMember(d);
    } catch (Exception e) {
      if (e instanceof OpenException) {
        throw (OpenException) e;
      }
      throw new OpenException(e);
    }
  }
 /*
  * @see junit.framework.TestCase#setUp()
  */
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   InitializeModel.initializeDefault();
   new InitProfileSubsystem().init();
   Project p = ProjectManager.getManager().getCurrentProject();
   elem = Model.getCommonBehaviorFactory().createReception();
   signals = new Object[NO_OF_ELEMENTS];
   Object m = Model.getModelManagementFactory().createModel();
   Collection roots = new ArrayList();
   roots.add(m);
   p.setRoots(roots);
   Model.getCoreHelper().setNamespace(elem, m);
   for (int i = 0; i < NO_OF_ELEMENTS; i++) {
     signals[i] = Model.getCommonBehaviorFactory().createSignal();
     Model.getCoreHelper().addOwnedElement(m, signals[i]);
   }
   model = new UMLReceptionSignalComboBoxModel();
   model.targetSet(new TargetEvent(this, "set", new Object[0], new Object[] {elem}));
   ThreadHelper.synchronize();
 }
  public void testListener() {
    Object model = Model.getModelManagementFactory().createModel();
    Project p = ProjectManager.getManager().getCurrentProject();
    p.addModel(model);
    aClass = Model.getCoreFactory().buildClass(model);

    NotationProvider np = new NPImpl();
    np.initialiseListener(this, aClass);

    propChanged = false;
    Model.getCoreHelper().setName(aClass, "ClassA1");
    Model.getPump().flushModelEvents();
    assertTrue("No event received", propChanged);

    np.cleanListener(this, aClass);
    propChanged = false;
    Model.getCoreHelper().setName(aClass, "ClassA2");
    Model.getPump().flushModelEvents();
    assertTrue("Event received, despite not listening", !propChanged);

    np.updateListener(this, aClass, null);
  }
 /**
  * @param name the public name of the member to be found
  * @param project the project
  * @return the member
  */
 public ProjectMember findDiagramMemberByUniqueName(Project project, String name) {
   name = name + DIAGRAM_SUFFIX;
   Iterator iter = project.getMembers().iterator();
   while (iter.hasNext()) {
     ProjectMember element = (ProjectMember) iter.next();
     if (element instanceof ProjectMemberDiagram) {
       if (name.equals(element.getUniqueDiagramName())) {
         return element;
       }
     }
   }
   return null;
 }
  /**
   * @param memento the GEF memento
   * @see org.tigris.gef.undo.UndoManager#addMemento(org.tigris.gef.undo.Memento)
   */
  @Override
  public void addMemento(final Memento memento) {
    // TODO: This shouldn't be referencing the current project.  Instead
    // the appropriate UndoManager should have already been retrieved from
    // the correct project.
    Project p = ProjectManager.getManager().getCurrentProject();
    if (p != null) {
      org.argouml.kernel.UndoManager undo = p.getUndoManager();
      if (undo != null) {
        if (startChain) {
          // TODO i18n: GEF needs to pass us back the description
          // of what is being done.
          undo.startInteraction("Diagram Interaction");
        }
        // TODO: I presume this would fix issue 5250 - but
        // GEF would need to be adapted:
        //                if (!(memento instanceof SelectionMemento))
        undo.addCommand(new DiagramCommand(memento));

        startChain = false;
      }
    }
  }
Example #27
0
 /**
  * @param theUri the URI for the project
  * @param p the project that receives the URI
  */
 public void setProjectURI(URI theUri, Project p) {
   if (theUri != null) {
     theUri = fixUriExtension(theUri);
   }
   p.setUri(theUri);
 }
Example #28
0
 /**
  * Find the right namespace for the diagram.
  *
  * @return the namespace or null
  */
 protected Object findNamespace() {
   Project p = ProjectManager.getManager().getCurrentProject();
   return p.getRoot();
 }
Example #29
0
 /**
  * Utility function to create a collaboration.
  *
  * @return a new collaboration
  * @deprecated by MVW in V0.25.3. Replaced by createCollaboration(Object namespace)
  */
 @Deprecated
 protected static Object createCollaboration() {
   Project p = ProjectManager.getManager().getCurrentProject();
   Object namespace = p.getRoot(); // the root model
   return createCollaboration(namespace);
 }
 /*
  * @see org.argouml.ui.GUISettingsTabInterface#handleSettingsTabSave()
  */
 public void handleSettingsTabSave() {
   assert p != null;
   p.setAuthorname(userFullname.getText());
   p.setAuthoremail(userEmail.getText());
   p.setDescription(description.getText());
 }