Search in sources :

Example 1 with SubEditorSite

use of org.jkiss.dbeaver.ui.editors.SubEditorSite in project dbeaver by serge-rider.

the class XMLPanelEditor method createControl.

@Override
public StyledText createControl(IValueController valueController) {
    this.valueController = valueController;
    this.subSite = new SubEditorSite(valueController.getValueSite());
    editor = new XMLEditor();
    try {
        editor.init(subSite, StringEditorInput.EMPTY_INPUT);
    } catch (PartInitException e) {
        valueController.showMessage(e.getMessage(), DBPMessageType.ERROR);
        return new StyledText(valueController.getEditPlaceholder(), SWT.NONE);
    }
    editor.createPartControl(valueController.getEditPlaceholder());
    ContentPanelEditor.setEditorSettings(editor.getEditorControl());
    return editor.getEditorControl();
}
Also used : SubEditorSite(org.jkiss.dbeaver.ui.editors.SubEditorSite) StyledText(org.eclipse.swt.custom.StyledText) PartInitException(org.eclipse.ui.PartInitException) XMLEditor(org.jkiss.dbeaver.ui.editors.xml.XMLEditor)

Example 2 with SubEditorSite

use of org.jkiss.dbeaver.ui.editors.SubEditorSite in project dbeaver by serge-rider.

the class PrefPageSQLFormat method createPreferenceContent.

@Override
protected Control createPreferenceContent(Composite parent) {
    Composite composite = UIUtils.createPlaceholder(parent, 2, 5);
    // Autoclose
    {
        Composite acGroup = UIUtils.createControlGroup(composite, "Auto close", 1, GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING, 0);
        acSingleQuotesCheck = UIUtils.createCheckbox(acGroup, "Single quotes", false);
        acDoubleQuotesCheck = UIUtils.createCheckbox(acGroup, "Double quotes", false);
        acBracketsCheck = UIUtils.createCheckbox(acGroup, "Brackets", false);
    }
    {
        // Formatting
        Composite afGroup = UIUtils.createControlGroup(composite, "Auto format", 1, GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING, 0);
        afKeywordCase = UIUtils.createCheckbox(afGroup, "Convert keyword case", "Auto-convert keywords to upper/lower case on enter", false, 1);
        afExtractFromSource = UIUtils.createCheckbox(afGroup, "Extract SQL from source code", "On source code paste will remove all source language elements like quotes, +, \\n, etc", false, 1);
    }
    Composite formatterGroup = UIUtils.createControlGroup(composite, "Formatter", 1, GridData.FILL_BOTH, 0);
    ((GridData) formatterGroup.getLayoutData()).horizontalSpan = 2;
    {
        Composite formatterPanel = UIUtils.createPlaceholder(formatterGroup, 2);
        formatterPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        formatterSelector = UIUtils.createLabelCombo(formatterPanel, "Formatter", SWT.DROP_DOWN | SWT.READ_ONLY);
        formatterSelector.add(capitalizeCaseName(SQLTokenizedFormatter.FORMATTER_ID));
        formatterSelector.add(capitalizeCaseName(SQLExternalFormatter.FORMATTER_ID));
        formatterSelector.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                showFormatterSettings();
            }
        });
        formatterSelector.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    }
    // Default formatter settings
    {
        defaultGroup = UIUtils.createPlaceholder(formatterGroup, 2, 0);
        defaultGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        keywordCaseCombo = UIUtils.createLabelCombo(defaultGroup, "Keyword case", SWT.DROP_DOWN | SWT.READ_ONLY);
        keywordCaseCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        keywordCaseCombo.add("Database");
        for (DBPIdentifierCase c : DBPIdentifierCase.values()) {
            keywordCaseCombo.add(capitalizeCaseName(c.name()));
        }
        keywordCaseCombo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                performApply();
            }
        });
    }
    // External formatter
    {
        externalGroup = UIUtils.createPlaceholder(formatterGroup, 2);
        externalGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        externalCmdText = UIUtils.createLabelText(externalGroup, "Command line", "");
        externalCmdText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        externalUseFile = UIUtils.createLabelCheckbox(externalGroup, "Use temp file", "Use temporary file to pass SQL text.\nTo pass file name in command line use parameter ${file}", false);
        externalTimeout = UIUtils.createLabelSpinner(externalGroup, "Exec timeout", "Time to wait until formatter process finish (ms)", 100, 100, 10000);
    }
    {
        // SQL preview
        Composite previewGroup = new Composite(formatterGroup, SWT.BORDER);
        previewGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
        previewGroup.setLayout(new FillLayout());
        sqlViewer = new SQLEditorBase() {

            @Override
            public DBCExecutionContext getExecutionContext() {
                final DBPDataSourceContainer container = getDataSourceContainer();
                if (container != null) {
                    final DBPDataSource dataSource = container.getDataSource();
                    if (dataSource != null) {
                        return dataSource.getDefaultContext(false);
                    }
                }
                return null;
            }
        };
        try {
            try (final InputStream sqlStream = getClass().getResourceAsStream(FORMAT_FILE_NAME)) {
                final String sqlText = ContentUtils.readToString(sqlStream, GeneralUtils.DEFAULT_ENCODING);
                IEditorSite subSite = new SubEditorSite(DBeaverUI.getActiveWorkbenchWindow().getActivePage().getActivePart().getSite());
                StringEditorInput sqlInput = new StringEditorInput("SQL preview", sqlText, true, GeneralUtils.getDefaultFileEncoding());
                sqlViewer.init(subSite, sqlInput);
            }
        } catch (Exception e) {
            log.error(e);
        }
        sqlViewer.createPartControl(previewGroup);
        Object text = sqlViewer.getAdapter(Control.class);
        if (text instanceof StyledText) {
            ((StyledText) text).setWordWrap(true);
        }
        sqlViewer.reloadSyntaxRules();
        previewGroup.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                sqlViewer.dispose();
            }
        });
    }
    return composite;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) StyledText(org.eclipse.swt.custom.StyledText) InputStream(java.io.InputStream) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DisposeEvent(org.eclipse.swt.events.DisposeEvent) StringEditorInput(org.jkiss.dbeaver.ui.editors.StringEditorInput) SubEditorSite(org.jkiss.dbeaver.ui.editors.SubEditorSite) SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPIdentifierCase(org.jkiss.dbeaver.model.DBPIdentifierCase) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IEditorSite(org.eclipse.ui.IEditorSite)

