| /******************************************************************************* |
| * 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 org.eclipse.jface.dialogs.MessageDialog; |
| import org.eclipse.ui.ISharedImages; |
| import org.eclipse.ui.PlatformUI; |
| import org.eclipse.viatra2.core.IModelManager; |
| import org.eclipse.viatra2.core.IModelSpace; |
| import org.eclipse.viatra2.framework.IFramework; |
| import org.eclipse.viatra2.frameworkgui.actions.AbstractFrameworkGUIAction; |
| import org.eclipse.viatra2.frameworkgui.content.FrameworkContainer; |
| import org.eclipse.viatra2.frameworkgui.views.FrameworkTreeView; |
| import org.eclipse.viatra2.logger.Logger; |
| import org.eclipse.viatra2.visualisation.IVisualisationDescriptor; |
| import org.eclipse.viatra2.visualisation.modelspace.ModelSpaceVisualisationDescriptor; |
| import org.eclipse.viatra2.visualisation.view.ViatraVisualisationView; |
| |
| /** |
| * @author Zoltan Ujhelyi |
| */ |
| public class VisualiseModelSpaceAction extends AbstractFrameworkGUIAction { |
| |
| ModelSpaceVisualisationDescriptor descriptor; |
| |
| /** |
| * Initializes the model space visualisation action |
| */ |
| public VisualiseModelSpaceAction() { |
| super(); |
| setText("Visualise Model Space"); |
| setToolTipText("Graph Visualisation for the Model Space"); |
| setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() |
| .getImageDescriptor(ISharedImages.IMG_OBJ_ELEMENT)); |
| } |
| |
| /** |
| * Initializes the model space visualisation action |
| * @param part |
| */ |
| public VisualiseModelSpaceAction(FrameworkTreeView part) { |
| this(); |
| setupInternals(part); |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see |
| * org.eclipse.viatra2.frameworkgui.actions.AbstractFrameworkGUIAction#isEnabled |
| * () |
| */ |
| @Override |
| public boolean isEnabled() { |
| return true; |
| } |
| |
| |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.jface.action.Action#run() |
| */ |
| @Override |
| public void run() { |
| refreshSelection(); |
| Object c = getFirstSelected(); |
| Logger log = iViatraFramework.getLogger(); |
| if (c instanceof FrameworkContainer) { |
| IFramework framework = ((FrameworkContainer) c).getFramework(); |
| IModelSpace modelSpace = (framework.getTopmodel()); |
| IModelManager manager = modelSpace.getModelManager(); |
| if (manager == null) { |
| log |
| .error("***The machine is not connected to a Model Space***"); |
| return; |
| } |
| // open view |
| ViatraVisualisationView view = ViatraVisualisationView.openView(); |
| IVisualisationDescriptor newDescriptor = view.getDescriptor(framework); |
| if (newDescriptor == null || !(newDescriptor instanceof ModelSpaceVisualisationDescriptor)) { |
| descriptor = new ModelSpaceVisualisationDescriptor(); |
| view.setDescriptor(framework, descriptor); |
| } 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.includeItem(manager.getRoot()); |
| descriptor.setModelManager(manager); |
| } |
| } |
| |
| } |