コード例 #1
0
ファイル: TestProject.java プロジェクト: ckaestne/LEADT
  /** Test the moveToTrash function for package and content. */
  public void testTrashcanPackageContent() {
    Project p = ProjectManager.getManager().getOpenProjects().get(0);
    // test with a class in a package
    Object package1 = Model.getModelManagementFactory().buildPackage("test1");
    Model.getCoreHelper().setNamespace(package1, p.getRoot());
    Object cls1 = Model.getCoreFactory().buildClass(package1);
    Object cls2 = Model.getCoreFactory().buildClass(package1);
    Object cls3 = Model.getCoreFactory().buildClass(package1);
    Object cls4 = Model.getCoreFactory().buildClass(p.getRoot());
    Object c1 = Model.getFacade().getOwnedElements(p.getRoot());
    assertTrue(c1 instanceof Collection);
    // Let's make it a bit more difficult by setting the target:
    TargetManager.getInstance().setTarget(cls2);

    p.moveToTrash(package1);
    Model.getPump().flushModelEvents();

    // TODO: We should also test that the object
    // have been removed from their namespace.
    // Collection c = Model.getFacade().getOwnedElements(p.getRoot());
    assertTrue("Package not in trash", p.isInTrash(package1));
    assertTrue("Package not deleted", Model.getUmlFactory().isRemoved(package1));
    assertTrue("Class 1 not deleted", Model.getUmlFactory().isRemoved(cls1));
    assertTrue("Class 2 not deleted", Model.getUmlFactory().isRemoved(cls2));
    assertTrue("Class 3 not deleted", Model.getUmlFactory().isRemoved(cls3));
    assertTrue("Class 4 has been deleted", !Model.getUmlFactory().isRemoved(cls4));
  }
コード例 #2
0
  /*
   * @see junit.framework.TestCase#setUp()
   */
  public void setUp() throws Exception {
    super.setUp();
    (new InitNotation()).init();
    (new InitNotationUml()).init();
    (new InitNotationJava()).init();

    InitializeModel.initializeDefault();
    new InitProfileSubsystem().init();
    nodeTypes =
        new Object[] {
          Model.getCoreFactory().createClass(),
          Model.getCoreFactory().createComment(),
          Model.getCoreFactory().createDataType(),
          Model.getCoreFactory().createEnumeration(),
          Model.getCommonBehaviorFactory().createException(),
          Model.getCoreFactory().createInterface(),
          Model.getModelManagementFactory().createModel(),
          Model.getModelManagementFactory().createPackage(),
          Model.getCommonBehaviorFactory().createSignal(),
          Model.getExtensionMechanismsFactory().createStereotype(),
          Model.getModelManagementFactory().createSubsystem(),
          Model.getUseCasesFactory().createActor(),
          Model.getUseCasesFactory().createUseCase(),
          Model.getCommonBehaviorFactory().createObject(),
          Model.getCommonBehaviorFactory().createComponentInstance(),
          Model.getCommonBehaviorFactory().createNodeInstance(),
        };
  }
コード例 #3
0
ファイル: TestProject.java プロジェクト: ckaestne/LEADT
  /**
   * Test deleting an operation that contains a statechart diagram. The diagram should be deleted,
   * too.
   */
  public void testDeleteOperationWithStateDiagram() {
    Project p = ProjectManager.getManager().getOpenProjects().get(0);
    assertEquals(2, p.getDiagramList().size());

    int sizeMembers = p.getMembers().size();
    int sizeDiagrams = p.getDiagramList().size();

    // test with a class and class diagram
    Object package1 = Model.getModelManagementFactory().buildPackage("test1");
    Object aClass = Model.getCoreFactory().buildClass(package1);

    Object voidType = p.getDefaultReturnType();
    Object oper = Model.getCoreFactory().buildOperation(aClass, voidType);

    // try with Statediagram
    Object machine = Model.getStateMachinesFactory().buildStateMachine(oper);
    UMLStateDiagram d = new UMLStateDiagram(Model.getFacade().getNamespace(machine), machine);
    p.addMember(d);
    assertEquals(sizeDiagrams + 1, p.getDiagramList().size());
    assertEquals(sizeMembers + 1, p.getMembers().size());

    p.moveToTrash(oper);
    Model.getPump().flushModelEvents();

    assertTrue("Operation not in trash", p.isInTrash(oper));
    /* Changed by issue 4281: */
    assertTrue("Statemachine in trash", !Model.getUmlFactory().isRemoved(machine));
    assertEquals(sizeDiagrams + 1, p.getDiagramList().size());
    assertEquals(sizeMembers + 1, p.getMembers().size());
    /* After issue 4284 will be solved, we
     * may even delete the class, and the diagram
     * should still exist. */
  }
コード例 #4
0
ファイル: TestProject.java プロジェクト: carvalhomb/tsmells
  /**
   * Test deleting an operation that contains a statechart diagram. The diagram should be deleted,
   * too.
   */
  public void testDeleteOperationWithStateDiagram() {
    Project p = ProjectManager.getManager().getCurrentProject();
    assertEquals(2, p.getDiagrams().size());

    int sizeMembers = p.getMembers().size();
    int sizeDiagrams = p.getDiagrams().size();

    // test with a class and class diagram
    Object package1 = Model.getModelManagementFactory().buildPackage("test1", null);
    Object aClass = Model.getCoreFactory().buildClass(package1);

    Collection propertyChangeListeners = p.findFigsForMember(aClass);
    Object model = p.getModel();
    Object voidType = p.findType("void");
    Object oper =
        Model.getCoreFactory().buildOperation(aClass, model, voidType, propertyChangeListeners);

    // try with Statediagram
    Object machine = Model.getStateMachinesFactory().buildStateMachine(oper);
    UMLStateDiagram d = new UMLStateDiagram(Model.getFacade().getNamespace(machine), machine);
    p.addMember(d);
    assertEquals(sizeDiagrams + 1, p.getDiagrams().size());
    assertEquals(sizeMembers + 1, p.getMembers().size());

    p.moveToTrash(oper);

    assertTrue("Operation not in trash", p.isInTrash(oper));
    assertTrue("Statemachine not in trash", Model.getUmlFactory().isRemoved(machine));
    assertEquals(sizeDiagrams, p.getDiagrams().size());
    assertEquals(sizeMembers, p.getMembers().size());
  }
コード例 #5
0
 /** Tests the programmatically adding of multiple elements to the list. */
 public void testAddMultiple() throws Exception {
   Object[] suppliers = new Object[NO_OF_ELEMENTS];
   Object[] dependencies = new Object[NO_OF_ELEMENTS];
   for (int i = 0; i < NO_OF_ELEMENTS; i++) {
     suppliers[i] = Model.getCoreFactory().buildClass(ns);
     dependencies[i] = Model.getCoreFactory().buildDependency(elem, suppliers[i]);
   }
   ThreadHelper.synchronize();
   assertEquals(NO_OF_ELEMENTS, model.getSize());
   assertEquals(model.getElementAt(NO_OF_ELEMENTS / 2), dependencies[NO_OF_ELEMENTS / 2]);
   assertEquals(model.getElementAt(0), dependencies[0]);
   assertEquals(model.getElementAt(NO_OF_ELEMENTS - 1), dependencies[NO_OF_ELEMENTS - 1]);
 }
