diff --git a/plugins/org.jkiss.dbeaver.core/META-INF/MANIFEST.MF b/plugins/org.jkiss.dbeaver.core/META-INF/MANIFEST.MF index 035ed2daa36580633409ba6507f535e33c66fa45..c6371266ae710db9ec68dd3d3c5b6ea45c50ba82 100644 --- a/plugins/org.jkiss.dbeaver.core/META-INF/MANIFEST.MF +++ b/plugins/org.jkiss.dbeaver.core/META-INF/MANIFEST.MF @@ -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, diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/IStreamValueManager.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/IStreamValueManager.java index 8cf50a38ad9fa507b75c0f3b2f49a06a43d49980..aac9ac47fd7f01fcef8ef3af4ad52ca7ead29455 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/IStreamValueManager.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/IStreamValueManager.java @@ -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; diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/editors/XMLPanelEditor.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/editors/XMLPanelEditor.java index 0ea620c0295ab37579abcd5177ac4f73c544558d..587134c6b03bbcc7ed86d70cf62f767aa43ec394 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/editors/XMLPanelEditor.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/editors/XMLPanelEditor.java @@ -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); diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/ContentValueManager.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/ContentValueManager.java index 084b610a88609e98a9c1eef42b8aa06d68f7c1a6..2d22113c538218047c72624b2f618ef29b90c0b3 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/ContentValueManager.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/ContentValueManager.java @@ -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 parts = new ArrayList<>(); + Map streamManagers = + ValueManagerRegistry.getInstance().getApplicableStreamManagers(VoidProgressMonitor.INSTANCE, controller.getValueType(), content); + //boolean isText = ContentUtils.isTextContent(content); + List parts = new ArrayList<>(); + IEditorPart defaultPart = null; + IStreamValueManager.MatchType defaultMatch = null; + for (Map.Entry 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; diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/BinaryEditorPart.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/BinaryEditorPart.java new file mode 100644 index 0000000000000000000000000000000000000000..37dc7987df0b0a78df31f0562e1a59a9919a4b68 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/BinaryEditorPart.java @@ -0,0 +1,47 @@ +/* + * 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); + } + +} diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/BinaryStreamValueManager.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/BinaryStreamValueManager.java index 5809390d66a5d4fe270f4f1ef606c38fae45c37f..596d16b8b31f46f3395c67f5a0c3c3da619e22e9 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/BinaryStreamValueManager.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/BinaryStreamValueManager.java @@ -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(); } } diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/parts/ContentImageEditorPart.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/ImageEditorPart.java similarity index 74% rename from plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/parts/ContentImageEditorPart.java rename to plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/ImageEditorPart.java index 6d2a4751d553de8b8349054f985726e96bf50726..d0351d9c885c96317b9503135896e9f3b6688843 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/parts/ContentImageEditorPart.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/ImageEditorPart.java @@ -1,205 +1,163 @@ -/* - * 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 diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/ImageStreamValueManager.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/ImageStreamValueManager.java index 7517c0b5bd2b81a8a79a92babfdd460942a35c56..8cd7b900ae8dd2d65246a3b404d0ed56f83f0a9f 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/ImageStreamValueManager.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/ImageStreamValueManager.java @@ -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 { diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/TextEditorPart.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/TextEditorPart.java new file mode 100644 index 0000000000000000000000000000000000000000..3fd7a6fb00840138ee3946f691e047255ee22dbe --- /dev/null +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/TextEditorPart.java @@ -0,0 +1,48 @@ +/* + * 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); + } + +} diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/TextStreamValueManager.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/TextStreamValueManager.java index 829e41f574942d6e37fabefc38f79cfb66e9270f..4f0eed4abc9f1fef8fb9d580ce31114db6c158e1 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/TextStreamValueManager.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/managers/stream/TextStreamValueManager.java @@ -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(); } } diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/registry/ValueManagerRegistry.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/registry/ValueManagerRegistry.java index dba1a7506e589c28eaedbd48966e8c122d935d95..4b71f1cd46adc56c068bfbd27fab5d7c9e787924 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/registry/ValueManagerRegistry.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/data/registry/ValueManagerRegistry.java @@ -99,7 +99,7 @@ public class ValueManagerRegistry { return getInstance().getManager(dataSource, typedObject, valueType); } - public Map getApplicableStreamManagers(@NotNull DBRProgressMonitor monitor, @NotNull DBSAttributeBase attribute, @Nullable DBDContent value) { + public Map getApplicableStreamManagers(@NotNull DBRProgressMonitor monitor, @NotNull DBSTypedObject attribute, @Nullable DBDContent value) { Map result = new LinkedHashMap<>(); for (StreamValueManagerDescriptor contentManager : streamManagers) { IStreamValueManager.MatchType matchType = contentManager.getInstance().matchesTo(monitor, attribute, value); diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditor.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditor.java index e856bb108cce098e2a79bcd50bb5a784c5eaa5e1..472db65af0983411480ff97732f7d201534e1a0d 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditor.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditor.java @@ -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 dirtyParts = new ArrayList<>(); + final List 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); diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditorInput.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditorInput.java index ca146263b25b75355c2ce6df02521ee3c3c55368..9fdea9826328cdc1e20e95ec52b6f91174f7da97 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditorInput.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditorInput.java @@ -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); diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditorPart.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditorPart.java deleted file mode 100644 index 7a3ec1a865419cc3230faeb1eed556e3b8a1d357..0000000000000000000000000000000000000000 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditorPart.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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(); -} diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditorSite.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditorSite.java index ef57507e79227fa7c7230317c76d9599d823adca..c73eaa1c267bb0a7b714ead6ab5fbb32bd1c1396 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditorSite.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/ContentEditorSite.java @@ -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(); diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/SelectContentPartDialog.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/SelectContentPartDialog.java index 04668cf37331d5fb5648d7d733ffe9b83dc3bca8..a911cab927358a7e2b81b62ad630db3c28062abb 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/SelectContentPartDialog.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/SelectContentPartDialog.java @@ -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 dirtyParts; - private ContentEditorPart selectedPart; + private List dirtyParts; + private IEditorPart selectedPart; - private SelectContentPartDialog(Shell parentShell, List dirtyParts) + private SelectContentPartDialog(Shell parentShell, List 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 dirtyParts) + public static IEditorPart selectContentPart(Shell parentShell, List dirtyParts) { SelectContentPartDialog scDialog = new SelectContentPartDialog(parentShell, dirtyParts); if (scDialog.open() == IDialogConstants.OK_ID) { diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/parts/ContentBinaryEditorPart.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/parts/ContentBinaryEditorPart.java deleted file mode 100644 index 557830b02f6e6d5cbd7c62841700a6ee9bce7d14..0000000000000000000000000000000000000000 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/parts/ContentBinaryEditorPart.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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; - } - -} diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/parts/ContentTextEditorPart.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/parts/ContentTextEditorPart.java deleted file mode 100644 index d675d099508c289b67042f0712208cadb43b9960..0000000000000000000000000000000000000000 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/parts/ContentTextEditorPart.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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; - } -} diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/parts/ContentXMLEditorPart.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/parts/ContentXMLEditorPart.java deleted file mode 100644 index e10728f8448f8fc1d18900978401b57c82ae2ce6..0000000000000000000000000000000000000000 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/content/parts/ContentXMLEditorPart.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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; - } -} diff --git a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/BytesContentStorage.java b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/BytesContentStorage.java index 605454d624b5b3d874b80bad7f2094bdcb213048..5a5e783c1bc5b443d0314b6ceb2cddf6c1a2e98c 100644 --- a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/BytesContentStorage.java +++ b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/BytesContentStorage.java @@ -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; + } }