1 23 package org.objectweb.clif.scenario.util.isac.gui.action; 24 25 import java.io.FileOutputStream ; 26 import java.io.PrintStream ; 27 import java.net.URL ; 28 29 import org.apache.log4j.Category; 30 import org.eclipse.jface.action.Action; 31 import org.eclipse.jface.resource.ImageDescriptor; 32 import org.eclipse.jface.window.ApplicationWindow; 33 import org.eclipse.swt.SWT; 34 import org.eclipse.swt.widgets.FileDialog; 35 import org.objectweb.clif.scenario.util.isac.FileName; 36 import org.objectweb.clif.scenario.util.isac.gui.ScenarioGUIEditor; 37 import org.objectweb.clif.scenario.util.isac.util.tree.TreeManager; 38 44 public class SaveScenarioAsAction extends Action { 45 static Category cat = Category.getInstance(SaveScenarioAsAction.class.getName()); 46 49 private ScenarioGUIEditor window; 50 51 55 public SaveScenarioAsAction(ApplicationWindow w) { 56 cat.debug("-> constructor") ; 57 this.window = (ScenarioGUIEditor) w; 58 this.setText("Save &As...@Ctrl+Alt+S"); 59 this.setToolTipText("Save the current Scenario in a specified file"); 60 try { 61 this.setImageDescriptor( 62 ImageDescriptor.createFromURL( 63 new URL ("file:" + FileName.SAVE_AS_ICON))); 64 } catch (Exception e) { 65 cat.warn("Unable to find save_as icon file"); 66 } 67 } 68 69 public void run() { 70 cat.debug("-> run") ; 71 FileDialog dialog = new FileDialog(this.window.getShell(), SWT.SAVE); 73 String fileName = dialog.open(); 75 if (fileName == null) { 76 this.window.getStatusLine().getProgressMonitor().done() ; 77 return ; 78 } 79 80 cat.debug("Save into the file "+fileName); 82 this.window.setFileName(fileName); 83 try { 85 FileOutputStream fileStream = new FileOutputStream (fileName) ; 86 PrintStream out = new PrintStream (fileStream) ; 87 TreeManager treeManager = TreeManager.getTreeManager(null) ; 88 treeManager.saveScenario(out); 90 fileStream.flush(); 91 fileStream.close() ; 92 this.window.setScenarioSavedState(true) ; 94 } 95 catch (Exception e) { 96 cat.warn("Unable to save the scenario in "+ fileName +", " + e) ; 97 } 98 } 99 } 100 | Popular Tags |