コード例 #6
0
ファイル: TestProject.java プロジェクト: carvalhomb/tsmells
  /** Test deleting a class that contains a Class. The class should be deleted, too. */
  public void testDeleteClassWithInnerClass() {
    Project p = ProjectManager.getManager().getCurrentProject();
    assertEquals(2, p.getDiagrams().size());

    // test with a class and an inner class
    Object aClass = Model.getCoreFactory().buildClass("Test");
    Object bClass = Model.getCoreFactory().buildClass(aClass);

    p.moveToTrash(aClass);

    assertTrue("Class not in trash", p.isInTrash(aClass));
    assertTrue("Inner Class not in trash", Model.getUmlFactory().isRemoved(bClass));
  }
コード例 #7
0
ファイル: TestProject.java プロジェクト: ckaestne/LEADT
  /**
   * Test deleting a package that contains a Class with Statechart diagram. The diagram should be
   * deleted, too.
   */
  public void testDeletePackageWithStateDiagram() {
    Project p = ProjectManager.getManager().getOpenProjects().get(0);
    assertEquals(2, p.getDiagramList().size());

    int sizeMembers = p.getMembers().size();
    int sizeDiagrams = p.getDiagramList().size();

    // test with a class and class diagram
    Object package1 = Model.getModelManagementFactory().buildPackage("test1");
    Object aClass = Model.getCoreFactory().buildClass(package1);

    // try with Statediagram
    Object machine = Model.getStateMachinesFactory().buildStateMachine(aClass);
    UMLStateDiagram d = new UMLStateDiagram(Model.getFacade().getNamespace(machine), machine);
    p.addMember(d);
    assertEquals(sizeDiagrams + 1, p.getDiagramList().size());
    assertEquals(sizeMembers + 1, p.getMembers().size());

    p.moveToTrash(package1);
    Model.getPump().flushModelEvents();

    assertTrue("Class not in trash", Model.getUmlFactory().isRemoved(aClass));
    assertTrue("Statemachine not in trash", Model.getUmlFactory().isRemoved(machine));
    assertEquals(sizeDiagrams, p.getDiagramList().size());
    assertEquals(sizeMembers, p.getMembers().size());
  }
コード例 #8
0
 /**
  * Test the creation of a profile which depends on another profile. Doesn't use the {@link
  * ProfileMother#createXmiDependentProfile(File, ProfileMother.DependencyCreator, File, String)}
  * method, but, it serves as good executable documentation of how this is done as a whole.
  *
  * @throws IOException When saving the profile models fails.
  * @throws UmlException When something in the model subsystem goes wrong.
  */
 public void testXmiDependentProfile() throws IOException, UmlException {
   Object model = mother.createSimpleProfileModel();
   File file = File.createTempFile("simple-profile", ".xmi");
   mother.saveProfileModel(model, file);
   XmiReader xmiReader = Model.getXmiReader();
   xmiReader.addSearchPath(file.getParent());
   InputSource pIs = new InputSource(file.toURI().toURL().toExternalForm());
   pIs.setPublicId(file.getName());
   Collection simpleModelTopElements = xmiReader.parse(pIs, true);
   Object model2 = mother.createSimpleProfileModel();
   Object theClass = Model.getCoreFactory().buildClass("TheClass", model2);
   Collection stereotypes = getFacade().getStereotypes(simpleModelTopElements.iterator().next());
   Object stereotype = stereotypes.iterator().next();
   Model.getCoreHelper().addStereotype(theClass, stereotype);
   File dependentProfileFile = File.createTempFile("dependent-profile", ".xmi");
   mother.saveProfileModel(model2, dependentProfileFile);
   assertTrue(
       "The file to where the file was supposed to be saved " + "doesn't exist.",
       dependentProfileFile.exists());
   assertStringInLineOfFile(
       "The name of the file which contains the profile "
           + "from which the dependent profile depends must occur in the "
           + "file.",
       file.getName(),
       dependentProfileFile);
   // Clean up our two models and the extent that we read profile in to
   Model.getUmlFactory().delete(model);
   Model.getUmlFactory().delete(model2);
   Model.getUmlFactory().deleteExtent(simpleModelTopElements.iterator().next());
 }
コード例 #9
0
ファイル: TestProject.java プロジェクト: carvalhomb/tsmells
  /**
   * Test deleting a package with a Class with a Activity diagram. The diagram should be deleted,
   * too.
   */
  public void testDeletePackageWithClassWithActivityDiagram() {
    Project p = ProjectManager.getManager().getCurrentProject();
    assertEquals(2, p.getDiagrams().size());

    int sizeMembers = p.getMembers().size();
    int sizeDiagrams = p.getDiagrams().size();

    // test with a package and a class and activity diagram
    Object package1 = Model.getModelManagementFactory().buildPackage("test1", null);
    Object aClass = Model.getCoreFactory().buildClass(package1);

    // build the Activity Diagram
    Object actgrph = Model.getActivityGraphsFactory().buildActivityGraph(aClass);
    UMLActivityDiagram d = new UMLActivityDiagram(Model.getFacade().getNamespace(actgrph), actgrph);
    p.addMember(d);
    assertEquals(sizeDiagrams + 1, p.getDiagrams().size());
    assertEquals(sizeMembers + 1, p.getMembers().size());

    p.moveToTrash(package1);

    assertTrue("Class not in trash", Model.getUmlFactory().isRemoved(aClass));
    assertTrue("ActivityGraph not in trash", Model.getUmlFactory().isRemoved(actgrph));
    assertEquals(sizeDiagrams, p.getDiagrams().size());
    assertEquals(sizeMembers, p.getMembers().size());
  }
コード例 #10
0
 /**
  * Create a simple profile model with a class named "foo" and with a stereotype named "st".
  *
  * @return the profile model.
  */
 public Object createSimpleProfileModel() {
   Object model = getModelManagementFactory().createModel();
   Object profileStereotype = getProfileStereotype();
   getCoreHelper().addStereotype(model, profileStereotype);
   Object fooClass = Model.getCoreFactory().buildClass("foo", model);
   getExtensionMechanismsFactory().buildStereotype(fooClass, STEREOTYPE_NAME_ST, model);
   return model;
 }
 /*
  * @see org.argouml.uml.ui.AbstractUMLModelElementListModel2Test#fillModel()
  */
 protected Object[] fillModel() {
   Object[] constraints = new Object[10];
   for (int i = 0; i < constraints.length; i++) {
     constraints[i] = Model.getCoreFactory().createConstraint();
     Model.getCollaborationsHelper().addConstrainingElement(getElem(), constraints[i]);
   }
   return constraints;
 }
 /** @see org.argouml.uml.ui.AbstractUMLModelElementListModel2Test#fillModel() */
 protected Object[] fillModel() {
   Object[] features = new Object[10];
   for (int i = 0; i < features.length; i++) {
     features[i] = Model.getCoreFactory().createOperation();
     Model.getCoreHelper().addFeature(base, features[i]);
   }
   return features;
 }
