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

Last change on this file since 18113 was 18113, checked in by cc108, 15 years ago

add a new extension pane to admin tool

  • 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.gui.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 ext_pane.display();
130 tab_pane.addTab("Extensions", EXT_ICON, ext_pane);
131 tab_pane.setEnabledAt(tab_pane.indexOfComponent(ext_pane),Configuration.get("admin.ext"));
132 }
133
134 //set up the Monitor Pane
135 if (Configuration.get("admin.monitor")){
136 monitor_pane = new JPanel();
137 //monitor_pane.display();
138 tab_pane.addTab("Monitor", MONITOR_ICON, monitor_pane);
139 tab_pane.setEnabledAt(tab_pane.indexOfComponent(monitor_pane),Configuration.get("admin.monitor"));
140 }
141
142 //set up the Log Pane
143 if (Configuration.get("admin.log")){
144 log_pane = new LogPane();
145 log_pane.display();
146 tab_pane.addTab("Log", LOG_ICON, log_pane);
147 tab_pane.setEnabledAt(tab_pane.indexOfComponent(log_pane),Configuration.get("admin.log"));
148 }
149 content_pane.setLayout(new BorderLayout());
150 content_pane.add(tab_pane, BorderLayout.CENTER);
151 pack();
152 setVisible(true);
153 } catch (Exception e){
154 e.printStackTrace();
155 System.exit(1);
156 }
157 }
158
159 /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed
160 * when an action has occured. In this case we are listening to actions from the menu-bar, and should
161 * react appropriately.
162 * @param event An <strong>ActionEvent</strong> containing information about the action that has occured.
163 */
164
165 public void actionPerformed (ActionEvent event){
166 Object esrc = event.getSource();
167 if (esrc == menu_bar.file_exit){
168 if (conf_pane.configurationChanged()) {
169 // prompt users for save
170 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);
171 if ( result == JOptionPane.YES_OPTION) {
172 conf_pane.save();
173 }
174 }
175 exit();
176 }
177 else if (esrc == menu_bar.file_save){
178 /* sliently and Globally save Project and Site configuration*/
179 conf_pane.save();
180 }
181 else if (esrc == menu_bar.help_conf){
182 }
183 else if (esrc == menu_bar.help_ext){
184 }
185 else if (esrc == menu_bar.help_monitor){
186 }
187 else if (esrc == menu_bar.help_log){
188 }
189 else if (esrc == menu_bar.help_about) {
190 }
191 }
192
193
194 public void destory (){
195 // Destroying create pane ensures the latest log has been closed
196 //if (status_pane != null) {
197 //}
198 }
199 /**Overridden from JFrame so we can exit safely when window is closed
200 *(or destroyed). @param event A <strong>WindowEvent</strong> containing
201 *information about the event that fired this call.
202 */
203 protected void processWindowEvent(WindowEvent event) {
204 if(event.getID() == WindowEvent.WINDOW_CLOSING) {
205 exit();
206 }
207 }
208
209
210 /** Listens to actions upon the menu bar, and if it detects a click over
211 *the help menu brings the help window to the front if it has become hidden.
212 */
213 private class MenuListenerImpl
214 implements MenuListener {
215 public void menuCanceled (MenuEvent e) {
216 }
217
218 public void menuDeselected (MenuEvent e){
219 }
220
221 public void menuSelected (MenuEvent e){
222 if (e.getSource() == menu_bar.file_exit) {
223 exit();
224 }
225
226 if (e.getSource() == menu_bar.help){
227 if (menu_bar.help.isSelected()){
228 menu_bar.help.doClick(10);
229 }
230 }
231 }
232 }
233
234
235 /** This method ensures that all the things needing saving
236 * are saved before GAIManager.exit() is called.
237 */
238 public void exit() {
239 System.exit(0);
240 }
241
242
243 /** Any implementation of ChangeListener must include this method
244 **so we can be informed when the state of one of the registered
245 **objects changes. In this case we are listening to view changes
246 **within the tabbed pane.
247 * @param event A ChangeEvent containing information about the event that fired this call.
248 */
249 public void stateChanged(ChangeEvent event) {
250 if(previous_pane != null) {
251 }
252
253 //menu_bar.tabSelected(tab_pane.getSelectedIndex());
254 int selected_index = tab_pane.getSelectedIndex();
255 if (selected_index == tab_pane.indexOfComponent(log_pane)) {
256 log_pane.gainFocus();
257 }
258 else if (selected_index == tab_pane.indexOfComponent(conf_pane)) {
259 conf_pane.gainFocus();
260 }
261 previous_pane = (JPanel) tab_pane.getSelectedComponent();
262 }
263
264 public void modeChanged (int mode){
265 if (log_pane != null){
266 log_pane.modeChanged(mode);
267 }
268 if (conf_pane !=null) {
269 conf_pane.modeChanged(mode);
270 }
271 }
272
273 // public void refresh (int refresh_reason, boolean collection_loaded)
274 public void refresh () {
275 if (log_pane != null ){
276 }
277 }
278
279 public void returnToInitialPane(){
280 if (log_pane != null) {
281 tab_pane.setSelectedComponent(log_pane);
282 }
283 }
284 public void wait(boolean waiting) {
285 Component glass_pane = getGlassPane();
286 if(waiting) {
287 // Show wait cursor.
288 //glass_pane.addMouseListener(mouse_blocker_listener);
289 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
290 glass_pane.setVisible(true);
291 }
292 else {
293 // Hide wait cursor.
294 glass_pane.setVisible(false);
295 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
296 //glass_pane.removeMouseListener(mouse_blocker_listener);
297 }
298 glass_pane = null;
299 }
300
301 private class TabUpdater
302 implements Runnable {
303 private boolean ready = false;
304 private int conf_pos = -1;
305 private int ext_pos = -1;
306 private int monitor_pos = -1;
307 private int log_pos = -1;
308 private JTabbedPane tab_pane = null;
309
310 public TabUpdater (JTabbedPane tab_pane, boolean ready){
311 this.ready = ready;
312 this.tab_pane = tab_pane;
313 conf_pos = tab_pane.indexOfComponent(conf_pane);
314 ext_pos = tab_pane.indexOfComponent(ext_pane);
315 monitor_pos = tab_pane.indexOfComponent(monitor_pane);
316 log_pos = tab_pane.indexOfComponent(log_pane);
317 }
318
319 public void run() {
320 if (conf_pos != -1){
321 if (ready) {
322 tab_pane.setEnabledAt (conf_pos,Configuration.get("admin.conf"));
323 } else {
324 tab_pane.setEnabledAt (conf_pos,false);
325 }
326 }
327 if (ext_pos != -1){
328 if (ready) {
329 tab_pane.setEnabledAt (ext_pos,Configuration.get("admin.ext"));
330 } else {
331 tab_pane.setEnabledAt (ext_pos,false);
332 }
333 }
334 if (monitor_pos != -1){
335 if (ready) {
336 tab_pane.setEnabledAt (monitor_pos,Configuration.get("admin.monitor"));
337 } else {
338 tab_pane.setEnabledAt (monitor_pos,false);
339 }
340 }
341 if (log_pos != -1){
342 if (ready) {
343 tab_pane.setEnabledAt (log_pos,Configuration.get("admin.log"));
344 } else {
345 tab_pane.setEnabledAt (log_pos,false);
346 }
347 }
348 }
349 public void setReady (boolean ready){
350
351 this.ready = ready;
352 }
353 }
354}
Note: See TracBrowser for help on using the repository browser.