use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project translationstudio8 by heartsome.
the class AutomaticUpdate method checkForUpdates.
public void checkForUpdates() throws OperationCanceledException {
// 检查 propfile
String profileId = getProvisioningUI().getProfileId();
IProvisioningAgent agent = getProvisioningUI().getSession().getProvisioningAgent();
IProfile profile = null;
if (agent != null) {
IProfileRegistry registry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
if (registry != null) {
profile = registry.getProfile(profileId);
}
}
if (profile == null) {
// Inform the user nicely
P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_AUTO_CHECK);
return;
}
// 开始检查前先确定是否有repository
RepositoryTracker repoMan = getProvisioningUI().getRepositoryTracker();
if (repoMan.getKnownRepositories(getProvisioningUI().getSession()).length == 0) {
P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_AUTO_CHECK);
return;
}
final IStatus[] checkStatus = new IStatus[1];
Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(getProvisioningUI()) {
public IStatus runModal(IProgressMonitor monitor) {
SubMonitor sub = SubMonitor.convert(monitor, P2UpdateUtil.CHECK_UPDATE_TASK_NAME, 1000);
// load repository
IStatus status = super.runModal(sub.newChild(500));
if (status.getSeverity() == IStatus.CANCEL) {
return status;
}
if (status.getSeverity() != Status.OK) {
// load repository error
checkStatus[0] = status;
}
operation = getProvisioningUI().getUpdateOperation(null, null);
// check for updates
IStatus resolveStatus = operation.resolveModal(sub.newChild(500));
if (resolveStatus.getSeverity() == IStatus.CANCEL) {
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
};
loadJob.setName(P2UpdateUtil.ATUO_CHECK_UPDATE_JOB_NAME);
loadJob.setProperty(LoadMetadataRepositoryJob.ACCUMULATE_LOAD_ERRORS, Boolean.toString(true));
loadJob.addJobChangeListener(new JobChangeAdapter() {
public void done(IJobChangeEvent event) {
if (PlatformUI.isWorkbenchRunning())
if (event.getResult().isOK()) {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
if (checkStatus[0] != null) {
// 提示连接异常
P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_AUTO_CHECK);
return;
}
doUpdate();
}
});
}
}
});
loadJob.setUser(true);
loadJob.schedule();
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project translationstudio8 by heartsome.
the class TMX2TXTConverterDialog method convert.
/**
* 开始转换
*/
private void convert() {
final String tmxLocation = tmxTxt.getText();
if (tmxLocation.equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg1"));
return;
}
final String txtLocation = txtTxt.getText();
if (txtLocation.equals("")) {
//$NON-NLS-1$
MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg2"));
return;
}
File txtFile = new File(txtLocation);
if (txtFile.exists()) {
boolean response = MessageDialog.openConfirm(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle2"), MessageFormat.format(Messages.getString("dialog.TMX2TXTConverterDialog.msg3"), txtLocation));
if (!response) {
return;
}
} else if (!txtFile.getParentFile().exists()) {
txtFile.getParentFile().mkdirs();
}
Job job = new Job(Messages.getString("dialog.TMX2TXTConverterDialog.job")) {
@Override
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask(Messages.getString("dialog.TMX2TXTConverterDialog.task"), 10);
// 先解析文件,花费一格
int openResult = openFile(tmxLocation, monitor);
if (openResult == 0) {
return Status.CANCEL_STATUS;
} else if (openResult == -2) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg4"));
}
});
return Status.CANCEL_STATUS;
} else if (openResult == -1) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg5"));
}
});
return Status.CANCEL_STATUS;
}
if (!validVersion(tmxLocation)) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg6"));
}
});
return Status.CANCEL_STATUS;
}
if ((tuNodesCount = getTUCount(tmxLocation)) <= 0) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg7"));
}
});
return Status.CANCEL_STATUS;
}
try {
output = new FileOutputStream(txtLocation);
byte[] bom = new byte[3];
bom[0] = (byte) 0xEF;
bom[1] = (byte) 0xBB;
bom[2] = (byte) 0xBF;
output.write(bom);
writeHeader();
monitor.worked(1);
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 8, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
return processTU(tmxLocation, txtLocation, subMonitor);
} catch (Exception e) {
e.printStackTrace();
LOGGER.error("", e);
}
monitor.done();
return Status.OK_STATUS;
}
};
// 当程序退出时,检测当前 job 是否正常关闭
CommonFunction.jobCantCancelTip(job);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void running(IJobChangeEvent event) {
ProgressIndicatorManager.displayProgressIndicator();
super.running(event);
}
@Override
public void done(IJobChangeEvent event) {
ProgressIndicatorManager.hideProgressIndicator();
super.done(event);
}
});
job.setUser(true);
job.schedule();
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project translationstudio8 by heartsome.
the class ExportTmxDialog method okPressed.
@Override
protected void okPressed() {
String encoding = "UTF-8";
if (hasChangedCodingCbtn.getSelection()) {
encoding = this.encodingComboViewer.getCombo().getText();
}
String exportPath = this.tmxFileText.getText();
boolean isTopLevelTmx = this.isTopLevelTmxCbtn.getSelection();
boolean isTagLevelTmx = this.isTagCbtn.getSelection();
ExportFilterBean filterBean = null;
if (this.hasfilterCbtn.getSelection()) {
IStructuredSelection sel = (IStructuredSelection) filterComboViewer.getSelection();
filterBean = (ExportFilterBean) sel.getFirstElement();
if (filterBean.equals(filterList.get(0))) {
filterBean = null;
}
}
if (this.dbList.size() == 0) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg3"));
return;
}
for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
ExportDatabaseBean dbBean = iterator.next();
String dbType = dbBean.getDbBean().getDbType();
String name = dbBean.getDbBean().getDatabaseName();
if (dbBean.getHasSelectedLangs().size() < 2) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg4"), dbType, name));
return;
}
if (dbBean.getSrcLang().equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg5"), dbType, name));
return;
}
}
if (exportPath == null || exportPath.equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg6"));
return;
}
if (this.dbList.size() > 1) {
File f = new File(exportPath);
if (!f.isDirectory()) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg8"));
return;
}
}
if (this.dbList.size() == 1) {
File f = new File(exportPath);
if (f.isDirectory()) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg9"));
return;
}
}
if (this.dbList.size() == 1) {
dbList.get(0).setExportFilePath(exportPath);
File file = new File(exportPath);
if (file.exists()) {
if (!MessageDialog.openConfirm(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg7"), exportPath))) {
return;
}
}
} else {
for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
ExportDatabaseBean db = iterator.next();
String databaseName = db.getDbBean().getDatabaseName();
String path = exportPath + System.getProperty("file.separator") + databaseName + db.getDbBean().getDbType() + ".tmx";
File file = new File(path);
if (file.exists()) {
if (!MessageDialog.openConfirm(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg7"), path))) {
return;
}
}
db.setExportFilePath(path);
}
}
final ExportAbstract tmxExport = new ExportTmxImpl(this.dbList, filterBean, encoding, isTopLevelTmx, isTagLevelTmx);
Job job = new Job(Messages.getString("dialog.ExportTmxDialog.job")) {
@Override
protected IStatus run(IProgressMonitor monitor) {
final String result = DatabaseService.executeExport(tmxExport, monitor);
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), result);
}
});
return Status.OK_STATUS;
}
};
// 当程序退出时,检测当前 job 是否正常关闭
CommonFunction.jobCantCancelTip(job);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void running(IJobChangeEvent event) {
ProgressIndicatorManager.displayProgressIndicator();
super.running(event);
}
@Override
public void done(IJobChangeEvent event) {
ProgressIndicatorManager.hideProgressIndicator();
super.done(event);
}
});
job.setUser(true);
job.schedule();
super.okPressed();
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project translationstudio8 by heartsome.
the class ExportDocxDialog method okPressed.
@Override
protected void okPressed() {
if (xliffPathTxt.getText() == null || xliffPathTxt.getText().trim().equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxDialog.ok.msg0"));
return;
}
String docxPath = docxPathTxt.getText().trim();
if (docxPath == null || docxPath.length() <= 0) {
MessageDialog.openInformation(getShell(), Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxDialog.ok.msg3"));
return;
}
IDialogSettings dialogSettings = Activator.getDefault().getDialogSettings();
dialogSettings.put(STORE_DOCX_PATH, docxPath);
XLFValidator.resetFlag();
if (!XLFValidator.validateXliffFile(strXliffFullPath)) {
return;
}
XLFValidator.resetFlag();
// 补全 docx 路径
docxPath = docxPath + File.separator + new File(strXliffFullPath).getName() + ".docx";
if (new File(docxPath).exists()) {
boolean confirm = MessageDialog.openConfirm(getShell(), Messages.getString("all.dialog.confirm"), MessageFormat.format(Messages.getString("ExportDocxDialog.ok.msg5"), "DOCX", docxPath));
if (confirm) {
new File(docxPath).delete();
} else {
return;
}
}
final boolean commentSelection = commentBtn.getSelection();
final boolean statusSelection = statusBtn.getSelection();
// 设置查询每个 tu 的条件,比如排除或者 仅导出
String expandXpath = "";
if (excludeBtn.getSelection()) {
if (excludeLockedBtn.getSelection()) {
expandXpath += " and not(@translate='no')";
}
if (exclude101Btn.getSelection()) {
expandXpath += " and not(target[@hs:quality='101'])";
}
if (exclude100Btn.getSelection()) {
expandXpath += " and not(target[@hs:quality='100'])";
}
} else if (onlyExportBtn.getSelection()) {
if (onlyExportNoteBtn.getSelection()) {
expandXpath += " and note/text()!=''";
} else if (onlyExportReviewBtn.getSelection()) {
expandXpath += " and @hs:needs-review='yes'";
}
}
final String finalExpandXpath = expandXpath;
// 这里开始调用导出的方法
final String finalDocxPath = docxPath;
Job job = new Job(Messages.getString("ExportDocxDialog.ok.monitor.title")) {
protected IStatus run(final IProgressMonitor monitor) {
try {
// 解析文件花一格。读取 xliff 数据花 1 格,导出花 18 格。
monitor.beginTask(Messages.getString("ExportDocxDialog.ok.monitor.msg0"), 20);
beginExport(monitor, finalDocxPath, commentSelection, statusSelection, finalExpandXpath);
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxDialog.ok.msg4"));
}
});
monitor.done();
} catch (OperationCanceledException e) {
// do nothing
} catch (final Exception e) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openError(getShell(), Messages.getString("all.dialog.error"), Messages.getString("ExportDocxDialog.ok.exportError") + "\n" + e.getMessage());
}
});
LOGGER.error("Export xliff to MS WORD error\n" + e.getMessage(), e);
}
return Status.OK_STATUS;
}
};
// 当程序退出时,检测当前 job 是否正常关闭
CommonFunction.jobCantCancelTip(job);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void running(IJobChangeEvent event) {
ProgressIndicatorManager.displayProgressIndicator();
super.running(event);
}
@Override
public void done(IJobChangeEvent event) {
ProgressIndicatorManager.hideProgressIndicator();
super.done(event);
}
});
job.setUser(true);
job.schedule();
close();
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project translationstudio8 by heartsome.
the class FileAnalysisHandler method analysisFile.
/**
* 准备分析文件
*/
public void analysisFile(String title) {
final QAXmlHandler handler = new QAXmlHandler();
Job job = new Job(title) {
@Override
protected IStatus run(IProgressMonitor monitor) {
// 要分析的文件的个数
int fileNum = model.getAnalysisIFileList().size();
model.setSubFileNum(fileNum);
// 定义的进度条总共四格,其中,解析文件一格,分析文件三格
monitor.beginTask("", fileNum * 4);
// 解析文件,如果解析不成功,退出程序, 解析要分析的文件,用掉fileNum*1个格子
if (!openXliff(handler, monitor)) {
monitor.done();
return Status.CANCEL_STATUS;
}
if (model.getAnalysisIFileList().size() == 0) {
MessageDialog.openInformation(shell, Messages.getString("qa.all.dialog.info"), Messages.getString("qa.handlers.FileAnalysisHandler.tip4"));
return Status.CANCEL_STATUS;
}
// 填充要分析文件的所有trans-unit节点个数的总和
model.setAllTuSize(allTUSize);
FileAnalysis fileAnalysis = getClassInstance(faItemId);
// 分析文件用去fileNum*3个格子
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, fileNum * 3, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
int analysisResult = fileAnalysis.beginAnalysis(model, subMonitor, handler);
if (analysisResult == -1 || analysisResult == QAConstant.QA_ZERO) {
return Status.CANCEL_STATUS;
}
subMonitor.done();
monitor.done();
return Status.OK_STATUS;
}
};
// 当程序退出时,检测当前 job 是否正常关闭
CommonFunction.jobCantCancelTip(job);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void running(IJobChangeEvent event) {
ProgressIndicatorManager.displayProgressIndicator();
super.running(event);
}
@Override
public void done(IJobChangeEvent event) {
ProgressIndicatorManager.hideProgressIndicator();
super.done(event);
}
});
job.setUser(true);
job.schedule();
}
Aggregations