use of org.eclipse.ui.IEditorSite 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.eclipse.ui.IEditorSite in project sling by apache.
the class StatusLineUtils method getStatusLineManager.
private static IStatusLineManager getStatusLineManager() {
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow == null) {
return null;
}
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
if (activePage == null) {
return null;
}
IEditorPart activeEditor = activePage.getActiveEditor();
if (activeEditor != null) {
return activeEditor.getEditorSite().getActionBars().getStatusLineManager();
}
IViewReference[] viewRefs = activePage.getViewReferences();
if (viewRefs != null) {
for (IViewReference aViewRef : viewRefs) {
IViewPart view = aViewRef.getView(false);
if (view != null) {
return view.getViewSite().getActionBars().getStatusLineManager();
}
}
}
IEditorReference[] editorRefs = activePage.getEditorReferences();
if (editorRefs != null) {
for (IEditorReference anEditorRef : editorRefs) {
IEditorPart editor = anEditorRef.getEditor(false);
if (editor != null) {
return editor.getEditorSite().getActionBars().getStatusLineManager();
}
}
}
IWorkbenchPart activePart = activePage.getActivePart();
if (activePart == null) {
return null;
}
IWorkbenchPartSite site = activePart.getSite();
if (site instanceof IEditorSite) {
IEditorSite editorSite = (IEditorSite) site;
return editorSite.getActionBars().getStatusLineManager();
} else if (site instanceof IViewSite) {
IViewSite viewSite = (IViewSite) site;
return viewSite.getActionBars().getStatusLineManager();
} else {
return null;
}
}
use of org.eclipse.ui.IEditorSite in project knime-core by knime.
the class WorkflowEditor method createGraphicalViewer.
/**
* Creates the graphical viewer that is hosted in this editor and hooks
* keyhandler and edit domain.
*
* @see org.eclipse.gef.ui.parts.GraphicalEditor
* #createGraphicalViewer(org.eclipse.swt.widgets.Composite)
* @param parent The parent
*/
@Override
protected void createGraphicalViewer(final Composite parent) {
IEditorSite editorSite = getEditorSite();
GraphicalViewer viewer = new WorkflowGraphicalViewerCreator(editorSite, this.getActionRegistry()).createViewer(parent);
// Add a listener to the static node provider
NodeProvider.INSTANCE.addListener(this);
// Configure the key handler
GraphicalViewerKeyHandler keyHandler = new GraphicalViewerKeyHandler(viewer);
KeyHandler parentKeyHandler = keyHandler.setParent(getCommonKeyHandler());
viewer.setKeyHandler(parentKeyHandler);
// hook the viewer into the EditDomain
getEditDomain().addViewer(viewer);
// activate the viewer as selection provider for Eclipse
getSite().setSelectionProvider(viewer);
// remember this viewer
m_graphicalViewer = viewer;
// load properties like grid- or node-connections settings (e.g. width, curved)
// needs to be called before getGraphicalViewer().setContents(m_manager), since
// the node connections are repainted on that setContents-call and the properties need
// to be set by then
loadProperties();
// We already have the model - set it into the viewer
getGraphicalViewer().setContents(m_manager);
// add Help context
WorkbenchHelpSystem.getInstance().setHelp(m_graphicalViewer.getControl(), "org.knime.workbench.help.flow_editor_context");
updateEditorBackgroundColor();
updateJobManagerDisplay();
updateTempRemoteWorkflowMessage();
RootEditPart rep = getGraphicalViewer().getRootEditPart();
((WorkflowRootEditPart) rep.getChildren().get(0)).createToolTipHelper(getSite().getShell());
ZoomManager zm = this.getZoomManager();
zm.setZoomLevels(ZOOM_LEVELS);
m_zoomWheelListener = new ZoomWheelListener(zm, (FigureCanvas) getViewer().getControl());
}
use of org.eclipse.ui.IEditorSite 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;
}
use of org.eclipse.ui.IEditorSite in project liferay-ide by liferay.
the class CodePropertyEditorRenderer method createContents.
@Override
protected void createContents(Composite parent) {
PropertyEditorPart part = getPart();
Composite scriptEditorParent = createMainComposite(parent, new CreateMainCompositeDelegate(part) {
@Override
public boolean canScaleVertically() {
return true;
}
});
context.adapt(scriptEditorParent);
int textFieldParentColumns = 1;
SapphireToolBarActionPresentation toolBarActionsPresentation = new SapphireToolBarActionPresentation(getActionPresentationManager());
boolean actionsToolBarNeeded = toolBarActionsPresentation.hasActions();
if (actionsToolBarNeeded || true)
textFieldParentColumns++;
scriptEditorParent.setLayout(glayout(textFieldParentColumns, 0, 0, 0, 0));
Composite nestedComposite = new Composite(scriptEditorParent, SWT.NONE);
nestedComposite.setLayoutData(gdfill());
nestedComposite.setLayout(glspacing(glayout(2, 0, 0), 2));
this.context.adapt(nestedComposite);
PropertyEditorAssistDecorator decorator = createDecorator(nestedComposite);
decorator.control().setLayoutData(gdvalign(gd(), SWT.TOP));
decorator.addEditorControl(nestedComposite);
/*
* scriptEditorParent.setLayout( new FillLayout( SWT.HORIZONTAL ) );
* scriptEditorParent.setLayoutData( gdhhint( gdfill(), 300 ) );
*/
PropertyEditorInput editorInput = new PropertyEditorInput(part.getLocalModelElement(), (ValueProperty) part.getProperty());
try {
ScriptLanguageType scriptLang = context.getPart().getLocalModelElement().nearest(IScriptable.class).getScriptLanguage().getContent(false);
String fileName = scriptLang.getClass().getField(scriptLang.toString()).getAnnotation(DefaultValue.class).text();
IContentDescription contentDescription = ContentTypeManager.getInstance().getDescriptionFor(editorInput.getStorage().getContents(), fileName, IContentDescription.ALL);
EditorDescriptor defaultEditor = (EditorDescriptor) PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(editorInput.getName(), contentDescription.getContentType());
_textEditor = (ITextEditor) defaultEditor.createEditor();
} catch (Exception e1) {
}
IEditorReference ref = new ScriptEditorReference(_textEditor, editorInput);
IEditorSite site = new ScriptEditorSite(ref, _textEditor, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage());
try {
_textEditor.init(site, editorInput);
_textEditor.getDocumentProvider().getDocument(editorInput).addDocumentListener(new IDocumentListener() {
public void documentAboutToBeChanged(DocumentEvent event) {
}
public void documentChanged(DocumentEvent event) {
String content = event.getDocument().get();
part.getLocalModelElement().write(((ValueProperty) part.getProperty()), content);
}
});
ModelPropertyListener modelListener = new ModelPropertyListener() {
@Override
public void handlePropertyChangedEvent(ModelPropertyChangeEvent event) {
CodePropertyEditorRenderer.this.textEditor.getDocumentProvider().getDocument(editorInput).set(part.getLocalModelElement().read(getProperty()).getText());
}
};
part.getLocalModelElement().addListener(modelListener, part.getProperty().getName());
} catch (PartInitException pie) {
pie.printStackTrace();
}
Control[] prevChildren = scriptEditorParent.getChildren();
// _textEditor.createPartControl( scriptEditorParent );
new Label(scriptEditorParent, SWT.NONE);
Control[] newChildren = scriptEditorParent.getChildren();
decorator.addEditorControl(newChildren[prevChildren.length], true);
if (actionsToolBarNeeded) {
ToolBar toolbar = new ToolBar(scriptEditorParent, SWT.FLAT | SWT.HORIZONTAL);
toolbar.setLayoutData(gdvfill());
toolBarActionsPresentation.setToolBar(toolbar);
toolBarActionsPresentation.render();
context.adapt(toolbar);
decorator.addEditorControl(toolbar);
// relatedControls.add( toolbar );
}
}
Aggregations