コード例 #13
0
  /**
   * 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;
    }
  }
コード例 #14
0
 /*
  * @see junit.framework.TestCase#setUp()
  */
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   InitializeModel.initializeDefault();
   ns = Model.getModelManagementFactory().createModel();
   elem = Model.getCoreFactory().buildClass(ns);
   model = new UMLModelElementClientDependencyListModel();
   model.setTarget(elem);
   ThreadHelper.synchronize();
 }
コード例 #15
0
 /*
  * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
  */
 public void actionPerformed(ActionEvent e) {
   Object target = TargetManager.getInstance().getModelTarget();
   if (Model.getFacade().isAEnumerationLiteral(target)) {
     target = Model.getFacade().getEnumeration(target);
   }
   if (Model.getFacade().isAClassifier(target)) {
     Object el = Model.getCoreFactory().buildEnumerationLiteral("", target);
     TargetManager.getInstance().setTarget(el);
     super.actionPerformed(e);
   }
 }
コード例 #16
0
 /*
  * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
  */
 public void actionPerformed(ActionEvent e) {
   Object target = TargetManager.getInstance().getModelTarget();
   if (Model.getFacade().isAClassifier(target)) {
     Object classifier = target;
     Object ns = Model.getFacade().getNamespace(classifier);
     if (ns != null) {
       Object peer = Model.getCoreFactory().buildClass(ns);
       TargetManager.getInstance().setTarget(peer);
       super.actionPerformed(e);
     }
   }
 }
 /** @see junit.framework.TestCase#setUp() */
 protected void setUp() throws Exception {
   super.setUp();
   Object mmodel = Model.getModelManagementFactory().createModel();
   Model.getCoreHelper().setName(mmodel, "untitledModel");
   Model.getModelManagementFactory().setRootModel(mmodel);
   namespace = Model.getModelManagementFactory().createPackage();
   child = Model.getCoreFactory().buildClass("child", namespace);
   parent = Model.getCoreFactory().buildClass("parent", namespace);
   elem = Model.getCoreFactory().buildGeneralization(child, parent);
   model = new UMLGeneralizationPowertypeComboBoxModel();
   model.targetSet(new TargetEvent(this, "set", new Object[0], new Object[] {elem}));
   types = new Object[10];
   Object m = Model.getModelManagementFactory().createModel();
   ProjectManager.getManager().getCurrentProject().setRoot(m);
   Model.getCoreHelper().setNamespace(elem, m);
   for (int i = 0; i < 10; i++) {
     types[i] = Model.getCoreFactory().createClass();
     Model.getCoreHelper().addOwnedElement(m, types[i]);
   }
   Model.getPump().flushModelEvents();
 }
コード例 #18
0
ファイル: TestProject.java プロジェクト: carvalhomb/tsmells
  /** Test deleting a package that contains a Class. The class should be deleted, too. */
  public void testDeletePackageWithClass() {
    Project p = ProjectManager.getManager().getCurrentProject();
    assertEquals(2, p.getDiagrams().size());

    // test with a class and class diagram
    Object package1 = Model.getModelManagementFactory().buildPackage("test1", null);
    Object aClass = Model.getCoreFactory().buildClass(package1);

    p.moveToTrash(package1);

    assertTrue("Class not in trash", Model.getUmlFactory().isRemoved(aClass));
  }
コード例 #19
0
  /*
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  public void actionPerformed(ActionEvent ae) {
    super.actionPerformed(ae);
    Object target = TargetManager.getInstance().getModelTarget();

    Object enumeration;
    if (Model.getFacade().isAEnumeration(target)) {
      enumeration = target;
    } else if (Model.getFacade().isAEnumerationLiteral(target)) {
      enumeration = Model.getFacade().getEnumeration(target);
    } else {
      return;
    }

    Object oper = Model.getCoreFactory().buildEnumerationLiteral("anon", enumeration);
    TargetManager.getInstance().setTarget(oper);
  }
コード例 #20
0
 private void fixModel() {
   Fig sourceFig = getSourceFigNode();
   Fig destFig = getDestFigNode();
   Object source = sourceFig.getOwner();
   Object dest = destFig.getOwner();
   LOG.error(
       "Missing Generalization for figure in PGML -"
           + " attempting to recreate between "
           + source
           + " and "
           + dest);
   if (Model.getFacade().isAGeneralizableElement(source)
       && Model.getFacade().isAGeneralizableElement(dest)) {
     setOwner(Model.getCoreFactory().buildGeneralization(source, dest));
   }
 }
コード例 #21
0
ファイル: TestProject.java プロジェクト: carvalhomb/tsmells
 /** Test the moveToTrash function for class and content. */
 public void testTrashcanClassContent() {
   Project p = ProjectManager.getManager().getCurrentProject();
   // test with a class and an inner class
   Object aClass = Model.getCoreFactory().buildClass("Test", p.getRoot());
   Object cls1 = Model.getCoreFactory().buildClass(aClass);
   Object cls2 = Model.getCoreFactory().buildClass(aClass);
   Object cls3 = Model.getCoreFactory().buildClass(aClass);
   Object typ = Model.getCoreFactory().buildClass(p.getRoot());
   Object oper2a = Model.getCoreFactory().buildOperation(cls2, p.getRoot(), cls3, new ArrayList());
   Object oper2b = Model.getCoreFactory().buildOperation(cls2, p.getRoot(), typ, new ArrayList());
   p.moveToTrash(aClass);
   // Collection c = Model.getFacade().getOwnedElements(p.getRoot());
   assertTrue("Package not in trash", p.isInTrash(aClass));
   assertTrue("Package not deleted", Model.getUmlFactory().isRemoved(aClass));
   assertTrue("Class 1 not deleted", Model.getUmlFactory().isRemoved(cls1));
   assertTrue("Class 2 not deleted", Model.getUmlFactory().isRemoved(cls2));
   assertTrue("Class 3 not deleted", Model.getUmlFactory().isRemoved(cls3));
 }
コード例 #22
0
  /**
   * Test if the listener gets events when model elements change:
   *
   * @throws InterruptedException
   */
  public void testListener() throws InterruptedException {
    Object model = Model.getModelManagementFactory().createModel();
    aClass = Model.getCoreFactory().buildClass(model);

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

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

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

    np.updateListener(aClass, null);
  }
コード例 #23
0
  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);
  }
