/******************************************************************************* | |
* 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.editor.text.light.vtcl; | |
import org.eclipse.viatra2.editor.text.Activator; | |
import org.eclipse.viatra2.editor.text.light.VTCLEditor; | |
import org.eclipse.swt.widgets.Event; | |
import org.eclipse.ui.IFileEditorInput; | |
import org.eclipse.ui.actions.RetargetAction; | |
import org.eclipse.viatra2.framework.FrameworkManager; | |
import org.eclipse.viatra2.framework.IFramework; | |
public class ParseVTCLAction extends RetargetAction { | |
protected VTCLEditor iEditor = null; | |
protected String iFrameworkID; | |
public ParseVTCLAction updateSelf(VTCLEditor e) | |
{ | |
iEditor = e; | |
return this; | |
} | |
public ParseVTCLAction(String fwid) { | |
super("parseVTCL", "Parse VTCL"); | |
iFrameworkID = fwid; | |
setImageDescriptor(Activator.getImageDescriptor("icons/parse.png")); | |
} | |
public ParseVTCLAction(String actionID, String text) { | |
super(actionID, text); | |
} | |
@Override | |
public boolean isEnabled() { | |
return true; | |
} | |
@Override | |
public void runWithEvent(Event event) { | |
run(); | |
} | |
@Override | |
public void run() { | |
if (iEditor!=null && iFrameworkID!=null) | |
{ | |
IFramework fw = FrameworkManager.getInstance().getFramework(iFrameworkID); | |
if (fw==null) | |
return; | |
if (iEditor.isDirty()) | |
iEditor.doSave(null); | |
try { | |
fw.nativeImport(((IFileEditorInput)iEditor.getEditorInput()).getFile().getContents(), | |
fw.getNativeImportersForExtension("vtcl").iterator().next()); | |
} catch (Exception e) | |
{ | |
fw.getLogger().fatal(e.getMessage()); | |
} | |
} | |
} | |
} |