提交 301d7f8d 编写于 作者: S Serge Rider

Boolean value editor/renderer redesign/fix

上级 7241cfdc
......@@ -20,20 +20,23 @@ package org.jkiss.dbeaver.ui.controls;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.jkiss.dbeaver.model.DBConstants;
import org.jkiss.utils.CommonUtils;
/**
* Checkbox cell editor
*/
public class CustomCheckboxCellEditor extends CellEditor {
private Button checkbox;
private CCombo combo;
public CustomCheckboxCellEditor(Composite parent) {
this(parent, SWT.NONE);
......@@ -54,21 +57,22 @@ public class CustomCheckboxCellEditor extends CellEditor {
gl.marginWidth = 0;
placeholder.setLayout(gl);
checkbox = new Button(placeholder, SWT.CHECK);
final GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_CENTER);
gd.verticalIndent = 2;
gd.horizontalIndent = 4;
combo = new CCombo(placeholder, SWT.DROP_DOWN | SWT.READ_ONLY);
final GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
// gd.verticalIndent = 2;
// gd.horizontalIndent = 4;
gd.grabExcessHorizontalSpace = true;
checkbox.setLayoutData(gd);
checkbox.setFont(parent.getFont());
checkbox.addFocusListener(new FocusAdapter() {
combo.add(DBConstants.BOOLEAN_PROP_NO);
combo.add(DBConstants.BOOLEAN_PROP_YES);
combo.setLayoutData(gd);
combo.setFont(parent.getFont());
combo.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e)
{
public void focusLost(FocusEvent e) {
applyEditorValue();
}
});
// checkbox.addSelectionListener(new SelectionAdapter() {
// combo.addSelectionListener(new SelectionAdapter() {
// public void widgetDefaultSelected(SelectionEvent event) {
// applyEditorValue();
// }
......@@ -82,15 +86,15 @@ public class CustomCheckboxCellEditor extends CellEditor {
}
@Override
protected Object doGetValue() {
return checkbox.getSelection();
protected Boolean doGetValue() {
return combo.getSelectionIndex() > 0;
}
@Override
protected void doSetFocus() {
checkbox.setFocus();
//checkbox.setSelection(!checkbox.getSelection());
// checkbox.getDisplay().asyncExec(new Runnable() {
combo.setFocus();
//combo.setSelection(!combo.getSelection());
// combo.getDisplay().asyncExec(new Runnable() {
// public void run()
// {
// applyEditorValue();
......@@ -100,8 +104,8 @@ public class CustomCheckboxCellEditor extends CellEditor {
@Override
protected void doSetValue(Object value) {
Assert.isTrue(checkbox != null && (value instanceof Boolean));
checkbox.setSelection((Boolean)value);
Assert.isTrue(combo != null && (value instanceof Boolean));
combo.select(CommonUtils.toBoolean(value) ? 1 : 0);
}
@Override
......
......@@ -27,6 +27,7 @@ import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.DBPNamedObject;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.ui.ImageUtils;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
......@@ -170,17 +171,17 @@ public abstract class ObjectViewerRenderer {
Object cellValue = getCellValue(element, columnIndex);
if (cellValue != null ) {
GC gc = event.gc;
if (cellValue instanceof Boolean) {
/*if (cellValue instanceof Boolean) {
//int columnWidth = UIUtils.getColumnWidth(item);
int columnHeight = isTree ? getTree().getItemHeight() : getTable().getItemHeight();
Image image = (Boolean)cellValue ?
(editable ? ImageUtils.getImageCheckboxEnabledOn() : ImageUtils.getImageCheckboxDisabledOn()) :
(editable ? ImageUtils.getImageCheckboxEnabledOff() : ImageUtils.getImageCheckboxDisabledOff());
final Rectangle imageBounds = image.getBounds();
gc.drawImage(image, event.x + 4/*(columnWidth - imageBounds.width) / 2*/, event.y + (columnHeight - imageBounds.height) / 2);
gc.drawImage(image, event.x + 4*//*(columnWidth - imageBounds.width) / 2*//*, event.y + (columnHeight - imageBounds.height) / 2);
event.doit = false;
// System.out.println("PAINT " + cellValue + " " + System.currentTimeMillis());
} else if (isHyperlink(cellValue)) {
} else */if (isHyperlink(cellValue)) {
// Print link
boolean isSelected = gc.getBackground().equals(selectionBackgroundColor);
prepareLinkStyle(cellValue, isSelected ? gc.getForeground() : null);
......@@ -318,11 +319,12 @@ public abstract class ObjectViewerRenderer {
public static String getCellString(@Nullable Object value)
{
if (value == null || value instanceof Boolean) {
if (value == null) {
return "";
}
if (value instanceof DBPNamedObject) {
} else if (value instanceof DBPNamedObject) {
value = ((DBPNamedObject)value).getName();
} else if (value instanceof Boolean) {
value = DBUtils.getBooleanString((Boolean) value);
}
return GeneralUtils.makeDisplayString(value).toString();
}
......
......@@ -32,9 +32,7 @@ import org.eclipse.swt.widgets.*;
import org.eclipse.ui.views.properties.IPropertySource2;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.DBPObject;
import org.jkiss.dbeaver.model.DBPPropertyDescriptor;
import org.jkiss.dbeaver.model.DBPPropertySource;
import org.jkiss.dbeaver.model.*;
import org.jkiss.dbeaver.model.navigator.DBNDatabaseNode;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.runtime.properties.IPropertySourceEditable;
......@@ -220,7 +218,7 @@ public class PropertyTreeViewer extends TreeViewer {
}
TreeNode category = (parent != null ? parent : categories.get(categoryName));
if (category == null) {
category = new TreeNode(parent, propertySource, categoryName);
category = new TreeNode(null, propertySource, categoryName);
categories.put(categoryName, category);
}
TreeNode propNode = new TreeNode(category, propertySource, prop);
......@@ -247,7 +245,7 @@ public class PropertyTreeViewer extends TreeViewer {
}
PropertySourceCollection psc = new PropertySourceCollection(collection);
for (DBPPropertyDescriptor pd : psc.getPropertyDescriptors2()) {
TreeNode itemNode = new TreeNode(propNode, psc, pd);
new TreeNode(propNode, psc, pd);
}
}
}
......@@ -278,10 +276,8 @@ public class PropertyTreeViewer extends TreeViewer {
{
if (node instanceof TreeNode) {
TreeNode treeNode = (TreeNode) node;
if (treeNode.propertySource instanceof DBPPropertySource) {
((DBPPropertySource) treeNode.propertySource).resetPropertyValueToDefault(treeNode.property.getId());
} else {
treeNode.propertySource.resetPropertyValue(treeNode.property.getId());
if (treeNode.propertySource != null) {
treeNode.propertySource.resetPropertyValueToDefault(treeNode.property.getId());
}
treeNode.parent.children.remove(treeNode);
handlePropertyRemove(treeNode);
......@@ -295,11 +291,6 @@ public class PropertyTreeViewer extends TreeViewer {
super.refresh();
}
public DBPPropertyDescriptor getSelectedProperty()
{
return selectedProperty;
}
private void disposeOldEditor()
{
if (curCellEditor != null) {
......@@ -486,19 +477,19 @@ public class PropertyTreeViewer extends TreeViewer {
});
}
if (isPropertyChanged(prop) && prop.isEditable()) {
if (prop.propertySource instanceof IPropertySource2 && !((IPropertySource2) prop.propertySource).isPropertyResettable(prop.property.getId())) {
if (prop.propertySource instanceof IPropertySource2 && !prop.propertySource.isPropertyResettable(prop.property.getId())) {
// it is not resettable
} else {
manager.add(new ActionResetProperty(prop, false));
if (!isCustomProperty(prop.property) &&
prop.propertySource instanceof DBPPropertySource) {
if (!isCustomProperty(prop.property)) {
manager.add(new ActionResetProperty(prop, true));
}
}
}
manager.add(new Separator());
contributeContextMenu(manager, object, prop.category != null ? prop.category : prop.property.getCategory(), prop.property);
}
contributeContextMenu(manager, object, prop.category != null ? prop.category : prop.property.getCategory(), prop.property);
}
}
});
......@@ -612,10 +603,10 @@ public class PropertyTreeViewer extends TreeViewer {
boolean isEditable()
{
if (property instanceof DBPPropertyDescriptor) {
return ((DBPPropertyDescriptor) property).isEditable(propertySource.getEditableValue());
if (property != null) {
return property.isEditable(propertySource.getEditableValue());
} else {
return property != null;
return false;
}
}
}
......@@ -690,10 +681,11 @@ public class PropertyTreeViewer extends TreeViewer {
} else {
if (node.property != null) {
final Object propertyValue = getPropertyValue(node);
if (propertyValue == null || propertyValue instanceof Boolean || renderer.isHyperlink(propertyValue)) {
if (propertyValue == null || renderer.isHyperlink(propertyValue)) {
return ""; //$NON-NLS-1$
}
if (BeanUtils.isCollectionType(propertyValue.getClass())) {
} else if (propertyValue instanceof Boolean) {
return DBUtils.getBooleanString((Boolean) propertyValue);
} else if (BeanUtils.isCollectionType(propertyValue.getClass())) {
return "";
}
return CommonUtils.toString(propertyValue);
......@@ -735,11 +727,6 @@ public class PropertyTreeViewer extends TreeViewer {
boolean changed = false;
if (node.property != null) {
changed = node.isEditable() && isPropertyChanged(node);
/*
if (((DBPProperty)element).isRequired() && cell.getColumnIndex() == 0) {
cell.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
}
*/
}
if (extraLabelProvider instanceof IFontProvider) {
cell.setFont(((IFontProvider) extraLabelProvider).getFont(node.property));
......@@ -807,10 +794,12 @@ public class PropertyTreeViewer extends TreeViewer {
@Override
public void run()
{
if (toDefault && prop.propertySource instanceof DBPPropertySource) {
((DBPPropertySource) prop.propertySource).resetPropertyValueToDefault(prop.property.getId());
} else {
prop.propertySource.resetPropertyValue(prop.property.getId());
if (prop.propertySource != null) {
if (toDefault) {
prop.propertySource.resetPropertyValueToDefault(prop.property.getId());
} else {
prop.propertySource.resetPropertyValue(prop.property.getId());
}
}
handlePropertyChange(prop);
PropertyTreeViewer.this.update(prop, null);
......@@ -839,4 +828,5 @@ public class PropertyTreeViewer extends TreeViewer {
}
}
}
}
......@@ -49,4 +49,6 @@ public class DBConstants {
"number" //NON-NLS-1
};
public static final String BOOLEAN_PROP_YES = "yes";
public static final String BOOLEAN_PROP_NO = "no";
}
......@@ -1400,4 +1400,7 @@ public final class DBUtils {
return (Class<T>) Class.forName(className, true, dataSource.getContainer().getDriver().getClassLoader());
}
public static String getBooleanString(boolean propertyValue) {
return propertyValue ? DBConstants.BOOLEAN_PROP_YES : DBConstants.BOOLEAN_PROP_NO;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册