Ejemplo n.º 1
0
 protected void updateLabel(FormElement fw, String name) {
   if (headless) {
     fw.setLabel(name);
   } else {
     cc.append(SetCommand.create(domain, fw, FormPackage.eINSTANCE.getFormElement_Label(), name));
   }
 }
Ejemplo n.º 2
0
  public void updateAttributeFields(
      FormContainer formContainer, FormElement formElement, Attribute att) {
    FormElement fieldForAttribute = null;
    if (formContainer instanceof FormSearch) {
      fieldForAttribute = SearchInitialization.getSearchFieldForAttribute(att);
    } else if (formContainer instanceof FormClass || formContainer instanceof FormWorkflow) {
      fieldForAttribute = ClassDiagramUtils.getFieldForAttribute(att);
    }

    if (!fieldForAttribute.getClass().isInstance(formElement)) {
      // mismatch so we replace the Field
      FormGroup eContainer = (FormGroup) formElement.eContainer();
      boolean contains = eContainer.getChildren().contains(formElement);

      if (headless) {
        EList<FormElement> children = null;
        if (contains) {
          children = eContainer.getChildren();
        } else {
          children = eContainer.getDisabled();
        }
        // add the new Field
        children.add(fieldForAttribute);
        // remove
        children.remove(formElement);
      } else {
        if (contains) {
          cc.append(
              AddCommand.create(
                  domain,
                  eContainer,
                  FormPackage.eINSTANCE.getFormGroup_Children(),
                  fieldForAttribute));
        } else {
          cc.append(
              AddCommand.create(
                  domain,
                  eContainer,
                  FormPackage.eINSTANCE.getFormGroup_Disabled(),
                  fieldForAttribute));
        }
        Command rmCmd = RemoveCommand.create(domain, formElement);
        cc.append(rmCmd);
      }
    }
  }
Ejemplo n.º 3
0
 protected void updateId(FormElement fw, String computeFormWorkflowId) {
   if (headless) {
     fw.setId(computeFormWorkflowId);
   } else {
     cc.append(
         SetCommand.create(
             domain, fw, FormPackage.eINSTANCE.getFormElement_Id(), computeFormWorkflowId));
   }
 }
Ejemplo n.º 4
0
  void update(FormContainer formContainer, List<FormElement> allchildren) {
    // update id
    if (updateId) {
      updateFormContainerId(formContainer);
    }

    if (updateLabel) {
      updateLabel(
          formContainer, ((TitledNamedClassModelElement) formContainer.getRef()).getLabel());
    }

    for (FormElement formElement : allchildren) {
      ModelElement ref = formElement.getRef();
      if (ref instanceof NamedModelElement) {
        NamedModelElement nme = (NamedModelElement) ref;
        String name = nme.getName();

        if (updateId && !name.equals(formElement.getId())) {
          updateId(formElement, name);
        }

        if (updateLabel && ref instanceof TitledNamedClassModelElement) {
          updateLabel(formContainer, ((TitledNamedClassModelElement) ref).getLabel());
        }
      }

      // check Field subType
      if (ref instanceof Attribute) {
        Attribute att = (Attribute) ref;

        updateAttributeFields(formContainer, formElement, att);
      } else if (ref instanceof Association) {

        Association ass = (Association) ref;
        if (formElement instanceof ModelChoiceField) {
          ModelChoiceField mcf = (ModelChoiceField) formElement;
          ClassReference cref = (ClassReference) formContainer;
          AbstractClass srcClazz = cref.getReal_class();
          updateModelChoiceField(srcClazz, ass, mcf);
        }
      }
    }
  }
