Search in sources :

Example 51 with DBPPreferenceStore

use of org.jkiss.dbeaver.model.preferences.DBPPreferenceStore in project dbeaver by serge-rider.

the class DataSourcePreferenceStore method firePropertyChangeEvent.

@Override
public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
    super.firePropertyChangeEvent(name, oldValue, newValue);
    // Forward event to global DS prefs store
    DBPPreferenceStore gps = DBWorkbench.getPlatform().getDataSourceProviderRegistry().getGlobalDataSourcePreferenceStore();
    if (gps instanceof AbstractPreferenceStore) {
        ((AbstractPreferenceStore) gps).firePropertyChangeEvent(this, name, oldValue, newValue);
    }
}
Also used : AbstractPreferenceStore(org.jkiss.dbeaver.model.impl.preferences.AbstractPreferenceStore) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)

Example 52 with DBPPreferenceStore

use of org.jkiss.dbeaver.model.preferences.DBPPreferenceStore in project dbeaver by serge-rider.

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();
}
Also used : DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) StreamConsumerSettings(org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings) DBDDataFilter(org.jkiss.dbeaver.model.data.DBDDataFilter) StreamTransferConsumer(org.jkiss.dbeaver.tools.transfer.stream.StreamTransferConsumer) IDataTransferConsumer(org.jkiss.dbeaver.tools.transfer.IDataTransferConsumer) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) IDataTransferProcessor(org.jkiss.dbeaver.tools.transfer.IDataTransferProcessor) ExecutionException(org.eclipse.core.commands.ExecutionException) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) DatabaseProducerSettings(org.jkiss.dbeaver.tools.transfer.database.DatabaseProducerSettings) IStreamDataExporter(org.jkiss.dbeaver.tools.transfer.stream.IStreamDataExporter) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Example 53 with DBPPreferenceStore

use of org.jkiss.dbeaver.model.preferences.DBPPreferenceStore in project dbeaver by serge-rider.

the class SpreadsheetPresentation method refreshData.

@Override
public void refreshData(boolean refreshMetadata, boolean append, boolean keepState) {
    // Cache preferences
    DBPPreferenceStore preferenceStore = getPreferenceStore();
    showOddRows = preferenceStore.getBoolean(ResultSetPreferences.RESULT_SET_SHOW_ODD_ROWS);
    // showCelIcons = preferenceStore.getBoolean(ResultSetPreferences.RESULT_SET_SHOW_CELL_ICONS);
    rightJustifyNumbers = preferenceStore.getBoolean(ResultSetPreferences.RESULT_SET_RIGHT_JUSTIFY_NUMBERS);
    rightJustifyDateTime = preferenceStore.getBoolean(ResultSetPreferences.RESULT_SET_RIGHT_JUSTIFY_DATETIME);
    rowBatchSize = preferenceStore.getInt(ResultSetPreferences.RESULT_SET_ROW_BATCH_SIZE);
    showAttrOrdering = preferenceStore.getBoolean(ResultSetPreferences.RESULT_SET_SHOW_ATTR_ORDERING);
    showAttributeIcons = controller.getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_SHOW_ATTR_ICONS);
    showAttributeDescription = getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_SHOW_DESCRIPTION);
    supportsAttributeFilter = (controller.getDecorator().getDecoratorFeatures() & IResultSetDecorator.FEATURE_FILTERS) != 0 && (controller.getDataContainer().getSupportedFeatures() & DBSDataContainer.DATA_FILTER) != 0 && controller.getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_SHOW_ATTR_FILTERS);
    autoFetchSegments = controller.getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_AUTO_FETCH_NEXT_SEGMENT);
    calcColumnWidthByValue = getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_CALC_COLUMN_WIDTH_BY_VALUES);
    showBooleanAsCheckbox = preferenceStore.getBoolean(ResultSetPreferences.RESULT_SET_SHOW_BOOLEAN_AS_CHECKBOX);
    useNativeNumbersFormat = controller.getPreferenceStore().getBoolean(ModelPreferences.RESULT_NATIVE_NUMERIC_FORMAT);
    spreadsheet.setColumnScrolling(!getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_USE_SMOOTH_SCROLLING));
    spreadsheet.setRedraw(false);
    try {
        spreadsheet.refreshData(refreshMetadata, keepState, false);
    } finally {
        spreadsheet.setRedraw(true);
    }
}
Also used : DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)

Example 54 with DBPPreferenceStore

use of org.jkiss.dbeaver.model.preferences.DBPPreferenceStore in project dbeaver by serge-rider.

the class PrefPageDatabaseNavigator method performOk.

