提交 d1b95751 编写于 作者: J jurgen

Properties model refactoring

Former-commit-id: 413c23d1
上级 078eb939
......@@ -95,8 +95,6 @@ public @interface Property
String helpContextId() default ""; //NON-NLS-1
Class<? extends ILabelProvider> labelProvider() default ILabelProvider.class;
Class<? extends IPropertyValueTransformer> valueTransformer() default IPropertyValueTransformer.class;
Class<? extends IPropertyValueListProvider> listProvider() default IPropertyValueListProvider.class;
......
......@@ -31,6 +31,7 @@ import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.model.*;
import org.jkiss.dbeaver.model.struct.*;
import org.jkiss.dbeaver.ui.properties.PropertyCollector;
import org.jkiss.dbeaver.ui.properties.PropertySourceDelegate;
/**
* Navigator AdapterFactory
......@@ -104,11 +105,18 @@ public class DBNAdapterFactory implements IAdapterFactory
if (dbObject instanceof IPropertySource) {
return dbObject;
}
if (dbObject instanceof DBPPropertySource) {
return new PropertySourceDelegate((DBPPropertySource) dbObject);
}
if (dbObject instanceof IAdaptable) {
Object adapter = ((IAdaptable) dbObject).getAdapter(IPropertySource.class);
if (adapter != null) {
return adapter;
}
adapter = ((IAdaptable) dbObject).getAdapter(DBPPropertySource.class);
if (adapter != null) {
return new PropertySourceDelegate((DBPPropertySource) adapter);
}
}
if (dbObject != null) {
PropertyCollector props = new PropertyCollector(adaptableObject, dbObject , true);
......@@ -119,7 +127,7 @@ public class DBNAdapterFactory implements IAdapterFactory
props.addProperty(null, "name", CoreMessages.model_navigator_Name, meta.getName()); //$NON-NLS-1$
props.addProperty(null, "desc", CoreMessages.model_navigator_Description, meta.getDescription()); //$NON-NLS-1$
}
return props;
return new PropertySourceDelegate(props);
}
} else if (adapterType == IWorkbenchAdapter.class) {
// Workbench adapter
......
......@@ -23,7 +23,6 @@ import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISaveablePart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.views.properties.IPropertySource;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
......@@ -1014,7 +1013,7 @@ public class DataSourceDescriptor
{
if (DBSDataSourceContainer.class.isAssignableFrom(adapter)) {
return this;
} else if (adapter == IPropertySource.class) {
} else if (adapter == DBPPropertySource.class) {
PropertyCollector coll = new PropertyCollector(this, true);
coll.collectProperties();
if (dataSource != null) {
......
......@@ -90,6 +90,7 @@ import org.jkiss.dbeaver.ui.controls.lightgrid.IGridLabelProvider;
import org.jkiss.dbeaver.ui.controls.resultset.*;
import org.jkiss.dbeaver.ui.dialogs.ConfirmationDialog;
import org.jkiss.dbeaver.ui.properties.PropertyCollector;
import org.jkiss.dbeaver.ui.properties.PropertySourceDelegate;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.CommonUtils;
......@@ -946,7 +947,7 @@ public class SpreadsheetPresentation extends AbstractPresentation implements IRe
PropertyCollector props = new PropertyCollector(valueController.getBinding().getAttribute(), false);
props.collectProperties();
valueController.getValueHandler().contributeProperties(props, valueController);
return props;
return new PropertySourceDelegate(props);
}
return null;
}
......
......@@ -18,12 +18,12 @@
package org.jkiss.dbeaver.ui.properties;
import org.eclipse.ui.views.properties.IPropertySource2;
import org.jkiss.dbeaver.model.DBPPropertySource;
/**
* Property source which allows editing of multiple objects.
*/
public interface IPropertySourceMulti extends IPropertySource2 {
public interface IPropertySourceMulti extends DBPPropertySource {
boolean isPropertySet(Object object, ObjectPropertyDescriptor id);
......
......@@ -18,23 +18,13 @@
package org.jkiss.dbeaver.ui.properties;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.IFontProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.jkiss.dbeaver.model.DBPPersistedObject;
import org.jkiss.dbeaver.model.DBPPropertyDescriptor;
import org.jkiss.dbeaver.model.DBPPropertySource;
import org.jkiss.dbeaver.model.meta.IPropertyValueTransformer;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.utils.BeanUtils;
import org.jkiss.utils.CommonUtils;
import org.osgi.framework.Bundle;
......@@ -47,13 +37,12 @@ import java.util.ResourceBundle;
/**
* ObjectPropertyDescriptor
*/
public class ObjectPropertyDescriptor extends ObjectAttributeDescriptor implements DBPPropertyDescriptor, IPropertyDescriptor, IPropertyValueListProvider<Object>
public class ObjectPropertyDescriptor extends ObjectAttributeDescriptor implements DBPPropertyDescriptor, IPropertyValueListProvider<Object>
{
private final Property propInfo;
private final String propName;
private final String propDescription;
private Method setter;
private ILabelProvider labelProvider;
private IPropertyValueTransformer valueTransformer;
private final Class<?> declaringClass;
......@@ -78,19 +67,6 @@ public class ObjectPropertyDescriptor extends ObjectAttributeDescriptor implemen
}
}
// Obtain label provider
Class<? extends ILabelProvider> labelProviderClass = propInfo.labelProvider();
if (labelProviderClass != null && labelProviderClass != ILabelProvider.class) {
try {
this.labelProvider = labelProviderClass.newInstance();
} catch (Throwable e) {
log.warn(e);
}
}
if (this.labelProvider == null) {
this.labelProvider = new DefaultLabelProvider();
}
// Obtain value transformer
Class<? extends IPropertyValueTransformer> valueTransformerClass = propInfo.valueTransformer();
if (valueTransformerClass != null && valueTransformerClass != IPropertyValueTransformer.class) {
......@@ -138,12 +114,6 @@ public class ObjectPropertyDescriptor extends ObjectAttributeDescriptor implemen
return valueTransformer;
}
@Override
public CellEditor createPropertyEditor(Composite parent)
{
return UIUtils.createPropertyEditor(parent, getSource(), this);
}
@Override
public boolean isEditable(Object object)
{
......@@ -183,31 +153,6 @@ public class ObjectPropertyDescriptor extends ObjectAttributeDescriptor implemen
return propName;
}
@Override
public String[] getFilterFlags()
{
return null;
}
@Override
public Object getHelpContextIds()
{
return propInfo.helpContextId();
}
@Override
public ILabelProvider getLabelProvider()
{
return this.labelProvider;
}
@Override
public boolean isCompatibleWith(IPropertyDescriptor anotherProperty)
{
return anotherProperty instanceof ObjectPropertyDescriptor &&
((ObjectPropertyDescriptor)anotherProperty).propInfo == propInfo;
}
public Object readValue(Object object, DBRProgressMonitor progressMonitor)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
......@@ -363,36 +308,5 @@ public class ObjectPropertyDescriptor extends ObjectAttributeDescriptor implemen
return string;
}
private class DefaultLabelProvider extends LabelProvider implements IFontProvider {
@Override
public Image getImage(Object element)
{
// if (getSource() instanceof IPropertySourceEditable) {
// if (isReadOnly()) {
// return DBIcon.BULLET_GREEN.getImage();
// } else {
// return DBIcon.BULLET_BLACK.getImage();
// }
// }
return null;
}
@Override
public String getText(Object element)
{
return element == null ?
"" :
element instanceof DBSObject ?
((DBSObject)element).getName() :
element.toString();
}
@Override
public Font getFont(Object element)
{
return null;
}
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* 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.ui.properties;
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.eclipse.ui.views.properties.IPropertySource2;
import org.jkiss.dbeaver.model.DBPPropertyDescriptor;
import org.jkiss.dbeaver.model.DBPPropertySource;
import org.jkiss.dbeaver.ui.UIUtils;
/**
* PropertyDescriptorDelegate
*/
public class PropertyDescriptorDelegate implements IPropertyDescriptor
{
private final DBPPropertySource propSource;
private final DBPPropertyDescriptor source;
public PropertyDescriptorDelegate(DBPPropertySource propSource, DBPPropertyDescriptor source) {
this.propSource = propSource;
this.source = source;
}
@Override
public CellEditor createPropertyEditor(Composite parent) {
return UIUtils.createCellEditor(parent, propSource, source);
}
@Override
public String getCategory() {
return source.getCategory();
}
@Override
public String getDescription() {
return source.getDescription();
}
@Override
public String getDisplayName() {
return source.getDisplayName();
}
@Override
public String[] getFilterFlags() {
return null;
}
@Override
public Object getHelpContextIds() {
return null;
}
@Override
public Object getId() {
return source.getId();
}
@Override
public ILabelProvider getLabelProvider() {
return null;
}
@Override
public boolean isCompatibleWith(IPropertyDescriptor anotherProperty) {
return false;
}
}
\ No newline at end of file
......@@ -17,17 +17,12 @@
*/
package org.jkiss.dbeaver.ui.properties;
import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.core.Log;
import org.eclipse.core.runtime.IConfigurationElement;
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.dbeaver.model.DBPPropertyDescriptor;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.utils.ArrayUtils;
import org.jkiss.utils.CommonUtils;
......@@ -37,7 +32,7 @@ import java.util.List;
/**
* PropertyDescriptorEx
*/
public class PropertyDescriptorEx implements DBPPropertyDescriptor, IPropertyDescriptor, IPropertyValueListProvider<Object>
public class PropertyDescriptorEx implements DBPPropertyDescriptor, IPropertyValueListProvider<Object>
{
static final Log log = Log.getLog(PropertyDescriptorEx.class);
......@@ -121,15 +116,6 @@ public class PropertyDescriptorEx implements DBPPropertyDescriptor, IPropertyDes
this.editable = editable;
}
@Override
public CellEditor createPropertyEditor(Composite parent)
{
if (!editable) {
return null;
}
return UIUtils.createCellEditor(parent, null, this);
}
@Nullable
@Override
public String getCategory()
......@@ -144,19 +130,6 @@ public class PropertyDescriptorEx implements DBPPropertyDescriptor, IPropertyDes
return id;
}
@Override
public ILabelProvider getLabelProvider()
{
return null;
}
@Override
public boolean isCompatibleWith(IPropertyDescriptor anotherProperty)
{
return CommonUtils.equalObjects(category, anotherProperty.getCategory()) &&
CommonUtils.equalObjects(id, anotherProperty.getId());
}
@NotNull
@Override
public String getDisplayName()
......@@ -164,18 +137,6 @@ public class PropertyDescriptorEx implements DBPPropertyDescriptor, IPropertyDes
return name;
}
@Override
public String[] getFilterFlags()
{
return new String[0]; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public Object getHelpContextIds()
{
return null;
}
@Override
public String getDescription()
{
......
......@@ -21,7 +21,6 @@ import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.jface.viewers.IFilter;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.core.Log;
import org.jkiss.dbeaver.model.DBPContextProvider;
......@@ -119,12 +118,6 @@ public abstract class PropertySourceAbstract implements DBPPropertySource, IProp
return object;
}
@Override
public IPropertyDescriptor[] getPropertyDescriptors()
{
return props.toArray(new IPropertyDescriptor[props.size()]);
}
@Override
public DBPPropertyDescriptor[] getPropertyDescriptors2() {
return props.toArray(new DBPPropertyDescriptor[props.size()]);
......
......@@ -17,11 +17,6 @@
*/
package org.jkiss.dbeaver.ui.properties;
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.eclipse.ui.views.properties.IPropertySource;
import org.jkiss.dbeaver.model.DBPPropertyDescriptor;
import org.jkiss.dbeaver.model.DBPPropertySource;
import org.jkiss.dbeaver.model.DBUtils;
......@@ -33,9 +28,9 @@ import java.util.List;
/**
* Simple property source which store properties in map
*/
public class PropertySourceCollection implements DBPPropertySource, IPropertySource {
public class PropertySourceCollection implements DBPPropertySource {
private List<IPropertyDescriptor> props = new ArrayList<IPropertyDescriptor>();
private List<DBPPropertyDescriptor> props = new ArrayList<DBPPropertyDescriptor>();
private List<Object> items;
......@@ -59,12 +54,6 @@ public class PropertySourceCollection implements DBPPropertySource, IPropertySou
return props.toArray(new DBPPropertyDescriptor[props.size()]);
}
@Override
public IPropertyDescriptor[] getPropertyDescriptors()
{
return props.toArray(new IPropertyDescriptor[props.size()]);
}
@Override
public Object getPropertyValue(Object id)
{
......@@ -108,7 +97,7 @@ public class PropertySourceCollection implements DBPPropertySource, IPropertySou
return false;
}
private class ItemPropertyDescriptor implements DBPPropertyDescriptor, IPropertyDescriptor {
private class ItemPropertyDescriptor implements DBPPropertyDescriptor {
private Integer id;
private Object item;
......@@ -117,11 +106,6 @@ public class PropertySourceCollection implements DBPPropertySource, IPropertySou
this.item = item;
}
@Override
public CellEditor createPropertyEditor(Composite composite) {
return null;
}
@Override
public String getCategory() {
return null;
......@@ -157,29 +141,9 @@ public class PropertySourceCollection implements DBPPropertySource, IPropertySou
return DBUtils.getObjectShortName(item);
}
@Override
public String[] getFilterFlags() {
return null;
}
@Override
public Object getHelpContextIds() {
return null;
}
@Override
public Object getId() {
return id;
}
@Override
public ILabelProvider getLabelProvider() {
return null;
}
@Override
public boolean isCompatibleWith(IPropertyDescriptor prop) {
return this.equals(prop);
}
}
}
......@@ -17,9 +17,6 @@
*/
package org.jkiss.dbeaver.ui.properties;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.IPropertySource2;
import org.jkiss.dbeaver.model.DBPPropertyDescriptor;
import org.jkiss.dbeaver.model.DBPPropertySource;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
......@@ -30,7 +27,7 @@ import java.util.*;
/**
* Simple property source which store properties in map
*/
public class PropertySourceCustom implements DBPPropertySource, IPropertySource2 {
public class PropertySourceCustom implements DBPPropertySource {
private List<DBPPropertyDescriptor> props = new ArrayList<DBPPropertyDescriptor>();
......@@ -107,12 +104,6 @@ public class PropertySourceCustom implements DBPPropertySource, IPropertySource2
return props.toArray(new DBPPropertyDescriptor[props.size()]);
}
@Override
public IPropertyDescriptor[] getPropertyDescriptors()
{
return props.toArray(new IPropertyDescriptor[props.size()]);
}
@Override
public Object getPropertyValue(Object id)
{
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* 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.ui.properties;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource2;
import org.jkiss.dbeaver.model.DBPPropertyDescriptor;
import org.jkiss.dbeaver.model.DBPPropertySource;
/**
* PropertySourceDelegate
*/
public class PropertySourceDelegate implements IPropertySource2
{
private final DBPPropertySource source;
public PropertySourceDelegate(DBPPropertySource source) {
this.source = source;
}
@Override
public boolean isPropertyResettable(Object id) {
return source.isPropertyResettable(id);
}
@Override
public Object getEditableValue() {
return source.getEditableValue();
}
@Override
public IPropertyDescriptor[] getPropertyDescriptors() {
DBPPropertyDescriptor[] src = source.getPropertyDescriptors2();
if (src == null) {
return null;
}
IPropertyDescriptor[] dst = new IPropertyDescriptor[src.length];
for (int i = 0; i < src.length; i++) {
dst[i] = new PropertyDescriptorDelegate(source, src[i]);
}
return dst;
}
@Override
public Object getPropertyValue(Object id) {
return source.getPropertyValue(id);
}
@Override
public boolean isPropertySet(Object id) {
return source.isPropertySet(id);
}
@Override
public void resetPropertyValue(Object id) {
source.resetPropertyValue(id);
}
@Override
public void setPropertyValue(Object id, Object value) {
source.setPropertyValue(id, value);
}
}
\ No newline at end of file
......@@ -78,7 +78,6 @@ public class PropertyTreeViewer extends TreeViewer {
//this.setLayoutData(gd);
super.setContentProvider(new PropsContentProvider());
//super.setLabelProvider(labelProvider);
final Tree treeControl = super.getTree();
if (parent.getLayout() instanceof GridLayout) {
GridData gd = new GridData(GridData.FILL_BOTH);
......
......@@ -55,7 +55,7 @@
<adapter type="org.jkiss.dbeaver.model.DBPQualifiedObject"/>
<adapter type="org.jkiss.dbeaver.model.struct.DBSObject"/>
<adapter type="org.jkiss.dbeaver.model.struct.DBSEntity"/>
<adapter type="org.eclipse.ui.views.properties.IPropertySource"/>
<adapter type="org.jkiss.dbeaver.model.DBPPropertySource"/>
</factory>
<factory adaptableType="org.eclipse.swt.widgets.Control" class="org.jkiss.dbeaver.ext.erd.editor.ERDEditorAdapter">
<adapter type="org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart"/>
......
......@@ -23,10 +23,10 @@ package org.jkiss.dbeaver.ext.erd.model;
import org.jkiss.dbeaver.core.Log;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.views.properties.IPropertySource;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.DBPNamedObject;
import org.jkiss.dbeaver.model.DBPPropertySource;
import org.jkiss.dbeaver.model.navigator.DBNDatabaseNode;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress;
......@@ -119,7 +119,7 @@ public abstract class ERDObject<OBJECT> implements IAdaptable, DBPNamedObject
@Override
public Object getAdapter(Class adapter) {
if (adapter == IPropertySource.class) {
if (adapter == DBPPropertySource.class) {
return getPropertyCollector();
}
return null;
......
......@@ -21,6 +21,7 @@ import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.gef.EditPart;
import org.jkiss.dbeaver.model.DBPNamedObject;
import org.jkiss.dbeaver.model.DBPObject;
import org.jkiss.dbeaver.model.DBPPropertySource;
import org.jkiss.dbeaver.model.DBPQualifiedObject;
import org.jkiss.dbeaver.model.navigator.DBNNode;
import org.jkiss.dbeaver.model.struct.DBSObject;
......@@ -48,6 +49,13 @@ public class ERDObjectAdapter implements IAdapterFactory {
}
}
}
} else if (DBPPropertySource.class.isAssignableFrom(adapterType)) {
if (adaptableObject instanceof EditPart) {
Object model = ((EditPart) adaptableObject).getModel();
if (model instanceof ERDObject) {
return ((ERDObject) model).getAdapter(adapterType);
}
}
}
return null;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册