use of org.jkiss.dbeaver.model.preferences.DBPPreferenceStore in project dbeaver by serge-rider.
the class GISViewerPreferencesInitializer method initializeDefaultPreferences.
@Override
public void initializeDefaultPreferences() {
// Init default preferences
DBPPreferenceStore store = new BundlePreferenceStore(GISViewerActivator.getDefault().getBundle());
// View settings
PrefUtils.setDefaultPreferenceValue(store, GeometryViewerConstants.PREF_MAX_OBJECTS_RENDER, GeometryViewerConstants.DEFAULT_MAX_OBJECTS_RENDER);
PrefUtils.setDefaultPreferenceValue(store, GeometryViewerConstants.PREF_DEFAULT_SRID, GisConstants.SRID_4326);
}
use of org.jkiss.dbeaver.model.preferences.DBPPreferenceStore in project dbeaver by serge-rider.
the class JDBCContentValueHandler method getValueFromObject.
@Override
public DBDContent getValueFromObject(@NotNull DBCSession session, @NotNull DBSTypedObject type, Object object, boolean copy, boolean validateValue) throws DBCException {
if (object == null) {
// Create wrapper using column type
switch(type.getTypeID()) {
case java.sql.Types.CHAR:
case java.sql.Types.VARCHAR:
case java.sql.Types.NVARCHAR:
case java.sql.Types.LONGVARCHAR:
case java.sql.Types.LONGNVARCHAR:
return new JDBCContentChars(session.getExecutionContext(), null);
case java.sql.Types.CLOB:
case java.sql.Types.NCLOB:
return new JDBCContentCLOB(session.getExecutionContext(), null);
case java.sql.Types.BINARY:
case java.sql.Types.VARBINARY:
case java.sql.Types.LONGVARBINARY:
return new JDBCContentBytes(session.getExecutionContext());
case java.sql.Types.BLOB:
return new JDBCContentBLOB(session.getExecutionContext(), null);
case java.sql.Types.SQLXML:
return new JDBCContentXML(session.getExecutionContext(), null);
default:
{
String typeName = type.getTypeName();
if (typeName.contains(DBConstants.TYPE_NAME_XML) || typeName.contains(DBConstants.TYPE_NAME_XML2)) {
return new JDBCContentXML(session.getExecutionContext(), null);
} else if (typeName.contains(DBConstants.TYPE_NAME_JSON) || typeName.contains(DBConstants.TYPE_NAME_JSON2)) {
return new JDBCContentChars(session.getExecutionContext(), null);
} else {
// log.debug(ModelMessages.model_jdbc_unsupported_column_type_ + type.getTypeName());
return new JDBCContentBytes(session.getExecutionContext());
}
}
}
} else if (object instanceof byte[]) {
return new JDBCContentBytes(session.getExecutionContext(), (byte[]) object);
} else if (object instanceof String) {
// So it is possible that real object type isn't string
switch(type.getTypeID()) {
case java.sql.Types.BINARY:
case java.sql.Types.VARBINARY:
case java.sql.Types.LONGVARBINARY:
return new JDBCContentBytes(session.getExecutionContext(), (String) object);
default:
// String by default
return new JDBCContentChars(session.getExecutionContext(), (String) object);
}
} else if (object instanceof Number) {
return new JDBCContentBytes(session.getExecutionContext(), object.toString());
} else if (object instanceof Blob) {
final JDBCContentBLOB blob = new JDBCContentBLOB(session.getExecutionContext(), (Blob) object);
final DBPPreferenceStore preferenceStore = session.getDataSource().getContainer().getPreferenceStore();
if (preferenceStore.getBoolean(ModelPreferences.CONTENT_CACHE_BLOB) && blob.getLOBLength() < preferenceStore.getLong(ModelPreferences.CONTENT_CACHE_MAX_SIZE)) {
// Precache content
blob.getContents(session.getProgressMonitor());
}
return blob;
} else if (object instanceof Clob) {
JDBCContentCLOB clob = new JDBCContentCLOB(session.getExecutionContext(), (Clob) object);
final DBPPreferenceStore preferenceStore = session.getDataSource().getContainer().getPreferenceStore();
if (preferenceStore.getBoolean(ModelPreferences.CONTENT_CACHE_CLOB) && clob.getLOBLength() < preferenceStore.getLong(ModelPreferences.CONTENT_CACHE_MAX_SIZE)) {
// Precache content
clob.getContents(session.getProgressMonitor());
}
return clob;
} else if (object instanceof SQLXML) {
return new JDBCContentXML(session.getExecutionContext(), (SQLXML) object);
} else if (object instanceof InputStream) {
// Some weird drivers returns InputStream instead of Xlob.
// Copy stream to byte array
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
final InputStream stream = (InputStream) object;
try {
IOUtils.copyStream(stream, buffer);
} catch (Exception e) {
throw new DBCException("Error reading content stream", e);
}
IOUtils.close(stream);
return new JDBCContentBytes(session.getExecutionContext(), buffer.toByteArray());
} else if (object instanceof Reader) {
// Copy reader to string
StringWriter buffer = new StringWriter();
final Reader reader = (Reader) object;
try {
IOUtils.copyText(reader, buffer);
} catch (Exception e) {
throw new DBCException("Error reading content reader", e);
}
IOUtils.close(reader);
return new JDBCContentChars(session.getExecutionContext(), buffer.toString());
} else if (object instanceof DBDContent) {
if (copy && object instanceof DBDValueCloneable) {
return (DBDContent) ((DBDValueCloneable) object).cloneValue(session.getProgressMonitor());
}
return (DBDContent) object;
} else {
// Give up. Let's show string value
return new JDBCContentChars(session.getExecutionContext(), CommonUtils.toString(object));
// throw new DBCException(ModelMessages.model_jdbc_unsupported_value_type_ + object.getClass().getName());
}
}
use of org.jkiss.dbeaver.model.preferences.DBPPreferenceStore in project dbeaver by serge-rider.
the class UINavigatorPreferencesInitializer method initializeDefaultPreferences.
@Override
public void initializeDefaultPreferences() {
// Init default preferences
DBPPreferenceStore store = DBWorkbench.getPlatform().getPreferenceStore();
// Navigator
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_EXPAND_ON_CONNECT, false);
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_RESTORE_STATE_DEPTH, 0);
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_COLOR_ALL_NODES, false);
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_SYNC_EDITOR_DATASOURCE, false);
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_REFRESH_EDITORS_ON_OPEN, false);
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_GROUP_BY_DRIVER, false);
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_EDITOR_SHOW_TABLE_GRID, true);
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_OBJECT_DOUBLE_CLICK, NavigatorPreferences.DoubleClickBehavior.EDIT.name());
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_CONNECTION_DOUBLE_CLICK, NavigatorPreferences.DoubleClickBehavior.EXPAND.name());
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_DEFAULT_EDITOR_PAGE, "");
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_SHOW_SQL_PREVIEW, true);
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_SHOW_OBJECT_TIPS, true);
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_LONG_LIST_FETCH_SIZE, 5000);
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_SHOW_STATISTICS_INFO, true);
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_SHOW_CONNECTION_HOST_NAME, true);
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_SHOW_NODE_ACTIONS, true);
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.ENTITY_EDITOR_DETACH_INFO, true);
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_SHOW_TOOLTIPS, true);
PrefUtils.setDefaultPreferenceValue(store, NavigatorPreferences.NAVIGATOR_SHOW_CONTENTS_IN_TOOLTIP, false);
}
use of org.jkiss.dbeaver.model.preferences.DBPPreferenceStore in project dbeaver by serge-rider.
the class ERDEditorPart method printDiagram.
public void printDiagram() {
GraphicalViewer viewer = getGraphicalViewer();
PrintDialog dialog = new PrintDialog(viewer.getControl().getShell(), SWT.NULL);
PrinterData data = dialog.open();
if (data != null) {
IFigure rootFigure = rootPart.getLayer(ScalableFreeformRootEditPart.PRINTABLE_LAYERS);
// EntityDiagramFigure diagramFigure = findFigure(rootFigure, EntityDiagramFigure.class);
if (rootFigure != null) {
PrintFigureOperation printOp = new PrintFigureOperation(new Printer(data), rootFigure);
// Set print preferences
DBPPreferenceStore store = ERDUIActivator.getDefault().getPreferences();
printOp.setPrintMode(store.getInt(ERDUIConstants.PREF_PRINT_PAGE_MODE));
printOp.setPrintMargin(new Insets(store.getInt(ERDUIConstants.PREF_PRINT_MARGIN_TOP), store.getInt(ERDUIConstants.PREF_PRINT_MARGIN_LEFT), store.getInt(ERDUIConstants.PREF_PRINT_MARGIN_BOTTOM), store.getInt(ERDUIConstants.PREF_PRINT_MARGIN_RIGHT)));
// Run print
printOp.run("Print ER diagram");
}
}
// new PrintAction(this).run();
}
use of org.jkiss.dbeaver.model.preferences.DBPPreferenceStore in project dbeaver by serge-rider.
the class AbstractJob method runBlockCanceler.
private void runBlockCanceler() {
final List<DBRBlockingObject> activeBlocks = new ArrayList<>(CommonUtils.safeList(progressMonitor.getActiveBlocks()));
if (activeBlocks.isEmpty()) {
// Nothing to cancel
return;
}
final DBRBlockingObject lastBlock = activeBlocks.remove(activeBlocks.size() - 1);
try {
new JobCanceler(lastBlock).schedule();
} catch (Exception e) {
// If this happens during shutdown and job manager is not active
log.debug(e);
}
if (!activeBlocks.isEmpty()) {
DBPPreferenceStore preferenceStore;
if (activeBlocks.get(0) instanceof DBCSession) {
DBPDataSource dataSource = ((DBCSession) activeBlocks.get(0)).getDataSource();
if (dataSource == null) {
return;
}
preferenceStore = dataSource.getContainer().getPreferenceStore();
} else {
preferenceStore = ModelPreferences.getPreferences();
}
int cancelCheckTimeout = preferenceStore.getInt(ModelPreferences.EXECUTE_CANCEL_CHECK_TIMEOUT);
if (cancelCheckTimeout > 0) {
// There are other blocks. If last one can't be canceled then try others
Job cancelChecker = new // $NON-N LS-1$
Job(// $NON-N LS-1$
"Cancel checker block") {
{
setSystem(true);
setUser(false);
}
@Override
protected IStatus run(IProgressMonitor monitor) {
if (!finished) {
DBRBlockingObject nextBlock = activeBlocks.remove(activeBlocks.size() - 1);
new JobCanceler(nextBlock).schedule();
if (!activeBlocks.isEmpty()) {
schedule(cancelCheckTimeout);
}
}
return Status.OK_STATUS;
}
};
cancelChecker.schedule(cancelCheckTimeout);
}
}
}
Aggregations