Skip to content

Commit

Permalink
[2095] "Show in Project Explorer" or "Show related Elements in Capella
Browse files Browse the repository at this point in the history
Explorer" shall propose to unhide model elements in Explorer 

Bug 2095

Change-Id: Ifa75069b3f93a6d9235f39e406c30989fc7683eb
Signed-off-by: Ali Akar <ali.akar82@gmail.com>
  • Loading branch information
aliakar82 authored and pdulth committed Jun 18, 2018
1 parent 4953156 commit 2b5ea86
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 76 deletions.
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2017 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
* 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
Expand All @@ -18,14 +18,15 @@
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.sirius.viewpoint.DRepresentation;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.navigator.CommonNavigator;
import org.polarsys.capella.common.helpers.EObjectLabelProviderHelper;
import org.polarsys.capella.common.tools.report.EmbeddedMessage;
import org.polarsys.capella.common.tools.report.config.registry.ReportManagerRegistry;
import org.polarsys.capella.common.tools.report.util.IReportManagerDefaultComponents;
import org.polarsys.capella.common.ui.actions.LocateFilteredElementsInCommonNavigatorAction;
import org.polarsys.capella.common.ui.services.helper.EObjectImageProviderHelper;
import org.polarsys.capella.core.model.handler.helpers.RepresentationHelper;

Expand Down Expand Up @@ -68,34 +69,30 @@ public void run() {
selectElementInCapellaExplorer(eObject);
}

protected Object getFirstSelectedElement(ISelection selection) {
if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
return null;
}
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
return structuredSelection.getFirstElement();
}

