1 /***
2 *
3 */
4 package org.telscenter.pas.beans;
5
6 import java.awt.event.ActionEvent;
7 import java.awt.event.WindowAdapter;
8 import java.awt.event.WindowEvent;
9 import java.util.Collection;
10 import java.util.Iterator;
11
12 import javax.swing.AbstractAction;
13 import javax.swing.JButton;
14 import javax.swing.JDialog;
15
16 import org.telscenter.pas.steps.INoteStep;
17 import org.telscenter.pas.steps.INoteUI;
18 import org.telscenter.pas.steps.Note;
19 import org.telscenter.pas.steps.ProjectInfoStep;
20 import org.telscenter.pas.steps.actions.DialogSaveAction;
21 import org.telscenter.pas.ui.dialog.PasDialogManager;
22 import org.telscenter.pas.ui.dialog.PasMessageDialogUI;
23 import org.telscenter.pas.ui.dialog.PasSystemExitConfirmDialogUI;
24 import org.xito.dialog.CustomDialog;
25
26 /***
27 * @author aperritano
28 *
29 */
30 public class ExitSessionAction extends AbstractAction {
31
32 private PasProject pasProject;
33
34 /***
35 *
36 */
37 public ExitSessionAction(PasProject pasProject) {
38 this.pasProject = pasProject;
39
40 }
41
42
43
44
45
46
47 public void actionPerformed(final ActionEvent e) {
48
49 if(pasProject.isAuthoringMode()) {
50 pasProject.getProjectFrame().dispose();
51 return;
52 }
53
54
55 if (!pasProject.getExitOnClose()) {
56 pasProject.getProjectFrame().setVisible(false);
57 return;
58 }
59
60
61 if( isNoteOpen() ) {
62 JDialog showNoteOpenCheckDialog = showNoteOpenCheckDialog();
63 showNoteOpenCheckDialog.setVisible(true);
64 } else {
65
66 DialogSaveAction ds = new DialogSaveAction(Messages
67 .getString("PasProject.confirm_end")) {
68
69 public void actionPerformed(ActionEvent e) {
70 super.actionPerformed(e);
71 pasProject.getProjectFrame().dispose();
72 pasProject.getSessionService().userRequestsTermination();
73 }
74
75 };
76
77 PasSystemExitConfirmDialogUI ui = new PasSystemExitConfirmDialogUI(ds);
78
79 ui.setMessage(Messages.getString("PasProject.1"));
80 CustomDialog showPasMessageDialog = PasDialogManager
81 .showPasMessageDialog(
82 Messages.getString("PasProject.exit_dialog_title"),
83 ui.createDialogPanel(), pasProject.getProjectFrame(),
84 true);
85
86 if (e != null) {
87 final JButton b = (JButton) e.getSource();
88 b.setEnabled(false);
89
90 showPasMessageDialog.addWindowListener(new WindowAdapter() {
91
92 public void windowOpened(WindowEvent e) {
93 }
94
95 public void windowActivated(WindowEvent arg0) {
96
97 };
98
99 public void windowClosed(WindowEvent arg0) {
100 b.setEnabled(true);
101 }
102 });
103 }
104 }
105
106 }
107
108 /***
109 * checks if there any open notes
110 *
111 * @return
112 */
113 protected boolean isNoteOpen() {
114
115 PasActivity[] activities = this.pasProject.getActivities();
116 for (PasActivity activity : activities) {
117 PasStep[] steps = activity.getSteps();
118 for (PasStep step : steps) {
119 if (step instanceof INoteStep) {
120 INoteUI noteUI = ((INoteStep) step).getNoteUI();
121 if ( noteUI != null && noteUI.isNoteOpen())
122 return true;
123 }
124 }
125
126
127 }
128 return false;
129 }
130
131 public JDialog showNoteOpenCheckDialog() {
132 final PasMessageDialogUI ui = new PasMessageDialogUI(true);
133
134
135 ui.setMessage("Please save and close all Notes before exiting.");
136 return PasDialogManager.showPasMessageDialog("Warning", ui
137 .createDialogPanel(), null, true);
138 }
139
140 }