source: main/trunk/greenstone3/src/java/org/greenstone/admin/gui/ConfPane.java@ 24408

Last change on this file since 24408 was 24408, checked in by sjm84, 13 years ago

Some admin fixes

  • Property svn:keywords set to Author Date Id Revision
File size: 33.2 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.util.Hashtable;
46import java.util.Enumeration;
47import java.lang.Object;
48import javax.swing.*;
49import javax.swing.event.*;
50import javax.swing.tree.*;
51import javax.swing.table.*;
52import java.awt.event.MouseEvent;
53import java.net.*;
54import java.sql.*;
55
56import org.greenstone.admin.GAI;
57import org.greenstone.admin.GAIManager;
58import org.greenstone.admin.gui.ThreadControl;
59//import org.greenstone.admin.gui.ConfSettingTableModel;
60import org.greenstone.admin.gui.SiteConfSetting;
61import org.greenstone.admin.gui.ParsingProgress;
62
63import org.greenstone.util.Configuration;
64import org.greenstone.gsdl3.util.GSFile;
65
66/** The Configuration pane is to view the status of relevant configure files in GSIII
67 * @author Chi-Yu Huang, Greenstone Digital Library, University of Waikato
68 * @version
69 */
70public class ConfPane
71 extends JPanel
72 implements ActionListener {
73
74 /* The pane to demonstrate Configuration information, including the build property file
75 * being monitored and their content, and control functions */
76 protected JSplitPane main_conf_pane = null;
77
78 protected JPanel main_contentPane = null;
79 public Hashtable conf_table;
80
81 /** The panel that contains a Conf_list */
82 private JPanel confList_pane = null;
83
84 /** The panel that contains the conf content. */
85 private JPanel confContent_pane = null;
86 private JScrollPane conf_table_pane = null;
87
88 /** The List showing all the Configuration files concerned. */
89 private JList conf_list=null;
90 private JTree conf_tree = null;
91
92 /** The label at the top of the confList_pane. */
93 private JLabel confList_label = null;
94 /** The label shown at the top of the confContent Pane. */
95 private JLabel confContent_label = null;
96
97 // The control buttons used to manipulate Configuration Pane
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 private JLabel conf_label = null;
115 private JLabel conf_setting_label = null;
116
117 /* ConfPane empty AREA to show XML configuration file*/
118 //private JTextArea conf_xml_area = null;
119
120 //control tomcat and mysql server running status
121 private String tomcat_server;
122 private String tomcat_port;
123 private String mysql_adminuser;
124 private String mysql_server;
125 private String mysql_port;
126 private String conf_pane_name;
127
128 private boolean tomcat_server_up = false;
129 private boolean mysql_server_up = false;
130
131 /** The scrollable area into which the configuration content is placed. */
132 //private JScrollPane conf_xml_content = null;
133
134 public SiteConfSetting site_conf = null;
135 public SiteConfSetting interface_conf = null;
136
137 /** The various sizes for the screen layout*/
138 static private Dimension MIN_SIZE = new Dimension( 90, 90);
139 static private Dimension LIST_SIZE = new Dimension(200, 450);
140 static private Dimension CONTENT_SIZE = new Dimension (600,450);
141 static private Dimension TABLE_SIZE = new Dimension(500,200);
142 static private int MINIMUM_TABLE_HEADER_SIZE = 15;
143
144 private JTable conf_setting_table = null;
145
146 private int num_of_setting;
147
148 //The details display in the table
149 int display_row_count = 5;
150 int rowLength = 20;
151 int colLength = 3;
152 private Object[][] conf_display = new Object [rowLength][colLength];
153 private Object[][] conf_setting;
154
155 //An array to store all the details in the build.properties file
156 private ArrayList conf_array;
157
158 //Site configuration
159 // TODO!! there are more than one site and interface - need to extend this
160 public File site_conf_file = new File(GSFile.siteConfigFile(GSFile.siteHome(GAI.gsdl3_web_home, "localsite")));
161 public File interface_conf_file = new File(GSFile.interfaceConfigFile(GSFile.interfaceHome(GAI.gsdl3_web_home, "default")));
162 public boolean project_conf_changed = false;
163
164 ConfSettingTableModel conf_table_model = null;
165 DefaultMutableTreeNode top = new DefaultMutableTreeNode("Configuration Files");
166 //Constructor
167 public ConfPane() {
168 conf_table = new Hashtable();
169 // create all the control button panes
170 inner_control_pane = new JPanel();
171 inner_button_pane = new JPanel();
172 tomcat_button_pane = new JPanel();
173 mysql_button_pane = new JPanel();
174
175 /*the class for showing the site configurations including
176 * siteConfig.xml and interfaceConfig.xml
177 */
178 site_conf = new SiteConfSetting("siteConfig", site_conf_file);
179 interface_conf = new SiteConfSetting("interfaceConfig", interface_conf_file);
180
181 // Main Configuration Pane
182 main_conf_pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
183 // Main pane for Configuration Content Pane
184 main_contentPane = new JPanel();
185
186 //Create a tree for a list Configuration files we are interested
187 //DefaultMutableTreeNode child1 = new DefaultMutableTreeNode();
188 DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Project Configuration");
189
190 DefaultMutableTreeNode compile = new DefaultMutableTreeNode("Compile");
191 DefaultMutableTreeNode tomcat = new DefaultMutableTreeNode("Tomcat");
192 DefaultMutableTreeNode proxy = new DefaultMutableTreeNode("Proxy");
193 DefaultMutableTreeNode mysql = new DefaultMutableTreeNode("MySQL");
194 DefaultMutableTreeNode gsdl = new DefaultMutableTreeNode("GSDL");
195 child1.add(compile);
196 child1.add(tomcat);
197 child1.add(proxy);
198 child1.add(mysql);
199 child1.add(gsdl);
200
201 DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("Site Configuration");
202 //DefaultMutableTreeNode child2 = new DefaultMutableTreeNode();
203 DefaultMutableTreeNode siteConf = new DefaultMutableTreeNode("SiteConfig");
204 DefaultMutableTreeNode interfaceConf = new DefaultMutableTreeNode("InterfaceConfig");
205 child2.add(siteConf);
206 child2.add(interfaceConf);
207
208 //DefaultMutableTreeNode child3 = new DefaultMutableTreeNode("Conf 3");
209 top.add(child1);
210 top.add(child2);
211 //top.add(child3);
212 conf_tree = new JTree(top);
213 conf_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
214 conf_tree.addTreeSelectionListener(new ConfTreeListener());
215
216 // inner button_pane Buttons
217 StartupTomcatButtonListener stbl = new StartupTomcatButtonListener();
218 ShutdownTomcatButtonListener stdbl = new ShutdownTomcatButtonListener();
219 RestartTomcatButtonListener rtbl = new RestartTomcatButtonListener();
220
221 StartupMysqlButtonListener smbl = new StartupMysqlButtonListener();
222 ShutdownMysqlButtonListener smdbl = new ShutdownMysqlButtonListener();
223 RestartMysqlButtonListener rmbl = new RestartMysqlButtonListener();
224
225 ImageIcon startupTomcatButtonIcon = new ImageIcon(GAI.images_path + "redo.gif");
226 ImageIcon shutdownTomcatButtonIcon = new ImageIcon(GAI.images_path + "stop.gif");
227 ImageIcon restartTomcatButtonIcon = new ImageIcon(GAI.images_path + "stop.gif");
228
229 ImageIcon startupMysqlButtonIcon = new ImageIcon(GAI.images_path + "redo.gif");
230 ImageIcon shutdownMysqlButtonIcon = new ImageIcon(GAI.images_path + "stop.gif");
231 ImageIcon restartMysqlButtonIcon = new ImageIcon(GAI.images_path + "stop.gif");
232 ImageIcon saveButtonIcon = new ImageIcon(GAI.images_path + "save.gif");
233
234 startup_tomcat_button = new JButton();
235 startup_tomcat_button.addActionListener(stbl);
236 startup_tomcat_button.setMnemonic(KeyEvent.VK_S);
237 startup_tomcat_button.setEnabled(false);
238 startup_tomcat_button.setText(GAI.dictionary.get("ConfPane.Tomcat_Startup"));
239 startup_tomcat_button.setToolTipText(GAI.dictionary.get("ConfPane.Tomcat_Startup_Tooltip"));
240
241 shutdown_tomcat_button = new JButton();
242 shutdown_tomcat_button.addActionListener(stdbl);
243 shutdown_tomcat_button.setEnabled(false);
244 shutdown_tomcat_button.setText(GAI.dictionary.get("ConfPane.Tomcat_Shutdown"));
245 shutdown_tomcat_button.setToolTipText(GAI.dictionary.get("ConfPane.Tomcat_Shutdown_Tooltip"));
246
247 restart_tomcat_button = new JButton();
248 restart_tomcat_button.addActionListener(rtbl);
249 restart_tomcat_button.setEnabled(false);
250 restart_tomcat_button.setText(GAI.dictionary.get("ConfPane.Tomcat_Restart"));
251 restart_tomcat_button.setToolTipText(GAI.dictionary.get("ConfPane.Tomcat_Restart_Tooltip"));
252
253 startup_mysql_button = new JButton();
254 startup_mysql_button.addActionListener(smbl);
255 startup_mysql_button.setMnemonic(KeyEvent.VK_S);
256 startup_mysql_button.setEnabled(false);
257 startup_mysql_button.setText(GAI.dictionary.get("ConfPane.MySQL_Startup"));
258 startup_mysql_button.setToolTipText(GAI.dictionary.get("ConfPane.MySQL_Startup_Tooltip"));
259
260 shutdown_mysql_button = new JButton();
261 shutdown_mysql_button.addActionListener(smdbl);
262 shutdown_mysql_button.setEnabled(false);
263 shutdown_mysql_button.setText(GAI.dictionary.get("ConfPane.MySQL_Shutdown"));
264 shutdown_mysql_button.setToolTipText(GAI.dictionary.get("ConfPane.MySQL_Shutdown_Tooltip"));
265
266 restart_mysql_button = new JButton();
267 restart_mysql_button.addActionListener(rmbl);
268 restart_mysql_button.setEnabled(false);
269 restart_mysql_button.setText(GAI.dictionary.get("ConfPane.MySQL_Restart"));
270 restart_mysql_button.setToolTipText(GAI.dictionary.get("ConfPane.MySQL_Restart_Tooltip"));
271
272 //tomcat control buttons
273 stbl = null;
274 stdbl = null;
275 rtbl = null;
276
277 //mysql control button
278 smbl = null;
279 smdbl = null;
280 rmbl = null;
281
282 //read in build properties
283 getConfContent();
284 }
285
286 /** Any implementation of ActionListener requires this method so that when an
287 **action is performed the appropriate effect can occur.*/
288 public void actionPerformed(ActionEvent event) {
289 }
290
291
292 /** This method is called to actually layout the components.*/
293 public void display() {
294 //Create Components.
295 //KeyListenerImpl key_listener = new KeyListenerImpl();
296 //MouseListenerImpl mouse_listener = new MouseListenerImpl();
297 //this.addKeyListener(key_listener);
298
299 //confList_Pane
300 confList_pane = new JPanel();
301 confList_pane.setBorder(BorderFactory.createLoweredBevelBorder());
302 confList_pane.setPreferredSize(LIST_SIZE);
303 confList_pane.setSize(LIST_SIZE);
304 confList_pane.setBackground(Configuration.getColor("coloring.workspace_selection_background"));
305 confList_pane.setForeground(Configuration.getColor("coloring.workspace_selection_foreground"));
306
307 confList_label = new JLabel();
308 confList_label.setOpaque(true);
309 confList_label.setBackground(Configuration.getColor("coloring.workspace_selection_background"));
310 confList_label.setForeground(Configuration.getColor("coloring.workspace_selection_foreground"));
311 confList_label.setText(GAI.dictionary.get("ConfPane.Conf_List"));
312
313 // confContent_Pane
314 confContent_pane = new JPanel();
315 confContent_pane.setBorder(BorderFactory.createEmptyBorder(10,20,10,20));
316 confContent_pane.setBackground(Configuration.getColor("coloring.workspace_selection_background"));
317 confContent_pane.setForeground(Configuration.getColor("coloring.workspace_selection_foreground"));
318
319 confContent_label = new JLabel();
320 confContent_label.setOpaque(true);
321 confContent_label.setBackground(Configuration.getColor("coloring.workspace_selection_background"));
322 confContent_label.setForeground(Configuration.getColor("coloring.workspace_selection_foreground"));
323 confContent_label.setText(GAI.dictionary.get("ConfPane.Conf_Content"));
324
325 conf_table_model = new ConfSettingTableModel();
326 conf_setting_table = new JTable(conf_table_model){
327 public String getToolTipText(MouseEvent e){
328 String tip = null;
329 Point p = e.getPoint();
330 int rowIndex = rowAtPoint(p);
331 int colIndex = columnAtPoint(p);
332 int realColumnIndex = convertColumnIndexToModel(colIndex);
333 if (realColumnIndex == 0){
334 tip = conf_display[rowIndex][realColumnIndex].toString();
335 } else {
336 tip = super.getToolTipText(e);
337 }
338 return tip;
339 }
340 public Component prepareRenderer (TableCellRenderer renderer,
341 int rowIndex, int colIndex){
342 Component c = super.prepareRenderer(renderer, rowIndex, colIndex);
343 if (colIndex == 0) {
344 c.setBackground(Configuration.getColor("coloring.table_noneditable_background"));
345 } else {
346 c.setBackground(Configuration.getColor("coloring.table_editable_background"));
347 }
348 return c;
349 }
350 };
351
352 //When the MySQL and TOMCAT servers are still running and detect double-clicking occuring (editing mode)
353 conf_setting_table.addMouseListener(new MouseAdapter(){
354 public void mouseClicked(MouseEvent e){
355 if (e.getClickCount() == 2){
356 if (conf_pane_name.matches("MYSQL")){
357 mysql_server_up = false;
358 mysql_server_up = checkMysqlServer();
359 if (mysql_server_up) {
360 JOptionPane.showMessageDialog((Component) null,"MySQL is running, shutdown the MySQL server before making any changes");
361 }
362 }
363 if (conf_pane_name.matches("TOMCAT")){
364 tomcat_server_up = false;
365 tomcat_server_up = checkTomcatServer();
366 if (tomcat_server_up) {
367 JOptionPane.showMessageDialog((Component) null,"TOMCAT is running, shutdown the TOMCAT server before making any changes");
368 }
369 }
370 }
371 }
372 });
373 conf_setting_table.addKeyListener(new KeyAdapter(){
374 public void keyPressed(KeyEvent ke){
375 if (ke.getKeyCode() == KeyEvent.VK_F2){
376 if (conf_pane_name.matches("MYSQL")){
377 mysql_server_up = checkMysqlServer();
378 if (mysql_server_up) {
379 JOptionPane.showMessageDialog((Component) null,"MySQL is running, shutdown the MySQL server before making any changes");
380 }
381 }
382 if (conf_pane_name.matches("TOMCAT")){
383 tomcat_server_up = checkTomcatServer();
384 if (tomcat_server_up) {
385 JOptionPane.showMessageDialog((Component) null,"TOMCAT is running, shutdown the TOMCAT server before making any changes");
386 }
387 }
388 }
389 }
390 });
391
392 //Set up tableHeader
393 JTableHeader table_header = conf_setting_table.getTableHeader();
394 Dimension table_header_preferred_size = table_header.getPreferredSize();
395 if (table_header_preferred_size.height < MINIMUM_TABLE_HEADER_SIZE) {
396 table_header_preferred_size.setSize(table_header_preferred_size.width, MINIMUM_TABLE_HEADER_SIZE);
397 table_header.setPreferredSize(table_header_preferred_size);
398 }
399
400 table_header.setFont(new Font("Arial", Font.BOLD, 13));
401 conf_setting_table.setRowHeight(30);
402 conf_table_pane = new JScrollPane(conf_setting_table);
403 conf_table_pane.setVisible(false);
404 conf_table_pane.getViewport().setBackground(Configuration.getColor("coloring.collection_tree_background"));
405
406 // Layout Components
407 confList_pane.setLayout(new BorderLayout());
408 JScrollPane conf_treeView = new JScrollPane(conf_tree);
409 confList_pane.add(conf_treeView, BorderLayout.CENTER);
410 confList_pane.add(confList_label, BorderLayout.NORTH);
411 confContent_pane.setLayout(new BorderLayout());
412 confContent_pane.add(conf_table_pane, BorderLayout.CENTER);
413
414 inner_button_pane.setLayout(new GridLayout(1,2));
415 inner_control_pane.setLayout (new BorderLayout());
416 inner_control_pane.setBorder(BorderFactory.createEmptyBorder(5,10,5,10));
417 inner_control_pane.setPreferredSize(new Dimension(50,50));
418 inner_control_pane.setSize(new Dimension(50,50));
419 inner_control_pane.add (inner_button_pane, BorderLayout.CENTER);
420
421 main_contentPane.setLayout (new BorderLayout());
422 main_contentPane.add(confContent_label, BorderLayout.NORTH);
423 main_contentPane.add(confContent_pane, BorderLayout.CENTER);
424 main_contentPane.add(inner_control_pane, BorderLayout.SOUTH);
425 main_conf_pane.add(confList_pane, JSplitPane.LEFT);
426 main_conf_pane.add(main_contentPane, JSplitPane.RIGHT);
427 main_conf_pane.setDividerLocation(LIST_SIZE.width - 10);
428
429 this.setLayout(new BorderLayout());
430 this.add(main_conf_pane, BorderLayout.CENTER);
431 }
432
433 public void save() {
434 if (project_conf_changed) {
435 saveProjectConf(GAI.build_properties_file);
436 }
437 if (site_conf.confChanged()){
438 site_conf.saveFile(site_conf_file);
439 }
440 if (interface_conf.confChanged()) {
441 interface_conf.saveFile(interface_conf_file);
442 }
443
444
445 }
446
447 public boolean configurationChanged() {
448 return (project_conf_changed || site_conf.confChanged() ||
449 interface_conf.confChanged());
450
451 }
452
453 private class StartupTomcatButtonListener
454 implements ActionListener {
455 public void actionPerformed(ActionEvent event) {
456 /*before startup Tomcat server, we want to make sure project and Site configuration
457 * files are saved*/
458 if (project_conf_changed) {
459 saveProjectConf(GAI.build_properties_file);
460 }
461 /*boolean site_conf_changed = site_conf.confChanged();
462 boolean interface_conf_changed=interface_conf.confChanged();
463 if (site_conf_changed) {
464 site_conf.saveFile(site_conf_file);
465 }
466 if (interface_conf_changed) {
467 interface_conf.saveFile(interface_conf_file);
468 }*/
469 tomcat_server_up = checkTomcatServer();
470 if (!tomcat_server_up) {
471 ThreadControl threadControl = new ThreadControl();
472 Runnable startupTomcatThread = threadControl.new startupTomcatServer("start-tomcat");
473 new Thread(startupTomcatThread).start();
474 threadControl.destroy();
475 tomcat_server_up = true;
476 JOptionPane.showMessageDialog((Component) null,"Tomcat server has been Startup successfully!");
477 } else {
478 JOptionPane.showMessageDialog((Component) null,"Tomcat server is running");
479 }
480 changeTomcatButtonPane1();
481 }
482 }
483
484 private class ShutdownTomcatButtonListener
485 implements ActionListener {
486 public void actionPerformed(ActionEvent event) {
487 tomcat_server_up = checkTomcatServer();
488 if (tomcat_server_up){
489 ThreadControl threadControl = new ThreadControl();
490 Runnable shutdownTomcatThread = threadControl.new shutdownTomcatServer("stop-tomcat");
491 new Thread(shutdownTomcatThread).start();
492 threadControl.destroy();
493 tomcat_server_up = false;
494 JOptionPane.showMessageDialog((Component) null, "Tomcat server has been shutted down !");
495 } else {
496 JOptionPane.showMessageDialog((Component) null,"Tomcat server was not running!");
497 }
498 changeTomcatButtonPane2();
499 }
500 }
501
502 private class RestartTomcatButtonListener
503 implements ActionListener {
504 public void actionPerformed(ActionEvent event) {
505 //before we restart Tomcat server, we want to make sure the conf_pane settings are saved
506 if (project_conf_changed) {
507 saveProjectConf(GAI.build_properties_file);
508 }
509 /*boolean site_conf_changed = site_conf.confChanged();
510 boolean interface_conf_changed=interface_conf.confChanged();
511 if (site_conf_changed) {
512 site_conf.saveFile(site_conf_file);
513 }
514 if (interface_conf_changed) {
515 interface_conf.saveFile(interface_conf_file);
516 }*/
517 tomcat_server_up = checkTomcatServer();
518 if (tomcat_server_up) {
519 ThreadControl threadControl = new ThreadControl();
520 Runnable restartTomcatThread = threadControl.new restartTomcatServer("restart-tomcat");
521 new Thread(restartTomcatThread).start();
522 threadControl.destroy();
523 tomcat_server_up = true;
524 JOptionPane.showMessageDialog((Component) null,"Tomcat server has been Restarted successfully!");
525 } else {
526 JOptionPane.showMessageDialog((Component) null,"Tomcat server was not running!");
527 }
528 }
529 }
530
531 private class StartupMysqlButtonListener
532 implements ActionListener {
533 public void actionPerformed(ActionEvent event) {
534 //before we startup the MySQL server, we want to make sure the Conf_pane settings are saved
535 saveProjectConf(GAI.build_properties_file);
536 mysql_server_up = checkMysqlServer();
537 if (!mysql_server_up) {
538 ThreadControl threadControl = new ThreadControl();
539 Runnable startupMysqlThread = threadControl.new startupMysqlServer("start-mysql");
540 new Thread(startupMysqlThread).start();
541 threadControl.destroy();
542 mysql_server_up = true;
543 JOptionPane.showMessageDialog((Component) null,"MYSQL server has been Startup successfully!");
544 } else {
545 JOptionPane.showMessageDialog((Component) null,"MYSQL server has been running");
546 }
547 changeMysqlButtonPane1();
548 }
549 }
550
551 private class ShutdownMysqlButtonListener
552 implements ActionListener {
553 public void actionPerformed(ActionEvent event) {
554 mysql_server_up = checkMysqlServer();
555 if (mysql_server_up){
556 ThreadControl threadControl = new ThreadControl();
557 Runnable shutdownMysqlThread = threadControl.new shutdownMysqlServer("stop-mysql");
558 new Thread(shutdownMysqlThread).start();
559 threadControl.destroy();
560 JOptionPane.showMessageDialog((Component) null,"MYSQL server has been Shutdown successfully !");
561 mysql_server_up = false;
562 } else {
563 JOptionPane.showMessageDialog((Component) null,"MYSQL server was not running!");
564 }
565 changeMysqlButtonPane2();
566 }
567 }
568
569 private class RestartMysqlButtonListener
570 implements ActionListener {
571 public void actionPerformed(ActionEvent event) {
572 saveProjectConf(GAI.build_properties_file);
573 mysql_server_up = checkMysqlServer();
574 if (mysql_server_up) {
575 ThreadControl threadControl = new ThreadControl();
576 Runnable restartMysqlThread = threadControl.new restartMysqlServer("restart-mysql");
577 new Thread(restartMysqlThread).start();
578 threadControl.destroy();
579 JOptionPane.showMessageDialog((Component) null,"MYSQL server has been Restarted successfully!");
580 mysql_server_up = true;
581 } else {
582 JOptionPane.showMessageDialog((Component) null,"MYSQL server was not running!");
583 }
584 }
585 }
586
587 // Save the configuration file globally,when click File->Save or restart (or startup) Tomcat and MySQl server
588 public void saveProjectConf(File file){
589 String new_string;
590 Enumeration keys = conf_table.keys();
591 String key;
592 String value;
593 String filename = file.getPath();
594 while (keys.hasMoreElements()) {
595 key = (String) keys.nextElement();
596 value = (String) conf_table.get(key);
597 for (int j=0 ; j < conf_array.size(); j++){
598 if (((String)conf_array.get(j)).startsWith(key.toLowerCase())){
599 new_string = key+"="+value;
600 conf_array.set(j, new_string.toLowerCase());
601 }
602 }
603 }
604
605 try {
606 BufferedWriter conf_out = new BufferedWriter(new FileWriter(filename));
607 for (int j=0 ; j < conf_array.size(); j++){
608 conf_out.write(conf_array.get(j).toString());
609 conf_out.newLine();
610 }
611 conf_out.close();
612 getConfContent();
613 project_conf_changed = false;
614 } catch (Exception e) {
615 e.printStackTrace();
616 }
617 }
618
619 public boolean projectConfChanged() {
620 return project_conf_changed;
621 }
622
623 public void getConfContent(){
624 String filename = GAI.build_properties_file.getPath();
625 if (!GAI.build_properties_file.exists()){
626 JOptionPane.showMessageDialog((Component) null,"Build property file does not exist");
627 } else {
628 readProjectConf(filename);
629 }
630 }
631
632 /* Read build.properties file
633 * @param
634 */
635 public void readProjectConf (String filename) {
636 String fileLine;
637 /*inside the array will store, the conf_setting[i][0]:Comment,
638 * conf_setting[i][1]:Para and conf_setting[i][2]:Value
639 * conf_array[] store all the details from the build.properties*/
640 conf_array = new ArrayList();
641 conf_setting = new Object [rowLength][colLength];
642 try {
643 BufferedReader conf_in = new BufferedReader(new FileReader(filename));
644 int i = 0;
645 while ((fileLine = conf_in.readLine()) != null) {
646 // This is an empty line
647 if (fileLine.matches("^\\s*$")) {
648 // Do Nothing
649 } else if (fileLine.matches("##.+")){
650 //This line shows the specific service for these conf setting
651 conf_array.add(fileLine);
652 } else if (fileLine.matches("#.+")){
653 //This line is Configuration Comment line
654 conf_array.add(fileLine);
655 conf_setting[i][0] = fileLine.substring(1); // use 1 to get rid of the # symbol.
656 } else if (!fileLine.matches("#.+") && !fileLine.matches("^\\s*$") ){
657 //This line is Setting line
658 int end_index = fileLine.indexOf("=");
659 conf_setting[i][1] = fileLine.substring(0,end_index).toUpperCase();
660 conf_setting[i][2] = fileLine.substring(end_index+1);
661 conf_table.put(conf_setting[i][1], conf_setting[i][2]);
662 i++; //calculat the number of settings
663 conf_array.add(fileLine);
664 } else {
665 // Wrong character in the line
666 }
667 }
668 num_of_setting = i;
669 for (int j=0; j<num_of_setting; j++){
670 if (conf_setting[j][1].toString().matches("TOMCAT.SERVER")){
671 tomcat_server = conf_setting[j][2].toString();
672 }
673 if (conf_setting[j][1].toString().matches("TOMCAT.PORT")){
674 tomcat_port = conf_setting[j][2].toString();
675 }
676 if (conf_setting[j][1].toString().matches("MYSQL.ADMIN.USER")){
677 mysql_adminuser = conf_setting[j][2].toString();
678 }
679 if (conf_setting[j][1].toString().matches("MYSQL.SERVER")){
680 mysql_server = conf_setting[j][2].toString();
681 }
682 if (conf_setting[j][1].toString().matches("MYSQL.PORT")){
683 mysql_port = conf_setting[j][2].toString();
684 }
685 }
686 conf_in.close();
687 } catch (Exception e) {
688 e.printStackTrace();
689 }
690 }
691
692
693 public void clearTable (){
694 for (int i=0; i< rowLength; i++){
695 conf_display[i][0] = "";
696 conf_display[i][1] = "";
697 conf_display[i][2] = "";
698 }
699 }
700
701 private boolean checkTomcatServer (){
702 try {
703 if (tomcat_server != "" && tomcat_port != ""){
704 String http_string = "http://" + tomcat_server+":"+tomcat_port+"/";
705 URL tomcatURL = new URL(http_string);
706 HttpURLConnection tomcatConn = (HttpURLConnection) tomcatURL.openConnection();
707 tomcatConn.connect();
708 //necessary to get a Response, even if you don't care about contents
709 InputStream connIn = tomcatConn.getInputStream();
710 int pageStatus = tomcatConn.getResponseCode();
711 if (pageStatus == HttpURLConnection.HTTP_NOT_FOUND) {//404 error
712 //Tomcat is not running
713 tomcat_server_up = false;
714 } else {
715 tomcat_server_up = true;
716 }
717 } else {
718 System.err.println("Either Tomcat server or Tomcat port was not set properly");
719 }
720 } catch (Exception ex) {
721 tomcat_server_up = false;
722 System.err.println(ex.getMessage());
723 }
724 return tomcat_server_up;
725 }
726
727 private boolean checkMysqlServer(){
728 Connection conn = null;
729 try {
730 String mysql_userName ="gsdl3reader";
731 String mysql_password = "";
732 String mysql_url ="jdbc:mysql://"+mysql_server+":"+mysql_port+"/localsite_gs3mgdemo";
733 //System.err.println("what is Mysql_URL:" + mysql_url);
734 Class.forName("com.mysql.jdbc.Driver").newInstance();
735 conn = DriverManager.getConnection(mysql_url, mysql_userName, mysql_password);
736 if (conn == null) {
737 mysql_server_up =false;
738 } else {
739 mysql_server_up = true;
740 }
741 } catch (Exception e) {
742 mysql_server_up = false;
743 System.err.println("Cannot connect to database server");
744 }
745 return mysql_server_up;
746 }
747
748 public class ConfSettingTableModel
749 extends AbstractTableModel
750 {
751 String[] columnNames = {"Configuration Parameter",
752 "Configuration Value"};
753
754 public int getColumnCount(){
755 return columnNames.length;
756 }
757
758 public int getRowCount() {
759 return display_row_count;
760 }
761
762 public String getColumnName(int col){
763
764 return columnNames[col];
765 }
766
767 public Object getValueAt(int row,int col){
768 return conf_display[row][col+1];
769 }
770
771 public boolean isCellEditable(int row, int col){
772 if (col==0){
773 return false;
774 } else if (conf_display[row][col].toString().matches("MYSQL.+")){
775 mysql_server_up = checkMysqlServer();
776 if (mysql_server_up) {
777 return false;
778 }
779 } else if (conf_display[row][col].toString().matches("TOMCAT.+")){
780 tomcat_server_up = checkTomcatServer();
781 if (tomcat_server_up) {
782 return false;
783 }
784 }
785 return true;
786 }
787
788 public void setValueAt(Object value, int row, int col){
789 if (!isCellEditable(row, col))
790 return;
791 conf_display[row][col+1] = value;
792 project_conf_changed = true;
793 //System.err.println("**ConfDisplay:" + conf_display[row][col].toString());
794 conf_table.put(conf_display[row][col].toString(), value);
795 fireTableCellUpdated(row,col+1);
796 updateUI();
797 }
798 }
799
800 public int showProjectConf(String conf_param) {
801 conf_table_pane.setVisible(true);
802 clearPrevConfPane();
803 confContent_pane.add(conf_table_pane, BorderLayout.CENTER);
804 confContent_pane.revalidate();
805 clearTable();
806 int j=0;
807 int row_count = 0;
808 for (int i=0; i< num_of_setting; i++){
809 if (conf_setting[i][1].toString().matches("^("+ conf_param +").+")) {
810 row_count = row_count +1;
811 conf_display[j][0] = conf_setting[i][0];
812 conf_display[j][1] = conf_setting[i][1];
813 conf_display[j][2] = conf_table.get(conf_setting[i][1]);
814 j++;
815 }
816 }
817 return row_count;
818 }
819
820 public void displaySiteConf(SiteConfSetting site_conf_tmp){
821 clearPrevConfPane();
822 confContent_pane.add(site_conf_tmp, BorderLayout.CENTER);
823 try {
824 site_conf_tmp.showText();
825 site_conf_tmp.goTop();
826 confContent_pane.revalidate();
827 } catch (Exception e) {
828 e.printStackTrace();
829 }
830 }
831
832 public void clearPrevConfPane() {
833 confContent_pane.remove(conf_table_pane);
834 confContent_pane.remove(site_conf);
835 confContent_pane.remove(interface_conf);
836 }
837
838
839 private class ConfTreeListener implements TreeSelectionListener{
840 public void valueChanged (TreeSelectionEvent e){
841 String option = conf_tree.getLastSelectedPathComponent().toString();
842 conf_table_pane.setVisible(true);
843 if (option == "Compile"){
844 conf_pane_name = "COMPILE";
845 display_row_count = showProjectConf(conf_pane_name);
846 inner_button_pane.removeAll();
847 inner_button_pane.setLayout(new GridLayout(1,3));
848 } else if (option == "Tomcat"){
849 conf_pane_name ="TOMCAT";
850 display_row_count = showProjectConf(conf_pane_name);
851 //Setup Tomcat button control pane
852 inner_button_pane.removeAll();
853 inner_button_pane.setLayout(new GridLayout(1,3));
854 if (checkTomcatServer()) {
855 changeTomcatButtonPane1();
856 } else {
857 changeTomcatButtonPane2();
858 }
859 } else if (option =="Proxy"){
860 conf_pane_name="PROXY";
861 display_row_count = showProjectConf(conf_pane_name);
862 //Setup Proxy button control pane
863 inner_button_pane.removeAll();
864 inner_button_pane.setLayout(new GridLayout(1,3));
865 } else if (option == "MySQL"){
866 conf_pane_name="MYSQL";
867 display_row_count = showProjectConf(conf_pane_name);
868 // Setup MySQL button control pane
869 inner_button_pane.removeAll();
870 inner_button_pane.setLayout(new GridLayout(1,3));
871 if (checkMysqlServer()) {
872 changeMysqlButtonPane1();
873 } else {
874 changeMysqlButtonPane2();
875 }
876 } else if (option == "GSDL"){
877 conf_pane_name ="GSDL";
878 display_row_count = showProjectConf(conf_pane_name);
879 inner_button_pane.removeAll();
880 } else if (option == "SiteConfig"){
881 conf_pane_name = "SiteConfig";
882 inner_button_pane.removeAll();
883 displaySiteConf(site_conf);
884 } else if (option == "InterfaceConfig") {
885 conf_pane_name = "InterfaceConfig";
886 inner_button_pane.removeAll();
887 displaySiteConf(interface_conf);
888 }
889 updateUI();
890 }
891 }
892
893 public void modeChanged (int mode){
894 return;
895 }
896
897 public void gainFocus() {
898 return;
899 }
900
901 public void changeTomcatButtonPane1 (){
902 inner_button_pane.removeAll();
903 inner_button_pane.setLayout(new GridLayout(1,2));
904 inner_button_pane.add(restart_tomcat_button);
905 inner_button_pane.add(shutdown_tomcat_button);
906 restart_tomcat_button.setEnabled (true);
907 shutdown_tomcat_button.setEnabled (true);
908 updateUI();
909 }
910 public void changeTomcatButtonPane2 (){
911 inner_button_pane.removeAll();
912 inner_button_pane.setLayout(new GridLayout(1,2));
913 inner_button_pane.add(startup_tomcat_button);
914 inner_button_pane.add(shutdown_tomcat_button);
915 startup_tomcat_button.setEnabled (true);
916 shutdown_tomcat_button.setEnabled (false);
917 updateUI();
918 }
919 public void changeMysqlButtonPane1 (){
920 inner_button_pane.removeAll();
921 inner_button_pane.setLayout(new GridLayout(1,2));
922 inner_button_pane.add(restart_mysql_button);
923 inner_button_pane.add(shutdown_mysql_button);
924 restart_mysql_button.setEnabled (true);
925 shutdown_mysql_button.setEnabled (true);
926 updateUI();
927 }
928 public void changeMysqlButtonPane2 (){
929 inner_button_pane.removeAll();
930 inner_button_pane.setLayout(new GridLayout(1,2));
931 inner_button_pane.add(startup_mysql_button);
932 inner_button_pane.add(shutdown_mysql_button);
933 startup_mysql_button.setEnabled (true);
934 shutdown_mysql_button.setEnabled (false);
935 updateUI();
936 }
937 public void afterDisplay(){
938 return;
939 }
940}
941
Note: See TracBrowser for help on using the repository browser.