use of org.eclipse.ui.progress.UIJob in project dbeaver by serge-rider.
the class SpreadsheetPresentation method openValueEditor.
@Override
@Nullable
public Control openValueEditor(final boolean inline) {
// The control that will be the editor must be a child of the Table
DBDAttributeBinding attr = getFocusAttribute();
ResultSetRow row = getFocusRow();
if (attr == null || row == null) {
return null;
}
if (!inline) {
for (Iterator<SpreadsheetValueController> iterator = openEditors.keySet().iterator(); iterator.hasNext(); ) {
SpreadsheetValueController valueController = iterator.next();
if (attr == valueController.getBinding() && row == valueController.getCurRow()) {
IValueEditorStandalone editor = openEditors.get(valueController);
if (editor.getControl() != null && !editor.getControl().isDisposed()) {
editor.showValueEditor();
return null;
} else {
// Remove disposed editor from the list
iterator.remove();
}
}
}
}
// if (controller.isAttributeReadOnly(attr) && inline) {
// // No inline editors for readonly columns
// return null;
// }
Composite placeholder = null;
if (inline) {
if (controller.isReadOnly()) {
return null;
}
spreadsheet.cancelInlineEditor();
placeholder = new Composite(spreadsheet, SWT.NONE);
placeholder.setFont(spreadsheet.getFont());
placeholder.setLayout(new FillLayout());
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalIndent = 0;
gd.verticalIndent = 0;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
placeholder.setLayoutData(gd);
controller.lockActionsByControl(placeholder);
}
SpreadsheetValueController valueController = new SpreadsheetValueController(controller, attr, row, inline ? IValueController.EditType.INLINE : IValueController.EditType.EDITOR, placeholder);
IValueController.EditType[] supportedEditTypes = valueController.getValueManager().getSupportedEditTypes();
if (supportedEditTypes.length == 0) {
if (placeholder != null) {
placeholder.dispose();
}
return null;
}
/*
if (inline &&
(!ArrayUtils.contains(supportedEditTypes, IValueController.EditType.INLINE) || controller.isAttributeReadOnly(attr)) &&
ArrayUtils.contains(supportedEditTypes, IValueController.EditType.PANEL))
{
// Inline editor isn't supported but panel viewer is
// Enable panel
if (!isPreviewVisible()) {
togglePreview();
}
placeholder.dispose();
return null;
}
*/
final IValueEditor editor;
try {
editor = valueController.getValueManager().createEditor(valueController);
} catch (Exception e) {
UIUtils.showErrorDialog(spreadsheet.getShell(), "Cannot edit value", null, e);
return null;
}
if (editor != null) {
editor.createControl();
}
if (editor instanceof IValueEditorStandalone) {
valueController.registerEditor((IValueEditorStandalone) editor);
// show dialog in separate job to avoid block
new UIJob("Open separate editor") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
((IValueEditorStandalone) editor).showValueEditor();
return Status.OK_STATUS;
}
}.schedule();
//((IValueEditorStandalone)editor).showValueEditor();
} else {
// Set editable value
if (editor != null) {
try {
editor.primeEditorValue(valueController.getValue());
} catch (DBException e) {
log.error(e);
}
editor.setDirty(false);
}
}
if (inline) {
if (editor != null) {
spreadsheet.showCellEditor(placeholder);
return editor.getControl();
} else {
// No editor was created so just drop placeholder
placeholder.dispose();
// Probably we can just show preview panel
if (ArrayUtils.contains(supportedEditTypes, IValueController.EditType.PANEL)) {
// Inline editor isn't supported but panel viewer is
// Enable panel
controller.activatePanel(ViewValuePanel.PANEL_ID, true, true);
return null;
}
}
}
return null;
}
use of org.eclipse.ui.progress.UIJob in project cubrid-manager by CUBRID.
the class QueryEditorPart method newQueryTab.
public void newQueryTab(final String query, final boolean run) {
UIJob job = new UIJob(Messages.settingQueries) {
public IStatus runInUIThread(IProgressMonitor monitor) {
if (isAvilableEditor()) {
String sql = combinedQueryComposite.getSqlEditorComp().getText().getText();
if (!StringUtil.isEmpty(sql)) {
addEditorTab();
}
combinedQueryComposite.getSqlEditorComp().setQueries(query);
if (run) {
runQueryInCursorLine();
}
}
return Status.OK_STATUS;
}
};
job.setPriority(UIJob.SHORT);
job.schedule();
}
use of org.eclipse.ui.progress.UIJob in project cubrid-manager by CUBRID.
the class QueryEditorPart method setQuery.
/**
* Set and run queries with prepared parameters
*
* @param displayQueries
* @param runQueries
* @param rowParameterList
* @param isAppend
* @param isRun
* @param isOnlyQueryPlan
*/
public void setQuery(final String displayQueries, final String runQueries, final List<List<PstmtParameter>> rowParameterList, final boolean isAppend, final boolean isRun, final boolean isOnlyQueryPlan) {
// Update queries in the UI JOB
UIJob job = new UIJob(Messages.settingQueries) {
public IStatus runInUIThread(IProgressMonitor monitor) {
if (isAvilableEditor()) {
if (isAppend) {
String allQuery = getAllQueries();
int start = allQuery.indexOf(displayQueries);
if (start == -1) {
combinedQueryComposite.getSqlEditorComp().getText().append(displayQueries);
} else {
setSelection(start, start + displayQueries.length());
}
} else {
combinedQueryComposite.getSqlEditorComp().setQueries(displayQueries);
}
if (isRun) {
runQuery(false, runQueries, rowParameterList);
} else if (isOnlyQueryPlan) {
runQuery(true, runQueries, rowParameterList);
}
}
return Status.OK_STATUS;
}
};
job.setPriority(UIJob.SHORT);
job.schedule();
}
use of org.eclipse.ui.progress.UIJob in project cubrid-manager by CUBRID.
the class ERSchemaEditor method generateSqlsToQueryEditor.
private void generateSqlsToQueryEditor(List<StringBuffer> sqls) throws PartInitException {
final boolean isSupportOnServer = CompatibleUtil.isCommentSupports(database.getDatabaseInfo());
final QueryEditorPart editPart = CommonUITool.openQueryEditor(database, false);
editPart.setQuery(sqls.get(0).toString(), true, false, false);
if (sqls.size() > 1) {
editPart.newQueryTab(sqls.get(1).toString(), false);
}
UIJob job = new UIJob("") {
public IStatus runInUIThread(IProgressMonitor monitor) {
String tabMessage = isSupportOnServer ? Messages.edittabNameAlterSQL : Messages.edittabNameInsertSQL;
List<CombinedQueryEditorComposite> allTabItems = editPart.getAllCombinedQueryEditorComposite();
editPart.updateTabName(allTabItems.get(0).getSubQueryEditorTabItem(), tabMessage, true);
if (allTabItems.size() > 1) {
editPart.updateTabName(allTabItems.get(1).getSubQueryEditorTabItem(), Messages.edittabNameUpdateSQL, true);
}
return Status.OK_STATUS;
}
};
job.setPriority(UIJob.BUILD);
job.schedule();
}
use of org.eclipse.ui.progress.UIJob in project tdi-studio-se by Talend.
the class CodeView method refresh.
public void refresh() {
ICodeGeneratorService service = DesignerPlugin.getDefault().getCodeGeneratorService();
if (service.isInitializingJet()) {
return;
}
if (isGenerating()) {
return;
}
setGenerating(true);
final List<? extends INode> generatingNodes = selectedNode.getProcess().getGeneratingNodes();
Job job = new //$NON-NLS-1$
Job(//$NON-NLS-1$
Messages.getString("CodeView.initMessage")) {
@Override
protected IStatus run(IProgressMonitor monitor) {
if (selectedNode != null) {
//$NON-NLS-1$
generatedCode = "";
try {
// joblet or joblet node
boolean isJoblet = AbstractProcessProvider.isExtensionProcessForJoblet(selectedNode.getProcess());
if (!isJoblet && PluginChecker.isJobLetPluginLoaded()) {
IJobletProviderService jobletSservice = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (jobletSservice != null && jobletSservice.isJobletComponent(selectedNode)) {
isJoblet = true;
}
}
if (isJoblet) {
return org.eclipse.core.runtime.Status.OK_STATUS;
}
generatingNode = null;
for (INode node : generatingNodes) {
if (node.getUniqueName().equals(selectedNode.getUniqueName())) {
generatingNode = node;
}
}
if (generatingNode == null) {
//$NON-NLS-1$
generatedCode = Messages.getString("CodeView.MultipleComponentError");
return org.eclipse.core.runtime.Status.OK_STATUS;
}
ICodeGeneratorService service = DesignerPlugin.getDefault().getCodeGeneratorService();
// have to do this dirty change to avoid the side effect for BD component.
codeGenerator = service.createCodeGenerator(selectedNode.getProcess(), false, false);
viewStartAction.setChecked(false);
viewMainAction.setChecked(false);
viewEndAction.setChecked(false);
viewAllAction.setChecked(false);
switch(codeView) {
case CODE_START:
viewStartAction.setChecked(true);
generatedCode = codeGenerator.generateComponentCode(generatingNode, ECodePart.BEGIN);
break;
case CODE_MAIN:
viewMainAction.setChecked(true);
generatedCode = codeGenerator.generateComponentCode(generatingNode, ECodePart.MAIN);
break;
case CODE_END:
viewEndAction.setChecked(true);
generatedCode = codeGenerator.generateComponentCode(generatingNode, ECodePart.END);
break;
case CODE_ALL:
viewAllAction.setChecked(true);
generatedCode = codeGenerator.generateComponentCode(generatingNode, ECodePart.BEGIN);
generatedCode += codeGenerator.generateComponentCode(generatingNode, ECodePart.MAIN);
generatedCode += codeGenerator.generateComponentCode(generatingNode, ECodePart.END);
break;
default:
}
} catch (SystemException e) {
//$NON-NLS-1$
generatedCode = Messages.getString("CodeView.Error");
ExceptionHandler.process(e);
} catch (Exception e) {
// Some exceptions can appear in case we close some jobs while generating
// Just ignore them, and set blank directly to the code view
//$NON-NLS-1$
generatedCode = "";
}
}
return org.eclipse.core.runtime.Status.OK_STATUS;
}
};
job.setPriority(Job.INTERACTIVE);
job.schedule();
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
new UIJob("") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
document.set(generatedCode);
setGenerating(false);
return org.eclipse.core.runtime.Status.OK_STATUS;
}
}.schedule();
}
});
}
Aggregations