From 5ec9346ef2dd07cb387865b6b71ab1ae10d14c6f Mon Sep 17 00:00:00 2001 From: Benoit Maggi Date: Mon, 12 May 2014 14:57:03 +0200 Subject: Bug 434514 - [Model Explorer] Cut action is enabled on read-only elements and root package. Add tests and patch for the 3 usecases : - disable cut on the root element - disable cut on a read only element - disable paste on a read only element Change-Id: If40d0b27055bed41633746dcbce808f156c33732 Signed-off-by: Benoit Maggi Signed-off-by: Christian W. Damus --- .../views/modelexplorer/handler/CopyHandler.java | 43 +++++++--- .../views/modelexplorer/handler/CutHandler.java | 95 ++-------------------- .../handler/DeleteCommandHandler.java | 83 ++++++++++--------- .../views/modelexplorer/handler/PasteHandler.java | 3 +- .../tests/paste/CopyPasteModelExplorerTest.java | 54 ++++++++++++ .../tests/paste/CutPasteModelExplorerTest.java | 69 +++++++++++++++- 6 files changed, 208 insertions(+), 139 deletions(-) diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CopyHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CopyHandler.java index 93240f017a7..beb38f27133 100644 --- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CopyHandler.java +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CopyHandler.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2011 CEA LIST. + * Copyright (c) 2011, 2014 CEA LIST and others. * * * All rights reserved. This program and the accompanying materials @@ -13,6 +13,7 @@ *****************************************************************************/ package org.eclipse.papyrus.views.modelexplorer.handler; +import java.util.Collection; import java.util.List; import org.eclipse.emf.common.command.Command; @@ -30,25 +31,40 @@ import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.PasteStrategyMana public class CopyHandler extends AbstractCommandHandler { /** - * - * @see org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler#getCommand() - * + * Check if the selection allow copy + * @param selectedElements * @return */ - @Override - protected Command getCommand() { - List selection = getSelectedElements(); - TransactionalEditingDomain editingDomain = getEditingDomain(); - PapyrusClipboard papyrusClipboard = PapyrusClipboard.getNewInstance(); - - DefaultCopyCommand defaultCopyCommand = new DefaultCopyCommand(editingDomain, papyrusClipboard, selection); // TODO : select copyStrategy + public static boolean isCopyEnabled(Collection selectedElements) { + return !selectedElements.isEmpty(); + } + /** + * Construct copy command from the selection + * @param editingDomain + * @param selectedElements + * @return + */ + public static Command buildCopyCommand(TransactionalEditingDomain editingDomain, Collection selectedElements) { + PapyrusClipboard papyrusClipboard = PapyrusClipboard.getNewInstance(); + DefaultCopyCommand defaultCopyCommand = new DefaultCopyCommand(editingDomain, papyrusClipboard, selectedElements); List allStrategies = PasteStrategyManager.getInstance().getAllStrategies(); for(IStrategy iStrategy : allStrategies) { IPasteStrategy iPasteStrategy = (IPasteStrategy)iStrategy; iPasteStrategy.prepare(papyrusClipboard); } - return defaultCopyCommand; + return defaultCopyCommand; + } + + /** + * + * @see org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler#getCommand() + * + * @return + */ + @Override + protected Command getCommand() { + return buildCopyCommand(getEditingDomain(),getSelectedElements()); } /* (non-Javadoc) @@ -56,9 +72,10 @@ public class CopyHandler extends AbstractCommandHandler { */ @Override protected boolean computeEnabled() { // copy is enable as long as there is an EObject to put in the Clipboard - return !getSelectedElements().isEmpty(); + return isCopyEnabled(getSelectedElements()); } + /* (non-Javadoc) * @see org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler#setEnabled(java.lang.Object) */ diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CutHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CutHandler.java index 09613a5afd4..4567e2afa28 100644 --- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CutHandler.java +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CutHandler.java @@ -13,25 +13,12 @@ *****************************************************************************/ package org.eclipse.papyrus.views.modelexplorer.handler; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.eclipse.emf.common.command.Command; import org.eclipse.emf.common.command.CompoundCommand; -import org.eclipse.emf.common.command.UnexecutableCommand; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; -import org.eclipse.gmf.runtime.common.core.command.ICommand; -import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard; -import org.eclipse.papyrus.infra.gmfdiag.common.commands.DefaultCopyCommand; -import org.eclipse.papyrus.infra.gmfdiag.common.strategy.IStrategy; -import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy; -import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.PasteStrategyManager; -import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; -import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; /** * Handler for the Cut Action in Model Explorer : it's a copy followed by a delete @@ -48,89 +35,23 @@ public class CutHandler extends AbstractCommandHandler { @Override protected Command getCommand() { CompoundCommand cutInModelExplorerCommand = new CompoundCommand("Cut in Model Explorer Command"); //$NON-NLS-1$ - DefaultCopyCommand copyCommand = buildCopyCommand(); + Command copyCommand = CopyHandler.buildCopyCommand(getEditingDomain(), getSelectedElements()); cutInModelExplorerCommand.append(copyCommand); - Command create = buildDeleteCommand(); - cutInModelExplorerCommand.append(create); + Command deleteCommand = DeleteCommandHandler.buildDeleteCommand(getSelectedElements()); + cutInModelExplorerCommand.append(deleteCommand); return cutInModelExplorerCommand; } - - /** - * Construct a copy command with the cut selection - * @return the copy command - */ - protected DefaultCopyCommand buildCopyCommand() { - List selection = getSelectedElements(); - TransactionalEditingDomain editingDomain = getEditingDomain(); - PapyrusClipboard papyrusClipboard = PapyrusClipboard.getNewInstance(); - DefaultCopyCommand defaultCopyCommand = new DefaultCopyCommand(editingDomain, papyrusClipboard, selection); - List allStrategies = PasteStrategyManager.getInstance().getAllStrategies(); - for(IStrategy iStrategy : allStrategies) { - IPasteStrategy iPasteStrategy = (IPasteStrategy)iStrategy; - iPasteStrategy.prepare(papyrusClipboard); - } - return defaultCopyCommand; - } - - /** - * Construct a delete command with the cut selection - * @return the delete command - */ - protected Command buildDeleteCommand() { - - ICommand gmfCommand = null; - - // Parameters store the Request parameters of the previous request - // if multiple elements are selected for deletion. - Map parameters = new HashMap(); - - for(EObject selectedEObject : getSelectedElements()) { - - if(selectedEObject == null) { - continue; - } - - IElementEditService provider = ElementEditServiceUtils.getCommandProvider(selectedEObject); - if(provider == null) { - continue; - } - - // Retrieve delete command from the Element Edit service - DestroyElementRequest request = new DestroyElementRequest(selectedEObject, false); - // Add parameters (contains the list of previously dependents to be deleted - // by previous commands. - request.getParameters().putAll(parameters); - - ICommand deleteCommand = provider.getEditCommand(request); - - // Add current EObject destroy command to the global command - gmfCommand = CompositeCommand.compose(gmfCommand, deleteCommand); - - // Store the new parameters for next delete command. - parameters.clear(); - parameters.putAll(request.getParameters()); - } - - if(gmfCommand == null) { - return UnexecutableCommand.INSTANCE; - } - - Command emfCommand = new org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper(gmfCommand.reduce()); - return emfCommand; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler#computeEnabled() + * {@inheritDoc} */ @Override - protected boolean computeEnabled() { // copy is enable as long as there is an EObject to put in the Clipboard - return !getSelectedElements().isEmpty(); + protected boolean computeEnabled() { + List selectedElements = getSelectedElements(); + return CopyHandler.isCopyEnabled(selectedElements) && DeleteCommandHandler.isDeleteEnabled(selectedElements); } + /* * (non-Javadoc) * diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/DeleteCommandHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/DeleteCommandHandler.java index 3582d482420..12692ac5fa1 100644 --- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/DeleteCommandHandler.java +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/DeleteCommandHandler.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2010 CEA LIST. + * Copyright (c) 2010, 2014 CEA LIST and others. * * * All rights reserved. This program and the accompanying materials @@ -14,8 +14,8 @@ *****************************************************************************/ package org.eclipse.papyrus.views.modelexplorer.handler; +import java.util.Collection; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.eclipse.core.commands.IHandler; @@ -25,6 +25,7 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; import org.eclipse.gmf.runtime.common.core.command.ICommand; import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; +import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper; import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager; import org.eclipse.papyrus.infra.core.services.ServiceException; import org.eclipse.papyrus.infra.emf.utils.EMFHelper; @@ -38,20 +39,55 @@ import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; */ public class DeleteCommandHandler extends AbstractCommandHandler implements IHandler { + + /** + * Check if the selection allow delete + * @param selectedElements + * @return + */ + public static boolean isDeleteEnabled(Collection selectedElements) { + if(selectedElements.size() == 0) { + return false; + } + + for(EObject current : selectedElements) { + if(EMFHelper.isReadOnly(current)) { + return false; + } + //the root of the model can't be deleted! + if(current.eContainer() == null) { + try { + //Pages can be deleted even when they are root elements + IPageManager pageManager = ServiceUtilsForEObject.getInstance().getIPageManager(current); + if(pageManager.allPages().contains(current)) { + return true; + } + } catch (ServiceException ex) { + //Cannot retrieve the ServicesRegistry: ignore + } + return false; + } + } + + // Don't compute the delete command to know if it is enabled, + // it can be WAY too slow... + return true; + } + /** *
 	 * 
 	 * Build the delete command for a set of EObject selected in the ModelExplorer.
 	 * The delete command is given by the {@link IElementEditService} of selected 
 	 * elements.
-	 * 
+	 * @param selectedElements elements to delete
 	 * @return the composite deletion command for current selection
 	 * 
 	 * @TODO : Manage possible Diagrams listed in the selection
 	 * 
 	 * 
*/ - private Command buildCommand() { + public static Command buildDeleteCommand(Collection selectedElements) { ICommand gmfCommand = null; @@ -59,7 +95,7 @@ public class DeleteCommandHandler extends AbstractCommandHandler implements IHan // if multiple elements are selected for deletion. Map parameters = new HashMap(); - for(EObject selectedEObject : getSelectedElements()) { + for(EObject selectedEObject : selectedElements) { if(selectedEObject == null) { continue; @@ -90,10 +126,10 @@ public class DeleteCommandHandler extends AbstractCommandHandler implements IHan return UnexecutableCommand.INSTANCE; } - Command emfCommand = new org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper(gmfCommand.reduce()); - return emfCommand; + return GMFtoEMFCommandWrapper.wrap(gmfCommand.reduce()); } - + + /** * * @see org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler#getCommand() @@ -103,7 +139,7 @@ public class DeleteCommandHandler extends AbstractCommandHandler implements IHan @Override protected Command getCommand() { // Don't cache the command, as it is no more refreshed by isEnabled(). - return buildCommand(); + return buildDeleteCommand( getSelectedElements()); } /** @@ -111,34 +147,7 @@ public class DeleteCommandHandler extends AbstractCommandHandler implements IHan */ @Override protected boolean computeEnabled() { - //we need to test if selected element is not a meta-class - - List selectedElements = getSelectedElements(); - for(EObject current : selectedElements) { - if(EMFHelper.isReadOnly(current)) { - return false; - } - //the root of the model can't be deleted! - if(current.eContainer() == null) { - try { - //Pages can be deleted even when they are root elements - IPageManager pageManager = ServiceUtilsForEObject.getInstance().getIPageManager(current); - if(pageManager.allPages().contains(current)) { - return true; - } - } catch (ServiceException ex) { - //Cannot retrieve the ServicesRegistry: ignore - } - return false; - } - } - - if(selectedElements.size() == 0) { - return false; - } - // Don't compute the delete command to know if it is enabled, - // it can be WAY too slow... - return true; + return isDeleteEnabled(getSelectedElements()); } } diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/PasteHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/PasteHandler.java index 60ec26aeb3d..17f8ff5d0a8 100644 --- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/PasteHandler.java +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/PasteHandler.java @@ -20,6 +20,7 @@ import org.eclipse.emf.common.command.CompoundCommand; import org.eclipse.emf.common.command.UnexecutableCommand; import org.eclipse.emf.ecore.EObject; import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; import org.eclipse.papyrus.infra.gmfdiag.common.strategy.IStrategy; import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy; import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.PasteStrategyManager; @@ -61,7 +62,7 @@ public class PasteHandler extends AbstractCommandHandler { @Override protected boolean computeEnabled() { // paste is only available on a simple selection and wit ha full Clipboard if (!PapyrusClipboard.getInstance().isEmpty() && getSelectedElements().size() == 1){ - return true; + return !EMFHelper.isReadOnly(getSelectedElements().get(0)); } else { return super.computeEnabled(); } diff --git a/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CopyPasteModelExplorerTest.java b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CopyPasteModelExplorerTest.java index 81ba9972c5c..be12a0d7766 100644 --- a/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CopyPasteModelExplorerTest.java +++ b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CopyPasteModelExplorerTest.java @@ -18,6 +18,7 @@ import java.util.List; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.IHandler; +import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.papyrus.junit.utils.HandlerUtils; @@ -28,6 +29,7 @@ import org.eclipse.ui.ISelectionService; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.uml2.uml.Model; +import org.eclipse.uml2.uml.Package; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -67,7 +69,9 @@ public class CopyPasteModelExplorerTest extends AbstractEditorTest { return RESOURCES_PATH; } + + /** * Simple copy paste of a class1 * @@ -115,7 +119,57 @@ public class CopyPasteModelExplorerTest extends AbstractEditorTest { Assert.assertNotNull("The copy is missing", copyOfClass1); //$NON-NLS-1$ } + /** + * A user can not paste on a read only element (Bug 434514) + */ + @Test + public void pasteOnReadOnlyElement() throws Exception { + + Package rootUMLModel = getRootUMLModel(); + + Assert.assertNotNull("RootModel is null", rootUMLModel); //$NON-NLS-1$ + IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + ISelectionService selectionService = activeWorkbenchWindow.getSelectionService(); + + modelExplorerView = getModelExplorerView(); + modelExplorerView.setFocus(); + + List elements = new ArrayList(); + elements.add(rootUMLModel); + modelExplorerView.revealSemanticElement(elements); + + //getItem for model + EObject modelTreeObject = (EObject)((IStructuredSelection)selectionService.getSelection()).getFirstElement(); + Assert.assertNotNull("Model TreeElement is null", modelTreeObject); //$NON-NLS-1$ + // copy class1 + org.eclipse.uml2.uml.Class class1 = (org.eclipse.uml2.uml.Class)rootUMLModel.getPackagedElement(CLASS1_NAME); + elements.clear(); + elements.add(class1); + modelExplorerView.revealSemanticElement(elements); + EObject class1TreeObject = (EObject)((IStructuredSelection)selectionService.getSelection()).getFirstElement(); + Assert.assertNotNull("Class1 TreeElement is null", class1TreeObject); //$NON-NLS-1$ + + IHandler copyHandler = HandlerUtils.getActiveHandlerFor(COPY_COMMAND_ID); + Assert.assertTrue("Copy not available", copyHandler.isEnabled()); //$NON-NLS-1$ + copyHandler.execute(new ExecutionEvent()); + + //get read only item + EList importedPackages = rootUMLModel.getImportedPackages(); + Package primitiveTypes = importedPackages.get(0); + + elements.clear(); + elements.add(primitiveTypes); + modelExplorerView.revealSemanticElement(elements); + EObject treeObject = (EObject)((IStructuredSelection)selectionService.getSelection()).getFirstElement(); + Assert.assertNotNull("PrimitiveTypes TreeElement is null", treeObject); //$NON-NLS-1$ + + IHandler pasteHandler = HandlerUtils.getActiveHandlerFor(PASTE_COMMAND_ID); + Assert.assertFalse("Paste is available on a readonly element", pasteHandler.isEnabled()); //$NON-NLS-1$ + } + + + /** * Simple copy pasteof class1 & class2 test. */ diff --git a/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CutPasteModelExplorerTest.java b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CutPasteModelExplorerTest.java index 7bda2615af3..6b46343c3c3 100644 --- a/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CutPasteModelExplorerTest.java +++ b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CutPasteModelExplorerTest.java @@ -14,9 +14,11 @@ package org.eclipse.papyrus.uml.modelexplorer.tests.paste; import java.util.ArrayList; +import java.util.List; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.IHandler; +import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.papyrus.junit.utils.HandlerUtils; @@ -27,6 +29,8 @@ import org.eclipse.ui.ISelectionService; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.uml2.uml.Model; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.PackageableElement; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -50,7 +54,8 @@ public class CutPasteModelExplorerTest extends AbstractEditorTest { public final static String CLASS1_NAME = "Class1"; //$NON-NLS-1$ - + public final static String PRIMITIVE_BOOLEAN_NAME = "Boolean"; //$NON-NLS-1$ + @Before public void initModelForCutTest() { try { @@ -65,7 +70,69 @@ public class CutPasteModelExplorerTest extends AbstractEditorTest { return RESOURCES_PATH; } + /** + * A user can not cut the root of a model (Bug 434514) + */ + @Test + public void cutRootOfTheModel() throws Exception { + + Assert.assertNotNull("RootModel is null", getRootUMLModel()); //$NON-NLS-1$ + IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + ISelectionService selectionService = activeWorkbenchWindow.getSelectionService(); + modelExplorerView = getModelExplorerView(); + modelExplorerView.setFocus(); + List elements = new ArrayList(); + elements.add(getRootUMLModel()); + modelExplorerView.revealSemanticElement(elements); + + //getItem for model + EObject modelTreeObject = (EObject)((IStructuredSelection)selectionService.getSelection()).getFirstElement(); + Assert.assertNotNull("Model TreeElement is null", modelTreeObject); //$NON-NLS-1$ + + IHandler cutHandler = HandlerUtils.getActiveHandlerFor(CUT_COMMAND_ID); //$NON-NLS-1$ + Assert.assertFalse("Cut is available", cutHandler.isEnabled()); //$NON-NLS-1$ + } + + /** + * A user can not cut a read only element (Bug 434514) + */ + @Test + public void cutReadOnlyElement() throws Exception { + + Package rootUMLModel = getRootUMLModel(); + + Assert.assertNotNull("RootModel is null", rootUMLModel); //$NON-NLS-1$ + IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + ISelectionService selectionService = activeWorkbenchWindow.getSelectionService(); + + modelExplorerView = getModelExplorerView(); + modelExplorerView.setFocus(); + + List elements = new ArrayList(); + elements.add(rootUMLModel); + modelExplorerView.revealSemanticElement(elements); + + //getItem for model + EObject modelTreeObject = (EObject)((IStructuredSelection)selectionService.getSelection()).getFirstElement(); + Assert.assertNotNull("Model TreeElement is null", modelTreeObject); //$NON-NLS-1$ + + //get read only item + EList importedPackages = rootUMLModel.getImportedPackages(); + Package primitiveTypes = importedPackages.get(0); + PackageableElement packagedElement = primitiveTypes.getPackagedElement(PRIMITIVE_BOOLEAN_NAME); + + elements.clear(); + elements.add(packagedElement); + modelExplorerView.revealSemanticElement(elements); + EObject treeObject = (EObject)((IStructuredSelection)selectionService.getSelection()).getFirstElement(); + Assert.assertNotNull("Boolean Primitive PrimitiveTypes TreeElement is null", treeObject); //$NON-NLS-1$ + + IHandler cutHandler = HandlerUtils.getActiveHandlerFor(CUT_COMMAND_ID); + Assert.assertFalse("Cut is available on a readonly element (Boolean Primitive)", cutHandler.isEnabled()); //$NON-NLS-1$ + } + + /** * here the purpose is to test the cut/paste of a class in modelexplorer. */ -- cgit v1.2.3