1 package com.jahia.opentools.advancedapprunner; 2 3 import java.util.Map ; 4 5 import java.awt.Dimension ; 6 import java.awt.GridBagConstraints ; 7 import java.awt.GridBagLayout ; 8 import java.awt.Insets ; 9 import java.awt.event.ActionEvent ; 10 import javax.swing.JButton ; 11 import javax.swing.JLabel ; 12 import javax.swing.JTextField ; 13 import javax.swing.event.ChangeEvent ; 14 import javax.swing.event.ChangeListener ; 15 16 import com.borland.primetime.help.HelpTopic; 17 import com.borland.primetime.help.ZipHelpBook; 18 import com.borland.primetime.help.ZipHelpTopic; 19 import com.borland.primetime.node.Project; 20 import com.borland.primetime.properties.GlobalArrayProperty; 21 import com.borland.primetime.properties.PropertyPage; 22 23 32 public class AdvancedAppRunnerPropertyPage extends PropertyPage implements 33 ChangeListener { 34 35 public static final String CATEGORY = 36 "com.jahia.opentools.advancedapprunner"; 37 public static final GlobalArrayProperty DEFAULT_DIRS = 38 new GlobalArrayProperty(CATEGORY, "defaultDirs"); 39 40 private GridBagLayout gridBagLayout = new GridBagLayout (); 41 private JLabel mainClassNameLabel = new JLabel (); 42 private JTextField mainClassNameField = new JTextField (); 43 private JLabel vmParametersLabel = new JLabel (); 44 private JTextField vmparamsField = new JTextField (); 45 private JLabel appParamsLabel = new JLabel (); 46 private JTextField jbparamsField = new JTextField (); 47 private JLabel classPathLabel = new JLabel (); 48 private JButton loadButton = new JButton (); 49 private JButton saveButton = new JButton (); 50 private ClassPathListPanel classPathList = new ClassPathListPanel(); 51 52 private Map propertyMap = null; 53 54 public AdvancedAppRunnerPropertyPage(Project project, Map propertyMap) { 55 this.propertyMap = propertyMap; 56 try { 57 jbInit(); 58 } catch (Exception e) { 59 e.printStackTrace(); 60 } 61 } 62 63 66 private void jbInit() throws Exception { 67 this.setLayout(gridBagLayout); 68 mainClassNameLabel.setDisplayedMnemonic('M'); 69 mainClassNameLabel.setLabelFor(mainClassNameField); 70 mainClassNameLabel.setText("Main Class name:"); 71 mainClassNameField.setToolTipText("Fully qualified main class name"); 72 vmParametersLabel.setDisplayedMnemonic('V'); 73 vmParametersLabel.setLabelFor(vmparamsField); 74 vmParametersLabel.setText("VM parameters:"); 75 vmparamsField.setToolTipText("Parameters for the JVM"); 76 appParamsLabel.setDisplayedMnemonic('J'); 77 appParamsLabel.setLabelFor(jbparamsField); 78 appParamsLabel.setText("Application parameters:"); 79 jbparamsField.setToolTipText("Parameters for the application"); 80 classPathLabel.setDisplayedMnemonic('O'); 81 classPathLabel.setLabelFor(classPathList); 82 classPathLabel.setText("Class path (add class directories and JARs here) :"); 83 loadButton.setMinimumSize(new Dimension (53, 21)); 84 loadButton.setPreferredSize(new Dimension (53, 21)); 85 loadButton.setToolTipText("Reload directory list from defaults"); 86 loadButton.setActionCommand("Load"); 87 loadButton.setMargin(new Insets (2, 4, 2, 4)); 88 loadButton.setMnemonic('L'); 89 loadButton.setText("Load"); 90 loadButton.addActionListener(new java.awt.event.ActionListener () { 91 public void actionPerformed(ActionEvent e) { 92 loadButton_actionPerformed(e); 93 } 94 }); 95 loadButton.addActionListener(new java.awt.event.ActionListener () { 96 public void actionPerformed(ActionEvent e) { 97 loadButton_actionPerformed(e); 98 } 99 }); 100 saveButton.setMinimumSize(new Dimension (53, 21)); 101 saveButton.setPreferredSize(new Dimension (53, 21)); 102 saveButton.setToolTipText("Save directory list as defaults"); 103 saveButton.setActionCommand("Save"); 104 saveButton.setMargin(new Insets (2, 4, 2, 4)); 105 saveButton.setMnemonic('S'); 106 saveButton.setText("Save"); 107 saveButton.addActionListener(new java.awt.event.ActionListener () { 108 public void actionPerformed(ActionEvent e) { 109 saveButton_actionPerformed(e); 110 } 111 }); 112 this.add(mainClassNameLabel, new GridBagConstraints (0, 0, 2, 1, 0.0, 0.0 113 , GridBagConstraints.CENTER, 114 GridBagConstraints.HORIZONTAL, 115 new Insets (0, 4, 0, 4), 0, 0)); 116 this.add(mainClassNameField, 117 new GridBagConstraints (0, 1, 3, 1, 0.0, 0.0 118 , GridBagConstraints.WEST, 119 GridBagConstraints.HORIZONTAL, 120 new Insets (0, 4, 0, 4), 0, 0)); 121 122 this.add(vmParametersLabel, new GridBagConstraints (0, 2, 2, 1, 0.0, 0.0 123 , GridBagConstraints.CENTER, 124 GridBagConstraints.HORIZONTAL, 125 new Insets (0, 4, 0, 4), 0, 0)); 126 this.add(vmparamsField, new GridBagConstraints (0, 3, 3, 1, 0.0, 0.0 127 , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 128 new Insets (0, 4, 0, 4), 0, 0)); 129 130 this.add(appParamsLabel, new GridBagConstraints (0, 4, 2, 1, 0.0, 0.0 131 , GridBagConstraints.CENTER, 132 GridBagConstraints.HORIZONTAL, 133 new Insets (4, 4, 0, 4), 0, 0)); 134 this.add(jbparamsField, new GridBagConstraints (0, 5, 3, 1, 0.0, 0.0 135 , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 136 new Insets (0, 4, 0, 4), 0, 0)); 137 138 this.add(classPathLabel, new GridBagConstraints (0, 6, 1, 1, 1.0, 0.0 139 , GridBagConstraints.CENTER, 140 GridBagConstraints.HORIZONTAL, 141 new Insets (4, 4, 4, 4), 0, 0)); 142 this.add(classPathList, new GridBagConstraints (0, 7, 3, 1, 1.0, 1.0 143 , GridBagConstraints.CENTER, 144 GridBagConstraints.BOTH, 145 new Insets (0, 0, 0, 0), 0, 0)); 146 this.add(loadButton, new GridBagConstraints (1, 6, 1, 1, 0.0, 0.0 147 , GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, 148 new Insets (4, 0, 0, 0), 0, 0)); 149 this.add(saveButton, new GridBagConstraints (2, 6, 1, 1, 0.0, 0.0 150 , GridBagConstraints.CENTER, GridBagConstraints.NONE, 151 new Insets (4, 4, 0, 4), 0, 0)); 152 disEnableButtons(); 153 } 154 155 158 private void disEnableButtons() { 159 loadButton.setEnabled(DEFAULT_DIRS.getValues().length > 0); 160 saveButton.setEnabled(classPathList.getList().size() > 0); 161 } 162 163 166 public void stateChanged(ChangeEvent e) { 167 disEnableButtons(); 168 } 169 170 173 void loadButton_actionPerformed(ActionEvent e) { 174 loadDirectories(DEFAULT_DIRS.getValues()); 175 disEnableButtons(); 176 } 177 178 181 void saveButton_actionPerformed(ActionEvent e) { 182 DEFAULT_DIRS.setValues(saveDirectories()); 183 } 184 185 188 public void readProperties() { 189 mainClassNameField.setText(AdvancedAppRunner.MAIN_CLASS.getValue( 190 propertyMap)); 191 vmparamsField.setText(AdvancedAppRunner.VM_PARAMS.getValue(propertyMap)); 192 jbparamsField.setText(AdvancedAppRunner.JB_PARAMS.getValue(propertyMap)); 193 loadDirectories(AdvancedAppRunner.OTHER_DIRS.getValues(propertyMap)); 194 disEnableButtons(); 195 } 196 197 202 public void loadDirectories(String [] dirs) { 203 classPathList.clear(); 204 for (int index = 0; index < dirs.length; index++) { 205 classPathList.addListElement(dirs[index]); 206 } 207 } 208 209 212 public void writeProperties() { 213 AdvancedAppRunner.MAIN_CLASS.setValue(propertyMap, 214 mainClassNameField.getText()); 215 AdvancedAppRunner.VM_PARAMS.setValue(propertyMap, vmparamsField.getText()); 216 AdvancedAppRunner.JB_PARAMS.setValue(propertyMap, jbparamsField.getText()); 217 AdvancedAppRunner.OTHER_DIRS.setValues(propertyMap, saveDirectories()); 218 } 219 220 225 public String [] saveDirectories() { 226 String [] dirs = new String [classPathList.getList().size()]; 227 for (int index = 0; index < dirs.length; index++) { 228 dirs[index] = (String ) classPathList.getList().get(index); 229 } 230 return dirs; 231 } 232 233 236 public HelpTopic getHelpTopic() { 237 return new ZipHelpTopic(new ZipHelpBook("advancedapprunner-doc.jar"), 238 "AdvancedAppRunner.html"); 239 } 240 } 241 | Popular Tags |