From 3794e32468caad49611d66f160f6134272752db9 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 5 Feb 2019 13:36:49 +0000 Subject: [PATCH] JAL-3048 JS-compatible confirm dialog on delete all --- src/jalview/gui/AlignFrame.java | 114 ++++++++++++++++++------------------ src/jalview/gui/PopupMenu.java | 4 +- src/jalview/jbgui/GAlignFrame.java | 12 ++-- 3 files changed, 64 insertions(+), 66 deletions(-) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 0b09fe5..2a5d372 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -624,7 +624,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, case KeyEvent.VK_BACK_SPACE: if (!viewport.cursorMode) { - cut_actionPerformed(null); + cut_actionPerformed(); } else { @@ -1895,7 +1895,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * DOCUMENT ME! */ @Override - protected void copy_actionPerformed(ActionEvent e) + protected void copy_actionPerformed() { if (viewport.getSelectionGroup() == null) { @@ -2364,26 +2364,20 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! + * Action Cut (delete and copy) the selected region */ @Override - protected void cut_actionPerformed(ActionEvent e) + protected void cut_actionPerformed() { - copy_actionPerformed(null); - delete_actionPerformed(null); + copy_actionPerformed(); + delete_actionPerformed(); } /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! + * Performs menu option to Delete the currently selected region */ @Override - protected void delete_actionPerformed(ActionEvent evt) + protected void delete_actionPerformed() { SequenceGroup sg = viewport.getSelectionGroup(); @@ -2392,52 +2386,56 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return; } + Runnable okAction = new Runnable() + { + @Override + public void run() + { + SequenceI[] cut = sg.getSequences() + .toArray(new SequenceI[sg.getSize()]); + + addHistoryItem(new EditCommand( + MessageManager.getString("label.cut_sequences"), Action.CUT, + cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1, + viewport.getAlignment())); + + viewport.setSelectionGroup(null); + viewport.sendSelection(); + viewport.getAlignment().deleteGroup(sg); + + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); + if (viewport.getAlignment().getHeight() < 1) + { + try + { + AlignFrame.this.setClosed(true); + } catch (Exception ex) + { + } + } + }}; + /* - * If the cut affects all sequences, warn, remove highlighted columns + * If the cut affects all sequences, prompt for confirmation */ - if (sg.getSize() == viewport.getAlignment().getHeight()) - { - boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes()) - + 1) == viewport.getAlignment().getWidth()) ? true : false; - if (isEntireAlignWidth) - { - int confirm = JvOptionPane.showConfirmDialog(this, - MessageManager.getString("warn.delete_all"), // $NON-NLS-1$ - MessageManager.getString("label.delete_all"), // $NON-NLS-1$ - JvOptionPane.OK_CANCEL_OPTION); - - if (confirm == JvOptionPane.CANCEL_OPTION - || confirm == JvOptionPane.CLOSED_OPTION) - { - return; - } - } - viewport.getColumnSelection().removeElements(sg.getStartRes(), - sg.getEndRes() + 1); - } - SequenceI[] cut = sg.getSequences() - .toArray(new SequenceI[sg.getSize()]); - - addHistoryItem(new EditCommand( - MessageManager.getString("label.cut_sequences"), Action.CUT, - cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1, - viewport.getAlignment())); - - viewport.setSelectionGroup(null); - viewport.sendSelection(); - viewport.getAlignment().deleteGroup(sg); - - viewport.firePropertyChange("alignment", null, - viewport.getAlignment().getSequences()); - if (viewport.getAlignment().getHeight() < 1) - { - try - { - this.setClosed(true); - } catch (Exception ex) - { - } - } + boolean wholeHeight = sg.getSize() == viewport.getAlignment().getHeight(); + boolean wholeWidth = (((sg.getEndRes() - sg.getStartRes()) + + 1) == viewport.getAlignment().getWidth()) ? true : false; + if (wholeHeight && wholeWidth) + { + JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop); + dialog.setResponseHandler(0, okAction); // 0 = OK_OPTION + Object[] options = new Object[] { MessageManager.getString("action.ok"), + MessageManager.getString("action.cancel") }; + dialog.showDialog(MessageManager.getString("warn.delete_all"), + MessageManager.getString("label.delete_all"), + JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null, + options, options[0]); + } else + { + okAction.run(); + } } /** diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 7118c69..6902c88 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -1975,12 +1975,12 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener public void copy_actionPerformed() { - ap.alignFrame.copy_actionPerformed(null); + ap.alignFrame.copy_actionPerformed(); } public void cut_actionPerformed() { - ap.alignFrame.cut_actionPerformed(null); + ap.alignFrame.cut_actionPerformed(); } void changeCase(ActionEvent e) diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index a96d4f3..5940172 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -969,7 +969,7 @@ public class GAlignFrame extends JInternalFrame @Override public void actionPerformed(ActionEvent e) { - copy_actionPerformed(e); + copy_actionPerformed(); } }; addMenuActionAndAccelerator(keyStroke, copy, al); @@ -982,7 +982,7 @@ public class GAlignFrame extends JInternalFrame @Override public void actionPerformed(ActionEvent e) { - cut_actionPerformed(e); + cut_actionPerformed(); } }; addMenuActionAndAccelerator(keyStroke, cut, al); @@ -994,7 +994,7 @@ public class GAlignFrame extends JInternalFrame @Override public void actionPerformed(ActionEvent e) { - delete_actionPerformed(e); + delete_actionPerformed(); } }); @@ -2351,15 +2351,15 @@ public class GAlignFrame extends JInternalFrame { } - protected void copy_actionPerformed(ActionEvent e) + protected void copy_actionPerformed() { } - protected void cut_actionPerformed(ActionEvent e) + protected void cut_actionPerformed() { } - protected void delete_actionPerformed(ActionEvent e) + protected void delete_actionPerformed() { } -- 1.7.10.2