001: package newprocess.diagram.providers;
002:
003: import java.text.FieldPosition;
004: import java.text.MessageFormat;
005: import java.util.ArrayList;
006: import java.util.Iterator;
007: import java.util.List;
008:
009: import org.eclipse.core.runtime.IAdaptable;
010: import org.eclipse.emf.common.notify.Notification;
011: import org.eclipse.emf.ecore.EObject;
012: import org.eclipse.emf.ecore.EStructuralFeature;
013: import org.eclipse.emf.transaction.TransactionalEditingDomain;
014: import org.eclipse.emf.transaction.util.TransactionUtil;
015: import org.eclipse.gmf.runtime.common.core.command.ICommand;
016: import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
017: import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
018: import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
019: import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
020: import newprocess.diagram.part.New_processDiagramEditorPlugin;
021:
022: /**
023: * @generated
024: */
025: public class New_processStructuralFeaturesParser extends
026: New_processAbstractParser {
027:
028: /**
029: * @generated
030: */
031: private List features;
032:
033: /**
034: * @generated
035: */
036: public New_processStructuralFeaturesParser(List features) {
037: this .features = features;
038: }
039:
040: /**
041: * @generated
042: */
043: protected String getStringByPattern(IAdaptable adapter, int flags,
044: String pattern, MessageFormat processor) {
045: EObject element = (EObject) adapter.getAdapter(EObject.class);
046: List values = new ArrayList(features.size());
047: for (Iterator it = features.iterator(); it.hasNext();) {
048: EStructuralFeature feature = (EStructuralFeature) it.next();
049: Object value = element.eGet(feature);
050: value = getValidValue(feature, value);
051: values.add(value);
052: }
053: return processor.format(
054: values.toArray(new Object[values.size()]),
055: new StringBuffer(), new FieldPosition(0)).toString();
056: }
057:
058: /**
059: * @generated
060: */
061: protected IParserEditStatus validateValues(Object[] values) {
062: if (values.length != features.size()) {
063: return ParserEditStatus.UNEDITABLE_STATUS;
064: }
065: for (int i = 0; i < values.length; i++) {
066: Object value = getValidNewValue(
067: (EStructuralFeature) features.get(i), values[i]);
068: if (value instanceof InvalidValue) {
069: return new ParserEditStatus(
070: New_processDiagramEditorPlugin.ID,
071: IParserEditStatus.UNEDITABLE, value.toString());
072: }
073: }
074: return ParserEditStatus.EDITABLE_STATUS;
075: }
076:
077: /**
078: * @generated
079: */
080: public ICommand getParseCommand(IAdaptable adapter, Object[] values) {
081: EObject element = (EObject) adapter.getAdapter(EObject.class);
082: if (element == null) {
083: return UnexecutableCommand.INSTANCE;
084: }
085: TransactionalEditingDomain editingDomain = TransactionUtil
086: .getEditingDomain(element);
087: if (editingDomain == null) {
088: return UnexecutableCommand.INSTANCE;
089: }
090: CompositeTransactionalCommand command = new CompositeTransactionalCommand(
091: editingDomain, "Set Values"); //$NON-NLS-1$
092: for (int i = 0; i < values.length; i++) {
093: EStructuralFeature feature = (EStructuralFeature) features
094: .get(i);
095: command.compose(getModificationCommand(element, feature,
096: values[i]));
097: }
098: return command;
099: }
100:
101: /**
102: * @generated
103: */
104: public boolean isAffectingEvent(Object event, int flags) {
105: if (event instanceof Notification) {
106: Object feature = ((Notification) event).getFeature();
107: if (features.contains(feature)) {
108: return true;
109: }
110: }
111: return false;
112: }
113: }
|