@Override
public boolean performOk() {
    DBPPreferenceStore store = DBWorkbench.getPlatform().getPreferenceStore();
    store.setValue(NavigatorPreferences.NAVIGATOR_EXPAND_ON_CONNECT, expandOnConnectCheck.getSelection());
    store.setValue(NavigatorPreferences.NAVIGATOR_RESTORE_STATE_DEPTH, restoreStateDepthText.getText());
    store.setValue(NavigatorPreferences.NAVIGATOR_SHOW_OBJECT_TIPS, showObjectTipsCheck.getSelection());
    store.setValue(NavigatorPreferences.NAVIGATOR_SHOW_TOOLTIPS, showToolTipsCheck.getSelection());
    store.setValue(NavigatorPreferences.NAVIGATOR_SHOW_CONTENTS_IN_TOOLTIP, showContentsInToolTipsContents.getSelection());
    store.setValue(ModelPreferences.NAVIGATOR_SORT_ALPHABETICALLY, sortCaseInsensitiveCheck.getSelection());
    store.setValue(ModelPreferences.NAVIGATOR_SORT_FOLDERS_FIRST, sortFoldersFirstCheck.getSelection());
    store.setValue(NavigatorPreferences.NAVIGATOR_SHOW_CONNECTION_HOST_NAME, showConnectionHostCheck.getSelection());
    store.setValue(NavigatorPreferences.NAVIGATOR_SHOW_STATISTICS_INFO, showStatisticsCheck.getSelection());
    store.setValue(NavigatorPreferences.NAVIGATOR_SHOW_NODE_ACTIONS, showNodeActionsCheck.getSelection());
    store.setValue(NavigatorPreferences.NAVIGATOR_COLOR_ALL_NODES, colorAllNodesCheck.getSelection());
    store.setValue(ModelPreferences.NAVIGATOR_SHOW_FOLDER_PLACEHOLDERS, showResourceFolderPlaceholdersCheck.getSelection());
    store.setValue(NavigatorPreferences.NAVIGATOR_GROUP_BY_DRIVER, groupByDriverCheck.getSelection());
    store.setValue(NavigatorPreferences.NAVIGATOR_LONG_LIST_FETCH_SIZE, longListFetchSizeText.getText());
    NavigatorPreferences.DoubleClickBehavior objDCB = NavigatorPreferences.DoubleClickBehavior.EXPAND;
    if (objDoubleClickBehavior.getSelectionIndex() == 0) {
        objDCB = NavigatorPreferences.DoubleClickBehavior.EDIT;
    }
    store.setValue(NavigatorPreferences.NAVIGATOR_OBJECT_DOUBLE_CLICK, objDCB.name());
    store.setValue(NavigatorPreferences.NAVIGATOR_CONNECTION_DOUBLE_CLICK, CommonUtils.fromOrdinal(NavigatorPreferences.DoubleClickBehavior.class, dsDoubleClickBehavior.getSelectionIndex()).name());
    List<EntityEditorDescriptor> entityEditors = getAvailableEditorPages();
    int defEditorIndex = defaultEditorPageCombo.getSelectionIndex();
    store.setValue(NavigatorPreferences.NAVIGATOR_DEFAULT_EDITOR_PAGE, defEditorIndex <= 0 ? "" : entityEditors.get(defEditorIndex - 1).getId());
    PrefUtils.savePreferenceStore(store);
    return true;
}
Also used : NavigatorPreferences(org.jkiss.dbeaver.ui.navigator.NavigatorPreferences) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) EntityEditorDescriptor(org.jkiss.dbeaver.ui.editors.entity.EntityEditorDescriptor)

Example 55 with DBPPreferenceStore

use of org.jkiss.dbeaver.model.preferences.DBPPreferenceStore in project dbeaver by serge-rider.

the class TargetPrefPage method performOk.

@Override
public final boolean performOk() {
    DBPPreferenceStore store = isDataSourcePreferencePage() ? getDataSourceContainer().getPreferenceStore() : DBWorkbench.getPlatform().getPreferenceStore();
    if (isDataSourcePreferencePage() && !useDataSourceSettings()) {
        // Just delete datasource specific settings
        clearPreferences(store);
        PrefUtils.savePreferenceStore(store);
    } else {
        savePreferences(store);
    }
    // PrefUtils.savePreferenceStore(store);
    return super.performOk();
}
Also used : DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)

Aggregations

DBPPreferenceStore (org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)201 DBPPreferenceListener (org.jkiss.dbeaver.model.preferences.DBPPreferenceListener)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)10 ExecutionException (org.eclipse.core.commands.ExecutionException)8 GridData (org.eclipse.swt.layout.GridData)8 NotNull (org.jkiss.code.NotNull)8 BundlePreferenceStore (org.jkiss.dbeaver.model.impl.preferences.BundlePreferenceStore)8 Color (org.eclipse.swt.graphics.Color)6 FontData (org.eclipse.swt.graphics.FontData)6 DBException (org.jkiss.dbeaver.DBException)6 DBDDisplayFormat (org.jkiss.dbeaver.model.data.DBDDisplayFormat)6 QMObjectType (org.jkiss.dbeaver.model.qm.QMObjectType)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)4 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)4