コード例 #24
0
ファイル: TestProject.java プロジェクト: carvalhomb/tsmells
  /** Test deleting a statechart diagram directly. */
  public void testDeleteStateDiagram() {
    Project p = ProjectManager.getManager().getCurrentProject();
    assertEquals(2, p.getDiagrams().size());

    int sizeMembers = p.getMembers().size();
    int sizeDiagrams = p.getDiagrams().size();

    // test with a class and class diagram
    Object package1 = Model.getModelManagementFactory().buildPackage("test1", null);
    Object aClass = Model.getCoreFactory().buildClass(package1);

    // try with Statediagram
    Object machine = Model.getStateMachinesFactory().buildStateMachine(aClass);
    UMLStateDiagram d = new UMLStateDiagram(Model.getFacade().getNamespace(machine), machine);
    p.addMember(d);
    assertEquals(sizeDiagrams + 1, p.getDiagrams().size());
    assertEquals(sizeMembers + 1, p.getMembers().size());
    p.moveToTrash(d);
    assertTrue("Statediagram not in trash", p.isInTrash(d));
    assertEquals(sizeDiagrams, p.getDiagrams().size());
    assertEquals(sizeMembers, p.getMembers().size());
  }
コード例 #25
0
ファイル: TestProject.java プロジェクト: ckaestne/LEADT
  /** Test the moveToTrash function for class and content. */
  public void testTrashcanClassContent() {
    Project p = ProjectManager.getManager().getOpenProjects().get(0);
    // test with a class and an inner class
    Object aClass = Model.getCoreFactory().buildClass("Test", p.getRoot());
    Object cls1 = Model.getCoreFactory().buildClass(aClass);
    Object cls2 = Model.getCoreFactory().buildClass(aClass);
    Object cls3 = Model.getCoreFactory().buildClass(aClass);
    Object typ = Model.getCoreFactory().buildClass(p.getRoot());
    Object oper2a = Model.getCoreFactory().buildOperation(cls2, cls3);
    assertNotNull(oper2a);
    Object oper2b = Model.getCoreFactory().buildOperation(cls2, typ);
    assertNotNull(oper2b);

    p.moveToTrash(aClass);
    Model.getPump().flushModelEvents();

    assertTrue("Package not in trash", p.isInTrash(aClass));
    assertTrue("Package not deleted", Model.getUmlFactory().isRemoved(aClass));
    assertTrue("Class 1 not deleted", Model.getUmlFactory().isRemoved(cls1));
    assertTrue("Class 2 not deleted", Model.getUmlFactory().isRemoved(cls2));
    assertTrue("Class 3 not deleted", Model.getUmlFactory().isRemoved(cls3));
  }
コード例 #26
0
 /*
  * @see org.argouml.uml.ui.AbstractTestActionAddDiagram#getNamespace()
  */
 protected Object getNamespace() {
   return Model.getCoreFactory().createClass();
 }
コード例 #27
0
 /*
  * @see org.argouml.uml.ui.AbstractTestActionAddDiagram#getNamespace()
  */
 protected Object getNamespace() {
   Object pack = Model.getModelManagementFactory().createPackage();
   Object c = Model.getCoreFactory().buildClass(pack);
   TargetManager.getInstance().setTarget(c);
   return c;
 }
 /** @see junit.framework.TestCase#setUp() */
 protected void setUp() throws Exception {
   super.setUp();
   base = Model.getCoreFactory().createClass();
   Model.getCollaborationsHelper().addBase(getElem(), base);
 }
コード例 #29
0
ファイル: FigClass.java プロジェクト: carvalhomb/tsmells
/**
 * Class to display graphics for a UML Class in a diagram.
 *
 * <p>
 */
public class FigClass extends FigClassifierBox implements AttributesCompartmentContainer {

  /** Logger. */
  private static final Logger LOG = Logger.getLogger(FigClass.class);

  FigAttributesCompartment attributesFigCompartment;

  Fig borderFig;

  /**
   * Text highlighted by mouse actions on the diagram.
   *
   * <p>
   */
  private CompartmentFigText highlightedFigText = null;

  /**
   * Flag to indicate that we have just been created. This is to fix the problem with loading
   * classes that have stereotypes already defined.
   *
   * <p>
   */
  private boolean newlyCreated = false;

  /** Manages residency of a class within a component on a deployment diagram. */
  private Object resident = Model.getCoreFactory().createElementResidence();

  ////////////////////////////////////////////////////////////////
  // constructors

  /**
   * Main constructor for a {@link FigClass}.
   *
   * <p>Parent {@link FigNodeModelElement} will have created the main box {@link #getBigPort()} and
   * its name {@link #getNameFig()} and stereotype (@link #getStereotypeFig()}. This constructor
   * creates a box for the attributes and operations.
   *
   * <p>The properties of all these graphic elements are adjusted appropriately. The main boxes are
   * all filled and have outlines.
   *
   * <p>For reasons I don't understand the stereotype is created in a box with lines. So we have to
   * created a blanking rectangle to overlay the bottom line, and avoid four compartments showing.
   *
   * <p>There is some complex logic to allow for the possibility that stereotypes may not be
   * displayed (unlike operations and attributes this is not a standard thing for UML). Some care is
   * needed to ensure that additional space is not added, each time a stereotyped class is loaded.
   *
   * <p>There is a particular problem when loading diagrams with stereotyped classes. Because we
   * create a FigClass indicating the stereotype is not displayed, we then add extra space for such
   * classes when they are first rendered. This ought to be fixed by correctly saving the class
   * dimensions, but that needs more work. The solution here is to use a simple flag to indicate the
   * FigClass has just been created.
   *
   * <p><em>Warning</em>. Much of the graphics positioning is hard coded. The overall figure is
   * placed at location (10,10). The name compartment (in the parent {@link FigNodeModelElement} is
   * 21 pixels high. The stereotype compartment is created 15 pixels high in the parent, but we
   * change it to 19 pixels, 1 more than ({@link #STEREOHEIGHT} here. The attribute and operations
   * boxes are created at 19 pixels, 2 more than {@link #ROWHEIGHT}.
   *
   * <p>CAUTION: This constructor (with no arguments) is the only one that does
   * enableSizeChecking(false), all others must set it true. This is because this constructor is the
   * only one called when loading a project. In this case, the parsed size must be maintained.
   *
   * <p>
   */
  public FigClass() {

    getBigPort().setLineWidth(0);
    getBigPort().setFillColor(Color.white);

    // Attributes inside. First one is the attribute box itself.
    attributesFigCompartment = new FigAttributesCompartment(10, 30, 60, ROWHEIGHT + 2);

    // The operations compartment is built in the ancestor FigClassifierBox

    // Set properties of the stereotype box. Make it 1 pixel higher than
    // before, so it overlaps the name box, and the blanking takes out both
    // lines. Initially not set to be displayed, but this will be changed
    // when we try to render it, if we find we have a stereotype.
    getStereotypeFig().setFilled(false);
    getStereotypeFig().setHeight(STEREOHEIGHT + 1);
    // +1 to have 1 pixel overlap with getNameFig()
    getStereotypeFig().setVisible(true);

    borderFig = new FigEmptyRect(10, 10, 0, 0);
    borderFig.setLineWidth(1);
    borderFig.setLineColor(Color.black);

    getStereotypeFig().setLineWidth(0);

    // Mark this as newly created. This is to get round the problem with
    // creating figs for loaded classes that had stereotypes. They are
    // saved with their dimensions INCLUDING the stereotype, but since we
    // pretend the stereotype is not visible, we add height the first time
    // we render such a class. This is a complete fudge, and really we
    // ought to address how class objects with stereotypes are saved. But
    // that will be hard work.
    newlyCreated = true;

    // Put all the bits together, suppressing bounds calculations until
    // we're all done for efficiency.
    enableSizeChecking(false);
    setSuppressCalcBounds(true);
    addFig(getBigPort());
    addFig(getStereotypeFig());
    addFig(getNameFig());
    addFig(operationsFig);
    addFig(attributesFigCompartment);
    addFig(borderFig);

    setSuppressCalcBounds(false);
    // Set the bounds of the figure to the total of the above (hardcoded)
    setBounds(10, 10, 60, 22 + 2 * ROWHEIGHT);
  }

