Search in sources :

Example 6 with UIJob

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;
}
Also used : DBException(org.jkiss.dbeaver.DBException) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) FillLayout(org.eclipse.swt.layout.FillLayout) IValueEditor(org.jkiss.dbeaver.ui.data.IValueEditor) DBException(org.jkiss.dbeaver.DBException) MalformedURLException(java.net.MalformedURLException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GridData(org.eclipse.swt.layout.GridData) UIJob(org.eclipse.ui.progress.UIJob) IValueEditorStandalone(org.jkiss.dbeaver.ui.data.IValueEditorStandalone) Nullable(org.jkiss.code.Nullable)

Example 7 with UIJob

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) UIJob(org.eclipse.ui.progress.UIJob)

Example 8 with UIJob

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) UIJob(org.eclipse.ui.progress.UIJob) Point(org.eclipse.swt.graphics.Point)

Example 9 with UIJob

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();
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CombinedQueryEditorComposite(com.cubrid.common.ui.query.control.CombinedQueryEditorComposite) UIJob(org.eclipse.ui.progress.UIJob)

Example 10 with UIJob

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();
        }
    });
}
Also used : INode(org.talend.core.model.process.INode) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) SystemException(org.talend.commons.exception.SystemException) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) IJobletProviderService(org.talend.core.ui.IJobletProviderService) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SystemException(org.talend.commons.exception.SystemException) UIJob(org.eclipse.ui.progress.UIJob) Job(org.eclipse.core.runtime.jobs.Job) UIJob(org.eclipse.ui.progress.UIJob)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)11 UIJob (org.eclipse.ui.progress.UIJob)11 IStatus (org.eclipse.core.runtime.IStatus)3 GridData (org.eclipse.swt.layout.GridData)3 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)2 CombinedQueryEditorComposite (com.cubrid.common.ui.query.control.CombinedQueryEditorComposite)1 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)1 MalformedURLException (java.net.MalformedURLException)1 ResolutionResult (org.bndtools.core.resolve.ResolutionResult)1 ResolveJob (org.bndtools.core.resolve.ResolveJob)1 ResolutionWizard (org.bndtools.core.resolve.ui.ResolutionWizard)1 IFile (org.eclipse.core.resources.IFile)1 Job (org.eclipse.core.runtime.jobs.Job)1 Action (org.eclipse.jface.action.Action)1 ToolBarManager (org.eclipse.jface.action.ToolBarManager)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 StyledText (org.eclipse.swt.custom.StyledText)1 Point (org.eclipse.swt.graphics.Point)1