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

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

The latest development when Chi leave on 31/10/2005.

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