自定义子菜单不会对点击做出反应

时间:2014-01-12 17:59:03

标签: oracle-sqldeveloper jdeveloper

我正在尝试在JDeveloper中实现扩展。单击数据包时,它会创建子菜单。 当我点击我的自定义子菜单的一个元素时,它会返回一个空指针Exception。 我无法弄清楚我做错了什么。

你能帮帮我吗?

以下是我创建子菜单的方式:

submenu.xml文件:

<?xml version="1.0" encoding="windows-1252" ?>
<!-- usage of a name space?-->
<items id="my.contextMenu">

 <folder type="PACKAGE">
  <name>User Defined Context Menu</name>
  <item reloadparent="true"
        action-ref="utilitytools.customSave">
   <title>saveThisPackage</title>
 </folder>
</items>

extension.xml文件:

<?xml version="1.0" encoding="UTF-8" ?>
<extension id="utilitytools" version="1.0" esdk-version="1.0"
           rsbundle-class="utilitytools.Res"
           xmlns="http://jcp.org/jsr/198/extension-manifest">
  <name>Utility Tools</name>
  <owner>A name</owner>
  <dependencies>
    <import>oracle.sqldeveloper</import>
    <import>oracle.ide</import>
  </dependencies>
  <hooks>
    <jdeveloper-hook xmlns="http://xmlns.oracle.com/jdeveloper/1013/extension">
      <addins>
        <addin>utilitytools.UtilityToolsAddin</addin>
      </addins>
      <actions xmlns="http://xmlns.oracle.com/jdeveloper/1013/extension">
        <action id="utilitytools.customSave">
          <properties>
            <property name="Name">saveThisPackage</property>
            <property name="SmallIcon"></property>
            <property name="LongDescription"></property>
          </properties>
          <controller-class>utilitytools.savePackageController</controller-class>
          <command-class>utilitytools.savePackageCommand</command-class>
        </action>
      </actions>
    </jdeveloper-hook>
    <sqldev-navigator-hook xmlns="http://xmlns.oracle.com/sqldeveloper/sqldev-navigator">
        <descriptor>submenu.xml</descriptor>
    </sqldev-navigator-hook>
  </hooks>
</extension>

SubmenuListener文件:

public final class SubMenuListener implements ContextMenuListener {
    public SubMenuListener() {
        super();
    }

    public void menuWillShow(ContextMenu contextMenu) {
        contextMenu.add( contextMenu.createMenuItem( 
            IdeAction.find( savePackageCommand.actionId() )
        ));
    }

    public void menuWillHide(ContextMenu contextMenu) {
        //Nothing
    }

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

命令文件:

/**
 * Command handler for utilitytools.customSave.
 */
@RegisteredByExtension("utilitytools")
public final class sauvegardePackageCommand extends Command {
    public savePackageCommand() {
        super(actionId());
    }

    public int doit() {

        SwingUtilities.invokeLater(new Runnable(){
            public void run(){
                showSaveWindow();
            }
        });
        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(".utilitytools.customSave");
        if (cmdId == null)
            throw new IllegalStateException("Action esdksample.showElementClass not found.");
        return cmdId;
    }
    private static void showSaveWindow(){
        JFrame frame = new JFrame("SAVE");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.add(new JPanelSavePackage());//Or any window you want to popup


        frame.pack();
        frame.setVisible(true);
    }
}

0 个答案:

没有答案