use of org.jkiss.dbeaver.model.sql.format.SQLFormatter in project dbeaver by dbeaver.
the class SQLUtils method formatSQL.
public static String formatSQL(SQLDataSource dataSource, String query) {
SQLSyntaxManager syntaxManager = new SQLSyntaxManager();
syntaxManager.init(dataSource.getSQLDialect(), dataSource.getContainer().getPreferenceStore());
SQLFormatterConfiguration configuration = new SQLFormatterConfiguration(syntaxManager);
SQLFormatter formatter = dataSource.getDataSource().getContainer().getPlatform().getSQLFormatterRegistry().createFormatter(configuration);
if (formatter == null) {
return query;
}
return formatter.format(query, configuration);
}
use of org.jkiss.dbeaver.model.sql.format.SQLFormatter 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());
}
}
use of org.jkiss.dbeaver.model.sql.format.SQLFormatter in project dbeaver by dbeaver.
the class SQLFormatterConfigurationRegistry method createAndConfigureFormatter.
@Override
@Nullable
public SQLFormatter createAndConfigureFormatter(SQLFormatterConfiguration configuration) {
final String formatterId = configuration.getFormatterId();
SQLFormatterDescriptor formatterDesc = getFormatter(formatterId);
if (formatterDesc == null) {
log.error("Formatter '" + formatterId + "' not found");
return null;
}
try {
SQLFormatter formatter = formatterDesc.createFormatter();
SQLFormatterConfigurer configurer = formatterDesc.createConfigurer();
if (configurer != null) {
if (!configurer.configure(formatterDesc.getLabel(), formatter, configuration)) {
return null;
}
}
return formatter;
} catch (DBException e) {
log.error("Error creating and configuring formatter", e);
return null;
}
}
use of org.jkiss.dbeaver.model.sql.format.SQLFormatter in project dbeaver by dbeaver.
the class SQLFormattingStrategy method format.
@Override
public String format(String content, boolean isLineStart, String indentation, int[] positions) {
final String[] indentPrefixes = svConfig.getIndentPrefixes(sourceViewer, IDocument.DEFAULT_CONTENT_TYPE);
SQLFormatterConfiguration configuration = new SQLFormatterConfiguration(sqlSyntax);
configuration.setIndentString(indentPrefixes[0]);
SQLFormatter formatter = SQLFormatterConfigurationRegistry.getInstance().createFormatter(configuration);
if (formatter == null) {
return content;
}
return formatter.format(content, configuration);
}
use of org.jkiss.dbeaver.model.sql.format.SQLFormatter in project dbeaver by serge-rider.
the class SQLFormattingStrategy method format.
@Override
public String format(String content, boolean isLineStart, String indentation, int[] positions) {
final String[] indentPrefixes = svConfig.getIndentPrefixes(sourceViewer, IDocument.DEFAULT_CONTENT_TYPE);
SQLFormatterConfiguration configuration = new SQLFormatterConfiguration(svConfig.getSQLEditor().getDataSource(), sqlSyntax);
configuration.setIndentString(indentPrefixes[0]);
SQLFormatter formatter = SQLFormatterConfigurationRegistry.getInstance().createFormatter(configuration);
if (formatter == null) {
return content;
}
return formatter.format(content, configuration);
}
Aggregations