diff --git a/de.prob.ui/plugin.xml b/de.prob.ui/plugin.xml index b4914d0a1c2db03ecf6a9b255a947eebc874a7ee..fe42b2a1dc7b85af4ec8cee548048af2f3843c6a 100644 --- a/de.prob.ui/plugin.xml +++ b/de.prob.ui/plugin.xml @@ -744,7 +744,7 @@ <handler commandId="de.prob.ui.newcore.export"> <class - class="de.prob.ui.eventb.ExportClassicHandler"> + class="de.prob.ui.eventb.ExportNewCoreHandler"> </class> <enabledWhen> <with diff --git a/de.prob.ui/src/de/prob/ui/eventb/ExportClassicHandler.java b/de.prob.ui/src/de/prob/ui/eventb/ExportClassicHandler.java deleted file mode 100644 index 858938c0de120fc8d1caaeff0f7eb91be3dc421b..0000000000000000000000000000000000000000 --- a/de.prob.ui/src/de/prob/ui/eventb/ExportClassicHandler.java +++ /dev/null @@ -1,129 +0,0 @@ -package de.prob.ui.eventb; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.Writer; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.IHandler; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.preferences.InstanceScope; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.handlers.HandlerUtil; -import org.eventb.core.IEventBRoot; -import org.eventb.core.IMachineRoot; -import org.osgi.service.prefs.BackingStoreException; -import org.osgi.service.prefs.Preferences; - -import de.prob.core.translator.TranslationFailedException; -import de.prob.eventb.translator.TranslatorFactory; -import de.prob.logging.Logger; - -/** - * @author bendisposto - * @deprecated Use ExpprtNewCoreHandler instead - */ -@Deprecated -public class ExportClassicHandler extends AbstractHandler implements IHandler { - - public Object execute(final ExecutionEvent event) throws ExecutionException { - final IEventBRoot root = getSelectedEventBRoot(event); - if (root != null) { - final Preferences prefs = Platform.getPreferencesService() - .getRootNode().node(InstanceScope.SCOPE) - .node("prob_export_preferences"); - final Shell shell = HandlerUtil.getActiveShell(event); - final String fileName = askForExportFile(prefs, shell, root); - if (fileName != null) { - exportToClassic(fileName, root); - } - } - return null; - } - - private IEventBRoot getSelectedEventBRoot(final ExecutionEvent event) { - final ISelection fSelection = HandlerUtil.getCurrentSelection(event); - IEventBRoot root = null; - if (fSelection instanceof IStructuredSelection) { - final IStructuredSelection ssel = (IStructuredSelection) fSelection; - if (ssel.size() == 1 - && ssel.getFirstElement() instanceof IEventBRoot) { - root = (IEventBRoot) ssel.getFirstElement(); - } - } - return root; - } - - private String askForExportFile(final Preferences prefs, final Shell shell, - final IEventBRoot root) { - final String path = prefs.get("dir", System.getProperty("user.home")); - - final FileDialog dialog = new FileDialog(shell, SWT.SAVE); - dialog.setFilterExtensions(new String[] { "*.eventb" }); - - dialog.setFilterPath(path); - final String subext = (root instanceof IMachineRoot) ? "_mch" : "_ctx"; - dialog.setFileName(root.getComponentName() + subext + ".eventb"); - String result = dialog.open(); - if (result != null) { - final String newPath = dialog.getFilterPath(); - if (!path.equals(newPath)) { - prefs.put("dir", newPath); - try { - prefs.flush(); - } catch (BackingStoreException e) { - // Ignore, if preferences are not stored correctly we simply - // ignore it (annoying, but not critical) - } - } - if (!result.endsWith(".eventb")) { - result += ".eventb"; - } - } - return result; - } - - public static void exportToClassic(final String filename, - final IEventBRoot root) { - final boolean isSafeToWrite = isSafeToWrite(filename); - - if (isSafeToWrite) { - Writer fw = null; - try { - fw = new FileWriter(filename); - TranslatorFactory.translate(root, new PrintWriter(fw)); - fw.append('\n'); - } catch (TranslationFailedException e) { - e.notifyUserOnce(); - } catch (IOException e) { - Logger.notifyUser("Unable to create file '" + filename + "'"); - } finally { - if (fw != null) { - try { - fw.close(); - } catch (IOException e) { - } - } - } - } - } - - private static boolean isSafeToWrite(final String filename) { - if (new File(filename).exists()) { - final MessageDialog dialog = new MessageDialog(null, "File exists", - null, "The file exists. Do you want to overwrite it?", - MessageDialog.QUESTION, new String[] { "Yes", "No" }, 0); - return dialog.open() == 0; - } else - return true; - } -}