我正在尝试复制与此类似的 UI:
http://librixxxi.blogspot.com/2011/06/punch-clock-021-and-clickable-edit.html
我一直在按照作者的说明(没有成功)在我的表格的每一列中创建按钮。我的项目与他的不同之处在于我正在尝试使用 aTree
而不是 a Table
,并且我是在 eclipseTreeViewer
插件的上下文中进行的。从理论上讲,实现似乎应该很简单,但我似乎无法让它工作。
这是我的代码,它很容易复制,因为它只是带有树形查看器的示例 Java PDT 示例视图,以及createPartControl
. 您在这里看不到的所有内容都与示例相同:
class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
public String getColumnText(Object obj, int i) {
if(i == 0){
return obj.toString();
}
return "";
}
public Image getColumnImage(Object obj, int i) {
if(i == 0){
String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
if (obj instanceof TreeParent)
imageKey = ISharedImages.IMG_OBJ_FOLDER;
return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
}
return null;
}
}
class NameSorter extends ViewerSorter {
}
/**
* The constructor.
*/
public ButtonView() {
}
/**
* This is a callback that will allow us
* to create the viewer and initialize it.
*/
public void createPartControl(Composite parent) {
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
Tree tree = viewer.getTree();
tree.setLinesVisible(true);
tree.setHeaderVisible(true);
TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
column1.setText("Name");
column1.setWidth(400);
TreeColumn column2 = new TreeColumn(tree, SWT.LEFT);
column2.setText("Some info");
column2.setWidth(300);
// Button experimentation
TreeItem[] items = tree.getItems();
for(int i = 0; i < items.length; i++){
TreeEditor editor = new TreeEditor(tree);
TreeItem item = items[i];
Button button = new Button(tree, SWT.PUSH);
button.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT));
button.setSize(16,16);
button.pack();
editor.horizontalAlignment = SWT.RIGHT;
editor.setEditor(button, item);
}
drillDownAdapter = new DrillDownAdapter(viewer);
viewer.setContentProvider(new ViewContentProvider());
viewer.setLabelProvider(new ViewLabelProvider());
viewer.setSorter(new NameSorter());
viewer.setInput(getViewSite());
// Create the help context id for the viewer's control
PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "ButtonTest.viewer");
makeActions();
hookContextMenu();
hookDoubleClickAction();
contributeToActionBars();
}