EMF


EDataType
StringからEDataTypeオブジェクトにする方法
 EObject target = ・・・・
 EClass eClass = ・・・ target の EClass もしくは target の super な EClass  
 EPackage epackage = eClass.getEPackage();
 EFactory efactory = epackage.getEFactoryInstance();
 for (EAttribute attribute : eClass.getEAllAttributes()) {
  if(attribute.getEType() instanceof EDataType){
   Object value = efactory.createFromString((EDataType) attribute.getEType(), "1");
   target.eSet(attribute , value);
  }
 }

カスタマイズ方法
EMFモデルをジェネレート後にファクトリを編集
例 org.eclipse.gmf.runtime.notation.impl.NotationFactoryImpl
/**
 * @generated NOT
 */
public List createRelativeBendpointListFromString(EDataType eDataType, String initialValue) {
 StringTokenizer st = new StringTokenizer(initialValue, "$"); //$NON-NLS-1$
 List newList = new ArrayList(st.countTokens());
 while (st.hasMoreTokens())
  newList.add(new RelativeBendpoint(st.nextToken().trim()));
 return newList;
}
/**
 * @generated NOT
 */
public String convertRelativeBendpointListToString(EDataType eDataType, Object instanceValue) {
 StringBuffer sb = new StringBuffer();
 for (Iterator i = ((List)instanceValue).iterator(); i.hasNext();) {
  RelativeBendpoint point = (RelativeBendpoint) i.next();
  if (sb.length() != 0) sb.append('$');
  sb.append(point.convertToString());
 }
 return sb.toString();
}


TransactionalEditingDomain

runExclusive

排他実行
最終更新:2009年03月26日 10:34
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。