source: main/trunk/greenstone3/src/java/org/greenstone/admin/gui/SetServerPane.java

Last change on this file was 25635, checked in by sjm84, 12 years ago

Fixing Greenstone 3's use (or lack thereof) of generics, this was done automatically so we may want to change it over time. This change will also auto-format any files that have not already been formatted.

  • Property svn:keywords set to Author Date Id Revision
File size: 12.7 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 * Date: 05.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 */
38/* This program is intended to confirm the initial user's setting about
39 * the Tomcat server and MySQL server they would like to run GSDL3 with
40 */
41package org.greenstone.admin.gui;
42
43import java.awt.*;
44import java.awt.event.*;
45import java.io.*;
46import java.util.List;
47import java.util.ArrayList;
48import java.lang.Object;
49import javax.swing.*;
50import javax.swing.event.*;
51import javax.swing.tree.*;
52import javax.swing.table.*;
53import java.awt.event.MouseEvent;
54import java.net.*;
55import java.sql.*;
56
57import org.greenstone.util.Configuration;
58import org.greenstone.admin.gui.ParsingProgress;
59import org.greenstone.admin.GAI;
60
61
62/** The initial setting pane is to request the user to input the preferred
63 * Tomcat and Mysql server,they would like to run GSDL3 with
64 * @author Chi-Yu Huang, Greenstone Digital Library, University of Waikato
65 * @version
66 */
67public class SetServerPane
68 extends JFrame
69 implements ActionListener {
70
71 /* This pane is to allow the user to set up their own running Tomcat/Mysql server
72 * before the installation of the GSDL3*/
73 // protected JScrollPane setting_message_pane = null;
74 protected JPanel main_pane = null;
75 protected JPanel button_pane = null;
76 protected JPanel outter_control_pane = null;
77 protected JScrollPane setting_table_pane = null;
78 protected JTable server_setting_table = null;
79
80 private JButton save_button = null;
81 private JButton install_button = null;
82 private JButton exit_button = null;
83
84 ServerSettingTableModel server_setting_table_model = null;
85 private boolean setting_confirm = false;
86 private ArrayList<String> conf_array;
87 private boolean success = false;
88 private boolean file_saved = true;
89
90 /** The various sizes for the screen layout*/
91 static private Dimension MIN_SIZE = new Dimension( 90, 90);
92 static private Dimension LIST_SIZE = new Dimension(200, 450);
93 static private Dimension DIALOG_SIZE = new Dimension (400,300);
94 static private Dimension FRAME_SIZE = new Dimension (500, 450);
95 static private Dimension TABLE_SIZE = new Dimension(500,200);
96 static final Dimension SIZE = new Dimension(400,400);
97
98 //Constructor
99 public SetServerPane() {
100 super();
101 this.setDefaultCloseOperation(EXIT_ON_CLOSE);
102 this.setSize(FRAME_SIZE);
103 this.setTitle("Setting Tomcat/MYSQL Servers");
104
105 // create all the control button panes
106 button_pane = new JPanel();
107
108 //First time running button
109 SaveButtonListener ybl = new SaveButtonListener();
110 InstallButtonListener nbl = new InstallButtonListener();
111 ExitButtonListener ebl = new ExitButtonListener();
112
113 // ImagesIcon for the buttons
114 ImageIcon SaveButtonIcon = new ImageIcon(GAI.images_path + "refresh.gif");
115 ImageIcon InstallButtonIcon = new ImageIcon(GAI.images_path + "exit.gif");
116 ImageIcon ExitButtonIcon = new ImageIcon(GAI.images_path + "exit.gif");
117
118 save_button = new JButton("Save Setting", SaveButtonIcon);
119 save_button.addActionListener(ybl);
120 save_button.setMnemonic(KeyEvent.VK_S);
121 save_button.setToolTipText("Click this button to save up the setting");
122 save_button.setEnabled(false);
123
124 install_button = new JButton("Install GSDL3", InstallButtonIcon);
125 install_button.addActionListener(nbl);
126 install_button.setEnabled(false);
127 install_button.setMnemonic(KeyEvent.VK_I);
128 install_button.setToolTipText("Click this button to Install Greenstone III");
129
130 exit_button = new JButton("Exit Setting and Installation", ExitButtonIcon);
131 exit_button.addActionListener(ebl);
132 exit_button.setEnabled(false);
133 install_button.setMnemonic(KeyEvent.VK_I);
134 install_button.setToolTipText("Click this button to Exit the Setting and Installation of Greenstone III");
135
136 //Setting&Installation buttons
137 ybl = null;
138 nbl = null;
139 ebl = null;
140 }
141
142 /** Any implementation of ActionListener requires this method so that when an
143 **action is performed the appropriate effect can occur.*/
144 public void actionPerformed(ActionEvent event) {
145 }
146
147 /** This method is callsed to actually layout the components.*/
148 public void display() {
149 //KeyListenerImpl key_listener = new KeyListenerImpl();
150 //MouseListenerImpl mouse_listener = new MouseListenerImpl();
151 //this.addKeyListener(key_listener);
152
153 server_setting_table_model = new ServerSettingTableModel();
154 server_setting_table = new JTable(server_setting_table_model) {
155 protected String[] rowToolTips = {
156 "The name of the machine that Tomcat is/will be run on",
157 "The port number that Tomcat is/will be run on",
158 "The base directory for the existing Tomcat installation",
159 "The name of the machine that Mysql is/will be run on",
160 "The port number that Mysql is/will be run on",
161 "The base directory for the existing MYSQL installations",
162 "The user name for the administrator of using MySQL",
163 "The socket that Mysql is/will be run on"};
164
165 public String getToolTipText(MouseEvent e){
166 String tip = null;
167 Point p = e.getPoint();
168 int rowIndex = rowAtPoint(p);
169 int colIndex = columnAtPoint(p);
170 int realColumnIndex = convertColumnIndexToModel(colIndex);
171 if (realColumnIndex == 0){
172 tip = rowToolTips[rowIndex];
173 } else {
174 tip = super.getToolTipText(e);
175 }
176 return tip;
177 }
178 };
179
180 //Set up tableHeader
181 JTableHeader header = server_setting_table.getTableHeader();
182 header.setFont(new Font("Arial", Font.BOLD, 14));
183
184 server_setting_table.setRowHeight(30);
185 setting_table_pane = new JScrollPane(server_setting_table);
186
187 // Button Control Layout
188 save_button.setEnabled(true);
189 install_button.setEnabled(true);
190 exit_button.setEnabled(true);
191
192 button_pane.setLayout (new GridLayout(1,3));
193 button_pane.add(save_button);
194 button_pane.add(install_button);
195 button_pane.add(exit_button);
196
197 outter_control_pane = new JPanel();
198 outter_control_pane.setLayout (new BorderLayout());
199 outter_control_pane.setBorder(BorderFactory.createLoweredBevelBorder());
200 outter_control_pane.setPreferredSize(new Dimension(50,50));
201 outter_control_pane.setSize(new Dimension(50,50));
202 outter_control_pane.add (button_pane, BorderLayout.CENTER);
203
204 main_pane = (JPanel) getContentPane();
205 main_pane.setLayout (new BorderLayout());
206 main_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
207 main_pane.add(setting_table_pane, BorderLayout.CENTER);
208 main_pane.add(outter_control_pane, BorderLayout.SOUTH);
209 main_pane.setBackground(Configuration.getColor("coloring.workspace_selection_background"));
210 main_pane.setForeground(Configuration.getColor("coloring.workspace_selection_foreground"));
211
212 // Center and display
213 Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
214 setLocation((screen_size.width - SIZE.width) / 2,
215 (screen_size.height - SIZE.height) / 2);
216 setVisible(true);
217 }
218
219 public void destroy() {
220 }
221
222 /** This class serves as the listener for actions on the build button.*/
223 private class SaveButtonListener
224 implements ActionListener {
225 /** This button is to save any change you have added
226 ** to the Tomcat/Mysql servers setting*/
227 public void actionPerformed(ActionEvent event) {
228 setting_confirm = true;
229 int result = JOptionPane.showConfirmDialog((Component) null, "Do you really want to save the setting?", "Save Confirmation", JOptionPane.YES_NO_OPTION);
230 if ( result == JOptionPane.YES_OPTION) {
231 updateSetting (GAI.build_properties_file);
232 file_saved = writeFile (GAI.build_properties_file);
233 if (file_saved) {
234 JOptionPane.showMessageDialog((Component) null,"Change has been saved succefully!");
235 } else {
236 JOptionPane.showMessageDialog((Component) null,"Change has not been saved succefully!");
237 file_saved = false;
238 }
239 } else if (result == JOptionPane.NO_OPTION) {
240 JOptionPane.showMessageDialog((Component) null,"Change has not been saved!");
241 file_saved = false;
242 }
243 }
244 }
245
246 public void updateSetting(File build_properties_file) {
247 readFile (GAI.build_properties_file);
248 String new_string;
249 for (int i=0; i < server_setting_table_model.getRowCount(); i++){
250 //System.err.println("What is the value here:" + server_setting_table_model.getValueAt(i,0).toString());
251 if (!server_setting_table_model.getValueAt(i,1).toString().matches("^\\s*$")){
252 for (int j=0; j < conf_array.size(); j++){
253 if (conf_array.get(j).startsWith(server_setting_table_model.getValueAt(i,0).toString().toLowerCase())){
254 //System.err.println("What is the value in conf_array:" + conf_array.get(j));
255 new_string = server_setting_table_model.getValueAt(i,0).toString()+"="+server_setting_table_model.getValueAt(i,1).toString();
256 conf_array.set(j, new_string.toLowerCase());
257 }
258 }
259 }
260 }
261
262 }
263 public void readFile (File build_properties_file) {
264 String filename = build_properties_file.getPath();
265 String fileLine;
266 /*conf_array[] store all the details from the build.properties*/
267 conf_array = new ArrayList<String>();
268 try {
269 BufferedReader conf_in = new BufferedReader(new FileReader(filename));
270 while ((fileLine = conf_in.readLine()) != null) {
271 // Besides an empty line, all the other lines will be stored in the conf_array
272 if (!fileLine.matches("^\\s*$")) {
273 conf_array.add(fileLine);
274 }
275 }
276 conf_in.close();
277 } catch (Exception e) {
278 e.printStackTrace();
279 }
280 }
281
282 public boolean writeFile(File build_properties_file){
283 String filename = build_properties_file.getPath();
284 try {
285 BufferedWriter conf_out = new BufferedWriter(new FileWriter(filename));
286 for (int j=0 ; j < conf_array.size(); j++){
287 conf_out.write(conf_array.get(j).toString());
288 conf_out.newLine();
289 }
290 success = true;
291 conf_out.close();
292 } catch (Exception e) {
293 e.printStackTrace();
294 success = false;
295 }
296 return success;
297 }
298
299 private class InstallButtonListener
300 implements ActionListener {
301 // Exit the Adminstration tool
302 public void actionPerformed(ActionEvent event) {
303 setting_confirm = false;
304 /*if (!setting_confirm) {
305 GAIManager gai = new GAIManager("/research/chi/gsdl3-test/gsdl3", screen_size);
306 }*/
307 }
308 }
309
310 private class ExitButtonListener
311 implements ActionListener {
312 // Exit the Adminstration tool
313 public void actionPerformed(ActionEvent event) {
314 if (!file_saved) {
315 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);
316 if ( result == JOptionPane.YES_OPTION) {
317 System.exit(1);
318 } else if (result == JOptionPane.NO_OPTION) {
319 JOptionPane.showMessageDialog((Component) null,"Press Save button to save the change!");
320 }
321 } else {
322 System.exit(1);
323 }
324 }
325 }
326
327 class ServerSettingTableModel extends AbstractTableModel {
328 String[] columnNames = {"Configuration Parameter",
329 "Configuration Value"};
330 Object [][] conf_display = {{"TOMCAT.SERVER", ""},
331 {"TOMCAT.PORT", ""},
332 {"TOMCAT.INSTALLED.PATH",""},
333 {"MYSQL.SERVER",""},
334 {"MYSQL.PORT",""},
335 {"MYSQL.INSTALLED.PATH",""},
336 {"MYSQL.ADMIN.USER",""},
337 {"MYSQL.SOCKET",""}};
338
339 public int getColumnCount(){
340 return columnNames.length;
341 }
342
343 public int getRowCount() {
344 return conf_display.length;
345 }
346
347 public String getColumnName(int col){
348 return columnNames[col];
349 }
350
351 public Object getValueAt(int row,int col){
352 return conf_display[row][col];
353 }
354
355 public boolean isCellEditable(int row, int col){
356 if (col == 0){
357 return false;
358 } else {
359 return true;
360 }
361 }
362
363 public void setValueAt(Object value, int row, int col){
364 conf_display[row][col] = value;
365 fireTableCellUpdated(row,col);
366 }
367 }
368
369}
370
371
Note: See TracBrowser for help on using the repository browser.