Reputation: 2009
I'm currently learning how eclipse plugins work. I want to get a table into a view, and I have been messing with the sample view plugin for a while but I still can't get it to work. Here is the code snippet from the sample view plugin:
package com.example.helloworld2.views;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.*;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.jface.action.*;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.*;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.SWT;
public class SampleView extends ViewPart {
/**
* The ID of the view as specified by the extension.
*/
public static final String ID = "com.example.helloworld2.views.SampleView";
private TableViewer viewer;
private Action action1;
private Action action2;
private Action doubleClickAction;
/*
* The content provider class is responsible for
* providing objects to the view. It can wrap
* existing objects in adapters or simply return
* objects as-is. These objects may be sensitive
* to the current input of the view, or ignore
* it and always show the same content
* (like Task List, for example).
*/
class ViewContentProvider implements IStructuredContentProvider {
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
}
public void dispose() {
}
public Object[] getElements(Object parent) {
return new String[] { "Onsdfsde", "Twosdfsd", "Threesdf" };
}
}
class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
public String getColumnText(Object obj, int index) {
return getText(obj);
}
public Image getColumnImage(Object obj, int index) {
return getImage(obj);
}
public Image getImage(Object obj) {
return PlatformUI.getWorkbench().
getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
}
}
class NameSorter extends ViewerSorter {
}
/**
* The constructor.
*/
public SampleView() {
}
/**
* This is a callback that will allow us
* to create the viewer and initialize it.
*/
public void createPartControl(Composite parent) {
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
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(), "com.example.helloworld2.viewer");
}
...
}
It seems like the view content provider is responsible for putting content inside the view, but how exactly would I insert a table? Ideally I would eventually like to insert a complex tree table:
http://www.java2s.com/Tutorial/Java/0280__SWT/CreateaTreeTable.htm
But if anyone could point me the right direct with something similar or even some resource that I can read up on, that would be wonderful.
Thanks
Upvotes: 0
Views: 6159
Reputation: 35
Table table = viewer.getTable();
From what I infer from your question I think that the above code should do what you want.
Upvotes: 0
Reputation: 29139
You are already inserting a table in createPartControl() as part of "new TableViewer()" call. To insert a different widget you would change createPartControl() to do something different, such as using TreeTableViewer instead.
Upvotes: 1