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.
我正在实现SWT Java应用程序的OS X版本的视图,并希望在我的SWT树中使用NSOutlineView提供的“源列表”选项。
I implemented this by hacking my own version of Tree.class by adding this code to the #createHandle()
method:
我通过破解我自己版本的树来实现这一点。将此代码添加到#createHandle()方法:
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.
它本质上只是标记底层的NSOutlineView来使用NSTableViewSelectionHighlightStyleSourceList样式。
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:
哪种方法有效,但不能完全模拟NSOutlineView行为。例如,当选择根节点时,即使标题有足够的空间,它仍然像这样截断它:
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:
另一个问题是我不知道如何实现类别(或组/文件夹),就像你在Finder.app/iTunes.app/Mail中看到的那样。应用程序/下面的例子:
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.
请注意FAVORITES类别,以及它的格式。这在一个常规的ObjC应用程序中是通过在outlineView委托中的isGroupItem方法中返回true来处理的,但是我不知道从哪里破解它。
So my question is
我的问题是
How do I go about implementing the category(isGroupItem
) functionality in SWT on OS X?
如何在OS X上实现SWT中的类别(isGroupItem)功能?
1 个解决方案
#1
6
I managed to make the adjustments to the SWT java source and native source to get this working as shown in the image below.
我设法对SWT java源代码和本机源代码进行了调整,以使其工作,如下图所示。
A custom SWT for mac cocoa x86_64 can be dowloaded here.
maccocoa x86_64的自定义SWT可以在这里下载。
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.
下面显示了一个代码片段,展示了这是如何工作的。SWT。SOURCE_LIST样式用于将树标记为源列表和SWT。GROUP_ITEM样式用于标记属于组项的项。
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();
}
}
#1
6
I managed to make the adjustments to the SWT java source and native source to get this working as shown in the image below.
我设法对SWT java源代码和本机源代码进行了调整,以使其工作,如下图所示。
A custom SWT for mac cocoa x86_64 can be dowloaded here.
maccocoa x86_64的自定义SWT可以在这里下载。
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.
下面显示了一个代码片段,展示了这是如何工作的。SWT。SOURCE_LIST样式用于将树标记为源列表和SWT。GROUP_ITEM样式用于标记属于组项的项。
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();
}
}