/** * Returns a fixture that manages the field where the user can enter the name of the file to select in this fixture's * {@code JFileChooser}. * * @return the created fixture. * @throws org.assertj.swing.exception.ComponentLookupException if a matching textToMatch field could not be found. */ @Nonnull public JTextComponentFixture fileNameTextBox() { return new JTextComponentFixture(robot(), driver().fileNameTextBox(target())); }
/** * Finds a {@code JFileChooser} by name or type. * * @param robot contains the underlying finding to delegate the search to. * @return a {@code JFileChooserFixture} managing the found {@code JFileChooser}. * @throws org.assertj.swing.exception.WaitTimedOutError if a {@code JFileChooser} could not be found. */ @Override @Nonnull public JFileChooserFixture using(@Nonnull Robot robot) { return new JFileChooserFixture(robot, findComponentWith(robot)); }
/** * Simulates a user pressing the "Approve" button in this fixture's {@code JFileChooser}. * * @throws org.assertj.swing.exception.ComponentLookupException if the "Approve" button cannot be found. * @throws IllegalStateException if the "Approve" button is disabled. * @throws IllegalStateException if the "Approve" button is not showing on the screen. */ public void approve() { driver().clickApproveButton(target()); }
@Override public boolean matches(Object item) { if (item instanceof DialogFixture) return ((DialogFixture) item).target().isVisible(); if (item instanceof JDialog) return ((JDialog) item).isVisible(); if (item instanceof JFileChooserFixture) return ((JFileChooserFixture) item).target().isVisible(); throw new RuntimeException("Invalid matcher for " + item); }
public void cancelFileDialog() { // We need to be sure that the dialog is rendered before trying to cancel it waitFor(() -> fileDialog(500) != null); fileDialog().cancel(); // We wait for the dialog to disappear before handing over the thread waitFor(() -> fileDialog() == null); }
/** * Simulates a user pressing the "Cancel" button in this fixture's {@code JFileChooser}. * * @throws org.assertj.swing.exception.ComponentLookupException if the "Cancel" button cannot be found. * @throws IllegalStateException if the "Cancel" button is disabled. * @throws IllegalStateException if the "Cancel" button is not showing on the screen. */ public void cancel() { driver().clickCancelButton(target()); }
/** * Finds the "Cancel" button in this fixture's {@code JFileChooser}. * * @return the found "Cancel" button. * @throws org.assertj.swing.exception.ComponentLookupException if the "Cancel" button cannot be found. */ @Nonnull public JButtonFixture cancelButton() { return new JButtonFixture(robot(), driver().cancelButton(target())); }
/** * Sets the current directory of this fixture's {@code JFileChooser} to the given one. * * @param dir the directory to set as current. * @throws IllegalStateException if this fixture's {@code JFileChooser} is disabled. * @throws IllegalStateException if this fixture's {@code JFileChooser} is not showing on the screen. * @return this fixture. */ @Nonnull public JFileChooserFixture setCurrentDirectory(@Nonnull File dir) { driver().setCurrentDirectory(target(), dir); return this; } }
@RunsInEDT @Override @Nonnull public JFileChooserFixture fileChooser(@Nullable String name) { return new JFileChooserFixture(robot(), findByName(name, JFileChooser.class)); }
/** * Finds the "Approve" button in this fixture's {@code JFileChooser}. * * @return the found "Approve" button. * @throws org.assertj.swing.exception.ComponentLookupException if the "Approve" button cannot be found. */ @Nonnull public JButtonFixture approveButton() { return new JButtonFixture(robot(), driver().approveButton(target())); }
/** * Selects the given file in this fixture's {@code JFileChooser}. * * @param file the file to select. * @return this fixture. * @throws NullPointerException if the given file is {@code null}. * @throws IllegalStateException if this fixture's {@code JFileChooser} is disabled. * @throws IllegalStateException if this fixture's {@code JFileChooser} is not showing on the screen. * @throws IllegalArgumentException if this fixture's {@code JFileChooser} can select directories only and the file to * select is not a directory. * @throws IllegalArgumentException if this fixture's {@code JFileChooser} cannot select directories and the file to * select is a directory. */ @Nonnull public JFileChooserFixture selectFile(@Nonnull File file) { driver().selectFile(target(), file); return this; }
@Nonnull private JFileChooserFixture findFileChooser(@Nonnull ComponentMatcher matcher, @Nonnull Timeout timeout) { String description = "file chooser to be found using matcher " + matcher; ComponentFoundCondition condition = new ComponentFoundCondition(description, robot().finder(), matcher); pause(condition, timeout); JFileChooser fileChooser = (JFileChooser) condition.found(); return new JFileChooserFixture(robot(), checkNotNull(fileChooser)); }
/** * Selects the given files in this fixture's {@code JFileChooser}. * * @param files the files to select. * @return this fixture. * @throws NullPointerException if the given array of files is {@code null}. * @throws IllegalArgumentException if the given array of files is empty. * @throws IllegalStateException if this fixture's {@code JFileChooser} is disabled. * @throws IllegalStateException if this fixture's {@code JFileChooser} is not showing on the screen. * @throws IllegalStateException if this fixture's {@code JFileChooser} does not support multiple selection and there * is more than one file to select. * @throws IllegalArgumentException if this fixture's {@code JFileChooser} can select directories only and any of the * files to select is not a directory. * @throws IllegalArgumentException if this fixture's {@code JFileChooser} cannot select directories and any of the * files to select is a directory. */ @Nonnull public JFileChooserFixture selectFiles(@Nonnull File... files) { driver().selectFiles(target(), files); return this; }