开发JDeveloper插件

想要做的事很简单,就是在Project下加两个菜单,第一个是流程移植,第二个是流程设置。

第一步,实现一个菜单上下文监听器。
package bms.processdeploy;

import oracle.ide.Context;
import oracle.ide.controller.ContextMenu;
import oracle.ide.controller.ContextMenuListener;
import oracle.ide.controller.IdeAction;
import oracle.ide.model.Element;
import oracle.ide.model.Project;

public class DeployContextMenuListener implements ContextMenuListener {

public void menuWillShow(ContextMenu contextMenu) {
Element e = contextMenu.getContext().getElement();
if (e instanceof Project) {
IdeAction action = IdeAction.find(ProcessDeployCommand.actionId());
contextMenu.add(contextMenu.createMenuItem(action));

IdeAction _action = IdeAction.find(ProcessPreferenceCommand.actionId());
contextMenu.add(contextMenu.createMenuItem(_action));
}
}

public void menuWillHide(ContextMenu contextMenu) {
}

public boolean handleDefaultAction(Context context) {
return false;
}
}

代码里面涉及的两个Action稍后再补充说明,Action是指菜单项点击之后系统对应的动作。

第二步,加入流程移植和流程设置的两个Action。
右键选择New Gallery,选择Client Tier下面的Extension Development,分别创建两个Action。
流程移植的控制器代码如下:
package bms.processdeploy;

import oracle.ide.Context;
import oracle.ide.Ide;
import oracle.ide.controller.Controller;
import oracle.ide.controller.IdeAction;
import oracle.ide.extension.RegisteredByExtension;
import oracle.ide.wizard.WizardManager;


/**
* Controller for action bms.processdeploy.processdeploy.
*/
@RegisteredByExtension("bms.processdeploy")
public final class ProcessDeployController implements Controller {

public boolean update(IdeAction action, Context context) {
return true;
}

public boolean handleEvent(IdeAction action, Context context) {
return false;
}
}

流程移植的命令代码如下:
package bms.processdeploy;

import example.TempConvert;
import example.TempConvertSoap;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

import oracle.ide.Context;
import oracle.ide.Ide;
import oracle.ide.controller.Command;
import oracle.ide.extension.RegisteredByExtension;

import oracle.javatools.dialogs.MessageDialog;

/**
* Command handler for bms.processdeploy.processdeploy.
*/
@RegisteredByExtension("bms.processdeploy")
public final class ProcessDeployCommand extends Command {
public ProcessDeployCommand() {
super(actionId());
}

public int doit() {
String msg = "";
String dir = context.getProject().getBaseDirectory();
File processDir = new File(dir + "/processes");
if (processDir.exists()) {
for(File processFile : processDir.listFiles()) {
msg = processFile.getAbsolutePath();

try {
FileInputStream fis = new FileInputStream(processFile);
byte[] buf = new byte[1024];
StringBuffer sb=new StringBuffer();
while((fis.read(buf))!=-1) {
sb.append(new String(buf));
buf=new byte[1024];
}
System.out.println();
System.out.println(sb.toString());

msg += ",流程移植成功!";
} catch (FileNotFoundException e) {
msg += ",无法找到该文件!";
} catch (IOException e) {
msg += ",读写异常!";
}
}
} else {
msg = "这不是一个流程项目!";
}

showMessageBox(msg);
return OK;
}

private void showMessageBox(String msg) {
String caption = "流程移植";
TempConvert tempConvert = new TempConvert();
TempConvertSoap tempConvertSoap = tempConvert.getTempConvertSoap();
msg += "\n\nWebservice调用成功,输入0,返回" + tempConvertSoap.celsiusToFahrenheit("0");
Ide.getStatusBar().setText(caption);
MessageDialog.information(Ide.getMainWindow(), msg, caption, null);
}

/**
* Returns the id of the action this command is associated with.
*
* @return the id of the action this command is associated with.
* @throws IllegalStateException if the action this command is associated
* with is not registered.
*/
public static int actionId() {
final Integer cmdId = Ide.findCmdID("bms.processdeploy.processdeploy");
if (cmdId == null)
throw new IllegalStateException("Action bms.processdeploy.processdeploy not found.");
return cmdId;
}
}

流程设置的控制器代码如下:
package bms.processdeploy;

import oracle.ide.Context;
import oracle.ide.controller.Controller;
import oracle.ide.controller.IdeAction;
import oracle.ide.extension.RegisteredByExtension;


/**
* Controller for action bms.processdeploy.processpreference.
*/
@RegisteredByExtension("bms.processdeploy")
public final class ProcessPreferenceController implements Controller {

public boolean update(IdeAction action, Context context) {
return true;
}

public boolean handleEvent(IdeAction action, Context context) {
return false;
}
}

流程设置的命令代码如下:
package bms.processdeploy;

import java.io.IOException;

import oracle.ide.Ide;
import oracle.ide.controller.Command;
import oracle.ide.extension.RegisteredByExtension;

