1 23 package org.objectweb.clif.scenario.util.isac.gui.action; 24 25 import java.net.URL ; 26 import java.util.Vector ; 27 28 import org.apache.log4j.Category; 29 import org.eclipse.jface.action.Action; 30 import org.eclipse.jface.dialogs.MessageDialog; 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.Display; 35 import org.eclipse.swt.widgets.FileDialog; 36 import org.objectweb.clif.scenario.util.isac.FileName; 37 import org.objectweb.clif.scenario.util.isac.gui.ScenarioGUIEditor; 38 import org.objectweb.clif.scenario.util.isac.loadprofile.LoadProfileManager; 39 import org.objectweb.clif.scenario.util.isac.util.tree.ErrorWarningDialog; 40 import org.objectweb.clif.scenario.util.isac.util.tree.LoadScenario; 41 import org.objectweb.clif.scenario.util.isac.util.tree.ScenarioNode; 42 import org.objectweb.clif.scenario.util.isac.util.tree.TreeManager; 43 49 public class OpenScenarioAction extends Action { 50 53 private ScenarioGUIEditor window; 54 static Category cat = Category.getInstance(OpenScenarioAction.class.getName()); 55 56 60 public OpenScenarioAction(ApplicationWindow w) { 61 this.window = (ScenarioGUIEditor) w; 62 this.setText("&Open@Ctrl+O"); 63 this.setToolTipText("Open a scenario file"); 64 try { 65 this.setImageDescriptor( 66 ImageDescriptor.createFromURL( 67 new URL ("file:" + FileName.OPEN_ICON))); 68 } catch (Exception e) { 69 cat.warn("Unable to find load icon file"); 70 } 71 } 72 73 public void run() { 74 cat.debug("-> run") ; 75 if (!this.window.isBehaviorsSavedState() && this.window.isNotNullTree()) { 77 if (MessageDialog 79 .openQuestion( 80 Display.getCurrent().getActiveShell(), 81 "Scenario is not saved", 82 "The current scenario is not saved,\n" 83 + "you will loose changes. Would you like to save it ?")) { 84 SaveScenarioAction.saveScenario(this.window) ; 85 } 86 } 87 String [] filterExtensions={"*.xml"}; 89 FileDialog dialog = 91 new FileDialog(this.window.getShell(), SWT.OPEN); 92 dialog.setText("Open a CLIF scenario"); 93 dialog.setFilterExtensions(filterExtensions); 94 String fileName = dialog.open(); 96 if (fileName == null) return ; 97 this.window.setFileName(fileName); 98 cat.warn("LOAD THE SCENARIO IN THE FILE : " + fileName) ; 100 Vector errors = new Vector () ; 102 ScenarioNode tree = LoadScenario.loadScenario(fileName, TreeManager.getTreeManager(null).getNodes(), errors) ; 103 if (tree == null) { 104 ErrorWarningDialog dialogError = new ErrorWarningDialog(this.window.getShell(), errors) ; 106 dialogError.open() ; 107 LoadProfileManager.getInstance().createNewLoadProfile(); 109 } 110 else { 111 if (errors.size() != 0) { 113 ErrorWarningDialog dialogError = new ErrorWarningDialog(this.window.getShell(), errors) ; 115 dialogError.open() ; 116 } 117 TreeManager.getTreeManager(null).setTree(tree); 119 this.window.getTreeViewer().setInput(tree); 120 } 121 this.window.getTreeViewer().refresh() ; 122 this.window.setScenarioSavedState(true) ; 124 } 125 } 126 | Popular Tags |