/**
  * {@inheritDoc}
  *
  * @see
  *     org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
  */
 public Diagnostic validateValue(IPropertiesEditionEvent event) {
   Diagnostic ret = Diagnostic.OK_INSTANCE;
   if (event.getNewValue() != null) {
     try {
       if (GsnViewsRepository.Solution.Properties.identifier == event.getAffectedEditor()) {
         Object newValue = event.getNewValue();
         if (newValue instanceof String) {
           newValue =
               EcoreUtil.createFromString(
                   ArmPackage.eINSTANCE.getModelElement_Identifier().getEAttributeType(),
                   (String) newValue);
         }
         ret =
             Diagnostician.INSTANCE.validate(
                 ArmPackage.eINSTANCE.getModelElement_Identifier().getEAttributeType(), newValue);
       }
       if (GsnViewsRepository.Solution.Properties.description == event.getAffectedEditor()) {
         Object newValue = event.getNewValue();
         if (newValue instanceof String) {
           newValue =
               EcoreUtil.createFromString(
                   ArmPackage.eINSTANCE.getModelElement_Description().getEAttributeType(),
                   (String) newValue);
         }
         ret =
             Diagnostician.INSTANCE.validate(
                 ArmPackage.eINSTANCE.getModelElement_Description().getEAttributeType(), newValue);
       }
       if (GsnViewsRepository.Solution.Properties.content == event.getAffectedEditor()) {
         Object newValue = event.getNewValue();
         if (newValue instanceof String) {
           newValue =
               EcoreUtil.createFromString(
                   ArmPackage.eINSTANCE.getModelElement_Content().getEAttributeType(),
                   (String) newValue);
         }
         ret =
             Diagnostician.INSTANCE.validate(
                 ArmPackage.eINSTANCE.getModelElement_Content().getEAttributeType(), newValue);
       }
     } catch (IllegalArgumentException iae) {
       ret = BasicDiagnostic.toDiagnostic(iae);
     } catch (WrappedException we) {
       ret = BasicDiagnostic.toDiagnostic(we);
     }
   }
   return ret;
 }
 /**
  * {@inheritDoc}
  *
  * @see
  *     org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
  */
 public Diagnostic validateValue(IPropertiesEditionEvent event) {
   Diagnostic ret = Diagnostic.OK_INSTANCE;
   if (event.getNewValue() != null) {
     try {
       if (UmlViewsRepository.LinkEndDestructionData.Properties.isDestroyDuplicates
           == event.getAffectedEditor()) {
         Object newValue = event.getNewValue();
         if (newValue instanceof String) {
           newValue =
               EcoreUtil.createFromString(
                   UMLPackage.eINSTANCE
                       .getLinkEndDestructionData_IsDestroyDuplicates()
                       .getEAttributeType(),
                   (String) newValue);
         }
         ret =
             Diagnostician.INSTANCE.validate(
                 UMLPackage.eINSTANCE
                     .getLinkEndDestructionData_IsDestroyDuplicates()
                     .getEAttributeType(),
                 newValue);
       }
     } catch (IllegalArgumentException iae) {
       ret = BasicDiagnostic.toDiagnostic(iae);
     } catch (WrappedException we) {
       ret = BasicDiagnostic.toDiagnostic(we);
     }
   }
   return ret;
 }
 /**
  * {@inheritDoc}
  *
  * @see
  *     org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
  */
 public Diagnostic validateValue(IPropertiesEditionEvent event) {
   Diagnostic ret = Diagnostic.OK_INSTANCE;
   if (event.getNewValue() != null) {
     try {
       if (SpemViewsRepository.ProcessComponent.Properties.name == event.getAffectedEditor()) {
         Object newValue = event.getNewValue();
         if (newValue instanceof String) {
           newValue =
               EcoreUtil.createFromString(
                   SpemPackage.eINSTANCE.getProcessPackageableElement_Name().getEAttributeType(),
                   (String) newValue);
         }
         ret =
             Diagnostician.INSTANCE.validate(
                 SpemPackage.eINSTANCE.getProcessPackageableElement_Name().getEAttributeType(),
                 newValue);
       }
     } catch (IllegalArgumentException iae) {
       ret = BasicDiagnostic.toDiagnostic(iae);
     } catch (WrappedException we) {
       ret = BasicDiagnostic.toDiagnostic(we);
     }
   }
   return ret;
 }
 /**
  * {@inheritDoc}
  *
  * @see
  *     org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
  */
 public Diagnostic validateValue(IPropertiesEditionEvent event) {
   Diagnostic ret = Diagnostic.OK_INSTANCE;
   if (event.getNewValue() != null) {
     try {
       if (DroidViewsRepository.RotateAnimation.Properties.fromAlpha
           == event.getAffectedEditor()) {
         Object newValue = event.getNewValue();
         if (newValue instanceof String) {
           newValue =
               EcoreUtil.createFromString(
                   DroidPackage.eINSTANCE
                       .getTerminalAnimationElements_FromAlpha()
                       .getEAttributeType(),
                   (String) newValue);
         }
         ret =
             Diagnostician.INSTANCE.validate(
                 DroidPackage.eINSTANCE
                     .getTerminalAnimationElements_FromAlpha()
                     .getEAttributeType(),
                 newValue);
       }
       if (DroidViewsRepository.RotateAnimation.Properties.toAlpha == event.getAffectedEditor()) {
         Object newValue = event.getNewValue();
         if (newValue instanceof String) {
           newValue =
               EcoreUtil.createFromString(
                   DroidPackage.eINSTANCE
                       .getTerminalAnimationElements_ToAlpha()
                       .getEAttributeType(),
                   (String) newValue);
         }
         ret =
             Diagnostician.INSTANCE.validate(
                 DroidPackage.eINSTANCE.getTerminalAnimationElements_ToAlpha().getEAttributeType(),
                 newValue);
       }
     } catch (IllegalArgumentException iae) {
       ret = BasicDiagnostic.toDiagnostic(iae);
     } catch (WrappedException we) {
       ret = BasicDiagnostic.toDiagnostic(we);
     }
   }
   return ret;
 }
  @Override
  public void load() {
    Object value = getElementText(node);
    if (feature instanceof EAttribute) {
      EAttribute ea = (EAttribute) feature;
      value = EcoreUtil.createFromString(ea.getEAttributeType(), value.toString());
    }

    modelObject.eSet(feature, value);
  }
