提交 b1fe5cfc 编写于 作者: J jurgen

Value handlers model

Former-commit-id: 4924870e
上级 80624751
......@@ -32,7 +32,7 @@ import org.jkiss.dbeaver.ext.IDatabasePersistAction;
import org.jkiss.dbeaver.model.data.*;
import org.jkiss.dbeaver.model.exec.*;
import org.jkiss.dbeaver.model.impl.BaseEntityIdentifier;
import org.jkiss.dbeaver.model.impl.DBCDefaultValueHandler;
import org.jkiss.dbeaver.model.impl.data.DefaultValueHandler;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult;
import org.jkiss.dbeaver.model.sql.SQLDataSource;
......@@ -491,7 +491,7 @@ public final class DBUtils {
}
if (typeHandler == null) {
if (preferences == null) {
typeHandler = DBCDefaultValueHandler.INSTANCE;
typeHandler = DefaultValueHandler.INSTANCE;
} else {
typeHandler = preferences.getDefaultValueHandler();
}
......
......@@ -24,6 +24,7 @@ import org.jkiss.dbeaver.model.DBPTransactionIsolation;
import org.jkiss.dbeaver.model.data.DBDDataFormatterProfile;
import org.jkiss.dbeaver.model.data.DBDValueHandler;
import org.jkiss.dbeaver.model.exec.*;
import org.jkiss.dbeaver.model.impl.data.DefaultValueHandler;
import org.jkiss.dbeaver.model.qm.QMUtils;
import org.jkiss.dbeaver.model.runtime.DBRBlockingObject;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
......@@ -102,7 +103,7 @@ public abstract class AbstractSession implements DBCSession, DBRBlockingObject {
@Override
public DBDValueHandler getDefaultValueHandler()
{
return DBCDefaultValueHandler.INSTANCE;
return DefaultValueHandler.INSTANCE;
}
@Override
......
/*
* Copyright (C) 2010-2014 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.model.impl.data;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.ToolBar;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.data.*;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCLogicalOperator;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.ui.DBIcon;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.properties.PropertySourceAbstract;
/**
* Base value handler
*/
public abstract class BaseValueHandler implements DBDValueHandler {
@Override
public void releaseValueObject(Object value)
{
if (value instanceof DBDValue) {
((DBDValue)value).release();
}
}
@NotNull
@Override
public String getValueDisplayString(@NotNull DBSTypedObject column, Object value, @NotNull DBDDisplayFormat format) {
return DBUtils.getDefaultValueDisplayString(value, format);
}
@Override
public void contributeActions(@NotNull IContributionManager manager, @NotNull DBDValueController controller)
throws DBCException
{
}
@Override
public void contributeProperties(@NotNull PropertySourceAbstract propertySource, @NotNull DBDValueController controller)
{
}
@Override
public DBCLogicalOperator[] getSupportedOperators(@NotNull DBDAttributeBinding attribute) {
return DBUtils.getDefaultOperators(attribute);
}
protected abstract class ValueEditor<T extends Control> implements DBDValueEditor {
protected final DBDValueController valueController;
protected final T control;
private boolean activated;
protected ValueEditor(final DBDValueController valueController)
{
this.valueController = valueController;
this.control = createControl(valueController.getEditPlaceholder());
if (this.control != null) {
initInlineControl(this.control);
}
ToolBar editToolBar = valueController.getEditToolBar();
if (editToolBar != null) {
if (!valueController.isReadOnly()) {
UIUtils.createToolItem(editToolBar, "Save changes", DBIcon.SAVE.getImage(), new Action("Save") {
@Override
public void run()
{
saveValue();
}
});
}
}
}
@Override
public Control getControl()
{
return control;
}
protected abstract T createControl(Composite editPlaceholder);
protected void initInlineControl(final Control inlineControl)
{
boolean isInline = (valueController.getEditType() == DBDValueController.EditType.INLINE);
// Panel controls
inlineControl.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e)
{
if (!activated) {
UIUtils.enableHostEditorKeyBindings(valueController.getValueSite(), false);
activated = true;
}
}
@Override
public void focusLost(FocusEvent e)
{
if (activated) {
UIUtils.enableHostEditorKeyBindings(valueController.getValueSite(), true);
activated = false;
}
}
});
inlineControl.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e)
{
if (activated) {
UIUtils.enableHostEditorKeyBindings(valueController.getValueSite(), true);
activated = false;
}
}
});
// if (!isInline) {
// inlineControl.setBackground(valueController.getEditPlaceholder().getBackground());
// }
if (isInline) {
inlineControl.setFont(valueController.getEditPlaceholder().getFont());
// There is a bug in windows. First time date control gain focus it renders cell editor incorrectly.
// Let's focus on it in async mode
inlineControl.getDisplay().asyncExec(new Runnable() {
@Override
public void run()
{
if (!inlineControl.isDisposed()) {
inlineControl.setFocus();
}
}
});
inlineControl.addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e)
{
if (e.detail == SWT.TRAVERSE_RETURN) {
saveValue();
e.doit = false;
e.detail = SWT.TRAVERSE_NONE;
} else if (e.detail == SWT.TRAVERSE_ESCAPE) {
valueController.closeInlineEditor();
e.doit = false;
e.detail = SWT.TRAVERSE_NONE;
} else if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
saveValue();
valueController.nextInlineEditor(e.detail == SWT.TRAVERSE_TAB_NEXT);
e.doit = false;
e.detail = SWT.TRAVERSE_NONE;
}
}
});
inlineControl.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e)
{
// Check new focus control in async mode
// (because right now focus is still on edit control)
inlineControl.getDisplay().asyncExec(new Runnable() {
@Override
public void run()
{
if (inlineControl.isDisposed()) {
return;
}
Control newFocus = inlineControl.getDisplay().getFocusControl();
if (newFocus != null) {
for (Control fc = newFocus.getParent(); fc != null; fc = fc.getParent()) {
if (fc == valueController.getEditPlaceholder()) {
// New focus is still a child of inline placeholder - do not close it
return;
}
}
}
saveValue();
}
});
}
});
}
}
private void saveValue()
{
try {
Object newValue = extractEditorValue();
valueController.closeInlineEditor();
valueController.updateValue(newValue);
} catch (DBException e) {
UIUtils.showErrorDialog(getControl().getShell(), "Value save", "Can't save edited value", e);
}
}
}
protected abstract class ValueEditorEx<T extends Control> extends ValueEditor<T> implements DBDValueEditorStandalone {
protected ValueEditorEx(final DBDValueController valueController)
{
super(valueController);
}
}
}
\ No newline at end of file
......@@ -16,9 +16,8 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.model.impl;
package org.jkiss.dbeaver.model.impl.data;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
......@@ -30,14 +29,13 @@ import org.jkiss.dbeaver.model.data.*;
import org.jkiss.dbeaver.model.exec.*;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.ui.dialogs.data.TextViewDialog;
import org.jkiss.dbeaver.ui.properties.PropertySourceAbstract;
/**
* Default value handler
*/
public class DBCDefaultValueHandler implements DBDValueHandler {
public class DefaultValueHandler extends BaseValueHandler {
public static final DBCDefaultValueHandler INSTANCE = new DBCDefaultValueHandler();
public static final DefaultValueHandler INSTANCE = new DefaultValueHandler();
@Override
public int getFeatures()
......@@ -78,27 +76,6 @@ public class DBCDefaultValueHandler implements DBDValueHandler {
return object;
}
@Override
public void releaseValueObject(Object value) {
if (value instanceof DBDValue) {
((DBDValue) value).release();
}
}
@NotNull
@Override
public String getValueDisplayString(@NotNull DBSTypedObject column, Object value, @NotNull DBDDisplayFormat format) {
return DBUtils.getDefaultValueDisplayString(value, format);
}
@Override
public void contributeActions(@NotNull IContributionManager manager, @NotNull DBDValueController controller) throws DBCException {
}
@Override
public void contributeProperties(@NotNull PropertySourceAbstract propertySource, @NotNull DBDValueController controller) {
}
@Override
public DBDValueEditor createEditor(@NotNull final DBDValueController controller) throws DBException {
switch (controller.getEditType()) {
......@@ -129,9 +106,4 @@ public class DBCDefaultValueHandler implements DBDValueHandler {
}
}
@Override
public DBCLogicalOperator[] getSupportedOperators(@NotNull DBDAttributeBinding attribute) {
return DBUtils.getDefaultOperators(attribute);
}
}
......@@ -20,34 +20,25 @@ package org.jkiss.dbeaver.model.impl.jdbc.data;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.ToolBar;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.data.*;
import org.jkiss.dbeaver.model.exec.*;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCResultSet;
import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.exec.DBCStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.data.BaseValueHandler;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.ui.DBIcon;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.properties.PropertySourceAbstract;
import java.sql.SQLException;
/**
* Standard JDBC value handler
* Base JDBC value handler
*/
public abstract class JDBCAbstractValueHandler implements DBDValueHandler {
public abstract class JDBCAbstractValueHandler extends BaseValueHandler {
static final Log log = LogFactory.getLog(JDBCAbstractValueHandler.class);
......@@ -78,32 +69,6 @@ public abstract class JDBCAbstractValueHandler implements DBDValueHandler {
}
}
@Override
public void releaseValueObject(Object value)
{
if (value instanceof DBDValue) {
((DBDValue)value).release();
}
}
@NotNull
@Override
public String getValueDisplayString(@NotNull DBSTypedObject column, Object value, @NotNull DBDDisplayFormat format) {
return DBUtils.getDefaultValueDisplayString(value, format);
}
@Override
public void contributeActions(@NotNull IContributionManager manager, @NotNull DBDValueController controller)
throws DBCException
{
}
@Override
public void contributeProperties(@NotNull PropertySourceAbstract propertySource, @NotNull DBDValueController controller)
{
}
@Nullable
protected abstract Object fetchColumnValue(DBCSession session, JDBCResultSet resultSet, DBSTypedObject type, int index)
throws DBCException, SQLException;
......@@ -116,165 +81,4 @@ public abstract class JDBCAbstractValueHandler implements DBDValueHandler {
Object value)
throws DBCException, SQLException;
@Override
public DBCLogicalOperator[] getSupportedOperators(@NotNull DBDAttributeBinding attribute) {
return DBUtils.getDefaultOperators(attribute);
}
protected abstract class ValueEditor<T extends Control> implements DBDValueEditor {
protected final DBDValueController valueController;
protected final T control;
private boolean activated;
protected ValueEditor(final DBDValueController valueController)
{
this.valueController = valueController;
this.control = createControl(valueController.getEditPlaceholder());
if (this.control != null) {
initInlineControl(this.control);
}
ToolBar editToolBar = valueController.getEditToolBar();
if (editToolBar != null) {
if (!valueController.isReadOnly()) {
UIUtils.createToolItem(editToolBar, "Save changes", DBIcon.SAVE.getImage(), new Action("Save") {
@Override
public void run()
{
saveValue();
}
});
}
}
}
@Override
public Control getControl()
{
return control;
}
protected abstract T createControl(Composite editPlaceholder);
protected void initInlineControl(final Control inlineControl)
{
boolean isInline = (valueController.getEditType() == DBDValueController.EditType.INLINE);
// Panel controls
inlineControl.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e)
{
if (!activated) {
UIUtils.enableHostEditorKeyBindings(valueController.getValueSite(), false);
activated = true;
}
}
@Override
public void focusLost(FocusEvent e)
{
if (activated) {
UIUtils.enableHostEditorKeyBindings(valueController.getValueSite(), true);
activated = false;
}
}
});
inlineControl.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e)
{
if (activated) {
UIUtils.enableHostEditorKeyBindings(valueController.getValueSite(), true);
activated = false;
}
}
});
// if (!isInline) {
// inlineControl.setBackground(valueController.getEditPlaceholder().getBackground());
// }
if (isInline) {
inlineControl.setFont(valueController.getEditPlaceholder().getFont());
// There is a bug in windows. First time date control gain focus it renders cell editor incorrectly.
// Let's focus on it in async mode
inlineControl.getDisplay().asyncExec(new Runnable() {
@Override
public void run()
{
if (!inlineControl.isDisposed()) {
inlineControl.setFocus();
}
}
});
inlineControl.addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e)
{
if (e.detail == SWT.TRAVERSE_RETURN) {
saveValue();
e.doit = false;
e.detail = SWT.TRAVERSE_NONE;
} else if (e.detail == SWT.TRAVERSE_ESCAPE) {
valueController.closeInlineEditor();
e.doit = false;
e.detail = SWT.TRAVERSE_NONE;
} else if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
saveValue();
valueController.nextInlineEditor(e.detail == SWT.TRAVERSE_TAB_NEXT);
e.doit = false;
e.detail = SWT.TRAVERSE_NONE;
}
}
});
inlineControl.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e)
{
// Check new focus control in async mode
// (because right now focus is still on edit control)
inlineControl.getDisplay().asyncExec(new Runnable() {
@Override
public void run()
{
if (inlineControl.isDisposed()) {
return;
}
Control newFocus = inlineControl.getDisplay().getFocusControl();
if (newFocus != null) {
for (Control fc = newFocus.getParent(); fc != null; fc = fc.getParent()) {
if (fc == valueController.getEditPlaceholder()) {
// New focus is still a child of inline placeholder - do not close it
return;
}
}
}
saveValue();
}
});
}
});
}
}
private void saveValue()
{
try {
Object newValue = extractEditorValue();
valueController.closeInlineEditor();
valueController.updateValue(newValue);
} catch (DBException e) {
UIUtils.showErrorDialog(getControl().getShell(), "Value save", "Can't save edited value", e);
}
}
}
protected abstract class ValueEditorEx<T extends Control> extends ValueEditor<T> implements DBDValueEditorStandalone {
protected ValueEditorEx(final DBDValueController valueController)
{
super(valueController);
}
}
}
\ No newline at end of file
......@@ -41,7 +41,7 @@ import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCExecutionPurpose;
import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.exec.DBCTransactionManager;
import org.jkiss.dbeaver.model.impl.DBCDefaultValueHandler;
import org.jkiss.dbeaver.model.impl.data.DefaultValueHandler;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.net.DBWHandlerConfiguration;
import org.jkiss.dbeaver.model.net.DBWHandlerType;
......@@ -969,7 +969,7 @@ public class DataSourceDescriptor
@Override
public DBDValueHandler getDefaultValueHandler()
{
return DBCDefaultValueHandler.INSTANCE;
return DefaultValueHandler.INSTANCE;
}
@Override
......
......@@ -22,7 +22,7 @@ import org.eclipse.swt.graphics.Image;
import org.jkiss.dbeaver.model.data.DBDPreferences;
import org.jkiss.dbeaver.model.data.DBDValueHandler;
import org.jkiss.dbeaver.model.data.DBDValueHandlerProvider;
import org.jkiss.dbeaver.model.impl.DBCDefaultValueHandler;
import org.jkiss.dbeaver.model.impl.data.DefaultValueHandler;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
/**
......@@ -39,7 +39,7 @@ public class WMIValueHandlerProvider implements DBDValueHandlerProvider {
@Override
public DBDValueHandler getHandler(DBDPreferences preferences, DBSTypedObject typedObject)
{
return DBCDefaultValueHandler.INSTANCE;
return DefaultValueHandler.INSTANCE;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册