Announcement Announcement Module
Collapse
No announcement yet.
How to ask confirmation to close the view? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to ask confirmation to close the view?

    Hi!

    I am using the views in a MDI way, where the views appear as JInternalFrames.

    I need to let the user decide if he really wants to close the view when the "X" button of the view (JInternalFrame) is pressed, by showing a message with JOptionPane.

    Any hints?

    Thanks!

    Charles

  • #2
    Use a JInternalFrame with a registered VetoableChangeListener implemented like this:

    Code:
    public void vetoableChange(PropertyChangeEvent pEvt) throws PropertyVetoException
    {
       if (JInternalFrame.IS_CLOSED_PROPERTY.equals(pEvt.getPropertyName()) && Boolean.TRUE.equals(pEvt.getNewValue()))
    	{
    	     int ret = JOptionPane.showConfirmDialog(mInternalFrame, "Do you confirm ?", "confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    	     if (ret == JOptionPane.NO_OPTION)
    	     {
    		 throw new PropertyVetoException("", pEvt)
                 }
            }
    }

    Comment


    • #3
      Another way...

      Thanks!

      I also found another way to do it:

      Code:
      internalFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
      internalFrame.addInternalFrameListener(new InternalFrameAdapter() {
      
            public void internalFrameClosing(InternalFrameEvent e) {
                  int result = JOptionPane.showConfirmDialog(internalFrame, "Do you confirm ?",
                              "Confirm", JOptionPane.YES_NO_OPTION);
      
                  if (result == JOptionPane.YES_OPTION) {
                      internalFrame.dispose();
                  }
              }
      });

      Comment


      • #4
        But this seems to point to an "issue" in Spring RC.
        By issue, I mean the lack of support for this and the inability to pass the event to the view that has the model to detect whether or not it should be removed...

        Your solution require a change in Spring RC, in DesktopPageComponentPane from the mdi package I believe. It would be nice if the Component Pane could call a method on the pagecomponent to say "about to close" and have the ability to override it.

        I have raised this on JIRA
        http://opensource.atlassian.com/proj...browse/RCP-414

        Thanks

        Benoit

        Comment


        • #5
          This has been fixed.

          You can override the "boolean canClose()" method in your view, and return true or false. If you return false, the view will stay open.

          Peter

          Comment

          Working...
          X