diff options
author | Nicolas FAUVERGUE | 2019-08-28 14:42:21 +0000 |
---|---|---|
committer | Patrick Tessier | 2019-09-17 09:58:49 +0000 |
commit | d72fb6cccf471b28e310279f03f26bd19774197e (patch) | |
tree | 77039c35d3cfb1bb3bc156341e1b2548a6e79663 /plugins | |
parent | 77bc626b92bce788ca117d1d556b72554b52c1d1 (diff) | |
download | org.eclipse.papyrus-d72fb6cccf471b28e310279f03f26bd19774197e.tar.gz org.eclipse.papyrus-d72fb6cccf471b28e310279f03f26bd19774197e.tar.xz org.eclipse.papyrus-d72fb6cccf471b28e310279f03f26bd19774197e.zip |
Bug 550535: [AF] When switch viewpoints, the editors not managed by
current viewpoints must be closed
Add a command to manage the close of needed editors when switch
viewpoints.
Change-Id: I1562d03bc0400a835e5d8d4495d658e8ec78d611
Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
Diffstat (limited to 'plugins')
4 files changed, 208 insertions, 23 deletions
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/META-INF/MANIFEST.MF b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/META-INF/MANIFEST.MF index 51df8401427..7b6a0fd097f 100644 --- a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/META-INF/MANIFEST.MF +++ b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/META-INF/MANIFEST.MF @@ -2,13 +2,14 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.papyrus.infra.ui.architecture;singleton:=true -Bundle-Version: 2.0.0.qualifier +Bundle-Version: 2.1.0.qualifier Bundle-ClassPath: . Bundle-Activator: org.eclipse.papyrus.infra.ui.architecture.ArchitectureUIPlugin$Implementation Bundle-Vendor: %providerName Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: org.eclipse.papyrus.infra.ui.architecture, + org.eclipse.papyrus.infra.ui.architecture.commands, org.eclipse.papyrus.infra.ui.architecture.widgets Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.0.0,4.0.0)", org.eclipse.core.resources;bundle-version="[3.0.0,4.0.0)", @@ -26,6 +27,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.0.0,4.0.0)", org.eclipse.papyrus.infra.nattable.common;bundle-version="[5.0.0,6.0.0)", org.eclipse.jdt.core;bundle-version="[3.0.0,4.0.0)", org.eclipse.jdt.ui;bundle-version="[3.0.0,4.0.0)", - org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="[3.0.0,4.0.0)" + org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="[3.0.0,4.0.0)", + org.eclipse.papyrus.infra.gmfdiag.representation;bundle-version="[2.0.0,3.0.0)", + org.eclipse.papyrus.infra.nattable.representation;bundle-version="[2.0.0,3.0.0)" Bundle-ActivationPolicy: lazy Automatic-Module-Name: org.eclipse.papyrus.infra.ui.architecture diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/pom.xml b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/pom.xml index 41a3a0ce2ea..34d1d232ccd 100644 --- a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/pom.xml +++ b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/pom.xml @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -8,6 +9,6 @@ <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>org.eclipse.papyrus.infra.ui.architecture</artifactId> - <version>2.0.0-SNAPSHOT</version> + <version>2.1.0-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/commands/CloseEditorsForViewpointsCommand.java b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/commands/CloseEditorsForViewpointsCommand.java new file mode 100644 index 00000000000..c0f32244468 --- /dev/null +++ b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/commands/CloseEditorsForViewpointsCommand.java @@ -0,0 +1,168 @@ +/***************************************************************************** + * Copyright (c) 2019 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.infra.ui.architecture.commands; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.emf.common.command.AbstractCommand; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.papyrus.infra.architecture.representation.PapyrusRepresentationKind; +import org.eclipse.papyrus.infra.core.architecture.RepresentationKind; +import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureViewpoint; +import org.eclipse.papyrus.infra.core.sasheditor.editor.IMultiPageEditorPart; +import org.eclipse.papyrus.infra.core.sashwindows.di.service.IPageManager; +import org.eclipse.papyrus.infra.gmfdiag.representation.PapyrusDiagram; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; +import org.eclipse.papyrus.infra.nattable.representation.PapyrusTable; +import org.eclipse.papyrus.infra.ui.util.EditorHelper; +import org.eclipse.ui.IEditorPart; + +/** + * This allows to close editors depending to the current viewpoints. + * + * @since 2.1 + */ +public class CloseEditorsForViewpointsCommand extends AbstractCommand { + + /** + * Store the allowed editors identifiers to keep opened. + */ + private Set<String> allowedEditorIds; + + /** + * A set of editors to close. + */ + private Set<Object> pageIdentifiersToClose; + + /** + * Constructor. + * + * @param viewpoints + * The current viewpoints of the model. + */ + public CloseEditorsForViewpointsCommand(final Collection<MergedArchitectureViewpoint> viewpoints) { + // Calculate the allowed editors identifiers to keep opened + allowedEditorIds = new HashSet<>(); + for (final MergedArchitectureViewpoint viewpoint : viewpoints) { + for (final RepresentationKind representationKind : viewpoint.getRepresentationKinds()) { + if (representationKind instanceof PapyrusRepresentationKind) { + if (representationKind instanceof PapyrusDiagram) { + allowedEditorIds.add(((PapyrusRepresentationKind) representationKind).getImplementationID()); + } else if (representationKind instanceof PapyrusTable) { + allowedEditorIds.add(((PapyrusRepresentationKind) representationKind).getId()); + } + } + } + } + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.common.command.AbstractCommand#canExecute() + */ + @Override + public boolean canExecute() { + final IEditorPart activeEditor = EditorHelper.getCurrentEditor(); + return activeEditor instanceof IMultiPageEditorPart; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.common.command.Command#execute() + */ + @Override + public void execute() { + // Get the current editor. It should be a multi page sash editor from Papyrus + final IEditorPart activeEditor = EditorHelper.getCurrentEditor(); + if (activeEditor instanceof IMultiPageEditorPart) { + // Get the page manager + final IPageManager pageManager = ((IMultiPageEditorPart) activeEditor).getAdapter(IPageManager.class); + if (null != pageManager) { + + // Create a set of editors to close (to avoid concurrent modification) + pageIdentifiersToClose = new HashSet<>(); + for (Object object : pageManager.allPages()) { + // If this is a diagram not defined in allowed editors identifiers, mark it as closed + if (object instanceof Diagram && !allowedEditorIds.contains(((Diagram) object).getType())) { + pageIdentifiersToClose.add(object); + + // If this is a table not defined in allowed editors identifiers, mark it as closed + } else if (object instanceof Table && !allowedEditorIds.contains(((Table) object).getTableKindId())) { + pageIdentifiersToClose.add(object); + } + } + + // Close the needed editors + if (!pageIdentifiersToClose.isEmpty()) { + pageIdentifiersToClose.stream().forEach(pageIdentifier -> pageManager.closePage(pageIdentifier)); + } + } + } + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.common.command.AbstractCommand#canUndo() + */ + @Override + public boolean canUndo() { + return true; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.common.command.AbstractCommand#undo() + */ + @Override + public void undo() { + if (null != pageIdentifiersToClose && !pageIdentifiersToClose.isEmpty()) { + final IEditorPart activeEditor = EditorHelper.getCurrentEditor(); + if (activeEditor instanceof IMultiPageEditorPart) { + // Get the page manager + final IPageManager pageManager = ((IMultiPageEditorPart) activeEditor).getAdapter(IPageManager.class); + if (null != pageManager) { + pageIdentifiersToClose.stream().forEach(pageIdentifier -> pageManager.openPage(pageIdentifier)); + } + } + } + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.common.command.Command#redo() + */ + @Override + public void redo() { + if (null != pageIdentifiersToClose && !pageIdentifiersToClose.isEmpty()) { + final IEditorPart activeEditor = EditorHelper.getCurrentEditor(); + if (activeEditor instanceof IMultiPageEditorPart) { + // Get the page manager + final IPageManager pageManager = ((IMultiPageEditorPart) activeEditor).getAdapter(IPageManager.class); + if (null != pageManager) { + pageIdentifiersToClose.stream().forEach(pageIdentifier -> pageManager.closePage(pageIdentifier)); + } + } + } + } + +} diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/handlers/ChangeArchitectureViewpointsHandler.java b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/handlers/ChangeArchitectureViewpointsHandler.java index 21896ba4b23..9bf6d60a8f8 100644 --- a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/handlers/ChangeArchitectureViewpointsHandler.java +++ b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/handlers/ChangeArchitectureViewpointsHandler.java @@ -1,26 +1,28 @@ /** - * Copyright (c) 2017 CEA LIST. - * + * Copyright (c) 2017, 2019 CEA LIST. + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: - * Maged Elaasar - Initial API and implementation - * - * + * Maged Elaasar - Initial API and implementation + * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 550535 + * */ package org.eclipse.papyrus.infra.ui.architecture.handlers; import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; -import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.edit.provider.ComposedAdapterFactory; @@ -34,11 +36,12 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.papyrus.infra.architecture.ArchitectureDescriptionUtils; import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureContext; import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureViewpoint; -import org.eclipse.papyrus.infra.architecture.ArchitectureDescriptionUtils; import org.eclipse.papyrus.infra.core.resource.ModelSet; import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.infra.ui.architecture.commands.CloseEditorsForViewpointsCommand; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.CompoundContributionItem; @@ -52,25 +55,27 @@ public class ChangeArchitectureViewpointsHandler extends CompoundContributionIte // the label provider for architecture viewpoints private ILabelProvider provider; - + public ChangeArchitectureViewpointsHandler() { ComposedAdapterFactory composedAdapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE); provider = new AdapterFactoryLabelProvider(composedAdapterFactory); } - + @Override protected IContributionItem[] getContributionItems() { final EObject selection = getSelection(); - if (selection == null) + if (selection == null) { return new IContributionItem[0]; + } ResourceSet resourceSet = selection.eResource().getResourceSet(); - if (!(resourceSet instanceof ModelSet)) + if (!(resourceSet instanceof ModelSet)) { return new IContributionItem[0]; - final ArchitectureDescriptionUtils helper = new ArchitectureDescriptionUtils((ModelSet)resourceSet); + } + final ArchitectureDescriptionUtils helper = new ArchitectureDescriptionUtils((ModelSet) resourceSet); MergedArchitectureContext context = helper.getArchitectureContext(); - final Set<String> viewpointIds = new HashSet<String>(helper.getArchitectureViewpointIds()); + final Set<String> viewpointIds = new HashSet<>(helper.getArchitectureViewpointIds()); - List<IContributionItem> items = new ArrayList<IContributionItem>(); + List<IContributionItem> items = new ArrayList<>(); for (MergedArchitectureViewpoint viewpoint : context.getViewpoints()) { Object imageObject = viewpoint.getImageObject(); ImageDescriptor desc = ExtendedImageRegistry.getInstance().getImageDescriptor(provider.getImage(imageObject)); @@ -78,15 +83,23 @@ public class ChangeArchitectureViewpointsHandler extends CompoundContributionIte { setChecked(viewpointIds.contains(viewpoint.getId())); } + @Override public void run() { - if (!isChecked()) + final Collection<MergedArchitectureViewpoint> viewpoints = helper.getArchitectureViewpoints(); + CompoundCommand cc = new CompoundCommand(); + if (!isChecked()) { viewpointIds.remove(viewpoint.getId()); - else + viewpoints.remove(viewpoint); + } else { viewpointIds.add(viewpoint.getId()); + viewpoints.add(viewpoint); + } TransactionalEditingDomain ted = helper.getModelSet().getTransactionalEditingDomain(); - Command cmd = helper.switchArchitectureViewpointIds(viewpointIds.toArray(new String[0])); - ted.getCommandStack().execute(cmd); + cc.append(helper.switchArchitectureViewpointIds(viewpointIds.toArray(new String[0]))); + // More than set the architecture viewpoints used, close needed editors + cc.append(new CloseEditorsForViewpointsCommand(viewpoints.stream().filter(viewpoint -> viewpointIds.contains(viewpoint.getId())).collect(Collectors.toList()))); + ted.getCommandStack().execute(cc); } })); } |