[18140] | 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 |
|
---|
[18545] | 70 | abstract JPanel getControlPane();
|
---|
[18140] | 71 |
|
---|
[18545] | 72 | abstract JPanel getDescriptionPane();
|
---|
[18140] | 73 |
|
---|
[18545] | 74 | abstract boolean getCommandStatus(String Command);
|
---|
| 75 |
|
---|
[18140] | 76 | public String get_GSDL3HOME(){
|
---|
[18158] | 77 |
|
---|
| 78 | String gsdl3Home = globalProperty.getGSDL3Home();
|
---|
| 79 | String os = "linux";
|
---|
| 80 |
|
---|
| 81 | if(System.getProperty("os.name").toLowerCase().indexOf("windows")!=-1){
|
---|
| 82 | gsdl3Home = gsdl3Home.replaceAll("\\\\", "/");
|
---|
| 83 | os = "windows";
|
---|
| 84 |
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | gsdl3Home = gspath.removeLastLink(gsdl3Home);
|
---|
| 88 |
|
---|
| 89 | if(os.equals("windows")){
|
---|
| 90 | gsdl3Home = gsdl3Home.replaceAll("/", "\\\\");
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | return gsdl3Home;
|
---|
| 94 | }
|
---|
[18140] | 95 |
|
---|
| 96 | public String loadDescription(String className){
|
---|
| 97 |
|
---|
| 98 | String gsdl3Home = get_GSDL3HOME();
|
---|
| 99 | Element rootNode = getRootElement(gsdl3Home+fileSeparator+"ext"+fileSeparator+"extension_project_list.xml");
|
---|
| 100 | NodeList projectNodeList = rootNode.getElementsByTagName(EXTENSION);
|
---|
| 101 |
|
---|
| 102 | for(int i = 0; i < projectNodeList.getLength(); i++){
|
---|
| 103 |
|
---|
| 104 | Element projectNode = (Element)projectNodeList.item(i);
|
---|
| 105 | NodeList nameNodeList = projectNode.getElementsByTagName(NAME);
|
---|
| 106 | String name = nameNodeList.item(0).getChildNodes().item(0).getNodeValue();
|
---|
| 107 |
|
---|
| 108 | if(name.equals(className)){
|
---|
| 109 | NodeList descriptionNodeList = projectNode.getElementsByTagName(DESCRIPTION);
|
---|
| 110 | description = descriptionNodeList.item(0).getChildNodes().item(0).getNodeValue();
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 | return description;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | protected Element getRootElement(String url){
|
---|
| 117 |
|
---|
| 118 | Element rootNode = null;
|
---|
| 119 | try{
|
---|
| 120 | DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
|
---|
| 121 | DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
|
---|
| 122 | Document doc = docBuilder.newDocument();
|
---|
| 123 | doc = docBuilder.parse (new File(url));
|
---|
| 124 | rootNode = doc.getDocumentElement();
|
---|
| 125 | return rootNode;
|
---|
| 126 | }catch (Exception e) {
|
---|
| 127 | e.printStackTrace();
|
---|
| 128 | return null;
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | protected abstract Object[][] getConfigureContent();
|
---|
| 133 |
|
---|
[18545] | 134 | //protected abstract Boolean isConfigurable();
|
---|
[18140] | 135 |
|
---|
[18545] | 136 | abstract JPanel getButtonPane();
|
---|
[18140] | 137 | }
|
---|