Search in sources :

Example 91 with DBPPreferenceStore

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

the class PlainTextPresentation method refreshData.

@Override
public void refreshData(boolean refreshMetadata, boolean append, boolean keepState) {
    colWidths = null;
    DBPPreferenceStore prefs = getController().getPreferenceStore();
    rightJustifyNumbers = prefs.getBoolean(ResultSetPreferences.RESULT_SET_RIGHT_JUSTIFY_NUMBERS);
    rightJustifyDateTime = prefs.getBoolean(ResultSetPreferences.RESULT_SET_RIGHT_JUSTIFY_DATETIME);
    if (controller.isRecordMode()) {
        printRecord();
    } else {
        printGrid(append);
    }
}
Also used : DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)

Example 92 with DBPPreferenceStore

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

the class PlainTextPresentation method printGrid.

private void printGrid(boolean append) {
    DBPPreferenceStore prefs = getController().getPreferenceStore();
    int maxColumnSize = prefs.getInt(ResultSetPreferences.RESULT_TEXT_MAX_COLUMN_SIZE);
    boolean delimLeading = prefs.getBoolean(ResultSetPreferences.RESULT_TEXT_DELIMITER_LEADING);
    boolean delimTrailing = prefs.getBoolean(ResultSetPreferences.RESULT_TEXT_DELIMITER_TRAILING);
    boolean extraSpaces = prefs.getBoolean(ResultSetPreferences.RESULT_TEXT_EXTRA_SPACES);
    this.showNulls = getController().getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_TEXT_SHOW_NULLS);
    DBDDisplayFormat displayFormat = DBDDisplayFormat.safeValueOf(prefs.getString(ResultSetPreferences.RESULT_TEXT_VALUE_FORMAT));
    StringBuilder grid = new StringBuilder(512);
    ResultSetModel model = controller.getModel();
    List<DBDAttributeBinding> attrs = model.getVisibleAttributes();
    List<ResultSetRow> allRows = model.getAllRows();
    int extraSpacesNum = extraSpaces ? 2 : 0;
    if (colWidths == null) {
        // Calculate column widths
        colWidths = new int[attrs.size()];
        for (int i = 0; i < attrs.size(); i++) {
            DBDAttributeBinding attr = attrs.get(i);
            colWidths[i] = getAttributeName(attr).length() + extraSpacesNum;
            if (showNulls && !attr.isRequired()) {
                colWidths[i] = Math.max(colWidths[i], DBConstants.NULL_VALUE_LABEL.length());
            }
            for (ResultSetRow row : allRows) {
                String displayString = getCellString(model, attr, row, displayFormat);
                colWidths[i] = Math.max(colWidths[i], getStringWidth(displayString) + extraSpacesNum);
            }
        }
        for (int i = 0; i < colWidths.length; i++) {
            if (colWidths[i] > maxColumnSize) {
                colWidths[i] = maxColumnSize;
            }
        }
    }
    if (!append) {
        // Print header
        if (delimLeading)
            grid.append("|");
        for (int i = 0; i < attrs.size(); i++) {
            if (i > 0)
                grid.append("|");
            if (extraSpaces)
                grid.append(" ");
            DBDAttributeBinding attr = attrs.get(i);
            String attrName = getAttributeName(attr);
            grid.append(attrName);
            for (int k = colWidths[i] - attrName.length() - extraSpacesNum; k > 0; k--) {
                grid.append(" ");
            }
            if (extraSpaces)
                grid.append(" ");
        }
        if (delimTrailing)
            grid.append("|");
        grid.append("\n");
        // Print header
        if (delimLeading)
            grid.append("|");
        for (int i = 0; i < attrs.size(); i++) {
            if (i > 0)
                grid.append("|");
            for (int k = colWidths[i]; k > 0; k--) {
                grid.append("-");
            }
        }
        if (delimTrailing)
            grid.append("|");
        grid.append("\n");
    }
    // Print rows
    int firstRow = append ? totalRows : 0;
    if (append) {
        grid.append("\n");
    }
    for (int i = firstRow; i < allRows.size(); i++) {
        ResultSetRow row = allRows.get(i);
        if (delimLeading)
            grid.append("|");
        for (int k = 0; k < attrs.size(); k++) {
            if (k > 0)
                grid.append("|");
            DBDAttributeBinding attr = attrs.get(k);
            String displayString = getCellString(model, attr, row, displayFormat);
            if (displayString.length() >= colWidths[k]) {
                displayString = CommonUtils.truncateString(displayString, colWidths[k]);
            }
            int stringWidth = getStringWidth(displayString);
            if (extraSpaces)
                grid.append(" ");
            DBPDataKind dataKind = attr.getDataKind();
            if ((dataKind == DBPDataKind.NUMERIC && rightJustifyNumbers) || (dataKind == DBPDataKind.DATETIME && rightJustifyDateTime)) {
                // Right justify value
                for (int j = colWidths[k] - stringWidth - extraSpacesNum; j > 0; j--) {
                    grid.append(" ");
                }
                grid.append(displayString);
            } else {
                grid.append(displayString);
                for (int j = colWidths[k] - stringWidth - extraSpacesNum; j > 0; j--) {
                    grid.append(" ");
                }
            }
            if (extraSpaces)
                grid.append(" ");
        }
        if (delimTrailing)
            grid.append("|");
        grid.append("\n");
    }
    // cut last line feed
    grid.setLength(grid.length() - 1);
    if (append) {
        text.append(grid.toString());
    } else {
        text.setText(grid.toString());
    }
    totalRows = allRows.size();
}
Also used : DBDDisplayFormat(org.jkiss.dbeaver.model.data.DBDDisplayFormat) DBPDataKind(org.jkiss.dbeaver.model.DBPDataKind) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)

