source: main/trunk/greenstone3/src/java/org/greenstone/admin/GAIManager.java@ 21918

Last change on this file since 21918 was 21918, checked in by sjm84, 14 years ago

Further reorganising folders for GAI extension changes

  • Property svn:keywords set to Author Date Id Revision
File size: 10.7 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;
36import org.greenstone.admin.guiext.ExtPane;
37
38//import java AWT classes
39import java.awt.*;
40import java.awt.event.*;
41import java.io.*;
42import java.net.*;
43import java.util.*;
44import javax.swing.*;
45import javax.swing.event.*;
46import javax.swing.plaf.*;
47
48public class GAIManager
49 extends JFrame
50 implements ActionListener, ChangeListener{
51
52 private Dimension size = null;
53 // The ConfPane contains the configuration details of Greenstone III build and installation
54 public ConfPane conf_pane = null;
55 // The LogPane contains the log details for Tomcat Server used by gsdl3
56 public LogPane log_pane = null;
57 // Not designed yet
58 public ExtPane ext_pane = null;
59 // Not designed yet
60 public JPanel monitor_pane = null;
61
62 static public ImageIcon CONF_ICON = null;
63 static public ImageIcon EXT_ICON = null;
64 static public ImageIcon MONITOR_ICON = null;
65 static public ImageIcon LOG_ICON = null;
66
67 // Create a menu bar in the main Pane
68 public MenuBar menu_bar = null;
69
70 // HelpFrame
71
72 private JPanel previous_pane = null;
73 private JPanel content_pane = null;
74 private JTabbedPane tab_pane = null;
75
76 /** A threaded tab changer to try and avoid NPE on exit. */
77 private TabUpdater tab_updater = null;
78
79 //Contructor
80 public GAIManager(Dimension size){
81 super();
82 this.size = size;
83 this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
84 this.setTitle("GreenStone 3 Administration Tool");
85 /* Add a focus listener to ourselves. Thus if we gain focus when a Modal Dialog should
86 * instead have it, we can try to bring the modal dialog to the front*/
87 //this.addFocusListener(new GAIGUIFocusListener());
88 //display();
89 }
90
91 private class GAIGUIFocusListener
92 extends FocusAdapter {
93 public void focusGained(FocusEvent e) {
94 /* if (ModalDialog.current_modal != null) {
95 ModalDialog.current_modal.makeVisible();
96 ModalDialog.current_modal.toFront();
97 }*/
98 }
99 }
100
101 public void display(){
102 CONF_ICON = new ImageIcon (GAI.images_path + "create.gif");
103 EXT_ICON = new ImageIcon (GAI.images_path + "information.gif");
104 MONITOR_ICON = new ImageIcon (GAI.images_path + "zoom.gif");
105 LOG_ICON = new ImageIcon (GAI.images_path + "history.gif");
106 content_pane = (JPanel) this.getContentPane();
107
108 try {
109 this.setSize(size);
110 //create a menuBar
111 menu_bar = new MenuBar(new MenuListenerImpl());
112 this.setJMenuBar(menu_bar);
113
114 //Create the tabbed pane and put it in the center
115 tab_pane = new JTabbedPane();
116 tab_pane.addChangeListener(this);
117
118 //set up the Configuration Pane
119 if (Configuration.get("admin.conf")){
120 conf_pane = new ConfPane();
121 conf_pane.display();
122 tab_pane.addTab("Configuration", CONF_ICON, conf_pane);
123 tab_pane.setEnabledAt(tab_pane.indexOfComponent(conf_pane),Configuration.get("admin.conf"));
124 }
125
126 //set up the ext Pane
127 if (Configuration.get("admin.ext")){
128 ext_pane = new ExtPane();
129
130 ext_pane.display();
131 tab_pane.addTab("Extensions", EXT_ICON, ext_pane);
132 tab_pane.setEnabledAt(tab_pane.indexOfComponent(ext_pane),Configuration.get("admin.ext"));
133 }
134
135 //set up the Monitor Pane
136 if (Configuration.get("admin.monitor")){
137 monitor_pane = new JPanel();
138 //monitor_pane.display();
139 tab_pane.addTab("Monitor", MONITOR_ICON, monitor_pane);
140 tab_pane.setEnabledAt(tab_pane.indexOfComponent(monitor_pane),Configuration.get("admin.monitor"));
141 }
142
143 //set up the Log Pane
144 if (Configuration.get("admin.log")){
145 log_pane = new LogPane();
146 log_pane.display();
147 tab_pane.addTab("Log", LOG_ICON, log_pane);
148 tab_pane.setEnabledAt(tab_pane.indexOfComponent(log_pane),Configuration.get("admin.log"));
149 }
150 content_pane.setLayout(new BorderLayout());
151 content_pane.add(tab_pane, BorderLayout.CENTER);
152 pack();
153 setVisible(true);
154 } catch (Exception e){
155 e.printStackTrace();
156 System.exit(1);
157 }
158 }
159
160 /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed
161 * when an action has occured. In this case we are listening to actions from the menu-bar, and should
162 * react appropriately.
163 * @param event An <strong>ActionEvent</strong> containing information about the action that has occured.
164 */
165
166 public void actionPerformed (ActionEvent event){
167 Object esrc = event.getSource();
168 if (esrc == menu_bar.file_exit){
169 if (conf_pane.configurationChanged()) {
170 // prompt users for save
171 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);
172 if ( result == JOptionPane.YES_OPTION) {
173 conf_pane.save();
174 }
175 }
176 exit();
177 }
178 else if (esrc == menu_bar.file_save){
179 /* sliently and Globally save Project and Site configuration*/
180 conf_pane.save();
181 }
182 else if (esrc == menu_bar.help_conf){
183 }
184 else if (esrc == menu_bar.help_ext){
185 }
186 else if (esrc == menu_bar.help_monitor){
187 }
188 else if (esrc == menu_bar.help_log){
189 }
190 else if (esrc == menu_bar.help_about) {
191 }
192 }
193
194
195 public void destory (){
196 // Destroying create pane ensures the latest log has been closed
197 //if (status_pane != null) {
198 //}
199 }
200 /**Overridden from JFrame so we can exit safely when window is closed
201 *(or destroyed). @param event A <strong>WindowEvent</strong> containing
202 *information about the event that fired this call.
203 */
204 protected void processWindowEvent(WindowEvent event) {
205 if(event.getID() == WindowEvent.WINDOW_CLOSING) {
206 exit();
207 }
208 }
209
210
211 /** Listens to actions upon the menu bar, and if it detects a click over
212 *the help menu brings the help window to the front if it has become hidden.
213 */
214 private class MenuListenerImpl
215 implements MenuListener {
216 public void menuCanceled (MenuEvent e) {
217 }
218
219 public void menuDeselected (MenuEvent e){
220 }
221
222 public void menuSelected (MenuEvent e){
223 if (e.getSource() == menu_bar.file_exit) {
224 exit();
225 }
226
227 if (e.getSource() == menu_bar.help){
228 if (menu_bar.help.isSelected()){
229 menu_bar.help.doClick(10);
230 }
231 }
232 }
233 }
234
235
236 /** This method ensures that all the things needing saving
237 * are saved before GAIManager.exit() is called.
238 */
239 public void exit() {
240 System.exit(0);
241 }
242
243
244 /** Any implementation of ChangeListener must include this method
245 **so we can be informed when the state of one of the registered
246 **objects changes. In this case we are listening to view changes
247 **within the tabbed pane.
248 * @param event A ChangeEvent containing information about the event that fired this call.
249 */
250 public void stateChanged(ChangeEvent event) {
251 if(previous_pane != null) {
252 }
253
254 //menu_bar.tabSelected(tab_pane.getSelectedIndex());
255 int selected_index = tab_pane.getSelectedIndex();
256 if (selected_index == tab_pane.indexOfComponent(log_pane)) {
257 log_pane.gainFocus();
258 }
259 else if (selected_index == tab_pane.indexOfComponent(conf_pane)) {
260 conf_pane.gainFocus();
261 }
262 previous_pane = (JPanel) tab_pane.getSelectedComponent();
263 }
264
265 public void modeChanged (int mode){
266 if (log_pane != null){
267 log_pane.modeChanged(mode);
268 }
269 if (conf_pane !=null) {
270 conf_pane.modeChanged(mode);
271 }
272 }
273
274 // public void refresh (int refresh_reason, boolean collection_loaded)
275 public void refresh () {
276 if (log_pane != null ){
277 }
278 }
279
280 public void returnToInitialPane(){
281 if (log_pane != null) {
282 tab_pane.setSelectedComponent(log_pane);
283 }
284 }
285 public void wait(boolean waiting) {
286 Component glass_pane = getGlassPane();
287 if(waiting) {
288 // Show wait cursor.
289 //glass_pane.addMouseListener(mouse_blocker_listener);
290 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
291 glass_pane.setVisible(true);
292 }
293 else {
294 // Hide wait cursor.
295 glass_pane.setVisible(false);
296 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
297 //glass_pane.removeMouseListener(mouse_blocker_listener);
298 }
299 glass_pane = null;
300 }
301
302 private class TabUpdater
303 implements Runnable {
304 private boolean ready = false;
305 private int conf_pos = -1;
306 private int ext_pos = -1;
307 private int monitor_pos = -1;
308 private int log_pos = -1;
309 private JTabbedPane tab_pane = null;
310
311 public TabUpdater (JTabbedPane tab_pane, boolean ready){
312 this.ready = ready;
313 this.tab_pane = tab_pane;
314 conf_pos = tab_pane.indexOfComponent(conf_pane);
315 ext_pos = tab_pane.indexOfComponent(ext_pane);
316 monitor_pos = tab_pane.indexOfComponent(monitor_pane);
317 log_pos = tab_pane.indexOfComponent(log_pane);
318 }
319
320 public void run() {
321 if (conf_pos != -1){
322 if (ready) {
323 tab_pane.setEnabledAt (conf_pos,Configuration.get("admin.conf"));
324 } else {
325 tab_pane.setEnabledAt (conf_pos,false);
326 }
327 }
328 if (ext_pos != -1){
329 if (ready) {
330 tab_pane.setEnabledAt (ext_pos,Configuration.get("admin.ext"));
331 } else {
332 tab_pane.setEnabledAt (ext_pos,false);
333 }
334 }
335 if (monitor_pos != -1){
336 if (ready) {
337 tab_pane.setEnabledAt (monitor_pos,Configuration.get("admin.monitor"));
338 } else {
339 tab_pane.setEnabledAt (monitor_pos,false);
340 }
341 }
342 if (log_pos != -1){
343 if (ready) {
344 tab_pane.setEnabledAt (log_pos,Configuration.get("admin.log"));
345 } else {
346 tab_pane.setEnabledAt (log_pos,false);
347 }
348 }
349 }
350 public void setReady (boolean ready){
351
352 this.ready = ready;
353 }
354 }
355}
Note: See TracBrowser for help on using the repository browser.