如何在Eclipse中的Expressionss视图中正确实现自定义详细信息窗格?

时间:2013-12-17 18:00:22

标签: java eclipse debugging eclipse-rcp

我已经为org.eclipse.debug.ui.detailPaneFactories做出了贡献,这取代了Eclipse调试器中Variables视图中的详细信息窗格:

enter image description here

上面的详细信息窗格重新定义为黄色。

不幸的是,Expressions视图中的详细信息窗格不起作用,它在下面是灰色的:

enter image description here

我做错了什么?

我试图实现以下示例:http://alvinalexander.com/java/jwarehouse/eclipse/org.eclipse.jdt.debug.tests/test-plugin/org/eclipse/jdt/debug/testplugin/detailpane/SimpleDetailPane.java.shtml

我的plugin.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>

<plugin>
   <extension
         point="org.eclipse.debug.ui.detailPaneFactories">
      <detailFactories
            class="tests.debug.details.DetailPaneFactory"
            id="tests.debug.details.detailFactories">
      </detailFactories>
   </extension>



</plugin>

我的DetailPaneFactory.java如下:

package tests.debug.details;

import java.util.AbstractSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.eclipse.debug.ui.IDetailPane;
import org.eclipse.debug.ui.IDetailPaneFactory;
import org.eclipse.jface.viewers.IStructuredSelection;

public class DetailPaneFactory implements IDetailPaneFactory {

    private HashMap<String,Class<? extends IDetailPane>> classes = new HashMap<String,Class<? extends IDetailPane>>();

    private void addClass(Class<? extends IDetailPane> cls) {
        try {
            String paneID = (String) cls.getField("ID").get(null);
            classes.put(paneID, cls);
        } catch (IllegalArgumentException | IllegalAccessException
                | NoSuchFieldException | SecurityException e) {
            throw new RuntimeException(e);
        }
        finally {

        }

    }

    private Class<? extends IDetailPane> getClass(String paneID) {
        Class<? extends IDetailPane> ans = classes.get(paneID);
        return ans;
    }

    public DetailPaneFactory() {
        addClass(SimpleDetailPane.class);
    }


    @Override
    public IDetailPane createDetailPane(String paneID) {

        Class<? extends IDetailPane> cls = getClass(paneID);
        if( cls != null ) {
            try {
                return cls.newInstance();
            } catch (InstantiationException | IllegalAccessException e) {
                throw new RuntimeException();
            }
        }
        else {
            return null;
        }
    }

    @Override
    public String getDetailPaneName(String paneID) {
        Class<? extends IDetailPane> cls = getClass(paneID);
        if( cls != null ) {
            try {
                return (String)cls.getField("NAME").get(null);
            } catch (IllegalArgumentException | IllegalAccessException
                    | NoSuchFieldException | SecurityException e) {
                throw new RuntimeException(e);
            }
        }
        else {
            return null;
        }
    }

    @Override
    public String getDetailPaneDescription(String paneID) {
        Class<? extends IDetailPane> cls = getClass(paneID);
        if( cls != null ) {
            try {
                return (String)cls.getField("DESCRIPTION").get(null);
            } catch (IllegalArgumentException | IllegalAccessException
                    | NoSuchFieldException | SecurityException e) {
                throw new RuntimeException(e);
            }
        }
        else {
            return null;
        }
    }

    @Override
    public Set<String> getDetailPaneTypes(IStructuredSelection selection) {
        return new AbstractSet<String>() {

            @Override
            public Iterator<String> iterator() {
                return new Iterator<String>() {

                    private Iterator<Map.Entry<String,Class<? extends IDetailPane>>> it = classes.entrySet().iterator();

                    @Override
                    public void remove() {
                        it.remove();
                    }

                    @Override
                    public String next() {
                        return it.next().getKey();
                    }

                    @Override
                    public boolean hasNext() {
                        return it.hasNext();
                    }
                };
            }

            @Override
            public int size() {
                return classes.size();
            }

        };
    }

    @Override
    public String getDefaultDetailPane(IStructuredSelection selection) {
        return SimpleDetailPane.ID;
    }

}

和我的SimpleDetailPane.java在示例中除了&#34;其他&#34;颜色变黄。

1 个答案:

答案 0 :(得分:1)

表达式视图由org.eclipse.debug.internal.ui.views.expression.ExpressionView提供,VariablesVieworg.eclipse.debug.ui.detailPaneFactories的子类。

{{1}}扩展点的文档说:

  

此扩展点允许客户提供自定义渲染   对于变量,寄存器,表达式和中的详细信息窗格   断点视图

因此您应该能够为此视图使用相同的扩展点。