Changeset 22185 for main/trunk/greenstone3
- Timestamp:
- 2010-05-27T16:29:00+12:00 (14 years ago)
- Location:
- main/trunk/greenstone3/src/java/org/greenstone/admin/guiext
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/admin/guiext/Command.java
r22063 r22185 32 32 } 33 33 else{ 34 _osCommands.put(os, ExtXMLHelper.getValueFromSingleElement(currentCommand, true));34 _osCommands.put(os, ExtXMLHelper.getValueFromSingleElement(currentCommand, false)); 35 35 } 36 36 } -
main/trunk/greenstone3/src/java/org/greenstone/admin/guiext/Option.java
r21991 r22185 1 1 package org.greenstone.admin.guiext; 2 3 import java.lang.reflect.Constructor; 4 import java.lang.reflect.Method; 5 6 import javax.swing.ImageIcon; 7 import javax.swing.JTable; 8 9 import org.greenstone.admin.GAI; 2 10 3 11 import org.w3c.dom.Element; … … 5 13 public class Option 6 14 { 7 String _name = null; 8 String _id = null; 9 String _value = null; 10 OptionList _parent = null; 15 protected String _type = null; 16 protected String _name = null; 17 protected String _id = null; 18 protected String _value = null; 19 protected OptionList _parent = null; 20 21 protected Object _classObject = null; 22 protected Method _checkMethod = null; 23 24 protected ImageIcon _image = null; 25 26 private boolean _canCheck = false; 27 private int _checkResult = -1; 28 29 private final String GOOD_ICON = GAI.getGSDL3Home() + System.getProperty("file.separator") + "resources" + System.getProperty("file.separator") + "images" + System.getProperty("file.separator") + "icongreentick.png"; 30 private final String BAD_ICON = GAI.getGSDL3Home() + System.getProperty("file.separator") + "resources" + System.getProperty("file.separator") + "images" + System.getProperty("file.separator") + "iconredexclamation.png"; 31 private final String ERROR_ICON = GAI.getGSDL3Home() + System.getProperty("file.separator") + "resources" + System.getProperty("file.separator") + "images" + System.getProperty("file.separator") + "iconorangetriange.png"; 11 32 12 33 public Option(Element optionElement, OptionList parent) … … 30 51 _value = ""; 31 52 } 53 54 String checkClass = optionElement.getAttribute("checkClass"); 55 String checkMethod = optionElement.getAttribute("checkMethod"); 56 57 if(!checkClass.equals("") && !checkMethod.equals("")){ 58 loadCheckMethod(checkClass, checkMethod); 59 } 60 61 performCheck(); 62 63 _type = optionElement.getAttribute("type"); 64 65 if(!(_type.equals("") || _type.equals("password") || _type.equals("filebrowse") || _type.equals("folderbrowse"))){ 66 System.err.println("This option element specifies a type that is not \"password\", \"filebrowse\" or \"folderbrowse\""); 67 } 32 68 } 33 69 else{ … … 35 71 } 36 72 } 73 74 private void loadCheckMethod(String checkClassString, String checkMethodString) 75 { 76 _parent.getParent().getParent().getParent().loadGuiExtFile(); 77 78 Class checkClass = null; 79 try{ 80 checkClass = Class.forName(checkClassString); 81 } 82 catch(Exception ex){ 83 System.err.println("Could not get an instance of the check class, either the class name is incorrect or the class does not exist inside the guiext.jar file"); 84 return; 85 } 86 87 try{ 88 Constructor classConstructor = checkClass.getConstructor(new Class[0]); 89 _classObject = classConstructor.newInstance(new Object[0]); 90 } 91 catch(Exception ex){ 92 System.err.println("Could not instantiate the check class, either the class name is incorrect or the class does not exist inside the guiext.jar file"); 93 return; 94 } 95 96 try{ 97 _checkMethod = checkClass.getDeclaredMethod(checkMethodString, new Class[]{Object.class}); 98 } 99 catch(Exception ex){ 100 System.err.println("Could not get the check method, either the method name is incorrect or the method does not take an Object as a parameter"); 101 return; 102 } 103 104 if(!(_checkMethod.getReturnType().equals(Boolean.TYPE))){ 105 System.err.println("The check method does not return a boolean value as is required"); 106 return; 107 } 108 _canCheck = true; 109 } 110 111 private void setImageFromCheck() 112 { 113 if(_canCheck){ 114 if(_checkResult == 0){ 115 _image = new ImageIcon(GOOD_ICON); 116 } 117 else if(_checkResult == 1){ 118 _image = new ImageIcon(BAD_ICON); 119 } 120 else{ 121 _image = new ImageIcon(ERROR_ICON); 122 } 123 } 124 else{ 125 _image = new ImageIcon(GOOD_ICON); 126 } 127 } 128 129 private void performCheck() 130 { 131 if(_canCheck){ 132 Boolean result = null; 133 try{ 134 result = ((Boolean)_checkMethod.invoke(_classObject, new Object[]{_value})); 135 } 136 catch(Exception ex){ 137 _checkResult = -1; 138 } 139 if(result){ 140 _checkResult = 0; 141 } 142 else{ 143 _checkResult = 1; 144 } 145 } 146 setImageFromCheck(); 147 } 148 149 public boolean isCheckable() 150 { 151 return _canCheck; 152 } 153 154 public int getCheckResult() 155 { 156 return _checkResult; 157 } 37 158 38 159 public String getName() … … 49 170 { 50 171 _value = value; 172 performCheck(); 173 174 JTable table = _parent.getParent().getTableFromOptionList(_parent); 175 176 if(table != null){ 177 table.repaint(); 178 table.revalidate(); 179 } 51 180 } 52 181 … … 60 189 return _parent; 61 190 } 191 192 public String getType() 193 { 194 return _type; 195 } 196 197 public ImageIcon getImage() 198 { 199 return _image; 200 } 62 201 } -
main/trunk/greenstone3/src/java/org/greenstone/admin/guiext/PropertiesStep.java
r22085 r22185 1 1 package org.greenstone.admin.guiext; 2 2 3 import javax.crypto.Cipher; 4 import javax.crypto.KeyGenerator; 5 import javax.crypto.SecretKey; 6 7 import javax.crypto.spec.SecretKeySpec; 8 9 import javax.swing.AbstractCellEditor; 3 10 import javax.swing.BorderFactory; 11 import javax.swing.ImageIcon; 12 import javax.swing.JButton; 13 import javax.swing.JFileChooser; 14 import javax.swing.JFrame; 4 15 import javax.swing.JLabel; 16 import javax.swing.JOptionPane; 5 17 import javax.swing.JPanel; 6 import javax.swing.JFrame; 7 import javax.swing.JButton; 18 import javax.swing.JPasswordField; 8 19 import javax.swing.JScrollPane; 9 20 import javax.swing.JTable; 21 import javax.swing.JTextField; 10 22 import javax.swing.SwingConstants; 23 24 import javax.swing.event.DocumentListener; 25 import javax.swing.event.DocumentEvent; 11 26 12 27 import javax.swing.table.AbstractTableModel; 13 28 import javax.swing.table.TableCellEditor; 29 import javax.swing.table.TableColumn; 30 import javax.swing.table.TableModel; 14 31 15 32 import java.awt.event.ActionListener; … … 20 37 import java.awt.BorderLayout; 21 38 import java.awt.Color; 39 import java.awt.Component; 22 40 import java.awt.Font; 23 41 import java.awt.GridLayout; 24 42 25 43 import java.util.Properties; 44 import java.util.Arrays; 45 import java.util.HashMap; 26 46 27 47 import java.io.File; … … 39 59 JTable[] _tables = null; 40 60 OptionList[] _modifiedOptionLists = null; 61 62 HashMap _optionListTableMap = new HashMap(); 41 63 42 64 public PropertiesStep(Element propertiesStepElement, SequenceList parent) … … 80 102 } 81 103 } 104 } 105 106 public JTable getTableFromOptionList(OptionList list) 107 { 108 return ((JTable)_optionListTableMap.get(list)); 82 109 } 83 110 … … 114 141 Option[] options = currentList.getOptions(); 115 142 116 JTable propertiesTable = new JTable(new CustomTableModel(new String[]{"Setting", "Value"}, options)); 143 CustomTableModel tableModel = new CustomTableModel(new String[]{"Setting", "Value", "Check"}, options); 144 PropertyTable propertiesTable = new PropertyTable(tableModel, currentList); 145 TableColumn column = propertiesTable.getColumnModel().getColumn(2); 146 column.setPreferredWidth(32); 147 column.setMinWidth(32); 148 column.setMaxWidth(32); 149 column.setResizable(false); 150 151 _optionListTableMap.put(currentList, propertiesTable); 152 117 153 //The line below is necessary as the default grid colour on mac is white, which makes the lines invisible. 118 154 propertiesTable.setGridColor(Color.BLACK); … … 148 184 149 185 _parent.getParent().changeExtPane(mainPanel); 186 } 187 } 188 189 public class BrowseButtonListener implements ActionListener 190 { 191 Option _option = null; 192 JTextField _path = null; 193 JFileChooser _browser = null; 194 195 public BrowseButtonListener(Option option, JTextField path) 196 { 197 _option = option; 198 _path = path; 199 _browser = new JFileChooser(); 200 } 201 202 public void actionPerformed(ActionEvent e) 203 { 204 if(e.getActionCommand().equals("edit")){ 205 if(_option.getType().equalsIgnoreCase("folderbrowse")){ 206 _browser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 207 } 208 int returnValue = _browser.showOpenDialog(null); 209 210 if(returnValue == JFileChooser.APPROVE_OPTION){ 211 _option.setValue(_browser.getSelectedFile().getAbsolutePath()); 212 _path.setText(_option.getValue()); 213 } 214 } 215 } 216 } 217 218 public class PathBoxListener implements DocumentListener 219 { 220 Option _option = null; 221 JTextField _path = null; 222 223 public PathBoxListener(Option option, JTextField path) 224 { 225 _option = option; 226 _path = path; 227 } 228 229 public void changedUpdate(DocumentEvent e) 230 { 231 _option.setValue(_path.getText()); 232 } 233 234 public void insertUpdate(DocumentEvent e) 235 { 236 _option.setValue(_path.getText()); 237 } 238 239 public void removeUpdate(DocumentEvent e) 240 { 241 _option.setValue(_path.getText()); 242 } 243 } 244 245 public class PasswordOKButtonListener implements ActionListener 246 { 247 JPasswordField _password = null; 248 JPasswordField _confirm = null; 249 Option _option = null; 250 JFrame _passwordFrame = null; 251 252 public PasswordOKButtonListener(JPasswordField password, JPasswordField confirm, Option option, JFrame passwordFrame) 253 { 254 _password = password; 255 _confirm = confirm; 256 _option = option; 257 _passwordFrame = passwordFrame; 258 } 259 260 public void actionPerformed(ActionEvent e) 261 { 262 if(Arrays.equals(_password.getPassword(), _confirm.getPassword())){ 263 try{ 264 _option.setValue(new String(encrypt(_password.getPassword()))); 265 } 266 catch(Exception ex){ 267 System.err.println("Error encrypting password"); 268 } 269 _passwordFrame.dispose(); 270 } 271 else{ 272 JOptionPane.showMessageDialog(null, "The passwords you entered do not match."); 273 _password.setText(""); 274 _confirm.setText(""); 275 } 276 } 277 } 278 279 public static char[] encrypt(char[] value) throws Exception 280 { 281 byte[] salt = {'T', 'p'}; 282 int count = 20; 283 284 KeyGenerator keygen = KeyGenerator.getInstance("AES"); 285 SecretKey secretKey = keygen.generateKey(); 286 byte[] raw = secretKey.getEncoded(); 287 SecretKeySpec secretKeySpec = new SecretKeySpec(raw, "AES"); 288 289 Cipher cipher = Cipher.getInstance("AES"); 290 cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); 291 292 byte[] encryptedPassword = cipher.doFinal((new String(value)).getBytes("UTF-8")); 293 294 return new String(encryptedPassword).toCharArray(); 295 } 296 297 public class PasswordCancelButtonListener implements ActionListener 298 { 299 JFrame _passwordFrame = new JFrame(); 300 301 public PasswordCancelButtonListener(JFrame passwordFrame) 302 { 303 _passwordFrame = passwordFrame; 304 } 305 306 public void actionPerformed(ActionEvent e) 307 { 308 _passwordFrame.dispose(); 309 } 310 } 311 312 public class PasswordFieldListener implements ActionListener 313 { 314 JPasswordField _password = new JPasswordField(10); 315 JPasswordField _confirm = new JPasswordField(10); 316 JFrame _passwordFrame = new JFrame("Enter password"); 317 318 public PasswordFieldListener(Option option) 319 { 320 JButton okButton = new JButton("Change"); 321 JButton cancelButton = new JButton("Cancel"); 322 323 okButton.addActionListener(new PasswordOKButtonListener(_password, _confirm, option, _passwordFrame)); 324 cancelButton.addActionListener(new PasswordCancelButtonListener(_passwordFrame)); 325 326 _passwordFrame.getContentPane().setLayout(new GridLayout(3,2)); 327 _passwordFrame.getContentPane().add(new JLabel("Password:")); 328 _passwordFrame.getContentPane().add(_password); 329 _passwordFrame.getContentPane().add(new JLabel("Confirm:")); 330 _passwordFrame.getContentPane().add(_confirm); 331 _passwordFrame.getContentPane().add(okButton); 332 _passwordFrame.getContentPane().add(cancelButton); 333 _passwordFrame.pack(); 334 } 335 336 public void actionPerformed(ActionEvent e) 337 { 338 _password.setText(""); 339 _confirm.setText(""); 340 _passwordFrame.setLocationRelativeTo(null); 341 _passwordFrame.setVisible(true); 342 } 343 } 344 345 public class PasswordEditor extends AbstractCellEditor implements TableCellEditor 346 { 347 JButton _onClickButton = new JButton("Change Password?"); 348 349 public PasswordEditor(Option option) 350 { 351 _onClickButton.addActionListener(new PasswordFieldListener(option)); 352 } 353 354 public Object getCellEditorValue() 355 { 356 return ""; 357 } 358 359 public Component getTableCellEditorComponent(JTable table, Object path, boolean isSelected, int row, int column) 360 { 361 return _onClickButton; 362 } 363 } 364 365 public class BrowseEditor extends AbstractCellEditor implements TableCellEditor 366 { 367 JPanel _browserPanel = null; 368 JTextField _path = null; 369 JButton _browserButton = null; 370 Option _option = null; 371 String _type = null; 372 373 public BrowseEditor(Option option, String type) 374 { 375 _option = option; 376 _type = type; 377 378 _path = new JTextField(_option.getValue()); 379 _path.getDocument().addDocumentListener(new PathBoxListener(_option, _path)); 380 381 _browserButton = new JButton("Browse"); 382 _browserButton.setActionCommand("edit"); 383 _browserButton.addActionListener(new BrowseButtonListener(_option, _path)); 384 _browserButton.setBorderPainted(false); 385 386 _browserPanel = new JPanel(); 387 _browserPanel.setLayout(new BorderLayout()); 388 _browserPanel.add(_path, BorderLayout.CENTER); 389 _browserPanel.add(_browserButton, BorderLayout.EAST); 390 } 391 392 public Object getCellEditorValue() 393 { 394 _path.setText(_option.getValue()); 395 return _option.getValue(); 396 } 397 398 public Component getTableCellEditorComponent(JTable table, Object path, boolean isSelected, int row, int column) 399 { 400 return _browserPanel; 401 } 402 } 403 404 public class PropertyTable extends JTable 405 { 406 OptionList _properties = null; 407 TableCellEditor[] _editors = null; 408 409 public PropertyTable(TableModel tm, OptionList properties) 410 { 411 super(tm); 412 _properties = properties; 413 414 Option[] options = _properties.getOptions(); 415 _editors = new TableCellEditor[options.length]; 416 417 for(int i = 0; i < options.length; i++){ 418 Option currentOption = options[i]; 419 420 if(currentOption.getType().equals("filebrowse")){ 421 _editors[i] = new BrowseEditor(currentOption, "file"); 422 } 423 else if(currentOption.getType().equals("folderbrowse")){ 424 _editors[i] = new BrowseEditor(currentOption, "folder"); 425 } 426 else if(currentOption.getType().equals("password")){ 427 _editors[i] = new PasswordEditor(currentOption); 428 } 429 else{ 430 _editors[i] = null; 431 } 432 } 433 } 434 435 public TableCellEditor getCellEditor(int row, int column) 436 { 437 if(column == 1 && row < _editors.length && _editors[row] != null){ 438 return _editors[row]; 439 } 440 return super.getCellEditor(row, column); 150 441 } 151 442 } … … 225 516 public class CustomTableModel extends AbstractTableModel 226 517 { 227 private String[] _columnNames; 228 private Option[] _data; 518 private String[] _columnNames = null; 519 private Option[] _data = null; 520 private ImageIcon[] _images = null; 229 521 230 522 public CustomTableModel(String[] columnNames, Option[] data){ 231 523 _columnNames = columnNames; 232 524 _data = data; 525 526 _images = new ImageIcon[_data.length]; 527 for(int i = 0; i < _data.length; i++){ 528 _images[i] = _data[i].getImage(); 529 } 233 530 } 234 531 … … 246 543 247 544 public Object getValueAt(int row, int col) { 248 Option o = _data[row];249 545 if(col == 0){ 250 return o.getName();546 return _data[row].getName(); 251 547 } 252 548 else if(col == 1){ 253 return o.getValue(); 549 if(_data[row].getType().equals("password") && !_data[row].getValue().equals("")){ 550 return "Password Set"; 551 } 552 else if(_data[row].getType().equals("password") && _data[row].getValue().equals("")){ 553 return "No Password Set"; 554 } 555 556 return _data[row].getValue(); 557 } 558 else if(col == 2){ 559 return _data[row].getImage(); 254 560 } 255 561 else{ … … 264 570 265 571 public boolean isCellEditable(int row, int col) { 266 if (col < 1) { 572 if (col == 1) { 573 return true; 574 } else { 267 575 return false; 268 } else {269 return true;270 576 } 271 577 } 272 578 273 579 public void setValueAt(Object value, int row, int col) { 274 if(isCellEditable(row, col)){ 275 _data[row].setValue((String)value); 580 Option o = _data[row]; 581 if(isCellEditable(row, col) && !o.getType().equals("password")){ 582 o.setValue((String)value); 583 584 if(o.isCheckable()){ 585 _images[row] = o.getImage(); 586 } 276 587 } 277 588 fireTableDataChanged(); -
main/trunk/greenstone3/src/java/org/greenstone/admin/guiext/SequenceList.java
r21919 r22185 201 201 { 202 202 loadExtensionStatesFromFile(); 203 203 204 204 ExtensionInformation currentExtension = _parent; 205 205 String fileStem = currentExtension.getFileStem(); 206 207 File extDir = new File(currentExtension.getExtensionDirectory()); 208 if(!extDir.exists()){ 209 rollbackTo(""); 210 } 206 211 207 212 for(int i = 0; i < _steps.size(); i++){ -
main/trunk/greenstone3/src/java/org/greenstone/admin/guiext/Step.java
r21919 r22185 9 9 import javax.swing.JTextArea; 10 10 import javax.swing.JPanel; 11 12 /*13 if(_commonMessageArea == null){14 _commonMessageArea = new JTextArea();15 _commonMessageArea.setEditable(false);16 _commonMessageArea.setAutoscrolls(true);17 _commonMessageArea.setLineWrap(true);18 _commonMessageArea.setWrapStyleWord(true);19 _commonMessageArea.setMargin(new Insets(0,5,0,0));20 }21 */22 11 23 12 public class Step
Note:
See TracChangeset
for help on using the changeset viewer.