Clover Coverage Report - FEST Swing 1.2
Coverage timestamp: Tue Jun 1 2010 15:19:25 PDT
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
10   66   7   2.5
6   37   0.7   4
4     1.75  
1    
4.8% of code in this file is excluded from these metrics.
 
  JTableMatchingCellQuery       Line # 38 10 4.8% 7 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Nov 20, 2008
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10    * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11    * or implied. See the License for the specific language governing permissions and limitations under
12    * the License.
13    *
14    * Copyright @2008-2010 the original author or authors.
15    */
16    package org.fest.swing.driver;
17   
18    import static org.fest.swing.data.TableCell.row;
19    import static org.fest.swing.edt.GuiActionRunner.execute;
20    import static org.fest.swing.exception.ActionFailedException.actionFailure;
21    import static org.fest.util.Strings.concat;
22   
23    import javax.swing.JTable;
24   
25    import org.fest.swing.annotation.RunsInCurrentThread;
26    import org.fest.swing.annotation.RunsInEDT;
27    import org.fest.swing.cell.JTableCellReader;
28    import org.fest.swing.data.TableCell;
29    import org.fest.swing.edt.GuiQuery;
30    import org.fest.swing.util.TextMatcher;
31   
32    /**
33    * Understands an action, executed in the event dispatch thread, that returns the first cell in a
34    * <code>{@link JTable}</code> whose value matches the given one.
35    *
36    * @author Alex Ruiz
37    */
 
38    final class JTableMatchingCellQuery {
39   
 
40  8 toggle @RunsInEDT
41    static TableCell cellWithValue(final JTable table, final TextMatcher matcher, final JTableCellReader cellReader) {
42  8 return execute(new GuiQuery<TableCell>() {
 
43  8 toggle protected TableCell executeInEDT() {
44  8 return findMatchingCell(table, matcher, cellReader);
45    }
46    });
47    }
48   
 
49  8 toggle @RunsInCurrentThread
50    private static TableCell findMatchingCell(JTable table, TextMatcher matcher, JTableCellReader cellReader) {
51  8 int rCount = table.getRowCount();
52  8 int cCount = table.getColumnCount();
53  49 for (int r = 0; r < rCount; r++)
54  303 for (int c = 0; c < cCount; c++)
55  6 if (cellHasValue(table, r, c, matcher, cellReader)) return row(r).column(c);
56  2 throw actionFailure(concat("Unable to find cell matching ", matcher.description(), " ", matcher.formattedValues()));
57    }
58   
 
59  262 toggle @RunsInCurrentThread
60    private static boolean cellHasValue(JTable table, int row, int column, TextMatcher matcher,
61    JTableCellReader cellReader) {
62  262 return matcher.isMatching(cellReader.valueAt(table, row, column));
63    }
64   
 
65    toggle private JTableMatchingCellQuery() {}
66    }