  /**
   * Constructor for use if this figure is created for an existing class node in the metamodel.
   *
   * @param gm Not actually used in the current implementation
   * @param node The UML object being placed.
   */
  public FigClass(GraphModel gm, Object node) {
    this();
    setOwner(node);
    enableSizeChecking(true);
  }

  /** @see java.lang.Object#clone() */
  public Object clone() {
    FigClass figClone = (FigClass) super.clone();
    Iterator thisIter = this.getFigs().iterator();
    Iterator cloneIter = figClone.getFigs().iterator();
    while (thisIter.hasNext()) {
      Fig thisFig = (Fig) thisIter.next();
      Fig cloneFig = (Fig) cloneIter.next();
      if (thisFig == borderFig) {
        figClone.borderFig = (FigRect) thisFig;
      }
    }
    return figClone;
  }

  /** @see org.argouml.uml.diagram.ui.FigNodeModelElement#placeString() */
  public String placeString() {
    return "new Class";
  }

  ////////////////////////////////////////////////////////////////
  // accessors

  /** @see org.tigris.gef.presentation.Fig#makeSelection() */
  public Selection makeSelection() {
    return new SelectionClass(this);
  }

  /**
   * Build a collection of menu items relevant for a right-click popup menu on a Class.
   *
   * @param me a mouse event
   * @return a collection of menu items
   * @see org.tigris.gef.ui.PopupGenerator#getPopUpActions(java.awt.event.MouseEvent)
   */
  public Vector getPopUpActions(MouseEvent me) {
    Vector popUpActions = super.getPopUpActions(me);

    // Add...
    ArgoJMenu addMenu = new ArgoJMenu("menu.popup.add");
    addMenu.add(TargetManager.getInstance().getAddAttributeAction());
    addMenu.add(TargetManager.getInstance().getAddOperationAction());
    addMenu.add(new ActionAddNote());
    addMenu.add(ActionEdgesDisplay.getShowEdges());
    addMenu.add(ActionEdgesDisplay.getHideEdges());
    popUpActions.insertElementAt(addMenu, popUpActions.size() - getPopupAddOffset());

    // Show ...
    ArgoJMenu showMenu = new ArgoJMenu("menu.popup.show");
    Iterator i = ActionCompartmentDisplay.getActions().iterator();
    while (i.hasNext()) {
      showMenu.add((Action) i.next());
    }
    popUpActions.insertElementAt(showMenu, popUpActions.size() - getPopupAddOffset());

    // Modifiers ...
    popUpActions.insertElementAt(
        buildModifierPopUp(ABSTRACT | LEAF | ROOT | ACTIVE),
        popUpActions.size() - getPopupAddOffset());

    // Visibility ...
    popUpActions.insertElementAt(buildVisibilityPopUp(), popUpActions.size() - getPopupAddOffset());

    return popUpActions;
  }

  /** @return The bounds of the attributes compartment. */
  public Rectangle getAttributesBounds() {
    return attributesFigCompartment.getBounds();
  }

  /**
   * @return The vector of graphics for operations (if any). First one is the rectangle for the
   *     entire operations box.
   */
  private FigAttributesCompartment getAttributesFig() {
    return attributesFigCompartment;
  }

  /**
   * Returns the status of the attribute field.
   *
   * @return true if the attributes are visible, false otherwise
   * @see org.argouml.uml.diagram.ui.AttributesCompartmentContainer#isAttributesVisible()
   */
  public boolean isAttributesVisible() {
    return getAttributesFig().isVisible();
  }

  /**
   * @param isVisible true if the attribute compartment is visible
   * @see org.argouml.uml.diagram.ui.AttributesCompartmentContainer#setAttributesVisible(boolean)
   */
  public void setAttributesVisible(boolean isVisible) {
    Rectangle rect = getBounds();
    //        int h;
    //    	if (isCheckSize()) {
    //    	    h = ((ROWHEIGHT
    //                * Math.max(1, getAttributesFig().getFigs().size() - 1) + 2)
    //                * rect.height
    //                / getMinimumSize().height);
    //        } else {
    //            h = 0;
    //        }
    if (getAttributesFig().isVisible()) {
      if (!isVisible) { // hide compartment
        damage();
        Iterator it = getAttributesFig().getFigs().iterator();
        while (it.hasNext()) {
          ((Fig) (it.next())).setVisible(false);
        }
        getAttributesFig().setVisible(false);
        Dimension aSize = this.getMinimumSize();
        setBounds(rect.x, rect.y, (int) aSize.getWidth(), (int) aSize.getHeight());
      }
    } else {
      if (isVisible) { // show compartement
        Iterator it = getAttributesFig().getFigs().iterator();
        while (it.hasNext()) {
          ((Fig) (it.next())).setVisible(true);
        }
        getAttributesFig().setVisible(true);
        Dimension aSize = this.getMinimumSize();
        setBounds(rect.x, rect.y, (int) aSize.getWidth(), (int) aSize.getHeight());
        damage();
      }
    }
  }

  /**
   * @param isVisible true if the operation compartment is visible
   * @see org.argouml.uml.diagram.ui.OperationsCompartmentContainer#setOperationsVisible(boolean)
   */
  public void setOperationsVisible(boolean isVisible) {
    Rectangle rect = getBounds();
    //        int h =
    //    	    isCheckSize()
    //    	    ? ((ROWHEIGHT
    //                * Math.max(1, getOperationsFig().getFigs().size() - 1) + 2)
    //    	        * rect.height
    //    	        / getMinimumSize().height)
    //    	    : 0;
    if (isOperationsVisible()) { // if displayed
      if (!isVisible) {
        damage();
        Iterator it = getOperationsFig().getFigs().iterator();
        while (it.hasNext()) {
          ((Fig) (it.next())).setVisible(false);
        }
        getOperationsFig().setVisible(false);
        Dimension aSize = this.getMinimumSize();
        setBounds(rect.x, rect.y, (int) aSize.getWidth(), (int) aSize.getHeight());
      }
    } else {
      if (isVisible) {
        Iterator it = getOperationsFig().getFigs().iterator();
        while (it.hasNext()) {
          ((Fig) (it.next())).setVisible(true);
        }
        getOperationsFig().setVisible(true);
        Dimension aSize = this.getMinimumSize();
        setBounds(rect.x, rect.y, (int) aSize.getWidth(), (int) aSize.getHeight());
        damage();
      }
    }
  }