Example 3 with SubEditorSite

use of org.jkiss.dbeaver.ui.editors.SubEditorSite in project dbeaver by dbeaver.

the class PrefPageSQLFormat method createPreferenceContent.

@Override
protected Control createPreferenceContent(Composite parent) {
    Composite composite = UIUtils.createPlaceholder(parent, 2, 5);
    // Autoclose
    {
        Composite acGroup = UIUtils.createControlGroup(composite, CoreMessages.pref_page_sql_format_group_auto_close, 1, GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING, 0);
        acSingleQuotesCheck = UIUtils.createCheckbox(acGroup, CoreMessages.pref_page_sql_format_label_single_quotes, false);
        acDoubleQuotesCheck = UIUtils.createCheckbox(acGroup, CoreMessages.pref_page_sql_format_label_double_quotes, false);
        acBracketsCheck = UIUtils.createCheckbox(acGroup, CoreMessages.pref_page_sql_format_label_brackets, false);
    }
    {
        // Formatting
        Composite afGroup = UIUtils.createControlGroup(composite, CoreMessages.pref_page_sql_format_group_auto_format, 1, GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING, 0);
        afKeywordCase = UIUtils.createCheckbox(afGroup, CoreMessages.pref_page_sql_format_label_convert_keyword_case, CoreMessages.pref_page_sql_format_label_convert_keyword_case_tip, false, 1);
        afExtractFromSource = UIUtils.createCheckbox(afGroup, CoreMessages.pref_page_sql_format_label_extract_sql_from_source_code, CoreMessages.pref_page_sql_format_label_extract_sql_from_source_code_tip, false, 1);
    }
    Composite formatterGroup = UIUtils.createControlGroup(composite, CoreMessages.pref_page_sql_format_group_formatter, 1, GridData.FILL_BOTH, 0);
    ((GridData) formatterGroup.getLayoutData()).horizontalSpan = 2;
    {
        Composite formatterPanel = UIUtils.createPlaceholder(formatterGroup, 2);
        formatterPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        formatterSelector = UIUtils.createLabelCombo(formatterPanel, CoreMessages.pref_page_sql_format_label_formatter, SWT.DROP_DOWN | SWT.READ_ONLY);
        formatters = SQLFormatterConfigurationRegistry.getInstance().getFormatters();
        for (SQLFormatterDescriptor formatterDesc : formatters) {
            formatterSelector.add(DBPIdentifierCase.capitalizeCaseName(formatterDesc.getLabel()));
        }
        formatterSelector.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                showFormatterSettings();
                performApply();
            }
        });
        formatterSelector.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    }
    // Default formatter settings
    {
        defaultGroup = UIUtils.createPlaceholder(formatterGroup, 2, 0);
        defaultGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        keywordCaseCombo = UIUtils.createLabelCombo(defaultGroup, CoreMessages.pref_page_sql_format_label_keyword_case, SWT.DROP_DOWN | SWT.READ_ONLY);
        keywordCaseCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        keywordCaseCombo.add("Database");
        for (DBPIdentifierCase c : DBPIdentifierCase.values()) {
            keywordCaseCombo.add(DBPIdentifierCase.capitalizeCaseName(c.name()));
        }
        keywordCaseCombo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                performApply();
            }
        });
    }
    // External formatter
    {
        externalGroup = UIUtils.createPlaceholder(formatterGroup, 2, 5);
        externalGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING));
        externalCmdText = UIUtils.createLabelText(externalGroup, CoreMessages.pref_page_sql_format_label_external_command_line, "");
        externalCmdText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        UIUtils.installContentProposal(externalCmdText, new TextContentAdapter(), new SimpleContentProposalProvider(new String[] { GeneralUtils.variablePattern(SQLFormatterExternal.VAR_FILE) }));
        UIUtils.setContentProposalToolTip(externalCmdText, CoreMessages.pref_page_sql_format_label_external_set_content_tool_tip, SQLFormatterExternal.VAR_FILE);
        externalUseFile = UIUtils.createLabelCheckbox(externalGroup, CoreMessages.pref_page_sql_format_label_external_use_temp_file, CoreMessages.pref_page_sql_format_label_external_use_temp_file_tip + GeneralUtils.variablePattern(SQLFormatterExternal.VAR_FILE), false);
        externalTimeout = UIUtils.createLabelSpinner(externalGroup, CoreMessages.pref_page_sql_format_label_external_exec_timeout, CoreMessages.pref_page_sql_format_label_external_exec_timeout_tip, 100, 100, 10000);
    }
    {
        // SQL preview
        Composite previewGroup = new Composite(formatterGroup, SWT.BORDER);
        previewGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
        previewGroup.setLayout(new FillLayout());
        sqlViewer = new SQLEditorBase() {

            @Override
            public DBCExecutionContext getExecutionContext() {
                final DBPDataSourceContainer container = getDataSourceContainer();
                if (container != null) {
                    final DBPDataSource dataSource = container.getDataSource();
                    if (dataSource != null) {
                        return dataSource.getDefaultContext(false);
                    }
                }
                return null;
            }
        };
        try {
            try (final InputStream sqlStream = getClass().getResourceAsStream(FORMAT_FILE_NAME)) {
                final String sqlText = ContentUtils.readToString(sqlStream, GeneralUtils.DEFAULT_ENCODING);
                IEditorSite subSite = new SubEditorSite(DBeaverUI.getActiveWorkbenchWindow().getActivePage().getActivePart().getSite());
                StringEditorInput sqlInput = new StringEditorInput("SQL preview", sqlText, true, GeneralUtils.getDefaultFileEncoding());
                sqlViewer.init(subSite, sqlInput);
            }
        } catch (Exception e) {
            log.error(e);
        }
        sqlViewer.createPartControl(previewGroup);
        Object text = sqlViewer.getAdapter(Control.class);
        if (text instanceof StyledText) {
            ((StyledText) text).setWordWrap(true);
        }
        sqlViewer.reloadSyntaxRules();
        previewGroup.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                sqlViewer.dispose();
            }
        });
    }
    return composite;
}
Also used : SQLFormatterDescriptor(org.jkiss.dbeaver.registry.sql.SQLFormatterDescriptor) DisposeListener(org.eclipse.swt.events.DisposeListener) StyledText(org.eclipse.swt.custom.StyledText) InputStream(java.io.InputStream) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) TextContentAdapter(org.eclipse.jface.fieldassist.TextContentAdapter) DisposeEvent(org.eclipse.swt.events.DisposeEvent) StringEditorInput(org.jkiss.dbeaver.ui.editors.StringEditorInput) SubEditorSite(org.jkiss.dbeaver.ui.editors.SubEditorSite) SimpleContentProposalProvider(org.eclipse.jface.fieldassist.SimpleContentProposalProvider) SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPIdentifierCase(org.jkiss.dbeaver.model.DBPIdentifierCase) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IEditorSite(org.eclipse.ui.IEditorSite)

