提交 61a75824 编写于 作者: S serge-rider

#6030 GIS viewer: save/load srid and clip settings (per-attribute)

上级 e1bc341c
......@@ -33,10 +33,15 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.DBValueFormatting;
import org.jkiss.dbeaver.model.data.DBDAttributeBinding;
import org.jkiss.dbeaver.model.data.DBDDisplayFormat;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.gis.*;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.model.virtual.DBVEntity;
import org.jkiss.dbeaver.model.virtual.DBVEntityAttribute;
import org.jkiss.dbeaver.model.virtual.DBVUtils;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.ui.ActionUtils;
import org.jkiss.dbeaver.ui.DBeaverIcons;
......@@ -44,6 +49,7 @@ import org.jkiss.dbeaver.ui.UIIcon;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.css.CSSUtils;
import org.jkiss.dbeaver.ui.css.DBStyles;
import org.jkiss.dbeaver.ui.data.IAttributeController;
import org.jkiss.dbeaver.ui.data.IValueController;
import org.jkiss.dbeaver.ui.dialogs.DialogUtils;
import org.jkiss.dbeaver.ui.gis.GeometryDataUtils;
......@@ -70,6 +76,9 @@ public class GISLeafletViewer implements IGeometryValueEditor {
private static final String[] SUPPORTED_FORMATS = new String[] { "png", "gif", "bmp" };
private static final String PROP_FLIP_COORDINATES = "gis.flipCoords";
private static final String PROP_SRID = "gis.srid";
private final IValueController valueController;
private final Browser browser;
private DBGeometry[] lastValue;
......@@ -118,7 +127,23 @@ public class GISLeafletViewer implements IGeometryValueEditor {
GISEditorUtils.addRecentSRID(recentSRID);
}
}
//recentSRIDs.sort(Integer::compareTo);
}
{
// Check for save settings
if (valueController instanceof IAttributeController) {
DBDAttributeBinding binding = ((IAttributeController) valueController).getBinding();
if (binding.getEntityAttribute() != null) {
DBVEntity vEntity = DBVUtils.getVirtualEntity(binding, false);
if (vEntity != null) {
DBVEntityAttribute vAttr = vEntity.getVirtualAttribute(binding, false);
if (vAttr != null) {
this.flipCoordinates = CommonUtils.getBoolean(vAttr.getProperty(PROP_FLIP_COORDINATES), this.flipCoordinates);
this.sourceSRID = CommonUtils.toInt(vAttr.getProperty(PROP_SRID), this.sourceSRID);
}
}
}
}
}
}
......@@ -159,6 +184,7 @@ public class GISLeafletViewer implements IGeometryValueEditor {
}
GISViewerActivator.getDefault().getPreferences().setValue(PREF_RECENT_SRID_LIST, sridListStr.toString());
}
saveAttributeSettings();
}
public void setGeometryData(@Nullable DBGeometry[] values) throws DBException {
......@@ -467,6 +493,7 @@ public class GISLeafletViewer implements IGeometryValueEditor {
} catch (DBException e) {
DBWorkbench.getPlatformUI().showError("Render error", "Error rendering geometry", e);
}
saveAttributeSettings();
updateToolbar();
}
});
......@@ -494,6 +521,21 @@ public class GISLeafletViewer implements IGeometryValueEditor {
toolBarManager.update(true);
}
private void saveAttributeSettings() {
if (valueController instanceof IAttributeController) {
DBDAttributeBinding binding = ((IAttributeController) valueController).getBinding();
if (binding.getEntityAttribute() != null) {
DBVEntity vEntity = DBVUtils.getVirtualEntity(binding, true);
DBVEntityAttribute vAttr = vEntity.getVirtualAttribute(binding, true);
if (vAttr != null) {
vAttr.setProperty(PROP_FLIP_COORDINATES, String.valueOf(flipCoordinates));
vAttr.setProperty(PROP_SRID, String.valueOf(getValueSRID()));
}
valueController.getExecutionContext().getDataSource().getContainer().getRegistry().flushConfig();
}
}
}
private void updateControlsVisibility() {
GC gc = new GC(browser.getDisplay());
try {
......
......@@ -38,6 +38,7 @@ public class DBVEntityAttribute implements DBSEntityAttribute
private String defaultValue;
private String description;
private DBVTransformSettings transformSettings;
Map<String, String> properties;
public DBVEntityAttribute(DBVEntity entity, DBVEntityAttribute parent, String name) {
this.entity = entity;
......@@ -52,6 +53,9 @@ public class DBVEntityAttribute implements DBSEntityAttribute
for (DBVEntityAttribute child : copy.children) {
this.children.add(new DBVEntityAttribute(entity, this, child));
}
if (!CommonUtils.isEmpty(copy.properties)) {
this.properties = new LinkedHashMap<>(copy.properties);
}
}
@NotNull
......@@ -177,6 +181,28 @@ public class DBVEntityAttribute implements DBSEntityAttribute
this.transformSettings = transformSettings;
}
public Map<String, String> getProperties() {
return properties;
}
@Nullable
public String getProperty(String name)
{
return CommonUtils.isEmpty(properties) ? null : properties.get(name);
}
public void setProperty(String name, @Nullable String value)
{
if (properties == null) {
properties = new LinkedHashMap<>();
}
if (value == null) {
properties.remove(name);
} else {
properties.put(name, value);
}
}
public boolean hasValuableData() {
if (!CommonUtils.isEmpty(defaultValue) || !CommonUtils.isEmpty(description)) {
return true;
......@@ -188,6 +214,6 @@ public class DBVEntityAttribute implements DBSEntityAttribute
}
}
}
return transformSettings != null && transformSettings.hasValuableData();
return transformSettings != null && transformSettings.hasValuableData() || !CommonUtils.isEmpty(properties);
}
}
......@@ -24,10 +24,7 @@ import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.data.DBDAttributeTransformerDescriptor;
import org.jkiss.dbeaver.model.exec.DBCLogicalOperator;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSEntity;
import org.jkiss.dbeaver.model.struct.DBSEntityConstraintType;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.DBSObjectContainer;
import org.jkiss.dbeaver.model.struct.*;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.ArrayUtils;
import org.jkiss.utils.CommonUtils;
......@@ -206,6 +203,14 @@ public class DBVModel extends DBVContainer {
}
}
}
if (!CommonUtils.isEmpty(attr.properties)) {
for (Map.Entry<String, String> prop : attr.properties.entrySet()) {
xml.startElement(TAG_PROPERTY);
xml.addAttribute(ATTR_NAME, prop.getKey());
xml.addAttribute(ATTR_VALUE, prop.getValue());
xml.endElement();
}
}
}
}
// Constraints
......@@ -227,7 +232,10 @@ public class DBVModel extends DBVContainer {
xml.startElement(TAG_ASSOCIATION);
DBSEntity refEntity = fk.getAssociatedEntity();
xml.addAttribute(ATTR_ENTITY, DBUtils.getObjectFullId(refEntity));
xml.addAttribute(ATTR_CONSTRAINT, fk.getReferencedConstraint().getName());
DBSEntityConstraint refConstraint = fk.getReferencedConstraint();
if (refConstraint != null) {
xml.addAttribute(ATTR_CONSTRAINT, refConstraint.getName());
}
for (DBVEntityForeignKeyColumn cc : CommonUtils.safeCollection(fk.getAttributeReferences(null))) {
xml.startElement(TAG_ATTRIBUTE);
xml.addAttribute(ATTR_NAME, cc.getAttributeName());
......@@ -322,6 +330,10 @@ public class DBVModel extends DBVContainer {
curTransformSettings.setTransformOption(
atts.getValue(ATTR_NAME),
atts.getValue(ATTR_VALUE));
} else if (curAttribute != null) {
curAttribute.setProperty(
atts.getValue(ATTR_NAME),
atts.getValue(ATTR_VALUE));
} else if (curEntity != null) {
curEntity.setProperty(
atts.getValue(ATTR_NAME),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册