source: branches/ant-install-branch/gsdl3/src/java/org/greenstone/admin/gui/ConfPane.java@ 9972

Last change on this file since 9972 was 9972, checked in by chi, 19 years ago

The initial version of GAI applications.

  • Property svn:keywords set to Author Date Id Revision
File size: 33.5 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the GAI application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: Chi-Yu Huang, Greenstone Digital Library, University of Waikato
11 * Modified: 03.2005
12 *
13 * <BR><BR>
14 *
15 * Copyright (C) 1999 New Zealand Digital Library Project
16 *
17 * <BR><BR>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * <BR><BR>
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * <BR><BR>
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 *########################################################################
37 */
38package org.greenstone.admin.gui;
39
40import java.awt.*;
41import java.awt.event.*;
42import java.io.*;
43import java.util.List;
44import java.util.ArrayList;
45import java.lang.Object;
46import javax.swing.*;
47import javax.swing.event.*;
48import javax.swing.tree.*;
49import javax.swing.table.*;
50import java.awt.event.MouseEvent;
51import java.net.*;
52import java.sql.*;
53
54import org.greenstone.admin.GAI;
55import org.greenstone.admin.GAIManager;
56import org.greenstone.admin.gui.ThreadControl;
57import org.greenstone.core.Configuration;
58import org.greenstone.core.Dictionary;
59import org.greenstone.core.util.Utility;
60import org.greenstone.core.ParsingProgress;
61
62/** The Configuration pane is to view the status of relevant configure files in GSIII
63 * @author Chi-Yu Huang, Greenstone Digital Library, University of Waikato
64 * @version
65 */
66public class ConfPane
67 extends JPanel
68 implements ActionListener {
69
70 /* The pane to demonstrate Configuration information, including the build property file
71 * being monitored and their content, and control functions */
72 protected JSplitPane main_conf_pane = null;
73
74 protected JPanel main_contentPane = null;
75
76 /** The panel that contains a Conf_list */
77 private JPanel confList_pane = null;
78
79 /** The panel that contains the conf content. */
80 private JPanel confContent_pane = null;
81 private JScrollPane conf_table_pane = null;
82
83 /** The List showing all the Configuration files concerned. */
84 private JList conf_list=null;
85 private JTree conf_tree = null;
86
87 /** The pane area into which the Configuration content is placed. */
88 //private JScrollPane conf_content = null;
89
90 /** The label at the top of the confList_pane. */
91 private JLabel confList_label = null;
92 /** The label shown at the top of the confContent Pane. */
93 private JLabel confContent_label = null;
94
95 // The control buttons used to manipulate Configuration Pane
96 protected JPanel outter_button_pane = null;
97 protected JPanel outter_control_pane = null;
98 protected JPanel inner_button_pane = null;
99 protected JPanel inner_control_pane = null;
100 protected JPanel tomcat_button_pane = null;
101 protected JPanel mysql_button_pane = null;
102 protected JPanel setting_shown_pane = null;
103
104 /**Buttons in inner button pane */
105 private JButton startup_tomcat_button = null;
106 private JButton shutdown_tomcat_button = null;
107 private JButton restart_tomcat_button = null;
108 private JButton startup_mysql_button = null;
109 private JButton shutdown_mysql_button = null;
110 private JButton restart_mysql_button = null;
111
112 private JButton save_button = null;
113
114 /** Buttons in outter button pane*/
115 //private JButton reload_button = null;
116 //private JButton delete_button = null;
117 //private JButton exit_button = null;
118
119 private JLabel conf_label = null;
120 private JLabel conf_setting_label = null;
121 private JTextField conf_field = null;
122
123 //control tomcat and mysql server running status
124 private String tomcat_server;
125 private String tomcat_port;
126 private String mysql_adminuser;
127 private String mysql_server;
128 private String mysql_port;
129 private boolean tomcat_server_up = false;
130 private boolean mysql_server_up = false;
131
132 protected JTextArea text_area = null;
133
134 /** The various sizes for the screen layout*/
135 static private Dimension MIN_SIZE = new Dimension( 90, 90);
136 static private Dimension LIST_SIZE = new Dimension(200, 450);
137 static private Dimension CONTENT_SIZE = new Dimension (600,450);
138 static private Dimension TABLE_SIZE = new Dimension(500,200);
139
140 private JTable conf_setting_table = null;
141
142 private int num_of_setting;
143 private int num_of_change = 0;
144
145 //The details display in the table
146 int rowLength = 20;
147 int colLength = 3;
148 private Object[][] conf_display = new Object [rowLength][colLength];
149 private Object[][] conf_setting;
150
151 //An array to store all the details in the build.properties file
152 private ArrayList conf_array;
153
154 // all the relevant details from the build.properties
155 private static boolean valueChanged =false;
156
157 ConfTableModel conf_table_model;
158 DefaultMutableTreeNode top = new DefaultMutableTreeNode("Configuration Files");
159
160 //Constructor
161 public ConfPane() {
162 // create all the control button panes
163 inner_control_pane = new JPanel();
164 inner_button_pane = new JPanel();
165 tomcat_button_pane = new JPanel();
166 mysql_button_pane = new JPanel();
167 outter_control_pane = new JPanel();
168 outter_button_pane = new JPanel();
169
170 // Main Configuration Pane
171 main_conf_pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
172
173 // Main pane for Configuration Content Pane
174 main_contentPane = new JPanel();
175
176 //Create a tree for a list Configuration files we are interested
177 DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Build");
178 DefaultMutableTreeNode compile = new DefaultMutableTreeNode("Compile");
179 DefaultMutableTreeNode tomcat = new DefaultMutableTreeNode("Tomcat");
180 DefaultMutableTreeNode proxy = new DefaultMutableTreeNode("Proxy");
181 DefaultMutableTreeNode mysql = new DefaultMutableTreeNode("Mysql");
182 DefaultMutableTreeNode gsdl = new DefaultMutableTreeNode("GSDL");
183 child1.add(compile);
184 child1.add(tomcat);
185 child1.add(proxy);
186 child1.add(mysql);
187 child1.add(gsdl);
188
189 DefaultMutableTreeNode child2 =
190 new DefaultMutableTreeNode("Conf 2");
191 DefaultMutableTreeNode child3 =
192 new DefaultMutableTreeNode("Conf 3");
193 top.add(child1);
194 top.add(child2);
195 top.add(child3);
196 conf_tree = new JTree(top);
197 conf_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
198 conf_tree.addTreeSelectionListener(new ConfTreeListener());
199
200 // inner button_pane Buttons
201 StartupTomcatButtonListener stbl = new StartupTomcatButtonListener();
202 ShutdownTomcatButtonListener stdbl = new ShutdownTomcatButtonListener();
203 RestartTomcatButtonListener rtbl = new RestartTomcatButtonListener();
204
205 StartupMysqlButtonListener smbl = new StartupMysqlButtonListener();
206 ShutdownMysqlButtonListener smdbl = new ShutdownMysqlButtonListener();
207 RestartMysqlButtonListener rmbl = new RestartMysqlButtonListener();
208
209 //save button
210 SaveButtonListener sabl = new SaveButtonListener();
211
212 //outter button_pane Buttons
213 //ReloadButtonListener rbl = new ReloadButtonListener();
214 //DeleteButtonListener dbl = new DeleteButtonListener();
215 //ExitButtonListener ebl = new ExitButtonListener();
216 //ImageIcon reloadButtonIcon = new ImageIcon(GAI.admin_path + "images/toolbarButtonGraphics/general/Refresh16.gif");
217 //ImageIcon deleteButtonIcon = new ImageIcon(GAI.admin_path + "images/toolbarButtonGraphics/general/Delete16.gif");
218 //ImageIcon exitButtonIcon = new ImageIcon(GAI.admin_path + "images/toolbarButtonGraphics/general/exit16.gif");
219
220 ImageIcon startupTomcatButtonIcon = new ImageIcon(GAI.admin_path + "images/toolbarButtonGraphics/general/redo16.gif");
221 ImageIcon shutdownTomcatButtonIcon = new ImageIcon(GAI.admin_path + "images/toolbarButtonGraphics/general/stop16.gif");
222 ImageIcon restartTomcatButtonIcon = new ImageIcon(GAI.admin_path + "images/toolbarButtonGraphics/general/stop16.gif");
223
224 ImageIcon startupMysqlButtonIcon = new ImageIcon(GAI.admin_path + "images/toolbarButtonGraphics/general/redo16.gif");
225 ImageIcon shutdownMysqlButtonIcon = new ImageIcon(GAI.admin_path + "images/toolbarButtonGraphics/general/stop16.gif");
226 ImageIcon restartMysqlButtonIcon = new ImageIcon(GAI.admin_path + "images/toolbarButtonGraphics/general/stop16.gif");
227 ImageIcon saveButtonIcon = new ImageIcon(GAI.admin_path + "images/toolbarButtonGraphics/general/Save16.gif");
228
229 startup_tomcat_button = new JButton("Startup Tomcat", startupTomcatButtonIcon);
230 startup_tomcat_button.addActionListener(stbl);
231 startup_tomcat_button.setMnemonic(KeyEvent.VK_S);
232 startup_tomcat_button.setToolTipText("Click this button to startup the Tomcat server");
233 startup_tomcat_button.setEnabled(false);
234
235 shutdown_tomcat_button = new JButton("Shutdown Tomcat", shutdownTomcatButtonIcon);
236 shutdown_tomcat_button.addActionListener(stdbl);
237 shutdown_tomcat_button.setEnabled(false);
238 //shutdown_button.setMnemonic(KeyEvent.VK_h);
239 shutdown_tomcat_button.setToolTipText("Click this button to shutdown the Tomcat server");
240
241 restart_tomcat_button = new JButton("Restart Tomcat",restartTomcatButtonIcon);
242 restart_tomcat_button.addActionListener(rtbl);
243 restart_tomcat_button.setEnabled(false);
244 //shutdown_button.setMnemonic(KeyEvent.VK_h);
245 restart_tomcat_button.setToolTipText("Click this button to restart the Tomcat server(which will shutdown Tomcat server and restart it again");
246
247 startup_mysql_button = new JButton("Startup MYSQL", startupMysqlButtonIcon);
248 startup_mysql_button.addActionListener(smbl);
249 startup_mysql_button.setMnemonic(KeyEvent.VK_S);
250 startup_mysql_button.setToolTipText("Click this button to startup the MYSQL server");
251 startup_mysql_button.setEnabled(false);
252
253 shutdown_mysql_button = new JButton("Shutdown MYSQL", shutdownMysqlButtonIcon);
254 shutdown_mysql_button.addActionListener(smdbl);
255 shutdown_mysql_button.setEnabled(false);
256 //shutdown_button.setMnemonic(KeyEvent.VK_h);
257 shutdown_mysql_button.setToolTipText("Click this button to shutdown the MYSQL server");
258
259 restart_mysql_button = new JButton("Restart MYSQL",restartMysqlButtonIcon);
260 restart_mysql_button.addActionListener(rmbl);
261 restart_mysql_button.setEnabled(false);
262 //shutdown_button.setMnemonic(KeyEvent.VK_h);
263 restart_tomcat_button.setToolTipText("Click this button to restart the MYSQL server(which will shutdown MYSQL server and restart it again");
264
265 save_button = new JButton("Save Change", saveButtonIcon);
266 save_button.addActionListener(sabl);
267 //save_button.setMnemonic(KeyEvent.VK_a);
268 save_button.setEnabled(false);
269 save_button.setToolTipText("Click this button to save the change of build property file");
270
271 /*reload_button = new JButton("Reload", reloadButtonIcon);
272 reload_button.addActionListener(rbl);
273 reload_button.setMnemonic(KeyEvent.VK_R);
274 reload_button.setToolTipText("Click this button to reload the build properties file");*/
275 //Dictionary.registerBoth(build_button, "CreatePane.Build_Collection", "CreatePane.Build_Collection_Tooltip");
276
277 /*delete_button = new JButton("Delete", deleteButtonIcon);
278 delete_button.addActionListener(dbl);
279 delete_button.setEnabled(false);
280 delete_button.setMnemonic(KeyEvent.VK_D);
281 delete_button.setToolTipText("Click this button to delete the Configuration file");*/
282 //Dictionary.registerBoth(cancel_button, "CreatePane.Cancel_Build", "CreatePane.Cancel_Build_Tooltip");*/
283
284 /*exit_button = new JButton("Exit", exitButtonIcon);
285 exit_button.setToolTipText("Click this button to exit the viewing");
286 exit_button.addActionListener(ebl);
287 exit_button.setEnabled(true);
288 exit_button.setMnemonic(KeyEvent.VK_E);*/
289
290 //tomcat buttons
291 stbl = null;
292 stdbl = null;
293 rtbl = null;
294
295 //restart mysql button
296 smbl = null;
297 smdbl = null;
298 rmbl = null;
299
300 //rbl = null;
301 //dbl = null;
302 //ebl = null;
303
304 //read in build properties
305 getConfContent();
306 }
307
308 /** Any implementation of ActionListener requires this method so that when an
309 **action is performed the appropriate effect can occur.*/
310
311 public void actionPerformed(ActionEvent event) {
312 }
313
314 /** This method is callsed to actually layout the components.*/
315 public void display() {
316 //Create Components.
317 //KeyListenerImpl key_listener = new KeyListenerImpl();
318 //MouseListenerImpl mouse_listener = new MouseListenerImpl();
319 //this.addKeyListener(key_listener);
320
321 // confList_Pane
322 confList_pane = new JPanel();
323 confList_pane.setBorder(BorderFactory.createLoweredBevelBorder());
324 confList_pane.setPreferredSize(LIST_SIZE);
325 confList_pane.setSize(LIST_SIZE);
326 confList_label = new JLabel("Configuration Files");
327 confList_label.setOpaque(true);
328 confList_label.setBackground(Configuration.getColor("coloring.workspace_heading_background", false));
329 confList_label.setForeground(Configuration.getColor("coloring.workspace_heading_foreground", false));
330 //Dictionary.registerText(logList_label, "Log.List");
331
332 // confContent_Pane
333 confContent_pane = new JPanel();
334 //confContent_pane.setBorder(BorderFactory.createLoweredBevelBorder());
335 confContent_pane.setBorder(BorderFactory.createEmptyBorder(10,20,10,20));
336 confContent_pane.setBackground(Configuration.getColor("coloring.workspace_selection_background", false));
337 confContent_pane.setForeground(Configuration.getColor("coloring.workspace_selection_foreground", false));
338
339 confContent_label = new JLabel("Configuration Content");
340 confContent_label.setOpaque(true);
341 confContent_label.setBackground(Configuration.getColor("coloring.workspace_heading_background", false));
342 confContent_label.setForeground(Configuration.getColor("coloring.workspace_heading_foreground", false));
343 //Dictionary.registerText(logContent_label, "Log.Content");
344
345 conf_table_model = new ConfTableModel();
346 conf_setting_table = new JTable(conf_table_model){
347 public String getToolTipText(MouseEvent e){
348 String tip = null;
349 Point p = e.getPoint();
350 int rowIndex = rowAtPoint(p);
351 int colIndex = columnAtPoint(p);
352 int realColumnIndex = convertColumnIndexToModel(colIndex);
353 if (realColumnIndex == 0){
354 tip = conf_display[rowIndex][0].toString();
355 } else {
356 tip = super.getToolTipText(e);
357 }
358 return tip;
359 }
360 };
361
362 //Set up tableHeader
363 JTableHeader header = conf_setting_table.getTableHeader();
364 header.setFont(new Font("Arial", Font.BOLD, 14));
365
366 conf_setting_table.setRowHeight(30);
367 conf_table_pane = new JScrollPane(conf_setting_table);
368
369 // Layout Components
370 confList_pane.setLayout(new BorderLayout());
371 JScrollPane conf_treeView = new JScrollPane(conf_tree);
372 confList_pane.add(conf_treeView, BorderLayout.CENTER);
373 confList_pane.add(confList_label, BorderLayout.NORTH);
374
375 confContent_pane.setLayout(new BorderLayout());
376 confContent_pane.add(conf_table_pane, BorderLayout.CENTER);
377
378 inner_control_pane.setLayout (new BorderLayout());
379 inner_control_pane.setBorder(BorderFactory.createEmptyBorder(5,10,5,10));
380 inner_control_pane.setPreferredSize(new Dimension(50,50));
381 inner_control_pane.setSize(new Dimension(50,50));
382 inner_control_pane.add (inner_button_pane, BorderLayout.CENTER);
383
384 // Outter Button Layout
385 //outter_button_pane.setLayout (new GridLayout(1,2));
386 //outter_button_pane.add(reload_button);
387 //outter_button_pane.add(delete_button);
388 //outter_button_pane.add(exit_button);
389
390 /*outter_control_pane.setLayout (new BorderLayout());
391 outter_control_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
392 outter_control_pane.setPreferredSize(new Dimension(50,50));
393 outter_control_pane.setSize(new Dimension(50,50));
394 outter_control_pane.add (outter_button_pane, BorderLayout.CENTER);*/
395
396 main_contentPane.setLayout (new BorderLayout());
397 main_contentPane.add(confContent_label, BorderLayout.NORTH);
398 main_contentPane.add(confContent_pane, BorderLayout.CENTER);
399 main_contentPane.add(inner_control_pane, BorderLayout.SOUTH);
400 main_conf_pane.add(confList_pane, JSplitPane.LEFT);
401 main_conf_pane.add(main_contentPane, JSplitPane.RIGHT);
402 main_conf_pane.setDividerLocation(LIST_SIZE.width - 10);
403
404 this.setLayout(new BorderLayout());
405 this.add(main_conf_pane, BorderLayout.CENTER);
406 }
407
408 /*private class ExitButtonListener
409 implements ActionListener {
410 // Exit the Adminstration tool
411 public void actionPerformed(ActionEvent event) {
412 if (valueChanged) {
413 int result = JOptionPane.showConfirmDialog((Component) null, "The value of configuration has been changed,do you really want to exit?", "Exit Confirmation", JOptionPane.YES_NO_OPTION);
414 if ( result == JOptionPane.YES_OPTION) {
415 System.exit(1);
416 } else if (result == JOptionPane.NO_OPTION) {
417 JOptionPane.showMessageDialog((Component) null,"Press Save Change button to save the change!");
418 }
419 } else {
420 System.exit(1);
421 }
422 }
423 }*/
424
425 private class StartupTomcatButtonListener
426 implements ActionListener {
427 public void actionPerformed(ActionEvent event) {
428 tomcat_server_up = checkTomcatServer();
429 if (!tomcat_server_up) {
430 //ParsingProgress progressBar = new ParsingProgress("Startup Tomcat Server", "Starting up the Tomcat Server", 10);
431 ThreadControl threadControl = new ThreadControl();
432 Runnable startupTomcatThread = threadControl.new startupTomcatServer("start-tomcat");
433 new Thread(startupTomcatThread).start();
434 //if over two seconds
435 // activae progress bar
436 /*progressBar.dispose();
437 progressBar.destroy();
438 progressBar = null;*/
439 threadControl.destroy();
440 tomcat_server_up = true;
441 JOptionPane.showMessageDialog((Component) null,"The Tomcat server has been Startup successfully!");
442 } else {
443 JOptionPane.showMessageDialog((Component) null,"Tomcat server is running");
444 }
445 changeTomcatButtonPane1();
446 }
447 }
448
449 private class ShutdownTomcatButtonListener
450 implements ActionListener {
451 public void actionPerformed(ActionEvent event) {
452 tomcat_server_up = checkTomcatServer();
453 if (tomcat_server_up){
454 int result = JOptionPane.showConfirmDialog((Component) null, "Are you sure that you want to shutdown the Tomcat server?", "Shutdown Confirmation", JOptionPane.YES_NO_OPTION);
455 if (result == JOptionPane.YES_OPTION) {
456 // ParsingProgress progressBar = new ParsingProgress("Shutdown Tomcat Server", "Shutting down the Tomcat Server", 10);
457 ThreadControl threadControl = new ThreadControl();
458 Runnable shutdownTomcatThread = threadControl.new shutdownTomcatServer("stop-tomcat");
459 new Thread(shutdownTomcatThread).start();
460 /*progressBar.dispose();
461 progressBar.destroy();
462 progressBar = null;*/
463 threadControl.destroy();
464 tomcat_server_up = false;
465 JOptionPane.showMessageDialog((Component) null,"The Tomcat server has been Shutdown successfully !");
466 } else if (result == JOptionPane.NO_OPTION) {
467 JOptionPane.showMessageDialog((Component) null,"Cancel to Shutdown the Tomcat server!");
468 }
469 } else {
470 JOptionPane.showMessageDialog((Component) null,"The Tomcat server was not running!");
471 }
472 changeTomcatButtonPane2();
473 }
474 }
475
476 private class RestartTomcatButtonListener
477 implements ActionListener {
478 public void actionPerformed(ActionEvent event) {
479 tomcat_server_up = checkTomcatServer();
480 if (tomcat_server_up) {
481 ThreadControl threadControl = new ThreadControl();
482 Runnable restartTomcatThread = threadControl.new restartTomcatServer("restart-tomcat");
483 new Thread(restartTomcatThread).start();
484 threadControl.destroy();
485 tomcat_server_up = true;
486 JOptionPane.showMessageDialog((Component) null,"The Tomcat server has been Restarted successfully!");
487 } else {
488 JOptionPane.showMessageDialog((Component) null,"Tomcat server was not running!");
489 }
490 }
491 }
492
493
494 private class StartupMysqlButtonListener
495 implements ActionListener {
496 public void actionPerformed(ActionEvent event) {
497 mysql_server_up = checkMysqlServer();
498 if (!mysql_server_up) {
499 ThreadControl threadControl = new ThreadControl();
500 Runnable startupMysqlThread = threadControl.new startupMysqlServer("start-mysql");
501 new Thread(startupMysqlThread).start();
502 threadControl.destroy();
503 JOptionPane.showMessageDialog((Component) null,"The MYSQL server has been Startup successfully!");
504 mysql_server_up = true;
505 } else {
506 JOptionPane.showMessageDialog((Component) null,"MYSQL server has been running");
507 }
508 changeMysqlButtonPane1();
509 }
510 }
511
512 private class ShutdownMysqlButtonListener
513 implements ActionListener {
514 public void actionPerformed(ActionEvent event) {
515 mysql_server_up = checkMysqlServer();
516 if (mysql_server_up){
517 int result = JOptionPane.showConfirmDialog((Component) null, "Are you sure that you want to shutdown the MYSQL server?", "Shutdown Confirmation", JOptionPane.YES_NO_OPTION);
518 if (result == JOptionPane.YES_OPTION) {
519 ThreadControl threadControl = new ThreadControl();
520 Runnable shutdownMysqlThread = threadControl.new shutdownMysqlServer("stop-mysql");
521 new Thread(shutdownMysqlThread).start();
522 threadControl.destroy();
523 JOptionPane.showMessageDialog((Component) null,"The MYSQL server has been Shutdown successfully !");
524 mysql_server_up = false;
525 } else if (result == JOptionPane.NO_OPTION) {
526 JOptionPane.showMessageDialog((Component) null,"Cancel to Shutdown the MYSQL server!");
527 }
528 } else {
529 JOptionPane.showMessageDialog((Component) null,"The MYSQL server was not running!");
530 }
531 changeMysqlButtonPane2();
532 }
533 }
534
535 private class RestartMysqlButtonListener
536 implements ActionListener {
537 public void actionPerformed(ActionEvent event) {
538 mysql_server_up = checkMysqlServer();
539 if (mysql_server_up) {
540 ThreadControl threadControl = new ThreadControl();
541 Runnable restartMysqlThread = threadControl.new restartMysqlServer("restart-mysql");
542 new Thread(restartMysqlThread).start();
543 threadControl.destroy();
544 JOptionPane.showMessageDialog((Component) null,"MYSQL server has been Restarted successfully!");
545 mysql_server_up = true;
546 } else {
547 JOptionPane.showMessageDialog((Component) null,"MYSQL server was not running, use startup button to start the MYSQL server!");
548 }
549 }
550 }
551
552 private class SaveButtonListener
553 implements ActionListener {
554 public void actionPerformed(ActionEvent event) {
555
556 if (!valueChanged) {
557 JOptionPane.showMessageDialog((Component) null,"The configuration value has not been changed!");
558 } else {
559 int result = JOptionPane.showConfirmDialog((Component) null, "Do you really want to save the change", "Save Confirmation", JOptionPane.YES_NO_OPTION);
560 if ( result == JOptionPane.YES_OPTION) {
561 saveNewConfSetting();
562 writeConfFile(GAI.build_file);
563 valueChanged = false;
564 } else if (result == JOptionPane.NO_OPTION) {
565 valueChanged = true;
566 }
567 }
568
569 }
570 }
571
572 public void saveNewConfSetting(){
573 String new_string;
574 for (int i=0; i < conf_display.length; i++){
575 if (!conf_display[i][1].toString().matches("^\\s*$")){
576 for (int j=0; j < conf_array.size(); j++){
577 if (((String)conf_array.get(j)).startsWith(conf_display[i][1].toString().toLowerCase())){
578 new_string = conf_display[i][1].toString()+"="+conf_display[i][2].toString();
579 conf_array.set(j, new_string.toLowerCase());
580 }
581 }
582 }
583 }
584
585 }
586
587
588 public void writeConfFile(File file){
589 String filename = file.getPath();
590 try {
591 BufferedWriter conf_out = new BufferedWriter(new FileWriter(filename));
592 for (int j=0 ; j < conf_array.size(); j++){
593 conf_out.write(conf_array.get(j).toString());
594 conf_out.newLine();
595 }
596 conf_out.close();
597 getConfContent();
598 } catch (Exception e) {
599 e.printStackTrace();
600 }
601 }
602
603
604 public void getConfContent(){
605 System.err.println("GAI Build file:" + GAI.build_file);
606
607 String filename = GAI.build_file.getPath();
608
609 if (!GAI.build_file.exists()){
610 JOptionPane.showMessageDialog((Component) null,"Build property file does not exist");
611 //reload_button.setEnabled(false);
612 } else {
613 readFile(filename);
614 }
615 save_button.setEnabled(true);
616 }
617
618 public void readFile (String filename) {
619 String fileLine;
620 /*inside the array will store, the conf_setting[i][0]:Comment,
621 *conf_setting[i][1]:Para and conf_setting[i][2]:Value
622 * conf_array[] store all the details from the build.properties*/
623 conf_array = new ArrayList();
624 conf_setting = new Object [rowLength][colLength];
625 try {
626 BufferedReader conf_in = new BufferedReader(new FileReader(filename));
627 int i = 0;
628 int j = 0;
629 while ((fileLine = conf_in.readLine()) != null) {
630 // This is an empty line
631 if (fileLine.matches("^\\s*$")) {
632 // Do Nothing
633 } else if (fileLine.matches("##.+")){
634 //This line shows the specific service for these conf setting
635 conf_array.add(fileLine);
636 } else if (fileLine.matches("#.+")){
637 //This line is Configuration Comment line
638 conf_array.add(fileLine);
639 conf_setting[i][0] = fileLine.substring(1); // use 1 to get rid of the # symbol.
640 } else if (!fileLine.matches("#.+") && !fileLine.matches("^\\s*$") ){
641 //This line is Setting line
642 int end_index = fileLine.indexOf("=");
643 conf_setting[i][1] = fileLine.substring(0,end_index).toUpperCase();
644 conf_setting[i][2] = fileLine.substring(end_index+1);
645 i++; //calculat the number of settings
646 conf_array.add(fileLine);
647 } else {
648 // Wrong character in the line
649 }
650 }
651 num_of_setting = i;
652 conf_in.close();
653 } catch (Exception e) {
654 e.printStackTrace();
655 }
656 }
657
658 public void showConfSetting(String conf_param) {
659 clearTable();
660 int j=0;
661 for (int i=0; i< num_of_setting; i++){
662 if (conf_setting[i][1].toString().matches("^("+ conf_param +").+")) {
663 if (conf_setting[i][1].toString().matches("TOMCAT.SERVER")){
664 tomcat_server = conf_setting[i][2].toString();
665 }
666 if (conf_setting[i][1].toString().matches("TOMCAT.PORT")){
667 tomcat_port = conf_setting[i][2].toString();
668 }
669 if (conf_setting[i][1].toString().matches("MYSQL.ADMIN.USER")){
670 mysql_adminuser = conf_setting[i][2].toString();
671 }
672 if (conf_setting[i][1].toString().matches("MYSQL.SERVER")){
673 mysql_server = conf_setting[i][2].toString();
674 }
675 if (conf_setting[i][1].toString().matches("MYSQL.PORT")){
676 mysql_port = conf_setting[i][2].toString();
677 }
678 conf_display[j][0] = conf_setting[i][0];
679 conf_display[j][1] = conf_setting[i][1];
680 conf_display[j][2] = conf_setting[i][2];
681 j++;
682 }
683 }
684 }
685
686 public void clearTable (){
687 for (int i=0; i< rowLength; i++){
688 conf_display[i][0] = "";
689 conf_display[i][1] = "";
690 conf_display[i][2] = "";
691 }
692 }
693
694 private boolean checkTomcatServer (){
695 try {
696 if (tomcat_server != "" && tomcat_port != ""){
697 String http_string = "http://" + tomcat_server+":"+tomcat_port+"/";
698 URL tomcatURL = new URL(http_string);
699 HttpURLConnection tomcatConn = (HttpURLConnection) tomcatURL.openConnection();
700 tomcatConn.connect();
701 //necessary to get a Response, even if you don't care about contents
702 InputStream connIn = tomcatConn.getInputStream();
703 int pageStatus = tomcatConn.getResponseCode();
704 if (pageStatus == HttpURLConnection.HTTP_NOT_FOUND) {//404 error
705 //Tomcat is not running
706 tomcat_server_up = false;
707 } else {
708 tomcat_server_up = true;
709 }
710 } else {
711 System.err.println("Etiher tomcat server or tomcat port was not set properly");
712 }
713 } catch (Exception ex) {
714 System.err.println(ex.getMessage());
715 }
716 return tomcat_server_up;
717 }
718
719 private boolean checkMysqlServer(){
720 Connection conn = null;
721 try {
722 String mysql_userName ="gsdl3reader";
723 String mysql_password = "";
724 String mysql_url ="jdbc:mysql://"+mysql_server+":"+mysql_port+"/localsite_gs3mgdemo";
725 System.err.println("what is Mysql_URL:" + mysql_url);
726 Class.forName("com.mysql.jdbc.Driver").newInstance();
727 conn = DriverManager.getConnection(mysql_url, mysql_userName, mysql_password);
728 System.err.println("MYSQL Server connection:" + conn);
729 if (conn == null) {
730 //System.err.println("Connection is failed");
731 mysql_server_up =false;
732 } else {
733 mysql_server_up = true;
734 }
735 } catch (Exception e) {
736 System.err.println("Cannot connect to database server");
737 }
738 return mysql_server_up;
739 }
740
741 class ConfTableModel extends AbstractTableModel {
742 String[] columnNames = {"Configuration Parameter",
743 "Configuration Value"};
744
745 public int getColumnCount(){
746 return columnNames.length;
747 }
748
749 public int getRowCount() {
750 return conf_display.length;
751 }
752
753 public String getColumnName(int col){
754 return columnNames[col];
755 }
756
757 public Object getValueAt(int row,int col){
758 return conf_display[row][col+1];
759 }
760
761 public boolean isCellEditable(int row, int col){
762 if (col == 0){
763 return false;
764 } else {
765 return true;
766 }
767 }
768
769 public void setValueAt(Object value, int row, int col){
770 conf_display[row][col+1] = value;
771 fireTableCellUpdated(row,col+1);
772 valueChanged = true;
773 }
774 }
775
776 private class ConfTreeListener implements TreeSelectionListener{
777 String conf_param;
778 public void valueChanged (TreeSelectionEvent e){
779 String option = conf_tree.getLastSelectedPathComponent().toString();
780 if (option == "Compile"){
781 if (valueChanged){
782 JOptionPane.showMessageDialog((Component) null,"The configuration setting has been changed, please save the change");
783 } else {
784 conf_param = "COMPILE";
785 //conf_tree.setToolTipText("The Configuration Setting for the Compilation ");
786 inner_button_pane.removeAll();
787 inner_button_pane.setLayout(new GridLayout(1,3));
788 inner_button_pane.add(save_button);
789 save_button.setEnabled(true);
790 showConfSetting(conf_param);
791 updateUI();
792 }
793 } else if (option == "Tomcat"){
794 if (valueChanged) {
795 JOptionPane.showMessageDialog((Component) null,"The configuration setting has been changed, please save the change");
796 } else {
797 conf_param ="TOMCAT";
798 showConfSetting(conf_param);
799 //Setup Tomcat button control pane
800 inner_button_pane.removeAll();
801 inner_button_pane.setLayout(new GridLayout(1,3));
802 if (checkTomcatServer()) {
803 changeTomcatButtonPane1();
804 } else {
805 changeTomcatButtonPane2();
806 }
807 updateUI();
808 }
809 } else if (option =="Proxy"){
810 if (valueChanged) {
811 JOptionPane.showMessageDialog((Component) null,"The configuration setting has been changed, please save the change");
812 } else {
813 conf_param="PROXY";
814 showConfSetting(conf_param);
815 //conf_tree.setToolTipText("The Configuration Setting for the Proxy Server");
816 inner_button_pane.removeAll();
817 inner_button_pane.setLayout(new GridLayout(1,3));
818 inner_button_pane.add(save_button);
819 save_button.setEnabled(true);
820 updateUI();
821 }
822 } else if (option == "Mysql"){
823 if (valueChanged) {
824 JOptionPane.showMessageDialog((Component) null,"The configuration setting has been changed, please save the change");
825 } else {
826 conf_param="MYSQL";
827 showConfSetting(conf_param);
828 //conf_tree.setToolTipText("The Configuration Setting for the MYSQL Server");
829 // Setup MySQL button control pane
830 inner_button_pane.removeAll();
831 inner_button_pane.setLayout(new GridLayout(1,3));
832 if (checkMysqlServer()) {
833 changeMysqlButtonPane1();
834 } else {
835 changeMysqlButtonPane2();
836 }
837 updateUI();
838 }
839 } else if (option == "GSDL"){
840 if (valueChanged) {
841 JOptionPane.showMessageDialog((Component) null,"The configuration setting has been changed, please save the change");
842 } else {
843 showConfSetting(conf_param);
844 //conf_tree.setToolTipText("The Configuration Setting for the GSDL");
845 inner_button_pane.removeAll();
846 inner_button_pane.setLayout(new GridLayout(1,3));
847 inner_button_pane.add(save_button);
848 save_button.setEnabled(true);
849 conf_param ="GSDL";
850 updateUI();
851 }
852 } else if (option == "Conf 2"){
853 //MysqlInstall mysql =
854 JOptionPane.showMessageDialog((Component) null,"This has not been defined yet!");
855 } else if (option == "Conf 3") {
856 clearTable();
857 JOptionPane.showMessageDialog((Component) null,"This has not been defined yet!");
858 }
859 }
860 }
861 public void modeChanged (int mode){
862 return;
863 }
864
865 public void gainFocus() {
866 return;
867 }
868
869 public void changeTomcatButtonPane1 (){
870 inner_button_pane.removeAll();
871 inner_button_pane.setLayout(new GridLayout(1,3));
872 inner_button_pane.add(restart_tomcat_button);
873 inner_button_pane.add(shutdown_tomcat_button);
874 inner_button_pane.add(save_button);
875 restart_tomcat_button.setEnabled (true);
876 shutdown_tomcat_button.setEnabled (true);
877 save_button.setEnabled (true);
878 updateUI();
879 }
880 public void changeTomcatButtonPane2 (){
881 inner_button_pane.removeAll();
882 inner_button_pane.setLayout(new GridLayout(1,3));
883 inner_button_pane.add(startup_tomcat_button);
884 inner_button_pane.add(shutdown_tomcat_button);
885 inner_button_pane.add(save_button);
886 shutdown_tomcat_button.setEnabled (true);
887 startup_tomcat_button.setEnabled (true);
888 save_button.setEnabled (true);
889 updateUI();
890 }
891 public void changeMysqlButtonPane1 (){
892 inner_button_pane.removeAll();
893 inner_button_pane.setLayout(new GridLayout(1,3));
894 inner_button_pane.add(restart_mysql_button);
895 inner_button_pane.add(shutdown_mysql_button);
896 inner_button_pane.add(save_button);
897 restart_mysql_button.setEnabled (true);
898 shutdown_mysql_button.setEnabled (true);
899 save_button.setEnabled (true);
900 updateUI();
901 }
902 public void changeMysqlButtonPane2 (){
903 inner_button_pane.removeAll();
904 inner_button_pane.setLayout(new GridLayout(1,3));
905 inner_button_pane.add(startup_mysql_button);
906 inner_button_pane.add(shutdown_mysql_button);
907 inner_button_pane.add(save_button);
908 shutdown_mysql_button.setEnabled (true);
909 startup_mysql_button.setEnabled (true);
910 save_button.setEnabled (true);
911 updateUI();
912 }
913}
914
915
Note: See TracBrowser for help on using the repository browser.