/******************************************************************************* | |
* Copyright (C) 2017 Fondazione Bruno Kessler. | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v2.0 | |
* which accompanies this distribution, and is available at | |
* http://www.eclipse.org/legal/epl-v20.html | |
* | |
* Contributors: | |
* Alberto Debiasi - initial API and implementation | |
******************************************************************************/ | |
package org.polarsys.chess.contracts.refinementView.listener; | |
import org.eclipse.core.resources.IProject; | |
import org.eclipse.core.resources.IResource; | |
import org.eclipse.core.runtime.IAdaptable; | |
import org.eclipse.jface.viewers.ISelection; | |
import org.eclipse.jface.viewers.IStructuredSelection; | |
import org.eclipse.ui.IViewPart; | |
import org.eclipse.ui.IWorkbench; | |
import org.eclipse.ui.IWorkbenchPart; | |
import org.eclipse.ui.IWorkbenchWindow; | |
import org.eclipse.ui.PlatformUI; | |
import org.polarsys.chess.contracts.refinementView.view.CustomRefinementView; | |
import org.polarsys.chess.core.resourcelistener.SelectionListenerExtra; | |
public class SelectionListener extends SelectionListenerExtra { | |
private IProject prevProject; | |
@Override | |
public void selectionChanged(IWorkbenchPart part, ISelection selection) { | |
if (selection instanceof IStructuredSelection) { | |
Object element = ((IStructuredSelection) selection).getFirstElement(); | |
if (element instanceof IAdaptable) { | |
IResource resource = (IResource) ((IAdaptable) element).getAdapter(IResource.class); | |
if (resource != null) { | |
final IProject project = resource.getProject(); | |
if (project != prevProject) { | |
IWorkbench workbench = PlatformUI.getWorkbench(); | |
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); | |
IViewPart modelExplorerViewPart; | |
modelExplorerViewPart = window.getActivePage().findView(CustomRefinementView.View_ID); | |
if (modelExplorerViewPart != null) { | |
CustomRefinementView view = (CustomRefinementView) modelExplorerViewPart; | |
view.updateView(); | |
prevProject = project; | |
} | |
} | |
} | |
} | |
} | |
} | |
} |