1 19 20 25 package org.netbeans.jellytools.modules.editor; 26 27 import java.util.*; 28 import javax.swing.table.TableModel ; 29 import org.netbeans.jellytools.OptionsOperator; 30 import org.netbeans.jellytools.properties.Property; 31 import org.netbeans.jellytools.properties.PropertySheetOperator; 32 import org.netbeans.jemmy.EventTool; 33 import org.netbeans.jemmy.operators.*; 34 35 42 public class Abbreviations extends JDialogOperator { 43 44 46 public Abbreviations() { 47 super(java.util.ResourceBundle.getBundle("org/netbeans/modules/editor/options/Bundle").getString("PROP_Abbreviations")); 48 } 49 50 private JTableOperator _tabAbbreviations; 51 private JButtonOperator _btMetalScrollButton; 52 private JButtonOperator _btMetalScrollButton2; 53 private JButtonOperator _btAdd; 54 private JButtonOperator _btEdit; 55 private JButtonOperator _btRemove; 56 private JButtonOperator _btOK; 57 private JButtonOperator _btCancel; 58 private JButtonOperator _btHelp; 59 60 61 65 68 public JTableOperator tabAbbreviations() { 69 if (_tabAbbreviations==null) { 70 _tabAbbreviations = new JTableOperator(this); 71 } 72 return _tabAbbreviations; 73 } 74 75 78 public JButtonOperator btMetalScrollButton() { 79 if (_btMetalScrollButton==null) { 80 _btMetalScrollButton = new JButtonOperator(this, ""); 81 } 82 return _btMetalScrollButton; 83 } 84 85 88 public JButtonOperator btMetalScrollButton2() { 89 if (_btMetalScrollButton2==null) { 90 _btMetalScrollButton2 = new JButtonOperator(this, "", 1); 91 } 92 return _btMetalScrollButton2; 93 } 94 95 98 public JButtonOperator btAdd() { 99 if (_btAdd==null) { 100 _btAdd = new JButtonOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.modules.editor.options.Bundle").getString("KBEP_Add")); 101 } 102 return _btAdd; 103 } 104 105 108 public JButtonOperator btEdit() { 109 if (_btEdit==null) { 110 _btEdit = new JButtonOperator(this, java.util.ResourceBundle.getBundle("org/netbeans/modules/editor/options/Bundle").getString("AEP_Edit")); 111 } 112 return _btEdit; 113 } 114 115 118 public JButtonOperator btRemove() { 119 if (_btRemove==null) { 120 _btRemove = new JButtonOperator(this, java.util.ResourceBundle.getBundle("org/netbeans/modules/editor/options/Bundle").getString("Remove")); 121 } 122 return _btRemove; 123 } 124 125 128 public JButtonOperator btOK() { 129 if (_btOK==null) { 130 _btOK = new JButtonOperator(this, java.util.ResourceBundle.getBundle("org/netbeans/modules/editor/options/Bundle").getString("KBEP_OK_LABEL")); 131 } 132 return _btOK; 133 } 134 135 138 public JButtonOperator btCancel() { 139 if (_btCancel==null) { 140 _btCancel = new JButtonOperator(this, java.util.ResourceBundle.getBundle("org.openide.explorer.propertysheet.Bundle").getString("CTL_Cancel")); 141 } 142 return _btCancel; 143 } 144 145 148 public JButtonOperator btHelp() { 149 if (_btHelp==null) { 150 _btHelp = new JButtonOperator(this, java.util.ResourceBundle.getBundle("org.openide.explorer.propertysheet.Bundle").getString("CTL_Help")); 151 } 152 return _btHelp; 153 } 154 155 156 160 162 public void metalScrollButton() { 163 btMetalScrollButton().push(); 164 } 165 166 168 public void metalScrollButton2() { 169 btMetalScrollButton2().push(); 170 } 171 172 174 public void add() { 175 btAdd().push(); 176 } 177 178 180 public void edit() { 181 btEdit().push(); 182 } 183 184 186 public void remove() { 187 btRemove().push(); 188 } 189 190 192 public void oK() { 193 btOK().push(); 194 } 195 196 198 public void cancel() { 199 btCancel().push(); 200 } 201 202 204 public void help() { 205 btHelp().push(); 206 } 207 208 209 213 215 public void verify() { 216 tabAbbreviations(); 217 btMetalScrollButton(); 218 btMetalScrollButton2(); 219 btAdd(); 220 btEdit(); 221 btRemove(); 222 btOK(); 223 btCancel(); 224 btHelp(); 225 } 226 227 public void addAbbreviation(String abbreviation, String expansion) { 228 new EventTool().waitNoEvent(500); 229 btAdd().pushNoBlock(); 230 EnterAbbreviation enter = new EnterAbbreviation(); 231 enter.fillAbbreviation(abbreviation, expansion); 232 enter.oK(); 233 } 234 235 public boolean editAbbreviation(String abbreviationName, String newAbbreviationName, String newExpansion) { 236 int row = tabAbbreviations().findCellRow(abbreviationName); 237 238 if (row == (-1)) 239 return false; 240 241 tabAbbreviations().selectCell(row, 0); 242 btEdit().pushNoBlock(); 243 244 EnterAbbreviation enter = new EnterAbbreviation(); 245 246 enter.fillAbbreviation(newAbbreviationName, newExpansion); 247 enter.oK(); 248 249 return true; 250 } 251 252 public void addOrEditAbbreviation(String abbreviationName, String newAbbreviationName, String newExpansion) { 253 if (!editAbbreviation(abbreviationName, newAbbreviationName, newExpansion)) 254 addAbbreviation(newAbbreviationName, newExpansion); 255 } 256 257 public boolean removeAbbreviation(String abbreviation) { 258 int row = tabAbbreviations().findCellRow(abbreviation, 259 new Operator.DefaultStringComparator(true, true)); 260 261 if (row == (-1)) { 262 System.out.println("Didn't find "+abbreviation); 263 TableModel model = tabAbbreviations().getModel(); 264 int rowCount = model.getRowCount(); 265 for (int cntr = 0; cntr < rowCount; cntr++) { 266 System.out.print(model.getValueAt(cntr, 0)+" "); 267 } 268 System.out.println(""); 269 return false; 270 } 271 tabAbbreviations().selectCell(row, 0); 272 btRemove().pushNoBlock(); 273 274 return true; 275 } 276 277 public Map listAbbreviations() { 278 TableModel model = tabAbbreviations().getModel(); 279 int rowCount = model.getRowCount(); 280 Map result = new HashMap(); 281 282 for (int cntr = 0; cntr < rowCount; cntr++) { 283 result.put((String ) model.getValueAt(cntr, 0), (String ) model.getValueAt(cntr, 1)); 284 } 285 286 return result; 287 } 288 289 public static Abbreviations invoke(String editorName) { 290 OptionsOperator options = OptionsOperator.invoke(); 291 options.switchToClassicView(); options.selectOption(ResourceBundle.getBundle("org/netbeans/core/Bundle").getString("UI/Services/Editing")+ 293 "|"+ResourceBundle.getBundle("org/netbeans/modules/editor/options/Bundle").getString("OPTIONS_all")+ 294 "|" + editorName); 295 new EventTool().waitNoEvent(500); 296 PropertySheetOperator pso = new PropertySheetOperator(options); 297 new Property(pso,ResourceBundle.getBundle("org/netbeans/modules/editor/options/Bundle").getString("PROP_Abbreviations")).openEditor(); 298 299 Abbreviations abbs = new Abbreviations(); 300 301 options.btClose().push(); 302 return abbs; 303 } 304 305 public static void addAbbreviation(String editorName, String abbreviation, String expansion) { 306 Abbreviations instance = invoke(editorName); 307 308 instance.addAbbreviation(abbreviation, expansion); 309 instance.oK(); 310 } 311 312 public static void addOrEditAbbreviation(String editorName, String abbreviationName, String newAbbreviationName, String newExpansion) { 313 Abbreviations instance = invoke(editorName); 314 315 instance.addOrEditAbbreviation(abbreviationName, newAbbreviationName, newExpansion); 316 instance.oK(); 317 } 318 319 public static boolean removeAbbreviation(String editorName, String abbreviation) { 320 Abbreviations instance = invoke(editorName); 321 boolean result = instance.removeAbbreviation(abbreviation); 322 323 instance.oK(); 324 return result; 325 } 326 327 public static boolean editAbbreviation(String editorName, String abbreviationName, String newAbbreviationName, String newExpansion) { 328 Abbreviations instance = invoke(editorName); 329 boolean result = instance.editAbbreviation(abbreviationName, newAbbreviationName, newExpansion); 330 331 instance.oK(); 332 return result; 333 } 334 335 public static Map listAbbreviations(String editorName) { 336 Abbreviations instance = invoke(editorName); 337 Map result = instance.listAbbreviations(); 338 339 instance.oK(); 340 341 return result; 342 } 343 344 347 public static void main(String args[]) { 348 Abbreviations.addAbbreviation("Java Editor","aaa","All abbrev"); 349 try { 350 Thread.currentThread().sleep(5000); 351 } catch (Exception ex) { 352 ex.printStackTrace(); 353 } 354 Abbreviations.removeAbbreviation("Java Editor","aaa"); 355 370 371 } 372 } 373 374
| Popular Tags
|