public static void printAttributeValues(EObject object) {
   EClass eClass = object.eClass();
   System.out.println(eClass.getName());
   for (Iterator iter = eClass.getEAllAttributes().iterator(); iter.hasNext(); ) {
     EAttribute attribute = (EAttribute) iter.next();
     Object value = object.eGet(attribute);
     System.out.print("  " + attribute.getName() + ": " + value);
     if (object.eIsSet(attribute)) {
       System.out.println(); // attribute is set
     } else {
       System.out.println(" (default)"); // attribute is not set
     }
   }
 } // printAttributeValues
  private void setEnabledAll(boolean enabled) {
    for (EClass e : elementSet) {
      prefs.putBoolean(e.getName(), enabled);

      for (EAttribute a : e.getEAllAttributes()) {
        prefs.putBoolean(e.getName() + "." + a.getName(), enabled);
      }

      for (EReference a : e.getEAllContainments()) {
        prefs.putBoolean(e.getName() + "." + a.getName(), enabled);
      }

      for (EReference a : e.getEAllReferences()) {
        prefs.putBoolean(e.getName() + "." + a.getName(), enabled);
      }
    }
  }
  @SuppressWarnings({"unchecked", "rawtypes"})
  private void updateAttrs(
      EClass eClass, EObject eParentObj, EObject eObj, EObject eRef, EObject eDef) {

    List<EAttribute> listMany = new LinkedList<EAttribute>();
    List<EAttribute> list = new LinkedList<EAttribute>();

    for (EAttribute eAttr : eClass.getEAllAttributes()) {
      if (eAttr.isMany()) {
        listMany.add(eAttr);
      } else {
        list.add(eAttr);
      }
    }

    for (EAttribute eAttr : listMany) {
      List<?> vList = (List<?>) eObj.eGet(eAttr);
      if (vList.size() == 0) {
        if (eRef != null && ((List<?>) eRef.eGet(eAttr)).size() > 0) {
          vList.addAll((List) eRef.eGet(eAttr));
        } else if (eDef != null) {
          vList.addAll((List) eDef.eGet(eAttr));
        }
      }
    }

    for (EAttribute eAttr : list) {
      Object val = eObj.eGet(eAttr);
      if (eAttr.isUnsettable()) {
        if (!eObj.eIsSet(eAttr)) {
          if (eRef != null && eRef.eIsSet(eAttr)) {
            eObj.eSet(eAttr, eRef.eGet(eAttr));
          } else if (eDef != null && eDef.eIsSet(eAttr)) {
            eObj.eSet(eAttr, eDef.eGet(eAttr));
          }
        }
      } else if (val == null) {
        if (eRef != null && eRef.eGet(eAttr) != null) {
          eObj.eSet(eAttr, eRef.eGet(eAttr));
        } else if (eDef != null) {
          eObj.eSet(eAttr, eDef.eGet(eAttr));
        }
      }
    }
  }
 protected EStructuralFeature getLabelFeature(EClass eClass) {
   EAttribute result = null;
   for (EAttribute eAttribute : eClass.getEAllAttributes()) {
     if (!eAttribute.isMany()
         && eAttribute.getEType().getInstanceClass() != FeatureMap.Entry.class) {
       if ("name".equalsIgnoreCase(eAttribute.getName())) {
         result = eAttribute;
         break;
       } else if (result == null) {
         result = eAttribute;
       } else if (eAttribute.getEAttributeType().getInstanceClass() == String.class
           && result.getEAttributeType().getInstanceClass() != String.class) {
         result = eAttribute;
       }
     }
   }
   return result;
 }
  /**
   * This creates an {@link OclCondition} which describes the given object.<br>
   * Subclasses may override or extend the condition.
   *
   * @param self the context
   * @return an {@link OclCondition} which sufficiently describes the context
   */
  protected OclCondition createOclCondition(EObject self) {
    final EClass eclass = self.eClass();

    // build ocl condition for all attributes as a string
    String expr = ""; // "self.oclIsTypeOf(" + eclass.getName() + ")";
    for (final EAttribute attribute : eclass.getEAllAttributes()) {
      if (isRelevantAttribute(attribute)) {
        expr +=
            (expr.length() > 0 ? " and " : "")
                + eAttributeToCondition(attribute, self.eGet(attribute));
      }
    }

    // create ocl condition object
    final OclCondition condition = SymrefsFactory.eINSTANCE.createOclCondition();
    condition.setExpression(expr);

    return condition;
  }
 public String getHoverText(org.eclipse.emf.ecore.EObject object) {
   if (object == null) {
     return null;
   }
   org.eclipse.emf.ecore.EClass eClass = object.eClass();
   String label = "<strong>" + eClass.getName() + "</strong>";
   String documentation = org.eclipse.emf.ecore.util.EcoreUtil.getDocumentation(eClass);
   String documentationHTML = documentation == null ? "" : " (" + documentation + ")";
   label += documentationHTML;
   for (org.eclipse.emf.ecore.EAttribute attribute : eClass.getEAllAttributes()) {
     Object value = null;
     try {
       value = object.eGet(attribute);
     } catch (Exception e) {
       // Exception in eGet, do nothing
     }
     if (value != null && value.toString() != null && !value.toString().equals("[]")) {
       label += "<br />" + attribute.getName() + ": " + object.eGet(attribute).toString();
     }
   }
   return label;
 }
  public List<ToolEnablement> getAllElements() {
    ArrayList<ToolEnablement> ret = new ArrayList<ToolEnablement>();

    for (EClass e : elementSet) {

      ToolEnablement tool = new ToolEnablement();
      tool.setTool(e);
      tool.setEnabled(isEnabled(e));
      ret.add(tool);

      HashSet<EStructuralFeature> possibleFeatures = new HashSet<EStructuralFeature>();

      ArrayList<ToolEnablement> children = new ArrayList<ToolEnablement>();

      for (EAttribute a : e.getEAllAttributes()) {
        possibleFeatures.add(a);
      }

      for (EReference a : e.getEAllContainments()) {
        possibleFeatures.add(a);
      }

      for (EReference a : e.getEAllReferences()) {
        possibleFeatures.add(a);
      }

      for (EStructuralFeature feature : possibleFeatures) {
        ToolEnablement toolEnablement = new ToolEnablement(feature, tool);
        toolEnablement.setEnabled(isEnabled(e, feature));
        children.add(toolEnablement);
      }
      sortTools(children);
      tool.setChildren(children);
    }
    sortTools(ret);
    return ret;
  }
  /**
   * Generates the object described in the given instanciationInstruction.
   *
   * @param instanciationInstruction the instantiation instruction to inspect
   * @param importedPackageURIS the URIs corresponding to all the packages imported in this
   *     ModelingUnit
   * @param linkResolver the entity used in order to resolve links
   * @param modelingUnitGenerator the dispatcher to use for calling the correct generator on
   *     sub-elements
   * @return the object described in the given instanciationInstruction
   */
  public static EObject generate(
      InstanciationInstruction instanciationInstruction,
      List<String> importedPackageURIS,
      ModelingUnitLinkResolver linkResolver,
      ModelingUnitGenerator modelingUnitGenerator) {

    ModelingUnitGenerator.clearCompilationStatus(instanciationInstruction);

    EObject createdElement = null;
    // Step 1 : resolving the link to the metaType (thanks to the linkResolver)
    String metaTypeHref = instanciationInstruction.getMetaType().getTypeName();
    try {
      EClass metaType =
          (EClass)
              linkResolver.resolveEClassifierUsingPackage(
                  instanciationInstruction, importedPackageURIS, metaTypeHref);
      instanciationInstruction.getMetaType().setResolvedType(metaType);

      // Step 2 : instantiate correctly this entity
      // Step 2.1 : Creation using the factory
      createdElement = metaType.getEPackage().getEFactoryInstance().create(metaType);

      // Step 2.2 : If a name has been associated to this instance
      if (instanciationInstruction.getName() != null) {
        // We determine if this name can be assigned to any attribute
        for (EAttribute attribute : metaType.getEAllAttributes()) {
          if (isConcernedByNameAttribute(attribute)) {
            // if so, we set this attribute
            createdElement.eSet(attribute, instanciationInstruction.getName());
          }
        }
      }
      // Step 2.3 : We set all the structuralFeatureAffectation associated to this instance
      // leaving the other attributes to default values.
      for (StructuralFeatureAffectation sfa : instanciationInstruction.getStructuralFeatures()) {
        StructuralFeatureGenerator.generateFeatureAndAddToClass(
            sfa, createdElement, linkResolver, modelingUnitGenerator);
      }
    } catch (ResolveException e) {
      // If the metaType of the element to generate cannot be resolved
      // We generate a compilation status
      modelingUnitGenerator
          .getInformationHolder()
          .registerCompilationExceptionAsCompilationStatus(
              new CompilationException(
                  e.getInvalidInstruction(),
                  CompilationErrorType.INVALID_REFERENCE_ERROR,
                  e.getMessage()));
      // And we create a sample object, in order to let the compilation running
      createdElement = EcoreFactory.eINSTANCE.createEObject();
    } catch (IllegalArgumentException e) {
      modelingUnitGenerator
          .getInformationHolder()
          .registerCompilationExceptionAsCompilationStatus(
              new CompilationException(
                  instanciationInstruction,
                  CompilationErrorType.INVALID_VALUE_ERROR,
                  e.getMessage()));
      // And we create a sample object, in order to let the compilation running
      createdElement = EcoreFactory.eINSTANCE.createEObject();
    }

    // Step 3 : Registration of the generated element
    // Step 3.1 : we add the generated element in the current created Elements list
    modelingUnitGenerator
        .getInformationHolder()
        .addNameToCreatedElementEntry(
            instanciationInstruction.getName(), createdElement, instanciationInstruction);

    if (createdElement instanceof EPackage) {
      linkResolver.unregisterEPackage((EPackage) createdElement);
    }

    // Step 3.2 : if any unresolved contribution instructions were contributed to this element
    // We resolve these contributions
    for (final UnresolvedContributionHolder contributionHolder :
        modelingUnitGenerator
            .getInformationHolder()
            .getContributionsAssociatedTo(instanciationInstruction.getName())) {
      ContributionInstructionGenerator.generate(
          contributionHolder.getReferencedContribution(), modelingUnitGenerator, linkResolver);
    }

    return createdElement;
  }
  /**
   * Creates a list mapper that corresponding to the facilities of the specified type.
   *
   * <p>The mapper is chosen according to the following priorities:
   *
   * <ul>
   *   <li>annotated field
   *   <li>via genmodel label field - requires additional generation of information
   *   <li>by field name: label, name, fullName
   *   <li>by field type: String
   *   <li>{@link #toString()}
   * </ul>
   *
   * @param binding the binding to map
   * @param ec the class to create the mapper for
   * @return the mapper
   */
  public static IClassIdentiferMapper createClassIdentiferMapper(IBinding binding, EClass ec) {
    EStructuralFeature feature;

    /*
     * Any constant string is used first of all...
     *
     * TODO: Problem: if text is specified, icon and other arguments are ignored!
     */
    final String constantText = binding.getArgument(Constants.ARG_TEXT, String.class, null);
    if (constantText != null)
      return new IClassIdentiferMapper() {
        @Override
        public Object map(Object value) {
          return constantText;
        }

        @Override
        public IObservableValue getObservableValue(
            IObservableValue value, EditingDomain editingDomain) {
          return value;
        }
      };

    // Via Annotation
    final String featureNames = binding.getArgument(Constants.ARG_FEATURE_NAME, String.class, null);
    if (featureNames != null) {
      // Pattern.compile("(\\p{L}+)")
      final StringTokenizer st = new StringTokenizer(featureNames, ".");
      EClassifier c = ec;
      final List<EStructuralFeature> sfs = new ArrayList<EStructuralFeature>();
      while (st.hasMoreTokens()) {
        final String name = st.nextToken();
        binding.assertTrue(c instanceof EClass, "Intermidiate features must be references");
        final EClass eClass = (EClass) c;
        feature = eClass.getEStructuralFeature(name);
        binding.assertTrue(
            feature != null,
            "Unknown feature: '"
                + eClass.getName()
                + "."
                + name
                + "' in argument "
                + Constants.ARG_FEATURE_NAME
                + " ("
                + featureNames
                + ")");

        sfs.add(feature);
        c = feature.getEType();
      }

      switch (sfs.size()) {
        case 0:
          LogUtils.error(
              binding,
              "Feature names '" + featureNames + "' does not exist. Ignored.",
              binding.getCreationPoint());
          break;
        case 1:
          return new SingleFeatureMapper(sfs.get(0));
        default:
          return new MultipleFeatureMapper(sfs.toArray(new EStructuralFeature[sfs.size()]));
      }
    }

    // By Field Name
    feature = ec.getEStructuralFeature("label");
    if (feature != null) return new SingleFeatureMapper(feature);
    feature = ec.getEStructuralFeature("name");
    if (feature != null) return new SingleFeatureMapper(feature);
    feature = ec.getEStructuralFeature("fullName");
    if (feature != null) return new SingleFeatureMapper(feature);

    // By Field Type
    for (final EAttribute a : ec.getEAllAttributes()) {
      if (a.getEType() == EcorePackage.Literals.ESTRING) return new SingleFeatureMapper(a);
    }

    // Fall back on toString()....
    return DEFAULT_MAPPER;
  }