Example 4 with SubEditorSite

use of org.jkiss.dbeaver.ui.editors.SubEditorSite in project dbeaver by serge-rider.

the class AbstractTextPanelEditor method createControl.

@Override
public StyledText createControl(IValueController valueController) {
    this.valueController = valueController;
    this.subSite = new SubEditorSite(valueController.getValueSite());
    editor = createEditorParty(valueController);
    try {
        editor.init(subSite, StringEditorInput.EMPTY_INPUT);
    } catch (PartInitException e) {
        valueController.showMessage(e.getMessage(), DBPMessageType.ERROR);
        return new StyledText(valueController.getEditPlaceholder(), SWT.NONE);
    }
    editor.createPartControl(valueController.getEditPlaceholder());
    StyledText editorControl = editor.getEditorControl();
    assert editorControl != null;
    initEditorSettings(editorControl);
    editorControl.addDisposeListener(e -> editor.releaseEditorInput());
    editor.addContextMenuContributor(manager -> contributeTextEditorActions(manager, editorControl));
    return editorControl;
}
Also used : SubEditorSite(org.jkiss.dbeaver.ui.editors.SubEditorSite) StyledText(org.eclipse.swt.custom.StyledText) PartInitException(org.eclipse.ui.PartInitException)

Example 5 with SubEditorSite

