Skip to content

Commit

Permalink
Implement confirmation dialogs and string overrides
Browse files Browse the repository at this point in the history
This implements two APIs:

  * An API for requiring the confirmation of selections
    of existing files when the chooser is in CREATE
    mode.

  * An API for providing overrides of button strings.

Affects: #17
Affects: #7
  • Loading branch information
io7m committed May 1, 2021
1 parent c4b177b commit a36e341
Show file tree
Hide file tree
Showing 12 changed files with 634 additions and 52 deletions.
Expand Up @@ -74,7 +74,8 @@ public static DateTimeFormatter fileTimeFormatter()
* returned.
*/

public static Function<Path, Boolean> fileSelectionMode() {
public static Function<Path, Boolean> fileSelectionMode()
{
return (path) -> true;
}

Expand Down
Expand Up @@ -143,6 +143,8 @@ default boolean allowDirectoryCreation()
* the file listing. This entry is always called "..".
*
* @return {@code true} if the directory listing will contain ".."
*
* @since 3.0.0
*/

@Value.Default
Expand Down Expand Up @@ -214,4 +216,32 @@ default void checkPreconditions()
);
});
}

/**
* If set to {@code true}, then when the user is using a mode such as
* {@link JWFileChooserAction#CREATE}, a confirmation dialog will be displayed
* if the user selects a file that already exists.
*
* @return {@code true} if confirmation dialogs should be shown
*
* @since 3.0.0
*/

@Value.Default
default boolean confirmFileSelection()
{
return false;
}

/**
* @return A provider of UI string overrides
*
* @since 3.0.0
*/

@Value.Default
default JWFileChooserStringOverridesType stringOverrides()
{
return JWFileChooserStringOverridesEmpty.get();
}
}
@@ -0,0 +1,93 @@
/*
* Copyright © 2021 Mark Raynsford <code@io7m.com> http://io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

package com.io7m.jwheatsheaf.api;

import java.util.Optional;

/**
* An abstract set of string overrides that override nothing.
*/

public abstract class JWFileChooserStringOverridesAbstract
implements JWFileChooserStringOverridesType
{
protected JWFileChooserStringOverridesAbstract()
{

}

/**
* {@inheritDoc}
*
* Overrides of this method are NOT required to call this method via {@code super}.
*/

@Override
public Optional<String> buttonOpen()
{
return Optional.empty();
}

/**
* {@inheritDoc}
*
* Overrides of this method are NOT required to call this method via {@code super}.
*/

@Override
public Optional<String> buttonSave()
{
return Optional.empty();
}

/**
* {@inheritDoc}
*
* Overrides of this method are NOT required to call this method via {@code super}.
*/

@Override
public Optional<String> confirmReplaceMessage(
final String file)
{
return Optional.empty();
}

/**
* {@inheritDoc}
*
* Overrides of this method are NOT required to call this method via {@code super}.
*/

@Override
public Optional<String> confirmReplaceButton()
{
return Optional.empty();
}

/**
* {@inheritDoc}
*
* Overrides of this method are NOT required to call this method via {@code super}.
*/

@Override
public Optional<String> confirmTitleMessage()
{
return Optional.empty();
}
}
@@ -0,0 +1,42 @@
/*
* Copyright © 2021 Mark Raynsford <code@io7m.com> http://io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

package com.io7m.jwheatsheaf.api;

/**
* A set of string overrides that override nothing.
*/

public final class JWFileChooserStringOverridesEmpty
extends JWFileChooserStringOverridesAbstract
{
private static final JWFileChooserStringOverridesType INSTANCE =
new JWFileChooserStringOverridesEmpty();

private JWFileChooserStringOverridesEmpty()
{

}

/**
* @return The empty set of overrides
*/

public static JWFileChooserStringOverridesType get()
{
return INSTANCE;
}
}
@@ -0,0 +1,71 @@
/*
* Copyright © 2021 Mark Raynsford <code@io7m.com> http://io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

package com.io7m.jwheatsheaf.api;

import java.util.Optional;

/**
* The set of string overrides. For any of the methods in this class, if
* {@link Optional#empty()} is returned, a default string will be used.
*
* @since 3.0.0
*/

