--- old/src/org/netbeans/jemmy/operators/JFileChooserOperator.java 2017-12-06 15:27:52.000000000 -0800 +++ new/src/org/netbeans/jemmy/operators/JFileChooserOperator.java 2017-12-06 15:27:52.000000000 -0800 @@ -37,6 +37,7 @@ import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JList; +import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.JToggleButton; import javax.swing.ListModel; @@ -44,6 +45,7 @@ import javax.swing.filechooser.FileSystemView; import javax.swing.filechooser.FileView; import javax.swing.plaf.FileChooserUI; +import javax.swing.table.TableModel; import org.netbeans.jemmy.ComponentChooser; import org.netbeans.jemmy.ComponentSearcher; @@ -59,6 +61,7 @@ /** * * Class provides methods to cover main JFileChooser component functionality. + * Supports choosers using either JList or JTable as the component showing files. * * @author Alexandre Iline (alexandre.iline@oracle.com) * @@ -330,29 +333,29 @@ } /** - * Returns file list. + * Returns either a JList or JTable, depending on the implementation. * - * @return a list being used to display directory content. + * @return a component being used to display directory content. */ - public JList getFileList() { - return ((JList) innerSearcher. + public Component getFileList() { + return innerSearcher. findComponent(new ComponentChooser() { @Override public boolean checkComponent(Component comp) { return (comp != null - && comp instanceof JList); + && (comp instanceof JList || comp instanceof JTable)); } @Override public String getDescription() { - return "JList"; + return "JList or JTable used to show list of files"; } @Override public String toString() { return "JFileChooserOperator.getFileList.ComponentChooser{description = " + getDescription() + '}'; } - })); + }); } /** @@ -445,14 +448,23 @@ public void clickOnFile(int index, int clickCount) { getQueueTool().waitEmpty(); output.printTrace("Click " + Integer.toString(clickCount) - + "times on " + Integer.toString(index) + + " times on " + Integer.toString(index) + "`th file in JFileChooser\n : " + toStringSource()); - JListOperator listOper = new JListOperator(getFileList()); waitPainted(index); - listOper.copyEnvironment(this); - listOper.setOutput(output.createErrorOutput()); - listOper.clickOnItem(index, clickCount); + Component list = getFileList(); + System.out.println(list); + if(list instanceof JList) { + JListOperator listOper = new JListOperator((JList) list); + listOper.copyEnvironment(this); + listOper.setOutput(output.createErrorOutput()); + listOper.clickOnItem(index, clickCount); + } else { + JTableOperator tableOper = new JTableOperator((JTable) list); + tableOper.copyEnvironment(this); + tableOper.setOutput(output.createErrorOutput()); + tableOper.clickOnCell(index, 0, clickCount); + } } /** @@ -464,7 +476,7 @@ */ public void clickOnFile(String file, StringComparator comparator, int clickCount) { output.printTrace("Click " + Integer.toString(clickCount) - + "times on \"" + file + + " times on \"" + file + "\" file in JFileChooser\n : " + toStringSource()); clickOnFile(findFileIndex(file, comparator), clickCount); @@ -589,11 +601,18 @@ public void selectFile(String file, StringComparator comparator) { getQueueTool().waitEmpty(); int index = findFileIndex(file, comparator); - JListOperator listOper = new JListOperator(getFileList()); - waitPainted(index); - listOper.copyEnvironment(this); - listOper.setOutput(output.createErrorOutput()); - listOper.setSelectedIndex(index); + Component list = getFileList(); + if(list instanceof JList) { + JListOperator listOper = new JListOperator((JList) list); + listOper.copyEnvironment(this); + listOper.setOutput(output.createErrorOutput()); + listOper.setSelectedIndex(index); + } else { + JTableOperator tableOper = new JTableOperator((JTable) list); + tableOper.copyEnvironment(this); + tableOper.setOutput(output.createErrorOutput()); + tableOper.changeSelection(index, 0, false, false); + } } /** @@ -749,7 +768,8 @@ */ public int getFileCount() { waitPainted(-1); - return getFileList().getModel().getSize(); + Component list = getFileList(); + return (list instanceof JList) ? ((JList)list).getModel().getSize() : ((JTable)list).getModel().getRowCount(); } /** @@ -759,12 +779,22 @@ */ public File[] getFiles() { waitPainted(-1); - ListModel listModel = getFileList().getModel(); - File[] result = new File[listModel.getSize()]; - for (int i = 0; i < listModel.getSize(); i++) { - result[i] = (File) listModel.getElementAt(i); + Component list = getFileList(); + if(list instanceof JList) { + ListModel listModel = ((JList)list).getModel(); + File[] result = new File[listModel.getSize()]; + for (int i = 0; i < listModel.getSize(); i++) { + result[i] = (File) listModel.getElementAt(i); + } + return result; + } else { + TableModel listModel = ((JTable)list).getModel(); + File[] result = new File[listModel.getRowCount()]; + for (int i = 0; i < listModel.getRowCount(); i++) { + result[i] = (File) listModel.getValueAt(i, 0); + } + return result; } - return result; } /** @@ -1487,15 +1517,23 @@ Waiter drawingWaiter = new Waiter<>(new Waitable() { @Override public Rectangle actionProduced(Integer param) { - JList list = getFileList(); - int last_one = list.getModel().getSize() - 1; - if (last_one == -1) { + Component list = getFileList(); + int size = (list instanceof JList) ? ((JList) list).getModel().getSize() : + ((JTable)list).getModel().getRowCount(); + if (size == 0) { return new Rectangle(); } int current = (param != null) ? param : 0; try { - if (list.getCellBounds(current, current) != null) { - return list.getCellBounds(last_one, last_one); + if(list instanceof JList) + if (((JList) list).getCellBounds(current, current) != null) { + return ((JList) list).getCellBounds(size - 1, size - 1); + } else { + return null; + } + else + if (((JTable)list).getCellRect(current, 0, false) != null) { + return ((JTable)list).getCellRect(size - 1, 0, false); } else { return null; }