use of org.eclipse.jface.resource.FontRegistry in project arduino-eclipse-plugin by Sloeber.
the class SerialMonitor method createPartControl.
/**
* This is a callback that will allow us to create the viewer and initialize
* it.
*/
@Override
public void createPartControl(Composite parent1) {
this.parent = parent1;
parent1.setLayout(new GridLayout());
GridLayout layout = new GridLayout(5, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
Composite top = new Composite(parent1, SWT.NONE);
top.setLayout(layout);
top.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
this.serialPorts = new ComboViewer(top, SWT.READ_ONLY | SWT.DROP_DOWN);
GridData minSizeGridData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
minSizeGridData.widthHint = 150;
this.serialPorts.getControl().setLayoutData(minSizeGridData);
this.serialPorts.setContentProvider(new IStructuredContentProvider() {
@Override
public void dispose() {
// no need to do something here
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// no need to do something here
}
@Override
public Object[] getElements(Object inputElement) {
@SuppressWarnings("unchecked") Map<Serial, SerialListener> items = (Map<Serial, SerialListener>) inputElement;
return items.keySet().toArray();
}
});
this.serialPorts.setLabelProvider(new LabelProvider());
this.serialPorts.setInput(this.serialConnections);
this.serialPorts.addSelectionChangedListener(new ComPortChanged(this));
this.sendString = new Text(top, SWT.SINGLE | SWT.BORDER);
this.sendString.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
this.lineTerminator = new ComboViewer(top, SWT.READ_ONLY | SWT.DROP_DOWN);
this.lineTerminator.setContentProvider(new ArrayContentProvider());
this.lineTerminator.setLabelProvider(new LabelProvider());
this.lineTerminator.setInput(SerialManager.listLineEndings());
this.lineTerminator.getCombo().select(MyPreferences.getLastUsedSerialLineEnd());
this.lineTerminator.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
MyPreferences.setLastUsedSerialLineEnd(SerialMonitor.this.lineTerminator.getCombo().getSelectionIndex());
}
});
this.send = new Button(top, SWT.BUTTON1);
this.send.setText(Messages.serialMonitorSend);
this.send.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
int index = SerialMonitor.this.lineTerminator.getCombo().getSelectionIndex();
GetSelectedSerial().write(SerialMonitor.this.sendString.getText(), SerialManager.getLineEnding(index));
// $NON-NLS-1$
SerialMonitor.this.sendString.setText("");
SerialMonitor.this.sendString.setFocus();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// nothing needs to be done here
}
});
this.send.setEnabled(false);
this.reset = new Button(top, SWT.BUTTON1);
this.reset.setText(Messages.serialMonitorReset);
this.reset.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
GetSelectedSerial().reset();
SerialMonitor.this.sendString.setFocus();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// nothing needs to be done here
}
});
this.reset.setEnabled(false);
// register the combo as a Selection Provider
getSite().setSelectionProvider(this.serialPorts);
this.monitorOutput = new StyledText(top, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
this.monitorOutput.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
this.monitorOutput.setEditable(false);
IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
ITheme currentTheme = themeManager.getCurrentTheme();
FontRegistry fontRegistry = currentTheme.getFontRegistry();
// $NON-NLS-1$
this.monitorOutput.setFont(fontRegistry.get("io.sloeber.serial.fontDefinition"));
this.monitorOutput.setText(Messages.serialMonitorNoInput);
this.parent.getShell().setDefaultButton(this.send);
makeActions();
contributeToActionBars();
}
use of org.eclipse.jface.resource.FontRegistry in project egit by eclipse.
the class DiffViewer method refreshDiffStyles.
private void refreshDiffStyles() {
ColorRegistry col = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
FontRegistry reg = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry();
// We do the foreground via syntax coloring and the background via a
// line background listener. If we did the background also via the
// TextAttributes, this would take precedence over the line background
// resulting in strange display if the current line is highlighted:
// that highlighting would appear only beyond the end of the actual
// text content (i.e., beyond the end-of-line), while actual text
// would still get the background from the attribute.
tokens.put(IDocument.DEFAULT_CONTENT_TYPE, new Token(null));
tokens.put(DiffDocument.HEADLINE_CONTENT_TYPE, new Token(new TextAttribute(col.get(THEME_DiffHeadlineForegroundColor), null, SWT.NORMAL, reg.get(THEME_DiffHeadlineFont))));
tokens.put(DiffDocument.HUNK_CONTENT_TYPE, new Token(new TextAttribute(col.get(THEME_DiffHunkForegroundColor))));
tokens.put(DiffDocument.ADDED_CONTENT_TYPE, new Token(new TextAttribute(col.get(THEME_DiffAddForegroundColor))));
tokens.put(DiffDocument.REMOVED_CONTENT_TYPE, new Token(new TextAttribute(col.get(THEME_DiffRemoveForegroundColor))));
backgroundColors.put(DiffDocument.HEADLINE_CONTENT_TYPE, col.get(THEME_DiffHeadlineBackgroundColor));
backgroundColors.put(DiffDocument.HUNK_CONTENT_TYPE, col.get(THEME_DiffHunkBackgroundColor));
backgroundColors.put(DiffDocument.ADDED_CONTENT_TYPE, col.get(THEME_DiffAddBackgroundColor));
backgroundColors.put(DiffDocument.REMOVED_CONTENT_TYPE, col.get(THEME_DiffRemoveBackgroundColor));
}
use of org.eclipse.jface.resource.FontRegistry in project dbeaver by dbeaver.
the class ResultSetHandlerMain method execute.
@Nullable
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
if (activePart == null) {
return null;
}
final ResultSetViewer rsv = (ResultSetViewer) getActiveResultSet(activePart);
if (rsv == null) {
return null;
}
Shell activeShell = HandlerUtil.getActiveShell(event);
String actionId = event.getCommand().getId();
IResultSetPresentation presentation = rsv.getActivePresentation();
DBPDataSource dataSource = rsv.getDataSource();
switch(actionId) {
case IWorkbenchCommandConstants.FILE_REFRESH:
rsv.refreshData(null);
break;
case CMD_TOGGLE_MODE:
rsv.toggleMode();
break;
case CMD_TOGGLE_PANELS:
rsv.showPanels(!rsv.isPanelsVisible(), true, true);
break;
case CMD_ACTIVATE_PANELS:
rsv.togglePanelsFocus();
break;
case CMD_TOGGLE_MAXIMIZE:
rsv.togglePanelsMaximize();
break;
case CMD_TOGGLE_LAYOUT:
rsv.toggleVerticalLayout();
break;
case CMD_FOCUS_FILTER:
rsv.switchFilterFocus();
break;
case CMD_SWITCH_PRESENTATION:
rsv.switchPresentation();
break;
case CMD_ROW_PREVIOUS:
case ITextEditorActionDefinitionIds.WORD_PREVIOUS:
presentation.scrollToRow(IResultSetPresentation.RowPosition.PREVIOUS);
break;
case CMD_ROW_NEXT:
case ITextEditorActionDefinitionIds.WORD_NEXT:
presentation.scrollToRow(IResultSetPresentation.RowPosition.NEXT);
break;
case CMD_ROW_FIRST:
case ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS:
presentation.scrollToRow(IResultSetPresentation.RowPosition.FIRST);
break;
case CMD_ROW_LAST:
case ITextEditorActionDefinitionIds.SELECT_WORD_NEXT:
presentation.scrollToRow(IResultSetPresentation.RowPosition.LAST);
break;
case CMD_FETCH_PAGE:
rsv.readNextSegment();
break;
case CMD_FETCH_ALL:
rsv.readAllData();
break;
case CMD_ROW_EDIT:
if (presentation instanceof IResultSetEditor) {
((IResultSetEditor) presentation).openValueEditor(false);
}
break;
case CMD_ROW_EDIT_INLINE:
if (presentation instanceof IResultSetEditor) {
((IResultSetEditor) presentation).openValueEditor(true);
}
break;
case CMD_ROW_ADD:
case CMD_ROW_COPY:
{
boolean copy = actionId.equals(CMD_ROW_COPY);
boolean shiftPressed = event.getTrigger() instanceof Event && ((((Event) event.getTrigger()).stateMask & SWT.SHIFT) == SWT.SHIFT);
boolean insertAfter = rsv.getPreferenceStore().getBoolean(ResultSetPreferences.RS_EDIT_NEW_ROWS_AFTER);
if (shiftPressed)
insertAfter = !insertAfter;
rsv.addNewRow(copy, insertAfter, true);
if (insertAfter) {
presentation.scrollToRow(IResultSetPresentation.RowPosition.NEXT);
}
break;
}
case CMD_ROW_DELETE:
case IWorkbenchCommandConstants.EDIT_DELETE:
rsv.deleteSelectedRows();
break;
case CMD_CELL_SET_NULL:
case CMD_CELL_SET_DEFAULT:
case CMD_CELL_RESET:
{
IResultSetSelection selection = rsv.getSelection();
for (Object cell : selection.toArray()) {
DBDAttributeBinding attr = selection.getElementAttribute(cell);
ResultSetRow row = selection.getElementRow(cell);
if (row != null && attr != null) {
ResultSetValueController valueController = new ResultSetValueController(rsv, attr, row, IValueController.EditType.NONE, null);
if (actionId.equals(CMD_CELL_SET_NULL)) {
valueController.updateValue(BaseValueManager.makeNullValue(valueController), false);
} else if (actionId.equals(CMD_CELL_SET_DEFAULT)) {
DBDValueHandler valueHandler = valueController.getValueHandler();
if (valueHandler instanceof DBDValueDefaultGenerator) {
try (DBCSession session = rsv.getExecutionContext().openSession(new VoidProgressMonitor(), DBCExecutionPurpose.UTIL, "Generate default value")) {
Object defValue = ((DBDValueDefaultGenerator) valueHandler).generateDefaultValue(session, valueController.getValueType());
valueController.updateValue(defValue, false);
}
}
} else {
rsv.getModel().resetCellValue(attr, row);
}
}
}
rsv.redrawData(false, false);
rsv.updatePanelsContent(false);
break;
}
case CMD_APPLY_CHANGES:
{
if (dataSource == null) {
return null;
}
ResultSetSaveSettings saveSettings = new ResultSetSaveSettings();
rsv.applyChanges(null, saveSettings);
break;
}
case CMD_REJECT_CHANGES:
rsv.rejectChanges();
break;
case CMD_GENERATE_SCRIPT:
{
ResultSetSaveReport saveReport = rsv.generateChangesReport();
if (saveReport == null) {
return null;
}
ResultSetSaveSettings saveSettings = showPreviewScript(rsv, saveReport);
if (saveSettings != null) {
rsv.applyChanges(null, saveSettings);
}
break;
}
case CMD_COPY_COLUMN_NAMES:
{
StringBuilder buffer = new StringBuilder();
String columnNames = event.getParameter("columns");
IResultSetSelection selection = rsv.getSelection();
List<DBDAttributeBinding> attrs = selection.isEmpty() ? rsv.getModel().getVisibleAttributes() : selection.getSelectedAttributes();
if (!CommonUtils.isEmpty(columnNames) && attrs.size() == 1) {
attrs = new ArrayList<>();
for (String colName : columnNames.split(",")) {
for (DBDAttributeBinding attr : rsv.getModel().getVisibleAttributes()) {
if (colName.equals(attr.getName())) {
attrs.add(attr);
}
}
}
}
ResultSetCopySettings settings = new ResultSetCopySettings();
if (attrs.size() > 1) {
ResultSetHandlerCopySpecial.CopyConfigDialog configDialog = new ResultSetHandlerCopySpecial.CopyConfigDialog(activeShell, "CopyGridNamesOptionsDialog");
if (configDialog.open() != IDialogConstants.OK_ID) {
return null;
}
settings = configDialog.copySettings;
}
for (DBDAttributeBinding attr : attrs) {
if (buffer.length() > 0) {
buffer.append(settings.getColumnDelimiter());
}
String colName = attr.getLabel();
if (CommonUtils.isEmpty(colName)) {
colName = attr.getName();
}
if (dataSource == null) {
buffer.append(colName);
} else {
buffer.append(DBUtils.getQuotedIdentifier(dataSource, colName));
}
}
ResultSetUtils.copyToClipboard(buffer.toString());
break;
}
case CMD_COPY_ROW_NAMES:
{
StringBuilder buffer = new StringBuilder();
List<ResultSetRow> selectedRows = rsv.getSelection().getSelectedRows();
ResultSetCopySettings settings = new ResultSetCopySettings();
if (selectedRows.size() > 1) {
ResultSetHandlerCopySpecial.CopyConfigDialog configDialog = new ResultSetHandlerCopySpecial.CopyConfigDialog(activeShell, "CopyGridNamesOptionsDialog");
if (configDialog.open() != IDialogConstants.OK_ID) {
return null;
}
settings = configDialog.copySettings;
}
for (ResultSetRow row : selectedRows) {
if (buffer.length() > 0) {
buffer.append(settings.getRowDelimiter());
}
buffer.append(row.getVisualNumber() + 1);
}
ResultSetUtils.copyToClipboard(buffer.toString());
break;
}
case IWorkbenchCommandConstants.EDIT_COPY:
ResultSetUtils.copyToClipboard(presentation.copySelection(new ResultSetCopySettings(false, false, false, true, false, null, null, null, DBDDisplayFormat.EDIT)));
break;
case IWorkbenchCommandConstants.EDIT_PASTE:
case IActionConstants.CMD_PASTE_SPECIAL:
if (presentation instanceof IResultSetEditor) {
((IResultSetEditor) presentation).pasteFromClipboard(actionId.equals(IActionConstants.CMD_PASTE_SPECIAL));
}
break;
case IWorkbenchCommandConstants.EDIT_CUT:
ResultSetUtils.copyToClipboard(presentation.copySelection(new ResultSetCopySettings(false, false, true, true, false, null, null, null, DBDDisplayFormat.EDIT)));
break;
case IWorkbenchCommandConstants.FILE_PRINT:
presentation.printResultSet();
break;
case ITextEditorActionDefinitionIds.SMART_ENTER:
if (presentation instanceof IResultSetEditor) {
((IResultSetEditor) presentation).openValueEditor(false);
}
break;
case IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE:
IAction action = TextEditorUtils.createFindReplaceAction(activeShell, rsv.getAdapter(IFindReplaceTarget.class));
action.run();
break;
case CMD_NAVIGATE_LINK:
{
final DBDAttributeBinding attr = rsv.getActivePresentation().getCurrentAttribute();
if (attr != null) {
new AbstractJob("Navigate association") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
rsv.navigateAssociation(monitor, rsv.getModel(), DBExecUtils.getAssociationByAttribute(attr), rsv.getSelection().getSelectedRows(), false);
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
}
break;
}
case CMD_COUNT:
rsv.updateRowCount();
break;
case IWorkbenchCommandConstants.NAVIGATE_BACKWARD_HISTORY:
{
final int hp = rsv.getHistoryPosition();
if (hp > 0) {
rsv.navigateHistory(hp - 1);
}
break;
}
case IWorkbenchCommandConstants.NAVIGATE_FORWARD_HISTORY:
{
final int hp = rsv.getHistoryPosition();
if (hp < rsv.getHistorySize() - 1) {
rsv.navigateHistory(hp + 1);
}
break;
}
case ITextEditorActionDefinitionIds.LINE_GOTO:
{
ResultSetRow currentRow = rsv.getCurrentRow();
final int rowCount = rsv.getModel().getRowCount();
if (rowCount <= 0) {
break;
}
GotoLineDialog d = new GotoLineDialog(activeShell, "Go to Row", "Enter row number (1.." + rowCount + ")", String.valueOf(currentRow == null ? 1 : currentRow.getVisualNumber() + 1), input -> {
try {
int i = Integer.parseInt(input);
if (i <= 0 || rowCount < i) {
return "Row number is out of range";
}
} catch (NumberFormatException x) {
return "Not a number";
}
return null;
});
if (d.open() == Window.OK) {
int line = Integer.parseInt(d.getValue());
rsv.setCurrentRow(rsv.getModel().getRow(line - 1));
rsv.getActivePresentation().scrollToRow(IResultSetPresentation.RowPosition.CURRENT);
}
break;
}
case CMD_FILTER_MENU:
{
rsv.showFiltersMenu();
break;
}
case CMD_FILTER_MENU_DISTINCT:
{
DBDAttributeBinding curAttribute = rsv.getActivePresentation().getCurrentAttribute();
if (curAttribute != null) {
rsv.showFiltersDistinctMenu(curAttribute, true);
}
break;
}
case CMD_FILTER_EDIT_SETTINGS:
{
rsv.showFilterSettingsDialog();
break;
}
case CMD_FILTER_SAVE_SETTING:
{
rsv.saveDataFilter();
break;
}
case CMD_FILTER_CLEAR_SETTING:
{
rsv.clearDataFilter(true);
}
case CMD_REFERENCES_MENU:
{
boolean shiftPressed = event.getTrigger() instanceof Event && ((((Event) event.getTrigger()).stateMask & SWT.SHIFT) == SWT.SHIFT);
rsv.showReferencesMenu(shiftPressed);
break;
}
case CMD_EXPORT:
{
List<Long> selectedRows = new ArrayList<>();
for (ResultSetRow selectedRow : rsv.getSelection().getSelectedRows()) {
selectedRows.add(Long.valueOf(selectedRow.getRowNumber()));
}
List<String> selectedAttributes = new ArrayList<>();
for (DBDAttributeBinding attributeBinding : rsv.getSelection().getSelectedAttributes()) {
selectedAttributes.add(attributeBinding.getName());
}
ResultSetDataContainerOptions options = new ResultSetDataContainerOptions();
options.setSelectedRows(selectedRows);
options.setSelectedColumns(selectedAttributes);
ResultSetDataContainer dataContainer = new ResultSetDataContainer(rsv, options);
DataTransferWizard.openWizard(HandlerUtil.getActiveWorkbenchWindow(event), Collections.singletonList(new DatabaseTransferProducer(dataContainer, rsv.getModel().getDataFilter())), null, rsv.getSelection());
break;
}
case CMD_ZOOM_IN:
case CMD_ZOOM_OUT:
{
FontRegistry fontRegistry = rsv.getSite().getWorkbenchWindow().getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry();
Font font = fontRegistry.get(ThemeConstants.FONT_SQL_RESULT_SET);
if (font != null) {
FontData[] fondData = font.getFontData();
if (fondData != null) {
int zoomFactor = actionId.equals(CMD_ZOOM_IN) ? 1 : -1;
FontDescriptor fd = createFontDescriptor(fondData, zoomFactor);
fontRegistry.put(ThemeConstants.FONT_SQL_RESULT_SET, fd.getFontData());
}
}
break;
}
case CMD_TOGGLE_ORDER:
{
final DBDAttributeBinding attr = rsv.getActivePresentation().getCurrentAttribute();
if (attr != null) {
rsv.toggleSortOrder(attr, false, false);
}
break;
}
}
return null;
}
use of org.eclipse.jface.resource.FontRegistry in project dbeaver by dbeaver.
the class ResultSetCommandHandler method execute.
@Nullable
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ResultSetViewer rsv = (ResultSetViewer) getActiveResultSet(HandlerUtil.getActivePart(event));
if (rsv == null) {
return null;
}
String actionId = event.getCommand().getId();
IResultSetPresentation presentation = rsv.getActivePresentation();
switch(actionId) {
case IWorkbenchCommandConstants.FILE_REFRESH:
rsv.refreshData(null);
break;
case CMD_TOGGLE_MODE:
rsv.toggleMode();
break;
case CMD_TOGGLE_PANELS:
rsv.showPanels(!rsv.isPanelsVisible());
break;
case CMD_FOCUS_FILTER:
rsv.switchFilterFocus();
break;
case CMD_SWITCH_PRESENTATION:
rsv.switchPresentation();
break;
case CMD_ROW_PREVIOUS:
case ITextEditorActionDefinitionIds.WORD_PREVIOUS:
presentation.scrollToRow(IResultSetPresentation.RowPosition.PREVIOUS);
break;
case CMD_ROW_NEXT:
case ITextEditorActionDefinitionIds.WORD_NEXT:
presentation.scrollToRow(IResultSetPresentation.RowPosition.NEXT);
break;
case CMD_ROW_FIRST:
case ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS:
presentation.scrollToRow(IResultSetPresentation.RowPosition.FIRST);
break;
case CMD_ROW_LAST:
case ITextEditorActionDefinitionIds.SELECT_WORD_NEXT:
presentation.scrollToRow(IResultSetPresentation.RowPosition.LAST);
break;
case CMD_FETCH_PAGE:
rsv.readNextSegment();
break;
case CMD_FETCH_ALL:
rsv.readAllData();
break;
case CMD_ROW_EDIT:
if (presentation instanceof IResultSetEditor) {
((IResultSetEditor) presentation).openValueEditor(false);
}
break;
case CMD_ROW_EDIT_INLINE:
if (presentation instanceof IResultSetEditor) {
((IResultSetEditor) presentation).openValueEditor(true);
}
break;
case CMD_ROW_ADD:
case CMD_ROW_COPY:
{
boolean copy = actionId.equals(CMD_ROW_COPY);
boolean shiftPressed = event.getTrigger() instanceof Event && ((((Event) event.getTrigger()).stateMask & SWT.SHIFT) == SWT.SHIFT);
boolean insertAfter = rsv.getPreferenceStore().getBoolean(DBeaverPreferences.RS_EDIT_NEW_ROWS_AFTER);
if (shiftPressed)
insertAfter = !insertAfter;
rsv.addNewRow(copy, insertAfter, true);
if (insertAfter) {
presentation.scrollToRow(IResultSetPresentation.RowPosition.NEXT);
}
break;
}
case CMD_ROW_DELETE:
case IWorkbenchCommandConstants.EDIT_DELETE:
rsv.deleteSelectedRows();
break;
case CMD_CELL_SET_NULL:
case CMD_CELL_RESET:
{
IResultSetSelection selection = rsv.getSelection();
for (Object cell : selection.toArray()) {
DBDAttributeBinding attr = selection.getElementAttribute(cell);
ResultSetRow row = selection.getElementRow(cell);
if (row != null && attr != null) {
ResultSetValueController valueController = new ResultSetValueController(rsv, attr, row, IValueController.EditType.NONE, null);
if (actionId.equals(CMD_CELL_SET_NULL)) {
valueController.updateValue(BaseValueManager.makeNullValue(valueController), false);
} else {
rsv.getModel().resetCellValue(attr, row);
}
}
}
rsv.redrawData(false, false);
rsv.updatePanelsContent(false);
break;
}
case CMD_APPLY_CHANGES:
rsv.applyChanges(null);
break;
case CMD_REJECT_CHANGES:
rsv.rejectChanges();
break;
case CMD_GENERATE_SCRIPT:
{
try {
final List<DBEPersistAction> sqlScript = new ArrayList<>();
try {
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
List<DBEPersistAction> script = rsv.generateChangesScript(monitor);
if (script != null) {
sqlScript.addAll(script);
}
}
});
} catch (InterruptedException e) {
// ignore
}
if (!sqlScript.isEmpty()) {
String scriptText = SQLUtils.generateScript(rsv.getDataContainer() == null ? null : rsv.getDataContainer().getDataSource(), sqlScript.toArray(new DBEPersistAction[sqlScript.size()]), false);
scriptText = SQLUtils.generateCommentLine(rsv.getExecutionContext() == null ? null : rsv.getExecutionContext().getDataSource(), "Actual parameter values may differ, what you see is a default string representation of values") + scriptText;
ViewSQLDialog dialog = new ViewSQLDialog(HandlerUtil.getActivePart(event).getSite(), rsv.getExecutionContext(), CoreMessages.editors_entity_dialog_preview_title, UIIcon.SQL_PREVIEW, scriptText);
dialog.open();
}
} catch (InvocationTargetException e) {
DBUserInterface.getInstance().showError("Script generation", "Can't generate changes script", e.getTargetException());
}
break;
}
case CMD_COPY_COLUMN_NAMES:
{
ResultSetCopySpecialHandler.CopyConfigDialog configDialog = new ResultSetCopySpecialHandler.CopyConfigDialog(HandlerUtil.getActiveShell(event), "CopyGridNamesOptionsDialog");
if (configDialog.open() != IDialogConstants.OK_ID) {
return null;
}
StringBuilder buffer = new StringBuilder();
IResultSetSelection selection = rsv.getSelection();
Collection<DBDAttributeBinding> attrs = selection.isEmpty() ? rsv.getModel().getVisibleAttributes() : selection.getSelectedAttributes();
for (DBDAttributeBinding attr : attrs) {
if (buffer.length() > 0) {
buffer.append(configDialog.copySettings.getColumnDelimiter());
}
String colName = attr.getLabel();
if (CommonUtils.isEmpty(colName)) {
colName = attr.getName();
}
buffer.append(colName);
}
ResultSetUtils.copyToClipboard(buffer.toString());
break;
}
case CMD_COPY_ROW_NAMES:
{
ResultSetCopySpecialHandler.CopyConfigDialog configDialog = new ResultSetCopySpecialHandler.CopyConfigDialog(HandlerUtil.getActiveShell(event), "CopyGridNamesOptionsDialog");
if (configDialog.open() != IDialogConstants.OK_ID) {
return null;
}
StringBuilder buffer = new StringBuilder();
IResultSetSelection selection = rsv.getSelection();
for (ResultSetRow row : selection.getSelectedRows()) {
if (buffer.length() > 0) {
buffer.append(configDialog.copySettings.getRowDelimiter());
}
buffer.append(row.getVisualNumber() + 1);
}
ResultSetUtils.copyToClipboard(buffer.toString());
break;
}
case IWorkbenchCommandConstants.EDIT_COPY:
ResultSetUtils.copyToClipboard(presentation.copySelectionToString(new ResultSetCopySettings(false, false, false, true, false, null, null, null, DBDDisplayFormat.EDIT)));
break;
case IWorkbenchCommandConstants.EDIT_PASTE:
case CoreCommands.CMD_PASTE_SPECIAL:
if (presentation instanceof IResultSetEditor) {
((IResultSetEditor) presentation).pasteFromClipboard(actionId.equals(CoreCommands.CMD_PASTE_SPECIAL));
}
break;
case IWorkbenchCommandConstants.EDIT_CUT:
ResultSetUtils.copyToClipboard(presentation.copySelectionToString(new ResultSetCopySettings(false, false, true, true, false, null, null, null, DBDDisplayFormat.EDIT)));
break;
case IWorkbenchCommandConstants.FILE_PRINT:
presentation.printResultSet();
break;
case ITextEditorActionDefinitionIds.SMART_ENTER:
if (presentation instanceof IResultSetEditor) {
((IResultSetEditor) presentation).openValueEditor(false);
}
break;
case IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE:
FindReplaceAction action = new FindReplaceAction(DBeaverActivator.getCoreResourceBundle(), "Editor.FindReplace.", HandlerUtil.getActiveShell(event), rsv.getAdapter(IFindReplaceTarget.class));
action.run();
break;
case CMD_NAVIGATE_LINK:
{
final ResultSetRow row = rsv.getCurrentRow();
final DBDAttributeBinding attr = rsv.getActivePresentation().getCurrentAttribute();
if (row != null && attr != null) {
new AbstractJob("Navigate association") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
rsv.navigateAssociation(monitor, attr, row, false);
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
}
break;
}
case CMD_COUNT:
rsv.updateRowCount();
break;
case IWorkbenchCommandConstants.NAVIGATE_BACKWARD_HISTORY:
{
final int hp = rsv.getHistoryPosition();
if (hp > 0) {
rsv.navigateHistory(hp - 1);
}
break;
}
case IWorkbenchCommandConstants.NAVIGATE_FORWARD_HISTORY:
{
final int hp = rsv.getHistoryPosition();
if (hp < rsv.getHistorySize() - 1) {
rsv.navigateHistory(hp + 1);
}
break;
}
case ITextEditorActionDefinitionIds.LINE_GOTO:
{
ResultSetRow currentRow = rsv.getCurrentRow();
final int rowCount = rsv.getModel().getRowCount();
if (rowCount <= 0) {
break;
}
GotoLineDialog d = new GotoLineDialog(HandlerUtil.getActiveShell(event), "Go to Row", "Enter row number (1.." + rowCount + ")", String.valueOf(currentRow == null ? 1 : currentRow.getVisualNumber() + 1), new IInputValidator() {
@Override
public String isValid(String input) {
try {
int i = Integer.parseInt(input);
if (i <= 0 || rowCount < i) {
return "Row number is out of range";
}
} catch (NumberFormatException x) {
return "Not a number";
}
return null;
}
});
if (d.open() == Window.OK) {
int line = Integer.parseInt(d.getValue());
rsv.setCurrentRow(rsv.getModel().getRow(line - 1));
rsv.getActivePresentation().scrollToRow(IResultSetPresentation.RowPosition.CURRENT);
}
break;
}
case CMD_FILTER_MENU:
{
rsv.showFiltersMenu();
break;
}
case CMD_FILTER_MENU_DISTINCT:
{
DBDAttributeBinding curAttribute = rsv.getActivePresentation().getCurrentAttribute();
if (curAttribute != null) {
rsv.showFiltersDistinctMenu(curAttribute, true);
}
break;
}
case CMD_REFERENCES_MENU:
{
rsv.showReferencesMenu();
break;
}
case CMD_EXPORT:
{
List<Long> selectedRows = new ArrayList<>();
for (ResultSetRow selectedRow : rsv.getSelection().getSelectedRows()) {
selectedRows.add(Long.valueOf(selectedRow.getRowNumber()));
}
List<String> selectedAttributes = new ArrayList<>();
for (DBDAttributeBinding attributeBinding : rsv.getSelection().getSelectedAttributes()) {
selectedAttributes.add(attributeBinding.getName());
}
ResultSetDataContainerOptions options = new ResultSetDataContainerOptions();
options.setSelectedRows(selectedRows);
options.setSelectedColumns(selectedAttributes);
ResultSetDataContainer dataContainer = new ResultSetDataContainer(rsv.getDataContainer(), rsv.getModel(), options);
ActiveWizardDialog dialog = new ActiveWizardDialog(HandlerUtil.getActiveWorkbenchWindow(event), new DataTransferWizard(new IDataTransferProducer[] { new DatabaseTransferProducer(dataContainer, rsv.getModel().getDataFilter()) }, null), rsv.getSelection());
dialog.open();
break;
}
case CMD_ZOOM_IN:
case CMD_ZOOM_OUT:
{
FontRegistry fontRegistry = rsv.getSite().getWorkbenchWindow().getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry();
Font font = fontRegistry.get(ThemeConstants.FONT_SQL_RESULT_SET);
if (font != null) {
FontData[] fondData = font.getFontData();
if (fondData != null) {
int zoomFactor = actionId.equals(CMD_ZOOM_IN) ? 1 : -1;
FontDescriptor fd = createFontDescriptor(fondData, zoomFactor);
fontRegistry.put(ThemeConstants.FONT_SQL_RESULT_SET, fd.getFontData());
}
}
break;
}
case CMD_TOGGLE_ORDER:
{
final DBDAttributeBinding attr = rsv.getActivePresentation().getCurrentAttribute();
if (attr != null) {
rsv.toggleSortOrder(attr, false, false);
}
break;
}
}
return null;
}
use of org.eclipse.jface.resource.FontRegistry in project eclipse.platform.text by eclipse.
the class AbstractTextZoomHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
AbstractTextEditor textEditor = getActiveTextEditor(event);
if (textEditor == null) {
return null;
}
FontRegistry fontRegistry = textEditor.getSite().getWorkbenchWindow().getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry();
String fontProperty = textEditor.getSymbolicFontName();
if (fontProperty == null) {
fontProperty = JFaceResources.TEXT_FONT;
}
Set<String> fontsToSet = getAffectedFontNames(fontProperty, fontRegistry);
FontData[] initialFontData = null;
String currentFontName = fontProperty;
while (currentFontName != null && (initialFontData = fontRegistry.getFontData(currentFontName)) == null) {
currentFontName = fgFontToDefault.get(currentFontName);
}
FontData[] newFontData = createFontDescriptor(initialFontData).getFontData();
if (newFontData != null) {
fontsToSet.stream().forEach(fontName -> fontRegistry.put(fontName, newFontData));
}
return Status.OK_STATUS;
}
Aggregations