KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > isac > gui > action > NewScenarioAction


1 /*
2  * CLIF is a Load Injection Framework
3  * Copyright (C) 2004 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * CLIF
20  *
21  * Contact: clif@objectweb.org
22  */

23 package org.objectweb.clif.scenario.util.isac.gui.action;
24
25 import java.net.URL JavaDoc;
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 /**
41  * Action which create a new scenario
42  *
43  * @author JC Meillaud
44  * @author A Peyrard
45  */

46 public class NewScenarioAction extends Action {
47     /**
48      * The application window, which launch this action
49      */

50     private ScenarioGUIEditor window;
51     private TreeManager treeManager;
52     private ScenarioTreeViewer viewer;
53     static Category cat = Category.getInstance(NewScenarioAction.class
54             .getName());
55     /**
56      * Build a new 'new scenario' action
57      *
58      * @param w
59      * The application window, in wich we will use this action
60      */

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 JavaDoc(
69                     "file:" + FileName.NEW_ICON)));
70         } catch (Exception JavaDoc e) {
71             cat.warn("Unable to find new icon file");
72         }
73     }
74
75     public void run() {
76         cat.debug("-> run");
77
78         // check if the scenario is saved
79
if (!this.window.isBehaviorsSavedState() && this.window.isNotNullTree()) {
80             // ask the user if he wants to save the scenario
81
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         // update the file name to null
92
this.window.setFileName(null);
93         ScenarioTreeViewer tv = this.window.getTreeViewer();
94         tv.setInput(tree);
95         tv.refresh();
96         // Clear the XML editor
97
this.window.getStyledText().setText("") ;
98         // create a new empty profile
99
LoadProfileManager.getInstance().createNewLoadProfile() ;
100         // set the saved state
101
this.window.setScenarioSavedState(false) ;
102     }
103 }
Popular Tags