| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
package org.xmlhammer.gui.actions; |
| 23 |
|
|
| 24 |
|
import java.awt.Toolkit; |
| 25 |
|
import java.awt.event.KeyEvent; |
| 26 |
|
import java.text.DateFormat; |
| 27 |
|
import java.util.Date; |
| 28 |
|
|
| 29 |
|
import javax.swing.ImageIcon; |
| 30 |
|
import javax.swing.JOptionPane; |
| 31 |
|
import javax.swing.KeyStroke; |
| 32 |
|
|
| 33 |
|
import org.bounce.RunnableAction; |
| 34 |
|
import org.xmlhammer.Module; |
| 35 |
|
import org.xmlhammer.ModuleThread; |
| 36 |
|
import org.xmlhammer.ModuleThreadListener; |
| 37 |
|
import org.xmlhammer.gui.ProjectView; |
| 38 |
|
import org.xmlhammer.gui.XMLHammer; |
| 39 |
|
import org.xmlhammer.model.project.Project; |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
public class ExecuteAction extends RunnableAction implements ModuleThreadListener { |
| 49 |
|
private static final long serialVersionUID = 950916505478822172L; |
| 50 |
|
|
| 51 |
220 |
private XMLHammer parent = null; |
| 52 |
220 |
private ModuleThread thread = null; |
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
public ExecuteAction( XMLHammer parent) { |
| 60 |
220 |
super( "Execute"); |
| 61 |
|
|
| 62 |
220 |
this.parent = parent; |
| 63 |
|
|
| 64 |
220 |
putValue( MNEMONIC_KEY, new Integer( 'N')); |
| 65 |
220 |
putValue( ACCELERATOR_KEY, KeyStroke.getKeyStroke( KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false)); |
| 66 |
220 |
putValue( SMALL_ICON, new ImageIcon( getClass().getResource( "/org/xmlhammer/gui/icons/etool16/run_exc.gif"))); |
| 67 |
220 |
putValue( SHORT_DESCRIPTION, "Execute Project"); |
| 68 |
|
|
| 69 |
220 |
setEnabled( false); |
| 70 |
220 |
} |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
public void run() { |
| 76 |
462 |
parent.repaint(); |
| 77 |
462 |
ProjectView view = parent.getProjectsView().getSelectedView(); |
| 78 |
|
|
| 79 |
462 |
if (view.hasError()) { |
| 80 |
0 |
int result = JOptionPane.showConfirmDialog( parent, |
| 81 |
|
"Errors exist in project \""+view.getName()+"\".\n"+ |
| 82 |
|
"Continue execution?", "Errors in Project", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE); |
| 83 |
|
|
| 84 |
0 |
if (result == JOptionPane.NO_OPTION) { |
| 85 |
0 |
return; |
| 86 |
|
} |
| 87 |
|
} |
| 88 |
|
|
| 89 |
|
try { |
| 90 |
462 |
view.getLogger().info( "Start time: "+DateFormat.getDateTimeInstance().format(new Date())); |
| 91 |
|
|
| 92 |
462 |
Module module = view.getModule(); |
| 93 |
|
|
| 94 |
462 |
if (module != null) { |
| 95 |
440 |
if (module.hasFatal()) { |
| 96 |
0 |
JOptionPane.showMessageDialog( parent, |
| 97 |
|
"Unable to initialise the project.\n"+ |
| 98 |
|
"See log for more information.", "Fatal Initialization Error", JOptionPane.ERROR_MESSAGE); |
| 99 |
|
|
| 100 |
0 |
return; |
| 101 |
440 |
} else if (module.hasErrors()) { |
| 102 |
0 |
int result = JOptionPane.showConfirmDialog( parent, |
| 103 |
|
"Errors occurred during initialization, please see log for more information.\n"+ |
| 104 |
|
"Continue execution?", "Initialization Errors", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE); |
| 105 |
|
|
| 106 |
0 |
if (result == JOptionPane.NO_OPTION) { |
| 107 |
0 |
return; |
| 108 |
|
} |
| 109 |
0 |
} else if (module.hasWarnings()) { |
| 110 |
0 |
int result = JOptionPane.showConfirmDialog(parent, |
| 111 |
|
"Warnings occurred during initialization, please see log for more information.\n"+ |
| 112 |
|
"Continue execution?", "Initialization Warnings", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE); |
| 113 |
|
|
| 114 |
0 |
if (result == JOptionPane.NO_OPTION) { |
| 115 |
0 |
return; |
| 116 |
|
} |
| 117 |
|
} |
| 118 |
|
|
| 119 |
440 |
Project project = view.getProject(null); |
| 120 |
|
|
| 121 |
440 |
ModuleThread thread = new ModuleThread( view.getLogger(), view.getStatusBar(), view.getResult(), project.getInput(), module); |
| 122 |
|
|
| 123 |
|
|
| 124 |
440 |
setModuleThread(thread); |
| 125 |
440 |
parent.getStopAction().setModuleThread(thread); |
| 126 |
440 |
view.setModuleThread(thread); |
| 127 |
|
|
| 128 |
440 |
thread.start(); |
| 129 |
|
} |
| 130 |
0 |
} catch (Throwable t) { |
| 131 |
0 |
view.getStatusBar().setStatus("Execution Error"); |
| 132 |
0 |
view.getLogger().error("Module Execution Error", t); |
| 133 |
462 |
} |
| 134 |
462 |
} |
| 135 |
|
|
| 136 |
|
public ModuleThread getModuleThread() { |
| 137 |
462 |
return this.thread; |
| 138 |
|
} |
| 139 |
|
|
| 140 |
|
public void setModuleThread( ModuleThread thread) { |
| 141 |
1012 |
if (this.thread != null) { |
| 142 |
352 |
this.thread.removeListener( this); |
| 143 |
|
} |
| 144 |
|
|
| 145 |
1012 |
this.thread = thread; |
| 146 |
|
|
| 147 |
1012 |
if (thread != null) { |
| 148 |
440 |
setEnabled( false); |
| 149 |
440 |
thread.addListener( this); |
| 150 |
440 |
} else { |
| 151 |
572 |
setEnabled( true); |
| 152 |
572 |
thread = null; |
| 153 |
|
} |
| 154 |
1012 |
} |
| 155 |
|
|
| 156 |
|
public void threadFinished( ModuleThread thread) { |
| 157 |
440 |
setEnabled( true); |
| 158 |
440 |
thread.removeListener( this); |
| 159 |
440 |
thread = null; |
| 160 |
440 |
} |
| 161 |
|
|
| 162 |
|
public void threadStarted( ModuleThread thread) { |
| 163 |
440 |
setEnabled(false); |
| 164 |
440 |
} |
| 165 |
|
} |