1 | package org.greenstone.admin.gui;
|
---|
2 |
|
---|
3 | import java.awt.Insets;
|
---|
4 | import java.io.File;
|
---|
5 |
|
---|
6 | import javax.swing.JPanel;
|
---|
7 | import javax.swing.JScrollPane;
|
---|
8 | import javax.swing.JTextArea;
|
---|
9 | import javax.xml.parsers.DocumentBuilder;
|
---|
10 | import javax.xml.parsers.DocumentBuilderFactory;
|
---|
11 |
|
---|
12 | import org.greenstone.gsdl3.util.GSPath;
|
---|
13 | import org.greenstone.gsdl3.util.GlobalProperties;
|
---|
14 | import org.w3c.dom.*;
|
---|
15 |
|
---|
16 | public abstract class adminUI_Pane {
|
---|
17 |
|
---|
18 | static JScrollPane description_pane;
|
---|
19 | static JPanel main_pane;
|
---|
20 | static JPanel control_pane;
|
---|
21 | static JTextArea descriptionTextArea;
|
---|
22 | static String description;
|
---|
23 |
|
---|
24 | JPanel button_pane;
|
---|
25 | String extension_name;
|
---|
26 | String destination_folder;
|
---|
27 | String url;
|
---|
28 | String group;
|
---|
29 | String download_type;
|
---|
30 | Boolean configurable;
|
---|
31 |
|
---|
32 | static final String EXTENSION = "extension";
|
---|
33 | static final String GROUP = "group";
|
---|
34 | static final String ADMIN_UI = "admin_ui";
|
---|
35 | static final String NAME = "name";
|
---|
36 | static final String DOWNLOAD = "download";
|
---|
37 | static final String INSTALL = "install";
|
---|
38 | static final String UNINSTALL = "uninstall";
|
---|
39 | static final String ENABLE = "enable";
|
---|
40 | static final String DISABLE = "disable";
|
---|
41 | static final String DESTINATION = "destination";
|
---|
42 | static final String DESCRIPTION = "description";
|
---|
43 | static final String PROPERTY = "property";
|
---|
44 | static final String STEP ="step";
|
---|
45 |
|
---|
46 | GlobalProperties globalProperty = null;
|
---|
47 | String fileSeparator = File.separator;
|
---|
48 | GSPath gspath = null;
|
---|
49 |
|
---|
50 | public adminUI_Pane(){
|
---|
51 |
|
---|
52 | }
|
---|
53 |
|
---|
54 | public void setup(){
|
---|
55 |
|
---|
56 | descriptionTextArea.setText("");
|
---|
57 | description = loadDescription(extension_name);
|
---|
58 | descriptionTextArea = new JTextArea();
|
---|
59 | descriptionTextArea.setText("");
|
---|
60 | descriptionTextArea.append(description);
|
---|
61 | descriptionTextArea.setEditable(false);
|
---|
62 | descriptionTextArea.setLineWrap(true);
|
---|
63 | descriptionTextArea.setWrapStyleWord(true);
|
---|
64 | descriptionTextArea.setMargin(new Insets(0,ExtPane.left_padding,0,0));
|
---|
65 |
|
---|
66 | description_pane = new JScrollPane(descriptionTextArea);
|
---|
67 | description_pane.setAutoscrolls(true);
|
---|
68 | }
|
---|
69 |
|
---|
70 | public JPanel getControlPane(){
|
---|
71 | return control_pane;
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | public String get_GSDL3HOME(){
|
---|
76 |
|
---|
77 | String gsdl3Home = globalProperty.getGSDL3Home();
|
---|
78 | String os = "linux";
|
---|
79 |
|
---|
80 | if(fileSeparator.equals("\\")){
|
---|
81 | gsdl3Home = gsdl3Home.replace("\\", "/");
|
---|
82 | os = "windows";
|
---|
83 | }
|
---|
84 |
|
---|
85 | gsdl3Home = gspath.removeLastLink(gsdl3Home);
|
---|
86 |
|
---|
87 | if(os.equals("windows")){
|
---|
88 | gsdl3Home = gsdl3Home.replace("/", "\\");
|
---|
89 | }
|
---|
90 | return gsdl3Home;
|
---|
91 | }
|
---|
92 |
|
---|
93 | public String loadDescription(String className){
|
---|
94 |
|
---|
95 | String gsdl3Home = get_GSDL3HOME();
|
---|
96 | Element rootNode = getRootElement(gsdl3Home+fileSeparator+"ext"+fileSeparator+"extension_project_list.xml");
|
---|
97 | NodeList projectNodeList = rootNode.getElementsByTagName(EXTENSION);
|
---|
98 |
|
---|
99 | for(int i = 0; i < projectNodeList.getLength(); i++){
|
---|
100 |
|
---|
101 | Element projectNode = (Element)projectNodeList.item(i);
|
---|
102 | NodeList nameNodeList = projectNode.getElementsByTagName(NAME);
|
---|
103 | String name = nameNodeList.item(0).getChildNodes().item(0).getNodeValue();
|
---|
104 |
|
---|
105 | if(name.equals(className)){
|
---|
106 | NodeList descriptionNodeList = projectNode.getElementsByTagName(DESCRIPTION);
|
---|
107 | description = descriptionNodeList.item(0).getChildNodes().item(0).getNodeValue();
|
---|
108 | }
|
---|
109 | }
|
---|
110 | return description;
|
---|
111 | }
|
---|
112 |
|
---|
113 | protected Element getRootElement(String url){
|
---|
114 |
|
---|
115 | Element rootNode = null;
|
---|
116 | try{
|
---|
117 | DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
|
---|
118 | DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
|
---|
119 | Document doc = docBuilder.newDocument();
|
---|
120 | doc = docBuilder.parse (new File(url));
|
---|
121 | rootNode = doc.getDocumentElement();
|
---|
122 | return rootNode;
|
---|
123 | }catch (Exception e) {
|
---|
124 | e.printStackTrace();
|
---|
125 | return null;
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 | protected abstract Object[][] getConfigureContent();
|
---|
130 |
|
---|
131 | protected abstract Boolean isConfigurable();
|
---|
132 |
|
---|
133 | public JPanel getButtonPane(){
|
---|
134 | return button_pane;
|
---|
135 | }
|
---|
136 | }
|
---|