use of org.eclipse.jface.viewers.IStructuredSelection in project translationstudio8 by heartsome.
the class NonTranslationQAPage method editNontransElement.
/**
* 编辑非译元素
*/
private void editNontransElement() {
NontransElementBean bean = null;
ISelection selection = tableViewer.getSelection();
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
if (structuredSelection.getFirstElement() instanceof NontransElementBean) {
bean = (NontransElementBean) structuredSelection.getFirstElement();
if (validIsInternalElementNonTip(bean)) {
return;
}
AddOrEditNontransElementDialog dialog = new AddOrEditNontransElementDialog(getShell(), false, tableViewer, bean);
int result = dialog.open();
if (result == IDialogConstants.OK_ID) {
tableViewer.refresh();
}
}
}
}
use of org.eclipse.jface.viewers.IStructuredSelection in project translationstudio8 by heartsome.
the class NonTranslationQAPage method initListener.
/**
* 一些事件的添加
*/
public void initListener() {
// 非译元素的添加事件
addBtn.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
addNonTransElement();
}
public void widgetDefaultSelected(SelectionEvent e) {
addNonTransElement();
}
});
editBtn.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent arg0) {
editNontransElement();
}
public void widgetDefaultSelected(SelectionEvent arg0) {
editNontransElement();
}
});
// 删除按钮的点击操作
deleteBtn.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
deleteElement();
}
public void widgetDefaultSelected(SelectionEvent e) {
deleteElement();
}
});
// 给comboViewer添加事件,同时传入内置元素
comboViewer.getCombo().addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
addInternalElement();
comboViewer.getCombo().setText(Messages.getString("qa.preference.NonTranslationQAPage.addInterElement"));
}
public void widgetDefaultSelected(SelectionEvent e) {
addInternalElement();
comboViewer.getCombo().setText(Messages.getString("qa.preference.NonTranslationQAPage.addInterElement"));
}
});
// 非译元素列表的点击事件
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = tableViewer.getSelection();
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
if (structuredSelection.getFirstElement() instanceof NontransElementBean) {
if (structuredSelection.size() == 1 && !validIsInternalElementNonTip((NontransElementBean) structuredSelection.getFirstElement())) {
editBtn.setEnabled(true);
} else {
editBtn.setEnabled(false);
}
deleteBtn.setEnabled(true);
} else {
setAddModel();
}
} else {
setAddModel();
}
}
});
tableViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent arg0) {
editNontransElement();
}
});
}
use of org.eclipse.jface.viewers.IStructuredSelection in project translationstudio8 by heartsome.
the class TerminologyViewPart method selectionChanged.
/**
* 监听来自IHSEditor的选中改变事件。
* @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart,
* org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
// UNDO 每次启动程序后,术语匹配面板无法识别出术语。 2012-06-21
if (part == null || selection == null) {
return;
}
if (part instanceof IXliffEditor) {
if (!part.equals(tempEditor)) {
IXliffEditor editor = (IXliffEditor) part;
tempEditor = editor;
tempEditor = (IXliffEditor) part;
FileEditorInput input = (FileEditorInput) getSite().getPage().getActiveEditor().getEditorInput();
IProject currProject = input.getFile().getProject();
matcher.setCurrentProject(currProject);
}
} else {
firstAction.setEnabled(false);
return;
}
if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
firstAction.setEnabled(false);
return;
}
IStructuredSelection structuredSelecion = (IStructuredSelection) selection;
Object object = structuredSelecion.getFirstElement();
if (object instanceof Integer) {
rowIndex = (Integer) object;
IXliffEditor editor = (IXliffEditor) part;
// handler.getTransUnit(rowId);
TransUnitBean bean = editor.getRowTransUnitBean(rowIndex);
String pureText = bean.getSrcText();
srcLang = bean.getSrcLang();
tgtLang = bean.getTgtLang();
tgtLang = tgtLang == null || tgtLang.equals("") ? editor.getTgtColumnName() : tgtLang;
srcLang = srcLang == null || "".equals(srcLang) ? editor.getSrcColumnName() : srcLang;
if (srcLang == null || "".equals(srcLang) || tgtLang == null || "".equals(tgtLang)) {
return;
}
Language srcLangL = LocaleService.getLanguageConfiger().getLanguageByCode(srcLang);
Language tgtLangL = LocaleService.getLanguageConfiger().getLanguageByCode(tgtLang);
if (srcLangL.isBidi() || tgtLangL.isBidi()) {
gridTable.setOrientation(SWT.RIGHT_TO_LEFT);
} else {
gridTable.setOrientation(SWT.LEFT_TO_RIGHT);
}
srcTableColumn.setText(srcLang);
tgtTableColumn.setText(tgtLang);
loadData(pureText, srcLang, tgtLang, true);
}
}
use of org.eclipse.jface.viewers.IStructuredSelection in project translationstudio8 by heartsome.
the class OpenMultiXliffHandler method execute.
@SuppressWarnings("unchecked")
public Object execute(ExecutionEvent event) throws ExecutionException {
IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.common.ui.navigator.view");
ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
if (currentSelection.isEmpty() || !(currentSelection instanceof IStructuredSelection)) {
return null;
}
IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
Iterator<Object> selectIt = structuredSelection.iterator();
final ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
shell = window.getShell();
// 先验证是否跨项目
IProject selectedProject = null;
while (selectIt.hasNext()) {
Object object = selectIt.next();
if (object instanceof IFile) {
IFile iFile = (IFile) object;
if (!CommonFunction.validXlfExtension(iFile.getFileExtension())) {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), MessageFormat.format(Messages.getString("handlers.OpenMultiXliffHandler.msg1"), iFile.getFullPath().toOSString()));
continue;
}
selectIFiles.add(iFile);
if (selectedProject == null) {
selectedProject = iFile.getProject();
} else {
if (selectedProject != iFile.getProject()) {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg2"));
return null;
}
}
} else if (object instanceof IContainer) {
IContainer selectContainer = (IContainer) object;
if (selectedProject == null) {
selectedProject = selectContainer.getProject();
}
// 判断当前文件夹是否处于 XLIFF 文件夹下
try {
ResourceUtils.getXliffs(selectContainer, selectIFiles);
} catch (CoreException e) {
logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger1"), selectContainer.getFullPath().toOSString(), e);
}
}
}
// 过滤重复选择文件
CommonFunction.removeRepeateSelect(selectIFiles);
if (selectIFiles.size() < 2) {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg3"));
return null;
}
MultiFilesOper oper = new MultiFilesOper(selectedProject, selectIFiles);
// 先验证这些文件是否已经合并打开,如果是,则退出
if (oper.validExist()) {
return null;
}
// 判断是否有重复打开的文件,并删除缓存中要合并打开的文件。
if (oper.hasOpenedIFile()) {
if (oper.getSelectIFiles().size() <= 0) {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg4"));
return null;
} else {
boolean isResponse = MessageDialog.openConfirm(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle2"), Messages.getString("handlers.OpenMultiXliffHandler.msg5"));
if (isResponse) {
if (oper.getSelectIFiles().size() < 2) {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg6"));
return null;
}
} else {
return null;
}
}
}
final IFile multiIFile = oper.createMultiTempFile();
if (multiIFile != null && multiIFile.exists()) {
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(Messages.getString("handler.OpenMultiXliffHandler.tip1"), 10);
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 7, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
// 进行判断所选择文件的语言对是否符合标准,先解析文件
final XLFHandler xlfHander = new XLFHandler();
final Map<String, Object> newResultMap = xlfHander.openFiles(ResourceUtils.iFilesToFiles(selectIFiles), subMonitor);
// 针对解析失败
if (newResultMap == null || QAConstant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) newResultMap.get(QAConstant.RETURNVALUE_RESULT)) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), (String) newResultMap.get(Constant.RETURNVALUE_MSG));
}
});
return;
}
// 验证是否有多个语言
boolean hasDiffrentLangPair = false;
Map<String, ArrayList<String>> langMap = xlfHander.getLanguages();
if (langMap.size() > 1) {
hasDiffrentLangPair = true;
} else {
for (Entry<String, ArrayList<String>> entry : langMap.entrySet()) {
if (entry.getValue().size() > 1) {
hasDiffrentLangPair = true;
}
}
}
if (monitor.isCanceled()) {
return;
}
monitor.worked(1);
if (hasDiffrentLangPair) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg7"));
}
});
// 先删除临时文件,再退出
try {
multiIFile.delete(true, monitor);
} catch (CoreException e) {
logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger2"), e);
}
return;
}
final boolean[] validateResult = new boolean[] { false };
Display.getDefault().syncExec(new Runnable() {
public void run() {
validateResult[0] = XLFValidator.validateXlifIFiles(selectIFiles);
}
});
if (!validateResult[0]) {
try {
multiIFile.delete(true, monitor);
} catch (CoreException e) {
logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger2"), e);
}
return;
}
final FileEditorInput input = new FileEditorInput(multiIFile);
if (monitor.isCanceled()) {
return;
}
monitor.worked(1);
Display.getDefault().syncExec(new Runnable() {
public void run() {
try {
// UNDO 这里合并打开时,要考虑传入参数xlfHandler,以防多次解析文件带来的消耗。
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, XLIFF_EDITOR_ID, true);
} catch (PartInitException e) {
e.printStackTrace();
}
}
});
if (monitor.isCanceled()) {
return;
}
monitor.worked(1);
monitor.done();
}
};
try {
new ProgressMonitorDialog(shell).run(true, true, runnable);
} catch (Exception e) {
logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger3"), e);
}
} else {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg8"));
return null;
}
return null;
}
use of org.eclipse.jface.viewers.IStructuredSelection in project translationstudio8 by heartsome.
the class ProjectSettingHandler method execute.
/**
* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
runWizardPageExtension();
ISelection curSelection = HandlerUtil.getCurrentSelection(event);
if (curSelection != null && !curSelection.isEmpty() && curSelection instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) curSelection;
Object obj = selection.getFirstElement();
if (obj instanceof IProject) {
IProject project = (IProject) obj;
ProjectConfiger cfg = ProjectConfigerFactory.getProjectConfiger(project);
final ProjectInfoBean cfgBean = cfg.getCurrentProjectConfig();
cfgBean.setProjectName(project.getName());
ProjectSettingBaseInfoPage infoPage = new ProjectSettingBaseInfoPage(cfgBean);
ProjectSettingLanguagePage langPag = new ProjectSettingLanguagePage(cfgBean);
final PreferenceManager mgr = new PreferenceManager();
IPreferenceNode infoNode = new PreferenceNode("infoPage", infoPage);
IPreferenceNode langNode = new PreferenceNode("langPag", langPag);
mgr.addToRoot(infoNode);
mgr.addTo("infoPage", langNode);
AbstractProjectSettingPage pageTm = getPageByType("TM");
if (pageTm != null) {
pageTm.setProjectInfoBean(cfgBean);
IPreferenceNode extensionNode = new PreferenceNode("tmInfo", pageTm);
mgr.addTo("infoPage", extensionNode);
}
AbstractProjectSettingPage pageTb = getPageByType("TB");
if (pageTb != null) {
pageTb.setProjectInfoBean(cfgBean);
IPreferenceNode extensionNode = new PreferenceNode("tbInfo", pageTb);
mgr.addTo("infoPage", extensionNode);
}
for (AbstractProjectSettingPage page : extensionPages) {
page.setProjectInfoBean(cfgBean);
IPreferenceNode extensionNode = new PreferenceNode("tbInfo", page);
mgr.addTo("infoPage", extensionNode);
}
ProjectSettingDialog dialog = new ProjectSettingDialog(window.getShell(), mgr);
dialog.create();
dialog.setMessage(infoPage.getTitle());
if (dialog.open() == 0) {
cfg.updateProjectConfig(cfgBean);
try {
project.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
logger.error("", e);
}
}
} else {
MessageDialog.openError(window.getShell(), Messages.getString("handlers.ProjectSettingHandler.msgTitle"), Messages.getString("handlers.ProjectSettingHandler.msg1"));
return null;
}
} else {
MessageDialog.openError(window.getShell(), Messages.getString("handlers.ProjectSettingHandler.msgTitle"), Messages.getString("handlers.ProjectSettingHandler.msg1"));
return null;
}
return null;
}
Aggregations