diff options
author | Nicolas FAUVERGUE | 2019-09-03 08:24:59 +0000 |
---|---|---|
committer | Patrick Tessier | 2019-09-18 13:50:43 +0000 |
commit | a39eec0a3c86af8d5fc476dd42c027b35104cb72 (patch) | |
tree | 9bff03b6d9ebce8313f7d6fc0121f6ccf4b54bd2 /plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org | |
parent | 37eba0da47d6b9a26299f133d69e93223a20dcb6 (diff) | |
download | org.eclipse.papyrus-a39eec0a3c86af8d5fc476dd42c027b35104cb72.tar.gz org.eclipse.papyrus-a39eec0a3c86af8d5fc476dd42c027b35104cb72.tar.xz org.eclipse.papyrus-a39eec0a3c86af8d5fc476dd42c027b35104cb72.zip |
Bug 550569: [AF] Double-click on diagrams and tables icons of disabled
viewpoint should open a dialog to enable viewpoint
- When a diagram/table is needed to be open but his viewpoint is not
enable, a dialog is opened to select the viewpoint
Change-Id: I052209b91b0e85742af60177e6c733c96c8730c9
Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
Diffstat (limited to 'plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org')
6 files changed, 411 insertions, 125 deletions
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/dialogs/ArchitectureContextDialog.java b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/dialogs/ArchitectureContextDialog.java new file mode 100644 index 00000000000..403868fd29c --- /dev/null +++ b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/dialogs/ArchitectureContextDialog.java @@ -0,0 +1,211 @@ +/***************************************************************************** + * 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: + * Maged Elaasar - Initial API and implementation + * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 550569 + * + *****************************************************************************/ + +package org.eclipse.papyrus.infra.ui.architecture.dialogs; + +import java.util.Arrays; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.papyrus.infra.architecture.ArchitectureDomainManager; +import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureContext; +import org.eclipse.papyrus.infra.ui.architecture.ArchitectureUIPlugin; +import org.eclipse.papyrus.infra.ui.architecture.widgets.ArchitectureContextComposite; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; + +/** + * A dialog to allow choosing a new architecture context and viewpoints. + * + * @since 2.1 + */ +public class ArchitectureContextDialog extends Dialog { + + /** + * The dialog section name. + */ + private final static String DIALOG_SECTION = ArchitectureContextDialog.class.getName(); + + /** + * The initial context ids. + */ + private String[] originalContextIds; + + /** + * The selected context ids. + */ + private String[] selectedContextIds; + + /** + * The selected viewpoints ids. + */ + private String[] selectedViewpointIds; + + /** + * The shell title. + */ + private String shellTitle; + + /** + * The label displayed in the dialog. + */ + private String labelText; + + /** + * Constructor. + * + * @param parentShell + * The parent shell. + * @param shellTitle + * The shell title. + * @param labelText + * The label of text in the dialog. + */ + public ArchitectureContextDialog(final Shell parentShell, final String shellTitle, final String labelText) { + super(parentShell); + this.shellTitle = shellTitle; + this.labelText = labelText; + } + + /** + * Get the selected context ids. + * + * @return The selected context ids. + */ + public String[] getSelectedContextIds() { + return selectedContextIds; + } + + /** + * Get the selected viewpoints ids. + * + * @return The selected viewpoints ids. + */ + public String[] getSelectedViewpointIds() { + return selectedViewpointIds; + } + + /** + * Set the selected context ids. + * + * @param selectedContextIds + * The selected context ids. + */ + public void setSelectedContexts(final String[] selectedContextIds) { + this.selectedContextIds = selectedContextIds; + this.originalContextIds = selectedContextIds; + } + + /** + * Set the selected viewpoints ids. + * + * @param selectedContextIds + * The selected viewpoints ids. + */ + public void setSelectedViewpoints(final String[] selectedViewpointIds) { + this.selectedViewpointIds = selectedViewpointIds; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + @Override + protected Control createDialogArea(final Composite parent) { + final Composite container = (Composite) super.createDialogArea(parent); + + final Label label = new Label(container, SWT.NONE); + label.setText(labelText); + + final ArchitectureDomainManager manager = ArchitectureDomainManager.getInstance(); + + final ArchitectureContextComposite acc = new ArchitectureContextComposite(container, 1, 1, GridData.FILL_BOTH, 0, 0); + acc.setAllowSeveralContexts(false); + acc.setSelectedContexts(selectedContextIds); + acc.setSelectedViewpoints(selectedViewpointIds); + acc.setInput(manager.getVisibleArchitectureContexts().toArray(new MergedArchitectureContext[0])); + acc.setUpdater(new ArchitectureContextComposite.Updater() { + @Override + public void update() { + selectedContextIds = acc.getSelectedContexts(); + selectedViewpointIds = acc.getSelectedViewpoints(); + } + }); + + return container; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) + */ + @Override + protected void configureShell(final Shell newShell) { + super.configureShell(newShell); + newShell.setText(shellTitle); + } + + /** + * [{@inheritDoc} + * + * @see org.eclipse.jface.dialogs.Dialog#isResizable() + */ + @Override + protected boolean isResizable() { + return true; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsSettings() + */ + @Override + protected IDialogSettings getDialogBoundsSettings() { + final IDialogSettings globalSettings = ArchitectureUIPlugin.getPlugin().getDialogSettings(); + IDialogSettings dialogSettings = globalSettings.getSection(DIALOG_SECTION); + if (dialogSettings == null) { + dialogSettings = globalSettings.addNewSection(DIALOG_SECTION); + } + return dialogSettings; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.dialogs.Dialog#okPressed() + */ + @Override + protected void okPressed() { + if (!Arrays.equals(getSelectedContextIds(), originalContextIds)) { + final MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_WARNING | SWT.YES | SWT.NO); + messageBox.setMessage("Changing the architecture context may cause significant changes to the model.\nDo you like to proceed?"); //$NON-NLS-1$ + messageBox.setText("Warning"); //$NON-NLS-1$ + final int response = messageBox.open(); + if (response != SWT.YES) { + return; + } + } + super.okPressed(); + } +}
\ No newline at end of file diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/handlers/ChangeArchitectureContextHandler.java b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/handlers/ChangeArchitectureContextHandler.java index 7a2a92dfdfc..7c10c739166 100644 --- a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/handlers/ChangeArchitectureContextHandler.java +++ b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/handlers/ChangeArchitectureContextHandler.java @@ -1,17 +1,17 @@ /** - * 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 550569 + * */ package org.eclipse.papyrus.infra.ui.architecture.handlers; @@ -25,64 +25,59 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.jface.action.IContributionItem; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureContext; import org.eclipse.papyrus.infra.architecture.ArchitectureDescriptionUtils; -import org.eclipse.papyrus.infra.architecture.ArchitectureDomainManager; import org.eclipse.papyrus.infra.core.resource.ModelSet; import org.eclipse.papyrus.infra.emf.utils.EMFHelper; -import org.eclipse.papyrus.infra.ui.architecture.ArchitectureUIPlugin; -import org.eclipse.papyrus.infra.ui.architecture.widgets.ArchitectureContextComposite; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; +import org.eclipse.papyrus.infra.ui.architecture.dialogs.ArchitectureContextDialog; +import org.eclipse.papyrus.infra.ui.architecture.messages.Messages; import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.handlers.HandlerUtil; /** * A command handler for changing architecture context in a model set - * + * * @since 1.0 */ public class ChangeArchitectureContextHandler extends AbstractHandler { - private final static String DIALOG_SECTION = ChangeArchitectureContextHandler.class.getName(); - /** * Constructor. */ public ChangeArchitectureContextHandler() { // nothing by default } - + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ @Override - public Object execute(ExecutionEvent event) throws ExecutionException { + public Object execute(final ExecutionEvent event) throws ExecutionException { EObject selection = getSelection(event); - 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); - String[] contextIds = new String[] {helper.getArchitectureContextId()}; + } + final ArchitectureDescriptionUtils helper = new ArchitectureDescriptionUtils((ModelSet) resourceSet); + String[] contextIds = new String[] { helper.getArchitectureContextId() }; String[] viewpointIds = helper.getArchitectureViewpointIds().toArray(new String[0]); - + final Shell shell = Display.getCurrent().getActiveShell(); - ArchitectureContextDialog dialog = new ArchitectureContextDialog(shell); + ArchitectureContextDialog dialog = new ArchitectureContextDialog(shell, Messages.ChangeArchitectureContextHandler_dialogTitle, Messages.ChangeArchitectureContextHandler_dialogLabel); dialog.setSelectedContexts(contextIds); dialog.setSelectedViewpoints(viewpointIds); dialog.create(); - + if (dialog.open() == Window.OK) { - TransactionalEditingDomain dom = helper.getModelSet().getTransactionalEditingDomain(); - CompoundCommand cmd = new CompoundCommand("Change Architecture Context"); + final TransactionalEditingDomain dom = helper.getModelSet().getTransactionalEditingDomain(); + final CompoundCommand cmd = new CompoundCommand("Change Architecture Context"); //$NON-NLS-1$ if (!Arrays.equals(dialog.getSelectedContextIds(), contextIds)) { cmd.append(helper.switchArchitectureContextId(dialog.getSelectedContextIds()[0])); } @@ -111,96 +106,4 @@ public class ChangeArchitectureContextHandler extends AbstractHandler { return null; } - /** - * A dialog to allow choosing a new architecture context and viewpoints - */ - private class ArchitectureContextDialog extends Dialog { - - private String[] originalContextIds; - - private String[] selectedContextIds; - - private String[] selectedViewpointIds; - - protected ArchitectureContextDialog(Shell parentShell) { - super(parentShell); - } - - public String[] getSelectedContextIds() { - return selectedContextIds; - } - - public String[] getSelectedViewpointIds() { - return selectedViewpointIds; - } - - public void setSelectedContexts(String[] selectedContextIds) { - this.selectedContextIds = selectedContextIds; - this.originalContextIds = selectedContextIds; - } - - public void setSelectedViewpoints(String[] selectedViewpointIds) { - this.selectedViewpointIds = selectedViewpointIds; - } - - @Override - protected Control createDialogArea(Composite parent) { - Composite container = (Composite) super.createDialogArea(parent); - - Label label = new Label(container, SWT.NONE); - label.setText("Switch the architecture context and/or viewpoints applied to the Papyrus model:"); - - ArchitectureDomainManager manager = ArchitectureDomainManager.getInstance(); - - ArchitectureContextComposite acc = new ArchitectureContextComposite(container, 1, 1, GridData.FILL_BOTH, 0, 0); - acc.setAllowSeveralContexts(false); - acc.setSelectedContexts(selectedContextIds); - acc.setSelectedViewpoints(selectedViewpointIds); - acc.setInput(manager.getVisibleArchitectureContexts().toArray(new MergedArchitectureContext[0])); - acc.setUpdater(new ArchitectureContextComposite.Updater() { - @Override - public void update() { - selectedContextIds = acc.getSelectedContexts(); - selectedViewpointIds = acc.getSelectedViewpoints(); - } - }); - - return container; - } - - @Override - protected void configureShell(Shell newShell) { - super.configureShell(newShell); - newShell.setText("Switch Architecture Context"); - } - - @Override - protected boolean isResizable() { - return true; - } - - @Override - protected IDialogSettings getDialogBoundsSettings() { - IDialogSettings globalSettings = ArchitectureUIPlugin.getPlugin().getDialogSettings(); - IDialogSettings dialogSettings = globalSettings.getSection(DIALOG_SECTION); - if (dialogSettings == null) { - dialogSettings = globalSettings.addNewSection(DIALOG_SECTION); - } - return dialogSettings; - } - - @Override - protected void okPressed() { - if (!Arrays.equals(getSelectedContextIds(), originalContextIds)) { - MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_WARNING | SWT.YES | SWT.NO); - messageBox.setMessage("Changing the architecture context may cause significant changes to the model.\nDo you like to proceed?"); - messageBox.setText("Warning"); - int response = messageBox.open(); - if (response != SWT.YES) - return; - } - super.okPressed(); - } - } - } 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 9bf6d60a8f8..34ef5dbb901 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 @@ -96,9 +96,10 @@ public class ChangeArchitectureViewpointsHandler extends CompoundContributionIte viewpoints.add(viewpoint); } TransactionalEditingDomain ted = helper.getModelSet().getTransactionalEditingDomain(); - cc.append(helper.switchArchitectureViewpointIds(viewpointIds.toArray(new String[0]))); // More than set the architecture viewpoints used, close needed editors + // It is needed to be the first action to avoid opened dialog for viewpoints selection cc.append(new CloseEditorsForViewpointsCommand(viewpoints.stream().filter(viewpoint -> viewpointIds.contains(viewpoint.getId())).collect(Collectors.toList()))); + cc.append(helper.switchArchitectureViewpointIds(viewpointIds.toArray(new String[0]))); ted.getCommandStack().execute(cc); } })); diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/messages/Messages.java b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/messages/Messages.java new file mode 100644 index 00000000000..527d82dce86 --- /dev/null +++ b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/messages/Messages.java @@ -0,0 +1,36 @@ +/***************************************************************************** + * 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.messages; + +import org.eclipse.osgi.util.NLS; + +/** + * Messages for architecture framework. + */ +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.ui.architecture.messages.messages"; //$NON-NLS-1$ + public static String ArchitecturePageAddValidator_diagleTitle; + public static String ArchitecturePageAddValidator_dialogLabel; + public static String ChangeArchitectureContextHandler_dialogLabel; + public static String ChangeArchitectureContextHandler_dialogTitle; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/messages/messages.properties b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/messages/messages.properties new file mode 100644 index 00000000000..2a11d2cbdc8 --- /dev/null +++ b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/messages/messages.properties @@ -0,0 +1,4 @@ +ArchitecturePageAddValidator_diagleTitle=Enable viewpoint for diagram(s)/table(s) +ArchitecturePageAddValidator_dialogLabel=The current diagram(s)/table(s) you want to open is not managed by the current viewpoint(s).\nSwitch the architecture context and/or viewpoints to get the one containing the diagram(s)/table(s) you want to open: +ChangeArchitectureContextHandler_dialogLabel=Switch the architecture context and/or viewpoints applied to the Papyrus model: +ChangeArchitectureContextHandler_dialogTitle=Switch Architecture Context diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/validators/ArchitecturePageAddValidator.java b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/validators/ArchitecturePageAddValidator.java new file mode 100644 index 00000000000..41bdd7b7668 --- /dev/null +++ b/plugins/infra/ui/org.eclipse.papyrus.infra.ui.architecture/src/org/eclipse/papyrus/infra/ui/architecture/validators/ArchitecturePageAddValidator.java @@ -0,0 +1,131 @@ +/***************************************************************************** + * 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.validators; + +import java.util.Arrays; + +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.infra.architecture.ArchitectureDescriptionUtils; +import org.eclipse.papyrus.infra.core.resource.ModelSet; +import org.eclipse.papyrus.infra.core.sasheditor.api.IPageAddValidator; +import org.eclipse.papyrus.infra.core.sashwindows.di.PageRef; +import org.eclipse.papyrus.infra.editor.welcome.Welcome; +import org.eclipse.papyrus.infra.ui.architecture.dialogs.ArchitectureContextDialog; +import org.eclipse.papyrus.infra.ui.architecture.messages.Messages; +import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker; +import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/** + * The page add validator for architecture framework. + * In our case, this will check if the page to add is contained in the current viewpoint. If not, open a dialog to change the context/viewpoint. + */ +public class ArchitecturePageAddValidator implements IPageAddValidator { + + /** + * Constructor. + */ + public ArchitecturePageAddValidator() { + // No nothing here + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.core.sasheditor.api.IPageAddValidator#isValid(java.lang.Object) + */ + @Override + public boolean isValid(final Object pageIdentifier) { + Object currentPageIdentifier = pageIdentifier instanceof PageRef ? ((PageRef) pageIdentifier).getPageIdentifier() : pageIdentifier; + + // We need to check if this is an EObject and not the welcome (for the welcome page) + if (currentPageIdentifier instanceof EObject && !(currentPageIdentifier instanceof Welcome)) { + final EObject eObject = (EObject) currentPageIdentifier; + final ViewPrototype prototype = ViewPrototype.get(eObject); + + // Get the checker + PolicyChecker checker = PolicyChecker.getFor(eObject); + + if (null != checker && null != prototype) { + // Initialize with window.OK + while (!checker.isInViewpoint(prototype.getRepresentationKind())) { + // If the dialog result is not OK button value, return false + // Otherwise, if the window returns OK, loop on while and re-open the dialog (if viewpoint is not the correct one) or return true + if (Window.OK != changeArchitectureContextAndViewPoint(eObject)) { + return false; + } else { + // Reload the policy checker after switch context/viewpoints + checker = PolicyChecker.getFor(eObject); + } + } + return true; + } + } + return true; + } + + /** + * This allows to change the context/viewpoint to manage the viewpoint for the selected diagram/table. + * + * @param eObject + * The diagram or table. + * @return The dialog result. + */ + private int changeArchitectureContextAndViewPoint(final EObject eObject) { + // Check the resource set as first + if (null == eObject.eResource() || !(eObject.eResource().getResourceSet() instanceof ModelSet)) { + // The initial result is the cancel fake + return Window.CANCEL; + } + + // Get the current contexts and viewpoints + final ArchitectureDescriptionUtils helper = new ArchitectureDescriptionUtils((ModelSet) eObject.eResource().getResourceSet()); + final String[] contextIds = new String[] { helper.getArchitectureContextId() }; + final String[] viewpointIds = helper.getArchitectureViewpointIds().toArray(new String[0]); + + // Prepare the dialog + final Shell shell = Display.getCurrent().getActiveShell(); + final ArchitectureContextDialog dialog = new ArchitectureContextDialog(shell, Messages.ArchitecturePageAddValidator_diagleTitle, + Messages.ArchitecturePageAddValidator_dialogLabel); + dialog.setSelectedContexts(contextIds); + dialog.setSelectedViewpoints(viewpointIds); + dialog.create(); + + // Open the dialog + int result = dialog.open(); + if (Window.OK == result) { + // In this case, activate the context and viewpoints + final TransactionalEditingDomain dom = helper.getModelSet().getTransactionalEditingDomain(); + final CompoundCommand cmd = new CompoundCommand("Change Architecture Viewpoint to open diagrams and tables"); //$NON-NLS-1$ + if (!Arrays.equals(dialog.getSelectedContextIds(), contextIds)) { + cmd.append(helper.switchArchitectureContextId(dialog.getSelectedContextIds()[0])); + } + if (!Arrays.equals(dialog.getSelectedViewpointIds(), viewpointIds)) { + cmd.append(helper.switchArchitectureViewpointIds(dialog.getSelectedViewpointIds())); + } + if (!cmd.isEmpty()) { + dom.getCommandStack().execute(cmd); + } + } + + return result; + } + +} |