Can't get SWT Display on Mac OS X

前端 未结 4 1915
情歌与酒
情歌与酒 2021-02-06 07:50

I\'m running Mac OS X Snow Leopard and wan\'t to access the Display from the activator in an OSGi bundle.

Below is the start method for my activator:

@O         


        
4条回答
  •  太阳男子
    2021-02-06 08:16

    This code looks very strange... is this supposed to be an Eclipse plugin? What are you trying to do? I'll guess that you are trying to create an RCP plugin with a User Interface. If so, here's the answer: Don't do that. Your OSGi Activator is not be responsible for creating the SWT display event loop.

    Create an application extension in your plugin.xml to declaratively create the SWT bootstrap. It will look something like this:

       
          
             
             
          
       
    

    Then create the Application class (call it whatever you want) to look something like this:

    public class Application implements IApplication {
    
        /* (non-Javadoc)
         * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
         */
        public Object start(IApplicationContext context) {
            Display display = PlatformUI.createDisplay();
            try {
                int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());
                if (returnCode == PlatformUI.RETURN_RESTART) {
                    return IApplication.EXIT_RESTART;
                }
                return IApplication.EXIT_OK;
            } finally {
                display.dispose();
            }
        }
    
        /* (non-Javadoc)
         * @see org.eclipse.equinox.app.IApplication#stop()
         */
        public void stop() {
            final IWorkbench workbench = PlatformUI.getWorkbench();
            if (workbench == null)
                return;
            final Display display = workbench.getDisplay();
            display.syncExec(new Runnable() {
                public void run() {
                    if (!display.isDisposed())
                        workbench.close();
                }
            });
        }
    }
    

    Obviously make sure you have the SWT plugins (org.eclipse.ui) available in your Manifest as well as the runtime.

    I hope that helps.

提交回复
热议问题