use of org.jkiss.dbeaver.ui.editors.SubEditorSite in project dbeaver by dbeaver.

the class XMLPanelEditor method createControl.

@Override
public StyledText createControl(IValueController valueController) {
    this.valueController = valueController;
    this.subSite = new SubEditorSite(valueController.getValueSite());
    editor = new XMLEditor();
    try {
        editor.init(subSite, StringEditorInput.EMPTY_INPUT);
    } catch (PartInitException e) {
        valueController.showMessage(e.getMessage(), DBPMessageType.ERROR);
        return new StyledText(valueController.getEditPlaceholder(), SWT.NONE);
    }
    editor.createPartControl(valueController.getEditPlaceholder());
    // TODO: move to base class. Refactor resource release
    StyledText editorControl = editor.getEditorControl();
    assert editorControl != null;
    initEditorSettings(editorControl);
    editorControl.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            editor.releaseEditorInput();
        }
    });
    return editorControl;
}
Also used : SubEditorSite(org.jkiss.dbeaver.ui.editors.SubEditorSite) DisposeListener(org.eclipse.swt.events.DisposeListener) StyledText(org.eclipse.swt.custom.StyledText) PartInitException(org.eclipse.ui.PartInitException) DisposeEvent(org.eclipse.swt.events.DisposeEvent) XMLEditor(org.jkiss.dbeaver.ui.editors.xml.XMLEditor)

Aggregations

SubEditorSite (org.jkiss.dbeaver.ui.editors.SubEditorSite)10 StyledText (org.eclipse.swt.custom.StyledText)8 PartInitException (org.eclipse.ui.PartInitException)6 StringEditorInput (org.jkiss.dbeaver.ui.editors.StringEditorInput)6 InputStream (java.io.InputStream)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 FillLayout (org.eclipse.swt.layout.FillLayout)4 GridData (org.eclipse.swt.layout.GridData)4 Composite (org.eclipse.swt.widgets.Composite)4 IEditorSite (org.eclipse.ui.IEditorSite)4 DBException (org.jkiss.dbeaver.DBException)4 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)4 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)4 DBPIdentifierCase (org.jkiss.dbeaver.model.DBPIdentifierCase)4 SQLEditorBase (org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase)4 StandardCharsets (java.nio.charset.StandardCharsets)2 Comparator (java.util.Comparator)2 List (java.util.List)2 Locale (java.util.Locale)2