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);
      }
    }
  }
  private void findReferencedPackages(EClassifier classifier) {
    if (classifier instanceof EClass == false) {
      return;
    }

    EClass cls = (EClass) classifier;

    for (EClass superClass : cls.getEAllSuperTypes()) {
      referenced(superClass);
    }

    for (EReference ref : cls.getEAllReferences()) {
      EClassifier type = ref.getEType();
      if (type != null) {
        referenced(type);
      }
    }
  }
  /**
   * @see org.teiid.designer.core.util.ModelVisitor#visit(org.eclipse.emf.ecore.EObject)
   * @since 4.3
   */
  @Override
  public boolean visit(final EObject object) {
    // Find all references ...
    final EClass eclass = object.eClass();
    final Collection allRefs = eclass.getEAllReferences();

    for (final Iterator i = allRefs.iterator(); i.hasNext(); ) {
      final EReference reference = (EReference) i.next();

      // Process only non-containment references ...
      if (!reference.isContainment() && !reference.isContainer() && !reference.isVolatile()) {
        final Object value = object.eGet(reference, false);

        if (reference.isMany()) {
          // There may be many values ...
          boolean removeRefdValue = false;
          for (Iterator j = ((List) value).iterator(); j.hasNext(); ) {
            final Object valueInList = j.next();
            if (valueInList instanceof EObject && valueInList == refdObject) {
              removeRefdValue = true;
            }
          }
          if (removeRefdValue && reference.isChangeable()) {
            ((List) value).remove(refdObject);
            this.affectedObjects.add(object);
          }

        } else {
          // There may be 0..1 value ...
          if (value instanceof EObject && value == refdObject) {
            if (reference.isChangeable()) {
              object.eUnset(reference);
              this.affectedObjects.add(object);
            }
          }
        }
      }
    }
    return true;
  }
  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;
  }
  /**
   * Updates chart element object.
   *
   * @param expected class of expected chart element.
   * @param name chart element name
   * @param eParentObj container of chart element object.
   * @param eObj chart element object.
   * @param eRef reference chart object to be used to update chart object's values.
   * @param eDef default chart object to be used to update chart object's values.
   */
  public void update(
      EClass expected, String name, EObject eParentObj, EObject eObj, EObject eRef, EObject eDef) {
    if (eObj == null) {
      if (eRef != null) {
        if (eRef instanceof IChartObject) {
          eObj = ((IChartObject) eRef).copyInstance();
          ChartElementUtil.setEObjectAttribute(eParentObj, name, eObj, false);
        }
      } else if (eDef != null) {
        if (eDef instanceof IChartObject) {
          eObj = ((IChartObject) eDef).copyInstance();
          ChartElementUtil.setEObjectAttribute(eParentObj, name, eObj, false);
          return;
        }
      }
    }
    if (eObj == null || (eRef == null && eDef == null)) {
      return;
    }

    // Process visible case.
    if (contanisVisibleElement(eObj.eClass())) {
      if (eObj.eIsSet(eObj.eClass().getEStructuralFeature("visible"))) // $NON-NLS-1$
      {
        if (eObj.eGet(eObj.eClass().getEStructuralFeature("visible"))
            != Boolean.TRUE) // $NON-NLS-1$
        {
          // If the visible attribute is set to false, directly return, no need
          // to update other attributes.
          return;
        }
      } else {
        // If eObj isn't set visible and the visible attribute of
        // reference object is set to false, directly return, no need to
        // update other attributes.
        if (eRef != null
            && eRef.eIsSet(eRef.eClass().getEStructuralFeature("visible"))) // $NON-NLS-1$
        {
          if (eRef.eGet(eRef.eClass().getEStructuralFeature("visible"))
              != Boolean.TRUE) // $NON-NLS-1$
          {
            eObj.eSet(eRef.eClass().getEStructuralFeature("visible"), Boolean.FALSE); // $NON-NLS-1$
            return;
          }
        } else if (eDef != null
            && eDef.eIsSet(eDef.eClass().getEStructuralFeature("visible"))) // $NON-NLS-1$
        {
          if (eDef.eGet(eDef.eClass().getEStructuralFeature("visible"))
              != Boolean.TRUE) // $NON-NLS-1$
          {
            eObj.eSet(eDef.eClass().getEStructuralFeature("visible"), Boolean.FALSE); // $NON-NLS-1$
            return;
          }
        }
      }
    }

    EClass eClass = eObj.eClass();

    // attributes
    updateAttrs(eClass, eParentObj, eObj, eRef, eDef);

    // list attributes

    // references
    for (EReference ref : eClass.getEAllReferences()) {
      String childName = ref.getName();
      Object child = eObj.eGet(ref);
      Object refChild = eRef != null ? eRef.eGet(ref) : null;
      Object defChild = eDef != null ? eDef.eGet(ref) : null;
      EObject eChildParntObj = eObj;
      if (child == null) {
        if (refChild != null) {
          if (refChild instanceof IChartObject) {
            child = updateFromReference(childName, refChild, eChildParntObj);
          }
        } else if (defChild != null) {
          if (defChild instanceof IChartObject) {
            child = ((IChartObject) defChild).copyInstance();
            ChartElementUtil.setEObjectAttribute(eChildParntObj, childName, child, false);
            continue;
          }
        }
      }

      if (child != null) {
        if (ref.isMany()) {
          int size = ((List<?>) child).size();
          for (int i = 0; i < size; i++) {
            Object item = ((List<?>) child).get(i);
            Object refItem =
                (refChild == null || (i >= ((List<?>) refChild).size()))
                    ? null
                    : ((List<?>) refChild).get(i);
            Object defItem =
                (defChild == null || (i >= ((List<?>) defChild).size()))
                    ? null
                    : ((List<?>) defChild).get(i);
            update(ref, eObj, (EObject) item, (EObject) refItem, (EObject) defItem);
          }
        } else {
          update(ref, eObj, (EObject) child, (EObject) refChild, (EObject) defChild);
        }
      }
    }
  }