/**
* Command handler for bms.processdeploy.processpreference.
*/
@RegisteredByExtension("bms.processdeploy")
public final class ProcessPreferenceCommand extends Command {
public ProcessPreferenceCommand() {
super(actionId());
}

public int doit() {
String url ="http://www.bmsoft.com.cn/";
try {
Process op = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
} catch(IOException ex) {
System.out.println(ex);
}

return OK;
}

/**
* Returns the id of the action this command is associated with.
*
* @return the id of the action this command is associated with.
* @throws IllegalStateException if the action this command is associated
* with is not registered.
*/
public static int actionId() {
final Integer cmdId =
Ide.findCmdID("bms.processdeploy.processpreference");
if (cmdId == null)
throw new IllegalStateException("Action bms.processdeploy.processpreference not found.");
return cmdId;
}
}


第三步,请修改META-INF目录下的extension.xml,加入<context-menu-listeners>元素,在插件扩展里绑定上下文菜单的监听器。
<extension id="bms.processdeploy" version="1.0" esdk-version="1.0"
rsbundle-class="bms.processdeploy.Res"
xmlns="http://jcp.org/jsr/198/extension-manifest">
<name>BMS Process Deploy</name>
<owner>BMS</owner>
<dependencies>
<import>oracle.ide</import>
</dependencies>
<hooks>
<!-- TODO Declare functionality provided by the bms.processdeploy extension. -->
<jdeveloper-hook xmlns="http://xmlns.oracle.com/jdeveloper/1013/extension">
<actions>
<action id="bms.processdeploy.processdeploy">
<properties>
<property name="Name">流程移植</property>
<property name="SmallIcon">${OracleIcons.TO_REF}</property>
<property name="LongDescription">Process Deploy</property>
</properties>
<controller-class>bms.processdeploy.ProcessDeployController</controller-class>
<command-class>bms.processdeploy.ProcessDeployCommand</command-class>
</action>
<action id="bms.processdeploy.processpreference">
<properties>
<property name="Name">流程设置</property>
<property name="SmallIcon"></property>
<property name="LongDescription">ProcessPreference</property>
</properties>
<controller-class>bms.processdeploy.ProcessPreferenceController</controller-class>
<command-class>bms.processdeploy.ProcessPreferenceCommand</command-class>
</action>
</actions>

<!--
Install listeners to the navigator, editor, and structure pane (explorer)
context menus so that we can install menu items for our action.
-->
<context-menu-listeners>
<site idref="navigator">
<listener-class>bms.processdeploy.DeployContextMenuListener</listener-class>
</site>
</context-menu-listeners>

</jdeveloper-hook>
</hooks>
</extension>


第四步,发布成插件。
首先,把项目部署成jar包,拷贝出该jar包,在同级目录建立一个META-INF目录,在META-INF目录下,新建一个bundle.xml,代码如下:
<update-bundle version="1.0" 
xmlns="http://xmlns.oracle.com/jdeveloper/updatebundle"
xmlns:u="http://xmlns.oracle.com/jdeveloper/update">
<!-- The id *MUST* match exactly the id in your extension.xml. -->
<u:update id="bms.processdeploy">
<!-- The name of your extension as you want it to appear under the check for update menu -->
<u:name>ProcessDeploy</u:name>
<!-- The version *MUST* match exactly the version in your extension.xml. -->
<u:version>2</u:version>
<u:author>Sunny Zhou</u:author>
</u:update>
</update-bundle>

[color=red]<u:update id="bms.processdeploy">,这个id一定要跟extension.xml里的extension的id一致。jar包的名字用id的名称,如bms.processdeploy.jar。[/color]
恭喜你,你成功了,赶紧从jdeveloper的check for update里去安装这个本地插件吧!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
JDeveloper是一款由Oracle开发的集成开发环境(IDE)工具,主要用于开发Java和Web应用程序。下面是关于JDeveloper使用教程的简要说明: 1. 下载和安装:首先,从Oracle官方网站下载JDeveloper安装包。然后,按照安装向导的指示完成安装过程。确保你的计算机上已经安装了Java开发工具包(JDK)。 2. 创建项目:打开JDeveloper后,选择"新建",然后选择"项目"。在"项目类型"中选择你需要开发的应用程序类型(如Java、Web应用程序等),并按照向导的指示完成项目的创建过程。 3. 编辑代码:在项目中,你可以使用JDeveloper提供的代码编辑器编写代码。这个编辑器具有语法高亮、代码补全等功能,使代码编写更加方便。 4. 构建和调试:在编辑代码之后,你可以使用JDeveloper的构建工具将代码编译成可执行文件。并且,你还可以使用调试器来检查代码的执行过程,找出潜在的错误。 5. 运行和部署:在开发过程中,你可以使用JDeveloper提供的内置服务器来运行和测试你的应用程序。如果你想要将应用程序部署到其他服务器上,你可以使用JDeveloper提供的部署工具完成。 6. 使用其他工具和插件:JDeveloper还支持许多其他工具和插件,例如版本控制工具、数据库连接工具等。你可以根据需要安装并配置这些工具。 总之,JDeveloper是一款功能强大的开发工具,它提供了许多功能和特性来帮助开发人员加快应用程序的开发过程。熟悉并掌握JDeveloper的使用方法,将大大提高开发效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值