Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » TableTreeViewer support for the new tree table widget
TableTreeViewer support for the new tree table widget [message #464706] Tue, 29 November 2005 01:42 Go to next message
Michael Xia is currently offline Michael XiaFriend
Messages: 119
Registered: July 2009
Senior Member
I recall this hasn't been done but like to make sure. With now the Tree
widget supporting multiple columns and thus making TableTree class
depreciated, is there an equivalent viewer support of TableTreeViewer from
jface side, or will I need to construct and update the TreeItem nodes
manually? Thanks.

Michael
Re: TableTreeViewer support for the new tree table widget [message #464777 is a reply to message #464706] Tue, 29 November 2005 18:19 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
import java.io.*;
import java.util.*;

import org.eclipse.jface.viewers.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.program.*;
import org.eclipse.swt.widgets.*;
public class TreeViewerTest {

class TreeViewerTestLabelProvider implements ITableLabelProvider,
ITableColorProvider, ITableFontProvider {
Font font = null;
public String getColumnText(Object element, int columnIndex) {
if (!(element instanceof File)) return null;
File file = (File)element;
switch (columnIndex) {
case 0:
return file.getName();
case 1:
return ""+new Date(file.lastModified());
case 2:
return ""+file.isHidden();
}
return null;
}
public Image getColumnImage(Object element, int columnIndex) {
if (columnIndex != 0) return null;
if (!(element instanceof File)) return null;
File file = (File)element;
Display display = Display.getCurrent();
if (file.isDirectory()) return
display.getSystemImage(SWT.ICON_WARNING);
return display.getSystemImage(SWT.ICON_QUESTION);
}
public void dispose() {
if (font != null) font.dispose();
font = null;
}
public boolean isLabelProperty(Object element, String
property) {
return false;
}
public void addListener(ILabelProviderListener listener) {
}
public void removeListener(ILabelProviderListener listener) {
}
public Color getForeground(Object element, int columnIndex) {
if (columnIndex == 1) {
Display display = Display.getCurrent();
return display.getSystemColor(SWT.COLOR_RED);
}
return null;
}
public Color getBackground(Object element, int columnIndex) {
if (columnIndex == 0) {
File file = (File)element;
Display display = Display.getCurrent();
if (file.isDirectory()) return
display.getSystemColor(SWT.COLOR_CYAN);
return
display.getSystemColor(SWT.COLOR_MAGENTA);
}
return null;
}
public Font getFont(Object element, int columnIndex) {
if (columnIndex == 2) {
if (font == null) {
Display display = Display.getCurrent();
font = new Font(display, "Times", 12,
SWT.ITALIC);
}
return font;
}
return null;
}
}
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FormLayout());

TreeViewerTestLabelProvider labelProvider1 = new TreeViewerTest().new
TreeViewerTestLabelProvider();
ITreeContentProvider contentProvider = new ITreeContentProvider() {
public Object[] getChildren(Object parentElement) {
if (!(parentElement instanceof File)) return null;
File file = (File)parentElement;
if (file.isDirectory()) return file.listFiles();
return null;
}

public Object getParent(Object element) {
if (!(element instanceof File)) return null;
File file = (File)element;
return file.getParentFile();
}

public boolean hasChildren(Object element) {
if (!(element instanceof File)) return false;
File file = (File)element;
return file.isDirectory();
}

public Object[] getElements(Object inputElement) {
return getChildren(inputElement);
}

public void dispose() {
}

public void inputChanged(Viewer viewer, Object oldInput,
Object newInput) {
}
};

ILabelProvider labelProvider2 = new ILabelProvider() {
public void dispose() {
}
public boolean isLabelProperty(Object element, String
property) {
return false;
}
public void addListener(ILabelProviderListener listener) {
}
public void removeListener(ILabelProviderListener listener) {
}
public Image getImage(Object element) {
if (!(element instanceof File)) return null;
File file = (File)element;
if (file.isDirectory()) return
display.getSystemImage(SWT.ICON_WARNING);
return display.getSystemImage(SWT.ICON_QUESTION);
}
public String getText(Object element) {
if (!(element instanceof File)) return null;
File file = (File)element;
return file.getName();
}

};

final TreeViewer treeViewer1 = new TreeViewer(shell,
SWT.FULL_SELECTION | SWT.CHECK);
Tree tree1 = treeViewer1.getTree();
tree1.setHeaderVisible(true);
TreeColumn column1 = new TreeColumn(tree1, SWT.LEFT);
column1.setText("Name");
column1.setImage(display.getSystemImage(SWT.ICON_WORKING));
column1.setWidth(200);
TreeColumn column2 = new TreeColumn(tree1, SWT.CENTER);
column2.setText("Last Modified");
column2.setImage(display.getSystemImage(SWT.ICON_INFORMATION ));
column2.setWidth(200);
TreeColumn column3 = new TreeColumn(tree1, SWT.CENTER);
column3.setText("Hidden");
column3.setImage(display.getSystemImage(SWT.ICON_INFORMATION ));
column3.setWidth(100);
treeViewer1.setLabelProvider(labelProvider1);
treeViewer1.setContentProvider(contentProvider);

final TreeViewer treeViewer2 = new TreeViewer(shell);
Tree tree2 = treeViewer2.getTree();
treeViewer2.setLabelProvider(labelProvider2);
treeViewer2.setContentProvider(contentProvider);

Button b = new Button(shell, SWT.PUSH);
b.setText("choose root folder");
b.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
DirectoryDialog f = new DirectoryDialog(shell,
SWT.OPEN);
String root = f.open();
if (root != null) {
File file = new File(root);
if (file.exists()) {
treeViewer1.setInput(file);
treeViewer1.refresh();
treeViewer2.setInput(file);
treeViewer2.refresh();
}
}
}
});

FormData data = new FormData();
data.left = new FormAttachment(0, 10);
data.top = new FormAttachment(0, 10);
data.right = new FormAttachment(50, -5);
data.bottom = new FormAttachment(b, -10);
tree1.setLayoutData(data);

data = new FormData();
data.left = new FormAttachment(50, 5);
data.top = new FormAttachment(0, 10);
data.right = new FormAttachment(100, -10);
data.bottom = new FormAttachment(b, -10);
tree2.setLayoutData(data);

data = new FormData();
data.left = new FormAttachment(0, 10);
data.bottom = new FormAttachment(100, -10);
b.setLayoutData(data);

shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Re: TableTreeViewer support for the new tree table widget [message #464781 is a reply to message #464777] Tue, 29 November 2005 19:14 Go to previous message
Michael Xia is currently offline Michael XiaFriend
Messages: 119
Registered: July 2009
Senior Member
Thank you very much!

Best,
Michael
Previous Topic:Eclipse Stype Tabs
Next Topic:ControlTransfer ?
Goto Forum:
  


Current Time: Sat Dec 14 11:17:17 GMT 2024

Powered by FUDForum. Page generated in 0.04202 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top