Search in sources :

Example 1 with TreeAdapter

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;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) TreeItem(org.eclipse.swt.widgets.TreeItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TreeAdapter(org.eclipse.swt.events.TreeAdapter) TreeEvent(org.eclipse.swt.events.TreeEvent) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) Browser(org.eclipse.swt.browser.Browser)

Aggregations

Browser (org.eclipse.swt.browser.Browser)1 SashForm (org.eclipse.swt.custom.SashForm)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 TreeAdapter (org.eclipse.swt.events.TreeAdapter)1 TreeEvent (org.eclipse.swt.events.TreeEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Tree (org.eclipse.swt.widgets.Tree)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1