  /** @see org.tigris.gef.presentation.Fig#setLineWidth(int) */
  public void setLineWidth(int w) {
    borderFig.setLineWidth(w);
  }

  /** @see org.tigris.gef.presentation.Fig#getLineWidth() */
  public int getLineWidth() {
    return borderFig.getLineWidth();
  }

  /**
   * USED BY PGML.tee.
   *
   * @return the class name and bounds together with compartment visibility.
   */
  public String classNameAndBounds() {
    return super.classNameAndBounds()
        + "operationsVisible="
        + isOperationsVisible()
        + ";"
        + "attributesVisible="
        + isAttributesVisible();
  }

  /**
   * Gets the minimum size permitted for a class on the diagram.
   *
   * <p>Parts of this are hardcoded, notably the fact that the name compartment has a minimum height
   * of 21 pixels.
   *
   * <p>
   *
   * @return the size of the minimum bounding box.
   */
  public Dimension getMinimumSize() {
    // Use "aSize" to build up the minimum size. Start with the size of the
    // name compartment and build up.

    Dimension aSize = getNameFig().getMinimumSize();

    // If we have a stereotype displayed, then allow some space for that
    // (width and height)

    if (getStereotypeFig().isVisible()) {
      Dimension stereoMin = getStereotypeFig().getMinimumSize();
      aSize.width = Math.max(aSize.width, stereoMin.width);
      aSize.height += stereoMin.height;
    }

    // Allow space for each of the attributes we have

    if (getAttributesFig().isVisible()) {
      Dimension attrMin = getAttributesFig().getMinimumSize();
      aSize.width = Math.max(aSize.width, attrMin.width);
      aSize.height += attrMin.height;
    }

    // Allow space for each of the operations we have

    if (isOperationsVisible()) {
      Dimension operMin = getOperationsFig().getMinimumSize();
      aSize.width = Math.max(aSize.width, operMin.width);
      aSize.height += operMin.height;
    }

    // we want to maintain a minimum width for the class
    aSize.width = Math.max(60, aSize.width);

    // And now aSize has the answer

    return aSize;
  }
  /**
   * Gets the minimum size permitted for a class on the diagram.
   *
   * <p>
   *
   * @return the size of the minimum bounding box.
   */
  public Dimension getMinimumSizeSingleStereotype() {

    // Use "aSize" to build up the minimum size. Start with the size of the
    // name compartment and build up.

    Dimension aSize = getNameFig().getMinimumSize();

    // If we have a stereotype displayed, then allow some space for that
    // (width and height)

    if (getStereotypeFig().isVisible()) {
      aSize.width = Math.max(aSize.width, getStereotypeFig().getMinimumSize().width);
      aSize.height += STEREOHEIGHT;
    }

    // Allow space for each of the attributes we have

    if (getAttributesFig().isVisible()) {

      // Loop through all the attributes, to find the widest (remember
      // the first fig is the box for the whole lot, so ignore it).

      Iterator it = getAttributesFig().getFigs().iterator();
      it.next(); // Ignore first element

      while (it.hasNext()) {
        int elemWidth = ((FigText) it.next()).getMinimumSize().width + 2;
        aSize.width = Math.max(aSize.width, elemWidth);
      }

      // Height allows one row for each attribute (remember to ignore the
      // first element.

      aSize.height += ROWHEIGHT * Math.max(1, getAttributesFig().getFigs().size() - 1) + 1;
    }

    // Allow space for each of the operations we have

    if (isOperationsVisible()) {

      // Loop through all the operations, to find the widest (remember
      // the first fig is the box for the whole lot, so ignore it).

      Iterator it = getOperationsFig().getFigs().iterator();
      it.next(); // ignore

      while (it.hasNext()) {
        int elemWidth = ((FigText) it.next()).getMinimumSize().width + 2;
        aSize.width = Math.max(aSize.width, elemWidth);
      }

      aSize.height += ROWHEIGHT * Math.max(1, getOperationsFig().getFigs().size() - 1) + 1;
    }

    // we want to maintain a minimum width for the class
    aSize.width = Math.max(60, aSize.width);

    // And now aSize has the answer

    return aSize;
  }

  /** @see org.tigris.gef.presentation.Fig#translate(int, int) */
  public void translate(int dx, int dy) {
    super.translate(dx, dy);
    Editor ce = Globals.curEditor();
    Selection sel = ce.getSelectionManager().findSelectionFor(this);
    if (sel instanceof SelectionClass) {
      ((SelectionClass) sel).hideButtons();
    }
  }

  ////////////////////////////////////////////////////////////////
  // user interaction methods

  /** @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent) */
  public void keyPressed(KeyEvent ke) {
    int key = ke.getKeyCode();
    if (key == KeyEvent.VK_UP || key == KeyEvent.VK_DOWN) {
      CompartmentFigText ft = unhighlight();
      if (ft != null) {
        int i = new Vector(getAttributesFig().getFigs()).indexOf(ft);
        FigGroup fg = getAttributesFig();
        if (i == -1) {
          i = new Vector(getOperationsFig().getFigs()).indexOf(ft);
          fg = getOperationsFig();
        }
        if (i != -1) {
          if (key == KeyEvent.VK_UP) {
            ft = (CompartmentFigText) getPreviousVisibleFeature(fg, ft, i);
          } else {
            ft = (CompartmentFigText) getNextVisibleFeature(fg, ft, i);
          }
          if (ft != null) {
            ft.setHighlighted(true);
            highlightedFigText = ft;
            return;
          }
        }
      }
    } else if (key == KeyEvent.VK_ENTER && highlightedFigText != null) {
      highlightedFigText.startTextEditor(ke);
      ke.consume();
      return;
    }
    super.keyPressed(ke);
  }

  ////////////////////////////////////////////////////////////////
  // internal methods

  /**
   * @see
   *     org.argouml.uml.diagram.ui.FigNodeModelElement#textEdited(org.tigris.gef.presentation.FigText)
   */
  protected void textEdited(FigText ft) throws PropertyVetoException {
    super.textEdited(ft);
    Object classifier = getOwner();
    if (classifier == null) {
      return;
    }
    int i = new Vector(getAttributesFig().getFigs()).indexOf(ft);
    if (i != -1) {
      highlightedFigText = (CompartmentFigText) ft;
      highlightedFigText.setHighlighted(true);
      try {
        Object attribute = highlightedFigText.getOwner();
        ParserDisplay.SINGLETON.parseAttributeFig(
            classifier, attribute, highlightedFigText.getText().trim());
        ProjectBrowser.getInstance().getStatusBar().showStatus("");
      } catch (ParseException pe) {
        String msg = "statusmsg.bar.error.parsing.attribute";
        Object[] args = {pe.getLocalizedMessage(), new Integer(pe.getErrorOffset())};
        ProjectBrowser.getInstance().getStatusBar().showStatus(Translator.messageFormat(msg, args));
      }
      return;
    }
    i = new Vector(getOperationsFig().getFigs()).indexOf(ft);
    if (i != -1) {
      highlightedFigText = (CompartmentFigText) ft;
      highlightedFigText.setHighlighted(true);
      try {
        Object operation = highlightedFigText.getOwner();
        ParserDisplay.SINGLETON.parseOperationFig(
            classifier, operation, highlightedFigText.getText().trim());
        ProjectBrowser.getInstance().getStatusBar().showStatus("");
      } catch (ParseException pe) {
        String msg = "statusmsg.bar.error.parsing.operation";
        Object[] args = {pe.getLocalizedMessage(), new Integer(pe.getErrorOffset())};
        ProjectBrowser.getInstance().getStatusBar().showStatus(Translator.messageFormat(msg, args));
      }
      return;
    }
  }

