1 19 package org.netbeans.test.subversion.operators; 20 21 import java.awt.Component ; 22 import javax.swing.JComponent ; 23 import org.netbeans.jellytools.Bundle; 24 import org.netbeans.jellytools.TopComponentOperator; 25 import org.netbeans.jellytools.actions.Action; 26 import org.netbeans.jemmy.ComponentChooser; 27 import org.netbeans.jemmy.operators.JButtonOperator; 28 import org.netbeans.jemmy.operators.JComboBoxOperator; 29 import org.netbeans.jemmy.operators.JPopupMenuOperator; 30 import org.netbeans.jemmy.operators.JTableOperator; 31 import org.netbeans.jemmy.operators.JToggleButtonOperator; 32 import org.netbeans.jemmy.operators.Operator; 33 34 35 public class DiffOperator extends TopComponentOperator { 36 37 40 public DiffOperator(String name) { 41 super(waitTopComponent(null, name, 0, new DiffSubchooser())); 42 } 43 44 45 public DiffOperator() { 46 this(null); 47 } 48 49 private JButtonOperator _btNext; 50 private JButtonOperator _btPrevious; 51 private JToggleButtonOperator _tbRemoveLocal; 52 private JToggleButtonOperator _tbLocal; 53 private JToggleButtonOperator _tbRemote; 54 private JButtonOperator _btRefresh; 55 private JButtonOperator _btUpdate; 56 private JButtonOperator _btCommit; 57 private JComboBoxOperator _cbFiles; 58 59 63 66 public JButtonOperator btNext() { 67 if (_btNext==null) { 68 String tooltip = "Go to next difference"; 69 _btNext = new JButtonOperator(this, new TooltipChooser(tooltip, getComparator())); 70 } 71 return _btNext; 72 } 73 74 77 public JButtonOperator btPrevious() { 78 if (_btPrevious==null) { 79 String tooltip = "Go to previous difference"; 80 _btPrevious = new JButtonOperator(this, new TooltipChooser(tooltip, getComparator())); 81 } 82 return _btPrevious; 83 } 84 85 88 public JToggleButtonOperator tbRemoteLocal() { 89 if (_tbRemoveLocal==null) { 90 _tbRemoveLocal = new JToggleButtonOperator(this, "Remote vs Local"); 91 } 92 return _tbRemoveLocal; 93 } 94 95 98 public JToggleButtonOperator tbLocal() { 99 if (_tbLocal==null) { 100 Operator.StringComparator oldComparator = Operator.getDefaultStringComparator(); 101 Operator.DefaultStringComparator comparator = new Operator.DefaultStringComparator(true, true); 102 try { 103 this.setComparator(comparator); 104 _tbLocal = new JToggleButtonOperator(this, "Local"); 105 } finally { 106 this.setComparator(oldComparator); 107 } 108 } 109 return _tbLocal; 110 } 111 112 115 public JToggleButtonOperator tbRemote() { 116 if (_tbRemote==null) { 117 Operator.StringComparator oldComparator = Operator.getDefaultStringComparator(); 118 Operator.DefaultStringComparator comparator = new Operator.DefaultStringComparator(true, true); 119 try { 120 this.setComparator(comparator); 121 _tbRemote = new JToggleButtonOperator(this, "Remote"); 122 } finally { 123 this.setComparator(oldComparator); 124 } 125 } 126 return _tbRemote; 127 } 128 129 132 public JButtonOperator btRefresh() { 133 if (_btRefresh==null) { 134 _btRefresh = new JButtonOperator(this, new TooltipChooser("Refresh Diff", this.getComparator())); 135 } 136 return _btRefresh; 137 } 138 139 142 public JButtonOperator btUpdate() { 143 if (_btUpdate==null) { 144 _btUpdate = new JButtonOperator(this, new TooltipChooser("Update \"{0}\"", this.getComparator())); 145 } 146 return _btUpdate; 147 } 148 149 152 public JButtonOperator btCommit() { 153 if (_btCommit==null) { 154 _btCommit = new JButtonOperator(this, new TooltipChooser("Commit \"{0}\"", this.getComparator())); 155 } 156 return _btCommit; 157 } 158 159 162 public JComboBoxOperator cbFiles() { 163 if (_cbFiles == null) { 164 _cbFiles = new JComboBoxOperator(this); 165 } 166 return _cbFiles; 167 } 168 172 174 public void next() { 175 btNext().push(); 176 } 177 178 180 public void previous() { 181 btPrevious().push(); 182 } 183 184 187 public void checkRemoteLocal(boolean state) { 188 if (tbRemoteLocal().isSelected()!=state) { 189 tbRemoteLocal().push(); 190 } 191 } 192 193 196 public void checkLocal(boolean state) { 197 if (tbLocal().isSelected()!=state) { 198 tbLocal().push(); 199 } 200 } 201 202 205 public void checkRemote(boolean state) { 206 if (tbRemote().isSelected()!=state) { 207 tbRemote().push(); 208 } 209 } 210 211 213 public void refresh() { 214 btRefresh().push(); 215 } 216 217 219 public void update() { 220 btUpdate().push(); 221 } 222 223 226 public CommitOperator commit() { 227 btCommit().pushNoBlock(); 228 return new CommitOperator(); 229 } 230 231 234 public void selectFile(String name) { 235 cbFiles().selectItem(name); 236 } 237 238 241 public void selectFile(int index) { 242 cbFiles().selectItem(index); 243 } 244 245 249 251 public void verify() { 252 btNext(); 253 btPrevious(); 254 tbRemoteLocal(); 255 tbLocal(); 256 tbRemote(); 257 btRefresh(); 258 btUpdate(); 259 btCommit(); 260 cbFiles(); 261 } 262 263 267 private static final class DiffSubchooser implements ComponentChooser { 268 public boolean checkComponent(Component comp) { 269 return comp.getClass().getName().endsWith("DiffTopComponent"); } 271 272 public String getDescription() { 273 return "org.netbeans.modules.subversion.ui.diff.DiffTopComponent"; } 275 } 276 277 280 private static class TooltipChooser implements ComponentChooser { 281 private String buttonTooltip; 282 private StringComparator comparator; 283 284 public TooltipChooser(String buttonTooltip, StringComparator comparator) { 285 this.buttonTooltip = buttonTooltip; 286 this.comparator = comparator; 287 } 288 289 public boolean checkComponent(Component comp) { 290 return comparator.equals(((JComponent )comp).getToolTipText(), buttonTooltip); 291 } 292 293 public String getDescription() { 294 return "Button with tooltip \""+buttonTooltip+"\"."; 295 } 296 } 297 } 298 299 | Popular Tags |