| /******************************************************************************* |
| * Copyright (c) 2009 Zoltan Ujhelyi and Daniel Varro. |
| * 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: |
| * Zoltan Ujhelyi - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.viatra2.visualisation.modelspace.actions; |
| |
| import java.util.List; |
| |
| import org.eclipse.jface.dialogs.MessageDialog; |
| import org.eclipse.ui.ISharedImages; |
| import org.eclipse.ui.IWorkbenchPart; |
| import org.eclipse.ui.PlatformUI; |
| import org.eclipse.viatra2.core.IModelElement; |
| import org.eclipse.viatra2.core.IModelManager; |
| import org.eclipse.viatra2.framework.IFramework; |
| import org.eclipse.viatra2.logger.Logger; |
| import org.eclipse.viatra2.treeeditor.actions.ViatraTreeEditorSelectionAction; |
| import org.eclipse.viatra2.visualisation.IVisualisationDescriptor; |
| import org.eclipse.viatra2.visualisation.modelspace.ModelSpaceVisualisationDescriptor; |
| import org.eclipse.viatra2.visualisation.view.ViatraVisualisationView; |
| |
| /** |
| * Describes an abstract element visualisation action. |
| * @author Zoltan Ujhelyi |
| */ |
| public abstract class VisualiseSelectedElementAction extends |
| ViatraTreeEditorSelectionAction { |
| |
| /** |
| * Contains the ID of the graph visualiser view |
| */ |
| public static final String ID_VIEW = "org.eclipse.viatra2.visualisation.view"; |
| ViatraVisualisationView view; |
| ModelSpaceVisualisationDescriptor descriptor; |
| |
| /** |
| * Initializes the abstract action |
| */ |
| public VisualiseSelectedElementAction() { |
| super(); |
| setText("Graph Visualisation"); |
| setToolTipText(""); |
| setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() |
| .getImageDescriptor(ISharedImages.IMG_OBJ_ELEMENT)); |
| } |
| |
| /** |
| * Initializes the abstract action |
| * @param part |
| */ |
| public VisualiseSelectedElementAction(IWorkbenchPart part) { |
| super(part); |
| } |
| |
| @Override |
| public void run() { |
| @SuppressWarnings("unchecked") |
| List<IModelElement> selectedObjects = getSelectedObjects().toList(); |
| |
| IModelElement element = selectedObjects.get(0); |
| |
| IFramework framework = element.getModelSpace().getFramework(); |
| Logger log = framework.getLogger(); |
| IModelManager manager = framework.getTopmodel().getModelManager(); |
| if (manager == null) { |
| log.error("***The machine is not connected to a Model Space***"); |
| return; |
| } |
| |
| view = ViatraVisualisationView.openView(); |
| IVisualisationDescriptor newDescriptor = view.getDescriptor(framework); |
| if (newDescriptor == null || !(newDescriptor instanceof ModelSpaceVisualisationDescriptor)) { |
| descriptor = new ModelSpaceVisualisationDescriptor(); |
| view.setDescriptor(framework, descriptor); |
| descriptor.setFramework(framework); |
| descriptor.setModelManager(manager); |
| } else { |
| descriptor = (ModelSpaceVisualisationDescriptor) newDescriptor; |
| IModelManager oldManager = descriptor.getModelManager(); |
| if (oldManager != null && !manager.equals(oldManager)) { |
| if (!MessageDialog.openConfirm(PlatformUI.getWorkbench().getDisplay() |
| .getActiveShell(), "Graph overwrite", "Another model space is already visualised. Do you want to overwrite it?")) { |
| return; |
| } |
| descriptor.setFramework(framework); |
| descriptor.setModelManager(manager); |
| } else if (oldManager == null) { |
| descriptor.setFramework(framework); |
| descriptor.setModelManager(manager); |
| } |
| } |
| |
| loadFilterData(view, selectedObjects); |
| descriptor.redrawGraph(); |
| } |
| |
| @Override |
| public void updateSelf() { |
| if (getSelectedObjects().size()!=1) setEnabled(false); |
| else setEnabled(true); |
| } |
| |
| /** |
| * Loads a filter of a list of elements |
| * @param view the view to load the information |
| * @param elements the list of elements to be loaded |
| */ |
| abstract void loadFilterData(ViatraVisualisationView view, List<IModelElement>elements); |
| |
| } |