Search in sources :

Example 1 with SQLTokenizedFormatterConfigurationPage

use of org.jkiss.dbeaver.ui.editors.sql.preferences.format.tokenized.SQLTokenizedFormatterConfigurationPage in project dbeaver by serge-rider.

the class PrefPageSQLFormat method showFormatterSettings.

private void showFormatterSettings() {
    if (curConfigurator != null) {
        curConfigurator.saveSettings(getTargetPreferenceStore());
    }
    UIUtils.disposeChildControls(formatterConfigPlaceholder);
    SQLFormatterDescriptor selFormatter = formatters.get(formatterSelector.getSelectionIndex());
    try {
        SQLFormatter sqlFormatter = selFormatter.createFormatter();
        // FIXME: for now we support only predefined list of formatters
        if (sqlFormatter instanceof SQLFormatterTokenized) {
            curConfigurator = new SQLTokenizedFormatterConfigurationPage();
        } else if (sqlFormatter instanceof SQLFormatterExternal) {
            curConfigurator = new SQLExternalFormatterConfigurationPage();
        } else {
            curConfigurator = GeneralUtils.adapt(sqlFormatter, SQLFormatterConfigurator.class);
        }
        if (curConfigurator instanceof IDialogPage) {
            curConfigurator.configure(selFormatter, () -> {
                curConfigurator.saveSettings(getTargetPreferenceStore());
                formatSQL();
            });
            ((IDialogPage) curConfigurator).createControl(formatterConfigPlaceholder);
            curConfigurator.loadSettings(getTargetPreferenceStore());
        }
    } catch (DBException e) {
        log.error("Error creating formatter configurator", e);
        setMessage(CommonUtils.toString(e.getMessage()), SWT.ICON_ERROR);
        return;
    }
    ((Composite) getControl()).layout(true, true);
    if (isDataSourcePreferencePage()) {
        enablePreferenceContent(useDataSourceSettings());
    }
}
Also used : SQLFormatterDescriptor(org.jkiss.dbeaver.model.sql.registry.SQLFormatterDescriptor) DBException(org.jkiss.dbeaver.DBException) SQLFormatter(org.jkiss.dbeaver.model.sql.format.SQLFormatter) SQLFormatterTokenized(org.jkiss.dbeaver.model.sql.format.tokenized.SQLFormatterTokenized) Composite(org.eclipse.swt.widgets.Composite) SQLFormatterExternal(org.jkiss.dbeaver.model.sql.format.external.SQLFormatterExternal) SQLExternalFormatterConfigurationPage(org.jkiss.dbeaver.ui.editors.sql.preferences.format.SQLExternalFormatterConfigurationPage) IDialogPage(org.eclipse.jface.dialogs.IDialogPage) SQLTokenizedFormatterConfigurationPage(org.jkiss.dbeaver.ui.editors.sql.preferences.format.tokenized.SQLTokenizedFormatterConfigurationPage)

Example 2 with SQLTokenizedFormatterConfigurationPage

use of org.jkiss.dbeaver.ui.editors.sql.preferences.format.tokenized.SQLTokenizedFormatterConfigurationPage in project dbeaver by dbeaver.

the class PrefPageSQLFormat method showFormatterSettings.

private void showFormatterSettings() {
    if (curConfigurator != null) {
        curConfigurator.saveSettings(getTargetPreferenceStore());
    }
    UIUtils.disposeChildControls(formatterConfigPlaceholder);
    SQLFormatterDescriptor selFormatter = formatters.get(formatterSelector.getSelectionIndex());
    try {
        SQLFormatter sqlFormatter = selFormatter.createFormatter();
        // FIXME: for now we support only predefined list of formatters
        if (sqlFormatter instanceof SQLFormatterTokenized) {
            curConfigurator = new SQLTokenizedFormatterConfigurationPage();
        } else if (sqlFormatter instanceof SQLFormatterExternal) {
            curConfigurator = new SQLExternalFormatterConfigurationPage();
        } else {
            curConfigurator = GeneralUtils.adapt(sqlFormatter, SQLFormatterConfigurator.class);
        }
        if (curConfigurator instanceof IDialogPage) {
            curConfigurator.configure(selFormatter, () -> {
                curConfigurator.saveSettings(getTargetPreferenceStore());
                formatSQL();
            });
            ((IDialogPage) curConfigurator).createControl(formatterConfigPlaceholder);
            curConfigurator.loadSettings(getTargetPreferenceStore());
        }
    } catch (DBException e) {
        log.error("Error creating formatter configurator", e);
        setMessage(CommonUtils.toString(e.getMessage()), SWT.ICON_ERROR);
        return;
    }
    ((Composite) getControl()).layout(true, true);
    if (isDataSourcePreferencePage()) {
        enablePreferenceContent(useDataSourceSettings());
    }
}
Also used : SQLFormatterDescriptor(org.jkiss.dbeaver.model.sql.registry.SQLFormatterDescriptor) DBException(org.jkiss.dbeaver.DBException) SQLFormatter(org.jkiss.dbeaver.model.sql.format.SQLFormatter) SQLFormatterTokenized(org.jkiss.dbeaver.model.sql.format.tokenized.SQLFormatterTokenized) Composite(org.eclipse.swt.widgets.Composite) SQLFormatterExternal(org.jkiss.dbeaver.model.sql.format.external.SQLFormatterExternal) SQLExternalFormatterConfigurationPage(org.jkiss.dbeaver.ui.editors.sql.preferences.format.SQLExternalFormatterConfigurationPage) IDialogPage(org.eclipse.jface.dialogs.IDialogPage) SQLTokenizedFormatterConfigurationPage(org.jkiss.dbeaver.ui.editors.sql.preferences.format.tokenized.SQLTokenizedFormatterConfigurationPage)

Aggregations

IDialogPage (org.eclipse.jface.dialogs.IDialogPage)2 Composite (org.eclipse.swt.widgets.Composite)2 DBException (org.jkiss.dbeaver.DBException)2 SQLFormatter (org.jkiss.dbeaver.model.sql.format.SQLFormatter)2 SQLFormatterExternal (org.jkiss.dbeaver.model.sql.format.external.SQLFormatterExternal)2 SQLFormatterTokenized (org.jkiss.dbeaver.model.sql.format.tokenized.SQLFormatterTokenized)2 SQLFormatterDescriptor (org.jkiss.dbeaver.model.sql.registry.SQLFormatterDescriptor)2 SQLExternalFormatterConfigurationPage (org.jkiss.dbeaver.ui.editors.sql.preferences.format.SQLExternalFormatterConfigurationPage)2 SQLTokenizedFormatterConfigurationPage (org.jkiss.dbeaver.ui.editors.sql.preferences.format.tokenized.SQLTokenizedFormatterConfigurationPage)2