source: greenstone3/trunk/src/java/org/greenstone/admin/gui/ExtPane.java@ 18141

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

new extension pane class

File size: 19.8 KB
Line 
1package org.greenstone.admin.gui;
2
3import java.awt.*;
4import java.awt.event.*;
5import java.io.*;
6import java.lang.reflect.Constructor;
7import java.lang.reflect.Method;
8import java.util.*;
9
10import javax.swing.*;
11import javax.swing.event.*;
12import javax.swing.tree.*;
13
14import javax.xml.parsers.DocumentBuilder;
15import javax.xml.parsers.DocumentBuilderFactory;
16import javax.xml.transform.OutputKeys;
17import javax.xml.transform.Transformer;
18import javax.xml.transform.TransformerFactory;
19import javax.xml.transform.dom.DOMSource;
20import javax.xml.transform.stream.StreamResult;
21
22import org.greenstone.admin.GAIManager;
23import org.greenstone.admin.GAI;
24import org.greenstone.admin.Configuration;
25import org.greenstone.gsdl3.util.GSPath;
26import org.greenstone.gsdl3.util.GlobalProperties;
27
28import org.w3c.dom.Document;
29import org.w3c.dom.Element;
30import org.w3c.dom.Node;
31import org.w3c.dom.NodeList;
32import org.w3c.dom.Text;
33
34
35public class ExtPane extends JPanel {
36
37 /* The pane to demonstrate extension information*/
38
39 protected JSplitPane main_ext_pane = null;
40
41 /** The panel that contains a log_list */
42 private JPanel extensionList_pane = null;
43
44 /** The panel that contains the log content. */
45 protected static JPanel extensionContent_pane = null;
46
47 /** The List showing all the log files concerned. */
48 //protected JList extension_list=null;
49
50 /** The label at the top of the logList_pane. */
51 protected JLabel extensionList_label = null;
52
53 /** The label shown at the top of the logContent Pane. */
54 protected JLabel extensionContent_label = null;
55
56 /** The scrollable area into which the log content is placed. */
57 protected JScrollPane description_content = null;
58
59 /* Log TEXT AREA*/
60 protected JTextArea description_textarea = null;
61
62 protected JScrollPane message_content = null;
63
64 /* Log TEXT AREA*/
65 protected static JTextArea message_textarea = null;
66
67 protected static JPanel current_description_pane = null;
68
69 protected JPanel button_pane = null;
70
71 /** Buttons */
72 //protected JButton download_button = null;
73 //protected static JButton pre_configure_button = null;
74 //protected JButton install_button = null;
75 //protected JButton post_configure_button = null;
76 //protected JButton uninstall_button = null;
77 //protected JButton switch_button = null;
78
79 protected static JPanel control_pane = null;
80
81 protected JPanel main_content_pane = null;
82
83 protected JTree extensionTreeList = null;
84
85 protected DefaultMutableTreeNode top = new DefaultMutableTreeNode("Extension List");
86
87 protected HashMap extensionInformation = null;
88
89 protected JPanel extensionContentHeaderPane = null;
90
91 protected String file_location;
92
93 protected final String extension_status_root = "Configuration";
94 protected File extension_status_file = null;
95 protected String extension_file = null;
96
97 /** The various sizes for the screen layout*/
98 static protected Dimension MIN_SIZE = new Dimension( 90, 90);
99 static protected Dimension LIST_SIZE = new Dimension(200, 450);
100 static protected Dimension LOGPANE_SIZE = new Dimension (800,450);
101 static protected int left_padding = 5;
102 static String fileSeparator = File.separator;
103
104 GlobalProperties globalProperty = null;
105
106 GSPath gspath = null;
107
108
109 //WorkingCopy wc;
110
111 public ExtPane() {
112
113 //System.out.println("start");
114 String gsdl3Home = get_GSDL3HOME();
115 //file_location ="/research/cc108/greenstone3Project/ext/extension_project_list.xml";
116 file_location = gsdl3Home+fileSeparator+"ext"+fileSeparator+"extension_project_list.xml";
117 //file_lcoation = = "/research/cc108/greenstone3Project/ext/extension_project_list.xml
118 // create all the necessary panes
119 control_pane = new JPanel();
120 button_pane = new JPanel();
121 current_description_pane = new JPanel();
122 extensionContentHeaderPane = new JPanel();
123 extensionInformation = new HashMap();
124
125 //wc = new WorkingCopy();
126
127 // Extension_Pane
128 main_ext_pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
129 main_ext_pane.setPreferredSize(LOGPANE_SIZE);
130
131 // Extension_TextArea
132 description_textarea = new JTextArea();
133 description_textarea.setEditable(false);
134 description_textarea.setLineWrap(true);
135 description_textarea.setWrapStyleWord(true);
136 description_textarea.setMargin(new Insets(0,left_padding,0,0));
137 //description_textarea.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
138
139 message_textarea = new JTextArea();
140 message_textarea.setEditable(false);
141 message_textarea.setAutoscrolls(true);
142 message_textarea.setLineWrap(true);
143 message_textarea.setWrapStyleWord(true);
144 message_textarea.setMargin(new Insets(0,left_padding,0,0));
145
146 /*
147 download_button = new JButton();
148 download_button.setEnabled(false);
149 download_button.setText("Download");
150
151 ActionListener donwloadButton = new ActionListener() {
152 public void actionPerformed(ActionEvent ae) {
153 download_jButton_Adapter(ae);
154 }
155 };
156
157 ActionListener cursorDoIt1 = CursorController.createListener(this, donwloadButton);
158 download_button.addActionListener(cursorDoIt1);
159
160 pre_configure_button = new JButton();
161 pre_configure_button.setEnabled(false);
162 pre_configure_button.setText("Pre-Configuration");
163
164
165 ActionListener preconfigureButton = new ActionListener() {
166 public void actionPerformed(ActionEvent ae) {
167 preConfigure_jButton_Adapter(ae);
168 }
169 };
170
171 ActionListener cursorDoIt3 = CursorController.createListener(this,preconfigureButton);
172 pre_configure_button.addActionListener(cursorDoIt3);
173
174
175 install_button = new JButton();
176 install_button.setEnabled(false);
177 install_button.setText("Compile/Install");
178
179 post_configure_button = new JButton();
180 post_configure_button.setText("Post-Configuration");
181 post_configure_button.setEnabled(false);
182
183 uninstall_button = new JButton();
184 uninstall_button.setText("Uninstall");
185 uninstall_button.setEnabled(false);
186
187 switch_button = new JButton();
188 switch_button.setText("Switch");
189 switch_button.setEnabled(false);
190
191
192 ActionListener switchButton = new ActionListener() {
193 public void actionPerformed(ActionEvent ae) {
194 switch_jButton_Adapter(ae);
195 }
196 };
197
198 ActionListener cursorDoIt2 = CursorController.createListener(this, switchButton);
199 switch_button.addActionListener(cursorDoIt2);
200 */
201 }
202
203
204 public void actionPerformed(ActionEvent event) {
205 }
206
207
208 /** This method is callsed to actually layout the components.*/
209 public void display() {
210
211 load_Admin_UI();
212 HashMap projectNameMap = getProjectList();
213 Set s = projectNameMap.keySet();
214 Iterator it = s.iterator();
215 int i = 0;
216
217 while(it.hasNext()){
218 String projectNameGroup = (String)it.next();
219 ArrayList alist = (ArrayList)projectNameMap.get(projectNameGroup);
220 DefaultMutableTreeNode projecti = new DefaultMutableTreeNode (projectNameGroup);
221
222 for (int j = 0; j< alist.size(); j++){
223 String projectName = (String)alist.get(j);
224 DefaultMutableTreeNode projectNameGroupj = new DefaultMutableTreeNode (projectName);
225 projecti.add(projectNameGroupj);
226 }
227 top.add(projecti);
228 i++;
229 }
230
231 extensionTreeList = new JTree(top);
232 extensionTreeList.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
233 extensionTreeList.addTreeSelectionListener(new ConfTreeListener());
234
235 // extensionList_Pane
236 extensionList_pane = new JPanel();
237 extensionList_pane.setBorder(BorderFactory.createLoweredBevelBorder());
238 extensionList_label = new JLabel();
239 extensionList_label.setOpaque(true);
240 extensionList_label.setBackground(Configuration.getColor("coloring.workspace_heading_background"));
241 extensionList_label.setForeground(Configuration.getColor("coloring.workspace_heading_foreground"));
242 extensionList_label.setText("Available Extensions");
243 extensionList_label.setBorder(BorderFactory.createEmptyBorder(0, left_padding, 0, 0));
244 // extensionContent_Pane
245 extensionContent_pane = new JPanel();
246 extensionContent_pane.setBorder(BorderFactory.createLoweredBevelBorder());
247 extensionContent_pane.setBackground(Configuration.getColor("coloring.workspace_selection_background"));
248 extensionContent_pane.setForeground(Configuration.getColor("coloring.workspace_selection_foreground"));
249
250 extensionContent_label = new JLabel();
251 extensionContent_label.setBorder(BorderFactory.createEmptyBorder(0, left_padding, 0, 0));
252 extensionContent_label.setOpaque(false);
253 extensionContent_label.setBackground(Configuration.getColor("coloring.workspace_selection_background"));
254 extensionContent_label.setForeground(Configuration.getColor("coloring.workspace_selection_foreground"));
255 extensionContent_label.setText("Extension Content");
256 main_content_pane = new JPanel();
257
258 // TEXTAREA Layout
259 description_content = new JScrollPane(description_textarea);
260 description_content .setName("description_content");
261 //description_content.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
262 message_content = new JScrollPane(message_textarea);
263
264 control_pane.setLayout (new BorderLayout());
265 control_pane.setBorder(BorderFactory.createEmptyBorder(05,10,5,10));
266 control_pane.setPreferredSize(new Dimension(200,50));
267 control_pane.setSize(new Dimension(200,50));
268 control_pane.add (button_pane, BorderLayout.CENTER);
269
270 // Layout Components
271 extensionList_pane.setLayout(new BorderLayout());
272 extensionList_pane.add(extensionTreeList, BorderLayout.CENTER);
273 extensionList_pane.add(extensionList_label, BorderLayout.NORTH);
274
275 main_content_pane.setLayout(new BorderLayout());
276 main_content_pane.setPreferredSize(new Dimension(600, 200));
277 main_content_pane.setSize(new Dimension(600, 200));
278 main_content_pane.add(control_pane, BorderLayout.WEST);
279 main_content_pane.add(message_content, BorderLayout.CENTER);
280
281 //extensionContentHeaderPane.setLayout(new FlowLayout());
282 //extensionContentHeaderPane.add(extensionContent_label);
283 //extensionContentHeaderPane.add(switch_button);
284
285 extensionContent_pane.setLayout(new BorderLayout());
286 extensionContent_pane.add(main_content_pane,BorderLayout.SOUTH);
287 extensionContent_pane.add(extensionContent_label, BorderLayout.NORTH);
288 extensionContent_pane.add(description_content, BorderLayout.CENTER);
289
290 main_ext_pane.add(extensionList_pane, JSplitPane.LEFT);
291 main_ext_pane.add(extensionContent_pane, JSplitPane.RIGHT);
292 main_ext_pane.setDividerLocation(LIST_SIZE.width - 10);
293
294 this.setLayout(new BorderLayout());
295 this.add(main_ext_pane, BorderLayout.CENTER);
296
297 }
298
299
300 protected Element getRootElement(){
301
302 Element rootNode = null;
303
304 try{
305 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
306 DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
307 Document doc = docBuilder.newDocument();
308 doc = docBuilder.parse (new File(file_location));
309 rootNode = doc.getDocumentElement();
310 return rootNode;
311
312 }catch (Exception e) {
313 e.printStackTrace();
314 return null;
315 }
316 }
317
318 protected HashMap getProjectList(){
319
320 HashMap projectGroupMap = new HashMap();
321 Element rootNode = getRootElement();
322 NodeList projectList = rootNode.getElementsByTagName(adminUI_Pane.EXTENSION);
323
324 for(int i = 0; i<projectList.getLength(); i++){
325
326 Element projectNode = (Element)projectList.item(i);
327 NodeList nameList = projectNode.getElementsByTagName(adminUI_Pane.NAME);
328 String name = nameList.item(0).getChildNodes().item(0).getNodeValue();
329
330 NodeList groupList = projectNode.getElementsByTagName(adminUI_Pane.GROUP);
331 String group = groupList.item(0).getChildNodes().item(0).getNodeValue();
332
333 if(projectGroupMap.containsKey(group)){
334 ArrayList alist = (ArrayList)projectGroupMap.get(group);
335 alist.add(name);
336 projectGroupMap.put(group, alist);
337 }
338 else{
339 ArrayList alist = new ArrayList();
340 alist.add(name);
341 projectGroupMap.put(group, alist);
342 }
343 }
344 return projectGroupMap;
345 }
346
347 public String get_GSDL3HOME(){
348
349 String gsdl3Home = globalProperty.getGSDL3Home();
350 String os = "linux";
351
352 if(fileSeparator.equals("\\")){
353 gsdl3Home = gsdl3Home.replaceAll("\\", "/");
354 os = "windows";
355 }
356
357 gsdl3Home = gspath.removeLastLink(gsdl3Home);
358
359 if(os.equals("windows")){
360 gsdl3Home = gsdl3Home.replaceAll("/", "\\");
361 }
362 return gsdl3Home;
363 }
364
365 protected class ConfTreeListener implements TreeSelectionListener{
366
367 public void valueChanged (TreeSelectionEvent e){
368
369 String option = new String();
370
371 try{
372 option = extensionTreeList.getLastSelectedPathComponent().toString();
373 }catch(Exception ex){
374
375 }
376
377 if(extensionInformation.containsKey(option)){
378
379 try{
380 extensionContent_pane.remove(2);
381 extensionContent_pane.validate();
382 extensionContent_pane.repaint();
383
384 ArrayList alist = (ArrayList) extensionInformation.get(option);
385 Class c = (Class)alist.get(0);
386 Object o = (Object)alist.get(1);
387
388
389
390
391 JPanel cardLayoutPane = new JPanel(new CardLayout());
392 Method get_Description_Pane = c.getMethod("getDescriptionPane", new Class[0]);
393 JPanel descriptionPane = (JPanel)get_Description_Pane.invoke(o,new Object[0]);
394 Method get_Control_Pane = c.getMethod("getControlPane", new Class[0]);
395 JPanel controlPane = (JPanel)get_Control_Pane.invoke(o,new Object[0]);
396
397 cardLayoutPane.add(descriptionPane, "Description");
398 cardLayoutPane.add(controlPane, "Control");
399 current_description_pane = cardLayoutPane;
400
401
402 control_pane.remove(0);
403 control_pane.revalidate();
404 control_pane.repaint();
405
406 button_pane = getProjetcButtonPane();
407 control_pane.add(button_pane);
408 control_pane.revalidate();
409 control_pane.repaint();
410
411 Method isConfigurable = c.getMethod("isConfigurable", new Class[0]);
412 Boolean configurable = (Boolean) isConfigurable.invoke(o,new Object[0]);
413
414 extensionContent_label.setText(option);
415
416 extensionContent_pane.add(current_description_pane, BorderLayout.CENTER);
417 extensionContent_pane.validate();
418 extensionContent_pane.repaint();
419
420 Class[] types = new Class[] { String.class};
421 Method getStatus = c.getMethod("getCommandStatus", types);
422
423 Object[] args = new Object[] { "install"};
424 Boolean bv = (Boolean)(getStatus.invoke(o, args));
425 boolean status = bv.booleanValue();
426
427 if(status){
428 updateExtensionContentPane();
429 }
430 /*
431 *
432 *
433 * updateExtensionContentPane
434 */
435
436 }catch(Exception ex){
437 ex.printStackTrace();
438 description_textarea.setText("");
439 description_textarea.append("Sorry, this extension is not available!");
440 extensionContent_pane.add(description_content, BorderLayout.CENTER);
441 extensionContent_pane.validate();
442 extensionContent_pane.repaint();
443 }
444 }
445 else{
446 if(control_pane.getComponentCount()>0){
447 System.out.println("remove");
448 control_pane.remove(0);
449 control_pane.revalidate();
450 control_pane.repaint();
451 control_pane.add(new JPanel());
452 control_pane.revalidate();
453 control_pane.repaint();
454 }
455
456 if(extensionContent_pane.getComponentCount()>0){
457
458 extensionContent_label.setText("Extension Content");
459 extensionContent_pane.remove(2);
460 extensionContent_pane.revalidate();
461 extensionContent_pane.repaint();
462
463
464 JTextArea ja= new JTextArea();
465 JScrollPane jp = new JScrollPane(ja);
466 extensionContent_pane.add(jp);
467 extensionContent_pane.revalidate();
468 extensionContent_pane.repaint();
469
470
471
472 }
473 }
474 }
475 }
476
477
478
479
480 public JPanel getProjetcButtonPane(){
481 String option = extensionTreeList.getLastSelectedPathComponent().toString();
482 JPanel buttonPane = new JPanel();
483 try{
484
485 ArrayList alist = (ArrayList) extensionInformation.get(option);
486 Class c = (Class)alist.get(0);
487 Object o = (Object)alist.get(1);
488
489 Method a = c.getMethod("getButtonPane", new Class[0]);
490 buttonPane = (JPanel)a.invoke(o, new Object[0]);
491
492
493 }catch (Exception ex){
494 ex.printStackTrace();
495 }
496 return buttonPane;
497 }
498
499 public void load_Admin_UI(){
500
501 Element rootNode = getRootElement();
502
503 NodeList projectList = rootNode.getElementsByTagName(adminUI_Pane.EXTENSION);
504
505 for(int i = 0; i<projectList.getLength(); i++){
506
507 Element projectNode = (Element)projectList.item(i);
508 ArrayList alist = new ArrayList();
509 NodeList nameList = projectNode.getElementsByTagName(adminUI_Pane.NAME);
510 String name = nameList.item(0).getChildNodes().item(0).getNodeValue();
511
512 NodeList uiList = projectNode.getElementsByTagName(adminUI_Pane.ADMIN_UI);
513 String admin_ui = uiList.item(0).getChildNodes().item(0).getNodeValue();
514
515 try{
516 Class c = Class.forName(admin_ui);
517 Class[] paramTypes = {String.class};
518 Constructor ct = c.getConstructor(paramTypes);
519 Object[] paramList = {name};
520
521 Object theNewObject = (Object)ct.newInstance(paramList);
522 alist.add(c);
523 alist.add(theNewObject);
524 extensionInformation.put(name, alist);
525 }catch (Exception ex){
526 ex.printStackTrace();
527 }
528
529 }
530 }
531
532 public static void updateButtonPane(JPanel pane){
533 control_pane.remove(0);
534 control_pane.revalidate();
535 control_pane.repaint();
536 control_pane.add(pane);
537 }
538
539 public static void updateExtensionContentPane(){
540 CardLayout cl = (CardLayout)( current_description_pane.getLayout());
541 cl.next(current_description_pane);
542
543 }
544
545 /*
546 private void updateStatus(String project_name, String action){
547
548 try{
549 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
550 DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
551 Document doc = docBuilder.newDocument();
552 Element root = doc.createElement(extension_status_root);
553
554 boolean fileExist = extension_status_file.exists();
555
556 if(!fileExist){
557 extension_status_file = new File (extension_file);
558 root = doc.createElement(extension_status_root);
559 }
560 else{
561 doc = docBuilder.parse (extension_status_file);
562 root = doc.getDocumentElement();
563 }
564
565
566 TransformerFactory tf = TransformerFactory.newInstance();
567 Transformer transformer= tf.newTransformer();
568 DOMSource source= new DOMSource(root);
569 transformer.setOutputProperty(OutputKeys.INDENT,"yes");
570
571 Writer pwx= new BufferedWriter(new OutputStreamWriter(new FileOutputStream(extension_status_file),"UTF-8"));
572 StreamResult result= new StreamResult(pwx);
573 transformer.transform(source,result);
574 pwx.close();
575
576 root = null;
577 docBuilderFactory = null;
578 docBuilder = null;
579 doc = null;
580
581 }catch (Exception e) {
582 System.out.println(e);
583 }
584 }*/
585
586}
587
588/*
589class SVNDownloadThread extends Thread {
590
591 JTextArea _messageTextArea;
592 WorkingCopy _workingCopy;
593 ExtPane _extPane;
594 String _URL;
595 String _destination;
596
597 public SVNDownloadThread (JTextArea messageArea, WorkingCopy working_copy, ExtPane ext_pane, String svnURL, String destination) {
598 _workingCopy= working_copy;
599 _messageTextArea = messageArea;
600 _extPane = ext_pane;
601 _URL = svnURL;
602 _destination = destination;
603 }
604
605 public void run() {
606 try{
607 _workingCopy.Download(_messageTextArea, _extPane.message_content, _URL, _destination);
608 }catch(Exception ex){}
609 }
610}
611*/
612
613class ProjectGroup{
614
615 protected String groupName = null;
616 protected ArrayList nameList = null;
617
618 public ProjectGroup(){
619 nameList = new ArrayList();
620 }
621
622 public void setGroupName(String name){
623 groupName = name;
624 }
625
626 public String getGroupName(){
627 return groupName;
628 }
629
630 public void addGroupName(String name){
631 nameList.add(name);
632 }
633
634 public ArrayList getGroupNameList(){
635 return nameList;
636 }
637}
Note: See TracBrowser for help on using the repository browser.