Example 93 with DBPPreferenceStore

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

the class BinaryEditor method dispose.

/**
 * Removes preferences-changed listener
 *
 * @see WorkbenchPart#dispose()
 */
@Override
public void dispose() {
    if (manager != null) {
        manager.dispose();
        manager = null;
    }
    DBPPreferenceStore store = DBWorkbench.getPlatform().getPreferenceStore();
    store.removePropertyChangeListener(preferencesChangeListener);
    ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
    super.dispose();
}
Also used : DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)

Example 94 with DBPPreferenceStore

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

the class BinaryEditor method createPartControl.

@Override
public void createPartControl(Composite parent) {
    IStorage storage = EditorUtils.getStorageFromInput(getEditorInput());
    manager = new HexManager();
    manager.setTextFont(HexPreferencesPage.getPrefFontData());
    manager.setDefWidth(HexPreferencesPage.getDefaultWidth());
    manager.setMenuListener(this);
    int editorStyle = SWT.NONE;
    if (storage != null && storage.isReadOnly()) {
        editorStyle = SWT.READ_ONLY;
    }
    manager.createEditorPart(parent, editorStyle);
    FillLayout fillLayout = new FillLayout();
    parent.setLayout(fillLayout);
    loadBinaryContent();
    // Register any global actions with the site's IActionBars.
    IActionBars bars = getEditorSite().getActionBars();
    createEditorAction(bars, IWorkbenchCommandConstants.EDIT_UNDO);
    createEditorAction(bars, IWorkbenchCommandConstants.EDIT_REDO);
    createEditorAction(bars, IWorkbenchCommandConstants.EDIT_CUT);
    createEditorAction(bars, IWorkbenchCommandConstants.EDIT_COPY);
    createEditorAction(bars, IWorkbenchCommandConstants.EDIT_PASTE);
    createEditorAction(bars, IWorkbenchCommandConstants.EDIT_DELETE);
    createEditorAction(bars, IWorkbenchCommandConstants.EDIT_SELECT_ALL);
    createEditorAction(bars, IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE);
    createEditorAction(bars, ITextEditorActionConstants.GOTO_LINE);
    manager.addListener(new Listener() {

        @Override
        public void handleEvent(Event event) {
            firePropertyChange(PROP_DIRTY);
            updateActionsStatus();
        }
    });
    bars.updateActionBars();
    preferencesChangeListener = new DBPPreferenceListener() {

        @Override
        public void preferenceChange(PreferenceChangeEvent event) {
            if (HexPreferencesPage.PROP_FONT_DATA.equals(event.getProperty())) {
                manager.setTextFont((FontData) event.getNewValue());
            }
            if (HexPreferencesPage.PROP_DEF_WIDTH.equals(event.getProperty())) {
                manager.setDefWidth((String) event.getNewValue());
            }
        }
    };
    DBPPreferenceStore store = DBWorkbench.getPlatform().getPreferenceStore();
    store.addPropertyChangeListener(preferencesChangeListener);
    manager.addLongSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (selectionListeners == null)
                return;
            long[] longSelection = HexEditControl.getLongSelection(e);
            SelectionChangedEvent event = new SelectionChangedEvent(BinaryEditor.this, new StructuredSelection(new Object[] { longSelection[0], longSelection[1] }));
            for (ISelectionChangedListener selectionListener : selectionListeners) {
                selectionListener.selectionChanged(event);
            }
        }
    });
}
Also used : Listener(org.eclipse.swt.widgets.Listener) DBPPreferenceListener(org.jkiss.dbeaver.model.preferences.DBPPreferenceListener) FontData(org.eclipse.swt.graphics.FontData) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) DBPPreferenceListener(org.jkiss.dbeaver.model.preferences.DBPPreferenceListener)

