use of org.jkiss.dbeaver.model.preferences.DBPPreferenceStore in project dbeaver by dbeaver.
the class DatabaseTasksTree method loadViewConfig.
public void loadViewConfig() {
DBPPreferenceStore preferenceStore = DBWorkbench.getPlatform().getPreferenceStore();
groupByProject = preferenceStore.getBoolean("dbeaver.tasks.view.groupByProject");
groupByCategory = preferenceStore.getBoolean("dbeaver.tasks.view.groupByCategory");
groupByType = preferenceStore.getBoolean("dbeaver.tasks.view.groupByType");
}
use of org.jkiss.dbeaver.model.preferences.DBPPreferenceStore in project dbeaver by dbeaver.
the class DatabaseTasksTree method saveViewConfig.
public void saveViewConfig() {
DBPPreferenceStore preferenceStore = DBWorkbench.getPlatform().getPreferenceStore();
preferenceStore.setValue("dbeaver.tasks.view.groupByProject", groupByProject);
preferenceStore.setValue("dbeaver.tasks.view.groupByCategory", groupByCategory);
preferenceStore.setValue("dbeaver.tasks.view.groupByType", groupByType);
try {
preferenceStore.save();
} catch (IOException e) {
log.debug(e);
}
}
use of org.jkiss.dbeaver.model.preferences.DBPPreferenceStore in project dbeaver by dbeaver.
the class DiagramToggleGridAction method run.
@Override
public void run() {
final DBPPreferenceStore store = ERDUIActivator.getDefault().getPreferences();
final boolean gridEnabled = store.getBoolean(ERDUIConstants.PREF_GRID_ENABLED);
store.setValue(ERDUIConstants.PREF_GRID_ENABLED, !gridEnabled);
PrefUtils.savePreferenceStore(store);
}
use of org.jkiss.dbeaver.model.preferences.DBPPreferenceStore in project dbeaver by dbeaver.
the class ResultSetHandlerOpenWith method openResultsWith.
private static void openResultsWith(IResultSetController resultSet, DataTransferProcessorDescriptor processor) {
ResultSetDataContainerOptions options = new ResultSetDataContainerOptions();
IResultSetSelection rsSelection = resultSet.getSelection();
List<ResultSetRow> rsSelectedRows = rsSelection.getSelectedRows();
List<DBDAttributeBinding> rsSelectedAttributes = rsSelection.getSelectedAttributes();
if (rsSelectedRows.size() > 1 || rsSelectedAttributes.size() > 1) {
List<Long> selectedRows = new ArrayList<>();
for (ResultSetRow selectedRow : rsSelectedRows) {
selectedRows.add((long) selectedRow.getRowNumber());
}
List<String> selectedAttributes = new ArrayList<>();
for (DBDAttributeBinding attributeBinding : rsSelectedAttributes) {
selectedAttributes.add(attributeBinding.getName());
}
options.setSelectedRows(selectedRows);
options.setSelectedColumns(selectedAttributes);
}
ResultSetDataContainer dataContainer = new ResultSetDataContainer(resultSet, options);
if (dataContainer.getDataSource() == null) {
DBWorkbench.getPlatformUI().showError("Open " + processor.getAppName(), ModelMessages.error_not_connected_to_database);
return;
}
DBPPreferenceStore preferenceStore = DBWorkbench.getPlatform().getPreferenceStore();
String prevActiveApp = preferenceStore.getString(PARAM_ACTIVE_APP);
if (!CommonUtils.equalObjects(prevActiveApp, processor.getFullId())) {
// preferenceStore.setValue(PARAM_ACTIVE_APP, processor.getFullId());
// resultSet.updateEditControls();
// resultSet.getControl().layout(true);
}
AbstractJob exportJob = new AbstractJob("Open " + processor.getAppName()) {
{
setUser(true);
setSystem(false);
}
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
File tempDir = DBWorkbench.getPlatform().getTempFolder(monitor, "data-files");
File tempFile = new File(tempDir, new SimpleDateFormat("yyyyMMdd-HHmmss").format(System.currentTimeMillis()) + "." + processor.getAppFileExtension());
tempFile.deleteOnExit();
IDataTransferProcessor processorInstance = processor.getInstance();
if (!(processorInstance instanceof IStreamDataExporter)) {
return Status.CANCEL_STATUS;
}
IStreamDataExporter exporter = (IStreamDataExporter) processorInstance;
StreamTransferConsumer consumer = new StreamTransferConsumer();
StreamConsumerSettings settings = new StreamConsumerSettings();
settings.setOutputEncodingBOM(false);
settings.setOpenFolderOnFinish(false);
settings.setOutputFolder(tempDir.getAbsolutePath());
settings.setOutputFilePattern(tempFile.getName());
Map<String, Object> properties = new HashMap<>();
// Default values from wizard
IDialogSettings dtSettings = DataTransferWizard.getWizardDialogSettings();
IDialogSettings procListSection = dtSettings.getSection("processors");
IDialogSettings procSettings = null;
if (procListSection != null) {
procSettings = procListSection.getSection("stream_consumer:" + processor.getId());
}
for (DBPPropertyDescriptor prop : processor.getProperties()) {
Object defValue = procSettings == null ? null : procSettings.get(CommonUtils.toString(prop.getId()));
properties.put(prop.getId(), defValue != null ? defValue : prop.getDefaultValue());
}
// Remove extension property (we specify file name directly)
properties.remove(StreamConsumerSettings.PROP_FILE_EXTENSION);
consumer.initTransfer(dataContainer, settings, new IDataTransferConsumer.TransferParameters(processor.isBinaryFormat(), processor.isHTMLFormat()), exporter, properties);
DBDDataFilter dataFilter = resultSet.getModel().getDataFilter();
DatabaseTransferProducer producer = new DatabaseTransferProducer(dataContainer, dataFilter);
DatabaseProducerSettings producerSettings = new DatabaseProducerSettings();
producerSettings.setExtractType(DatabaseProducerSettings.ExtractType.SINGLE_QUERY);
producerSettings.setQueryRowCount(false);
// disable OpenNewconnection by default (#6432)
producerSettings.setOpenNewConnections(false);
producerSettings.setSelectedRowsOnly(!CommonUtils.isEmpty(options.getSelectedRows()));
producerSettings.setSelectedColumnsOnly(!CommonUtils.isEmpty(options.getSelectedColumns()));
producer.transferData(monitor, consumer, null, producerSettings, null);
consumer.finishTransfer(monitor, false);
UIUtils.asyncExec(() -> {
if (!UIUtils.launchProgram(tempFile.getAbsolutePath())) {
DBWorkbench.getPlatformUI().showError("Open " + processor.getAppName(), "Can't open " + processor.getAppFileExtension() + " file '" + tempFile.getAbsolutePath() + "'");
}
});
} catch (Exception e) {
DBWorkbench.getPlatformUI().showError("Error opening in " + processor.getAppName(), null, e);
}
return Status.OK_STATUS;
}
};
exportJob.schedule();
}
use of org.jkiss.dbeaver.model.preferences.DBPPreferenceStore in project dbeaver by dbeaver.
the class ResultSetViewer method createStatusBar.
private void createStatusBar() {
Composite statusComposite = UIUtils.createPlaceholder(viewerPanel, 3);
statusComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
statusBar = new Composite(statusComposite, SWT.NONE);
statusBar.setBackgroundMode(SWT.INHERIT_FORCE);
statusBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
CSSUtils.setCSSClass(statusBar, DBStyles.COLORED_BY_CONNECTION_TYPE);
RowLayout toolbarsLayout = new RowLayout(SWT.HORIZONTAL);
toolbarsLayout.marginTop = 0;
toolbarsLayout.marginBottom = 0;
toolbarsLayout.center = true;
toolbarsLayout.wrap = true;
toolbarsLayout.pack = true;
// toolbarsLayout.fill = true;
statusBar.setLayout(toolbarsLayout);
{
ToolBarManager editToolBarManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT);
// handle own commands
editToolBarManager.add(new Separator());
editToolBarManager.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_APPLY_CHANGES, "Save", null, null, true));
editToolBarManager.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_REJECT_CHANGES, "Cancel", null, null, true));
editToolBarManager.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_GENERATE_SCRIPT, "Script", null, null, true));
editToolBarManager.add(new Separator());
editToolBarManager.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_ROW_EDIT));
editToolBarManager.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_ROW_ADD));
editToolBarManager.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_ROW_COPY));
editToolBarManager.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_ROW_DELETE));
ToolBar editorToolBar = editToolBarManager.createControl(statusBar);
CSSUtils.setCSSClass(editorToolBar, DBStyles.COLORED_BY_CONNECTION_TYPE);
toolbarList.add(editToolBarManager);
}
{
ToolBarManager navToolBarManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT);
navToolBarManager.add(new ToolbarSeparatorContribution(true));
navToolBarManager.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_ROW_FIRST));
navToolBarManager.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_ROW_PREVIOUS));
navToolBarManager.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_ROW_NEXT));
navToolBarManager.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_ROW_LAST));
navToolBarManager.add(new Separator());
navToolBarManager.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_FETCH_PAGE));
navToolBarManager.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_FETCH_ALL));
navToolBarManager.add(new Separator(TOOLBAR_GROUP_NAVIGATION));
ToolBar navToolBar = navToolBarManager.createControl(statusBar);
CSSUtils.setCSSClass(navToolBar, DBStyles.COLORED_BY_CONNECTION_TYPE);
toolbarList.add(navToolBarManager);
}
{
ToolBarManager configToolBarManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT);
configToolBarManager.add(new ToolbarSeparatorContribution(true));
/*
if (supportsPanels()) {
CommandContributionItemParameter ciParam = new CommandContributionItemParameter(
site,
"org.jkiss.dbeaver.core.resultset.panels",
ResultSetHandlerMain.CMD_TOGGLE_PANELS,
CommandContributionItem.STYLE_PULLDOWN);
ciParam.label = ResultSetMessages.controls_resultset_config_panels;
ciParam.mode = CommandContributionItem.MODE_FORCE_TEXT;
configToolBarManager.add(new CommandContributionItem(ciParam));
}
configToolBarManager.add(new ToolbarSeparatorContribution(true));
*/
ToolBar configToolBar = configToolBarManager.createControl(statusBar);
CSSUtils.setCSSClass(configToolBar, DBStyles.COLORED_BY_CONNECTION_TYPE);
toolbarList.add(configToolBarManager);
}
{
ToolBarManager addToolbBarManagerar = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT);
addToolbBarManagerar.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_EXPORT));
addToolbBarManagerar.add(new GroupMarker(TOOLBAR_GROUP_PRESENTATIONS));
addToolbBarManagerar.add(new Separator(TOOLBAR_GROUP_ADDITIONS));
final IMenuService menuService = getSite().getService(IMenuService.class);
if (menuService != null) {
menuService.populateContributionManager(addToolbBarManagerar, TOOLBAR_CONTRIBUTION_ID);
}
ToolBar addToolBar = addToolbBarManagerar.createControl(statusBar);
CSSUtils.setCSSClass(addToolBar, DBStyles.COLORED_BY_CONNECTION_TYPE);
toolbarList.add(addToolbBarManagerar);
}
{
// Config toolbar
ToolBarManager configToolBarManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT);
configToolBarManager.add(new ToolbarSeparatorContribution(true));
configToolBarManager.add(new ConfigAction());
configToolBarManager.update(true);
ToolBar configToolBar = configToolBarManager.createControl(statusBar);
CSSUtils.setCSSClass(configToolBar, DBStyles.COLORED_BY_CONNECTION_TYPE);
toolbarList.add(configToolBarManager);
}
{
final int fontHeight = UIUtils.getFontHeight(statusBar);
resultSetSize = new Text(statusBar, SWT.BORDER);
resultSetSize.setLayoutData(new RowData(5 * fontHeight, SWT.DEFAULT));
resultSetSize.setBackground(UIStyles.getDefaultTextBackground());
resultSetSize.setToolTipText(DataEditorsMessages.resultset_segment_size);
resultSetSize.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
String realValue = String.valueOf(getSegmentMaxRows());
if (!realValue.equals(resultSetSize.getText())) {
resultSetSize.setText(realValue);
}
}
});
resultSetSize.addModifyListener(e -> {
DBSDataContainer dataContainer = getDataContainer();
int fetchSize = CommonUtils.toInt(resultSetSize.getText());
if (fetchSize > 0 && fetchSize < ResultSetPreferences.MIN_SEGMENT_SIZE) {
fetchSize = ResultSetPreferences.MIN_SEGMENT_SIZE;
}
if (dataContainer != null && dataContainer.getDataSource() != null) {
DBPPreferenceStore store = dataContainer.getDataSource().getContainer().getPreferenceStore();
int oldFetchSize = store.getInt(ModelPreferences.RESULT_SET_MAX_ROWS);
if (oldFetchSize != fetchSize) {
store.setValue(ModelPreferences.RESULT_SET_MAX_ROWS, fetchSize);
PrefUtils.savePreferenceStore(store);
}
}
});
UIUtils.addDefaultEditActionsSupport(site, resultSetSize);
rowCountLabel = new ActiveStatusMessage(statusBar, DBeaverIcons.getImage(UIIcon.RS_REFRESH), ResultSetMessages.controls_resultset_viewer_calculate_row_count, this) {
@Override
protected boolean isActionEnabled() {
return hasData();
}
@Override
protected ILoadService<String> createLoadService() {
return new DatabaseLoadService<String>("Load row count", getExecutionContext()) {
@Override
public String evaluate(DBRProgressMonitor monitor) throws InvocationTargetException {
try {
long rowCount = readRowCount(monitor);
return ROW_COUNT_FORMAT.format(rowCount);
} catch (DBException e) {
log.error(e);
throw new InvocationTargetException(e);
}
}
};
}
};
// rowCountLabel.setLayoutData();
CSSUtils.setCSSClass(rowCountLabel, DBStyles.COLORED_BY_CONNECTION_TYPE);
rowCountLabel.setMessage("Row Count");
rowCountLabel.setToolTipText("Calculates total row count in the current dataset");
UIUtils.createToolBarSeparator(statusBar, SWT.VERTICAL);
selectionStatLabel = new Text(statusBar, SWT.READ_ONLY);
selectionStatLabel.setToolTipText("Selected rows/columns/cells");
CSSUtils.setCSSClass(selectionStatLabel, DBStyles.COLORED_BY_CONNECTION_TYPE);
Label filler = new Label(statusComposite, SWT.NONE);
filler.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
statusLabel = new StatusLabel(statusComposite, SWT.NONE, this);
GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END);
gd.widthHint = 30 * fontHeight;
statusLabel.setLayoutData(gd);
CSSUtils.setCSSClass(statusLabel, DBStyles.COLORED_BY_CONNECTION_TYPE);
statusBar.addListener(SWT.Resize, event -> {
});
}
}
Aggregations