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

Content panel menu contribution refactoring

上级 39fc3497
......@@ -944,8 +944,23 @@ public class ResultSetViewer extends Viewer
}
// Try to get it from adapter
if (activePresentation instanceof IAdaptable) {
return ((IAdaptable) activePresentation).getAdapter(adapter);
T adapted = ((IAdaptable) activePresentation).getAdapter(adapter);
if (adapted != null) {
return adapted;
}
}
// FIXME: Not sure that we should adapt active panel. NOT TESTED YET
/*
if (getVisiblePanel() instanceof IAdaptable) {
CTabItem panelTab = panelFolder.getSelection();
if (panelTab != null && panelTab.getControl() != null && UIUtils.hasFocus(panelTab.getControl())) {
T adapted = ((IAdaptable) getVisiblePanel()).getAdapter(adapter);
if (adapted != null) {
return adapted;
}
}
}
*/
return null;
}
......
......@@ -16,6 +16,7 @@
*/
package org.jkiss.dbeaver.ui.controls.resultset.panel;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.jface.action.Separator;
......@@ -59,7 +60,7 @@ import org.jkiss.utils.CommonUtils;
/**
* RSV value view panel
*/
public class ViewValuePanel implements IResultSetPanel {
public class ViewValuePanel implements IResultSetPanel, IAdaptable {
private static final Log log = Log.getLog(ViewValuePanel.class);
......@@ -379,4 +380,17 @@ public class ViewValuePanel implements IResultSetPanel {
});
}
@Override
public <T> T getAdapter(Class<T> adapter) {
if (valueEditor != null) {
if (adapter.isAssignableFrom(valueEditor.getClass())) {
return adapter.cast(valueEditor);
}
if (valueEditor instanceof IAdaptable) {
return ((IAdaptable) valueEditor).getAdapter(adapter);
}
}
return null;
}
}
......@@ -16,6 +16,7 @@
*/
package org.jkiss.dbeaver.ui.data.editors;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IContributionManager;
......@@ -61,7 +62,7 @@ import java.util.List;
/**
* ControlPanelEditor
*/
public class ContentPanelEditor extends BaseValueEditor<Control> {
public class ContentPanelEditor extends BaseValueEditor<Control> implements IAdaptable {
private static final Log log = Log.getLog(ContentPanelEditor.class);
......@@ -193,6 +194,19 @@ public class ContentPanelEditor extends BaseValueEditor<Control> {
return dsId + ":" + valueId;
}
@Override
public <T> T getAdapter(Class<T> adapter) {
if (streamEditor != null) {
if (adapter.isAssignableFrom(streamEditor.getClass())) {
return adapter.cast(streamEditor);
}
if (streamEditor instanceof IAdaptable) {
return ((IAdaptable) streamEditor).getAdapter(adapter);
}
}
return null;
}
private class ContentTypeSwitchAction extends Action implements SelectionListener {
private Menu menu;
......
......@@ -16,9 +16,11 @@
*/
package org.jkiss.dbeaver.ui.data.managers.stream;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Control;
import org.jkiss.code.NotNull;
......@@ -26,11 +28,12 @@ import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.ui.controls.resultset.panel.ViewValuePanel;
import org.jkiss.dbeaver.ui.data.IStreamValueEditor;
import org.jkiss.dbeaver.ui.data.IValueController;
import org.jkiss.dbeaver.ui.editors.text.BaseTextEditor;
/**
* AbstractTextPanelEditor
*/
public abstract class AbstractTextPanelEditor implements IStreamValueEditor<StyledText> {
public abstract class AbstractTextPanelEditor implements IStreamValueEditor<StyledText>, IAdaptable {
public static final String PREF_TEXT_EDITOR_WORD_WRAP = "content.text.editor.word-wrap";
public static final String PREF_TEXT_EDITOR_AUTO_FORMAT = "content.text.editor.auto-format";
......@@ -60,13 +63,15 @@ public abstract class AbstractTextPanelEditor implements IStreamValueEditor<Styl
manager.add(wwAction);
}
{
BaseTextEditor textEditor = getTextEditor();
if (textEditor != null) {
final Action afAction = new Action("Auto Format", Action.AS_CHECK_BOX) {
@Override
public void run() {
boolean newAF = !ViewValuePanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_AUTO_FORMAT);
setChecked(newAF);
ViewValuePanel.getPanelSettings().put(PREF_TEXT_EDITOR_AUTO_FORMAT, newAF);
applyEditorStyle();
}
};
afAction.setChecked(ViewValuePanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_AUTO_FORMAT));
......@@ -74,12 +79,33 @@ public abstract class AbstractTextPanelEditor implements IStreamValueEditor<Styl
}
}
protected void setEditorSettings(Control control) {
if (control instanceof StyledText) {
if (ViewValuePanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_WORD_WRAP)) {
((StyledText) control).setWordWrap(true);
}
protected BaseTextEditor getTextEditor() {
return null;
}
protected void initEditorSettings(StyledText control) {
boolean wwEnabled = ViewValuePanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_WORD_WRAP);
if (wwEnabled != control.getWordWrap()) {
control.setWordWrap(wwEnabled);
}
}
protected void applyEditorStyle() {
BaseTextEditor textEditor = getTextEditor();
if (textEditor != null && ViewValuePanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_AUTO_FORMAT)) {
textEditor.getViewer().doOperation(ISourceViewer.FORMAT);
}
}
@Override
public <T> T getAdapter(Class<T> adapter) {
BaseTextEditor textEditor = getTextEditor();
if (textEditor != null) {
if (adapter.isAssignableFrom(textEditor.getClass())) {
return adapter.cast(textEditor);
}
return textEditor.getAdapter(adapter);
}
return null;
}
}
......@@ -16,19 +16,15 @@
*/
package org.jkiss.dbeaver.ui.data.managers.stream;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.data.DBDContent;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.impl.StringContentStorage;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.ui.data.IStreamValueEditor;
import org.jkiss.dbeaver.ui.data.IValueController;
import org.jkiss.dbeaver.ui.data.editors.ContentPanelEditor;
import org.jkiss.dbeaver.utils.ContentUtils;
/**
......@@ -42,7 +38,7 @@ public class TextPanelEditor extends AbstractTextPanelEditor {
StyledText text = new StyledText(valueController.getEditPlaceholder(), SWT.MULTI | SWT.V_SCROLL);
text.setEditable(!valueController.isReadOnly());
text.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
setEditorSettings(text);
initEditorSettings(text);
return text;
}
......
......@@ -30,6 +30,7 @@ import org.jkiss.dbeaver.ui.data.IValueController;
import org.jkiss.dbeaver.ui.editors.StringEditorInput;
import org.jkiss.dbeaver.ui.editors.SubEditorSite;
import org.jkiss.dbeaver.ui.editors.content.ContentEditorInput;
import org.jkiss.dbeaver.ui.editors.text.BaseTextEditor;
import org.jkiss.dbeaver.ui.editors.xml.XMLEditor;
import org.jkiss.dbeaver.utils.RuntimeUtils;
......@@ -55,7 +56,7 @@ public class XMLPanelEditor extends AbstractTextPanelEditor {
return new StyledText(valueController.getEditPlaceholder(), SWT.NONE);
}
editor.createPartControl(valueController.getEditPlaceholder());
setEditorSettings(editor.getEditorControl());
initEditorSettings(editor.getEditorControl());
return editor.getEditorControl();
}
......@@ -67,6 +68,7 @@ public class XMLPanelEditor extends AbstractTextPanelEditor {
monitor.subTask("Prime XML value");
IEditorInput sqlInput = new ContentEditorInput(valueController, null, null, monitor);
editor.init(subSite, sqlInput);
applyEditorStyle();
} catch (Exception e) {
throw new DBException("Can't load XML vaue", e);
} finally {
......@@ -90,5 +92,8 @@ public class XMLPanelEditor extends AbstractTextPanelEditor {
}
}
@Override
protected BaseTextEditor getTextEditor() {
return editor;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册