一、 将jbpm变为基于RCP的应用
开源的jbpm一个eclipse中plugin的项目不是RCP项目。所以要先将jbpm变为一个RCP独立的应用程序。
将jbpm导入eclipse
从http://labs.jboss.com/jbossjbpm/jpdl_downloads/上下载jbpm,解压;
在eclipse下导入工程,有两个工程要导入,如图中的两个文件夹,分别是org.jbpm.gd.jpdl文件夹和org.jbpm.gd.jpdl两个文件夹
导入好以后在eclipse中的形态应如图
在plugin.xml文件中增加对"org.eclipse.core.runtime.applications"的扩展
先在org.jbpm.gd.jpdl中新建一个包org.jbpm.gd.jpdl.rcp,在下面建五个类
package org.jbpm.gd.jpdl.rcp; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle */ public class Activator extends AbstractUIPlugin { // The plug-in ID public static final String PLUGIN_ID = "org.jbpm.gd.jpdl.rcp"; // The shared instance private static Activator plugin; /** * The constructor */ public Activator() { } /* * (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ public void start(BundleContext context) throws Exception { super.start(context); plugin = this; } /* * (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); } /** * Returns the shared instance * * @return the shared instance */ public static Activator getDefault() { return plugin; } /** * Returns an image descriptor for the image file at the given * plug-in relative path * * @param path the path * @return the image descriptor */ public static ImageDescriptor getImageDescriptor(String path) { return imageDescriptorFromPlugin(PLUGIN_ID, path); } }
package org.jbpm.gd.jpdl.rcp; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PlatformUI; /** * This class controls all aspects of the application's execution */ public class Application implements IApplication { /* (non-Javadoc) * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext) */ public Object start(IApplicationContext context) throws Exception { Display display = PlatformUI.createDisplay(); try { int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()); if (returnCode == PlatformUI.RETURN_RESTART) return IApplication.EXIT_RESTART; else 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(); } }); } }
package org.jbpm.gd.jpdl.rcp; import org.eclipse.jface.action.IMenuManager; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.application.ActionBarAdvisor; import org.eclipse.ui.application.IActionBarConfigurer; public class ApplicationActionBarAdvisor extends ActionBarAdvisor { public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) { super(configurer); } protected void makeActions(IWorkbenchWindow window) { } protected void fillMenuBar(IMenuManager menuBar) { } }
package org.jbpm.gd.jpdl.rcp; import org.eclipse.ui.application.IWorkbenchConfigurer; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; import org.eclipse.ui.application.WorkbenchAdvisor; import org.eclipse.ui.application.WorkbenchWindowAdvisor; public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor { private static final String PERSPECTIVE_ID = "org.jbpm.gd.jpdl.JpdlPerspective"; public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { return new ApplicationWorkbenchWindowAdvisor(configurer); } public String getInitialWindowPerspectiveId() { return PERSPECTIVE_ID; } public void initialize(IWorkbenchConfigurer configurer) { super.initialize(configurer); } }
package org.jbpm.gd.jpdl.rcp; import org.eclipse.swt.graphics.Point; import org.eclipse.ui.application.ActionBarAdvisor; import org.eclipse.ui.application.IActionBarConfigurer; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; import org.eclipse.ui.application.WorkbenchWindowAdvisor; public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { super(configurer); } public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) { return new ApplicationActionBarAdvisor(configurer); } public void preWindowOpen() { IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); configurer.setInitialSize(new Point(1024, 768)); configurer.setShowCoolBar(false); configurer.setShowStatusLine(false); configurer.setTitle("JBPM"); } }
打开org.jbpm.gd.jpdl中的plugin.xml,选择名为extensions的tab项,在Add中加入org.eclipse.croe.runtime.applications,并对其做如图配置,或者在plugin.xml代码中加入:
为项目增加product Configuration配置,并导出应用程序
选择org.jbpm.gd.jpdl工程,点右键New/Other/Product Configuration
增加一个名为org.jbpm.gd.jpdl.product的文件,在overview页中,为产品配置name为jbpm,在produt Id栏中点击new,设置name为org.jbpm.gd.jpdl,finish,在product configuration里选择plug-ins 保存。
然后点击product configuration进入configuration页,点击Add在弹出框里选择org.jbpm.gd.jpdl,然后点击add required plug-ins按钮。保存。
product Configuration 的配置完成,可以将工程导出为应用程序了。
导出程序
选择org.jbpm.gd.jpdl工程,点右键Export,在弹出框中选择Eclipse product,next,选择你建的product configuration和导出的目录,finish,工程导出完成。在你导出的目录里,你可以找到eclipse.exe文件,双击可以直接打开应用程序。