use of org.eclipse.swt.events.TreeAdapter in project translationstudio8 by heartsome.
the class PluginHelpDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite tparent = (Composite) super.createDialogArea(parent);
GridLayoutFactory.swtDefaults().spacing(0, 0).numColumns(1).applyTo(tparent);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tparent);
createMenu();
createToolBar(tparent);
mainSash = new SashForm(tparent, SWT.NONE);
mainSash.setOrientation(SWT.HORIZONTAL);
GridLayout layout = new GridLayout(1, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
mainSash.setLayout(layout);
mainSash.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
Composite navigation = new Composite(mainSash, SWT.BORDER);
navigation.setLayout(new GridLayout(1, false));
navigation.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
tree = new Tree(navigation, SWT.NONE);
tree.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
if (tree.getSelectionCount() > 0) {
TreeItem item = tree.getSelection()[0];
String url = hashTable.get(item);
if (url != null && !url.equals("")) {
browser.setUrl(url);
browser.update();
}
}
}
});
tree.addTreeListener(new TreeAdapter() {
public void treeCollapsed(TreeEvent e) {
TreeItem item = (TreeItem) e.item;
if (item != null && item.getData() != null) {
if (item.getData().equals("toc")) {
item.setImage(Activator.getImageDescriptor(PluginConstants.HELP_TOC_CLOSED).createImage());
}
if (item.getData().equals("book")) {
item.setImage(Activator.getImageDescriptor(PluginConstants.HELP_BOOK_CLOSED).createImage());
}
}
}
public void treeExpanded(TreeEvent e) {
TreeItem item = (TreeItem) e.item;
if (item != null && item.getData() != null) {
if (item.getData().equals("toc")) {
item.setImage(Activator.getImageDescriptor(PluginConstants.HELP_TOC_OPEN).createImage());
}
if (item.getData().equals("book")) {
item.setImage(Activator.getImageDescriptor(PluginConstants.HELP_BOOK_OPEN).createImage());
}
}
}
});
tree.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
Composite contents = new Composite(mainSash, SWT.BORDER);
contents.setLayout(new GridLayout(1, false));
contents.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
browser = new Browser(contents, SWT.NONE);
browser.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
mainSash.setWeights(new int[] { 30, 70 });
hashTable = new Hashtable<TreeItem, String>();
if (!helpFilePath.equals("")) {
loadTree(helpFilePath);
}
return tparent;
}
Aggregations