use of org.eclipse.jface.viewers.ISelection 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.jface.viewers.ISelection in project translationstudio8 by heartsome.
the class LanguageCodesPreferencePage method addListener.
// 对需要添加监听的控件添加相应的监听器
private void addListener() {
// 添加语言列表选择事件监听
fFilteredTree.getViewer().addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
if (selection.isEmpty()) {
return;
}
// 暂时注释
// if (selection instanceof IStructuredSelection) {
// refreshFormatControls((IStructuredSelection) selection);
// }
}
});
// 注册添加按钮的选择监听器
addBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
addLanguage();
}
});
// 注册编辑按钮的选择监听器
editBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
verifyCurrentSelected(EDIT);
}
});
// 注册删除按钮的选择监听器
removeBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
verifyCurrentSelected(REMOVE);
}
});
}
use of org.eclipse.jface.viewers.ISelection in project translationstudio8 by heartsome.
the class LanguageCodesPreferencePage method verifyCurrentSelected.
// 验证当前的选择是否合法,如果合法,根据操作类型进行后续的操作
protected void verifyCurrentSelected(int operateType) {
ISelection selection = fFilteredTree.getViewer().getSelection();
if (selection.isEmpty()) {
String messagePattern = Messages.getString("languagecode.LanguageCodesPreferencePage.msg1");
Object[] values = new String[0];
if (operateType == EDIT) {
values = new String[] { Messages.getString("languagecode.LanguageCodesPreferencePage.msg2") };
} else if (operateType == REMOVE) {
values = new String[] { Messages.getString("languagecode.LanguageCodesPreferencePage.msg3") };
}
String message = MessageFormat.format(messagePattern, values);
MessageDialog.openInformation(fFilteredTree.getShell(), Messages.getString("languagecode.LanguageCodesPreferencePage.msgTitle"), message);
return;
} else if (operateType == EDIT && fFilteredTree.getViewer().getTree().getSelectionCount() > 1) {
MessageDialog.openInformation(fFilteredTree.getShell(), Messages.getString("languagecode.LanguageCodesPreferencePage.msgTitle"), Messages.getString("languagecode.LanguageCodesPreferencePage.msg4"));
return;
}
if (selection instanceof IStructuredSelection) {
IStructuredSelection iStructuredSelection = (IStructuredSelection) selection;
Object object = iStructuredSelection.getFirstElement();
if (object instanceof Language) {
if (operateType == EDIT) {
Language language = (Language) object;
editLanguage(language);
} else if (operateType == REMOVE) {
// 删除所选择的语言
if (MessageDialog.openConfirm(fFilteredTree.getShell(), Messages.getString("languagecode.LanguageCodesPreferencePage.msgTitle"), Messages.getString("languagecode.LanguageCodesPreferencePage.msg5"))) {
removeLanguage(iStructuredSelection.toList());
}
}
}
}
}
use of org.eclipse.jface.viewers.ISelection in project translationstudio8 by heartsome.
the class AddOrEditSrxConfigDialog method editLangRules.
/**
* 修改语言规则,备注,在修改语言规则名称时,也会同步修改映射中语言规则的名称 ;
*/
private void editLangRules() {
ISelection selection = langTableViewer.getSelection();
if (!selection.isEmpty() && selection != null && selection instanceof StructuredSelection) {
StructuredSelection struSelection = (StructuredSelection) selection;
@SuppressWarnings("unchecked") Iterator<String[]> it = struSelection.iterator();
if (it.hasNext()) {
// 获取所选中的语言规则的名称
String langRuleName = it.next()[1];
SrxLanguageRulesManageDialog dialog = new SrxLanguageRulesManageDialog(getShell(), false, handler, srxLocation);
dialog.create();
dialog.setEditInitData(langRuleName);
int result = dialog.open();
if (result == IDialogConstants.OK_ID) {
refreshLangTable(dialog.getCurLanguageRuleName());
}
}
} else {
MessageDialog.openInformation(getShell(), Messages.getString("srx.AddOrEditSrxConfigDialog.msgTitle2"), Messages.getString("srx.AddOrEditSrxConfigDialog.msg6"));
}
}
use of org.eclipse.jface.viewers.ISelection in project translationstudio8 by heartsome.
the class SrxConfigurationDialog method editSrx.
/**
* 编辑SRX文件 ;
*/
private void editSrx() {
ISelection selection = tableViewer.getSelection();
if (!selection.isEmpty() && selection != null && selection instanceof StructuredSelection) {
StructuredSelection structSelection = (StructuredSelection) selection;
@SuppressWarnings("unchecked") Iterator<String[]> it = structSelection.iterator();
if (it.hasNext()) {
String srxName = it.next()[1];
if (isSystemSrx(srxName)) {
MessageDialog.openInformation(getShell(), Messages.getString("dialogs.CatalogManagerDialog.msgTitle2"), Messages.getString("srx.SrxConfigurationDialog.msg4"));
return;
}
CreateOrUpdataSRXDialog editDialog = new CreateOrUpdataSRXDialog(getShell(), false);
editDialog.create();
editDialog.setEditInitData(srxName);
int result = editDialog.open();
if (result == IDialogConstants.OK_ID) {
String editedSrxName = editDialog.getCurSrxName();
if (!openSrx(ADConstants.configLocation + ADConstants.AD_SRXConfigFolder + File.separator + editedSrxName)) {
return;
}
AddOrEditSrxConfigDialog addDialog = new AddOrEditSrxConfigDialog(getShell(), editedSrxName, handler);
addDialog.open();
refreshTable(editedSrxName);
}
}
}
}
Aggregations