Reputation: 1212
I am implementing the the views for the OS X version of our SWT Java application, and would like to use the 'source list' option offered by NSOutlineView in my SWT Tree.
I implemented this by hacking my own version of Tree.class by adding this code to the #createHandle()
method:
long NSTableViewSelectionHighlightStyleSourceList = 1;
long hi = OS.sel_registerName("setSelectionHighlightStyle:");
OS.objc_msgSend(widget.id, hi, NSTableViewSelectionHighlightStyleSourceList);
Which essentially just flags the underlying NSOutlineView to use the NSTableViewSelectionHighlightStyleSourceList style.
It looks like this:
which kind of works, but does not fully emulate the NSOutlineView behavior. For example, when selecting root nodes, even though the title has enough space it still truncates it like this:
Another problem with this is that I don't know how to implement categories (or groups/folders) like you see in Finder.app/iTunes.app/Mail.app/the following example:
Notice the FAVORITES
category, and how it is formatted. This is handled in a regular ObjC application by returning true in the outlineView:isGroupItem
method in the outlineView
delegate, but I have no idea where to hack that in.
So my question is
How do I go about implementing the category(isGroupItem
) functionality in SWT on OS X?
Upvotes: 3
Views: 445
Reputation: 111
I managed to make the adjustments to the SWT java source and native source to get this working as shown in the image below.
A custom SWT for mac cocoa x86_64 can be dowloaded here.
The changes made to the source at the time can be seen in this commit
A snippet showing how this works is shown below. The SWT.SOURCE_LIST
style is used to mark the tree as a source list and the SWT.GROUP_ITEM
style is used to mark the items that are group items.
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
public class SourceList {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final Tree tree = new Tree (shell, SWT.SOURCE_LIST);
for (int i=0; i<4; i++) {
final TreeItem iItem = new TreeItem (tree, SWT.GROUP_ITEM);
display.asyncExec( new Runnable() {
public void run() {
iItem.setExpanded(true);
}
});
iItem.setText ("GROUP " + i);
for (int j = 0; j < 4; j++) {
TreeItem jItem = new TreeItem (iItem, 0);
jItem.setText ("TreeItem " + j);
}
}
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Upvotes: 6