提交 fcb00fca 编写于 作者: S Serge Rider

GIS viewer model refactoring

上级 339938cf
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.gis;
/**
* Geometry value editor
*/
public interface IGeometryValueEditor {
int getValueSRID();
void setValueSRID(int srid);
}
......@@ -29,14 +29,12 @@ import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.*;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
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.DBDDisplayFormat;
import org.jkiss.dbeaver.model.data.DBDValueHandler;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.gis.*;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
......@@ -48,6 +46,7 @@ import org.jkiss.dbeaver.ui.data.IValueController;
import org.jkiss.dbeaver.ui.dialogs.DialogUtils;
import org.jkiss.dbeaver.ui.gis.GeometryDataUtils;
import org.jkiss.dbeaver.ui.gis.GeometryViewerConstants;
import org.jkiss.dbeaver.ui.gis.IGeometryValueEditor;
import org.jkiss.dbeaver.ui.gis.internal.GISViewerActivator;
import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
......@@ -61,7 +60,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class GISLeafletViewer {
public class GISLeafletViewer implements IGeometryValueEditor {
private static final Log log = Log.getLog(GISLeafletViewer.class);
......@@ -125,7 +124,14 @@ public class GISLeafletViewer {
}
}
private void setSourceSRID(int srid) {
@Override
public int getValueSRID() {
return actualSourceSRID != 0 ? actualSourceSRID :
defaultSRID != 0 ? defaultSRID : GeometryDataUtils.getDefaultSRID();
}
@Override
public void setValueSRID(int srid) {
if (srid == sourceSRID) {
//return;
}
......@@ -354,11 +360,6 @@ public class GISLeafletViewer {
return lastValue;
}
private int getCurrentSourceSRID() {
return actualSourceSRID != 0 ? actualSourceSRID :
defaultSRID != 0 ? defaultSRID : GeometryDataUtils.getDefaultSRID();
}
private void updateToolbar() {
toolBarManager.removeAll();
toolBarManager.add(new Action("Open in browser", DBeaverIcons.getImageDescriptor(UIIcon.BROWSER)) {
......@@ -506,7 +507,7 @@ public class GISLeafletViewer {
private MenuManager menuManager;
public ChangeCRSAction() {
super("EPSG:" + getCurrentSourceSRID(), Action.AS_DROP_DOWN_MENU);
super("EPSG:" + getValueSRID(), Action.AS_DROP_DOWN_MENU);
setImageDescriptor(DBeaverIcons.getImageDescriptor(UIIcon.CHART_LINE));
}
......@@ -514,9 +515,9 @@ public class GISLeafletViewer {
public void run() {
SelectSRIDDialog manageCRSDialog = new SelectSRIDDialog(
UIUtils.getActiveWorkbenchShell(),
getCurrentSourceSRID());
getValueSRID());
if (manageCRSDialog.open() == IDialogConstants.OK_ID) {
setSourceSRID(manageCRSDialog.getSelectedSRID());
setValueSRID(manageCRSDialog.getSelectedSRID());
}
}
......@@ -581,12 +582,12 @@ public class GISLeafletViewer {
@Override
public boolean isChecked() {
return srid == getCurrentSourceSRID();
return srid == getValueSRID();
}
@Override
public void run() {
setSourceSRID(srid);
setValueSRID(srid);
}
}
......
......@@ -23,14 +23,15 @@ import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.ui.data.IValueController;
import org.jkiss.dbeaver.ui.data.editors.StringInlineEditor;
import org.jkiss.dbeaver.ui.gis.IGeometryValueEditor;
import org.jkiss.dbeaver.ui.gis.IGeometryViewer;
import org.locationtech.jts.geom.Geometry;
/**
* GisAttribute.
* Edits value as string. Also manager SRID.
* GISTextViewer.
* Edits value as string. Also manages SRID.
*/
public class GISTextViewer extends StringInlineEditor implements IGeometryViewer {
public class GISTextViewer extends StringInlineEditor implements IGeometryViewer, IGeometryValueEditor {
private int valueSRID;
......@@ -63,4 +64,14 @@ public class GISTextViewer extends StringInlineEditor implements IGeometryViewer
return geometry;
}
@Override
public int getValueSRID() {
return valueSRID;
}
@Override
public void setValueSRID(int srid) {
this.valueSRID = srid;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册