Ejemplo n.º 5
0
  protected void synchronizeMissingAttributes(
      FormContainer o,
      List<FormElement> children,
      AbstractClass real_class,
      Set<FormGroup> groups,
      String filterNS) {

    List<Attribute> allAttributes = real_class.getAllAttributes();

    // get FormElement that miss
    ArrayList<Attribute> missAtt = new ArrayList<Attribute>();

    if (allAttributes != null) {
      missAtt.addAll(allAttributes);
    }

    for (FormElement formElement : children) {
      ModelElement ref = formElement.getRef();
      if (ref != null && ref instanceof Attribute) {
        // linked element is attribute so remove this attribute from the missing list
        missAtt.remove(ref);
      }
    }

    EList<FormGroup> allSubGroups = o.getAllSubGroups();
    groups.addAll(allSubGroups);

    // now we have the attribute missing list
    // initialize missing Field
    for (Attribute attribute : missAtt) {
      // Field or searchField
      FormElement fieldForAttribute = null;
      if (o instanceof FormSearch) {
        fieldForAttribute = SearchInitialization.getSearchFieldForAttribute(attribute);
      } else if (o instanceof FormClass || o instanceof FormWorkflow) {
        fieldForAttribute = ClassDiagramUtils.getFieldForAttribute(attribute);
      } else {
        System.out.println("SynchronizeWithClass.synchronizeMissingAttributes() o :" + o);
      }
      if (WorkflowInitialization.filterFormElement(filterNS, fieldForAttribute)) {

        // get where to add the field
        FormGroup parent = null;
        // mybe a group exist with ref to the attribute container
        AbstractClass eContainer = (AbstractClass) attribute.eContainer();
        // search for matching group

        for (FormGroup formGroup : groups) {
          ModelElement ref = formGroup.getRef();
          if (ref != null && ref.equals(eContainer)) {
            // matching group founded
            parent = formGroup;
            break;
          }
        }
        if (createMissingGroup && parent == null) {
          parent = ClassInitialization.createGroup(eContainer);
          groups.add(parent);
          addChild(o, parent);
        }
        if (parent == null) {
          parent = o;
        }

        // add new Field to the parent
        addChild(parent, fieldForAttribute);
      }
    }
  }
Ejemplo n.º 6
0
  protected void synchronizeMissingAssociations(
      FormContainer o,
      List<FormElement> children,
      AbstractClass real_class,
      Set<FormGroup> groups,
      String filterNS) {

    List<Association> allAssociations = real_class.getAllSourceAssociations();

    // get FormElement that miss
    ArrayList<Association> missAtt = new ArrayList<Association>();

    if (allAssociations != null) {
      missAtt.addAll(allAssociations);
    }

    for (FormElement formElement : children) {
      ModelElement ref = formElement.getRef();
      if (ref != null && ref instanceof Association) {
        // linked element is attribute so remove this attribute from the missing list
        missAtt.remove(ref);
      }
    }

    EList<FormGroup> allSubGroups = o.getAllSubGroups();
    groups.addAll(allSubGroups);

    // now we have the attribute missing list
    // initialize missing Field
    for (Association ass : missAtt) {

      FormElement fieldForAssociation = null;
      if (o instanceof FormClass || o instanceof FormWorkflow) {
        fieldForAssociation = ClassDiagramUtils.getModelChoiceFieldForAssociation(ass, real_class);
      } else if (o instanceof FormSearch) {
        fieldForAssociation =
            ClassDiagramUtils.transformAssociationIntoModelChoiceSearchField(ass, real_class);
      }

      if (WorkflowInitialization.filterFormElement(filterNS, fieldForAssociation)) {

        // get where to add the field
        FormGroup parent = null;
        // mybe a group exist with ref to the attribute container

        // search for matching group

        for (FormGroup formGroup : groups) {
          ModelElement ref = formGroup.getRef();
          if (ref instanceof AbstractClass
              && ((AbstractClass) ref).getSourceAssociations().contains(ass)) {
            // matching group founded
            parent = formGroup;
            break;
          }
        }

        if (createMissingGroup && parent == null) {
          AbstractClass source = null;
          EList<AbstractClass> sources = ass.getSource();
          if (sources.size() == 1) {
            source = sources.get(0);
          } else {
            EList<AbstractClass> allLinkedAbstractClass = real_class.getAllLinkedAbstractClass();
            boolean contains = allLinkedAbstractClass.contains(sources.get(0));
            if (contains) {
              source = sources.get(0);
            } else {
              source = sources.get(1);
            }
          }
          parent = ClassInitialization.createGroup(source);
          addChild(o, parent);
        }

        // add new Field to the parent
        if (parent == null) {
          parent = o;
        }
        addChild(parent, fieldForAssociation);
      }
    }
  }