Example 95 with DBPPreferenceStore

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

the class DataEditorsPreferencesInitializer method initializeDefaultPreferences.

@Override
public void initializeDefaultPreferences() {
    // Init default preferences
    DBPPreferenceStore store = DBWorkbench.getPlatform().getPreferenceStore();
    // Common
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.KEEP_STATEMENT_OPEN, false);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RS_EDIT_USE_ALL_COLUMNS, false);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RS_EDIT_MAX_TEXT_SIZE, 10 * 1000000);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RS_EDIT_LONG_AS_LOB, true);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RS_EDIT_AUTO_UPDATE_VALUE, true);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RS_COMMIT_ON_EDIT_APPLY, false);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RS_COMMIT_ON_CONTENT_APPLY, false);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RS_EDIT_NEW_ROWS_AFTER, true);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RS_EDIT_REFRESH_AFTER_UPDATE, true);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RS_GROUPING_DEFAULT_SORTING, "");
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RS_GROUPING_SHOW_DUPLICATES_ONLY, false);
    // ResultSet
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_AUTO_FETCH_NEXT_SEGMENT, true);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_CANCEL_TIMEOUT, 5000);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_BINARY_EDITOR_TYPE, IValueController.EditType.EDITOR);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_ORDERING_MODE, ResultSetUtils.OrderingMode.SMART);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_SHOW_ODD_ROWS, true);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_SHOW_CELL_ICONS, true);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_SHOW_ATTR_ICONS, true);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_SHOW_ATTR_FILTERS, true);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_SHOW_ATTR_ORDERING, true);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_USE_SMOOTH_SCROLLING, true);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_SHOW_BOOLEAN_AS_CHECKBOX, true);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_DOUBLE_CLICK, Spreadsheet.DoubleClickBehavior.INLINE_EDITOR.name());
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_AUTO_SWITCH_MODE, false);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_SHOW_DESCRIPTION, false);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_CALC_COLUMN_WIDTH_BY_VALUES, false);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_SHOW_CONNECTION_NAME, false);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_FILTER_AUTO_COMPLETE_PROPOSIAL, true);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_SHOW_SEL_ROWS, true);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_SHOW_SEL_COLUMNS, false);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_SHOW_SEL_CELLS, false);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_COLORIZE_DATA_TYPES, false);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_RIGHT_JUSTIFY_NUMBERS, true);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_RIGHT_JUSTIFY_DATETIME, true);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_ROW_BATCH_SIZE, 1);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_STRING_USE_CONTENT_EDITOR, false);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_USE_NAVIGATOR_FILTERS, true);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_SET_SHOW_ERRORS_IN_DIALOG, false);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_TEXT_TAB_SIZE, 4);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_TEXT_MAX_COLUMN_SIZE, 255);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_TEXT_VALUE_FORMAT, DBDDisplayFormat.EDIT.name());
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_TEXT_SHOW_NULLS, false);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_TEXT_DELIMITER_LEADING, false);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_TEXT_DELIMITER_TRAILING, true);
    PrefUtils.setDefaultPreferenceValue(store, ResultSetPreferences.RESULT_TEXT_EXTRA_SPACES, false);
// Override default editor page
// PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_DEFAULT_EDITOR_PAGE, DatabaseDataEditor.class.getName());
}
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