diff options
author | Vincent Lorenzo | 2018-02-28 16:31:30 +0000 |
---|---|---|
committer | vincent lorenzo | 2018-03-06 13:06:10 +0000 |
commit | c128f0461acb94535ab7b375e9bf05603d0135a6 (patch) | |
tree | 18c434ebbbafc207c1ed4684e4276224aad9eecf /plugins | |
parent | b62e4bff8ccd9a85aec3895fdcd63c0d6ea6ec9c (diff) | |
download | org.eclipse.papyrus-c128f0461acb94535ab7b375e9bf05603d0135a6.tar.gz org.eclipse.papyrus-c128f0461acb94535ab7b375e9bf05603d0135a6.tar.xz org.eclipse.papyrus-c128f0461acb94535ab7b375e9bf05603d0135a6.zip |
Bug 531802: [XText]The editor for CollaborationUse generate a NullPointerException
Change-Id: I7d39194ac5a93e6158f9c326733ef73df27f33f0
Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
Diffstat (limited to 'plugins')
4 files changed, 98 insertions, 165 deletions
diff --git a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui/META-INF/MANIFEST.MF b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui/META-INF/MANIFEST.MF index 4676217ec2a..c08dab05304 100644 --- a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui/META-INF/MANIFEST.MF +++ b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui/META-INF/MANIFEST.MF @@ -15,7 +15,7 @@ Require-Bundle: org.eclipse.papyrus.uml.textedit.collaborationuse.xtext;bundle-v org.eclipse.papyrus.uml.xtext.integration.ui;bundle-version="[2.0.0,3.0.0)", org.eclipse.papyrus.uml.internationalization.utils;bundle-version="[1.0.0,2.0.0)" Bundle-Vendor: %providerName -Bundle-Version: 2.0.0.qualifier +Bundle-Version: 2.0.100.qualifier Bundle-ManifestVersion: 2 Bundle-Activator: org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui.internal.UmlCollaborationUseActivator Import-Package: org.apache.log4j;version="[1.2.0,2.0.0)" diff --git a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui/pom.xml b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui/pom.xml index 92556205ad4..a43c1de9a8b 100644 --- a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui/pom.xml +++ b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui/pom.xml @@ -7,6 +7,6 @@ <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui</artifactId> - <version>2.0.0-SNAPSHOT</version> + <version>2.0.100-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project>
\ No newline at end of file diff --git a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui/src/org/eclipse/papyrus/uml/textedit/collaborationuse/xtext/ui/contributions/CollaborationUseEditor.java b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui/src/org/eclipse/papyrus/uml/textedit/collaborationuse/xtext/ui/contributions/CollaborationUseEditor.java index 93a3f93991d..10304df1bca 100644 --- a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui/src/org/eclipse/papyrus/uml/textedit/collaborationuse/xtext/ui/contributions/CollaborationUseEditor.java +++ b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui/src/org/eclipse/papyrus/uml/textedit/collaborationuse/xtext/ui/contributions/CollaborationUseEditor.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2010 CEA LIST. + * Copyright (c) 2010, 2018 CEA LIST. * * * All rights reserved. This program and the accompanying materials @@ -10,13 +10,10 @@ * Contributors: * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 - * + * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Bug 531802 *****************************************************************************/ package org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui.contributions; -import java.util.ArrayList; -import java.util.List; - import org.eclipse.core.commands.operations.IUndoableOperation; import org.eclipse.emf.ecore.EObject; import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; @@ -27,10 +24,12 @@ import org.eclipse.papyrus.infra.emf.gmf.command.EMFtoGMFCommandWrapper; import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesUtils; import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; import org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui.internal.UmlCollaborationUseActivator; +import org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.umlCollaborationUse.CollaborationUseRule; import org.eclipse.papyrus.uml.xtext.integration.DefaultXtextDirectEditorConfiguration; import org.eclipse.uml2.uml.Collaboration; import org.eclipse.uml2.uml.CollaborationUse; import org.eclipse.uml2.uml.UMLPackage; +import org.eclipse.xtext.EcoreUtil2; import com.google.inject.Injector; @@ -41,153 +40,36 @@ import com.google.inject.Injector; */ public class CollaborationUseEditor extends DefaultXtextDirectEditorConfiguration { - /** the new name for the {@link CollaborationUse} */ - private String newName; - - /** the new type for the {@link CollaborationUse} */ - private Collaboration newType; - - /** the new visibility for the {@link CollaborationUse} */ - private org.eclipse.uml2.uml.VisibilityKind newVisibility; - - /** the managed {@link CollaborationUse} */ - private CollaborationUse collaborationUse; - - /** - * - * @see org.eclipse.papyrus.infra.gmfdiag.xtext.glue.PopupEditorConfiguration#createPopupEditorHelper(java.lang.Object) - * - * @param editPart - * @return - */ - /* - * public IPopupEditorHelper createPopupEditorHelper(Object editPart) { - * - * // resolves the edit part, and the associated semantic element - * IGraphicalEditPart graphicalEditPart = null; - * if(!(editPart instanceof IGraphicalEditPart)) { - * return null; - * } - * graphicalEditPart = (IGraphicalEditPart)editPart; - * - * if(!(graphicalEditPart.resolveSemanticElement() instanceof CollaborationUse)) { - * return null; - * } - * collaborationUse = (CollaborationUse)graphicalEditPart.resolveSemanticElement(); - * - * // retrieves the XText injector - * Injector injector = UmlCollaborationUseActivator.getInstance().getInjector("org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.UmlCollaborationUse"); //$NON-NLS-1$ - * - * // builds the text content and extension for a temporary file, to be edited by the xtext editor - * String textToEdit = "" + this.getTextToEdit(graphicalEditPart.resolveSemanticElement()); //$NON-NLS-1$ - * String fileExtension = "" + ".umlcollaborationuse"; //$NON-NLS-1$ //$NON-NLS-2$ - * - * // builds a new IXtextEMFReconciler. - * // Its purpose is to extract any relevant information from the textual specification, - * // and then merge it in the context UML model if necessary - * IXtextEMFReconciler reconciler = new IXtextEMFReconciler() { - * - * public void reconcile(EObject modelObject, EObject xtextObject) { - * // first: retrieves / determines if the xtextObject is a CollaborationUseRule object - * EObject modifiedObject = xtextObject; - * if(!(modelObject instanceof CollaborationUse)) { - * return; - * } - * while(xtextObject != null && !(xtextObject instanceof CollaborationUseRule)) { - * modifiedObject = modifiedObject.eContainer(); - * } - * if(modifiedObject == null) { - * return; - * } - * CollaborationUseRule propertyRuleObject = (CollaborationUseRule)xtextObject; - * - * // Retrieves the information to be populated in modelObject - * - * - * newName = "" + propertyRuleObject.getName(); //$NON-NLS-1$ - * - * TypeRule typeRule = propertyRuleObject.getType(); - * if(typeRule == null) { - * newType = null; - * } else { - * newType = (Collaboration)typeRule.getType(); - * } - * - * newVisibility = org.eclipse.uml2.uml.VisibilityKind.PUBLIC_LITERAL; - * - * switch(propertyRuleObject.getVisibility()) { - * case PUBLIC: - * newVisibility = org.eclipse.uml2.uml.VisibilityKind.PUBLIC_LITERAL; - * break; - * case PACKAGE: - * newVisibility = org.eclipse.uml2.uml.VisibilityKind.PACKAGE_LITERAL; - * break; - * case PRIVATE: - * newVisibility = org.eclipse.uml2.uml.VisibilityKind.PRIVATE_LITERAL; - * break; - * case PROTECTED: - * newVisibility = org.eclipse.uml2.uml.VisibilityKind.PROTECTED_LITERAL; - * break; - * default: - * break; - * } - * - * IUndoableOperation updateCommand = getUpdateCommand(); - * - * try { - * CheckedOperationHistory.getInstance().execute(updateCommand, new NullProgressMonitor(), null); - * } catch (ExecutionException e) { - * System.err.println(e); - * } - * } - * }; - * return super.createPopupEditorHelper(graphicalEditPart, injector, reconciler, textToEdit, fileExtension, new SemanticValidator()); - * } - */ - - /** - * Returns the list of requests to update the {@link #collaborationUse} - * - * @return - * the list of requests to update the {@link #collaborationUse} - */ - protected List<SetRequest> getRequests() { - List<SetRequest> requests = new ArrayList<SetRequest>(); - requests.add(new SetRequest(collaborationUse, UMLPackage.eINSTANCE.getNamedElement_Visibility(), newVisibility)); - requests.add(new SetRequest(collaborationUse, UMLPackage.eINSTANCE.getCollaborationUse_Type(), newType)); - return requests; - } /** * Returns the update command * * @return - * the update command + * the update command */ - protected IUndoableOperation getUpdateCommand() { + private final IUndoableOperation getUpdateCommand(final CollaborationUse collaborationUse, final org.eclipse.uml2.uml.VisibilityKind newVisibility, final Collaboration newType, final String newName) { CompositeCommand cc = new CompositeCommand("Set values for CollaborationUse"); //$NON-NLS-1$ org.eclipse.papyrus.infra.services.edit.service.IElementEditService provider = org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils.getCommandProvider(collaborationUse); if (provider != null) { // Manage the name or the label set ICommand setNameCommand = null; - if(InternationalizationPreferencesUtils.getInternationalizationPreference(collaborationUse) && null != UMLLabelInternationalization.getInstance().getLabelWithoutUML(collaborationUse)){ - final ModelSet modelSet = (ModelSet)collaborationUse.eResource().getResourceSet(); + if (InternationalizationPreferencesUtils.getInternationalizationPreference(collaborationUse) && null != UMLLabelInternationalization.getInstance().getLabelWithoutUML(collaborationUse)) { + final ModelSet modelSet = (ModelSet) collaborationUse.eResource().getResourceSet(); setNameCommand = new EMFtoGMFCommandWrapper(UMLLabelInternationalization.getInstance().getSetLabelCommand(modelSet.getTransactionalEditingDomain(), collaborationUse, newName, null)); - }else{ + } else { final SetRequest setNameRequest = new SetRequest(collaborationUse, UMLPackage.eINSTANCE.getNamedElement_Name(), newName); setNameCommand = provider.getEditCommand(setNameRequest); } cc.add(setNameCommand); - - ICommand editCommand = null; - for (SetRequest current : getRequests()) { - editCommand = provider.getEditCommand(current); - if (editCommand != null && editCommand.canExecute()) { - cc.add(editCommand); - } + // set the visibility + if (false == collaborationUse.getVisibility().equals(newVisibility)) {// to avoid to have the green + displayed whereas the visibility didn't change + cc.add(provider.getEditCommand(new SetRequest(collaborationUse, UMLPackage.eINSTANCE.getNamedElement_Visibility(), newVisibility))); } + + // set type + cc.add(provider.getEditCommand(new SetRequest(collaborationUse, UMLPackage.eINSTANCE.getCollaborationUse_Type(), newType))); } return cc; } @@ -209,19 +91,69 @@ public class CollaborationUseEditor extends DefaultXtextDirectEditorConfiguratio return "not a CollaborationUse"; //$NON-NLS-1$ } + /** + * + * @see org.eclipse.papyrus.uml.xtext.integration.DefaultXtextDirectEditorConfiguration#getInjector() + * + * @return + */ @Override public Injector getInjector() { return UmlCollaborationUseActivator.getInstance().getInjector(UmlCollaborationUseActivator.ORG_ECLIPSE_PAPYRUS_UML_TEXTEDIT_COLLABORATIONUSE_XTEXT_UMLCOLLABORATIONUSE); } + /** + * + * @see org.eclipse.papyrus.uml.xtext.integration.DefaultXtextDirectEditorConfiguration#getParseCommand(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject) + * + * @param umlObject + * @param xtextObject + * @return + */ @Override - protected ICommand getParseCommand(EObject umlObject, EObject xtextObject) { - if (!(umlObject instanceof CollaborationUse)) { + protected ICommand getParseCommand(final EObject umlObject, EObject xtextObject) { + if (!(umlObject instanceof CollaborationUse) || null == xtextObject) { return null; } - // Creates and executes the update command - IUndoableOperation updateCommand = getUpdateCommand(); + // init the class fields, with the new values + final CollaborationUse collaborationUse = (CollaborationUse) umlObject; + xtextObject = EcoreUtil2.getContainerOfType(xtextObject, CollaborationUseRule.class); + if (null == xtextObject) { + return null; + } + CollaborationUseRule propertyRuleObject = (CollaborationUseRule) xtextObject; + final String newName = propertyRuleObject.getName(); + final Collaboration newType; + if (null != propertyRuleObject.getType()) { + newType = (Collaboration) propertyRuleObject.getType().getType(); + } else { + newType = null; + } + org.eclipse.uml2.uml.VisibilityKind newVisibility = org.eclipse.uml2.uml.VisibilityKind.PUBLIC_LITERAL; + + if (propertyRuleObject.getVisibility() != null) { + switch (propertyRuleObject.getVisibility()) { + case PUBLIC: + newVisibility = org.eclipse.uml2.uml.VisibilityKind.PUBLIC_LITERAL; + break; + case PACKAGE: + newVisibility = org.eclipse.uml2.uml.VisibilityKind.PACKAGE_LITERAL; + break; + case PRIVATE: + newVisibility = org.eclipse.uml2.uml.VisibilityKind.PRIVATE_LITERAL; + break; + case PROTECTED: + newVisibility = org.eclipse.uml2.uml.VisibilityKind.PROTECTED_LITERAL; + break; + default: + newVisibility = org.eclipse.uml2.uml.VisibilityKind.PUBLIC_LITERAL; + break; + } + } + // Creates the update command + IUndoableOperation updateCommand = getUpdateCommand(collaborationUse, newVisibility, newType, newName); + return (ICommand) updateCommand; } }
\ No newline at end of file diff --git a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui/src/org/eclipse/papyrus/uml/textedit/collaborationuse/xtext/ui/contributions/UMLCollaborationUseEditorUtil.java b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui/src/org/eclipse/papyrus/uml/textedit/collaborationuse/xtext/ui/contributions/UMLCollaborationUseEditorUtil.java index f15be258a73..d1cccc47477 100644 --- a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui/src/org/eclipse/papyrus/uml/textedit/collaborationuse/xtext/ui/contributions/UMLCollaborationUseEditorUtil.java +++ b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui/src/org/eclipse/papyrus/uml/textedit/collaborationuse/xtext/ui/contributions/UMLCollaborationUseEditorUtil.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2010 CEA LIST. + * Copyright (c) 2010, 2018 CEA LIST. * * * All rights reserved. This program and the accompanying materials @@ -10,14 +10,13 @@ * Contributors: * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 - * + * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Bug 531802 *****************************************************************************/ package org.eclipse.papyrus.uml.textedit.collaborationuse.xtext.ui.contributions; import java.util.ArrayList; import java.util.List; -import org.eclipse.emf.common.util.EList; import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization; import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil; import org.eclipse.papyrus.uml.tools.utils.TypeUtil; @@ -40,7 +39,7 @@ public class UMLCollaborationUseEditorUtil { * @param collaborationUse * the {@link CollaborationUse} * @return - * A String representing the {@link CollaborationUse} + * A String representing the {@link CollaborationUse} */ public static String getLabel(CollaborationUse collaborationUse) { StringBuffer buffer = new StringBuffer(); @@ -54,8 +53,9 @@ public class UMLCollaborationUseEditorUtil { // type if (collaborationUse.getType() != null) { - EList<Namespace> namespaces = collaborationUse.allNamespaces(); - buffer.append(" : " + getTypeLabel(collaborationUse.getType(), namespaces.get(namespaces.size() - 1))); //$NON-NLS-1$ + final List<Namespace> namespaces = collaborationUse.allNamespaces(); + final Namespace lastNamespace = (namespaces.size() - 1) >= 0 ? namespaces.get(namespaces.size() - 1) : null; + buffer.append(" : " + getTypeLabel(collaborationUse.getType(), lastNamespace)); //$NON-NLS-1$ } else { buffer.append(" : " + TypeUtil.UNDEFINED_TYPE_NAME); //$NON-NLS-1$ } @@ -68,7 +68,7 @@ public class UMLCollaborationUseEditorUtil { * @param collaborationUse * the {@link CollaborationUse} * @return - * The name of the {@link CollaborationUse} + * The name of the {@link CollaborationUse} */ public static String getName(CollaborationUse collaborationUse) { if (collaborationUse.getName() != null) { @@ -84,35 +84,36 @@ public class UMLCollaborationUseEditorUtil { * @param type * the type of the CollaborationUse * @return - * A string representing the Type of the {@link CollaborationUse} + * A string representing the Type of the {@link CollaborationUse} */ public static String getTypeLabel(Type type, Namespace model) { String label = ""; //$NON-NLS-1$ - List<Package> importedPackages = new ArrayList<Package>(model.getImportedPackages()); + if (null != model) { + List<Package> importedPackages = new ArrayList<Package>(model.getImportedPackages()); - List<Package> visitedPackages = new ArrayList<Package>(); - Package currentPackage = type.getNearestPackage(); + List<Package> visitedPackages = new ArrayList<Package>(); + Package currentPackage = type.getNearestPackage(); - boolean rootFound = false; + boolean rootFound = false; - while (currentPackage != null && !rootFound) { - visitedPackages.add(currentPackage); - if (importedPackages.contains(currentPackage) || currentPackage == model) { - rootFound = true; - } - Element owner = currentPackage.getOwner(); - while (owner != null && !(owner instanceof Package)) { - owner = owner.getOwner(); - } + while (currentPackage != null && !rootFound) { + visitedPackages.add(currentPackage); + if (importedPackages.contains(currentPackage) || currentPackage == model) { + rootFound = true; + } + Element owner = currentPackage.getOwner(); + while (owner != null && !(owner instanceof Package)) { + owner = owner.getOwner(); + } - currentPackage = owner != null ? (Package) owner : null; - } + currentPackage = owner != null ? (Package) owner : null; + } - for (int i = visitedPackages.size() - 1; i >= 0; i--) { - label += visitedPackages.get(i).getName() + "::"; //$NON-NLS-1$ + for (int i = visitedPackages.size() - 1; i >= 0; i--) { + label += visitedPackages.get(i).getName() + "::"; //$NON-NLS-1$ + } } - return label + type.getName(); } } |