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