1 19 package org.netbeans.test.subversion.operators; 20 21 import java.awt.Component ; 22 import java.awt.Point ; 23 import javax.swing.JComponent ; 24 import javax.swing.JTextField ; 25 import org.netbeans.jellytools.TopComponentOperator; 26 import org.netbeans.jellytools.nodes.Node; 27 import org.netbeans.jemmy.ComponentChooser; 28 import org.netbeans.jemmy.operators.JButtonOperator; 29 import org.netbeans.jemmy.operators.JLabelOperator; 30 import org.netbeans.jemmy.operators.JListOperator; 31 import org.netbeans.jemmy.operators.JPopupMenuOperator; 32 import org.netbeans.jemmy.operators.JTextFieldOperator; 33 import org.netbeans.jemmy.operators.JToggleButtonOperator; 34 import org.netbeans.test.subversion.operators.actions.SearchHistoryAction; 35 36 38 public class SearchHistoryOperator extends TopComponentOperator { 39 40 41 static final String SEARCH_HISTORY_TITLE = "Search History"; 42 43 44 public SearchHistoryOperator() { 45 super(waitTopComponent(null, SEARCH_HISTORY_TITLE, 0, new SearchHistorySubchooser())); 46 } 47 48 52 public static SearchHistoryOperator invoke(Node[] nodes) { 53 new SearchHistoryAction().perform(nodes); 54 return new SearchHistoryOperator(); 55 } 56 57 61 public static SearchHistoryOperator invoke(Node node) { 62 return invoke(new Node[] {node}); 63 } 64 65 private JLabelOperator _lblMessage; 66 private JTextFieldOperator _txtMessage; 67 private JLabelOperator _lblUsername; 68 private JTextFieldOperator _txtUsername; 69 private JLabelOperator _lblFrom; 70 private JTextFieldOperator _txtFrom; 71 private JButtonOperator _btBrowseFrom; 72 private JLabelOperator _lblTo; 73 private JTextFieldOperator _txtTo; 74 private JButtonOperator _btBrowseTo; 75 private JButtonOperator _btSearch; 76 private JToggleButtonOperator _tbSummary; 77 private JToggleButtonOperator _tbDiff; 78 private JButtonOperator _btNext; 79 private JButtonOperator _btPrevious; 80 private JListOperator _lstHistory; 81 82 86 89 public JLabelOperator lblMessage() { 90 if (_lblMessage==null) { 91 _lblMessage = new JLabelOperator(this, "Message:"); 92 } 93 return _lblMessage; 94 } 95 96 99 public JTextFieldOperator txtMessage() { 100 if (_txtMessage==null) { 101 _txtMessage = new JTextFieldOperator( 102 (JTextField )lblMessage().getLabelFor()); 103 } 104 return _txtMessage; 105 } 106 107 110 public JLabelOperator lblUsername() { 111 if (_lblUsername==null) { 112 _lblUsername = new JLabelOperator(this, "Username:"); 113 } 114 return _lblUsername; 115 } 116 117 120 public JTextFieldOperator txtUsername() { 121 if (_txtUsername==null) { 122 _txtUsername = new JTextFieldOperator( 123 (JTextField )lblUsername().getLabelFor()); 124 } 125 return _txtUsername; 126 } 127 128 131 public JLabelOperator lblFrom() { 132 if (_lblFrom==null) { 133 _lblFrom = new JLabelOperator(this, "From:"); 134 } 135 return _lblFrom; 136 } 137 138 141 public JTextFieldOperator txtFrom() { 142 if (_txtFrom==null) { 143 _txtFrom = new JTextFieldOperator( 144 (JTextField )lblFrom().getLabelFor()); 145 } 146 return _txtFrom; 147 } 148 149 152 public JButtonOperator btBrowseFrom() { 153 if (_btBrowseFrom==null) { 154 _btBrowseFrom = new JButtonOperator(this, "Browse"); 155 } 156 return _btBrowseFrom; 157 } 158 159 162 public JLabelOperator lblTo() { 163 if (_lblTo==null) { 164 _lblTo = new JLabelOperator(this, "To:"); 165 } 166 return _lblTo; 167 } 168 169 172 public JTextFieldOperator txtTo() { 173 if (_txtTo==null) { 174 _txtTo = new JTextFieldOperator( 175 (JTextField )lblTo().getLabelFor()); 176 } 177 return _txtTo; 178 } 179 180 183 public JButtonOperator btBrowseTo() { 184 if (_btBrowseTo==null) { 185 _btBrowseTo = new JButtonOperator(this, "Browse", 1); 186 } 187 return _btBrowseTo; 188 } 189 190 193 public JButtonOperator btSearch() { 194 if (_btSearch==null) { 195 _btSearch = new JButtonOperator(this, "Search"); 196 } 197 return _btSearch; 198 } 199 200 203 public JToggleButtonOperator tbSummary() { 204 if (_tbSummary==null) { 205 _tbSummary = new JToggleButtonOperator(this, "Summary"); 206 } 207 return _tbSummary; 208 } 209 210 213 public JToggleButtonOperator tbDiff() { 214 if (_tbDiff==null) { 215 _tbDiff = new JToggleButtonOperator(this, "Diff"); 216 } 217 return _tbDiff; 218 } 219 220 223 public JButtonOperator btNext() { 224 if (_btNext==null) { 225 String tooltip = "Go to next difference"; 226 _btNext = new JButtonOperator(this, new TooltipChooser(tooltip, getComparator())); 227 } 228 return _btNext; 229 } 230 231 234 public JButtonOperator btPrevious() { 235 if (_btPrevious==null) { 236 String tooltip = "Go to previous difference"; 237 _btPrevious = new JButtonOperator(this, new TooltipChooser(tooltip, getComparator())); 238 } 239 return _btPrevious; 240 } 241 242 245 public JListOperator lstHistory() { 246 if (_lstHistory==null) { 247 _lstHistory = new JListOperator(this); 248 } 249 return _lstHistory; 250 } 251 252 253 257 260 public String getMessage() { 261 return txtMessage().getText(); 262 } 263 264 267 public void setMessage(String text) { 268 txtMessage().clearText(); 269 txtMessage().typeText(text); 270 } 271 272 275 public String getUsername() { 276 return txtUsername().getText(); 277 } 278 279 282 public void setUsername(String text) { 283 txtUsername().clearText(); 284 txtUsername().typeText(text); 285 } 286 287 290 public String getFrom() { 291 return txtFrom().getText(); 292 } 293 294 297 public void setFrom(String text) { 298 txtFrom().clearText(); 299 txtFrom().typeText(text); 300 } 301 302 305 public String getTo() { 306 return txtTo().getText(); 307 } 308 309 312 public void setTo(String text) { 313 txtTo().clearText(); 314 txtTo().typeText(text); 315 } 316 317 319 public void search() { 320 btSearch().push(); 321 } 322 323 326 public void checkSummary(boolean state) { 327 if (tbSummary().isSelected()!=state) { 328 tbSummary().push(); 329 } 330 } 331 332 335 public void checkDiff(boolean state) { 336 if (tbDiff().isSelected()!=state) { 337 tbDiff().push(); 338 } 339 } 340 341 343 public void next() { 344 btNext().push(); 345 } 346 347 349 public void previous() { 350 btPrevious().push(); 351 } 352 353 public RepositoryBrowserOperator getRevisionFrom() { 354 btBrowseFrom().pushNoBlock(); 355 return new RepositoryBrowserOperator(); 356 } 357 358 public RepositoryBrowserOperator getRevisionTo() { 359 btBrowseTo().pushNoBlock(); 360 return new RepositoryBrowserOperator(); 361 } 362 363 367 public void performPopup(int rowIndex, String popupPath) { 368 Point point = lstHistory().getClickPoint(rowIndex); 369 lstHistory().clickForPopup(point.x, point.y); 370 JPopupMenuOperator popup = new JPopupMenuOperator(); 371 popup.pushMenu(popupPath); 372 } 373 374 378 380 public void verify() { 381 lblMessage(); 382 txtMessage(); 383 lblUsername(); 384 txtUsername(); 385 lblFrom(); 386 txtFrom(); 387 btBrowseFrom(); 388 lblTo(); 389 txtTo(); 390 btBrowseTo(); 391 btSearch(); 392 tbSummary(); 393 tbDiff(); 394 btNext(); 395 btPrevious(); 396 lstHistory(); 397 } 398 399 403 private static final class SearchHistorySubchooser implements ComponentChooser { 404 public boolean checkComponent(Component comp) { 405 return comp.getClass().getName().endsWith("SearchHistoryTopComponent"); 406 } 407 408 public String getDescription() { 409 return "org.netbeans.modules.subversion.ui.history.SearchHistoryTopComponent"; 410 } 411 } 412 413 416 private static class TooltipChooser implements ComponentChooser { 417 private String buttonTooltip; 418 private StringComparator comparator; 419 420 public TooltipChooser(String buttonTooltip, StringComparator comparator) { 421 this.buttonTooltip = buttonTooltip; 422 this.comparator = comparator; 423 } 424 425 public boolean checkComponent(Component comp) { 426 return comparator.equals(((JComponent )comp).getToolTipText(), buttonTooltip); 427 } 428 429 public String getDescription() { 430 return "Button with tooltip \""+buttonTooltip+"\"."; 431 } 432 } 433 } 434 | Popular Tags |