use of org.eclipse.core.runtime.IProgressMonitor in project dbeaver by serge-rider.
the class DBeaverUI method runInProgressDialog.
/**
* Runs task in Eclipse progress dialog.
* NOTE: this call can't be canceled if it will block in IO
*/
public static void runInProgressDialog(final DBRRunnableWithProgress runnable) throws InvocationTargetException {
try {
IRunnableContext runnableContext;
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
if (workbenchWindow != null) {
runnableContext = new ProgressMonitorDialog(workbench.getActiveWorkbenchWindow().getShell());
} else {
runnableContext = workbench.getProgressService();
}
runnableContext.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
runnable.run(RuntimeUtils.makeMonitor(monitor));
}
});
} catch (InterruptedException e) {
// do nothing
}
}
use of org.eclipse.core.runtime.IProgressMonitor in project dbeaver by serge-rider.
the class ScriptPositionColumn method columnCreated.
@Override
public void columnCreated() {
visible = true;
new UIJob("Update script ruler") {
{
setSystem(true);
}
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
if (DBeaverCore.isClosing()) {
return Status.CANCEL_STATUS;
}
BaseTextEditor editor = (BaseTextEditor) getEditor();
if (editor == null || editor.getTextViewer() == null)
return Status.CANCEL_STATUS;
StyledText textWidget = editor.getTextViewer().getTextWidget();
if (textWidget == null || textWidget.isDisposed())
return Status.CANCEL_STATUS;
if (textWidget.isVisible()) {
int[] newCurrentLines = editor.getCurrentLines();
if (!Arrays.equals(newCurrentLines, currentLines)) {
currentLines = newCurrentLines;
redraw();
}
}
if (visible) {
schedule(100);
}
return Status.OK_STATUS;
}
}.schedule(100);
}
use of org.eclipse.core.runtime.IProgressMonitor in project translationstudio8 by heartsome.
the class ExportTbxDialog method okPressed.
@Override
protected void okPressed() {
String encoding = "UTF-8";
if (hasChangedCodingCbtn.getSelection()) {
encoding = this.encodingComboViewer.getCombo().getText();
}
String exportPath = this.tbxFileText.getText();
ExportFilterBean filterBean = null;
if (hasFilterChangedBtn.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.ExportTbxDialog.msgTitle"), Messages.getString("dialog.ExportTbxDialog.msg3"));
return;
}
for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
ExportDatabaseBean dbBean = iterator.next();
if (dbBean.getHasSelectedLangs().size() < 2) {
String dbType = dbBean.getDbBean().getDbType();
String name = dbBean.getDbBean().getDatabaseName();
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTbxDialog.msg4"), dbType, name));
return;
}
}
if (exportPath == null || exportPath.equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), Messages.getString("dialog.ExportTbxDialog.msg5"));
return;
}
if (this.dbList.size() > 1) {
File f = new File(exportPath);
if (!f.isDirectory()) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), Messages.getString("dialog.ExportTbxDialog.msg7"));
return;
}
}
if (this.dbList.size() == 1) {
File f = new File(exportPath);
if (f.isDirectory()) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), Messages.getString("dialog.ExportTbxDialog.msg8"));
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.ExportTbxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTbxDialog.msg6"), 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() + ".tbx";
File file = new File(path);
if (file.exists()) {
if (!MessageDialog.openConfirm(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTbxDialog.msg6"), path))) {
return;
}
}
db.setExportFilePath(path);
}
}
final ExportAbstract exportor = new ExportTbxImpl(this.dbList, filterBean, encoding);
Job job = new Job(Messages.getString("dialog.ExportTbxDialog.job")) {
@Override
protected IStatus run(IProgressMonitor monitor) {
final String result = DatabaseService.executeExport(exportor, monitor);
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTbxDialog.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.IProgressMonitor in project translationstudio8 by heartsome.
the class ExportTbxImpl method executeExport.
/**
* (non-Javadoc)
* @see net.heartsome.cat.document.ExportAbstract#executeExport(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public String executeExport(IProgressMonitor monitor) {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
String whereResult = "";
if (this.filterBean != null) {
StringBuffer whereBf = new StringBuffer();
String connector = this.filterBean.getFilterConnector();
List<ExportFilterComponentBean> filterOptions = this.filterBean.getFilterOption();
whereBf.append(" AND ");
for (Iterator<ExportFilterComponentBean> iterator = filterOptions.iterator(); iterator.hasNext(); ) {
ExportFilterComponentBean filterBean = iterator.next();
whereBf.append("PURE ");
whereBf.append("LIKE ");
whereBf.append("'%" + filterBean.getFilterVlaue() + "%' ");
whereBf.append(connector + " ");
}
whereResult = whereBf.toString();
whereResult = whereResult.substring(0, whereResult.lastIndexOf(connector));
}
monitor.beginTask("", dbList.size());
for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
ExportDatabaseBean db = iterator.next();
String srcLang = db.getSrcLang();
List<String> needLang = db.getHasSelectedLangs();
DBOperator dbOp = DatabaseService.getDBOperator(db.getDbBean());
try {
dbOp.start();
output = new FileOutputStream(db.getExportFilePath());
writeHeader(srcLang);
writeString("<text>\n<body>\n");
List<Integer> tPkId = dbOp.getAfterFilterTermEntryPK(whereResult, needLang);
// Fix Bug #2361 TBX文件导出问题--语言不能正确过滤导出 by Jason
tPkId = dbOp.validateTermEntryPk(tPkId, needLang, srcLang);
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
subMonitor.beginTask(Messages.getString("document.ExportTbxImpl.task1") + db.getDbBean().getDatabaseName(), tPkId.size());
subMonitor.setTaskName(Messages.getString("document.ExportTbxImpl.task1") + db.getDbBean().getDatabaseName());
for (int i = 0; i < tPkId.size(); i++) {
// long l = System.currentTimeMillis();
if (monitor.isCanceled()) {
clearResource();
return USER_CANCEL;
}
int termEntryPK = tPkId.get(i);
String termEntry = dbOp.retrieveTermEntry(termEntryPK);
if (termEntry != null && !termEntry.equals("")) {
writeString(termEntry);
}
subMonitor.worked(1);
}
writeString("</body>\n</text>\n</martif>\n");
} catch (SQLException e) {
logger.error(DBOP_ERROR, e);
e.printStackTrace();
clearResource();
return DBOP_ERROR + db.getDbBean().getDbType() + " " + db.getDbBean().getDatabaseName();
} catch (ClassNotFoundException e) {
logger.error(JDBC_ERROR, e);
e.printStackTrace();
clearResource();
return JDBC_ERROR + db.getDbBean().getDbType();
} catch (IOException e) {
logger.error(FILE_ERROR, e);
e.printStackTrace();
clearResource();
return FILE_ERROR + db.getDbBean().getDbType() + " " + db.getDbBean().getDatabaseName();
} finally {
try {
output.close();
if (dbOp != null) {
dbOp.end();
}
} catch (SQLException e) {
logger.error(RELEASE_DB_ERROR, e);
} catch (IOException e) {
logger.error(RELEASE_FILE_ERROR, e);
}
}
filterLangSet(db.getExportFilePath(), srcLang, needLang);
}
monitor.done();
return SUCCESS;
}
use of org.eclipse.core.runtime.IProgressMonitor in project translationstudio8 by heartsome.
the class ExportTmxImpl method executeExport.
/**
* (non-Javadoc)
* @see net.heartsome.cat.document.ExportAbstract#executeExport()
*/
@Override
public String executeExport(IProgressMonitor monitor) {
String mTuFilter = "";
String textDataFilter = "";
String mNoteFilter = "";
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask("", dbList.size());
for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
ExportDatabaseBean db = iterator.next();
String srcLang = db.getSrcLang();
DBOperator dbOp = DatabaseService.getDBOperator(db.getDbBean());
// 过滤条件
if (this.filterBean != null) {
mTuFilter = dbOp.generationExportTMXFilter("MTU", this.filterBean);
textDataFilter = dbOp.generationExportTMXFilter("TEXTDATA", this.filterBean);
mNoteFilter = dbOp.generationExportTMXFilter("MNOTE", this.filterBean);
}
try {
dbOp.start();
output = new FileOutputStream(db.getExportFilePath());
if (encoding.equalsIgnoreCase("UTF-16LE")) {
output.write(0xFF);
output.write(0xFE);
} else if (encoding.equalsIgnoreCase("UTF-16BE")) {
output.write(0xFE);
output.write(0xFF);
}
List<Integer> filterTu = dbOp.getAfterFilterTuPk(mTuFilter, mNoteFilter, textDataFilter);
writeHeader(srcLang);
writeString("<body>\n");
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
subMonitor.beginTask(Messages.getString("document.ExportTmxImpl.task1") + db.getDbBean().getDatabaseName(), filterTu.size());
subMonitor.setTaskName(Messages.getString("document.ExportTmxImpl.task1") + db.getDbBean().getDatabaseName());
for (int i = 0; i < filterTu.size(); i++) {
// long l = System.currentTimeMillis();
if (monitor.isCanceled()) {
clearResource();
break;
}
int tuPk = filterTu.get(i);
String tuNodeContent = dbOp.retrieveTu(tuPk, db.getHasSelectedLangs(), isToplevelTmx, isTagLevelTmx);
if (tuNodeContent != null && !tuNodeContent.equals("")) {
writeString(tuNodeContent);
}
subMonitor.worked(1);
}
//$NON-NLS-1$
writeString("</body>\n");
//$NON-NLS-1$
writeString("</tmx>\n");
subMonitor.done();
} catch (SQLException e) {
logger.error(DBOP_ERROR, e);
e.printStackTrace();
clearResource();
return DBOP_ERROR + db.getDbBean().getDbType() + " " + db.getDbBean().getDatabaseName();
} catch (ClassNotFoundException e) {
logger.error(JDBC_ERROR, e);
e.printStackTrace();
clearResource();
return JDBC_ERROR + db.getDbBean().getDbType();
} catch (IOException e) {
logger.error(FILE_ERROR, e);
e.printStackTrace();
clearResource();
return FILE_ERROR + db.getDbBean().getDbType() + " " + db.getDbBean().getDatabaseName();
} finally {
try {
output.close();
if (dbOp != null) {
dbOp.end();
}
} catch (SQLException e) {
logger.error(RELEASE_DB_ERROR, e);
} catch (IOException e) {
logger.error(RELEASE_FILE_ERROR, e);
}
}
}
if (monitor.isCanceled()) {
return USER_CANCEL;
}
monitor.done();
return SUCCESS;
}
Aggregations