提交 03c544b3 编写于 作者: S Serge Rider

Content editor refactoring (+save fix)

上级 d40ef9a7
......@@ -54,6 +54,7 @@ Export-Package: org.jkiss.dbeaver,
org.jkiss.dbeaver.ui.data,
org.jkiss.dbeaver.ui.data.editors,
org.jkiss.dbeaver.ui.data.managers,
org.jkiss.dbeaver.ui.data.managers.stream,
org.jkiss.dbeaver.ui.data.registry,
org.jkiss.dbeaver.ui.dialogs,
org.jkiss.dbeaver.ui.dialogs.connection,
......@@ -69,7 +70,6 @@ Export-Package: org.jkiss.dbeaver,
org.jkiss.dbeaver.ui.editors.binary.dialogs,
org.jkiss.dbeaver.ui.editors.binary.pref,
org.jkiss.dbeaver.ui.editors.content,
org.jkiss.dbeaver.ui.editors.content.parts,
org.jkiss.dbeaver.ui.editors.data,
org.jkiss.dbeaver.ui.editors.entity,
org.jkiss.dbeaver.ui.editors.entity.handlers,
......
......@@ -25,6 +25,7 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.data.DBDContent;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSAttributeBase;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
/**
* Stream value manager
......@@ -39,7 +40,7 @@ public interface IStreamValueManager {
NONE, // Doesn't support
}
MatchType matchesTo(@NotNull DBRProgressMonitor monitor, @NotNull DBSAttributeBase attribute, @Nullable DBDContent value);
MatchType matchesTo(@NotNull DBRProgressMonitor monitor, @NotNull DBSTypedObject attribute, @Nullable DBDContent value);
IStreamValueEditor createPanelEditor(@NotNull IValueController controller)
throws DBException;
......
......@@ -66,7 +66,7 @@ public class XMLPanelEditor extends ContentPanelEditor {
try {
monitor.subTask("Prime XML value");
IEditorInput sqlInput = new ContentEditorInput(valueController, null, monitor);
IEditorInput sqlInput = new ContentEditorInput(valueController, null, null, monitor);
editor.init(subSite, sqlInput);
} catch (Exception e) {
log.error(e);
......
......@@ -20,34 +20,36 @@ package org.jkiss.dbeaver.ui.data.managers;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.ui.IEditorPart;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.model.DBPPropertyManager;
import org.jkiss.dbeaver.model.data.*;
import org.jkiss.dbeaver.model.data.DBDContent;
import org.jkiss.dbeaver.model.data.DBDContentCached;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIIcon;
import org.jkiss.dbeaver.ui.data.editors.XMLPanelEditor;
import org.jkiss.dbeaver.ui.dialogs.DialogUtils;
import org.jkiss.dbeaver.ui.data.IStreamValueManager;
import org.jkiss.dbeaver.ui.data.IValueController;
import org.jkiss.dbeaver.ui.data.IValueEditor;
import org.jkiss.dbeaver.ui.data.editors.ContentInlineEditor;
import org.jkiss.dbeaver.ui.data.editors.ContentPanelEditor;
import org.jkiss.dbeaver.ui.data.editors.XMLPanelEditor;
import org.jkiss.dbeaver.ui.data.registry.StreamValueManagerDescriptor;
import org.jkiss.dbeaver.ui.data.registry.ValueManagerRegistry;
import org.jkiss.dbeaver.ui.dialogs.DialogUtils;
import org.jkiss.dbeaver.ui.dialogs.data.TextViewDialog;
import org.jkiss.dbeaver.ui.editors.content.ContentEditor;
import org.jkiss.dbeaver.ui.editors.content.ContentEditorPart;
import org.jkiss.dbeaver.ui.editors.content.parts.ContentBinaryEditorPart;
import org.jkiss.dbeaver.ui.editors.content.parts.ContentImageEditorPart;
import org.jkiss.dbeaver.ui.editors.content.parts.ContentTextEditorPart;
import org.jkiss.dbeaver.ui.editors.content.parts.ContentXMLEditorPart;
import org.jkiss.dbeaver.utils.ContentUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* JDBC Content value handler.
......@@ -91,21 +93,59 @@ public class ContentValueManager extends BaseValueManager {
return new TextViewDialog(controller);
} else if (value instanceof DBDContent) {
DBDContent content = (DBDContent)value;
boolean isText = ContentUtils.isTextContent(content);
List<ContentEditorPart> parts = new ArrayList<>();
Map<StreamValueManagerDescriptor, IStreamValueManager.MatchType> streamManagers =
ValueManagerRegistry.getInstance().getApplicableStreamManagers(VoidProgressMonitor.INSTANCE, controller.getValueType(), content);
//boolean isText = ContentUtils.isTextContent(content);
List<IEditorPart> parts = new ArrayList<>();
IEditorPart defaultPart = null;
IStreamValueManager.MatchType defaultMatch = null;
for (Map.Entry<StreamValueManagerDescriptor, IStreamValueManager.MatchType> entry : streamManagers.entrySet()) {
IStreamValueManager streamValueManager = entry.getKey().getInstance();
try {
IEditorPart editorPart = streamValueManager.createEditorPart(controller);
IStreamValueManager.MatchType matchType = entry.getValue();
if (defaultPart == null) {
defaultPart = editorPart;
defaultMatch = matchType;
} else {
boolean setDefault = false;
switch (matchType) {
case EXCLUSIVE:
case PRIMARY:
setDefault = true;
break;
case DEFAULT:
setDefault = (defaultMatch == IStreamValueManager.MatchType.APPLIES);
break;
default:
break;
}
if (setDefault) {
defaultPart = editorPart;
defaultMatch = matchType;
}
}
parts.add(editorPart);
} catch (DBException e) {
log.error(e);
}
}
/*
if (isText) {
parts.add(new ContentTextEditorPart());
parts.add(new TextEditorPart());
if (ContentUtils.isXML(content)) {
parts.add(new ContentXMLEditorPart());
}
} else {
parts.add(new ContentBinaryEditorPart());
parts.add(new ContentTextEditorPart());
parts.add(new ContentImageEditorPart());
parts.add(new BinaryEditorPart());
parts.add(new TextEditorPart());
parts.add(new ImageEditorPart());
}
*/
return ContentEditor.openEditor(
controller,
parts.toArray(new ContentEditorPart[parts.size()]));
parts.toArray(new IEditorPart[parts.size()]),
defaultPart);
} else {
controller.showMessage(CoreMessages.model_jdbc_unsupported_content_value_type_, true);
return null;
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 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.editors.content;
import org.eclipse.ui.IEditorActionBarContributor;
import org.eclipse.ui.IEditorPart;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.DBPImage;
import org.jkiss.dbeaver.ui.ISingleControlEditor;
import javax.activation.MimeType;
/**
* Database content editor
*/
public interface ContentEditorPart extends IEditorPart, ISingleControlEditor {
void initPart(IEditorPart contentEditor, @Nullable MimeType mimeType);
IEditorActionBarContributor getActionBarContributor();
String getContentTypeTitle();
DBPImage getContentTypeImage();
String getPreferredMimeType();
/**
* Maximum part length. If content length is more than this value then this part will be committed.
* @return max length
*/
long getMaxContentLength();
/**
* Preferred content part will be set as default part in content editor.
* @return true or false
*/
boolean isPreferredContent();
boolean isOptionalContent();
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 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.data.managers.stream;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IEditorPart;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.editors.binary.BinaryEditor;
/**
* CONTENT Binary Editor
*/
public class BinaryEditorPart extends BinaryEditor implements IEditorPart {
public BinaryEditorPart()
{
}
@Override
public String getTitle()
{
return "Binary";
}
@Override
public Image getTitleImage()
{
return DBeaverIcons.getImage(DBIcon.TYPE_BINARY);
}
}
......@@ -24,11 +24,10 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.data.DBDContent;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSAttributeBase;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.ui.data.IStreamValueEditor;
import org.jkiss.dbeaver.ui.data.IStreamValueManager;
import org.jkiss.dbeaver.ui.data.IValueController;
import org.jkiss.dbeaver.ui.editors.content.parts.ContentBinaryEditorPart;
/**
* Hex editor manager
......@@ -38,7 +37,7 @@ public class BinaryStreamValueManager implements IStreamValueManager {
private static final Log log = Log.getLog(BinaryStreamValueManager.class);
@Override
public MatchType matchesTo(@NotNull DBRProgressMonitor monitor, @NotNull DBSAttributeBase attribute, @Nullable DBDContent value) {
public MatchType matchesTo(@NotNull DBRProgressMonitor monitor, @NotNull DBSTypedObject attribute, @Nullable DBDContent value) {
// Applies to any values
return MatchType.APPLIES;
}
......@@ -52,7 +51,7 @@ public class BinaryStreamValueManager implements IStreamValueManager {
@Override
public IEditorPart createEditorPart(@NotNull IValueController controller) {
return new ContentBinaryEditorPart();
return new BinaryEditorPart();
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 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.editors.content.parts;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.*;
import org.eclipse.ui.part.EditorPart;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.model.DBPImage;
import org.jkiss.dbeaver.ui.controls.imageview.ImageEditor;
import org.jkiss.dbeaver.ui.editors.content.ContentEditorPart;
import org.jkiss.dbeaver.utils.ContentUtils;
import javax.activation.MimeType;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
/**
* CONTENT text editor
*/
public class ContentImageEditorPart extends EditorPart implements ContentEditorPart, IResourceChangeListener {
private static final Log log = Log.getLog(ContentImageEditorPart.class);
private ImageEditor imageViewer;
private boolean contentValid;
@Override
public void doSave(IProgressMonitor monitor) {
}
@Override
public void doSaveAs() {
}
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
setSite(site);
setInput(input);
ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
}
@Override
public void dispose()
{
ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
super.dispose();
}
@Override
public boolean isDirty() {
return false;
}
@Override
public boolean isSaveAsAllowed() {
return false;
}
@Override
public void createPartControl(Composite parent) {
imageViewer = new ImageEditor(parent, SWT.NONE);
loadImage();
}
private void loadImage() {
if (imageViewer == null || imageViewer.isDisposed()) {
return;
}
if (getEditorInput() instanceof IPathEditorInput) {
try {
final IPath absolutePath = ((IPathEditorInput)getEditorInput()).getPath();
File localFile = absolutePath.toFile();
if (localFile.exists()) {
try (InputStream inputStream = new FileInputStream(localFile)) {
contentValid = imageViewer.loadImage(inputStream);
imageViewer.update();
}
}
}
catch (Exception e) {
log.error("Can't load image contents", e);
}
}
}
@Override
public void setFocus() {
imageViewer.setFocus();
}
@Override
public void initPart(IEditorPart contentEditor, MimeType mimeType)
{
}
@Override
public IEditorActionBarContributor getActionBarContributor()
{
return null;
}
@Nullable
@Override
public Control getEditorControl()
{
return imageViewer;
}
@Override
public String getContentTypeTitle()
{
return "Image";
}
@Override
public DBPImage getContentTypeImage()
{
return DBIcon.TYPE_IMAGE;
}
@Override
public String getPreferredMimeType()
{
return "image";
}
@Override
public long getMaxContentLength()
{
return 20 * 1024 * 1024;
}
@Override
public boolean isPreferredContent()
{
return contentValid;
}
@Override
public boolean isOptionalContent()
{
return true;
}
@Override
public void resourceChanged(IResourceChangeEvent event) {
IResourceDelta delta = event.getDelta();
if (delta == null) {
return;
}
IEditorInput input = getEditorInput();
IPath localPath = null;
if (input instanceof IPathEditorInput) {
localPath = ((IPathEditorInput) input).getPath();
}
if (localPath == null) {
return;
}
localPath = ContentUtils.convertPathToWorkspacePath(localPath);
delta = delta.findMember(localPath);
if (delta == null) {
return;
}
if (delta.getKind() == IResourceDelta.CHANGED) {
// Refresh editor
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
loadImage();
}
});
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 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.data.managers.stream;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IPathEditorInput;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.controls.imageview.ImageEditor;
import org.jkiss.dbeaver.utils.ContentUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
/**
* CONTENT text editor
*/
public class ImageEditorPart extends EditorPart implements IResourceChangeListener {
private static final Log log = Log.getLog(ImageEditorPart.class);
private ImageEditor imageViewer;
private boolean contentValid;
@Override
public void doSave(IProgressMonitor monitor) {
}
@Override
public void doSaveAs() {
}
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
setSite(site);
setInput(input);
ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
}
@Override
public void dispose()
{
ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
super.dispose();
}
@Override
public boolean isDirty() {
return false;
}
@Override
public boolean isSaveAsAllowed() {
return false;
}
@Override
public void createPartControl(Composite parent) {
imageViewer = new ImageEditor(parent, SWT.NONE);
loadImage();
}
private void loadImage() {
if (imageViewer == null || imageViewer.isDisposed()) {
return;
}
if (getEditorInput() instanceof IPathEditorInput) {
try {
final IPath absolutePath = ((IPathEditorInput)getEditorInput()).getPath();
File localFile = absolutePath.toFile();
if (localFile.exists()) {
try (InputStream inputStream = new FileInputStream(localFile)) {
contentValid = imageViewer.loadImage(inputStream);
imageViewer.update();
}
}
}
catch (Exception e) {
log.error("Can't load image contents", e);
}
}
}
@Override
public void setFocus() {
imageViewer.setFocus();
}
@Override
public String getTitle()
{
return "Image";
}
@Override
public Image getTitleImage()
{
return DBeaverIcons.getImage(DBIcon.TYPE_IMAGE);
}
@Override
public void resourceChanged(IResourceChangeEvent event) {
IResourceDelta delta = event.getDelta();
if (delta == null) {
return;
}
IEditorInput input = getEditorInput();
IPath localPath = null;
if (input instanceof IPathEditorInput) {
localPath = ((IPathEditorInput) input).getPath();
}
if (localPath == null) {
return;
}
localPath = ContentUtils.convertPathToWorkspacePath(localPath);
delta = delta.findMember(localPath);
if (delta == null) {
return;
}
if (delta.getKind() == IResourceDelta.CHANGED) {
// Refresh editor
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
loadImage();
}
});
}
}
}
\ No newline at end of file
......@@ -29,12 +29,10 @@ import org.jkiss.dbeaver.model.data.DBDContent;
import org.jkiss.dbeaver.model.data.DBDContentStorage;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress;
import org.jkiss.dbeaver.model.struct.DBSAttributeBase;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.ui.data.IStreamValueEditor;
import org.jkiss.dbeaver.ui.data.IStreamValueManager;
import org.jkiss.dbeaver.ui.data.IValueController;
import org.jkiss.dbeaver.ui.editors.content.parts.ContentBinaryEditorPart;
import org.jkiss.dbeaver.ui.editors.content.parts.ContentImageEditorPart;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
......@@ -47,7 +45,7 @@ public class ImageStreamValueManager implements IStreamValueManager {
private static final Log log = Log.getLog(ImageStreamValueManager.class);
@Override
public MatchType matchesTo(@NotNull DBRProgressMonitor monitor, @NotNull DBSAttributeBase attribute, @Nullable DBDContent value) {
public MatchType matchesTo(@NotNull DBRProgressMonitor monitor, @NotNull DBSTypedObject attribute, @Nullable DBDContent value) {
// Applies to image values
ImageDetector imageDetector = new ImageDetector(value);
if (!DBUtils.isNullValue(value)) {
......@@ -65,7 +63,7 @@ public class ImageStreamValueManager implements IStreamValueManager {
@Override
public IEditorPart createEditorPart(@NotNull IValueController controller) {
return new ContentImageEditorPart();
return new ImageEditorPart();
}
private static class ImageDetector implements DBRRunnableWithProgress {
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 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.editors.content.parts;
import org.eclipse.ui.IEditorActionBarContributor;
import org.eclipse.ui.IEditorPart;
import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.model.DBPContextProvider;
import org.jkiss.dbeaver.model.DBPImage;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.ui.editors.content.ContentEditorPart;
import org.jkiss.dbeaver.ui.editors.text.BaseTextEditor;
import org.jkiss.dbeaver.ui.editors.text.FileRefDocumentProvider;
import org.jkiss.dbeaver.utils.MimeTypes;
import javax.activation.MimeType;
/**
* CONTENT text editor
*/
public class ContentTextEditorPart extends BaseTextEditor implements ContentEditorPart {
private IEditorPart contentEditor;
public ContentTextEditorPart() {
setDocumentProvider(new FileRefDocumentProvider());
}
@Override
public void initPart(IEditorPart contentEditor, MimeType mimeType)
{
this.contentEditor = contentEditor;
}
@Override
public IEditorActionBarContributor getActionBarContributor()
{
return null;
}
@Override
public String getContentTypeTitle()
{
return "Text";
}
@Override
public DBPImage getContentTypeImage()
{
return DBIcon.TYPE_TEXT;
}
@Override
public String getPreferredMimeType()
{
return MimeTypes.TEXT;
}
@Override
public long getMaxContentLength()
{
if (contentEditor instanceof DBPContextProvider) {
DBCExecutionContext context = ((DBPContextProvider) contentEditor).getExecutionContext();
if (context != null) {
return context.getDataSource().getContainer().getPreferenceStore().getInt(DBeaverPreferences.RS_EDIT_MAX_TEXT_SIZE);
}
}
return 10 * 1024 * 1024;
}
/**
* Always return false cos' text editor can load any binary content
* @return false
*/
@Override
public boolean isPreferredContent()
{
return false;
}
@Override
public boolean isOptionalContent()
{
return true;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 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.data.managers.stream;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IEditorPart;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.editors.text.BaseTextEditor;
import org.jkiss.dbeaver.ui.editors.text.FileRefDocumentProvider;
/**
* CONTENT text editor
*/
public class TextEditorPart extends BaseTextEditor implements IEditorPart {
public TextEditorPart() {
setDocumentProvider(new FileRefDocumentProvider());
}
@Override
public String getTitle()
{
return "Text";
}
@Override
public Image getTitleImage()
{
return DBeaverIcons.getImage(DBIcon.TYPE_TEXT);
}
}
......@@ -24,11 +24,10 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.data.DBDContent;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSAttributeBase;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.ui.data.IStreamValueEditor;
import org.jkiss.dbeaver.ui.data.IStreamValueManager;
import org.jkiss.dbeaver.ui.data.IValueController;
import org.jkiss.dbeaver.ui.editors.content.parts.ContentTextEditorPart;
import org.jkiss.dbeaver.utils.ContentUtils;
/**
......@@ -39,7 +38,7 @@ public class TextStreamValueManager implements IStreamValueManager {
private static final Log log = Log.getLog(TextStreamValueManager.class);
@Override
public MatchType matchesTo(@NotNull DBRProgressMonitor monitor, @NotNull DBSAttributeBase attribute, @Nullable DBDContent value) {
public MatchType matchesTo(@NotNull DBRProgressMonitor monitor, @NotNull DBSTypedObject attribute, @Nullable DBDContent value) {
// Applies to text values
return ContentUtils.isTextContent(value) ? MatchType.DEFAULT : MatchType.APPLIES;
}
......@@ -53,7 +52,7 @@ public class TextStreamValueManager implements IStreamValueManager {
@Override
public IEditorPart createEditorPart(@NotNull IValueController controller) {
return new ContentTextEditorPart();
return new TextEditorPart();
}
}
......@@ -99,7 +99,7 @@ public class ValueManagerRegistry {
return getInstance().getManager(dataSource, typedObject, valueType);
}
public Map<StreamValueManagerDescriptor, IStreamValueManager.MatchType> getApplicableStreamManagers(@NotNull DBRProgressMonitor monitor, @NotNull DBSAttributeBase attribute, @Nullable DBDContent value) {
public Map<StreamValueManagerDescriptor, IStreamValueManager.MatchType> getApplicableStreamManagers(@NotNull DBRProgressMonitor monitor, @NotNull DBSTypedObject attribute, @Nullable DBDContent value) {
Map<StreamValueManagerDescriptor, IStreamValueManager.MatchType> result = new LinkedHashMap<>();
for (StreamValueManagerDescriptor contentManager : streamManagers) {
IStreamValueManager.MatchType matchType = contentManager.getInstance().matchesTo(monitor, attribute, value);
......
......@@ -32,23 +32,21 @@ import org.eclipse.ui.*;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.data.DBDContent;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.utils.RuntimeUtils;
import org.jkiss.dbeaver.ui.data.IValueController;
import org.jkiss.dbeaver.ui.data.IValueEditorStandalone;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.data.IValueController;
import org.jkiss.dbeaver.ui.data.IValueEditorStandalone;
import org.jkiss.dbeaver.ui.dialogs.ColumnInfoPanel;
import org.jkiss.dbeaver.ui.editors.MultiPageAbstractEditor;
import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.dbeaver.utils.RuntimeUtils;
import javax.activation.MimeType;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
......@@ -65,12 +63,12 @@ public class ContentEditor extends MultiPageAbstractEditor implements IValueEdit
}
@Nullable
public static ContentEditor openEditor(IValueController valueController, ContentEditorPart[] editorParts)
public static ContentEditor openEditor(IValueController valueController, IEditorPart[] editorParts, IEditorPart defaultPart)
{
ContentEditorInput editorInput;
// Save data to file
try {
LOBInitializer initializer = new LOBInitializer(valueController, editorParts, null);
LOBInitializer initializer = new LOBInitializer(valueController, editorParts, defaultPart, null);
//valueController.getValueSite().getWorkbenchWindow().run(true, true, initializer);
DBeaverUI.runInProgressService(initializer);
editorInput = initializer.editorInput;
......@@ -98,24 +96,28 @@ public class ContentEditor extends MultiPageAbstractEditor implements IValueEdit
private static final Log log = Log.getLog(ContentEditor.class);
static class ContentPartInfo {
ContentEditorPart editorPart;
IEditorPart editorPart;
boolean isDefault;
boolean activated;
public int index = -1;
private ContentPartInfo(ContentEditorPart editorPart) {
private ContentPartInfo(IEditorPart editorPart, boolean isDefault) {
this.editorPart = editorPart;
this.isDefault = isDefault;
}
}
private static class LOBInitializer implements DBRRunnableWithProgress {
IValueController valueController;
ContentEditorPart[] editorParts;
IEditorPart[] editorParts;
IEditorPart defaultPart;
ContentEditorInput editorInput;
private LOBInitializer(IValueController valueController, ContentEditorPart[] editorParts, @Nullable ContentEditorInput editorInput)
private LOBInitializer(IValueController valueController, IEditorPart[] editorParts, IEditorPart defaultPart, @Nullable ContentEditorInput editorInput)
{
this.valueController = valueController;
this.editorParts = editorParts;
this.defaultPart = defaultPart;
this.editorInput = editorInput;
}
......@@ -127,6 +129,7 @@ public class ContentEditor extends MultiPageAbstractEditor implements IValueEdit
editorInput = new ContentEditorInput(
valueController,
editorParts,
defaultPart,
monitor);
} else {
editorInput.refreshContent(monitor, valueController);
......@@ -171,14 +174,14 @@ public class ContentEditor extends MultiPageAbstractEditor implements IValueEdit
public void run() {
try {
// Check for dirty parts
final List<ContentEditorPart> dirtyParts = new ArrayList<>();
final List<IEditorPart> dirtyParts = new ArrayList<>();
for (ContentPartInfo partInfo : contentParts) {
if (partInfo.activated && partInfo.editorPart.isDirty()) {
dirtyParts.add(partInfo.editorPart);
}
}
ContentEditorPart dirtyPart = null;
IEditorPart dirtyPart = null;
if (dirtyParts.isEmpty()) {
// No modified parts - no additional save required
} else if (dirtyParts.size() == 1) {
......@@ -236,13 +239,11 @@ public class ContentEditor extends MultiPageAbstractEditor implements IValueEdit
return;
}
MimeType mimeType = ContentUtils.getMimeType(content.getContentType());
// Fill nested editorParts info
ContentEditorPart[] editorParts = getEditorInput().getEditors();
for (ContentEditorPart editorPart : editorParts) {
contentParts.add(new ContentPartInfo(editorPart));
editorPart.initPart(this, mimeType);
IEditorPart[] editorParts = getEditorInput().getEditors();
for (IEditorPart editorPart : editorParts) {
contentParts.add(new ContentPartInfo(editorPart, editorPart == getEditorInput().getDefaultEditor()));
//editorPart.init(site, input);
}
ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
......@@ -303,60 +304,24 @@ public class ContentEditor extends MultiPageAbstractEditor implements IValueEdit
if (content == null) {
return;
}
String contentType = null;
try {
contentType = content.getContentType();
} catch (Exception e) {
log.error("Can't determine value content type", e);
}
long contentLength;
try {
contentLength = content.getContentLength();
} catch (Exception e) {
log.warn("Can't determine value content length", e);
// Get file length
contentLength = getEditorInput().getContentFile().length();
}
MimeType mimeType = ContentUtils.getMimeType(contentType);
IEditorPart defaultPage = null, preferredPage = null;
ContentPartInfo defaultPage = null;
for (ContentPartInfo contentPart : contentParts) {
ContentEditorPart editorPart = contentPart.editorPart;
if (contentLength > editorPart.getMaxContentLength()) {
continue;
}
if (preferredPage != null && editorPart.isOptionalContent()) {
// Do not add optional parts if we already have prefered one
continue;
if (contentPart.isDefault) {
defaultPage = contentPart;
}
IEditorPart editorPart = contentPart.editorPart;
try {
int index = addPage(editorPart, getEditorInput());
setPageText(index, editorPart.getContentTypeTitle());
setPageImage(index, DBeaverIcons.getImage(editorPart.getContentTypeImage()));
setPageText(index, editorPart.getTitle());
setPageImage(index, editorPart.getTitleImage());
contentPart.activated = true;
contentPart.index = index;
// Check MIME type
if (mimeType != null && mimeType.getPrimaryType().equals(editorPart.getPreferredMimeType())) {
defaultPage = editorPart;
}
if (editorPart.isPreferredContent()) {
preferredPage = editorPart;
}
} catch (PartInitException e) {
log.error(e);
}
}
if (preferredPage != null) {
// Remove all optional pages
for (ContentPartInfo contentPart : contentParts) {
if (contentPart.activated && contentPart.editorPart != preferredPage && contentPart.editorPart.isOptionalContent()) {
removePage(contentPart.index);
}
}
// Set default page
setActiveEditor(preferredPage);
} else if (defaultPage != null) {
setActiveEditor(defaultPage);
if (defaultPage != null) {
setActiveEditor(defaultPage.editorPart);
}
this.partsLoaded = true;
......@@ -473,8 +438,9 @@ public class ContentEditor extends MultiPageAbstractEditor implements IValueEdit
@Override
public void primeEditorValue(@Nullable Object value) throws DBException
{
IValueController valueController = getEditorInput().getValueController();
LOBInitializer initializer = new LOBInitializer(valueController, getEditorInput().getEditors(), getEditorInput());
ContentEditorInput input = getEditorInput();
IValueController valueController = input.getValueController();
LOBInitializer initializer = new LOBInitializer(valueController, input.getEditors(), input.getDefaultEditor(), input);
try {
//valueController.getValueSite().getWorkbenchWindow().run(true, true, initializer);
DBeaverUI.runInProgressService(initializer);
......
......@@ -23,6 +23,7 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IPathEditorInput;
import org.eclipse.ui.IPersistableElement;
import org.jkiss.code.Nullable;
......@@ -32,19 +33,22 @@ import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.model.DBPContextProvider;
import org.jkiss.dbeaver.model.data.DBDContent;
import org.jkiss.dbeaver.model.data.DBDContentCached;
import org.jkiss.dbeaver.model.data.DBDContentStorage;
import org.jkiss.dbeaver.model.data.DBDContentStorageLocal;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.impl.BytesContentStorage;
import org.jkiss.dbeaver.model.impl.StringContentStorage;
import org.jkiss.dbeaver.model.impl.TemporaryContentStorage;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.runtime.LocalFileStorage;
import org.jkiss.dbeaver.utils.RuntimeUtils;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.data.IAttributeController;
import org.jkiss.dbeaver.ui.data.IValueController;
import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.dbeaver.utils.RuntimeUtils;
import java.io.*;
......@@ -56,19 +60,22 @@ public class ContentEditorInput implements IPathEditorInput, DBPContextProvider
private static final Log log = Log.getLog(ContentEditorInput.class);
private IValueController valueController;
private ContentEditorPart[] editorParts;
private IEditorPart[] editorParts;
private IEditorPart defaultPart;
private File contentFile;
private boolean contentDetached = false;
private String fileCharset = ContentUtils.DEFAULT_CHARSET;
public ContentEditorInput(
IValueController valueController,
ContentEditorPart[] editorParts,
IEditorPart[] editorParts,
IEditorPart defaultPart,
DBRProgressMonitor monitor)
throws DBException
{
this.valueController = valueController;
this.editorParts = editorParts;
this.defaultPart = defaultPart;
this.prepareContent(monitor);
}
......@@ -87,11 +94,15 @@ public class ContentEditorInput implements IPathEditorInput, DBPContextProvider
this.prepareContent(monitor);
}
ContentEditorPart[] getEditors()
IEditorPart[] getEditors()
{
return editorParts;
}
public IEditorPart getDefaultEditor() {
return defaultPart;
}
@Override
public boolean exists()
{
......@@ -296,6 +307,21 @@ public class ContentEditorInput implements IPathEditorInput, DBPContextProvider
if (storage instanceof DBDContentStorageLocal) {
// Nothing to update - we user content's storage
contentDetached = true;
} else if (storage instanceof DBDContentCached) {
// Create new storage and pass it to content
try (FileInputStream is = new FileInputStream(contentFile)) {
if (storage instanceof StringContentStorage) {
try (Reader reader = new InputStreamReader(is, GeneralUtils.getDefaultFileEncoding())) {
storage = StringContentStorage.createFromReader(reader);
}
} else {
storage = BytesContentStorage.createFromStream(is, contentFile.length(), GeneralUtils.getDefaultFileEncoding());
}
//StringContentStorage.
contentDetached = content.updateContents(localMonitor, storage);
} catch (IOException e) {
throw new DBException("Error reading content from file", e);
}
} else {
// Create new storage and pass it to content
storage = new TemporaryContentStorage(DBeaverCore.getInstance(), contentFile);
......
......@@ -17,7 +17,6 @@
*/
package org.jkiss.dbeaver.ui.editors.content;
import org.eclipse.ui.IEditorActionBarContributor;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.MultiPageEditorSite;
......@@ -32,18 +31,6 @@ class ContentEditorSite extends MultiPageEditorSite {
super(contentEditor, editor);
}
@Override
public IEditorActionBarContributor getActionBarContributor() {
IEditorPart editor = getEditor();
ContentEditor contentEditor = (ContentEditor) getMultiPageEditor();
ContentEditor.ContentPartInfo contentPart = contentEditor.getContentEditor(editor);
if (contentPart != null) {
return contentPart.editorPart.getActionBarContributor();
} else {
return super.getActionBarContributor();
}
}
@Override
public IWorkbenchPart getPart() {
return getMultiPageEditor();
......
......@@ -24,6 +24,7 @@ import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.IEditorPart;
import java.util.List;
......@@ -34,10 +35,10 @@ import java.util.List;
*/
class SelectContentPartDialog extends Dialog {
private List<ContentEditorPart> dirtyParts;
private ContentEditorPart selectedPart;
private List<IEditorPart> dirtyParts;
private IEditorPart selectedPart;
private SelectContentPartDialog(Shell parentShell, List<ContentEditorPart> dirtyParts)
private SelectContentPartDialog(Shell parentShell, List<IEditorPart> dirtyParts)
{
super(parentShell);
this.dirtyParts = dirtyParts;
......@@ -67,8 +68,8 @@ class SelectContentPartDialog extends Dialog {
gd = new GridData(GridData.FILL_HORIZONTAL);
combo.setLayoutData(gd);
combo.add("");
for (ContentEditorPart part : dirtyParts) {
combo.add(part.getContentTypeTitle());
for (IEditorPart part : dirtyParts) {
combo.add(part.getTitle());
}
combo.addSelectionListener(new SelectionAdapter() {
@Override
......@@ -82,39 +83,6 @@ class SelectContentPartDialog extends Dialog {
getButton(IDialogConstants.OK_ID).setEnabled(selectedPart != null);
}
});
/*
final Table table = new Table(group, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
table.setLinesVisible (true);
table.setHeaderVisible(true);
gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 150;
gd.widthHint = 200;
table.setLayoutData(gd);
TableColumn tableColumn = new TableColumn(table, SWT.NONE);
tableColumn.setText("Editor");
for (ContentEditorPart part : dirtyParts) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText(part.getContentTypeTitle());
Image image = part.getContentTypeImage();
if (image != null) {
item.setImage(image);
}
item.setData(part);
}
tableColumn.pack();
table.pack();
table.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
TableItem item = (TableItem) e.item;
selectedPart = (ContentEditorPart) item.getData();
getButton(IDialogConstants.OK_ID).setEnabled(true);
}
});
*/
return group;
}
......@@ -127,12 +95,12 @@ class SelectContentPartDialog extends Dialog {
return ctl;
}
public ContentEditorPart getSelectedPart()
public IEditorPart getSelectedPart()
{
return selectedPart;
}
public static ContentEditorPart selectContentPart(Shell parentShell, List<ContentEditorPart> dirtyParts)
public static IEditorPart selectContentPart(Shell parentShell, List<IEditorPart> dirtyParts)
{
SelectContentPartDialog scDialog = new SelectContentPartDialog(parentShell, dirtyParts);
if (scDialog.open() == IDialogConstants.OK_ID) {
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 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.editors.content.parts;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IEditorActionBarContributor;
import org.eclipse.ui.IEditorPart;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.model.DBPImage;
import org.jkiss.dbeaver.ui.editors.binary.BinaryEditor;
import org.jkiss.dbeaver.ui.editors.content.ContentEditorPart;
import javax.activation.MimeType;
/**
* CONTENT Binary Editor
*/
public class ContentBinaryEditorPart extends BinaryEditor implements ContentEditorPart {
public ContentBinaryEditorPart()
{
}
@Override
public void initPart(IEditorPart contentEditor, MimeType mimeType)
{
}
@Override
public IEditorActionBarContributor getActionBarContributor()
{
return null;
}
@Nullable
@Override
public Control getEditorControl()
{
return getManager().getControl();
}
@Override
public String getContentTypeTitle()
{
return "Binary";
}
@Override
public DBPImage getContentTypeImage()
{
return DBIcon.TYPE_BINARY;
}
@Override
public String getPreferredMimeType()
{
return "application";
}
@Override
public long getMaxContentLength()
{
return Long.MAX_VALUE;
}
/**
* Any content is valid for binary editor so always returns true
* @return
*/
@Override
public boolean isPreferredContent()
{
return false;
}
@Override
public boolean isOptionalContent()
{
return false;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 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.editors.content.parts;
import org.eclipse.ui.IEditorActionBarContributor;
import org.eclipse.ui.IEditorPart;
import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.model.DBPContextProvider;
import org.jkiss.dbeaver.model.DBPImage;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.ui.editors.content.ContentEditorPart;
import org.jkiss.dbeaver.ui.editors.xml.XMLEditor;
import org.jkiss.dbeaver.utils.MimeTypes;
import javax.activation.MimeType;
import javax.activation.MimeTypeParseException;
/**
* XML editor
*/
public class ContentXMLEditorPart extends XMLEditor implements ContentEditorPart {
private IEditorPart contentEditor;
private MimeType mimeType;
public ContentXMLEditorPart() {
}
@Override
public void initPart(IEditorPart contentEditor, MimeType mimeType)
{
this.contentEditor = contentEditor;
this.mimeType = mimeType;
}
@Override
public IEditorActionBarContributor getActionBarContributor()
{
return null;
}
@Override
public String getContentTypeTitle()
{
return "XML";
}
@Override
public DBPImage getContentTypeImage()
{
return DBIcon.TYPE_XML;
}
@Override
public String getPreferredMimeType()
{
return MimeTypes.TEXT_XML;
}
@Override
public long getMaxContentLength()
{
if (contentEditor instanceof DBPContextProvider) {
DBCExecutionContext context = ((DBPContextProvider) contentEditor).getExecutionContext();
if (context != null) {
return context.getDataSource().getContainer().getPreferenceStore().getInt(DBeaverPreferences.RS_EDIT_MAX_TEXT_SIZE);
}
}
return 10 * 1024 * 1024;
}
@Override
public boolean isPreferredContent()
{
try {
return mimeType.match(MimeTypes.TEXT_XML);
} catch (MimeTypeParseException e) {
return false;
}
}
@Override
public boolean isOptionalContent()
{
return true;
}
}
......@@ -18,9 +18,9 @@
package org.jkiss.dbeaver.model.impl;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.data.DBDContentCached;
import org.jkiss.dbeaver.model.data.DBDContentStorage;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.IOUtils;
import java.io.*;
......@@ -28,7 +28,7 @@ import java.io.*;
/**
* Memory content storage
*/
public class BytesContentStorage implements DBDContentStorage {
public class BytesContentStorage implements DBDContentStorage, DBDContentCached {
private static final Log log = Log.getLog(BytesContentStorage.class);
......@@ -66,7 +66,7 @@ public class BytesContentStorage implements DBDContentStorage {
@Override
public String getCharset()
{
return GeneralUtils.getDefaultFileEncoding();
return encoding;
}
@Override
......@@ -99,4 +99,9 @@ public class BytesContentStorage implements DBDContentStorage {
}
return new BytesContentStorage(result, encoding);
}
@Override
public Object getCachedValue() {
return data;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册