The ConfirmDeleteDialog uses the default constructor and seems to rely on
shouldDelete(String, String) for the dialog's properties. However, the
show() method uses 'type' and 'name' without checking if they've been set or
not. Is this intended? It seems like the show method should either be
private or a static call should be made in place of both methods (since the
purpose of the dialog is centered around the shouldDelete method and
instances of the dialog are useless by themselves). -Damian
On Sat, Mar 22, 2008 at 2:33 PM, Kevin Menard <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I've just committed a fix for CAY-1011: Add confirmation dialog for delete
> actions. This required a lot more changes to the modeler than I've ever
> done before. Additionally, I had to make some changes to make the
> callbacks
> and listeners work similarly to attributes, relationships, etc.
>
> I've tested a fair bit and it appears work fine. But, any beatings would
> be
> much appreciated.
>
> Thanks,
> Kevin
>
>
import org.apache.cayenne.modeler.util.CayenneDialog;
import org.apache.cayenne.modeler.Application;
import org.apache.cayenne.modeler.action.ConfigurePreferencesAction;
import org.apache.cayenne.modeler.dialog.pref.PreferenceDialog;
import org.apache.cayenne.modeler.dialog.pref.GeneralPreferences;
import org.apache.cayenne.pref.PreferenceDetail;
import javax.swing.*;
import java.awt.*;
/**
* Used to confirm deleting items in the model.
*
* @author Kevin Menard
*/
public class ConfirmDeleteDialog extends CayenneDialog {
private ConfirmDeleteDialog() {}
public static boolean showDialog(String type, String name) {
PreferenceDetail pref = Application.getInstance().getPreferenceDomain().getDetail(GeneralPreferences.DELETE_PROMPT_PREFERENCE, true);
// See if the user has opted not to show the delete dialog.
if ((pref == null) || (false == pref.getBooleanProperty(GeneralPreferences.DELETE_PROMPT_PREFERENCE))) {
JCheckBox neverPromptAgainBox = new JCheckBox("Always delete without prompt.");
Object message[] = {String.format("Are you sure you would like to delete the %s named '%s'?", type, name), neverPromptAgainBox};
JOptionPane pane =
new JOptionPane(message,
JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
JDialog dialog = pane.createDialog(Application.getFrame(), "File exists");
dialog.setVisible(true);
Object selectedValue = pane.getValue();
boolean shouldDelete = selectedValue.equals(JOptionPane.YES_OPTION);
// If the user clicks "no", we'll just ignore whatever's in the checkbox because it's non-sensical.
if (shouldDelete) {
pref.setBooleanProperty(GeneralPreferences.DELETE_PROMPT_PREFERENCE, neverPromptAgainBox.isSelected());
Application.getInstance().getPreferenceService().savePreferences();
}
return shouldDelete;
}
}
}