use of org.eclipse.swt.events.DisposeListener in project dbeaver by serge-rider.
the class HexManager method createEditorPart.
/**
* Creates editor part of parent application. Can only be called once per Manager object.
*
* @param parent composite where the part will be drawn.
* @throws IllegalStateException when editor part exists already (method called twice or more)
* @throws NullPointerException if textsParent is null
*/
public Composite createEditorPart(Composite parent, int style) {
if (hexEditControl != null)
throw new IllegalStateException("Editor part exists already");
if (parent == null)
throw new NullPointerException("Null parent");
textsParent = parent;
hexEditControl = new HexEditControl(textsParent, style);
hexEditControl.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (fontText != null && !fontText.isDisposed())
fontText.dispose();
}
});
if (fontData != null) {
fontText = new Font(Display.getCurrent(), fontData);
hexEditControl.setFont(fontText);
}
//hexEditControl.addLongSelectionListener(new ControlSelectionAdapter(ControlSelectionAdapter.UPDATE_POSITION_TEXT));
hexEditControl.addListener(SWT.Modify, new Listener() {
@Override
public void handleEvent(Event event) {
if (statusLine != null)
statusLine.updateInsertModeText(hexEditControl == null || !hexEditControl.isOverwriteMode());
}
});
if (listOfStatusChangedListeners != null) {
for (Listener listOfStatusChangedListener : listOfStatusChangedListeners) {
hexEditControl.addListener(SWT.Modify, listOfStatusChangedListener);
}
listOfStatusChangedListeners = null;
}
if (listOfLongListeners != null) {
for (SelectionListener listOfLongListener : listOfLongListeners) {
hexEditControl.addLongSelectionListener(listOfLongListener);
}
listOfLongListeners = null;
}
{
// Context menu
MenuManager menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
menuManager.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
if (menuListener != null) {
menuListener.menuAboutToShow(manager);
}
}
});
Menu contextMenu = menuManager.createContextMenu(hexEditControl.getHexText());
hexEditControl.getHexText().setMenu(contextMenu);
contextMenu = menuManager.createContextMenu(hexEditControl.getPreviewText());
hexEditControl.getPreviewText().setMenu(contextMenu);
//getSite().registerContextMenu(menuManager, this);
}
return hexEditControl;
}
use of org.eclipse.swt.events.DisposeListener in project dbeaver by serge-rider.
the class MetaDataPanel method createContents.
@Override
public Control createContents(final IResultSetPresentation presentation, Composite parent) {
this.presentation = presentation;
this.colorDisabled = presentation.getControl().getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
this.attributeList = new MetaDataTable(parent);
this.attributeList.setFitWidth(false);
this.attributeList.getItemsViewer().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
DBDAttributeBinding attr = getSelectedAttribute();
if (attr != null && !updateSelection) {
if (isAttributeVisible(attr)) {
updateSelection = true;
try {
presentation.setCurrentAttribute(attr);
} finally {
updateSelection = false;
}
}
}
}
});
if (this.presentation instanceof ISelectionProvider) {
final ISelectionChangedListener listener = new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (!updateSelection && MetaDataPanel.this.presentation.getController().getVisiblePanel() == MetaDataPanel.this) {
DBDAttributeBinding attr = presentation.getCurrentAttribute();
if (attr != null && attr != getSelectedAttribute()) {
updateSelection = true;
try {
attributeList.getItemsViewer().setSelection(new StructuredSelection(attr));
} finally {
updateSelection = false;
}
}
}
}
};
((ISelectionProvider) this.presentation).addSelectionChangedListener(listener);
attributeList.getControl().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
((ISelectionProvider) presentation).removeSelectionChangedListener(listener);
}
});
}
return this.attributeList;
}
use of org.eclipse.swt.events.DisposeListener in project dbeaver by serge-rider.
the class ViewValuePanel method createContents.
@Override
public Control createContents(IResultSetPresentation presentation, Composite parent) {
this.presentation = presentation;
viewPlaceholder = new Composite(parent, SWT.NONE);
viewPlaceholder.setLayout(new FillLayout());
viewPlaceholder.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
if (viewPlaceholder.getChildren().length == 0) {
String hidePanelCmd = ActionUtils.findCommandDescription(ResultSetCommandHandler.CMD_TOGGLE_PANELS, ViewValuePanel.this.presentation.getController().getSite(), true);
UIUtils.drawMessageOverControl(viewPlaceholder, e, "Select a cell to view/edit value", 0);
UIUtils.drawMessageOverControl(viewPlaceholder, e, "Press " + hidePanelCmd + " to hide this panel", 20);
}
}
});
if (this.presentation instanceof ISelectionProvider) {
final ISelectionProvider selectionProvider = (ISelectionProvider) this.presentation;
final ISelectionChangedListener selectionListener = new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (ViewValuePanel.this.presentation.getController().getVisiblePanel() == ViewValuePanel.this) {
refreshValue(false);
}
}
};
selectionProvider.addSelectionChangedListener(selectionListener);
viewPlaceholder.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
selectionProvider.removeSelectionChangedListener(selectionListener);
}
});
}
return viewPlaceholder;
}
use of org.eclipse.swt.events.DisposeListener 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.swt.events.DisposeListener in project translationstudio8 by heartsome.
the class TermBaseSearchDialog method createHelpControl.
/**
* 添加帮助按钮 robert 2012-09-06
*/
@Override
protected Control createHelpControl(Composite parent) {
// ROBERTHELP 搜索术语
String language = CommonFunction.getSystemLanguage();
final String helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch05s04.html#search-terminology", language);
Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
((GridLayout) parent.getLayout()).numColumns++;
toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
toolBar.setCursor(cursor);
toolBar.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
cursor.dispose();
}
});
ToolItem helpItem = new ToolItem(toolBar, SWT.NONE);
helpItem.setImage(helpImage);
//$NON-NLS-1$
helpItem.setToolTipText(JFaceResources.getString("helpToolTip"));
helpItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
}
});
return toolBar;
}
Aggregations