Setting a wait cursor in the standalone client

Post here questions and problems related to oXygen frameworks/document types.
queshaw
Posts: 41
Joined: Wed Aug 08, 2007 5:56 am

Setting a wait cursor in the standalone client

Post by queshaw » Thu Dec 05, 2019 10:05 pm

I am working on a WorkspaceAccessPluginExtension. The UI consists of a menu and menu item. How can I set a wait cursor?

What I've tried so far:

Code: Select all

private  AtomicReference<JMenuBar> menuRef = new AtomicReference<JMenuBar>(); // Cringe
...
    @Override
    public void applicationStarted(final StandalonePluginWorkspace ws) {
        ws.addMenuBarCustomizer(new MenuBarCustomizer() {
            @Override
            public void customizeMainMenu(JMenuBar menuBar) {
                ...
                menuRef = new AtomicReference(menuBar);
            }
        });
    }
...
       return new AbstractAction("Sync") {
                Cursor cursor = menuRef.get().getCursor();
                 try {
...
                    menuRef.get().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
...
                } finally {
                    menuRef.get().setCursor(cursor);
                }
       } 

Radu
Posts: 6981
Joined: Fri Jul 09, 2004 5:18 pm

Re: Setting a wait cursor in the standalone client

Post by Radu » Fri Dec 06, 2019 12:47 pm

Hi,

You should try to set the busy cursor on the entire application main frame, something like:

Code: Select all

    javax.swing.JFrame parentFrame = (JFrame) PluginWorkspaceProvider.getPluginWorkspace().getParentFrame();
    parentFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
otherwise you will only set it on the menu bar area which is probably not what you are after.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

queshaw
Posts: 41
Joined: Wed Aug 08, 2007 5:56 am

Re: Setting a wait cursor in the standalone client

Post by queshaw » Tue Dec 10, 2019 2:56 am

Thank you.

This seems to work if I use CROSSHAIR_CURSOR, but the cursor doesn't change if I use WAIT_CURSOR. Do you know why that might be?

Radu
Posts: 6981
Joined: Fri Jul 09, 2004 5:18 pm

Re: Setting a wait cursor in the standalone client

Post by Radu » Tue Dec 10, 2019 11:13 am

Hi,

I tested and this works for me:

Code: Select all

      pluginWorkspaceAccess.addMenuBarCustomizer(new MenuBarCustomizer() {
        
        @Override
        public void customizeMainMenu(JMenuBar mainMenu) {
          JMenu custom = new JMenu("ABC");
          custom.add(new AbstractAction("TEST") {
            
            @Override
            public void actionPerformed(ActionEvent e) {
              javax.swing.JFrame parentFrame = (JFrame) PluginWorkspaceProvider.getPluginWorkspace().getParentFrame();
              parentFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
              
              try {
                Thread.sleep(10000);
              } catch (InterruptedException e1) {
                e1.printStackTrace();
              }
              
              parentFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
            }
          });
          mainMenu.add(custom);
        }
      });
    
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

queshaw
Posts: 41
Joined: Wed Aug 08, 2007 5:56 am

Re: Setting a wait cursor in the standalone client

Post by queshaw » Tue Dec 10, 2019 9:09 pm

Ok. That works. Thanks!

Post Reply