  /**
   * @see
   *     org.argouml.uml.diagram.ui.FigNodeModelElement#textEditStarted(org.tigris.gef.presentation.FigText)
   */
  protected void textEditStarted(FigText ft) {
    super.textEditStarted(ft);
    if (getAttributesFig().getFigs().contains(ft)) {
      showHelp("parsing.help.attribute");
    }
    if (getOperationsFig().getFigs().contains(ft)) {
      showHelp("parsing.help.operation");
    }
  }

  /**
   * @param fgVec the FigGroup
   * @param ft the Figtext
   * @param i get the fig before fig i
   * @return the FigText
   */
  protected FigText getPreviousVisibleFeature(FigGroup fgVec, FigText ft, int i) {
    if (fgVec == null || i < 1) {
      return null;
    }
    FigText ft2 = null;
    // TODO: come GEF V 0.12 use getFigs returning an array
    Vector v = new Vector(fgVec.getFigs());
    if (i >= v.size() || !((FigText) v.elementAt(i)).isVisible()) {
      return null;
    }
    do {
      i--;
      while (i < 1) {
        if (fgVec == getAttributesFig()) {
          fgVec = getOperationsFig();
        } else {
          fgVec = getAttributesFig();
        }
        v = new Vector(fgVec.getFigs());
        i = v.size() - 1;
      }
      ft2 = (FigText) v.elementAt(i);
      if (!ft2.isVisible()) {
        ft2 = null;
      }
    } while (ft2 == null);
    return ft2;
  }

  /**
   * @param fgVec the FigGroup
   * @param ft the Figtext
   * @param i get the fig after fig i
   * @return the FigText
   */
  protected FigText getNextVisibleFeature(FigGroup fgVec, FigText ft, int i) {
    if (fgVec == null || i < 1) {
      return null;
    }
    FigText ft2 = null;
    // TODO: come GEF V 0.12 use getFigs returning an array
    Vector v = new Vector(fgVec.getFigs());
    if (i >= v.size() || !((FigText) v.elementAt(i)).isVisible()) {
      return null;
    }
    do {
      i++;
      while (i >= v.size()) {
        if (fgVec == getAttributesFig()) {
          fgVec = getOperationsFig();
        } else {
          fgVec = getAttributesFig();
        }
        v = new Vector(fgVec.getFigs());
        i = 1;
      }
      ft2 = (FigText) v.elementAt(i);
      if (!ft2.isVisible()) {
        ft2 = null;
      }
    } while (ft2 == null);
    return ft2;
  }

  /** @return the compartment */
  protected CompartmentFigText unhighlight() {
    CompartmentFigText fc = super.unhighlight();
    if (fc == null) {
      fc = unhighlight(getAttributesFig());
    }
    return fc;
  }

  /**
   * Handles changes of the model. Takes into account the event that occured. If you need to update
   * the whole fig, consider using renderingChanged.
   *
   * @see
   *     org.argouml.uml.diagram.ui.FigNodeModelElement#modelChanged(java.beans.PropertyChangeEvent)
   */
  protected void modelChanged(PropertyChangeEvent mee) {
    if (getOwner() == null) {
      return;
    }
    Object source = null;
    if (mee != null) {
      source = mee.getSource();
    } else {
      LOG.warn(
          "ModelChanged called with no event. "
              + "Please javadoc the situation in which this can happen");
    }

    // attributes
    if (mee == null
        || Model.getFacade().isAAttribute(source)
        || (source == getOwner() && mee.getPropertyName().equals("feature"))) {
      updateAttributes();
      damage();
    }
    // operations
    if (mee == null
        || Model.getFacade().isAOperation(source)
        || Model.getFacade().isAParameter(source)
        || (source == getOwner() && mee.getPropertyName().equals("feature"))) {
      updateOperations();
      damage();
    }
    if (mee != null
        && mee.getPropertyName().equals("parameter")
        && Model.getFacade().isAOperation(source)) {
      if (mee instanceof AddAssociationEvent) {
        AddAssociationEvent aae = (AddAssociationEvent) mee;
        /* Ensure we will get an event for the name change of
         * the newly created attribute: */
        Model.getPump()
            .addModelEventListener(
                this, aae.getChangedValue(), new String[] {"name", "kind", "type", "defaultValue"});
        damage();
        return;
      } else if (mee instanceof RemoveAssociationEvent) {
        RemoveAssociationEvent rae = (RemoveAssociationEvent) mee;
        Model.getPump().removeModelEventListener(this, rae.getChangedValue());
        damage();
        return;
      }
    }
    if (mee == null || mee.getPropertyName().equals("isAbstract")) {
      updateAbstract();
      damage();
    }
    if (mee == null || mee.getPropertyName().equals("stereotype")) {
      updateListeners(getOwner());
      updateStereotypeText();
      updateAttributes();
      updateOperations();
      damage();
    }
    if (mee != null && Model.getFacade().isAStereotype(source)) {
      if (Model.getFacade().getStereotypes(getOwner()).contains(source)) {
        updateStereotypeText();
        damage();
      } else if (mee.getPropertyName().equals("name")) {
        updateAttributes();
        updateOperations();
        damage();
      }
    }
    // name updating
    super.modelChanged(mee);
  }

  /**
   * @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateStereotypeText() TODO: Refactor into
   *     FigClassifierBox
   */
  protected void updateStereotypeText() {

    Rectangle rect = getBounds();

    int stereotypeHeight = 0;
    if (getStereotypeFig().isVisible()) {
      stereotypeHeight = getStereotypeFig().getHeight();
    }
    int heightWithoutStereo = getHeight() - stereotypeHeight;

    getStereotypeFig().setOwner(getOwner());
    ((FigStereotypesCompartment) getStereotypeFig()).populate();

    stereotypeHeight = 0;
    if (getStereotypeFig().isVisible()) {
      stereotypeHeight = getStereotypeFig().getHeight();
    }

    int minWidth = this.getMinimumSize().width;
    if (minWidth > rect.width) {
      rect.width = minWidth;
    }

    setBounds(rect.x, rect.y, rect.width, heightWithoutStereo + stereotypeHeight);
    calcBounds();
    newlyCreated = false;
  }

