| /***************************************************************************** |
| * Copyright (c) 2011 CEA LIST. |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * |
| * CEA LIST - Initial API and implementation |
| * |
| *****************************************************************************/ |
| package org.eclipse.papyrus.uml.diagram.common.parser; |
| |
| import java.util.ArrayList; |
| import java.util.Iterator; |
| import java.util.List; |
| |
| import org.eclipse.core.runtime.IAdaptable; |
| import org.eclipse.emf.common.notify.Notification; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.ecore.EStructuralFeature; |
| import org.eclipse.gmf.runtime.common.core.command.ICommand; |
| import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand; |
| import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; |
| import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus; |
| import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; |
| import org.eclipse.jface.text.contentassist.IContentAssistProcessor; |
| import org.eclipse.papyrus.infra.emf.utils.EMFHelper; |
| import org.eclipse.uml2.uml.InstanceValue; |
| import org.eclipse.uml2.uml.Slot; |
| import org.eclipse.uml2.uml.UMLPackage; |
| import org.eclipse.uml2.uml.ValueSpecification; |
| |
| /** |
| * Semantic Parser for {@link Slot} |
| */ |
| public class SlotLabelParser implements ISemanticParser { |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public String getEditString(IAdaptable element, int flags) { |
| return getPrintString(element, flags); |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public IParserEditStatus isValidEditString(IAdaptable element, String editString) { |
| return ParserEditStatus.UNEDITABLE_STATUS; |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public ICommand getParseCommand(IAdaptable element, String newString, int flags) { |
| return UnexecutableCommand.INSTANCE; |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public String getPrintString(IAdaptable element, int flags) { |
| String result = ""; |
| EObject eObject = EMFHelper.getEObject(element); |
| |
| if (eObject instanceof Slot) { |
| Slot slot = (Slot) eObject; |
| result = "<UNDEFINED>"; |
| |
| if (slot.getDefiningFeature() != null) { |
| |
| // Add defining feature |
| result = slot.getDefiningFeature().getName(); |
| |
| // Add values |
| if (!slot.getValues().isEmpty()) { |
| |
| String values = ""; |
| Iterator<ValueSpecification> iter = slot.getValues().iterator(); |
| while (iter.hasNext()) { |
| ValueSpecification currentSpecification = iter.next(); |
| |
| String currentValue = currentSpecification.stringValue(); |
| if ((currentSpecification instanceof InstanceValue) && ((InstanceValue) currentSpecification).getInstance() != null) { |
| currentValue = ((InstanceValue) currentSpecification).getInstance().getName(); |
| } |
| |
| values = values + currentValue; |
| if (iter.hasNext()) { |
| result = result + ", "; |
| } |
| } |
| |
| result = result + ": " + values; |
| } |
| } |
| } |
| |
| return result; |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public boolean isAffectingEvent(Object event, int flags) { |
| if (event instanceof Notification) { |
| Object feature = ((Notification) event).getFeature(); |
| if (feature instanceof EStructuralFeature) { |
| return UMLPackage.eINSTANCE.getSlot_DefiningFeature().equals(feature); |
| } |
| } |
| |
| return false; |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public IContentAssistProcessor getCompletionProcessor(IAdaptable element) { |
| return null; |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public List<EObject> getSemanticElementsBeingParsed(EObject element) { |
| List<EObject> semanticElementsBeingParsed = new ArrayList<EObject>(); |
| semanticElementsBeingParsed.add(element); |
| |
| return semanticElementsBeingParsed; |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public boolean areSemanticElementsAffected(EObject listener, Object notification) { |
| return true; |
| } |
| |
| } |