提交 6ef4e7c4 编写于 作者: J jurgen

Preference store model

Former-commit-id: e40d6418
上级 baafbf41
......@@ -52,6 +52,7 @@ Export-Package: org.jkiss.dbeaver,
org.jkiss.dbeaver.runtime.jobs,
org.jkiss.dbeaver.runtime.load,
org.jkiss.dbeaver.runtime.load.jobs,
org.jkiss.dbeaver.runtime.preferences,
org.jkiss.dbeaver.runtime.qm,
org.jkiss.dbeaver.runtime.qm.meta,
org.jkiss.dbeaver.runtime.sql,
......
......@@ -21,7 +21,7 @@ import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
/**
* Property descriptor
* Property descriptor.
*/
public interface DBPPropertyDescriptor {
......@@ -29,7 +29,7 @@ public interface DBPPropertyDescriptor {
* Returns the id for this property. This object is used internally to distinguish one property descriptor from another.
*/
@NotNull
public Object getId();
Object getId();
/**
* Returns the name of the category to which this property belongs. Properties
......@@ -37,7 +37,7 @@ public interface DBPPropertyDescriptor {
* string is shown to the user
*/
@Nullable
public String getCategory();
String getCategory();
/**
* Returns the display name for this property. This localized string is shown to
......@@ -46,14 +46,14 @@ public interface DBPPropertyDescriptor {
* @return a displayable name
*/
@NotNull
public String getDisplayName();
String getDisplayName();
/**
* Returns a brief description of this property. This localized string is shown
* to the user when this property is selected.
*/
@Nullable
public String getDescription();
String getDescription();
/**
* Returns the type of this property. Types is a java class.
......
......@@ -22,24 +22,22 @@ package org.jkiss.dbeaver.model;
*/
public interface DBPPropertySource {
public Object getEditableValue();
Object getEditableValue();
public DBPPropertyDescriptor[] getPropertyDescriptors2();
DBPPropertyDescriptor[] getPropertyDescriptors2();
public Object getPropertyValue(Object id);
Object getPropertyValue(Object id);
public boolean isPropertySet(Object id);
boolean isPropertySet(Object id);
boolean isPropertyResettable(Object id);
public void resetPropertyValue(Object id);
void resetPropertyValue(Object id);
void resetPropertyValueToDefault(Object id);
public void setPropertyValue(Object id, Object value);
void setPropertyValue(Object id, Object value);
boolean isDirty(Object id);
boolean hasDefaultValue(Object id);
}
......@@ -22,7 +22,7 @@ import org.jkiss.dbeaver.model.data.DBDDataFormatter;
import org.jkiss.dbeaver.model.data.DBDDataFormatterProfile;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.ui.properties.PropertyDescriptorEx;
import org.jkiss.dbeaver.utils.SimplePreferenceStore;
import org.jkiss.dbeaver.runtime.preferences.SimplePreferenceStore;
import org.jkiss.utils.CommonUtils;
import java.io.IOException;
......
......@@ -25,7 +25,7 @@ import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.model.data.DBDDataFormatterProfile;
import org.jkiss.dbeaver.utils.SimplePreferenceStore;
import org.jkiss.dbeaver.runtime.preferences.SimplePreferenceStore;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.CommonUtils;
import org.jkiss.utils.xml.SAXListener;
......
......@@ -57,7 +57,7 @@ import org.jkiss.dbeaver.ui.dialogs.ConfirmationDialog;
import org.jkiss.dbeaver.ui.dialogs.connection.EditConnectionDialog;
import org.jkiss.dbeaver.ui.dialogs.connection.EditConnectionWizard;
import org.jkiss.dbeaver.ui.properties.PropertyCollector;
import org.jkiss.dbeaver.utils.SimplePreferenceStore;
import org.jkiss.dbeaver.runtime.preferences.SimplePreferenceStore;
import org.jkiss.utils.CommonUtils;
import java.lang.reflect.InvocationTargetException;
......
......@@ -19,7 +19,7 @@ package org.jkiss.dbeaver.registry;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.model.DBConstants;
import org.jkiss.dbeaver.utils.SimplePreferenceStore;
import org.jkiss.dbeaver.runtime.preferences.SimplePreferenceStore;
import org.jkiss.utils.CommonUtils;
import java.io.IOException;
......
......@@ -40,7 +40,7 @@ import org.jkiss.dbeaver.registry.encode.PasswordEncrypter;
import org.jkiss.dbeaver.registry.encode.SimpleStringEncrypter;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.utils.SimplePreferenceStore;
import org.jkiss.dbeaver.runtime.preferences.SimplePreferenceStore;
import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.CommonUtils;
......
package org.jkiss.dbeaver.utils;
package org.jkiss.dbeaver.runtime.preferences;
import org.eclipse.core.commands.common.EventManager;
import org.eclipse.jface.resource.JFaceResources;
......
package org.jkiss.dbeaver.utils;
package org.jkiss.dbeaver.runtime.preferences;
public class GlobalPreferenceStore extends AbstractPreferenceStore{
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.osgi.framework.Bundle;
public class BundlePreferenceStore extends AbstractPreferenceStore{
private final IEclipsePreferences defaultProps;
private final IEclipsePreferences props;
private boolean dirty = false;
public BundlePreferenceStore(Bundle bundle) {
defaultProps = DefaultScope.INSTANCE.getNode(bundle.getSymbolicName());
props = InstanceScope.INSTANCE.getNode(bundle.getSymbolicName());
}
@Override
public boolean contains(String name) {
return false;
return props.get(name, null) != null || defaultProps.get(name, null) != null;
}
@Override
public boolean getBoolean(String name) {
return false;
return props.get(name, null) != null ?
props.getBoolean(name, BOOLEAN_DEFAULT_DEFAULT) :
defaultProps.get(name, null) != null ?
defaultProps.getBoolean(name, BOOLEAN_DEFAULT_DEFAULT) :
BOOLEAN_DEFAULT_DEFAULT;
}
@Override
public double getDouble(String name) {
return 0;
return props.get(name, null) != null ?
props.getDouble(name, DOUBLE_DEFAULT_DEFAULT) :
defaultProps.get(name, null) != null ?
defaultProps.getDouble(name, DOUBLE_DEFAULT_DEFAULT) :
DOUBLE_DEFAULT_DEFAULT;
}
@Override
public float getFloat(String name) {
return 0;
return props.get(name, null) != null ?
props.getFloat(name, FLOAT_DEFAULT_DEFAULT) :
defaultProps.get(name, null) != null ?
defaultProps.getFloat(name, FLOAT_DEFAULT_DEFAULT) :
FLOAT_DEFAULT_DEFAULT;
}
@Override
public int getInt(String name) {
return 0;
return props.get(name, null) != null ?
props.getInt(name, INT_DEFAULT_DEFAULT) :
defaultProps.get(name, null) != null ?
defaultProps.getInt(name, INT_DEFAULT_DEFAULT) :
INT_DEFAULT_DEFAULT;
}
@Override
public long getLong(String name) {
return 0;
return props.get(name, null) != null ?
props.getLong(name, LONG_DEFAULT_DEFAULT) :
defaultProps.get(name, null) != null ?
defaultProps.getLong(name, LONG_DEFAULT_DEFAULT) :
LONG_DEFAULT_DEFAULT;
}
@Override
public String getString(String name) {
return null;
return props.get(name, null) != null ?
props.get(name, STRING_DEFAULT_DEFAULT) :
defaultProps.get(name, null) != null ?
defaultProps.get(name, STRING_DEFAULT_DEFAULT) :
STRING_DEFAULT_DEFAULT;
}
@Override
public boolean getDefaultBoolean(String name) {
return false;
return defaultProps.getBoolean(name, BOOLEAN_DEFAULT_DEFAULT);
}
@Override
public double getDefaultDouble(String name) {
return 0;
return defaultProps.getDouble(name, DOUBLE_DEFAULT_DEFAULT);
}
@Override
public float getDefaultFloat(String name) {
return 0;
return defaultProps.getFloat(name, FLOAT_DEFAULT_DEFAULT);
}
@Override
public int getDefaultInt(String name) {
return 0;
return defaultProps.getInt(name, INT_DEFAULT_DEFAULT);
}
@Override
public long getDefaultLong(String name) {
return 0;
return defaultProps.getLong(name, LONG_DEFAULT_DEFAULT);
}
@Override
public String getDefaultString(String name) {
return null;
return defaultProps.get(name, STRING_DEFAULT_DEFAULT);
}
@Override
public boolean isDefault(String name) {
return false;
return props.get(name, null) == null && defaultProps.get(name, null) != null;
}
@Override
public boolean needsSaving() {
return false;
return dirty;
}
@Override
public void setDefault(String name, double value) {
defaultProps.putDouble(name, value);
}
@Override
public void setDefault(String name, float value) {
defaultProps.putFloat(name, value);
}
@Override
public void setDefault(String name, int value) {
defaultProps.putInt(name, value);
}
@Override
public void setDefault(String name, long value) {
defaultProps.putLong(name, value);
}
@Override
public void setDefault(String name, String defaultObject) {
defaultProps.put(name, defaultObject);
}
@Override
public void setDefault(String name, boolean value) {
defaultProps.putBoolean(name, value);
}
@Override
......
......@@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.utils;
package org.jkiss.dbeaver.runtime.preferences;
import org.eclipse.core.commands.common.EventManager;
import org.eclipse.jface.preference.IPersistentPreferenceStore;
......
......@@ -25,7 +25,7 @@ import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.core.Log;
import org.jkiss.dbeaver.registry.DataSourceProviderDescriptor;
import org.jkiss.dbeaver.registry.DataSourceProviderRegistry;
import org.jkiss.dbeaver.utils.SimplePreferenceStore;
import org.jkiss.dbeaver.runtime.preferences.SimplePreferenceStore;
import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.utils.CommonUtils;
import org.osgi.framework.Bundle;
......
......@@ -27,7 +27,7 @@ import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.registry.DataSourceDescriptor;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.utils.SimplePreferenceStore;
import org.jkiss.dbeaver.runtime.preferences.SimplePreferenceStore;
/**
* PrefPageDataEditor
......
......@@ -29,7 +29,7 @@ import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.registry.DataSourceDescriptor;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.utils.SimplePreferenceStore;
import org.jkiss.dbeaver.runtime.preferences.SimplePreferenceStore;
/**
* PrefPageMetaData
......
......@@ -32,7 +32,7 @@ import org.jkiss.dbeaver.registry.DataSourceDescriptor;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.resultset.spreadsheet.Spreadsheet;
import org.jkiss.dbeaver.utils.SimplePreferenceStore;
import org.jkiss.dbeaver.runtime.preferences.SimplePreferenceStore;
import org.jkiss.utils.CommonUtils;
/**
......
......@@ -34,7 +34,7 @@ import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditorInput;
import org.jkiss.dbeaver.ui.editors.sql.SQLPreferenceConstants;
import org.jkiss.dbeaver.utils.SimplePreferenceStore;
import org.jkiss.dbeaver.runtime.preferences.SimplePreferenceStore;
import java.util.HashMap;
import java.util.Map;
......
......@@ -29,7 +29,7 @@ import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.runtime.sql.SQLScriptCommitType;
import org.jkiss.dbeaver.runtime.sql.SQLScriptErrorHandling;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.utils.SimplePreferenceStore;
import org.jkiss.dbeaver.runtime.preferences.SimplePreferenceStore;
import org.jkiss.utils.CommonUtils;
/**
......
......@@ -18,6 +18,7 @@
package org.jkiss.dbeaver.ui.properties;
import org.eclipse.jface.viewers.IFilter;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.core.Log;
import org.jkiss.dbeaver.model.DBPPropertySource;
import org.jkiss.dbeaver.model.meta.IPropertyCacheValidator;
......@@ -98,6 +99,7 @@ public abstract class ObjectAttributeDescriptor {
return orderNumber;
}
@NotNull
public String getId()
{
return id;
......
......@@ -18,6 +18,7 @@
package org.jkiss.dbeaver.ui.properties;
import org.eclipse.core.runtime.Platform;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.DBPPersistedObject;
import org.jkiss.dbeaver.model.DBPPropertyDescriptor;
import org.jkiss.dbeaver.model.DBPPropertySource;
......@@ -147,6 +148,7 @@ public class ObjectPropertyDescriptor extends ObjectAttributeDescriptor implemen
return propDescription;
}
@NotNull
@Override
public String getDisplayName()
{
......
......@@ -260,11 +260,6 @@ public abstract class PropertySourceAbstract implements DBPPropertySource, IProp
throw new UnsupportedOperationException("Cannot reset property in non-editable property source");
}
@Override
public boolean hasDefaultValue(Object id) {
return false;
}
@Override
public final void setPropertyValue(Object id, Object value)
{
......
......@@ -17,6 +17,7 @@
*/
package org.jkiss.dbeaver.ui.properties;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.DBPPropertyDescriptor;
import org.jkiss.dbeaver.model.DBPPropertySource;
import org.jkiss.dbeaver.model.DBUtils;
......@@ -92,11 +93,6 @@ public class PropertySourceCollection implements DBPPropertySource {
return false;
}
@Override
public boolean hasDefaultValue(Object id) {
return false;
}
private class ItemPropertyDescriptor implements DBPPropertyDescriptor {
private Integer id;
private Object item;
......@@ -136,11 +132,13 @@ public class PropertySourceCollection implements DBPPropertySource {
return false;
}
@NotNull
@Override
public String getDisplayName() {
return DBUtils.getObjectShortName(item);
}
@NotNull
@Override
public Object getId() {
return id;
......
......@@ -162,12 +162,6 @@ public class PropertySourceCustom implements DBPPropertySource {
return !propValues.isEmpty();
}
@Override
public boolean hasDefaultValue(Object id)
{
return defaultValues.containsKey(id);
}
@Override
public void resetPropertyValueToDefault(Object id)
{
......
......@@ -21,6 +21,7 @@ import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.DBPPropertyDescriptor;
/**
......@@ -36,6 +37,7 @@ public class ProxyPropertyDescriptor implements DBPPropertyDescriptor
this.original = original;
}
@NotNull
@Override
public Object getId()
{
......@@ -74,6 +76,7 @@ public class ProxyPropertyDescriptor implements DBPPropertyDescriptor
return original.isEditable(object);
}
@NotNull
@Override
public String getDisplayName()
{
......
......@@ -28,7 +28,7 @@ import org.jkiss.dbeaver.registry.DataSourceDescriptor;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.preferences.TargetPrefPage;
import org.jkiss.dbeaver.utils.SimplePreferenceStore;
import org.jkiss.dbeaver.runtime.preferences.SimplePreferenceStore;
/**
* PrefPageOracle
......
......@@ -162,11 +162,6 @@ public class PostgrePlanNode implements DBCPlanNode, DBPPropertySource {
return false;
}
@Override
public boolean hasDefaultValue(Object id) {
return false;
}
@Override
public String toString() {
StringBuilder title = new StringBuilder();
......
......@@ -127,9 +127,4 @@ public abstract class WMIPropertySource implements DBPPropertySource
return false;
}
@Override
public boolean hasDefaultValue(Object id) {
return false;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册