KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > loader > wizard > OctopusLoaderFrame


1 package org.webdocwf.util.loader.wizard;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import javax.swing.*;
6 import javax.swing.event.*;
7 import javax.swing.border.*;
8 import java.io.*;
9 import java.util.*;
10
11 public class OctopusLoaderFrame
12     extends JInternalFrame {
13
14   private static final String JavaDoc LOG_MODE = " Log mode",
15       RESTART_INDICATOR = " Restart indicator",
16       USER_ID = " User Id",
17       VARIABLES = " Variables",
18       LOG_FILE_DIRECTORY = " Log file directory",
19       LOG_FILE_NAME = " Log file name",
20       VENDOR_CONF_FILE = " Specific vendor conf file",
21       ON_ERRORCONTINUE = " On error continue",
22       ADDITIONAL_CLASSPATH = " Aditional classpath",
23       COMMIT_COUNT = " Comit count",
24       RETURN_CODE = " Return code",
25       PATH_TO_XML_FILE = " Path to loaderJob.olj file",
26       INCLUDE_TABLES = " Include List",
27       PATH_TO_CONF_JAR = " Path to conf files in jar";
28
29   //dimensions
30
private static Dimension bigButton = new Dimension(110, 20);
31   private static Dimension smallComponent = new Dimension(150, 20);
32   private static Dimension bigComponent = new Dimension(400, 20);
33   private static Dimension veryBigComponent = new Dimension(650, 20);
34   private static Dimension veryBigPlusButton = new Dimension(630, 20);
35   private static Dimension panelComponenet = new Dimension(720, 40);
36
37   JSplitPane main;
38
39   Border loweredBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
40   Border raisedBorder = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
41   Border bevelBorder = BorderFactory.createLoweredBevelBorder();
42
43   private JDesktopPane desktop;
44   private JPanel commonPanel;
45   private OctopusLoaderData initData;
46   private HashMap fields;
47   private JTextArea traceArea;
48   private JTextField additionalPath;
49
50   public OctopusLoaderFrame(JDesktopPane desktop) {
51     super("Octopus Loader Application", true, true, true, true);
52     setFrameIcon( new ImageIcon(getClass().getClassLoader().getResource("org/webdocwf/util/loader/"+
53            "wizard/images/Enhydra16.gif")));
54
55     this.desktop = desktop;
56     fields = new HashMap();
57     //generatorOptions
58
JPanel loaderOptionsUp = new JPanel();
59     JPanel loaderOptionsDown = new JPanel();
60
61     //generator input data
62
JTabbedPane octopusLoaderData = new JTabbedPane();
63     commonPanel = new JPanel();
64     commonPanel.setLayout(new BoxLayout(commonPanel, BoxLayout.Y_AXIS));
65     octopusLoaderData.addTab("Input Parameters", commonPanel);
66
67     loaderOptionsUp.setLayout(new BoxLayout(loaderOptionsUp, BoxLayout.Y_AXIS));
68     loaderOptionsUp.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
69     JButton gotoOct = createOctopusButton("Generator", bigButton);
70     gotoOct.setAction(new StartOctopusGenerator());
71     JButton help = createOctopusButton("Help", bigButton);
72     help.setAction(new OctopusHelpAction());
73     loaderOptionsUp.add(gotoOct);
74     loaderOptionsUp.add(help);
75
76     //generatotOptionsDown panel
77
loaderOptionsDown.setLayout(new BoxLayout(loaderOptionsDown, BoxLayout.Y_AXIS));
78     loaderOptionsDown.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
79     JButton start = createOctopusButton("Start", bigButton);
80     start.setAction(new StartOctopusLoader());
81     JButton stop = createOctopusButton("Stop", bigButton);
82     stop.setAction(new StopOctopusLoader());
83     loaderOptionsDown.add(start);
84     loaderOptionsDown.add(stop);
85
86     //generatorOptions
87
JSplitPane generatorOptions = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true,
88         loaderOptionsUp, loaderOptionsDown);
89     generatorOptions.setOneTouchExpandable(true);
90     generatorOptions.setDividerLocation(360);
91
92     //log mode
93
JLabel strLogMode = createOctopusLabel(LOG_MODE, smallComponent);
94     JComboBox logMode = createOctopusCombobox(LOG_MODE, veryBigComponent);
95     //restart indicator
96
JLabel strRestartIndicator = createOctopusLabel(RESTART_INDICATOR, smallComponent);
97     JTextField restartIndicator = createOctopusTextField(RESTART_INDICATOR, veryBigComponent);
98     //user id
99
JLabel strUserId = createOctopusLabel(USER_ID, smallComponent);
100     JTextField userId = createOctopusTextField(USER_ID, veryBigComponent);
101     //variables
102
JLabel strVariables = createOctopusLabel(VARIABLES, smallComponent);
103     JTextField variables = createOctopusTextField(VARIABLES, veryBigComponent);
104     //log file directory
105
JLabel strLogFileDir = createOctopusLabel(LOG_FILE_DIRECTORY, smallComponent);
106     JTextField logFileDir = createOctopusTextField(LOG_FILE_DIRECTORY, veryBigPlusButton);
107     JButton logDirButton = createOctopusButton("", new Dimension(20, 20));
108     logDirButton.setAction(new BrowseAction_LD());
109     //log file name
110
JLabel strLogFileName = createOctopusLabel(LOG_FILE_NAME, smallComponent);
111     JTextField logFileName = createOctopusTextField(LOG_FILE_NAME, veryBigComponent);
112     //specific vendor conf file
113
JLabel strSpecVendorConf = createOctopusLabel(VENDOR_CONF_FILE, smallComponent);
114     JTextField specVendorConf = createOctopusTextField(VENDOR_CONF_FILE, veryBigPlusButton);
115     JButton specVendorButton = createOctopusButton("", new Dimension(20, 20));
116     specVendorButton.setAction(new BrowseAction_XML());
117     //on error continue
118
JLabel strOnError = createOctopusLabel(ON_ERRORCONTINUE, smallComponent);
119     JTextField onError = createOctopusTextField(ON_ERRORCONTINUE, veryBigComponent);
120     //additional classpaths
121
JLabel strAdditionalPath = createOctopusLabel(ADDITIONAL_CLASSPATH, smallComponent);
122     additionalPath = createOctopusTextField(ADDITIONAL_CLASSPATH, veryBigPlusButton);
123     JButton additionalPathButton = createOctopusButton("", new Dimension(20, 20));
124     additionalPathButton.setAction(new BrowseAction_AC());
125     //commit count
126
JLabel strCommitCount = createOctopusLabel(COMMIT_COUNT, smallComponent);
127     JTextField commitCount = createOctopusTextField(COMMIT_COUNT, veryBigComponent);
128     //return code
129
JLabel strReturnCode = createOctopusLabel(RETURN_CODE, smallComponent);
130     JTextField returnCode = createOctopusTextField(RETURN_CODE, veryBigComponent);
131     //pathe to olj file
132
JLabel strPathToOlj = createOctopusLabel(PATH_TO_XML_FILE, smallComponent);
133     JTextField pathToOlj = createOctopusTextField(PATH_TO_XML_FILE, veryBigPlusButton);
134     JButton pathToOljButton = createOctopusButton("", new Dimension(20, 20));
135     pathToOljButton.setAction(new BrowseAction_OLJ());
136     //include list
137
JLabel strIncludeList = createOctopusLabel(INCLUDE_TABLES, smallComponent);
138     JTextField includeList = createOctopusTextField(INCLUDE_TABLES, veryBigComponent);
139     //path to conf files in jar file
140
JLabel strPathToConf = createOctopusLabel(PATH_TO_CONF_JAR, smallComponent);
141     JTextField pathToConf = createOctopusTextField(PATH_TO_CONF_JAR, veryBigComponent);
142
143     JPanel inputParamPanelLabel = new JPanel();
144     inputParamPanelLabel.setLayout(new BoxLayout(inputParamPanelLabel, BoxLayout.Y_AXIS));
145     JPanel inputParamPanelField = new JPanel();
146     inputParamPanelField.setLayout(new BoxLayout(inputParamPanelField, BoxLayout.Y_AXIS));
147
148     commonPanel.add(Box.createRigidArea(new Dimension(0, 15)));
149     createRow(strLogMode, logMode, null);
150     fields.put(LOG_MODE, logMode);
151     createRow(strRestartIndicator, restartIndicator, null);
152     fields.put(RESTART_INDICATOR, restartIndicator);
153     createRow(strUserId, userId, null);
154     fields.put(USER_ID, userId);
155     createRow(strVariables, variables, null);
156     fields.put(VARIABLES, variables);
157     createRow(strLogFileDir, logFileDir, logDirButton);
158     fields.put(LOG_FILE_DIRECTORY, logFileDir);
159     createRow(strLogFileName, logFileName, null);
160     fields.put(LOG_FILE_NAME, logFileName);
161     createRow(strSpecVendorConf, specVendorConf, specVendorButton);
162     fields.put(VENDOR_CONF_FILE, specVendorConf);
163     createRow(strOnError, onError, null);
164     fields.put(ON_ERRORCONTINUE, onError);
165     createRow(strAdditionalPath, additionalPath, additionalPathButton);
166     fields.put(ADDITIONAL_CLASSPATH, additionalPath);
167     createRow(strCommitCount, commitCount, null);
168     fields.put(COMMIT_COUNT, commitCount);
169     createRow(strReturnCode, returnCode, null);
170     fields.put(RETURN_CODE, returnCode);
171     createRow(strPathToOlj, pathToOlj, pathToOljButton);
172     fields.put(PATH_TO_XML_FILE, pathToOlj);
173     createRow(strIncludeList, includeList, null);
174     fields.put(INCLUDE_TABLES, includeList);
175     createRow(strPathToConf, pathToConf, null);
176     fields.put(PATH_TO_CONF_JAR, pathToConf);
177
178     JSplitPane generatorInputData = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true,
179         generatorOptions, octopusLoaderData);
180
181     // output panel
182
JPanel textAreaPanel = new JPanel();
183     textAreaPanel.setLayout(new BoxLayout(textAreaPanel, BoxLayout.X_AXIS));
184     JPanel areaOptionPanel = new JPanel();
185     areaOptionPanel.setLayout(new BoxLayout(areaOptionPanel, BoxLayout.Y_AXIS));
186     traceArea = new JTextArea(18, 130);
187     traceArea.setLineWrap(true);
188     traceArea.setEditable(false);
189     traceArea.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
190     JScrollPane scrollPane = new JScrollPane(traceArea,
191         ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
192         ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
193
194     scrollPane.setBorder(setTitleOfBorder("Log Octopus Loader output ... ", loweredBorder));
195     JButton fullScreen = createOctopusButton("Full Screen", new Dimension(25, 25));
196     fullScreen.setAction(new FullScreenAction());
197     JButton normalScreen = createOctopusButton("Normal Screen", new Dimension(25, 25));
198     normalScreen.setAction(new NormalScreenAction());
199     JButton saveScreen = createOctopusButton("Save Trace", new Dimension(25, 25));
200     saveScreen.setAction(new SaveTraceAction());
201     JButton clearTrace = createOctopusButton("Clear Trace", new Dimension(25, 25));
202     clearTrace.setAction(new ClearTraceAction());
203
204     areaOptionPanel.add(fullScreen);
205     areaOptionPanel.add(normalScreen);
206     areaOptionPanel.add(saveScreen);
207     areaOptionPanel.add(clearTrace);
208     areaOptionPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
209
210     JPanel areaOptionMainPanel = new JPanel(new BorderLayout());
211     areaOptionMainPanel.add(areaOptionPanel, BorderLayout.PAGE_START);
212
213     textAreaPanel.add(areaOptionMainPanel);
214     textAreaPanel.add(scrollPane);
215     main = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, generatorInputData,
216         textAreaPanel);
217     main.setOneTouchExpandable(true);
218     main.setDividerLocation(450);
219
220     Container container = getContentPane();
221     container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS));
222     container.add(main);
223     setBounds(0, 0, 970, 480);
224   }
225
226   private void createRow(JLabel label, JComponent component, JButton button) {
227
228     JPanel jp = new JPanel();
229     jp.setLayout(new BoxLayout(jp, BoxLayout.X_AXIS));
230
231     jp.add(label);
232     jp.add(component);
233     if(button != null)
234       jp.add(button);
235     jp.add(Box.createHorizontalGlue());
236
237     commonPanel.add(jp);
238   }
239
240   private Border setTitleOfBorder(String JavaDoc title, Border border) {
241     Border inb = BorderFactory.createTitledBorder(border, title);
242     return inb;
243   }
244
245   private JButton createOctopusButton(String JavaDoc componentName, Dimension dimension) {
246
247     JButton button = new JButton();
248     if(!componentName.equalsIgnoreCase(""))
249       button.setText(componentName);
250
251     button.setAlignmentX(Component.LEFT_ALIGNMENT);
252     button.setAlignmentY(Component.CENTER_ALIGNMENT);
253     button.setMinimumSize(new Dimension(dimension));
254     button.setMaximumSize(new Dimension(dimension));
255     button.setPreferredSize(new Dimension(dimension));
256
257     return button;
258   }
259
260   private JComboBox createOctopusCombobox(String JavaDoc componentName, Dimension dimension) {
261
262     JComboBox comboBox = new JComboBox();
263     comboBox.setName(componentName);
264     comboBox.setAlignmentX(Component.LEFT_ALIGNMENT);
265     comboBox.setAlignmentY(Component.CENTER_ALIGNMENT);
266     comboBox.setMinimumSize(new Dimension(dimension));
267     comboBox.setMaximumSize(new Dimension(dimension));
268     comboBox.setPreferredSize(new Dimension(dimension));
269
270     return comboBox;
271   }
272
273   private JLabel createOctopusLabel(String JavaDoc componentName, Dimension dimension) {
274
275     JLabel label = new JLabel();
276     label.setText(componentName);
277     label.setAlignmentX(Component.LEFT_ALIGNMENT);
278     label.setAlignmentY(Component.CENTER_ALIGNMENT);
279     label.setMinimumSize(new Dimension(dimension));
280     label.setMaximumSize(new Dimension(dimension));
281     label.setPreferredSize(new Dimension(dimension));
282
283     return label;
284   }
285
286   private JTextField createOctopusTextField(String JavaDoc componentName, Dimension dimension) {
287
288     JTextField textField = new JTextField();
289     textField.setName(componentName);
290     textField.setAlignmentX(Component.LEFT_ALIGNMENT);
291     textField.setAlignmentY(Component.CENTER_ALIGNMENT);
292     textField.setMinimumSize(new Dimension(dimension));
293     textField.setMaximumSize(new Dimension(dimension));
294     textField.setPreferredSize(new Dimension(dimension));
295
296     return textField;
297   }
298
299   public void setOctopusLoaderInit(OctopusLoaderData initData, String JavaDoc xmlFile,
300       String JavaDoc confJarStructure) {
301     this.initData = initData;
302     setField(LOG_MODE, initData.getLogMode(), "box");
303     setField(LOG_FILE_DIRECTORY, initData.getLogFileDir(), "textfield");
304     setField(LOG_FILE_NAME, initData.getLogFileName(), "textfield");
305     setField(USER_ID, initData.getUserId(), "textfield");
306     setField(VARIABLES, initData.getVariables(), "textfield");
307     setField(RESTART_INDICATOR, initData.getRestartIndicator(), "textfield");
308     setField(VENDOR_CONF_FILE, initData.getVendorConf(), "textfield");
309     setField(ON_ERRORCONTINUE, initData.getOnErrorCon(), "textfield");
310     setField(ADDITIONAL_CLASSPATH, initData.getAdditionalPaths(), "textfield");
311     setField(COMMIT_COUNT, initData.getCommitCount(), "textfield");
312     setField(RETURN_CODE, initData.getReturnCode(), "textfield");
313     if(xmlFile != null)
314 //Zeljko Kovacevic,6.4 2004 change next line
315
//ORIGINAL setField(PATH_TO_XML_FILE, confJarStructure, "textfield");
316
setField(PATH_TO_XML_FILE, xmlFile, "textfield");
317     else
318       setField(PATH_TO_XML_FILE, initData.getPathToXml(), "textfield");
319
320     setField(INCLUDE_TABLES, initData.getIncludeTables(), "textfield");
321     if(confJarStructure != null)
322       setField(PATH_TO_CONF_JAR, confJarStructure, "textfield");
323     else
324       setField(PATH_TO_CONF_JAR, initData.getConfJarStructure(), "textfield");
325   }
326
327   public OctopusLoaderData getOctopusLoaderInit() throws Exception JavaDoc {
328
329     initData.setLogMode(getField(LOG_MODE, "box"));
330     initData.setLogFileName(getField(LOG_FILE_NAME, "label"));
331     initData.setLogFileDir(getField(LOG_FILE_DIRECTORY, "label"));
332     initData.setRestartIndicator(getField(RESTART_INDICATOR, "label"));
333     initData.setUserId(getField(USER_ID, "label"));
334     initData.setVariables(getField(VARIABLES, "label"));
335     initData.setVendorConf(getField(VENDOR_CONF_FILE, "label"));
336     initData.setOnErrorCon(getField(ON_ERRORCONTINUE, "label"));
337     initData.setAdditionalPaths(getField(ADDITIONAL_CLASSPATH, "label"));
338     initData.setCommitCount(getField(COMMIT_COUNT, "label"));
339     initData.setReturnCode(getField(RETURN_CODE, "label"));
340     initData.setPathToXml(getField(PATH_TO_XML_FILE, "label"));
341     initData.setIncludeTables(getField(INCLUDE_TABLES, "label"));
342     initData.setConfJarStructure(getField(PATH_TO_CONF_JAR, "label"));
343
344     return initData;
345   }
346
347   private void setField(String JavaDoc fieldName, String JavaDoc value, String JavaDoc type) {
348     if(type.equalsIgnoreCase("textfield")) {
349       JTextField field = (JTextField)fields.get(fieldName);
350       field.setText(value);
351     } else {
352       JComboBox field = (JComboBox)fields.get(fieldName);
353       for(int i = 0; i < OctopusLoaderData.getLogModes().length; i++) {
354         field.addItem(OctopusLoaderData.getLogModes()[i]);
355       }
356     }
357   }
358
359   private String JavaDoc getField(String JavaDoc fieldName, String JavaDoc type) {
360     if(type.equalsIgnoreCase("label")) {
361       JTextField field = (JTextField)fields.get(fieldName);
362       return field.getText().trim();
363     } else {
364       JComboBox field = (JComboBox)fields.get(fieldName);
365       return field.getSelectedItem().toString();
366     }
367   }
368
369   private class FullScreenAction
370       extends AbstractAction {
371
372     /**
373      * This method starts the LoaderGenerator application
374      */

375     public FullScreenAction() {
376
377       putValue(SMALL_ICON,
378           new ImageIcon(getClass().getClassLoader().getResource("org/webdocwf/util/loader/" +
379           "wizard/images/Host16.gif")));
380       putValue(SHORT_DESCRIPTION, "Full Screen");
381       putValue(LONG_DESCRIPTION, "Set Trace to Full Screen");
382       putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('F',
383           Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
384       putValue(MNEMONIC_KEY, new Integer JavaDoc('F'));
385     }
386
387     /**
388      * This method check if the action is performed (event key pressed)
389      * @param e is event
390      */

391     public void actionPerformed(ActionEvent e) {
392       main.setDividerLocation(0);
393     }
394   }
395
396   private class NormalScreenAction
397       extends AbstractAction {
398
399     /**
400      * This method starts the LoaderGenerator application
401      */

402     public NormalScreenAction() {
403
404       putValue(SMALL_ICON,
405           new ImageIcon(getClass().getClassLoader().getResource("org/webdocwf/util/loader/" +
406           "wizard/images/Unhost16.gif")));
407       putValue(SHORT_DESCRIPTION, "Normal Screen");
408       putValue(LONG_DESCRIPTION, "Back to normal screen");
409       putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('N',
410           Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
411       putValue(MNEMONIC_KEY, new Integer JavaDoc('N'));
412     }
413
414     /**
415      * This method check if the action is performed (event key pressed)
416      * @param e is event
417      */

418     public void actionPerformed(ActionEvent e) {
419       main.setDividerLocation(330);
420     }
421   }
422
423   private class SaveTraceAction
424       extends AbstractAction {
425
426     /**
427      * This method starts the LoaderGenerator application
428      */

429     public SaveTraceAction() {
430
431       putValue(SMALL_ICON,
432           new ImageIcon(getClass().getClassLoader().getResource("org/webdocwf/util/loader/" +
433           "wizard/images/Save16.gif")));
434       putValue(SHORT_DESCRIPTION, "Save Trace");
435       putValue(LONG_DESCRIPTION, "Save Trace to file");
436       putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('S',
437           Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
438       putValue(MNEMONIC_KEY, new Integer JavaDoc('S'));
439     }
440
441     /**
442      * This method check if the action is performed (event key pressed)
443      * @param e is event
444      */

445     public void actionPerformed(ActionEvent e) {
446       JFileChooser fc = new JFileChooser();
447       fc.setDialogTitle("Save Octopus log ...");
448       int returnVal = fc.showSaveDialog(null);
449       if(returnVal == JFileChooser.APPROVE_OPTION) {
450         File file = fc.getSelectedFile();
451         String JavaDoc text = traceArea.getText();
452         try {
453           Writer out = new BufferedWriter(new FileWriter(file, false));
454           out.write(text);
455           out.close();
456         }
457         catch(Exception JavaDoc ex) {
458           ex.printStackTrace();
459         }
460
461       } else {
462       //do nothing
463
}
464     }
465   }
466
467   private class ClearTraceAction
468       extends AbstractAction {
469
470     /**
471      * This method starts the LoaderGenerator application
472      */

473     public ClearTraceAction() {
474
475       putValue(SMALL_ICON,
476           new ImageIcon(getClass().getClassLoader().getResource("org/webdocwf/util/loader/" +
477           "wizard/images/Delete16.gif")));
478       putValue(SHORT_DESCRIPTION, "Clear Trace");
479       putValue(LONG_DESCRIPTION, "Clear Trace");
480       putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('L',
481           Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
482       putValue(MNEMONIC_KEY, new Integer JavaDoc('L'));
483     }
484
485     /**
486      * This method check if the action is performed (event key pressed)
487      * @param e is event
488      */

489     public void actionPerformed(ActionEvent e) {
490       traceArea.setText("");
491     }
492   }
493
494   //additional paths
495
private class BrowseAction_AC
496       extends AbstractAction {
497
498     /**
499      * This method stop the LoaderGenerator application
500      */

501     public BrowseAction_AC() {
502       putValue(SMALL_ICON,
503           new ImageIcon(getClass().getClassLoader().
504           getResource("org/webdocwf/util/loader/" +
505           "wizard/images/Open16.gif")));
506       putValue(SHORT_DESCRIPTION, "Add .jar files");
507       putValue(LONG_DESCRIPTION, "Add .jar (jdbc) files to system classpath");
508       putValue(MNEMONIC_KEY, new Integer JavaDoc('B'));
509     }
510
511     /**
512      * This method check if the action is performed (event key pressed)
513      * @param e is event
514      */

515     public void actionPerformed(ActionEvent e) {
516       JFileChooser chooser = null;
517       File choice = null;
518       File current = new File(System.getProperty("user.dir"));
519       chooser = new JFileChooser(current);
520       chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
521       chooser.setFileFilter((javax.swing.filechooser.FileFilter JavaDoc)new JarFilter());
522       chooser.setDialogTitle("Select .jar file");
523       chooser.setAcceptAllFileFilterUsed(false);
524       String JavaDoc strFieldText = additionalPath.getText();
525 //
526
if(!strFieldText.equalsIgnoreCase(""))
527         strFieldText = strFieldText + ";";
528
529       chooser.setCurrentDirectory(new File(strFieldText));
530       chooser.setApproveButtonText("OK");
531       int v = chooser.showOpenDialog(desktop);
532
533       desktop.requestFocus();
534       switch(v) {
535         case JFileChooser.APPROVE_OPTION:
536           if(chooser.getSelectedFile() != null) {
537             if(chooser.getSelectedFile().exists()) {
538               choice = chooser.getSelectedFile();
539             } else {
540               File parentFile = new File(chooser.getSelectedFile().getParent());
541               choice = parentFile;
542             }
543             additionalPath.setText(strFieldText + choice.getPath());
544           }
545           break;
546
547         case JFileChooser.CANCEL_OPTION:
548         case JFileChooser.ERROR_OPTION:
549
550           chooser.removeAll();
551           chooser = null;
552           current = null;
553
554       }
555     }
556   }
557
558   private class StartOctopusGenerator
559       extends AbstractAction {
560
561     /**
562      * This method starts the LoaderGenerator application
563      */

564     public StartOctopusGenerator() {
565
566       putValue(NAME, "Generator");
567       putValue(SMALL_ICON,
568           new ImageIcon(getClass().getClassLoader().getResource("org/webdocwf/util/loader/" +
569           "wizard/images/Goto16.gif")));
570       putValue(SHORT_DESCRIPTION, "Start the OctopusGenerator application");
571       putValue(LONG_DESCRIPTION, "Start the OctopusGenerator application");
572 // putValue(ACCELERATOR_KEY,KeyStroke.getKeyStroke('G',Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
573
// putValue(MNEMONIC_KEY, new Integer('G'));
574
}
575
576     /**
577      * This method check if the action is performed (event key pressed)
578      * @param e is event
579      */

580     public void actionPerformed(ActionEvent e) {
581       OctopusGeneratorFrame octopusGenerator = new OctopusGeneratorFrame(desktop);
582       setDefaultCloseOperation(DISPOSE_ON_CLOSE);
583       String JavaDoc confJarStructure = "";
584       try {
585         octopusGenerator.setOctopusGeneratorInit(new OctopusGeneratorData(confJarStructure),
586             confJarStructure);
587       }
588       catch(Exception JavaDoc ex) {
589         String JavaDoc message = ex.getMessage();
590         String JavaDoc message2 = "Check the OCTOPUS_HOME variable!";
591         JOptionPane error = new JOptionPane();
592         error.showMessageDialog(desktop, message + "\n" + message2, "Error", 0);
593         error.setVisible(true);
594         System.exit(0);
595       }
596       desktop.add(octopusGenerator);
597       octopusGenerator.setVisible(true);
598       //kill the instance of generator
599
dispose();
600     }
601   }
602
603   private class StopOctopusLoader
604       extends AbstractAction {
605
606     /**
607      * This method stop the LoaderGenerator application
608      */

609     public StopOctopusLoader() {
610
611       putValue(NAME, "Close");
612       putValue(SMALL_ICON,
613           new ImageIcon(getClass().getClassLoader().getResource("org/webdocwf/util/loader/" +
614           "wizard/images/Stop16.gif")));
615       putValue(SHORT_DESCRIPTION, "Stop the OctopusGenerator application");
616       putValue(LONG_DESCRIPTION, "Stop the OctopusGenerator application");
617       putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('T',
618           Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
619       putValue(MNEMONIC_KEY, new Integer JavaDoc('T'));
620     }
621
622     /**
623      * This method check if the action is performed (event key pressed)
624      * @param e is event
625      */

626     public void actionPerformed(ActionEvent e) {
627       dispose();
628
629     }
630   }
631
632   private class OctopusHelpAction
633       extends AbstractAction {
634
635     /**
636      * Action which creates new help frame
637      */

638     public OctopusHelpAction() {
639       putValue(NAME, "Help");
640       putValue(SMALL_ICON,
641           new ImageIcon(getClass().getClassLoader().getResource("org/webdocwf/util/loader/" +
642           "wizard/images/Help16.gif")));
643       putValue(SHORT_DESCRIPTION, "Help for running the program");
644       putValue(LONG_DESCRIPTION, "Help for running the program");
645       putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('H',
646           Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
647       putValue(MNEMONIC_KEY, new Integer JavaDoc('H'));
648     }
649
650     /**
651      * Creating event for new windows help frame
652      * @param e is creating events
653      */

654     public void actionPerformed(ActionEvent e) {
655       try {
656         OctopusGeneratorHelpFrame helpFrame = new OctopusGeneratorHelpFrame();
657         helpFrame.setIconImage(new ImageIcon(getClass().getClassLoader().getResource(
658             "org/webdocwf/util/loader/" +
659             "wizard/images/Enhydra16.gif")).getImage());
660         helpFrame.setVisible(true);
661       }
662       catch(Exception JavaDoc ex) {
663         String JavaDoc message = ex.getMessage();
664         String JavaDoc message2 = "Check the OCTOPUS_HOME variable!";
665         JOptionPane error = new JOptionPane();
666         error.showMessageDialog(desktop, message + "\n" + message2, "Error", 0);
667         error.setVisible(true);
668         System.exit(0);
669       }
670     }
671   }
672
673   private class StartOctopusLoader
674       extends AbstractAction {
675
676     /**
677      * This method starts the LoaderGenerator application
678      */

679     public StartOctopusLoader() {
680
681       putValue(NAME, "Start");
682       putValue(SMALL_ICON,
683           new ImageIcon(getClass().getClassLoader().getResource("org/webdocwf/util/loader/" +
684           "wizard/images/Play16.gif")));
685       putValue(SHORT_DESCRIPTION, "Start the OctopusLoader application");
686       putValue(LONG_DESCRIPTION, "Start the OctopusLoader application");
687       putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('R',
688           Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
689       putValue(MNEMONIC_KEY, new Integer JavaDoc('R'));
690     }
691
692     /**
693      * This method check if the action is performed (event key pressed)
694      * @param e is event
695      */

696     public void actionPerformed(ActionEvent e) {
697       OctopusLoaderData initData = null;
698       main.setDividerLocation(330);
699       String JavaDoc errorMsg = null;
700       try {
701         initData = getOctopusLoaderInit();
702       }
703       catch(Exception JavaDoc ex) {
704         errorMsg = ex.getMessage();
705       }
706       traceArea.setText("");
707       OctopusLoaderThread runOctopus = new OctopusLoaderThread(desktop,
708           initData,
709           errorMsg, traceArea);
710       runOctopus.start();
711     }
712   }
713
714   //log dir
715
private class BrowseAction_LD
716       extends AbstractAction {
717
718     /**
719      * This method stop the LoaderGenerator application
720      */

721     public BrowseAction_LD() {
722 // putValue(NAME, "browse");
723
putValue(SMALL_ICON,
724           new ImageIcon(getClass().getClassLoader().
725           getResource("org/webdocwf/util/loader/" +
726           "wizard/images/Open16.gif")));
727       putValue(SHORT_DESCRIPTION, "Browse for Log file directory");
728       putValue(LONG_DESCRIPTION, "Browse for Log file directory");
729       putValue(MNEMONIC_KEY, new Integer JavaDoc('B'));
730     }
731
732     /**
733      * This method check if the action is performed (event key pressed)
734      * @param e is event
735      */

736     public void actionPerformed(ActionEvent e) {
737       JFileChooser chooser = null;
738       File choice = null;
739       File current = new File(System.getProperty("user.dir"));
740       chooser = new JFileChooser(current);
741       chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
742       chooser.setFileFilter((javax.swing.filechooser.FileFilter JavaDoc)new DirectoryFilter());
743       chooser.setDialogTitle("Select Log File Directory");
744       chooser.setApproveButtonText("OK");
745       String JavaDoc strFieldText = "";
746
747       chooser.setCurrentDirectory(new File(strFieldText));
748       int v = chooser.showOpenDialog(desktop);
749       desktop.requestFocus();
750
751       switch(v) {
752         case JFileChooser.APPROVE_OPTION:
753           if(chooser.getSelectedFile() != null) {
754             if(chooser.getSelectedFile().exists()) {
755               choice = chooser.getSelectedFile();
756             } else {
757               File parentFile = new File(chooser.getSelectedFile().getParent());
758               choice = parentFile;
759             }
760             setField(LOG_FILE_DIRECTORY, choice.getPath(), "textfield");
761           }
762           break;
763
764         case JFileChooser.CANCEL_OPTION:
765         case JFileChooser.ERROR_OPTION:
766
767       }
768     }
769   }
770
771   private class BrowseAction_XML
772       extends AbstractAction {
773
774     /**
775      * This method stop the LoaderGenerator application
776      */

777     public BrowseAction_XML() {
778 // putValue(NAME, "browse");
779
putValue(SMALL_ICON,
780           new ImageIcon(getClass().getClassLoader().
781           getResource("org/webdocwf/util/loader/" +
782           "wizard/images/Open16.gif")));
783       putValue(SHORT_DESCRIPTION, "Browse for .xml file");
784       putValue(LONG_DESCRIPTION, "Browse for .xml file");
785       putValue(MNEMONIC_KEY, new Integer JavaDoc('B'));
786     }
787
788     /**
789      * This method check if the action is performed (event key pressed)
790      * @param e is event
791      */

792     public void actionPerformed(ActionEvent e) {
793       JFileChooser chooser = null;
794       File choice = null;
795       File current = new File(System.getProperty("user.dir"));
796       chooser = new JFileChooser(current);
797       chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
798       chooser.setFileFilter((javax.swing.filechooser.FileFilter JavaDoc)new XmlFilter());
799       chooser.setDialogTitle("Select .xml file");
800       chooser.setAcceptAllFileFilterUsed(false);
801       String JavaDoc strFieldText = "";
802
803       chooser.setCurrentDirectory(new File(strFieldText));
804       chooser.setApproveButtonText("OK");
805       int v = chooser.showOpenDialog(desktop);
806
807       desktop.requestFocus();
808       switch(v) {
809         case JFileChooser.APPROVE_OPTION:
810           if(chooser.getSelectedFile() != null) {
811             if(chooser.getSelectedFile().exists()) {
812               choice = chooser.getSelectedFile();
813             } else {
814               File parentFile = new File(chooser.getSelectedFile().getParent());
815               choice = parentFile;
816             }
817             setField(VENDOR_CONF_FILE, choice.getPath(), "textfield");
818           }
819           break;
820
821         case JFileChooser.CANCEL_OPTION:
822         case JFileChooser.ERROR_OPTION:
823
824           chooser.removeAll();
825           chooser = null;
826           current = null;
827       }
828     }
829   }
830
831   private class BrowseAction_OLJ
832       extends AbstractAction {
833
834     /**
835      * This method stop the LoaderGenerator application
836      */

837     public BrowseAction_OLJ() {
838 // putValue(NAME, "browse");
839
putValue(SMALL_ICON,
840           new ImageIcon(getClass().getClassLoader().
841           getResource("org/webdocwf/util/loader/" +
842           "wizard/images/Open16.gif")));
843       putValue(SHORT_DESCRIPTION, "Browse for LoaderJob.olj file");
844       putValue(LONG_DESCRIPTION, "Browse for LoaderJob.olj file");
845       putValue(MNEMONIC_KEY, new Integer JavaDoc('B'));
846     }
847
848     /**
849      * This method check if the action is performed (event key pressed)
850      * @param e is event
851      */

852     public void actionPerformed(ActionEvent e) {
853       JFileChooser chooser = null;
854       File choice = null;
855       File current = new File(System.getProperty("user.dir"));
856       chooser = new JFileChooser(current);
857       chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
858       chooser.setFileFilter((javax.swing.filechooser.FileFilter JavaDoc)new OljFilter());
859       chooser.setDialogTitle("Select .olj file");
860       chooser.setAcceptAllFileFilterUsed(false);
861       String JavaDoc strFieldText = "";
862
863       chooser.setCurrentDirectory(new File(strFieldText));
864       chooser.setApproveButtonText("OK");
865       int v = chooser.showOpenDialog(desktop);
866
867       desktop.requestFocus();
868       switch(v) {
869         case JFileChooser.APPROVE_OPTION:
870           if(chooser.getSelectedFile() != null) {
871             if(chooser.getSelectedFile().exists()) {
872               choice = chooser.getSelectedFile();
873             } else {
874               File parentFile = new File(chooser.getSelectedFile().getParent());
875               choice = parentFile;
876             }
877             setField(PATH_TO_XML_FILE, choice.getPath(), "textfield");
878           }
879           break;
880
881         case JFileChooser.CANCEL_OPTION:
882         case JFileChooser.ERROR_OPTION:
883
884           chooser.removeAll();
885           chooser = null;
886           current = null;
887
888       }
889     }
890   }
891
892 }
Popular Tags