提交 d1fcb8d0 编写于 作者: S serge-rider

#2663 Property viewer columns repack fix


Former-commit-id: 5e930e64
上级 db78c4f6
......@@ -95,19 +95,6 @@ public class PropertyTreeViewer extends TreeViewer {
}
treeControl.setHeaderVisible(true);
treeControl.setLinesVisible(true);
treeControl.addControlListener(new ControlAdapter() {
private boolean packing = false;
@Override
public void controlResized(ControlEvent e)
{
if (!packing) {
packing = true;
UIUtils.packColumns(treeControl, true, new float[]{0.1f, 0.9f});
}
}
});
treeControl.addListener(SWT.PaintItem, new PaintListener());
this.boldFont = UIUtils.makeBoldFont(treeControl.getFont());
......@@ -225,7 +212,8 @@ public class PropertyTreeViewer extends TreeViewer {
}
disposeOldEditor();
UIUtils.packColumns(getTree(), true, new float[]{0.5f, 0.5f});
DBeaverUI.asyncExec(() -> UIUtils.packColumns(getTree(), true, new float[]{0.5f, 0.5f}));
}
private Map<String, TreeNode> loadTreeNodes(@Nullable DBRProgressMonitor monitor, TreeNode parent, DBPPropertySource propertySource)
......@@ -363,24 +351,20 @@ public class PropertyTreeViewer extends TreeViewer {
}
}
});
treeControl.addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e)
{
if (e.detail == SWT.TRAVERSE_RETURN) {
// Set focus on editor
if (curCellEditor != null) {
curCellEditor.setFocus();
} else {
final TreeItem[] selection = treeControl.getSelection();
if (selection.length == 0) {
return;
}
showEditor(selection[0], true);
treeControl.addTraverseListener(e -> {
if (e.detail == SWT.TRAVERSE_RETURN) {
// Set focus on editor
if (curCellEditor != null) {
curCellEditor.setFocus();
} else {
final TreeItem[] selection = treeControl.getSelection();
if (selection.length == 0) {
return;
}
e.doit = false;
e.detail = SWT.TRAVERSE_NONE;
showEditor(selection[0], true);
}
e.doit = false;
e.detail = SWT.TRAVERSE_NONE;
}
});
}
......@@ -442,22 +426,18 @@ public class PropertyTreeViewer extends TreeViewer {
cellEditor.activate();
final Control editorControl = cellEditor.getControl();
if (editorControl != null) {
editorControl.addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e)
{
/*if (e.detail == SWT.TRAVERSE_RETURN) {
e.doit = false;
e.detail = SWT.TRAVERSE_NONE;
cellEditorListener.applyEditorValue();
disposeOldEditor();
} else */if (e.detail == SWT.TRAVERSE_ESCAPE) {
e.doit = false;
e.detail = SWT.TRAVERSE_NONE;
disposeOldEditor();
if (prop.isEditable()) {
new ActionResetProperty(prop, false).run();
}
editorControl.addTraverseListener(e -> {
/*if (e.detail == SWT.TRAVERSE_RETURN) {
e.doit = false;
e.detail = SWT.TRAVERSE_NONE;
cellEditorListener.applyEditorValue();
disposeOldEditor();
} else */if (e.detail == SWT.TRAVERSE_ESCAPE) {
e.doit = false;
e.detail = SWT.TRAVERSE_NONE;
disposeOldEditor();
if (prop.isEditable()) {
new ActionResetProperty(prop, false).run();
}
}
});
......@@ -480,52 +460,48 @@ public class PropertyTreeViewer extends TreeViewer {
// Register context menu
{
MenuManager menuMgr = new MenuManager();
menuMgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(final IMenuManager manager)
{
final IStructuredSelection selection = PropertyTreeViewer.this.getStructuredSelection();
menuMgr.addMenuListener(manager -> {
final IStructuredSelection selection = PropertyTreeViewer.this.getStructuredSelection();
if (selection.isEmpty()) {
return;
}
final Object object = selection.getFirstElement();
if (object instanceof TreeNode) {
final TreeNode prop = (TreeNode) object;
if (prop.property != null) {
final String stringValue = CommonUtils.toString(getPropertyValue(prop));
if (!CommonUtils.isEmpty(stringValue)) {
manager.add(new Action(CoreMessages.ui_properties_tree_viewer_action_copy_value) {
@Override
public void run()
{
UIUtils.setClipboardContents(
Display.getDefault(),
TextTransfer.getInstance(),
stringValue);
}
});
}
if (isPropertyChanged(prop) && prop.isEditable()) {
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)) {
manager.add(new ActionResetProperty(prop, true));
}
if (selection.isEmpty()) {
return;
}
final Object object = selection.getFirstElement();
if (object instanceof TreeNode) {
final TreeNode prop = (TreeNode) object;
if (prop.property != null) {
final String stringValue = CommonUtils.toString(getPropertyValue(prop));
if (!CommonUtils.isEmpty(stringValue)) {
manager.add(new Action(CoreMessages.ui_properties_tree_viewer_action_copy_value) {
@Override
public void run()
{
UIUtils.setClipboardContents(
Display.getDefault(),
TextTransfer.getInstance(),
stringValue);
}
});
}
if (isPropertyChanged(prop) && prop.isEditable()) {
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)) {
manager.add(new ActionResetProperty(prop, true));
}
}
}
manager.add(new Separator());
contributeContextMenu(
manager,
object,
prop.category != null ?
prop.category :
(prop.property == null ? null : prop.property.getCategory()),
prop.property);
}
manager.add(new Separator());
contributeContextMenu(
manager,
object,
prop.category != null ?
prop.category :
(prop.property == null ? null : prop.property.getCategory()),
prop.property);
}
});
......@@ -590,7 +566,7 @@ public class PropertyTreeViewer extends TreeViewer {
getTree().notifyListeners(SWT.Modify, event);
}
protected void handlePropertyCreate(TreeNode prop)
private void handlePropertyCreate(TreeNode prop)
{
handlePropertyChange(prop);
super.refresh(prop.parent);
......@@ -599,7 +575,7 @@ public class PropertyTreeViewer extends TreeViewer {
super.setSelection(new StructuredSelection(prop));
}
protected void handlePropertyRemove(TreeNode prop)
private void handlePropertyRemove(TreeNode prop)
{
handlePropertyChange(prop);
super.refresh(prop.parent);
......@@ -609,7 +585,7 @@ public class PropertyTreeViewer extends TreeViewer {
this.expandMode = expandMode;
}
public void setExpandSingleRoot(boolean expandSingleRoot) {
protected void setExpandSingleRoot(boolean expandSingleRoot) {
this.expandSingleRoot = expandSingleRoot;
}
......@@ -646,13 +622,8 @@ public class PropertyTreeViewer extends TreeViewer {
this(parent, propertySource, null, category);
}
boolean isEditable()
{
if (property != null) {
return property.isEditable(propertySource.getEditableValue());
} else {
return false;
}
boolean isEditable() {
return property != null && property.isEditable(propertySource.getEditableValue());
}
@Override
......@@ -728,7 +699,7 @@ public class PropertyTreeViewer extends TreeViewer {
private class PropsLabelProvider extends CellLabelProvider {
private final boolean isName;
public PropsLabelProvider(boolean isName)
PropsLabelProvider(boolean isName)
{
this.isName = isName;
}
......@@ -879,7 +850,7 @@ public class PropertyTreeViewer extends TreeViewer {
private final TreeNode prop;
private final boolean toDefault;
public ActionResetProperty(TreeNode prop, boolean toDefault)
ActionResetProperty(TreeNode prop, boolean toDefault)
{
super(CoreMessages.ui_properties_tree_viewer_action_reset_value + (!toDefault ? "" : CoreMessages.ui_properties_tree_viewer__to_default)); //$NON-NLS-2$
this.prop = prop;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册