public interface JWFileChooserStringOverridesType
{
/**
* A message override for the "Open" button.
*
* @return A message override
*/

Optional<String> buttonOpen();

/**
* A message override for the "Save" button.
*
* @return A message override
*/

Optional<String> buttonSave();

/**
* A message override for the "Do you want to replace this file?" message.
*
* @param file The file
*
* @return A message override
*/

Optional<String> confirmReplaceMessage(String file);

/**
* A message override for the "Replace" confirmation button.
*
* @return A message override
*/

Optional<String> confirmReplaceButton();

/**
* A message override for the "Replace?" confirmation dialog header.
*
* @return A message override
*/

Optional<String> confirmTitleMessage();
}
Expand Up @@ -19,6 +19,8 @@
import com.io7m.jwheatsheaf.api.JWFileChooserAction;
import com.io7m.jwheatsheaf.api.JWFileChooserConfiguration;
import com.io7m.jwheatsheaf.api.JWFileChooserEventType;
import com.io7m.jwheatsheaf.api.JWFileChooserStringOverridesEmpty;
import com.io7m.jwheatsheaf.api.JWFileChooserStringOverridesType;
import com.io7m.jwheatsheaf.ui.JWFileChoosers;
import com.io7m.jwheatsheaf.ui.internal.JWFileChoosersTesting;
import javafx.collections.FXCollections;
Expand Down Expand Up @@ -68,6 +70,10 @@ public final class ExampleViewController implements Initializable
@FXML
private CheckBox parentDirectory;
@FXML
private CheckBox confirmSelection;
@FXML
private CheckBox unusualStrings;
@FXML
private ChoiceBox<JWFileChooserAction> action;
@FXML
private TextField title;
Expand Down Expand Up @@ -151,6 +157,12 @@ private void onParentDirectoryChanged()

}

@FXML
private void onConfirmSelectionChanged()
{

}

@FXML
private void onOpenSelected()
throws IOException
Expand All @@ -170,16 +182,28 @@ private void onOpenSelected()
);

final var configurationBuilder =
JWFileChooserConfiguration.builder()
.setAllowDirectoryCreation(this.allowDirectoryCreation.isSelected())
.setShowParentDirectory(this.parentDirectory.isSelected())
.setFileSystem(fileSystem)
.setCssStylesheet(ExampleViewController.class.getResource(this.cssSelection.getValue()))
.setFileImageSet(imageSet)
.setAction(this.action.getValue())
.addFileFilters(new ExampleFilterRejectAll())
.addFileFilters(new ExampleFilterXML())
.addAllRecentFiles(recents);
JWFileChooserConfiguration.builder();

final JWFileChooserStringOverridesType stringOverrides;
if (this.unusualStrings.isSelected()) {
stringOverrides = new ExampleWeirdStrings();
configurationBuilder.setTitle("Please deblaterate on your limerance!");
} else {
stringOverrides = JWFileChooserStringOverridesEmpty.get();
}

configurationBuilder
.setAllowDirectoryCreation(this.allowDirectoryCreation.isSelected())
.setShowParentDirectory(this.parentDirectory.isSelected())
.setConfirmFileSelection(this.confirmSelection.isSelected())
.setFileSystem(fileSystem)
.setCssStylesheet(ExampleViewController.class.getResource(this.cssSelection.getValue()))
.setFileImageSet(imageSet)
.setAction(this.action.getValue())
.setStringOverrides(stringOverrides)
.addFileFilters(new ExampleFilterRejectAll())
.addFileFilters(new ExampleFilterXML())
.addAllRecentFiles(recents);

if (this.homeDirectory.isSelected()) {
configurationBuilder.setHomeDirectory(
Expand Down
@@ -0,0 +1,65 @@
/*
* Copyright © 2021 Mark Raynsford <code@io7m.com> http://io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

package com.io7m.jwheatsheaf.examples;

import com.io7m.jwheatsheaf.api.JWFileChooserStringOverridesAbstract;

import java.util.Optional;

/**
* A set of weird strings.
*/

public final class ExampleWeirdStrings
extends JWFileChooserStringOverridesAbstract
{
public ExampleWeirdStrings()
{

}

@Override
public Optional<String> buttonOpen()
{
return Optional.of("Vigilate");
}

@Override
public Optional<String> buttonSave()
{
return Optional.of("Manticulate");
}

@Override
public Optional<String> confirmReplaceMessage(
final String file)
{
return Optional.of(String.format("Defloccate velleity '%s'?", file));
}

@Override
public Optional<String> confirmReplaceButton()
{
return Optional.of("Defloccate");
}

@Override
public Optional<String> confirmTitleMessage()
{
return Optional.of("Defloccate velleity?");
}
}

0 comments on commit a36e341

Please sign in to comment.