1 23 package org.objectweb.clif.scenario.util.isac.gui.action; 24 25 import java.net.URL ; 26 27 import org.apache.log4j.Category; 28 import org.eclipse.jface.action.Action; 29 import org.eclipse.jface.dialogs.MessageDialog; 30 import org.eclipse.jface.resource.ImageDescriptor; 31 import org.eclipse.jface.window.ApplicationWindow; 32 import org.eclipse.swt.widgets.Display; 33 import org.objectweb.clif.scenario.util.isac.FileName; 34 import org.objectweb.clif.scenario.util.isac.gui.ScenarioGUIEditor; 35 import org.objectweb.clif.scenario.util.isac.gui.tree.ScenarioTreeViewer; 36 import org.objectweb.clif.scenario.util.isac.loadprofile.LoadProfileManager; 37 import org.objectweb.clif.scenario.util.isac.util.tree.ScenarioNode; 38 import org.objectweb.clif.scenario.util.isac.util.tree.TreeManager; 39 40 46 public class NewScenarioAction extends Action { 47 50 private ScenarioGUIEditor window; 51 private TreeManager treeManager; 52 private ScenarioTreeViewer viewer; 53 static Category cat = Category.getInstance(NewScenarioAction.class 54 .getName()); 55 61 public NewScenarioAction(ApplicationWindow w) { 62 cat.debug("-> constructor"); 63 this.window = (ScenarioGUIEditor) w; 64 treeManager = TreeManager.getTreeManager(null); 65 this.setText("&New@Ctrl+N"); 66 this.setToolTipText("Create a new Scenario"); 67 try { 68 this.setImageDescriptor(ImageDescriptor.createFromURL(new URL ( 69 "file:" + FileName.NEW_ICON))); 70 } catch (Exception e) { 71 cat.warn("Unable to find new icon file"); 72 } 73 } 74 75 public void run() { 76 cat.debug("-> run"); 77 78 if (!this.window.isBehaviorsSavedState() && this.window.isNotNullTree()) { 80 if (MessageDialog 82 .openQuestion( 83 Display.getCurrent().getActiveShell(), 84 "Scenario is not saved", 85 "The current scenario is not saved,\n" 86 + "you will loose changes. Would you like to save it ?")) { 87 SaveScenarioAction.saveScenario(this.window) ; 88 } 89 } 90 ScenarioNode tree = treeManager.createNewTree(); 91 this.window.setFileName(null); 93 ScenarioTreeViewer tv = this.window.getTreeViewer(); 94 tv.setInput(tree); 95 tv.refresh(); 96 this.window.getStyledText().setText("") ; 98 LoadProfileManager.getInstance().createNewLoadProfile() ; 100 this.window.setScenarioSavedState(false) ; 102 } 103 } | Popular Tags |