Search in sources :

Example 16 with TableCell

use of org.fest.swing.data.TableCell in project ats-framework by Axway.

the class SwingTable method getCellIndexesByValue.

/**
     * Get table cell coordinates by cell value
     *
     * @param value cell value to search for
     * @param isRegEx if the value is a regular expression
     * @return an {@link ArrayList} with cell coordinates(indexes) represented by arrays [ row, column ] which contains
     *  the searched value
     * @throws VerificationException if the table element doesn't exist
     */
@PublicAtsApi
public List<Integer[]> getCellIndexesByValue(String value, boolean isRegEx) {
    new SwingElementState(this).waitToBecomeExisting();
    List<Integer[]> results = new ArrayList<Integer[]>();
    JTableFixture tableFixture = (JTableFixture) SwingElementLocator.findFixture(this);
    try {
        if (value == null) {
            isRegEx = false;
        }
        Pattern regexPattern = null;
        if (isRegEx) {
            regexPattern = Pattern.compile(value);
        }
        for (int row = 0; row < tableFixture.target.getRowCount(); row++) {
            for (int column = 0; column < tableFixture.target.getColumnCount(); column++) {
                String cellValue = null;
                try {
                    cellValue = tableFixture.valueAt(new TableCell(row, column) {
                    });
                } catch (NullPointerException npe) {
                // valueAt() throws NPE if the cell is null
                }
                if (cellValue == null && value != null) {
                    continue;
                }
                if ((cellValue == null && value == null) || (isRegEx && regexPattern.matcher(cellValue).matches()) || (!isRegEx && cellValue.equals(value))) {
                    results.add(new Integer[] { row, column });
                }
            }
        }
    } catch (Exception e) {
        throw new UiElementException(e.getMessage(), this);
    }
    return results;
}
Also used : Pattern(java.util.regex.Pattern) JTableFixture(org.fest.swing.fixture.JTableFixture) TableCell(org.fest.swing.data.TableCell) SwingElementState(com.axway.ats.uiengine.utilities.swing.SwingElementState) ArrayList(java.util.ArrayList) UiElementException(com.axway.ats.uiengine.exceptions.UiElementException) VerifyNotEqualityException(com.axway.ats.uiengine.exceptions.VerifyNotEqualityException) VerifyEqualityException(com.axway.ats.uiengine.exceptions.VerifyEqualityException) VerificationException(com.axway.ats.uiengine.exceptions.VerificationException) UiElementException(com.axway.ats.uiengine.exceptions.UiElementException) NotSupportedOperationException(com.axway.ats.uiengine.exceptions.NotSupportedOperationException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 17 with TableCell

use of org.fest.swing.data.TableCell in project ats-framework by Axway.

the class SwingTable method selectCell.

/**
     * Select table cell
     *
     * @param row the row number
     * @param column the column number
     * @throws VerificationException if the table element doesn't exist
     */
@PublicAtsApi
public void selectCell(int row, int column) {
    new SwingElementState(this).waitToBecomeExisting();
    JTableFixture tableFixture = (JTableFixture) SwingElementLocator.findFixture(this);
    try {
        tableFixture.selectCell(new TableCell(row, column) {
        });
    } catch (Exception e) {
        throw new UiElementException(e.getMessage(), this);
    }
}
Also used : JTableFixture(org.fest.swing.fixture.JTableFixture) TableCell(org.fest.swing.data.TableCell) SwingElementState(com.axway.ats.uiengine.utilities.swing.SwingElementState) UiElementException(com.axway.ats.uiengine.exceptions.UiElementException) VerifyNotEqualityException(com.axway.ats.uiengine.exceptions.VerifyNotEqualityException) VerifyEqualityException(com.axway.ats.uiengine.exceptions.VerifyEqualityException) VerificationException(com.axway.ats.uiengine.exceptions.VerificationException) UiElementException(com.axway.ats.uiengine.exceptions.UiElementException) NotSupportedOperationException(com.axway.ats.uiengine.exceptions.NotSupportedOperationException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 18 with TableCell

use of org.fest.swing.data.TableCell in project ats-framework by Axway.

the class SwingTable method drop.

/**
     * Simulates a user dropping an item into a specific table cell
     *
     * @param row the row number
     * @param column the column number
     */
@PublicAtsApi
public void drop(int row, int column) {
    new SwingElementState(this).waitToBecomeExisting();
    ((JTableFixture) SwingElementLocator.findFixture(this)).drop(new TableCell(row, column) {
    });
}
Also used : JTableFixture(org.fest.swing.fixture.JTableFixture) TableCell(org.fest.swing.data.TableCell) SwingElementState(com.axway.ats.uiengine.utilities.swing.SwingElementState) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 19 with TableCell

use of org.fest.swing.data.TableCell in project ats-framework by Axway.

the class SwingTable method getCellBackgroundColor.

/**
     * Returns the table cell background {@link Color}
     *
     * @param row the row number
     * @param column the column number
     */
@PublicAtsApi
public Color getCellBackgroundColor(int row, int column) {
    new SwingElementState(this).waitToBecomeExisting();
    JTableFixture tableFixture = (JTableFixture) SwingElementLocator.findFixture(this);
    return tableFixture.backgroundAt(new TableCell(row, column) {
    }).target();
}
Also used : JTableFixture(org.fest.swing.fixture.JTableFixture) TableCell(org.fest.swing.data.TableCell) SwingElementState(com.axway.ats.uiengine.utilities.swing.SwingElementState) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 20 with TableCell

use of org.fest.swing.data.TableCell in project android by JetBrains.

the class ThemeEditorTableTest method testStateListPicker.

/**
   * Test creating a new state list and setting it as a style attribute value with the state list picker.
   */
@Test
public void testStateListPicker() throws IOException {
    guiTest.importSimpleApplication();
    ThemeEditorFixture themeEditor = ThemeEditorGuiTestUtils.openThemeEditor(guiTest.ideFrame());
    ThemeEditorTableFixture themeEditorTable = themeEditor.getPropertiesTable();
    TableCell parentCell = row(0).column(0);
    JTableCellFixture parentCellFixture = themeEditorTable.cell(parentCell);
    // Selects AppCompat as parent
    Component parentEditor = parentCellFixture.editor();
    parentCellFixture.startEditing();
    JComboBoxFixture parentComboBox = new JComboBoxFixture(guiTest.robot(), guiTest.robot().finder().findByType((JComponent) parentEditor, JComboBox.class));
    parentComboBox.selectItem("Theme.AppCompat.NoActionBar");
    parentCellFixture.stopEditing();
    TableCell cell = row(8).column(0);
    FontFixture cellFont = themeEditorTable.fontAt(cell);
    cellFont.requireNotBold();
    assertEquals("android:textColorPrimary", themeEditorTable.attributeNameAt(cell));
    assertEquals("@android:color/primary_text_material_dark", themeEditorTable.valueAt(cell));
    JTableCellFixture stateListCell = themeEditorTable.cell(cell);
    ResourceComponentFixture resourceComponent = new ResourceComponentFixture(guiTest.robot(), (ResourceComponent) stateListCell.editor());
    stateListCell.startEditing();
    resourceComponent.getSwatchButton().click();
    final ChooseResourceDialogFixture dialog = ChooseResourceDialogFixture.find(guiTest.robot());
    StateListPickerFixture stateListPicker = dialog.getStateListPicker();
    List<StateListComponentFixture> states = stateListPicker.getStateComponents();
    assertThat(states).hasSize(2);
    final StateListComponentFixture state0 = states.get(0);
    assertEquals("Not enabled", state0.getStateName());
    assertEquals("@android:color/primary_text_default_material_dark", state0.getValue());
    assertTrue(state0.isAlphaVisible());
    assertEquals("@android:dimen/disabled_alpha_material_dark", state0.getAlphaValue());
    final StateListComponentFixture state1 = states.get(1);
    assertEquals("Default", state1.getStateName());
    assertEquals("@android:color/primary_text_default_material_dark", state1.getValue());
    assertFalse(state1.isAlphaVisible());
    state0.getValueComponent().getSwatchButton().click();
    ChooseResourceDialogFixture secondDialog = ChooseResourceDialogFixture.find(guiTest.robot(), new GenericTypeMatcher<JDialog>(JDialog.class) {

        @Override
        protected boolean isMatching(@NotNull JDialog component) {
            return !component.equals(dialog.target());
        }
    });
    secondDialog.getColorPicker().setColorWithIntegers(new Color(200, 0, 0, 200));
    secondDialog.clickOK();
    Wait.seconds(1).expecting("component update").until(() -> "@color/primary_text_default_material_dark".equals(state0.getValue()));
    state0.getAlphaComponent().getSwatchButton().click();
    secondDialog = ChooseResourceDialogFixture.find(guiTest.robot(), new GenericTypeMatcher<JDialog>(JDialog.class) {

        @Override
        protected boolean isMatching(@NotNull JDialog component) {
            return !component.equals(dialog.target());
        }
    });
    secondDialog.getResourceNameTable().cell("android:disabledAlpha").click();
    secondDialog.clickOK();
    Wait.seconds(1).expecting("component update").until(() -> "?android:attr/disabledAlpha".equals(state0.getAlphaValue()));
    state1.getValueComponent().getSwatchButton().click();
    secondDialog = ChooseResourceDialogFixture.find(guiTest.robot(), new GenericTypeMatcher<JDialog>(JDialog.class) {

        @Override
        protected boolean isMatching(@NotNull JDialog component) {
            return !component.equals(dialog.target());
        }
    });
    secondDialog.getColorPicker().setColorWithIntegers(new Color(0, 200, 0, 255));
    secondDialog.clickOK();
    Wait.seconds(1).expecting("component update").until(() -> "@color/primary_text_default_material_dark".equals(state1.getValue()));
    dialog.requireNoError();
    dialog.clickOK();
    stateListCell.stopEditing();
    cellFont = themeEditorTable.fontAt(cell);
    cellFont.requireBold();
    assertEquals("android:textColorPrimary", themeEditorTable.attributeNameAt(cell));
    assertEquals("@color/primary_text_material_dark", themeEditorTable.valueAt(cell));
}
Also used : GenericTypeMatcher(org.fest.swing.core.GenericTypeMatcher) NotNull(org.jetbrains.annotations.NotNull) TableCell(org.fest.swing.data.TableCell) ResourceComponent(com.android.tools.idea.editors.theme.ui.ResourceComponent) Test(org.junit.Test)

Aggregations

TableCell (org.fest.swing.data.TableCell)26 JTableFixture (org.fest.swing.fixture.JTableFixture)15 PublicAtsApi (com.axway.ats.common.PublicAtsApi)12 SwingElementState (com.axway.ats.uiengine.utilities.swing.SwingElementState)12 Test (org.junit.Test)12 NotSupportedOperationException (com.axway.ats.uiengine.exceptions.NotSupportedOperationException)7 UiElementException (com.axway.ats.uiengine.exceptions.UiElementException)7 VerificationException (com.axway.ats.uiengine.exceptions.VerificationException)6 VerifyEqualityException (com.axway.ats.uiengine.exceptions.VerifyEqualityException)6 VerifyNotEqualityException (com.axway.ats.uiengine.exceptions.VerifyNotEqualityException)6 ChooseResourceDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.ChooseResourceDialogFixture)3 ResourceComponent (com.android.tools.idea.editors.theme.ui.ResourceComponent)2 JTableCellFixture (org.fest.swing.fixture.JTableCellFixture)2 NotNull (org.jetbrains.annotations.NotNull)2 ColorPickerFixture (com.android.tools.idea.tests.gui.framework.fixture.ColorPickerFixture)1 EditorFixture (com.android.tools.idea.tests.gui.framework.fixture.EditorFixture)1 SlideFixture (com.android.tools.idea.tests.gui.framework.fixture.SlideFixture)1 ThemeSelectionDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.ThemeSelectionDialogFixture)1 NewStyleDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.theme.NewStyleDialogFixture)1 ThemeEditorFixture (com.android.tools.idea.tests.gui.framework.fixture.theme.ThemeEditorFixture)1