use of org.jkiss.dbeaver.ui.editors.StringEditorInput in project dbeaver by serge-rider.
the class ResultSetFilterPanel method createObjectPanel.
@NotNull
private Control createObjectPanel(Shell popup) throws PartInitException {
Composite panel = new Composite(popup, SWT.NONE);
GridLayout gl = new GridLayout(2, false);
// gl.marginWidth = 0;
gl.marginHeight = 0;
// gl.horizontalSpacing = 0;
panel.setLayout(gl);
Label iconLabel = new Label(panel, SWT.NONE);
DBPImage activeObjectImage = getActiveObjectImage();
if (activeObjectImage != null) {
iconLabel.setImage(DBeaverIcons.getImage(activeObjectImage));
}
iconLabel.setToolTipText("Click to open query in editor");
iconLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
iconLabel.setCursor(getDisplay().getSystemCursor(SWT.CURSOR_HAND));
iconLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
openEditorForActiveQuery();
}
});
Composite editorPH = new Composite(panel, SWT.NONE);
editorPH.setLayoutData(new GridData(GridData.FILL_BOTH));
editorPH.setLayout(new FillLayout());
final SQLEditorBase editor = new SQLEditorBase() {
@Nullable
@Override
public DBCExecutionContext getExecutionContext() {
return viewer.getExecutionContext();
}
@Override
public void createPartControl(Composite parent) {
super.createPartControl(parent);
getAction(ITextEditorActionConstants.CONTEXT_PREFERENCES).setEnabled(false);
}
};
editor.setHasVerticalRuler(false);
editor.init(new SubEditorSite(viewer.getSite()), new StringEditorInput(DEFAULT_QUERY_TEXT, getActiveQueryText(), true, GeneralUtils.getDefaultFileEncoding()));
editor.createPartControl(editorPH);
editor.reloadSyntaxRules();
StyledText textWidget = editor.getTextViewer().getTextWidget();
//textWidget.setAlwaysShowScrollBars(false);
panel.setBackground(textWidget.getBackground());
panel.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
editor.dispose();
}
});
return textWidget;
}
use of org.jkiss.dbeaver.ui.editors.StringEditorInput 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;
}
use of org.jkiss.dbeaver.ui.editors.StringEditorInput in project dbeaver by serge-rider.
the class PrefPageSQLFormat method formatSQL.
private void formatSQL() {
try {
try (final InputStream sqlStream = getClass().getResourceAsStream(FORMAT_FILE_NAME)) {
final String sqlText = ContentUtils.readToString(sqlStream, GeneralUtils.DEFAULT_ENCODING);
sqlViewer.setInput(new StringEditorInput("SQL preview", sqlText, true, GeneralUtils.getDefaultFileEncoding()));
}
} catch (Exception e) {
log.error(e);
}
sqlViewer.getTextViewer().doOperation(ISourceViewer.FORMAT);
sqlViewer.reloadSyntaxRules();
}
use of org.jkiss.dbeaver.ui.editors.StringEditorInput in project dbeaver by serge-rider.
the class SessionManagerViewer method updateSQL.
protected void updateSQL() {
try {
String text = curSession == null ? "" : CommonUtils.notEmpty(curSession.getActiveQuery());
StringEditorInput sqlInput = new StringEditorInput(sessionTable.getShell().getText(), text, true, GeneralUtils.getDefaultFileEncoding());
sqlViewer.init(subSite, sqlInput);
if (sqlViewer.getTextViewer() != null) {
sqlViewer.reloadSyntaxRules();
}
} catch (PartInitException e) {
UIUtils.showErrorDialog(sessionTable.getShell(), sessionTable.getShell().getText(), null, e);
}
}
use of org.jkiss.dbeaver.ui.editors.StringEditorInput in project dbeaver by serge-rider.
the class SQLEditor method doSetInput.
@Override
protected void doSetInput(IEditorInput editorInput) throws CoreException {
// Check for file existence
try {
if (editorInput instanceof IFileEditorInput) {
final IFile file = ((IFileEditorInput) editorInput).getFile();
if (!file.exists()) {
file.create(new ByteArrayInputStream(new byte[] {}), true, new NullProgressMonitor());
}
}
} catch (Exception e) {
log.error("Error checking SQL file", e);
}
try {
super.doSetInput(editorInput);
} catch (Throwable e) {
// Something bas may happend. E.g. OutOfMemory error in case of rtoo big input file.
StringWriter out = new StringWriter();
e.printStackTrace(new PrintWriter(out, true));
editorInput = new StringEditorInput("Error", CommonUtils.truncateString(out.toString(), 10000), true, GeneralUtils.UTF8_ENCODING);
doSetInput(editorInput);
log.error("Error loading input SQL file", e);
}
syntaxLoaded = false;
setDataSourceContainer(EditorUtils.getInputDataSource(editorInput));
setPartName(getEditorName());
if (isNonPersistentEditor()) {
setTitleImage(DBeaverIcons.getImage(UIIcon.SQL_CONSOLE));
}
editorImage = getTitleImage();
}
Aggregations