提交 192c4d92 编写于 作者: J jurgen

Value handlers refactoring

上级 8917513d
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 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;
import org.eclipse.jface.action.IContributionManager;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPPropertyManager;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.ui.data.IValueController;
import org.jkiss.dbeaver.ui.data.IValueEditor;
import org.jkiss.dbeaver.ui.data.IValueManager;
import org.jkiss.dbeaver.ui.data.editors.StringInlineEditor;
import org.jkiss.dbeaver.ui.dialogs.data.TextViewDialog;
/**
* Default value handler
*/
public class DefaultValueManager implements IValueManager {
public static final DefaultValueManager INSTANCE = new DefaultValueManager();
@Override
public void contributeActions(@NotNull IContributionManager manager, @NotNull IValueController controller) throws DBCException {
// nothing
}
@Override
public void contributeProperties(@NotNull DBPPropertyManager propertySource, @NotNull IValueController controller) {
// nothing
}
@Override
public IValueEditor createEditor(@NotNull final IValueController controller) throws DBException {
switch (controller.getEditType()) {
case INLINE:
case PANEL:
return new StringInlineEditor(controller);
case EDITOR:
return new TextViewDialog(controller);
default:
return null;
}
}
}
......@@ -21,8 +21,11 @@ package org.jkiss.dbeaver.ui.data.registry;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.DBPDataKind;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.ui.data.IValueManager;
import org.jkiss.dbeaver.ui.data.managers.DefaultValueManager;
import java.util.ArrayList;
import java.util.List;
......@@ -55,9 +58,10 @@ public class DataManagerRegistry {
}
}
public DataManagerDescriptor findManager(DBPDataSource dataSource, DBPDataKind dataKind, Class<?> valueType) {
@NotNull
public IValueManager getManager(@NotNull DBPDataSource dataSource, @NotNull DBPDataKind dataKind, @NotNull Class<?> valueType) {
// Check starting from most restrictive to less restrictive
DataManagerDescriptor manager = findManager(dataSource, dataKind, valueType, true, true);
IValueManager manager = findManager(dataSource, dataKind, valueType, true, true);
if (manager == null) {
manager = findManager(dataSource, dataKind, valueType, false, true);
}
......@@ -67,13 +71,16 @@ public class DataManagerRegistry {
if (manager == null) {
manager = findManager(dataSource, dataKind, valueType, false, false);
}
if (manager == null) {
manager = DefaultValueManager.INSTANCE;
}
return manager;
}
private DataManagerDescriptor findManager(DBPDataSource dataSource, DBPDataKind dataKind, Class<?> valueType, boolean checkDataSource, boolean checkType) {
private IValueManager findManager(DBPDataSource dataSource, DBPDataKind dataKind, Class<?> valueType, boolean checkDataSource, boolean checkType) {
for (DataManagerDescriptor manager : managers) {
if (manager.supportsType(dataSource, dataKind, valueType, checkDataSource, checkType)) {
return manager;
return manager.getInstance();
}
}
return null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册