/**
* @param elem
* @param element
*/
public void selectElementInCapellaExplorer(EObject elem) {
if (null != elem) {
public void selectElementInCapellaExplorer(EObject element) {
if (null != element) {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ISelection newSelection = new StructuredSelection(elem);
Object firstElement = getFirstSelectedElement(newSelection);
ISelection newSelection = new StructuredSelection(element);

try {
IViewPart explorerView = activePage.showView(__EXPLORER_VIEW_ID);
if(firstElement instanceof DRepresentation){
explorerView.getViewSite().getSelectionProvider().setSelection(
new StructuredSelection(RepresentationHelper.getRepresentationDescriptor((DRepresentation)firstElement)));
CommonNavigator explorerView = (CommonNavigator)activePage.showView(__EXPLORER_VIEW_ID);
if(element instanceof DRepresentation){
explorerView.getViewSite().getSelectionProvider().setSelection(
new StructuredSelection(RepresentationHelper.getRepresentationDescriptor((DRepresentation)element)));
} else {
// when it doesn't concern DRepresentations
explorerView.getViewSite().getSelectionProvider().setSelection(newSelection);
// When it doesn't concern DRepresentations
explorerView.getViewSite().getSelectionProvider().setSelection(newSelection);
}
if (!LocateFilteredElementsInCommonNavigatorAction.isSetSelection(explorerView.getCommonViewer(), element)) {
LocateFilteredElementsInCommonNavigatorAction locateFilteredElementsInCommonNavigatorAction = new LocateFilteredElementsInCommonNavigatorAction(__EXPLORER_VIEW_ID);
locateFilteredElementsInCommonNavigatorAction.run((IStructuredSelection) newSelection);
explorerView.selectReveal(newSelection);
}
} catch (PartInitException exception) {
__logger.warn(new EmbeddedMessage(exception.getMessage(), IReportManagerDefaultComponents.UI), exception);
__logger.warn(new EmbeddedMessage(exception.getMessage(), IReportManagerDefaultComponents.UI), exception);
}
}
}
Expand Down
Expand Up @@ -11,8 +11,10 @@ Require-Bundle: org.eclipse.help,
org.eclipse.emf.transaction.ui;visibility:=reexport,
org.polarsys.capella.common.ef,
org.polarsys.capella.common;visibility:=reexport,
org.eclipse.ui.forms;visibility:=reexport
org.eclipse.ui.forms;visibility:=reexport,
org.eclipse.ui.navigator;visibility:=reexport
Export-Package: org.polarsys.capella.common.ui,
org.polarsys.capella.common.ui.actions,
org.polarsys.capella.common.ui.providers,
org.polarsys.capella.common.ui.services,
org.polarsys.capella.common.ui.services.commands,
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2017 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
* 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
Expand All @@ -8,40 +8,55 @@
* Contributors:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.core.platform.sirius.ui.navigator.actions;
package org.polarsys.capella.common.ui.actions;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.navigator.NavigatorFilterService;
import org.eclipse.ui.navigator.CommonNavigator;
import org.eclipse.ui.navigator.ICommonFilterDescriptor;
import org.eclipse.ui.navigator.INavigatorContentService;
import org.polarsys.capella.core.platform.sirius.ui.navigator.view.CapellaCommonNavigator;

/**
* This action will be executed if the navigated elements are not visible in the project explorer. Its responsibilities
* is to find the effective filters applied on the navigated elements and deactivate them, so that the navigated
* elements will be visible and focused on the project explorer.
*
* @author Cong Bang DO
*
*/
public class LocatedElementsNotFoundInCapellaExplorerHandlingAction {
public class LocateFilteredElementsInCommonNavigatorAction {

private String commonNavigatorID;

public LocateFilteredElementsInCommonNavigatorAction(String commonNavigatorID){
Assert.isLegal(commonNavigatorID != null && !commonNavigatorID.isEmpty());
this.commonNavigatorID = commonNavigatorID;
}

/**
*
* @param selection The structured selection on others views differ from the project explorer view.
*/
public void run(IStructuredSelection selection) {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
// Get the Capella Explorer.
CapellaCommonNavigator capellaNavigator = (CapellaCommonNavigator) activePage.findView(CapellaCommonNavigator.ID);
INavigatorContentService capellaNavigatorContentService = capellaNavigator.getNavigatorContentService();
// Get the View.
IViewPart viewPart = activePage.findView(commonNavigatorID);
Assert.isLegal(viewPart instanceof CommonNavigator);

CommonNavigator commonNavigator = (CommonNavigator) viewPart;
INavigatorContentService capellaNavigatorContentService = commonNavigator.getNavigatorContentService();
NavigatorFilterService capellaNavigatorFilterService = (NavigatorFilterService) capellaNavigatorContentService
.getFilterService();

Expand All @@ -58,7 +73,7 @@ public void run(IStructuredSelection selection) {
for (Object element : selection.toArray()) {
if (capellaNavigatorFilterService.isActive(filterDescriptor.getId())) {
activeFilterIds.add(filterDescriptor.getId());
if (!viewerFilter.select(capellaNavigator.getCommonViewer(), null, element)) {
if (!select(commonNavigator, viewerFilter, element)) {
effectiveFilterDescriptors.add(filterDescriptor);
effectiveFilterIds.add(filterDescriptor.getId());
}
Expand All @@ -68,24 +83,41 @@ public void run(IStructuredSelection selection) {

if (effectiveFilterDescriptors.size() > 0) {
StringBuilder dialogMessageBuilder = new StringBuilder();
dialogMessageBuilder.append(Messages.LocateInCapellaExplorerAction_SelectedElementNotVisible_0);
dialogMessageBuilder.append(Messages.LocateInCommonNavigator_SelectedElementNotVisible_0);
for (ICommonFilterDescriptor filterDescriptor : effectiveFilterDescriptors) {
dialogMessageBuilder
.append(" - " + filterDescriptor.getName() + ": " + filterDescriptor.getDescription() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
dialogMessageBuilder.append(Messages.LocateInCapellaExplorerAction_SelectedElementNotVisible_4);
dialogMessageBuilder.append(Messages.LocateInCommonNavigator_SelectedElementNotVisible_1);

boolean openFilterSelectionDialog = MessageDialog.openQuestion(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
Messages.LocateInCapellaExplorerAction_SelectedElementNotVisible_Title, dialogMessageBuilder.toString());
NLS.bind(Messages.LocateInCommonNavigator_SelectedElementNotVisible_Title, commonNavigator.getPartName()),
dialogMessageBuilder.toString());
if (openFilterSelectionDialog) {
activeFilterIds.removeAll(effectiveFilterIds);
capellaNavigatorFilterService.activateFilterIdsAndUpdateViewer(activeFilterIds.toArray(new String[0]));
}
} else {
MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
Messages.LocateInCapellaExplorerAction_SelectedElementNotVisible_Title,
Messages.LocateInCapellaExplorerAction_SelectedElementNotVisible_5);
NLS.bind(Messages.LocateInCommonNavigator_SelectedElementNotVisible_Title, commonNavigator.getPartName()),
NLS.bind(Messages.LocateInCommonNavigator_SelectedElementNotVisible_2, commonNavigator.getPartName()));
}
}

protected boolean select(CommonNavigator commonNavigator, ViewerFilter viewerFilter, Object element) {
boolean select = true;
while (select && !(element instanceof IFile)) {
select = viewerFilter.select(commonNavigator.getCommonViewer(), null, element);
ITreeContentProvider contentProvider = (ITreeContentProvider) commonNavigator.getCommonViewer()
.getContentProvider();
element = contentProvider.getParent(element);
}
return select;
}

public static boolean isSetSelection(StructuredViewer viewer, Object exptectedElement) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
return selection.toArray().length > 0 && selection.getFirstElement().equals(exptectedElement);
}
}
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
* 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:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.common.ui.actions;

import org.eclipse.osgi.util.NLS;

/**
* I18n support.
*/
public class Messages extends NLS {

private static final String BUNDLE_NAME = "org.polarsys.capella.common.ui.actions.messages"; //$NON-NLS-1$

public static String LocateInCommonNavigator_SelectedElementNotVisible_0;
public static String LocateInCommonNavigator_SelectedElementNotVisible_1;
public static String LocateInCommonNavigator_SelectedElementNotVisible_2;
public static String LocateInCommonNavigator_SelectedElementNotVisible_Title;

static {
// Initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}

/**
* Constructor.
*/
private Messages() {
// Do nothing.
}
}
@@ -0,0 +1,14 @@
#===============================================================================
# Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
# 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:
# Thales - initial API and implementation
#===============================================================================
LocateInCommonNavigator_SelectedElementNotVisible_0=One of the located elements might be hidden by the filters below: \n\n
LocateInCommonNavigator_SelectedElementNotVisible_1=\nDo you want to disable these filters?
LocateInCommonNavigator_SelectedElementNotVisible_2=No element(s) found in the {0}
LocateInCommonNavigator_SelectedElementNotVisible_Title=Show in {0}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
* 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
Expand Down Expand Up @@ -33,6 +33,7 @@
import org.polarsys.capella.common.tools.report.EmbeddedMessage;
import org.polarsys.capella.common.tools.report.config.registry.ReportManagerRegistry;
import org.polarsys.capella.common.tools.report.util.IReportManagerDefaultComponents;
import org.polarsys.capella.common.ui.actions.LocateFilteredElementsInCommonNavigatorAction;
import org.polarsys.capella.common.ui.toolkit.browser.content.provider.wrapper.EObjectWrapper;
import org.polarsys.capella.core.data.cs.Part;
import org.polarsys.capella.core.data.epbs.ConfigurationItem;
Expand Down Expand Up @@ -127,9 +128,9 @@ protected void selectElementInCapellaExplorer(ISelection selection) {
explorerView = (CapellaCommonNavigator) activePage.showView(CapellaCommonNavigator.ID);
}
explorerView.selectReveal(selection);
if (((StructuredSelection) explorerView.getCommonViewer().getSelection()).toArray().length == 0) {
LocatedElementsNotFoundInCapellaExplorerHandlingAction locatedElementsNotFoundInCapellaExplorerHandlingAction = new LocatedElementsNotFoundInCapellaExplorerHandlingAction();
locatedElementsNotFoundInCapellaExplorerHandlingAction.run((IStructuredSelection) selection);
if (!LocateFilteredElementsInCommonNavigatorAction.isSetSelection(explorerView.getCommonViewer(), ((IStructuredSelection) selection).getFirstElement())) {
LocateFilteredElementsInCommonNavigatorAction locateFilteredElementsInCommonNavigatorAction = new LocateFilteredElementsInCommonNavigatorAction(CapellaCommonNavigator.ID);
locateFilteredElementsInCommonNavigatorAction.run((IStructuredSelection) selection);
explorerView.selectReveal(selection);
}
} catch (PartInitException exception) {
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2014 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
* 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
Expand All @@ -15,6 +15,8 @@
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;
import org.polarsys.capella.common.ui.actions.LocateFilteredElementsInCommonNavigatorAction;
import org.polarsys.capella.core.platform.sirius.ui.navigator.view.CapellaCommonNavigator;

/**
*/
Expand All @@ -34,12 +36,12 @@ class NavigateAction extends Action {
/**
* Constructor.
*
* @param element_p
* @param viewer_p
* @param element
* @param viewer
*/
public NavigateAction(EObject element_p, StructuredViewer viewer_p) {
_element = element_p;
_viewer = viewer_p;
public NavigateAction(EObject element, StructuredViewer viewer) {
_element = element;
_viewer = viewer;
}

/**
Expand All @@ -49,9 +51,9 @@ public NavigateAction(EObject element_p, StructuredViewer viewer_p) {
public void run() {
IStructuredSelection selection = new StructuredSelection(_element);
_viewer.setSelection(selection, true);
if (((StructuredSelection) _viewer.getSelection()).toArray().length == 0) {
LocatedElementsNotFoundInCapellaExplorerHandlingAction locatedElementsNotFoundInCapellaExplorerHandlingAction = new LocatedElementsNotFoundInCapellaExplorerHandlingAction();
locatedElementsNotFoundInCapellaExplorerHandlingAction.run(selection);
if (!LocateFilteredElementsInCommonNavigatorAction.isSetSelection(_viewer, _element)) {
LocateFilteredElementsInCommonNavigatorAction LocateFilteredElementsInCommonNavigatorAction = new LocateFilteredElementsInCommonNavigatorAction(CapellaCommonNavigator.ID);
LocateFilteredElementsInCommonNavigatorAction.run(selection);
_viewer.setSelection(selection, true);
}
}
Expand Down

0 comments on commit 2b5ea86

Please sign in to comment.