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

Column controller typing


Former-commit-id: d10b5488
上级 9ffe7ef5
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2018 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.controls;
/**
* IColumnTextProvider
*/
public interface IColumnTextProvider<ELEMENT>
{
String getText(ELEMENT element);
}
\ No newline at end of file
...@@ -46,7 +46,7 @@ import java.util.List; ...@@ -46,7 +46,7 @@ import java.util.List;
/** /**
* Tree/table viewer column controller * Tree/table viewer column controller
*/ */
public class ViewerColumnController { public class ViewerColumnController<ELEMENT> {
private static final Log log = Log.getLog(ViewerColumnController.class); private static final Log log = Log.getLog(ViewerColumnController.class);
...@@ -73,9 +73,7 @@ public class ViewerColumnController { ...@@ -73,9 +73,7 @@ public class ViewerColumnController {
control.setData(DATA_KEY, this); control.setData(DATA_KEY, this);
if (control instanceof Tree || control instanceof Table) { if (control instanceof Tree || control instanceof Table) {
menuListener = new Listener() { menuListener = event -> {
@Override
public void handleEvent(Event event) {
Point pt = control.getDisplay().map(null, control, new Point(event.x, event.y)); Point pt = control.getDisplay().map(null, control, new Point(event.x, event.y));
Rectangle clientArea = ((Composite) control).getClientArea(); Rectangle clientArea = ((Composite) control).getClientArea();
if (RuntimeUtils.isPlatformMacOS()) { if (RuntimeUtils.isPlatformMacOS()) {
...@@ -87,7 +85,6 @@ public class ViewerColumnController { ...@@ -87,7 +85,6 @@ public class ViewerColumnController {
clickOnHeader = clientArea.y <= pt.y && pt.y < (clientArea.y + ((Table) control).getHeaderHeight()); clickOnHeader = clientArea.y <= pt.y && pt.y < (clientArea.y + ((Table) control).getHeaderHeight());
} }
} }
}
}; };
control.addListener(SWT.MenuDetect, menuListener); control.addListener(SWT.MenuDetect, menuListener);
} }
...@@ -120,6 +117,16 @@ public class ViewerColumnController { ...@@ -120,6 +117,16 @@ public class ViewerColumnController {
}); });
} }
public void addColumn(String name, String description, int style, boolean defaultVisible, boolean required, IColumnTextProvider<ELEMENT> labelProvider)
{
addColumn(name, description, style, defaultVisible, required, false, null, new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(labelProvider.getText((ELEMENT) cell.getElement()));
}
}, null);
}
public void addColumn(String name, String description, int style, boolean defaultVisible, boolean required, CellLabelProvider labelProvider) public void addColumn(String name, String description, int style, boolean defaultVisible, boolean required, CellLabelProvider labelProvider)
{ {
addColumn(name, description, style, defaultVisible, required, false, null, labelProvider, null); addColumn(name, description, style, defaultVisible, required, false, null, labelProvider, null);
...@@ -317,13 +324,12 @@ public class ViewerColumnController { ...@@ -317,13 +324,12 @@ public class ViewerColumnController {
if (columnInfo.labelProvider instanceof ILazyLabelProvider) { if (columnInfo.labelProvider instanceof ILazyLabelProvider) {
hasLazyColumns = true; hasLazyColumns = true;
} else if (columnInfo.labelProvider instanceof ILabelProvider) { } else if (columnInfo.labelProvider instanceof ILabelProvider) {
columnInfo.sortListener = new SortListener(columnInfo); columnInfo.sortListener = new SortListener(viewer, columnInfo);
columnInfo.column.addListener(SWT.Selection, columnInfo.sortListener); columnInfo.column.addListener(SWT.Selection, columnInfo.sortListener);
} }
} }
if (hasLazyColumns) { if (hasLazyColumns) {
viewer.getControl().addListener(SWT.PaintItem, new Listener() { viewer.getControl().addListener(SWT.PaintItem, event -> {
public void handleEvent(Event event) {
if (viewer instanceof TreeViewer) { if (viewer instanceof TreeViewer) {
TreeColumn column = ((TreeViewer) viewer).getTree().getColumn(event.index); TreeColumn column = ((TreeViewer) viewer).getTree().getColumn(event.index);
if (((ColumnInfo) column.getData()).labelProvider instanceof ILazyLabelProvider && if (((ColumnInfo) column.getData()).labelProvider instanceof ILazyLabelProvider &&
...@@ -343,7 +349,6 @@ public class ViewerColumnController { ...@@ -343,7 +349,6 @@ public class ViewerColumnController {
} }
} }
} }
}
}); });
} }
...@@ -357,7 +362,7 @@ public class ViewerColumnController { ...@@ -357,7 +362,7 @@ public class ViewerColumnController {
visibleList.add(column); visibleList.add(column);
} }
} }
Collections.sort(visibleList, new ColumnInfoComparator()); visibleList.sort(new ColumnInfoComparator());
return visibleList; return visibleList;
} }
...@@ -504,19 +509,17 @@ public class ViewerColumnController { ...@@ -504,19 +509,17 @@ public class ViewerColumnController {
UIUtils.createControlLabel(composite, "Select columns you want to display"); UIUtils.createControlLabel(composite, "Select columns you want to display");
List<ColumnInfo> orderedList = new ArrayList<>(columns); List<ColumnInfo> orderedList = new ArrayList<>(columns);
Collections.sort(orderedList, new ColumnInfoComparator()); orderedList.sort(new ColumnInfoComparator());
colTable = new Table(composite, SWT.BORDER | SWT.CHECK | SWT.H_SCROLL | SWT.V_SCROLL); colTable = new Table(composite, SWT.BORDER | SWT.CHECK | SWT.H_SCROLL | SWT.V_SCROLL);
colTable.setLayoutData(new GridData(GridData.FILL_BOTH)); colTable.setLayoutData(new GridData(GridData.FILL_BOTH));
colTable.setLinesVisible(true); colTable.setLinesVisible(true);
colTable.addListener(SWT.Selection,new Listener() { colTable.addListener(SWT.Selection, event -> {
public void handleEvent(Event event) {
if( event.detail == SWT.CHECK ) { if( event.detail == SWT.CHECK ) {
if (((TableItem)event.item).getGrayed()) { if (((TableItem)event.item).getGrayed()) {
((TableItem)event.item).setChecked(true); ((TableItem)event.item).setChecked(true);
event.doit = false; event.doit = false;
} }
} }
}
}); });
final TableColumn nameColumn = new TableColumn(colTable, SWT.LEFT); final TableColumn nameColumn = new TableColumn(colTable, SWT.LEFT);
nameColumn.setText("Name"); nameColumn.setText("Name");
...@@ -594,13 +597,15 @@ public class ViewerColumnController { ...@@ -594,13 +597,15 @@ public class ViewerColumnController {
} }
} }
private class SortListener implements Listener private static class SortListener implements Listener
{ {
ColumnViewer viewer;
ColumnInfo columnInfo; ColumnInfo columnInfo;
int sortDirection = SWT.DOWN; int sortDirection = SWT.DOWN;
Item prevColumn = null; Item prevColumn = null;
public SortListener(ColumnInfo columnInfo) { public SortListener(ColumnViewer viewer, ColumnInfo columnInfo) {
this.viewer = viewer;
this.columnInfo = columnInfo; this.columnInfo = columnInfo;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册