001: package newprocess.diagram.providers;
002:
003: import java.text.FieldPosition;
004: import java.text.MessageFormat;
005: import java.util.Collections;
006:
007: import org.eclipse.core.runtime.IAdaptable;
008: import org.eclipse.emf.common.notify.Notification;
009: import org.eclipse.emf.ecore.EObject;
010: import org.eclipse.emf.ecore.EStructuralFeature;
011: import org.eclipse.emf.transaction.TransactionalEditingDomain;
012: import org.eclipse.emf.transaction.util.TransactionUtil;
013: import org.eclipse.gmf.runtime.common.core.command.ICommand;
014: import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
015: import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
016: import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
017: import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
018: import newprocess.diagram.part.New_processDiagramEditorPlugin;
019:
020: /**
021: * @generated
022: */
023: public class New_processStructuralFeatureParser extends
024: New_processAbstractParser {
025:
026: /**
027: * @generated
028: */
029: public static final MessageFormat DEFAULT_PROCESSOR = new MessageFormat(
030: "{0}"); //$NON-NLS-1$
031:
032: /**
033: * @generated
034: */
035: private EStructuralFeature feature;
036:
037: /**
038: * @generated
039: */
040: public New_processStructuralFeatureParser(EStructuralFeature feature) {
041: this .feature = feature;
042: }
043:
044: /**
045: * @generated
046: */
047: protected MessageFormat getViewProcessor() {
048: MessageFormat processor = super .getViewProcessor();
049: return processor == null ? DEFAULT_PROCESSOR : processor;
050: }
051:
052: /**
053: * @generated
054: */
055: protected MessageFormat getEditProcessor() {
056: MessageFormat processor = super .getEditProcessor();
057: return processor == null ? DEFAULT_PROCESSOR : processor;
058: }
059:
060: /**
061: * @generated
062: */
063: protected EObject getDomainElement(EObject element) {
064: return element;
065: }
066:
067: /**
068: * @generated
069: */
070: protected String getStringByPattern(IAdaptable adapter, int flags,
071: String pattern, MessageFormat processor) {
072: EObject element = (EObject) adapter.getAdapter(EObject.class);
073: element = getDomainElement(element);
074: return getStringByPattern(element, feature, processor);
075: }
076:
077: /**
078: * @generated
079: */
080: protected String getStringByPattern(EObject element,
081: EStructuralFeature feature, MessageFormat processor) {
082: Object value = element == null ? null : element.eGet(feature);
083: value = getValidValue(feature, value);
084: return processor.format(new Object[] { value },
085: new StringBuffer(), new FieldPosition(0)).toString();
086: }
087:
088: /**
089: * @generated
090: */
091: protected IParserEditStatus validateValues(Object[] values) {
092: if (values.length > 1) {
093: return ParserEditStatus.UNEDITABLE_STATUS;
094: }
095: Object value = values.length == 1 ? values[0] : null;
096: value = getValidNewValue(feature, value);
097: if (value instanceof InvalidValue) {
098: return new ParserEditStatus(
099: New_processDiagramEditorPlugin.ID,
100: IParserEditStatus.UNEDITABLE, value.toString());
101: }
102: return ParserEditStatus.EDITABLE_STATUS;
103: }
104:
105: /**
106: * @generated
107: */
108: public ICommand getParseCommand(IAdaptable adapter, Object[] values) {
109: EObject element = (EObject) adapter.getAdapter(EObject.class);
110: element = getDomainElement(element);
111: if (element == null) {
112: return UnexecutableCommand.INSTANCE;
113: }
114: TransactionalEditingDomain editingDomain = TransactionUtil
115: .getEditingDomain(element);
116: if (editingDomain == null) {
117: return UnexecutableCommand.INSTANCE;
118: }
119: Object value = values.length == 1 ? values[0] : null;
120: ICommand command = getModificationCommand(element, feature,
121: value);
122: return new CompositeTransactionalCommand(editingDomain, command
123: .getLabel(), Collections.singletonList(command));
124: }
125:
126: /**
127: * @generated
128: */
129: public boolean isAffectingEvent(Object event, int flags) {
130: if (event instanceof Notification) {
131: return isAffectingFeature(((Notification) event)
132: .getFeature());
133: }
134: return false;
135: }
136:
137: /**
138: * @generated
139: */
140: protected boolean isAffectingFeature(Object eventFeature) {
141: return feature == eventFeature;
142: }
143: }
|