`
cutesunshineriver
  • 浏览: 196382 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

开发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> 

<u:update id="bms.processdeploy">,这个id一定要跟extension.xml里的extension的id一致。jar包的名字用id的名称,如bms.processdeploy.jar。
恭喜你,你成功了,赶紧从jdeveloper的check for update里去安装这个本地插件吧!
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics