source: trunk/gsdl3/src/java/org/greenstone/admin/GAIManager.java@ 10929

Last change on this file since 10929 was 10929, checked in by kjdon, 18 years ago

merged Chi's admin stuff from ant install branch into main repository

  • Property svn:keywords set to Author Date Id Revision
File size: 12.2 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Administration Tool (GAI) application, part of the
5 * Greenstone digital library suite from the New Zealand Digital Library
6 * Project at the University of Waikato, New Zealand.
7 *
8 * Copyright (C) 1999 New Zealand Digital Library Project
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 * Author: Chi-Yu Huang, Greenstone Digital Library, University of Waikato
25 *
26 *########################################################################
27 */
28
29package org.greenstone.admin;
30
31import org.greenstone.admin.GAI;
32import org.greenstone.admin.gui.TabbedPane;
33import org.greenstone.admin.gui.MenuBar;
34import org.greenstone.admin.gui.LogPane;
35import org.greenstone.admin.gui.ConfPane;
36
37import org.greenstone.core.Configuration;
38import org.greenstone.core.Dictionary;
39import org.greenstone.core.DebugStream;
40import org.greenstone.core.util.Utility;
41
42//import java AWT classes
43import java.awt.*;
44import java.awt.event.*;
45import java.io.*;
46import java.net.*;
47import java.util.*;
48import javax.swing.*;
49import javax.swing.event.*;
50import javax.swing.plaf.*;
51
52public class GAIManager
53 extends JFrame
54 implements ActionListener, ChangeListener{
55
56 private Dimension size = null;
57 // The ConfPane contains the configuration details of Greenstone III build and installation
58 public ConfPane conf_pane = null;
59 // The LogPane contains the log details for Tomcat Server used by gsdl3
60 public LogPane log_pane = null;
61 // Not designed yet
62 public JPanel ext_pane = null;
63 // Not designed yet
64 public JPanel monitor_pane = null;
65
66 static public ImageIcon CONF_ICON = null;
67 static public ImageIcon EXT_ICON = null;
68 static public ImageIcon MONITOR_ICON = null;
69 static public ImageIcon LOG_ICON = null;
70
71 // Create a menu bar in the main Pane
72 public MenuBar menu_bar = null;
73
74 // HelpFrame
75
76 private JPanel previous_pane = null;
77 private JPanel content_pane = null;
78 private JTabbedPane tab_pane = null;
79
80 /** A threaded tab changer to try and avoid NPE on exit. */
81 private TabUpdater tab_updater = null;
82
83 //Contructor
84 public GAIManager(Dimension size){
85 super();
86 this.size = size;
87 this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
88 this.setTitle("GreenStone 3 Administration Tool");
89 /* Add a focus listener to ourselves. Thus if we gain focus when a Modal Dialog should
90 * instead have it, we can try to bring the modal dialog to the front*/
91 //this.addFocusListener(new GAIGUIFocusListener());
92 //display();
93 }
94
95 private class GAIGUIFocusListener
96 extends FocusAdapter {
97 public void focusGained(FocusEvent e) {
98 /* if (ModalDialog.current_modal != null) {
99 ModalDialog.current_modal.makeVisible();
100 ModalDialog.current_modal.toFront();
101 }*/
102 }
103 }
104
105 public void display(){
106 CONF_ICON = new ImageIcon (GAI.images_path + "create.gif");
107 EXT_ICON = new ImageIcon (GAI.images_path + "toolbarButtonGraphics/general/Information16.gif");
108 MONITOR_ICON = new ImageIcon (GAI.images_path + "toolbarButtonGraphics/general/Zoom16.gif");
109 LOG_ICON = new ImageIcon (GAI.images_path + "toolbarButtonGraphics/general/History16.gif");
110 content_pane = (JPanel) this.getContentPane();
111
112 try {
113 this.setSize(size);
114 //create a menuBar
115 menu_bar = new MenuBar(new MenuListenerImpl());
116 this.setJMenuBar(menu_bar);
117
118 //Create the tabbed pane and put it in the center
119 tab_pane = new JTabbedPane();
120 tab_pane.addChangeListener(this);
121
122 //set up the Configuration Pane
123 if (Configuration.get("admin.conf", true)){
124 conf_pane = new ConfPane();
125 conf_pane.display();
126 tab_pane.addTab("Configuration", CONF_ICON, conf_pane);
127 tab_pane.setEnabledAt(tab_pane.indexOfComponent(conf_pane),Configuration.get("admin.conf", false));
128 }
129
130 //set up the ext Pane
131 if (Configuration.get("admin.ext", true)){
132 ext_pane = new JPanel();
133 //ext_pane.display();
134 tab_pane.addTab("Exts", EXT_ICON, ext_pane);
135 tab_pane.setEnabledAt(tab_pane.indexOfComponent(ext_pane),Configuration.get("admin.ext", false));
136 }
137
138 //set up the Monitor Pane
139 if (Configuration.get("admin.monitor", true)){
140 monitor_pane = new JPanel();
141 //monitor_pane.display();
142 tab_pane.addTab("Monitor", MONITOR_ICON, monitor_pane);
143 tab_pane.setEnabledAt(tab_pane.indexOfComponent(monitor_pane),Configuration.get("admin.monitor", false));
144 }
145
146 //set up the Log Pane
147 if (Configuration.get("admin.log", true)){
148 log_pane = new LogPane();
149 log_pane.display();
150 tab_pane.addTab("Log", LOG_ICON, log_pane);
151 tab_pane.setEnabledAt(tab_pane.indexOfComponent(log_pane),Configuration.get("admin.log", false));
152 }
153 content_pane.setLayout(new BorderLayout());
154 content_pane.add(tab_pane, BorderLayout.CENTER);
155 pack();
156 setVisible(true);
157 } catch (Exception e){
158 DebugStream.printStackTrace(e);
159 e.printStackTrace();
160 System.exit(1);
161 }
162 }
163
164 /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed
165 * when an action has occured. In this case we are listening to actions from the menu-bar, and should
166 * react appropriately.
167 * @param event An <strong>ActionEvent</strong> containing information about the action that has occured.
168 */
169
170 public void actionPerformed (ActionEvent event){
171 Object esrc = event.getSource();
172 boolean project_conf_changed = false;
173 boolean site_conf_changed = false;
174 boolean interface_conf_changed = false;
175 if (esrc == menu_bar.file_exit){
176 project_conf_changed = conf_pane.ProjectConfChanged();
177 site_conf_changed = conf_pane.site_conf.confChanged();
178 interface_conf_changed = conf_pane.interface_conf.confChanged();
179 /* Check if the Project and Site configuration files have been changed,
180 * if changed, prompt to users if they want to save*/
181 if (project_conf_changed || site_conf_changed || interface_conf_changed) {
182 int result = JOptionPane.showConfirmDialog((Component) null, "The Configuration files have been changed, do you want to save the change", "Save Confirmation", JOptionPane.YES_NO_OPTION);
183 if ( result == JOptionPane.YES_OPTION) {
184 conf_pane.saveProjectConf(GAI.build_file);
185 conf_pane.site_conf.saveFile(GAI.site_conf);
186 conf_pane.interface_conf.saveFile(GAI.interface_conf);
187 }
188 }
189 exit();
190 }
191 else if (esrc == menu_bar.file_save){
192 /* sliently and Globally save Project and Site configuration*/
193 project_conf_changed = conf_pane.ProjectConfChanged();
194 site_conf_changed = conf_pane.site_conf.confChanged();
195 interface_conf_changed = conf_pane.interface_conf.confChanged();
196 if (project_conf_changed) {
197 conf_pane.saveProjectConf(GAI.build_file);
198 }
199 if (site_conf_changed){
200 conf_pane.site_conf.saveFile(GAI.site_conf);
201 }
202 if (interface_conf_changed) {
203 conf_pane.interface_conf.saveFile(GAI.interface_conf);
204 }
205 }
206 else if (esrc == menu_bar.help_conf){
207 }
208 else if (esrc == menu_bar.help_ext){
209 }
210 else if (esrc == menu_bar.help_monitor){
211 }
212 else if (esrc == menu_bar.help_log){
213 }
214 else if (esrc == menu_bar.help_about) {
215 }
216 }
217
218
219 public void destory (){
220 // Destroying create pane ensures the latest log has been closed
221 //if (status_pane != null) {
222 //}
223 }
224 /**Overridden from JFrame so we can exit safely when window is closed
225 *(or destroyed). @param event A <strong>WindowEvent</strong> containing
226 *information about the event that fired this call.
227 */
228 protected void processWindowEvent(WindowEvent event) {
229 if(event.getID() == WindowEvent.WINDOW_CLOSING) {
230 exit();
231 }
232 }
233
234
235 /** Listens to actions upon the menu bar, and if it detects a click over
236 *the help menu brings the help window to the front if it has become hidden.
237 */
238 private class MenuListenerImpl
239 implements MenuListener {
240 public void menuCanceled (MenuEvent e) {
241 }
242
243 public void menuDeselected (MenuEvent e){
244 }
245
246 public void menuSelected (MenuEvent e){
247 if (e.getSource() == menu_bar.file_exit) {
248 exit();
249 }
250
251 if (e.getSource() == menu_bar.help){
252 if (menu_bar.help.isSelected()){
253 menu_bar.help.doClick(10);
254 }
255 }
256 }
257 }
258
259
260 /** This method ensures that all the things needing saving
261 * are saved before GAIManager.exit() is called.
262 */
263 public void exit() {
264 System.exit(0);
265 }
266
267
268 /** Any implementation of ChangeListener must include this method
269 **so we can be informed when the state of one of the registered
270 **objects changes. In this case we are listening to view changes
271 **within the tabbed pane.
272 * @param event A ChangeEvent containing information about the event that fired this call.
273 */
274 public void stateChanged(ChangeEvent event) {
275 if(previous_pane != null) {
276 }
277
278 //menu_bar.tabSelected(tab_pane.getSelectedIndex());
279 int selected_index = tab_pane.getSelectedIndex();
280 if (selected_index == tab_pane.indexOfComponent(log_pane)) {
281 log_pane.gainFocus();
282 }
283 else if (selected_index == tab_pane.indexOfComponent(conf_pane)) {
284 conf_pane.gainFocus();
285 }
286 previous_pane = (JPanel) tab_pane.getSelectedComponent();
287 }
288
289 public void modeChanged (int mode){
290 if (log_pane != null){
291 log_pane.modeChanged(mode);
292 }
293 if (conf_pane !=null) {
294 conf_pane.modeChanged(mode);
295 }
296 }
297
298 // public void refresh (int refresh_reason, boolean collection_loaded)
299 public void refresh () {
300 if (log_pane != null ){
301 }
302 }
303
304 public void returnToInitialPane(){
305 if (log_pane != null) {
306 tab_pane.setSelectedComponent(log_pane);
307 }
308 }
309 public void wait(boolean waiting) {
310 Component glass_pane = getGlassPane();
311 if(waiting) {
312 // Show wait cursor.
313 //glass_pane.addMouseListener(mouse_blocker_listener);
314 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
315 glass_pane.setVisible(true);
316 }
317 else {
318 // Hide wait cursor.
319 glass_pane.setVisible(false);
320 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
321 //glass_pane.removeMouseListener(mouse_blocker_listener);
322 }
323 glass_pane = null;
324 }
325
326 private class TabUpdater
327 implements Runnable {
328 private boolean ready = false;
329 private int conf_pos = -1;
330 private int ext_pos = -1;
331 private int monitor_pos = -1;
332 private int log_pos = -1;
333 private JTabbedPane tab_pane = null;
334
335 public TabUpdater (JTabbedPane tab_pane, boolean ready){
336 this.ready = ready;
337 this.tab_pane = tab_pane;
338 conf_pos = tab_pane.indexOfComponent(conf_pane);
339 ext_pos = tab_pane.indexOfComponent(ext_pane);
340 monitor_pos = tab_pane.indexOfComponent(monitor_pane);
341 log_pos = tab_pane.indexOfComponent(log_pane);
342 }
343
344 public void run() {
345 if (conf_pos != -1){
346 if (ready) {
347 tab_pane.setEnabledAt (conf_pos,Configuration.get("admin.conf", false));
348 } else {
349 tab_pane.setEnabledAt (conf_pos,Configuration.get("admin.conf",true));
350 }
351 }
352 if (ext_pos != -1){
353 if (ready) {
354 tab_pane.setEnabledAt (ext_pos,Configuration.get("admin.ext", false));
355 } else {
356 tab_pane.setEnabledAt (ext_pos,Configuration.get("admin.ext",true));
357 }
358 }
359 if (monitor_pos != -1){
360 if (ready) {
361 tab_pane.setEnabledAt (monitor_pos,Configuration.get("admin.monitor", false));
362 } else {
363 tab_pane.setEnabledAt (monitor_pos,Configuration.get("admin.monitor",true));
364 }
365 }
366 if (log_pos != -1){
367 if (ready) {
368 tab_pane.setEnabledAt (log_pos,Configuration.get("admin.log", false));
369 } else {
370 tab_pane.setEnabledAt (log_pos,Configuration.get("admin.log",true));
371 }
372 }
373 }
374 public void setReady (boolean ready){
375
376 this.ready = ready;
377 }
378 }
379}
Note: See TracBrowser for help on using the repository browser.