  /** @see org.tigris.gef.presentation.Fig#setEnclosingFig(org.tigris.gef.presentation.Fig) */
  public void setEnclosingFig(Fig encloser) {
    if (encloser == null
        || (encloser != null && !Model.getFacade().isAInstance(encloser.getOwner()))) {
      super.setEnclosingFig(encloser);
    }
    if (!(Model.getFacade().isAModelElement(getOwner()))) return;
    if (encloser != null && (Model.getFacade().isAComponent(encloser.getOwner()))) {
      Object component = /*(MComponent)*/ encloser.getOwner();
      Object in = /*(MInterface)*/ getOwner();
      Model.getCoreHelper().setContainer(resident, component);
      Model.getCoreHelper().setResident(resident, in);
    } else {
      Model.getCoreHelper().setContainer(resident, null);
      Model.getCoreHelper().setResident(resident, null);
    }
  }

  /**
   * Sets the bounds, but the size will be at least the one returned by {@link #getMinimumSize()},
   * unless checking of size is disabled.
   *
   * <p>If the required height is bigger, then the additional height is equally distributed among
   * all figs (i.e. compartments), such that the cumulated height of all visible figs equals the
   * demanded height
   *
   * <p>.
   *
   * <p>Some of this has "magic numbers" hardcoded in. In particular there is a knowledge that the
   * minimum height of a name compartment is 21 pixels.
   *
   * <p>
   *
   * @param x Desired X coordinate of upper left corner
   * @param y Desired Y coordinate of upper left corner
   * @param w Desired width of the FigClass
   * @param h Desired height of the FigClass
   */
  protected void setBoundsImpl(final int x, final int y, final int w, final int h) {
    Rectangle oldBounds = getBounds();

    // set bounds of big box
    getBigPort().setBounds(x, y, w, h);
    borderFig.setBounds(x, y, w, h);

    // Save our old boundaries (needed later), and get minimum size
    // info. "whitespace" will be used to maintain a running calculation of our
    // size at various points.

    final int whitespace = h - getMinimumSize().height;

    getNameFig().setLineWidth(0);
    getNameFig().setLineColor(Color.red);
    int currentHeight = 0;

    if (getStereotypeFig().isVisible()) {
      int stereotypeHeight = getStereotypeFig().getMinimumSize().height;
      getStereotypeFig().setBounds(x, y, w, stereotypeHeight);
      currentHeight = stereotypeHeight;
    }

    int nameHeight = getNameFig().getMinimumSize().height;
    getNameFig().setBounds(x, y + currentHeight, w, nameHeight);
    currentHeight += nameHeight;

    if (isAttributesVisible()) {
      int attributesHeight = getAttributesFig().getMinimumSize().height;
      if (isOperationsVisible()) {
        attributesHeight += whitespace / 2;
      }
      getAttributesFig().setBounds(x, y + currentHeight, w, attributesHeight);
      currentHeight += attributesHeight;
    }

    if (isOperationsVisible()) {
      int operationsY = y + currentHeight;
      int operationsHeight = (h + y) - operationsY - 1;
      if (operationsHeight < getOperationsFig().getMinimumSize().height) {
        operationsHeight = getOperationsFig().getMinimumSize().height;
      }
      getOperationsFig().setBounds(x, operationsY, w, operationsHeight);
    }

    // Now force calculation of the bounds of the figure, update the edges
    // and trigger anyone who's listening to see if the "bounds" property
    // has changed.

    calcBounds();
    updateEdges();
    firePropChange("bounds", oldBounds, getBounds());
  }

  /**
   * Updates the attributes in the fig. Called from modelchanged if there is a modelevent effecting
   * the attributes and from renderingChanged in all cases.
   */
  protected void updateAttributes() {
    if (!isAttributesVisible()) {
      return;
    }
    FigAttributesCompartment attributesCompartment = getAttributesFig();
    attributesCompartment.populate();

    Rectangle rect = getBounds();

    // ouch ugly but that's for a next refactoring
    // TODO: make setBounds, calcBounds and updateBounds consistent
    setBounds(rect.x, rect.y, rect.width, rect.height);
  }

  /**
   * Updates the operations box. Called from modelchanged if there is a modelevent effecting the
   * attributes and from renderingChanged in all cases.
   */
  protected void updateOperations() {
    if (!isOperationsVisible()) {
      return;
    }
    operationsFig.populate();

    Rectangle rect = getBounds();
    // ouch ugly but that's for a next refactoring
    // TODO: make setBounds, calcBounds and updateBounds consistent
    setBounds(rect.x, rect.y, rect.width, rect.height);
  }

  /** @see org.argouml.uml.diagram.ui.FigNodeModelElement#renderingChanged() */
  public void renderingChanged() {
    if (getOwner() != null) {
      updateAttributes();
      updateOperations();
      updateAbstract();
    }
    super.renderingChanged();
  }

  /** @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateNameText() */
  protected void updateNameText() {
    super.updateNameText();
    calcBounds();
    setBounds(getBounds());
  }

  /** Updates the name if modelchanged receives an "isAbstract" event. */
  protected void updateAbstract() {
    Rectangle rect = getBounds();
    if (getOwner() == null) {
      return;
    }
    Object cls = /*(MClass)*/ getOwner();
    if (Model.getFacade().isAbstract(cls)) {
      getNameFig().setFont(getItalicLabelFont());
    } else {
      getNameFig().setFont(getLabelFont());
    }
    super.updateNameText();
    setBounds(rect.x, rect.y, rect.width, rect.height);
  }

  /** @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateListeners(java.lang.Object) */
  protected void updateListeners(Object newOwner) {
    Object oldOwner = getOwner();
    if (oldOwner != null && oldOwner != newOwner) {
      // remove the listeners if the owner is changed
      Iterator it = Model.getFacade().getFeatures(oldOwner).iterator();
      while (it.hasNext()) {
        Object feat = it.next();
        Model.getPump().removeModelEventListener(this, feat);
        Collection c = new ArrayList(Model.getFacade().getStereotypes(feat));
        if (Model.getFacade().isAOperation(feat)) {
          c.addAll(Model.getFacade().getParameters(feat));
        }
        Iterator it2 = c.iterator();
        while (it2.hasNext()) {
          Object obj = it2.next();
          Model.getPump().removeModelEventListener(this, obj);
        }
      }
    }
    if (newOwner != null) {
      // add the listeners to the newOwner
      Iterator it = Model.getFacade().getFeatures(newOwner).iterator();
      while (it.hasNext()) {
        Object feat = it.next();
        Collection c = new ArrayList(Model.getFacade().getStereotypes(feat));
        if (Model.getFacade().isAOperation(feat)) {
          c.addAll(Model.getFacade().getParameters(feat));
        }
        Iterator it2 = c.iterator();
        while (it2.hasNext()) {
          Object obj = it2.next();
          Model.getPump().addModelEventListener(this, obj);
        }
      }
    }
    super.updateListeners(newOwner);
  }
} /* end class FigClass */
コード例 #30
0
 /** @see org.argouml.uml.diagram.static_structure.ui.SelectionDataType#getNewNode(int) */
 protected Object getNewNode(int buttonCode) {
   Object ns = Model.getFacade().getNamespace(getContent().getOwner());
   return Model.getCoreFactory().buildEnumeration("", ns);
 }