3

是否可以在 Eclipse 中创建自定义变量查看器?假设我希望分解位域或将位图视为图像。是否可以?

你能举一些最简单的例子吗?

更新

我试图实现以下示例: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的就像例子一样。

它显然有效。

4

1 回答 1

3

您可以使用 Window / Show View / Expressions 并添加可以进行一些计算并显示文本输出的表达式。但除了文本输出之外,您必须通过 Eclipse 平台扩展点贡献您自己的模型演示文稿。请参阅Eclipse 自己的 JDT 中的Detail Pane Factories Extension和类源。org.eclipse.temp.JavaTableDetailPaneFactory

作为一种快速解决方法,您还可以编写一个静态实用程序方法,该方法将打开一个新窗口,其中您的图像从位域转换,并使用 Ctrl-U 快捷方式从显示视图调用该方法。

于 2012-05-09T18:07:13.267 回答