use of org.eclipse.swt.events.DisposeEvent in project eclipse.platform.text by eclipse.
the class LineNumberRulerColumn method createControl.
@Override
public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
fParentRuler = parentRuler;
fCachedTextViewer = parentRuler.getTextViewer();
fCachedTextWidget = fCachedTextViewer.getTextWidget();
// on word wrap toggle a "resized" ControlEvent is fired: suggest a redraw of the line ruler
fCachedTextWidget.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
if (fCachedTextWidget != null && fCachedTextWidget.getWordWrap()) {
postRedraw();
}
}
});
// track when StyledText is redrawn to check if some line height changed. In this case, the ruler must be redrawn
// to draw line number with well height.
VisibleLinesTracker.track(fCachedTextViewer, lineHeightChangeHandler);
fCanvas = new Canvas(parentControl, SWT.NO_FOCUS) {
@Override
public void addMouseListener(MouseListener listener) {
// see bug 40889, bug 230073 and AnnotationRulerColumn#isPropagatingMouseListener()
if (listener == fMouseHandler)
super.addMouseListener(listener);
else {
TypedListener typedListener = null;
if (listener != null)
typedListener = new TypedListener(listener);
addListener(SWT.MouseDoubleClick, typedListener);
}
}
};
fCanvas.setBackground(getBackground(fCanvas.getDisplay()));
fCanvas.setForeground(fForeground);
fCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent event) {
if (fCachedTextViewer != null)
doubleBufferPaint(event.gc);
}
});
fCanvas.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
handleDispose();
fCachedTextViewer = null;
fCachedTextWidget = null;
}
});
fMouseHandler = new MouseHandler();
fCanvas.addMouseListener(fMouseHandler);
fCanvas.addMouseMoveListener(fMouseHandler);
fCanvas.addMouseWheelListener(fMouseHandler);
if (fCachedTextViewer != null) {
VisibleLinesTracker.track(fCachedTextViewer, lineHeightChangeHandler);
fCachedTextViewer.addTextListener(fInternalListener);
if (fFont == null) {
if (fCachedTextWidget != null && !fCachedTextWidget.isDisposed())
fFont = fCachedTextWidget.getFont();
}
}
if (fFont != null)
fCanvas.setFont(fFont);
updateNumberOfDigits();
computeIndentations();
return fCanvas;
}
use of org.eclipse.swt.events.DisposeEvent in project knime-core by knime.
the class SubnodeLayoutJSONEditorPage method createControl.
/**
* {@inheritDoc}
*/
@Override
public void createControl(final Composite parent) {
TabFolder tabs = new TabFolder(parent, SWT.BORDER);
TabItem usageTab = new TabItem(tabs, SWT.NONE);
usageTab.setText("Node Usage");
m_nodeUsageComposite = new NodeUsageComposite(tabs, m_viewNodes, m_subNodeContainer);
usageTab.setControl(m_nodeUsageComposite);
usageTab.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(final DisposeEvent e) {
m_nodeUsageComposite = null;
}
});
TabItem basicTab = new TabItem(tabs, SWT.NONE);
basicTab.setText("Basic Layout");
basicTab.setControl(createBasicComposite(tabs));
TabItem jsonTab = new TabItem(tabs, SWT.NONE);
jsonTab.setText("Advanced Layout");
jsonTab.setControl(createJSONEditorComposite(tabs));
setControl(tabs);
}
use of org.eclipse.swt.events.DisposeEvent in project yamcs-studio by yamcs.
the class ContentProposalAdapter method initPopup.
/*
* Init & open the popup on asynchronous call.
*/
private void initPopup(ContentProposalList proposalList, boolean autoActivated) {
if (proposalList.fullLength() > 0) {
if (DEBUG) {
// $NON-NLS-1$
System.out.println("POPUP OPENED BY PRECEDING EVENT");
}
popup = new ContentProposalPopup(this, null, proposalList);
popup.open();
popup.getShell().addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
popup = null;
}
});
internalPopupOpened();
notifyPopupOpened();
} else if (!autoActivated) {
getControl().getDisplay().beep();
}
}
use of org.eclipse.swt.events.DisposeEvent in project dbeaver by dbeaver.
the class DataSourceManagementToolbar method createControl.
Control createControl(Composite parent) {
workbenchWindow.addPageListener(pageListener);
IWorkbenchPage activePage = workbenchWindow.getActivePage();
if (activePage != null) {
pageListener.pageOpened(activePage);
}
// Register as datasource listener in all datasources
// We need it because at this moment there could be come already loaded registries (on startup)
DataSourceProviderRegistry.getInstance().addDataSourceRegistryListener(DataSourceManagementToolbar.this);
for (DataSourceRegistry registry : DataSourceRegistry.getAllRegistries()) {
handleRegistryLoad(registry);
}
Composite comboGroup = new Composite(parent, SWT.NONE);
RowLayout layout = new RowLayout(SWT.HORIZONTAL);
layout.marginTop = 0;
layout.marginBottom = 0;
layout.marginWidth = 5;
layout.marginHeight = 0;
comboGroup.setLayout(layout);
final int fontHeight = UIUtils.getFontHeight(parent);
int comboWidth = fontHeight * 20;
connectionCombo = new CSmartSelector<DBPDataSourceContainer>(comboGroup, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER, new ConnectionLabelProvider()) {
@Override
protected void dropDown(boolean drop) {
if (!drop) {
return;
}
showConnectionSelector();
}
};
RowData rd = new RowData();
rd.width = comboWidth;
connectionCombo.setLayoutData(rd);
connectionCombo.setVisibleItemCount(15);
connectionCombo.setWidthHint(comboWidth);
connectionCombo.setToolTipText(CoreMessages.toolbar_datasource_selector_combo_datasource_tooltip);
connectionCombo.addItem(null);
connectionCombo.select(0);
comboWidth = fontHeight * 16;
databaseCombo = new CSmartSelector<DBNDatabaseNode>(comboGroup, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER, new DatabaseLabelProvider()) {
@Override
protected void dropDown(boolean drop) {
if (!drop) {
return;
}
showDatabaseSelector();
}
};
rd = new RowData();
rd.width = comboWidth;
databaseCombo.setLayoutData(rd);
databaseCombo.setVisibleItemCount(15);
databaseCombo.setWidthHint(comboWidth);
databaseCombo.setToolTipText(CoreMessages.toolbar_datasource_selector_combo_database_tooltip);
databaseCombo.addItem(null);
databaseCombo.select(0);
resultSetSize = new Text(comboGroup, SWT.BORDER);
resultSetSize.setTextLimit(10);
rd = new RowData();
rd.width = fontHeight * 4;
resultSetSize.setLayoutData(rd);
resultSetSize.setToolTipText(CoreMessages.toolbar_datasource_selector_resultset_segment_size);
final DBPDataSourceContainer dataSourceContainer = getDataSourceContainer();
if (dataSourceContainer != null) {
resultSetSize.setText(String.valueOf(dataSourceContainer.getPreferenceStore().getInt(DBeaverPreferences.RESULT_SET_MAX_ROWS)));
}
// resultSetSize.setDigits(7);
resultSetSize.addVerifyListener(UIUtils.getIntegerVerifyListener(Locale.getDefault()));
resultSetSize.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
}
@Override
public void focusLost(FocusEvent e) {
changeResultSetSize();
}
});
comboGroup.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
DataSourceManagementToolbar.this.dispose();
}
});
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
if (workbenchWindow != null && workbenchWindow.getActivePage() != null) {
setActivePart(workbenchWindow.getActivePage().getActivePart());
}
}
});
return comboGroup;
}
use of org.eclipse.swt.events.DisposeEvent 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;
}
Aggregations