Skip to content

Commit

Permalink
[2122] Refactor of menu contributions
Browse files Browse the repository at this point in the history
- Fix: In ES for instance, selecting a Part in menu Show Related
Element(s) in Capella Explorer points to its AbstractType - Actor.
- Handling the semantic elements in LocateCapellaExplorerHandler instead
of CapellaCommonNavigator

Change-Id: I23a8d552cad5c66fb74f89ac07237ea65c23af3a
Signed-off-by: cong-bang.do <docongbang1993@gmail.com>
  • Loading branch information
bang-dc authored and pdulth committed Aug 22, 2018
1 parent e3b9213 commit 158295a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
Expand Up @@ -10,8 +10,12 @@
*******************************************************************************/
package org.polarsys.capella.core.platform.sirius.ui.navigator.handlers;

import java.util.ArrayList;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPart;

Expand Down Expand Up @@ -40,7 +44,20 @@ protected String getTargetedPartId() {
protected IViewPart handleSelection(ISelection selection, IWorkbenchPart activePart, ExecutionEvent event) {
LocateInCapellaExplorerAction relatedAction = new LocateInCapellaExplorerAction();
ActionCommandDelegate delegate = new ActionCommandDelegate(event);
relatedAction.selectionChanged(delegate, selection);

// Calculate the semantic elements to be selected in the navigator here, instead of inside the CapellaCommonNavigator;
// The CapellaCommonNavigator is used for all type of selection in the navigator, so handling
// the semantic elements in it is too late.
// It causes the selection of Part always points to its AbstractType (Actor i.e)
ArrayList<Object> semanticElementsToSelect = new ArrayList<>();
if (selection instanceof IStructuredSelection) {
Object[] selectedElements = ((IStructuredSelection) selection).toArray();
for (Object element : selectedElements) {
semanticElementsToSelect.add(LocateInCapellaExplorerAction.getElement(element));
}
}

relatedAction.selectionChanged(delegate, new StructuredSelection(semanticElementsToSelect));
relatedAction.setActivePart(delegate, activePart);
relatedAction.run(delegate);
return null;
Expand Down
Expand Up @@ -33,7 +33,6 @@
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
Expand Down Expand Up @@ -85,11 +84,9 @@
import org.polarsys.capella.common.ui.toolkit.widgets.filter.TreePatternFilter;
import org.polarsys.capella.core.commands.preferences.util.PreferencesHelper;
import org.polarsys.capella.core.data.capellacore.CapellaElement;
import org.polarsys.capella.core.model.handler.command.CapellaResourceHelper;
import org.polarsys.capella.core.platform.sirius.ui.navigator.CapellaNavigatorPlugin;
import org.polarsys.capella.core.platform.sirius.ui.navigator.IImageKeys;
import org.polarsys.capella.core.platform.sirius.ui.navigator.actions.LocateFilteredElementsInCommonNavigatorAction;
import org.polarsys.capella.core.platform.sirius.ui.navigator.actions.LocateInCapellaExplorerAction;
import org.polarsys.capella.core.platform.sirius.ui.navigator.actions.SelectionHelper;
import org.polarsys.capella.core.platform.sirius.ui.navigator.actions.move.MoveDownAction;
import org.polarsys.capella.core.platform.sirius.ui.navigator.actions.move.MoveUpAction;
Expand Down Expand Up @@ -798,20 +795,17 @@ public <T> T getAdapter(Class<T> adapter) {
@Override
public boolean show(ShowInContext context) {
ISelection selection = context.getSelection();

if (selection != null && !selection.isEmpty()) {
ArrayList<Object> toReveal = new ArrayList<Object>();
for (Object element : ((IStructuredSelection) selection).toArray()) {
toReveal.add(LocateInCapellaExplorerAction.getElement(element));
}
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;

IStructuredSelection newSelection = new StructuredSelection(toReveal);
selectReveal(newSelection);
if (!LocateFilteredElementsInCommonNavigatorAction.isSetSelection(this.getCommonViewer(), newSelection)) {
selectReveal(structuredSelection);

if (!LocateFilteredElementsInCommonNavigatorAction.isSetSelection(this.getCommonViewer(), structuredSelection)) {
LocateFilteredElementsInCommonNavigatorAction locateFilteredElementsInCommonNavigatorAction = new LocateFilteredElementsInCommonNavigatorAction(getSite().getId());
locateFilteredElementsInCommonNavigatorAction.run((IStructuredSelection) newSelection);
selectReveal(newSelection);
locateFilteredElementsInCommonNavigatorAction.run((IStructuredSelection) structuredSelection);
selectReveal(structuredSelection);
}

return true;
}

Expand Down

0 comments on commit 158295a

Please sign in to comment.