1 19 package org.netbeans.test.localhistory.operators; 20 21 import java.awt.Component ; 22 import java.awt.Point ; 23 import javax.swing.JComponent ; 24 import javax.swing.JPopupMenu ; 25 import org.netbeans.jellytools.TopComponentOperator; 26 import org.netbeans.jellytools.TreeTableOperator; 27 import org.netbeans.jellytools.nodes.Node; 28 import org.netbeans.jemmy.ComponentChooser; 29 import org.netbeans.jemmy.operators.JButtonOperator; 30 import org.netbeans.jemmy.operators.JListOperator; 31 import org.netbeans.jemmy.operators.JPopupMenuOperator; 32 import org.netbeans.test.localhistory.actions.ShowLocalHistoryAction; 33 34 36 public class ShowLocalHistoryOperator extends TopComponentOperator { 37 38 39 static final String LOCAL_HISTORY_TITLE = "Local History"; 40 41 42 public ShowLocalHistoryOperator() { 43 super(waitTopComponent(null, LOCAL_HISTORY_TITLE, 0, new LocalHistorySubchooser())); 44 } 45 46 50 public static ShowLocalHistoryOperator invoke(Node[] nodes) { 51 new ShowLocalHistoryAction().perform(nodes); 52 return new ShowLocalHistoryOperator(); 53 } 54 55 59 public static ShowLocalHistoryOperator invoke(Node node) { 60 return invoke(new Node[] {node}); 61 } 62 63 private JButtonOperator _btNext; 64 private JButtonOperator _btPrevious; 65 private TreeTableOperator _treeTable; 66 67 71 72 73 76 public JButtonOperator btNext() { 77 if (_btNext==null) { 78 String tooltip = "Go to next difference"; 79 _btNext = new JButtonOperator(this, new TooltipChooser(tooltip, getComparator())); 80 } 81 return _btNext; 82 } 83 84 87 public JButtonOperator btPrevious() { 88 if (_btPrevious==null) { 89 String tooltip = "Go to previous difference"; 90 _btPrevious = new JButtonOperator(this, new TooltipChooser(tooltip, getComparator())); 91 } 92 return _btPrevious; 93 } 94 95 98 public TreeTableOperator treeTableHistory() { 99 if (_treeTable == null) { 100 _treeTable = new TreeTableOperator(this); 101 } 102 return _treeTable; 103 } 104 105 106 110 112 public void next() { 113 btNext().push(); 114 } 115 116 118 public void previous() { 119 btPrevious().push(); 120 } 121 122 125 public void selectFolder(String path) { 126 new Node(treeTableHistory().tree(), path).select(); 127 } 128 129 public void performPopupAction(int rowIndex, String path) { 130 JPopupMenu popup = treeTableHistory().callPopupOnCell(rowIndex, 0); 131 JPopupMenuOperator popupOperator = new JPopupMenuOperator(popup); 132 popupOperator.pushMenu(path); 133 } 134 135 139 141 public void verify() { 142 btNext(); 143 btPrevious(); 144 treeTableHistory(); 145 } 146 147 151 private static final class LocalHistorySubchooser implements ComponentChooser { 152 public boolean checkComponent(Component comp) { 153 return comp.getClass().getName().endsWith("LocalHistoryTopComponent"); 154 } 155 156 public String getDescription() { 157 return "org.netbeans.modules.localhistory.ui.view.LocalHistoryTopComponent"; 158 } 159 } 160 161 164 private static class TooltipChooser implements ComponentChooser { 165 private String buttonTooltip; 166 private StringComparator comparator; 167 168 public TooltipChooser(String buttonTooltip, StringComparator comparator) { 169 this.buttonTooltip = buttonTooltip; 170 this.comparator = comparator; 171 } 172 173 public boolean checkComponent(Component comp) { 174 return comparator.equals(((JComponent )comp).getToolTipText(), buttonTooltip); 175 } 176 177 public String getDescription() { 178 return "Button with tooltip \""+buttonTooltip+"\"."; 179 } 180 } 181 } 182 | Popular Tags |