Beispiel #6
0
  private void setEAttributeValue(EObject obj, EAttribute attribute, JsonNode value) {
    @SuppressWarnings("deprecation")
    final String stringValue = value.getValueAsText();

    if (stringValue != null && !stringValue.trim().isEmpty()) {
      Object newValue;

      if (attribute.getEAttributeType().getInstanceClass().isEnum()) {
        newValue =
            EcoreUtil.createFromString(attribute.getEAttributeType(), stringValue.toUpperCase());
      } else {
        newValue = EcoreUtil.createFromString(attribute.getEAttributeType(), stringValue);
      }

      if (!attribute.isMany()) {
        obj.eSet(attribute, newValue);
      } else {
        @SuppressWarnings("unchecked")
        Collection<Object> values = (Collection<Object>) obj.eGet(attribute);
        values.add(newValue);
      }
    }
  }
 /**
  * {@inheritDoc}
  *
  * @see
  *     org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
  */
 public Diagnostic validateValue(IPropertiesEditionEvent event) {
   Diagnostic ret = Diagnostic.OK_INSTANCE;
   if (event.getNewValue() != null) {
     try {
       if (UmlViewsRepository.InputPin.Properties.name == event.getAffectedEditor()) {
         Object newValue = event.getNewValue();
         if (newValue instanceof String) {
           newValue =
               EcoreUtil.createFromString(
                   UMLPackage.eINSTANCE.getNamedElement_Name().getEAttributeType(),
                   (String) newValue);
         }
         ret =
             Diagnostician.INSTANCE.validate(
                 UMLPackage.eINSTANCE.getNamedElement_Name().getEAttributeType(), newValue);
       }
       if (UmlViewsRepository.InputPin.Properties.visibility == event.getAffectedEditor()) {
         Object newValue = event.getNewValue();
         if (newValue instanceof String) {
           newValue =
               EcoreUtil.createFromString(
                   UMLPackage.eINSTANCE.getNamedElement_Visibility().getEAttributeType(),
                   (String) newValue);
         }
         ret =
             Diagnostician.INSTANCE.validate(
                 UMLPackage.eINSTANCE.getNamedElement_Visibility().getEAttributeType(), newValue);
       }
       if (UmlViewsRepository.InputPin.Properties.isLeaf == event.getAffectedEditor()) {
         Object newValue = event.getNewValue();
         if (newValue instanceof String) {
           newValue =
               EcoreUtil.createFromString(
                   UMLPackage.eINSTANCE.getRedefinableElement_IsLeaf().getEAttributeType(),
                   (String) newValue);
         }
         ret =
             Diagnostician.INSTANCE.validate(
                 UMLPackage.eINSTANCE.getRedefinableElement_IsLeaf().getEAttributeType(),
                 newValue);
       }
       if (UmlViewsRepository.InputPin.Properties.ordering == event.getAffectedEditor()) {
         Object newValue = event.getNewValue();
         if (newValue instanceof String) {
           newValue =
               EcoreUtil.createFromString(
                   UMLPackage.eINSTANCE.getObjectNode_Ordering().getEAttributeType(),
                   (String) newValue);
         }
         ret =
             Diagnostician.INSTANCE.validate(
                 UMLPackage.eINSTANCE.getObjectNode_Ordering().getEAttributeType(), newValue);
       }
       if (UmlViewsRepository.InputPin.Properties.isControlType == event.getAffectedEditor()) {
         Object newValue = event.getNewValue();
         if (newValue instanceof String) {
           newValue =
               EcoreUtil.createFromString(
                   UMLPackage.eINSTANCE.getObjectNode_IsControlType().getEAttributeType(),
                   (String) newValue);
         }
         ret =
             Diagnostician.INSTANCE.validate(
                 UMLPackage.eINSTANCE.getObjectNode_IsControlType().getEAttributeType(), newValue);
       }
       if (UmlViewsRepository.InputPin.Properties.isOrdered == event.getAffectedEditor()) {
         Object newValue = event.getNewValue();
         if (newValue instanceof String) {
           newValue =
               EcoreUtil.createFromString(
                   UMLPackage.eINSTANCE.getMultiplicityElement_IsOrdered().getEAttributeType(),
                   (String) newValue);
         }
         ret =
             Diagnostician.INSTANCE.validate(
                 UMLPackage.eINSTANCE.getMultiplicityElement_IsOrdered().getEAttributeType(),
                 newValue);
       }
       if (UmlViewsRepository.InputPin.Properties.isUnique == event.getAffectedEditor()) {
         Object newValue = event.getNewValue();
         if (newValue instanceof String) {
           newValue =
               EcoreUtil.createFromString(
                   UMLPackage.eINSTANCE.getMultiplicityElement_IsUnique().getEAttributeType(),
                   (String) newValue);
         }
         ret =
             Diagnostician.INSTANCE.validate(
                 UMLPackage.eINSTANCE.getMultiplicityElement_IsUnique().getEAttributeType(),
                 newValue);
       }
       if (UmlViewsRepository.InputPin.Properties.isControl == event.getAffectedEditor()) {
         Object newValue = event.getNewValue();
         if (newValue instanceof String) {
           newValue =
               EcoreUtil.createFromString(
                   UMLPackage.eINSTANCE.getPin_IsControl().getEAttributeType(), (String) newValue);
         }
         ret =
             Diagnostician.INSTANCE.validate(
                 UMLPackage.eINSTANCE.getPin_IsControl().getEAttributeType(), newValue);
       }
     } catch (IllegalArgumentException iae) {
       ret = BasicDiagnostic.toDiagnostic(iae);
     } catch (WrappedException we) {
       ret = BasicDiagnostic.toDiagnostic(we);
     }
   }
   return ret;
 }
  public void resolve(
      String lexem,
      org.eclipse.emf.ecore.EStructuralFeature feature,
      org.emftext.term.propositional.expression.resource.expression.IExpressionTokenResolveResult
          result,
      String suffix,
      String prefix,
      String escapeCharacter) {
    // Step 1: unescape keywords if required
    if (escapeKeywords && lexem.startsWith("_")) {
      for (String keyword :
          org.emftext.term.propositional.expression.resource.expression.grammar
              .ExpressionGrammarInformationProvider.INSTANCE.getKeywords()) {
        if (lexem.endsWith(keyword)) {
          String keywordPrefix = lexem.substring(0, lexem.length() - keyword.length());
          if (keywordPrefix.matches("_+")) {
            lexem = lexem.substring(1);
            break;
          }
        }
      }
    }

    // Step 2: remove prefix, suffix and unescape escaped suffixes
    // Step 2a: remove prefix
    if (prefix != null) {
      int count = prefix.length();
      lexem = lexem.substring(count);
    }
    // Step 2b: remove suffix
    if (suffix != null) {
      int count = suffix.length();
      lexem = lexem.substring(0, lexem.length() - count);
      // take care of the escape character (may be null)
      // Step 2c: replaced escaped suffixes and escaped escape sequences
      if (escapeCharacter != null) {
        lexem = lexem.replace(escapeCharacter + suffix, suffix);
        lexem = lexem.replace(escapeCharacter + escapeCharacter, escapeCharacter);
      }
    }

    // Step 3: convert text to Java object
    if (feature instanceof org.eclipse.emf.ecore.EAttribute) {
      org.eclipse.emf.ecore.EClassifier featureType = feature.getEType();
      if (featureType instanceof org.eclipse.emf.ecore.EEnum) {
        org.eclipse.emf.ecore.EEnumLiteral literal =
            ((org.eclipse.emf.ecore.EEnum) featureType).getEEnumLiteralByLiteral(lexem);
        if (literal != null) {
          result.setResolvedToken(literal.getInstance());
          return;
        } else {
          result.setErrorMessage(
              "Could not map lexem '" + lexem + "' to enum '" + featureType.getName() + "'.");
          return;
        }
      } else if (featureType instanceof org.eclipse.emf.ecore.EDataType) {
        try {
          result.setResolvedToken(
              org.eclipse.emf.ecore.util.EcoreUtil.createFromString(
                  (org.eclipse.emf.ecore.EDataType) featureType, lexem));
        } catch (Exception e) {
          result.setErrorMessage(
              "Could not convert '" + lexem + "' to '" + featureType.getName() + "'.");
        }
        String typeName = featureType.getInstanceClassName();
        if (typeName.equals("boolean") || java.lang.Boolean.class.getName().equals(typeName)) {
          String featureName = feature.getName();
          boolean featureNameMatchesLexem = featureName.equals(lexem);
          if (featureNameMatchesLexem) {
            result.setResolvedToken(true);
            return;
          }
          if (featureName.length() > 2 && featureName.startsWith("is")) {
            if ((featureName.substring(2, 3).toLowerCase() + featureName.substring(3))
                .equals(lexem)) {
              result.setResolvedToken(true);
              return;
            }
          }
          if (Boolean.parseBoolean(lexem)) {
            result.setResolvedToken(true);
            return;
          }
        }
      } else {
        assert false;
      }
    } else {
      result.setResolvedToken(lexem);
      return;
    }
  }
Beispiel #9
0
 public Object toValue(String string) {
   return EcoreUtil.createFromString(eDataType, string);
 }
 /** @generated */
 public ICommand getParseCommand(IAdaptable adapter, String newString, int flags) {
   Object value = EcoreUtil.createFromString(editableFeatures[0].getEAttributeType(), newString);
   return getParseCommand(adapter, new Object[] {value}, flags);
 }