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

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

change the snytax of regular expression

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