Search in sources :

Example 1 with MenuDetectEvent

use of org.eclipse.swt.events.MenuDetectEvent in project translationstudio8 by heartsome.

the class TmDbManagerDialog method addListeners.

/**
	 * Add Selection Listener to tree viewer
	 * @param viewer
	 *            ;
	 */
private void addListeners(final TreeViewer viewer) {
    // 选择事件
    viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection.isEmpty()) {
                return;
            }
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            Object obj = structuredSelection.getFirstElement();
            if (obj instanceof DatabaseModelBean) {
                DatabaseModelBean bean = (DatabaseModelBean) obj;
                setCurrDbType(bean.getDbType());
                bean.copyToOtherIntance(currServer);
                SystemDBOperator dbop = getCurrSysDbOp();
                if (dbop != null) {
                    executeSearch(dbop);
                }
                // 当数据库类型发生改变时重新初始化界面
                initUI(false);
            } else if (obj instanceof String) {
                setCurrDbType((String) obj);
                resetInputValue();
                currServerdbListInput.clear();
                initUI(true);
            }
        }
    });
    // 双击展开事件
    ((Tree) viewer.getControl()).addSelectionListener(new SelectionAdapter() {

        public void widgetDefaultSelected(final SelectionEvent event) {
            ISelection selection = viewer.getSelection();
            if (selection.isEmpty()) {
                return;
            }
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            Object obj = structuredSelection.getFirstElement();
            if (obj instanceof String) {
                String type = (String) obj;
                boolean expanded = viewer.getExpandedState(type);
                viewer.setExpandedState(type, !expanded);
            }
        }
    });
    // 右键菜单事件,判断何时出现右键菜单
    viewer.getControl().addMenuDetectListener(new MenuDetectListener() {

        public void menuDetected(MenuDetectEvent e) {
            ISelection selection = viewer.getSelection();
            if (selection.isEmpty()) {
                return;
            }
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            Object obj = structuredSelection.getFirstElement();
            Tree tree = treeViewer.getTree();
            if (obj instanceof DatabaseModelBean) {
                // 将菜单挂到树上
                tree.setMenu(treePopMenu);
            } else {
                tree.setMenu(null);
            }
        }
    });
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) MenuDetectEvent(org.eclipse.swt.events.MenuDetectEvent) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) MenuDetectListener(org.eclipse.swt.events.MenuDetectListener)

Example 2 with MenuDetectEvent

use of org.eclipse.swt.events.MenuDetectEvent in project translationstudio8 by heartsome.

the class TermDbManagerDialog method addListeners.

/**
	 * Add Selection Listener to tree viewer
	 * @param viewer
	 *            ;
	 */
private void addListeners(final TreeViewer viewer) {
    // 选择事件
    viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection.isEmpty()) {
                return;
            }
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            Object obj = structuredSelection.getFirstElement();
            if (obj instanceof DatabaseModelBean) {
                DatabaseModelBean bean = (DatabaseModelBean) obj;
                setCurrDbType(bean.getDbType());
                bean.copyToOtherIntance(currServer);
                SystemDBOperator dbop = getCurrSysDbOp();
                if (dbop != null) {
                    executeSearch(dbop);
                }
                // 当数据库类型发生改变时重新初始化界面
                initUI(false);
            } else if (obj instanceof String) {
                setCurrDbType((String) obj);
                resetInputValue();
                currServerdbListInput.clear();
                initUI(true);
            }
        }
    });
    // 双击展开事件
    ((Tree) viewer.getControl()).addSelectionListener(new SelectionAdapter() {

        public void widgetDefaultSelected(final SelectionEvent event) {
            ISelection selection = viewer.getSelection();
            if (selection.isEmpty()) {
                return;
            }
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            Object obj = structuredSelection.getFirstElement();
            if (obj instanceof String) {
                String type = (String) obj;
                boolean expanded = viewer.getExpandedState(type);
                viewer.setExpandedState(type, !expanded);
            }
        }
    });
    // 右键菜单事件,判断何时出现右键菜单
    viewer.getControl().addMenuDetectListener(new MenuDetectListener() {

        public void menuDetected(MenuDetectEvent e) {
            ISelection selection = viewer.getSelection();
            if (selection.isEmpty()) {
                return;
            }
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            Object obj = structuredSelection.getFirstElement();
            Tree tree = treeViewer.getTree();
            if (obj instanceof DatabaseModelBean) {
                // 将菜单挂到树上
                tree.setMenu(treePopMenu);
            } else {
                tree.setMenu(null);
            }
        }
    });
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) MenuDetectEvent(org.eclipse.swt.events.MenuDetectEvent) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) MenuDetectListener(org.eclipse.swt.events.MenuDetectListener)

Aggregations

DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)2 SystemDBOperator (net.heartsome.cat.database.SystemDBOperator)2 ISelection (org.eclipse.jface.viewers.ISelection)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 MenuDetectEvent (org.eclipse.swt.events.MenuDetectEvent)2 MenuDetectListener (org.eclipse.swt.events.MenuDetectListener)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Tree (org.eclipse.swt.widgets.Tree)2