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
19   84   8   3.17
4   48   0.42   6
6     1.33  
1    
 
  JTableComboBoxEditorCellWriter       Line # 38 19 0% 8 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Jun 10, 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.driver.JComboBoxEditableQuery.isEditable;
19    import static org.fest.swing.driver.JTableStopCellEditingTask.stopEditing;
20    import static org.fest.util.Collections.list;
21   
22    import java.awt.Point;
23   
24    import javax.swing.JComboBox;
25    import javax.swing.JTable;
26   
27    import org.fest.swing.annotation.RunsInEDT;
28    import org.fest.swing.cell.JTableCellWriter;
29    import org.fest.swing.core.Robot;
30   
31    /**
32    * Understands an implementation of <code>{@link JTableCellWriter}</code> that knows how to use
33    * <code>{@link JComboBox}</code>es as cell editors.
34    *
35    * @author Alex Ruiz
36    * @author Yvonne Wang
37    */
 
38    public class JTableComboBoxEditorCellWriter extends AbstractJTableCellWriter {
39   
40    private final JComboBoxDriver driver;
41   
 
42  179 toggle public JTableComboBoxEditorCellWriter(Robot robot) {
43  179 super(robot);
44  179 driver = new JComboBoxDriver(robot);
45    }
46   
47    /** {@inheritDoc} */
 
48  5 toggle @RunsInEDT
49    public void enterValue(JTable table, int row, int column, String value) {
50  5 JComboBox editor = doStartCellEditing(table, row, column);
51  4 selectOrType(editor, value);
52  4 stopEditing(table, row, column);
53    }
54   
 
55  4 toggle private void selectOrType(JComboBox editor, String value) {
56  4 boolean selectValue = !isEditable(editor);
57  2 if (!selectValue) selectValue = list(driver.contentsOf(editor)).contains(value);
58  4 if (selectValue) {
59  3 driver.selectItem(editor, value);
60  3 return;
61    }
62  1 driver.enterText(editor, value);
63    }
64   
65    /** {@inheritDoc} */
 
66  2 toggle @RunsInEDT
67    public void startCellEditing(JTable table, int row, int column) {
68  2 doStartCellEditing(table, row, column);
69    }
70   
 
71  7 toggle @RunsInEDT
72    private JComboBox doStartCellEditing(JTable table, int row, int column) {
73  7 Point cellLocation = cellLocation(table, row, column, location);
74  7 robot.click(table, cellLocation); // activate JComboBox editor
75  7 JComboBox comboBox = waitForEditorActivation(table, row, column);
76  5 cellEditor(cellEditor(table, row, column));
77  5 return comboBox;
78    }
79   
 
80  7 toggle @RunsInEDT
81    private JComboBox waitForEditorActivation(JTable table, int row, int column) {
82  7 return waitForEditorActivation(table, row, column, JComboBox.class);
83    }
84    }