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 »

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: 9057
Joined: Fri Jul 09, 2004 5:18 pm

Re: Setting a wait cursor in the standalone client

Post by Radu »

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 »

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: 9057
Joined: Fri Jul 09, 2004 5:18 pm

Re: Setting a wait cursor in the standalone client

Post by Radu »

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 »

Ok. That works. Thanks!
Post Reply