From f0a5f7b106f3e393bbebb8e988e0dc7850423089 Mon Sep 17 00:00:00 2001 From: Fanch BONNABESSE Date: Thu, 4 Aug 2016 14:24:14 +0200 Subject: Bug 497289: [Model Explorer] Renaming an element in the model explorer should not open a modal editor https://bugs.eclipse.org/bugs/show_bug.cgi?id=497289 Activation of the DirectEditor configuration on the ModelExplorer view for: - NamedElement - Diagram - Table Add a Preference on "Papyrus > Papyrus Model Explorer > New Child Menu" Change-Id: I760b84ee4b30f8f05ccb6c2f001a4e0f1e82d150 Signed-off-by: Fanch BONNABESSE --- .../.classpath | 2 +- .../.settings/org.eclipse.jdt.core.prefs | 6 +- .../META-INF/MANIFEST.MF | 6 +- .../plugin.xml | 254 +++++++++++---------- .../TableDirectEditorConfiguration.java | 44 ++++ .../directeditor/TableDirectEditorParser.java | 129 +++++++++++ .../modelexplorer/handlers/RenameTableHandler.java | 40 +++- 7 files changed, 348 insertions(+), 133 deletions(-) create mode 100644 plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/directeditor/TableDirectEditorConfiguration.java create mode 100644 plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/directeditor/TableDirectEditorParser.java (limited to 'plugins/infra/nattable') diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/.classpath b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/.classpath index ad32c83a788..eca7bdba8f0 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/.classpath +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/.classpath @@ -1,6 +1,6 @@ - + diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/.settings/org.eclipse.jdt.core.prefs b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/.settings/org.eclipse.jdt.core.prefs index 94d61f00da6..b3aa6d60f94 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/.settings/org.eclipse.jdt.core.prefs +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/.settings/org.eclipse.jdt.core.prefs @@ -1,10 +1,10 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/META-INF/MANIFEST.MF b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/META-INF/MANIFEST.MF index 8c6e273480e..44cb4466d48 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/META-INF/MANIFEST.MF +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/META-INF/MANIFEST.MF @@ -7,7 +7,7 @@ Export-Package: org.eclipse.papyrus.infra.nattable.modelexplorer, Bundle-ActivationPolicy: lazy Bundle-ClassPath: . Bundle-Name: %Bundle-Name -Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Require-Bundle: org.eclipse.papyrus.infra.nattable.model;bundle-version="[2.0.0,3.0.0)";visibility:=reexport, org.eclipse.papyrus.infra.emf.gmf;bundle-version="[1.2.0,2.0.0)", org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="[1.2.0,2.0.0)", @@ -15,7 +15,9 @@ Require-Bundle: org.eclipse.papyrus.infra.nattable.model;bundle-version="[2.0.0, org.eclipse.papyrus.emf.facet.custom.metamodel;bundle-version="[1.2.0,2.0.0)";visibility:=reexport, org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="[2.0.0,3.0.0)", org.eclipse.papyrus.infra.ui;bundle-version="[1.2.0,2.0.0)";visibility:=reexport, - org.eclipse.papyrus.infra.emf;bundle-version="[2.0.0,3.0.0)" + org.eclipse.papyrus.infra.emf;bundle-version="[2.0.0,3.0.0)", + org.eclipse.papyrus.extensionpoints.editors;bundle-version="[1.2.0,2.0.0)", + org.eclipse.papyrus.views.modelexplorer;bundle-version="[2.0.0,3.0.0)" Bundle-Vendor: %Bundle-Vendor Bundle-Version: 2.0.0.qualifier Bundle-Activator: org.eclipse.papyrus.infra.nattable.modelexplorer.Activator diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/plugin.xml b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/plugin.xml index 0746ee37722..647b0add2cf 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/plugin.xml +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/plugin.xml @@ -1,120 +1,134 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/directeditor/TableDirectEditorConfiguration.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/directeditor/TableDirectEditorConfiguration.java new file mode 100644 index 00000000000..8cd32ae3bd4 --- /dev/null +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/directeditor/TableDirectEditorConfiguration.java @@ -0,0 +1,44 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * 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: + * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.infra.nattable.modelexplorer.directeditor; + +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.papyrus.extensionpoints.editors.configuration.AbstractBasicDirectEditorConfiguration; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; + +/** + * Specific direct editor configuration to rename Table. + */ +public class TableDirectEditorConfiguration extends AbstractBasicDirectEditorConfiguration { + + /** + * {@inheritDoc} + */ + @Override + public String getTextToEdit(final Object objectToEdit) { + if (objectToEdit instanceof Table) { + return ((Table) objectToEdit).getName(); + } + + return super.getTextToEdit(objectToEdit); + } + + /** + * {@inheritDoc} + */ + @Override + public IParser createDirectEditorParser() { + return new TableDirectEditorParser(getTextToEdit(objectToEdit)); + } +} diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/directeditor/TableDirectEditorParser.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/directeditor/TableDirectEditorParser.java new file mode 100644 index 00000000000..74e2d73fcef --- /dev/null +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/directeditor/TableDirectEditorParser.java @@ -0,0 +1,129 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * 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: + * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.infra.nattable.modelexplorer.directeditor; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.emf.transaction.util.TransactionUtil; +import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; + +/** + * Specific Parser for the Table. + */ +public class TableDirectEditorParser implements IParser { + + /** + * Name of the current Table. + */ + private String textToEdit; + + /** + * Constructor. + * + */ + public TableDirectEditorParser(final String textToEdit) { + this.textToEdit = textToEdit; + } + + /** + * {@inheritDoc} + */ + @Override + public String getEditString(final IAdaptable element, final int flags) { + return this.textToEdit; + } + + /** + * {@inheritDoc} + */ + @Override + public ICommand getParseCommand(final IAdaptable element, final String newString, final int flags) { + CompositeCommand result = new CompositeCommand("Rename"); //$NON-NLS-1$ + + EObject eObjectElement = element.getAdapter(EObject.class); + + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(eObjectElement); + + AbstractTransactionalCommand cmd = new AbstractTransactionalCommand(editingDomain, "RenameCommand", null) { //$NON-NLS-1$ + + /** + * + * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) + * + * @param monitor + * @param info + * @return + * @throws ExecutionException + */ + @Override + protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { + if (eObjectElement instanceof Table) { + if (null != newString && !newString.isEmpty()) { + ((Table) eObjectElement).setName(newString); + return CommandResult.newOKCommandResult(); + } + } + + return CommandResult.newCancelledCommandResult(); + } + }; + + result.add(cmd); + return result; + } + + /** + * {@inheritDoc} + */ + @Override + public String getPrintString(final IAdaptable element, final int flags) { + return this.textToEdit; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isAffectingEvent(final Object event, final int flags) { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public IContentAssistProcessor getCompletionProcessor(final IAdaptable element) { + // Not used + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public IParserEditStatus isValidEditString(final IAdaptable element, final String editString) { + // Not used + return null; + } +} diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/handlers/RenameTableHandler.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/handlers/RenameTableHandler.java index 79f69725e2d..a1623c64850 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/handlers/RenameTableHandler.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/handlers/RenameTableHandler.java @@ -8,6 +8,8 @@ * * Contributors: * Juan Cadavid (CEA LIST) juan.cadavid@cea.fr - Initial API and implementation + * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Bug 497289 + * *****************************************************************************/ package org.eclipse.papyrus.infra.nattable.modelexplorer.handlers; @@ -18,29 +20,26 @@ import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.emf.common.command.Command; 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.CommandResult; import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.window.Window; import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; import org.eclipse.papyrus.infra.nattable.model.nattable.Table; import org.eclipse.papyrus.infra.nattable.modelexplorer.messages.Messages; +import org.eclipse.papyrus.views.modelexplorer.DirectEditorEditingSupport; import org.eclipse.swt.widgets.Display; /** * This handler provides the method to rename a Table - * - * - * */ public class RenameTableHandler extends AbstractTableCommandHandler { /** - * - * @see org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler#getCommand() - * - * @return + * {@inheritDoc} */ @Override protected Command getCommand(IEvaluationContext context) { @@ -73,4 +72,31 @@ public class RenameTableHandler extends AbstractTableCommandHandler { } return UnexecutableCommand.INSTANCE; } + + /** + * {@inheritDoc} + */ + @Override + protected boolean computeEnabled(final IEvaluationContext context) { + boolean computeEnabled = super.computeEnabled(context); + if (computeEnabled) { + List selectedElements = getSelectedElements(); + EObject selection = selectedElements.get(0); + computeEnabled = !EMFHelper.isReadOnly(selection) && !isHandledByDirectEditor(selection); + } + + return computeEnabled; + } + + /** + * Check whether the editing of an element is handled by a direct editor. In this case, we do + * not want to open the rename pop-up. + * + * @param element + * an element that should be edited. + * @return true, if handled by a direct editor + */ + protected boolean isHandledByDirectEditor(final EObject element) { + return null != DirectEditorEditingSupport.getConfiguration(element); + } } -- cgit v1.2.3