Netbeans ExplorerTopComponent节点在显示对话框时失去焦点

Netbeans ExplorerTopComponent节点在显示对话框时失去焦点,netbeans,netbeans-7,netbeans-platform,Netbeans,Netbeans 7,Netbeans Platform,我有一个netbeans RCP应用程序,它显示了explorertopcomponent中的一组节点。选中此选项后,我将在editortopcomponent上显示详细信息,并且效果良好。当我在编辑器上使用JOptionPage显示对话框时,将取消选择树中的选定节点,最终我的editortopcomponent也会丢失选定节点的详细信息。如果打开对话框,是否有方法保存树中的选定节点,使其不被取消选择 谢谢。很简单 在explorertopcomponent中,您有LookupListner,在

我有一个netbeans RCP应用程序,它显示了explorertopcomponent中的一组节点。选中此选项后,我将在editortopcomponent上显示详细信息,并且效果良好。当我在编辑器上使用JOptionPage显示对话框时,将取消选择树中的选定节点,最终我的editortopcomponent也会丢失选定节点的详细信息。如果打开对话框,是否有方法保存树中的选定节点,使其不被取消选择

谢谢。

很简单

在explorertopcomponent中,您有LookupListner,在查找中显示“someYourNodeClass”(例如Album)事件“正在等待”。当您的explorertopcomponent不可见或您什么也不做时,您必须重新安装explorertopcomponent

/**
 * your explorertopcomponent
 */
@ConvertAsProperties(
    dtd = "-//com.galileo.netbeans.module//Y//EN",
    autostore = false)
@TopComponent.Description(
    preferredID = "YTopComponent",
    //iconBase="SET/PATH/TO/ICON/HERE", 
    persistenceType = TopComponent.PERSISTENCE_ALWAYS)
@TopComponent.Registration(mode = "explorer", openAtStartup = false)
@ActionID(category = "Window", id = "com.galileo.netbeans.module.YTopComponent")
@ActionReference(path = "Menu/Window" /*, position = 333 */)
@TopComponent.OpenActionRegistration(
    displayName = "#CTL_YAction",
    preferredID = "YTopComponent")
@Messages({
"CTL_YAction=Y",
"CTL_YTopComponent=Y Window",
"HINT_YTopComponent=This is a Y window"
})
public final class YTopComponent extends TopComponent implements LookupListener {

private Lookup.Result<Album> result;

public YTopComponent() {
    initComponents();
    setName(Bundle.CTL_YTopComponent());
    setToolTipText(Bundle.HINT_YTopComponent());

}

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.
 */
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 400, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 300, Short.MAX_VALUE)
    );
}// </editor-fold>                        

// Variables declaration - do not modify                     
// End of variables declaration                   
@Override
public void componentOpened() {
    result = Utilities.actionsGlobalContext().lookupResult(Album.class);
    result.addLookupListener(this);
}

@Override
public void componentClosed() {
    result.removeLookupListener(this);
}

void writeProperties(java.util.Properties p) {
    // better to version settings since initial version as advocated at
    // http://wiki.apidesign.org/wiki/PropertyFiles
    p.setProperty("version", "1.0");
    // TODO store your settings
}

void readProperties(java.util.Properties p) {
    String version = p.getProperty("version");
    // TODO read your settings according to their version
}

public void resultChanged(LookupEvent le) {
    Collection<? extends Album> allInstances = result.allInstances();
    TopComponent findTopComponent = WindowManager.getDefault().findTopComponent("YourNodeExplorerWindow");
    if (findTopComponent == null) {
        return;
    }
    if (!findTopComponent.isShowing()) {
        return;
    }
    if (!allInstances.isEmpty()) {
        showDetail(allInstances.iterator().next());
    }
}
}
/**
*您的explorertopcomponent
*/
@转炉房地产(
dtd=“-//com.galileo.netbeans.module//Y//EN”,
自动存储(错误)
@TopComponent.说明(
preferredID=“YTopComponent”,
//iconBase=“SET/PATH/TO/ICON/HERE”,
persistenceType=TopComponent.PERSISTENCE\u始终)
@注册(mode=“explorer”,openAtStartup=false)
@ActionID(category=“Window”,id=“com.galileo.netbeans.module.YTopComponent”)
@ActionReference(path=“Menu/Window”/*,position=333*/)
@TopComponent.OpenActionRegistration(
displayName=“#控制动作”,
preferredID=“YTopComponent”)
@信息({
“CTL_YAction=Y”,
“CTL_YTopComponent=Y窗口”,
“HINT_YTopComponent=这是一个Y窗口”
})
公共最终类YTopComponent扩展了TopComponent实现了LookupListener{
私有查找。结果;
公共组件(){
初始化组件();
setName(Bundle.CTL_YTopComponent());
setToolTipText(Bundle.HINT_YTopComponent());
}
/**
*从构造函数中调用此方法来初始化表单。
*警告:不要修改此代码。此方法的内容始终为
*由表单编辑器重新生成。
*/
//                           
私有组件(){
javax.swing.GroupLayout=newjavax.swing.GroupLayout(this);
这个.setLayout(布局);
layout.setHorizontalGroup(
createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0,400,短。最大值)
);
layout.setVerticalGroup(
createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0,300,短。最大值)
);
}//                         
//变量声明-不修改
//变量结束声明
@凌驾
公共无效组件已打开(){
结果=Utilities.actionsGlobalContext().lookupResult(Album.class);
result.addLookupListener(此);
}
@凌驾
公共无效组件已关闭(){
结果:移除超链接器(本);
}
void writeProperties(java.util.Properties p){
//更好的版本设置,因为初始版本在
// http://wiki.apidesign.org/wiki/PropertyFiles
p、 setProperty(“版本”、“1.0”);
//TODO存储您的设置
}
void readProperties(java.util.Properties p){
字符串版本=p.getProperty(“版本”);
//TODO根据设置的版本读取设置
}
公共无效结果已更改(LookupEvent le){
收集