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

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

remove unused method

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