I want to implement a tree with checkable root nodes and some parameters (actually, parameters in this case does not matter) inside. So, I make a Tree, then place there 2 columns, and after that place a TreeItem. Then I need to place a TreeEditor with checkbox-button Button button = new Button(tree, SWT.CHECK);
There is a problem: if the text in a TreeItem is not set (or is equal to “”), then on expanding a tree-node element, a small ractangle will be shown and will not be hidden. If the text is set to TreeItem, then rectangle will be shown around text in TreeItem, but it will hide if mouse moves out from TreeItem. Is there a way of not showing this rectangle?
Here are the sources:
Tree tree = new Tree(composite_1, SWT.NONE);
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
TreeColumn trclmnProperty = new TreeColumn(tree, SWT.NONE);
trclmnProperty.setWidth(100);
trclmnProperty.setText(Messages.AppWindow_trclmnProperty_text);
TreeColumn trclmnValue = new TreeColumn(tree, SWT.NONE);
trclmnValue.setWidth(100);
trclmnValue.setText(Messages.AppWindow_trclmnValue_text);
// Reading contents of a tree
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
try {
builder = factory.newDocumentBuilder();
File f = new File("ftplist.xml");
org.w3c.dom.Document doc = builder.parse(f);
NodeList ftpList = doc.getElementsByTagName("ftp");
for (int i = 0; i < ftpList.getLength(); i++) {
NodeList nodeList = ((Element) ftpList.item(i)).getElementsByTagName("ftpName");
TreeItem treeItemRootNode = new TreeItem(tree, SWT.NONE);
TreeEditor treeRootNodeEditor = new TreeEditor(tree);
final Button button = new Button(tree, SWT.CHECK);
button.setText(nodeList.item(0).getTextContent());
nodeList = ((Element) ftpList.item(0)).getElementsByTagName("ftpEnabled");
button.setSelection(nodeList.item(0).getTextContent().equalsIgnoreCase("true"));
button.pack();
treeRootNodeEditor.minimumWidth = button.getSize().x;
treeRootNodeEditor.horizontalAlignment = SWT.LEFT;
treeRootNodeEditor.setEditor(button, treeItemRootNode, 0);
nodeList = ((Element) ftpList.item(0)).getElementsByTagName("ftpHost");
TreeItem treeItemFtpHost = new TreeItem(treeItemRootNode, SWT.NONE);
treeItemFtpHost.setText(new String[] { "Host", nodeList.item(0).getTextContent() });
}
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
ftplist.xml – It is just a config file, contains just ftp-settings like host, port, etc.
ftplist.xml:
<?xml version="1.0"?>
<ftps>
<ftp>
<ftpName>SuperFtp</ftpName>
<ftpEnabled>true</ftpEnabled>
<ftpHost>ftp.com</ftpHost>
<ftpPort>21</ftpPort>
<ftpLogin>Login</ftpLogin>
<ftpPassword>Pass</ftpPassword>
<ftpUsePassiveMode>true</ftpUsePassiveMode>
<ftpRemoteDir>/</ftpRemoteDir>
<localSyncDir>C:/</localSyncDir>
</ftp>
<ftp>
<ftpName>SuperFtp2</ftpName>
<ftpEnabled>true</ftpEnabled>
<ftpHost>ftp.com</ftpHost>
<ftpPort>21</ftpPort>
<ftpLogin>Login</ftpLogin>
<ftpPassword>Pass</ftpPassword>
<ftpUsePassiveMode>true</ftpUsePassiveMode>
<ftpRemoteDir>/</ftpRemoteDir>
<localSyncDir>C:/</localSyncDir>
</ftp>
<ftps>

The following snippet should prevent your
Treefrom drawing its selection: