| /******************************************************************************* |
| * Copyright (c) 2004-2008 Istvan Rath 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: |
| * Istvan Rath - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.viatra2.frameworkgui.actions;
|
|
|
| import java.util.ArrayList; |
| |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.widgets.FileDialog; |
| import org.eclipse.ui.ISharedImages; |
| import org.eclipse.ui.PlatformUI; |
| import org.eclipse.viatra2.frameworkgui.views.FrameworkTreeView; |
| import org.eclipse.viatra2.loaders.LoaderFactory; |
|
|
| public class LoaderAction extends AbstractFrameworkGUIAction {
|
|
|
| private String iLoaderID;
|
|
|
| public LoaderAction(FrameworkTreeView part, String loaderid) {
|
| super();
|
| setupInternals(part);
|
| iLoaderID = loaderid;
|
| setText("Load program model");
|
| setToolTipText("Load a program model into the registry");
|
| setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
|
| .getImageDescriptor(ISharedImages.IMG_OBJ_FILE));
|
| }
|
|
|
| public void run() {
|
| refreshSelection();
|
| FileDialog fop = new FileDialog(iFT.getSite().getShell(), SWT.OPEN);
|
| fop.setText("Choose a program file to load");
|
| LoaderFactory lf = iViatraFramework.getLoaders().get(iLoaderID);
|
|
|
| ArrayList<String> exts = new ArrayList<String>();
|
| for (String ext : lf.getFileExtensionList())
|
| {
|
| exts.add("*."+ext);
|
| }
|
| fop.setFilterExtensions(exts.toArray(new String[0]));
|
| fop.setFilterNames(exts.toArray(new String[0]));
|
| String fn = fop.open();
|
| if (fn != null) {
|
| try {
|
| Long c = System.currentTimeMillis();
|
| iViatraFramework.loadMachine(fn, iLoaderID);
|
| Long c2 = System.currentTimeMillis();
|
| iViatraFramework.getLogger().info("Machine load lasted for "+(new Long(c2-c)).toString()+" ms");
|
| } catch (Exception e) {
|
| iFT.showMessage("Error performing native import with "+ iLoaderID);
|
| }
|
| }
|
| //iFT.refreshViewer();
|
| }
|
|
|
| }
|