use of org.eclipse.swt.events.MenuDetectListener 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);
}
}
});
}
use of org.eclipse.swt.events.MenuDetectListener 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);
}
}
});
}
Aggregations