提交 87ce3291 编写于 作者: J jurgen

Grid performance (ged rid of thousands of new GridPos)

上级 c0d97f38
......@@ -24,6 +24,7 @@ package org.jkiss.dbeaver.ui.controls.lightgrid;
*/
public class GridPos
{
private static long count = 0;
public int col;
public int row;
......@@ -31,14 +32,24 @@ public class GridPos
{
this.col = col;
this.row = row;
// measureCount();
}
public GridPos(GridPos copy)
{
this.col = copy.col;
this.row = copy.row;
// measureCount();
}
// private static void measureCount()
// {
// count++;
// if (count % 1000 == 0) {
// System.out.println(count);
// }
// }
public boolean isValid()
{
return col >= 0 && row >= 0;
......
/*
* Copyright (C) 2010-2012 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.ui.controls.lightgrid;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
public interface IGridLabelProvider {
public String getText(int col, int row);
public Image getImage(int col, int row);
Color getForeground(int col, int row);
Color getBackground(int col, int row);
}
......@@ -107,6 +107,7 @@ public abstract class LightGrid extends Canvas {
private GridColumn shiftSelectionAnchorColumn;
private GridColumn focusColumn;
private final GridPos focusCell = new GridPos(-1, -1);
/**
* List of table columns in creation/index order.
......@@ -463,7 +464,7 @@ public abstract class LightGrid extends Canvas {
public abstract IGridContentProvider getContentProvider();
public abstract ILabelProvider getContentLabelProvider();
public abstract IGridLabelProvider getContentLabelProvider();
public abstract ILabelProvider getColumnLabelProvider();
......@@ -4039,8 +4040,9 @@ public abstract class LightGrid extends Canvas {
if (focusColumn != null)
x = focusColumn.getIndex();
return new GridPos(x, focusItem);
focusCell.col = x;
focusCell.row = focusItem;
return focusCell;
}
/**
......@@ -4680,9 +4682,9 @@ public abstract class LightGrid extends Canvas {
public String getCellText(int column, int row)
{
ILabelProvider contentLabelProvider = getContentLabelProvider();
IGridLabelProvider contentLabelProvider = getContentLabelProvider();
if (contentLabelProvider != null) {
String text = contentLabelProvider.getText(new GridPos(column, row));
String text = contentLabelProvider.getText(column, row);
// Truncate too long texts (they are really bad for performance)
if (text.length() > MAX_TOOLTIP_LENGTH) {
text = text.substring(0, MAX_TOOLTIP_LENGTH) + " ...";
......@@ -4695,7 +4697,7 @@ public abstract class LightGrid extends Canvas {
public String getCellToolTip(int column, int row)
{
ILabelProvider contentLabelProvider = getContentLabelProvider();
IGridLabelProvider contentLabelProvider = getContentLabelProvider();
if (contentLabelProvider != null) {
String toolTip = getCellText(column, row);
if (toolTip == null) {
......@@ -4731,30 +4733,24 @@ public abstract class LightGrid extends Canvas {
public Image getCellImage(int column, int row)
{
ILabelProvider contentLabelProvider = getContentLabelProvider();
IGridLabelProvider contentLabelProvider = getContentLabelProvider();
if (contentLabelProvider != null) {
return contentLabelProvider.getImage(new GridPos(column, row));
return contentLabelProvider.getImage(column, row);
}
return null;
}
public Color getCellBackground(int column, int row)
{
ILabelProvider contentLabelProvider = getContentLabelProvider();
Color color = null;
if (contentLabelProvider instanceof IColorProvider) {
color = ((IColorProvider)contentLabelProvider).getBackground(new GridPos(column, row));
}
IGridLabelProvider contentLabelProvider = getContentLabelProvider();
Color color = contentLabelProvider.getBackground(column, row);
return color != null ? color : getBackground();
}
public Color getCellForeground(int column, int row)
{
ILabelProvider contentLabelProvider = getContentLabelProvider();
Color color = null;
if (contentLabelProvider instanceof IColorProvider) {
color = ((IColorProvider)contentLabelProvider).getForeground(new GridPos(column, row));
}
IGridLabelProvider contentLabelProvider = getContentLabelProvider();
Color color = contentLabelProvider.getForeground(column, row);
return color != null ? color : getForeground();
}
......
......@@ -348,7 +348,7 @@ public class ResultSetModel {
boolean isRowAdded(int row)
{
return addedRows.contains(new RowInfo(row));
return !addedRows.isEmpty() && addedRows.contains(new RowInfo(row));
}
void addNewRow(int rowNum, Object[] data)
......@@ -360,7 +360,7 @@ public class ResultSetModel {
boolean isRowDeleted(int row)
{
return removedRows.contains(new RowInfo(row));
return !removedRows.isEmpty() && removedRows.contains(new RowInfo(row));
}
/**
......
......@@ -85,6 +85,7 @@ import org.jkiss.dbeaver.ui.*;
import org.jkiss.dbeaver.ui.controls.lightgrid.GridColumn;
import org.jkiss.dbeaver.ui.controls.lightgrid.GridPos;
import org.jkiss.dbeaver.ui.controls.lightgrid.IGridContentProvider;
import org.jkiss.dbeaver.ui.controls.lightgrid.IGridLabelProvider;
import org.jkiss.dbeaver.ui.controls.lightgrid.renderers.AbstractRenderer;
import org.jkiss.dbeaver.ui.controls.spreadsheet.ISpreadsheetController;
import org.jkiss.dbeaver.ui.controls.spreadsheet.Spreadsheet;
......@@ -2414,10 +2415,9 @@ public class ResultSetViewer extends Viewer implements IDataSourceProvider, ISpr
}
}
private class ContentLabelProvider extends LabelProvider implements IColorProvider {
private Object getValue(Object element, boolean formatString)
private class ContentLabelProvider implements IGridLabelProvider {
private Object getValue(int col, int row, boolean formatString)
{
GridPos cell = (GridPos)element;
Object value;
DBDValueHandler valueHandler;
int rowNum;
......@@ -2430,24 +2430,24 @@ public class ResultSetViewer extends Viewer implements IDataSourceProvider, ISpr
return "";
}
Object[] values = model.getRowData(curRowNum);
if (cell.row >= values.length) {
log.warn("Bad record row number: " + cell.row);
if (row >= values.length) {
log.warn("Bad record row number: " + row);
return null;
}
value = values[cell.row];
valueHandler = model.getVisibleColumn(cell.row).getValueHandler();
value = values[row];
valueHandler = model.getVisibleColumn(row).getValueHandler();
} else {
rowNum = cell.row;
if (cell.row >= rowCount) {
log.warn("Bad grid row number: " + cell.row);
rowNum = row;
if (row >= rowCount) {
log.warn("Bad grid row number: " + row);
return null;
}
if (cell.col >= model.getVisibleColumnCount()) {
log.warn("Bad grid column number: " + cell.col);
if (col >= model.getVisibleColumnCount()) {
log.warn("Bad grid column number: " + col);
return null;
}
value = model.getCellValue(cell.row, cell.col);
valueHandler = model.getVisibleColumn(cell.col).getValueHandler();
value = model.getCellValue(row, col);
valueHandler = model.getVisibleColumn(col).getValueHandler();
}
if (rowNum == rowCount - 1 && (mode == ResultSetMode.RECORD || spreadsheet.isRowVisible(rowNum)) && dataReceiver.isHasMoreData()) {
......@@ -2456,7 +2456,7 @@ public class ResultSetViewer extends Viewer implements IDataSourceProvider, ISpr
if (formatString) {
return valueHandler.getValueDisplayString(
model.getVisibleColumn(cell.col).getMetaAttribute(),
model.getVisibleColumn(col).getMetaAttribute(),
value,
DBDDisplayFormat.UI);
} else {
......@@ -2465,20 +2465,19 @@ public class ResultSetViewer extends Viewer implements IDataSourceProvider, ISpr
}
@Override
public Image getImage(Object element)
public Image getImage(int col, int row)
{
GridPos cell = (GridPos)element;
DBDAttributeBinding attr;
if (mode == ResultSetMode.RECORD) {
if (cell.row >= model.getVisibleColumnCount()) {
if (row >= model.getVisibleColumnCount()) {
return null;
}
attr = model.getVisibleColumn(cell.row);
attr = model.getVisibleColumn(row);
} else {
if (cell.col >= model.getVisibleColumnCount()) {
if (col >= model.getVisibleColumnCount()) {
return null;
}
attr = model.getVisibleColumn(cell.col);
attr = model.getVisibleColumn(col);
}
if ((attr.getValueHandler().getFeatures() & DBDValueHandler.FEATURE_SHOW_ICON) != 0) {
return getTypeImage(attr.getMetaAttribute());
......@@ -2488,15 +2487,15 @@ public class ResultSetViewer extends Viewer implements IDataSourceProvider, ISpr
}
@Override
public String getText(Object element)
public String getText(int col, int row)
{
return String.valueOf(getValue(element, true));
return String.valueOf(getValue(col, row, true));
}
@Override
public Color getForeground(Object element)
public Color getForeground(int col, int row)
{
Object value = getValue(element, false);
Object value = getValue(col, row, false);
if (DBUtils.isNullValue(value)) {
return foregroundNull;
} else {
......@@ -2505,16 +2504,20 @@ public class ResultSetViewer extends Viewer implements IDataSourceProvider, ISpr
}
@Override
public Color getBackground(Object element)
public Color getBackground(int col, int row)
{
GridPos cell = translateGridPos((GridPos)element);
if (model.isRowAdded(cell.row)) {
if (mode == ResultSetMode.RECORD) {
col = row;
row = curRowNum;
}
if (model.isRowAdded(row)) {
return backgroundAdded;
}
if (model.isRowDeleted(cell.row)) {
if (model.isRowDeleted(row)) {
return backgroundDeleted;
}
if (model.isCellModified(cell)) {
if (model.isDirty() && model.isCellModified(new GridPos(col, row))) {
return backgroundModified;
}
return null;
......
......@@ -59,7 +59,7 @@ public class Spreadsheet extends LightGrid implements Listener {
private IWorkbenchPartSite site;
private ISpreadsheetController spreadsheetController;
private IGridContentProvider contentProvider;
private ILabelProvider contentLabelProvider;
private IGridLabelProvider contentLabelProvider;
private ILabelProvider columnLabelProvider;
private ILabelProvider rowLabelProvider;
......@@ -82,7 +82,7 @@ public class Spreadsheet extends LightGrid implements Listener {
final IWorkbenchPartSite site,
final ISpreadsheetController spreadsheetController,
final IGridContentProvider contentProvider,
final ILabelProvider contentLabelProvider,
final IGridLabelProvider contentLabelProvider,
final ILabelProvider columnLabelProvider,
final ILabelProvider rowLabelProvider
)
......@@ -474,7 +474,7 @@ public class Spreadsheet extends LightGrid implements Listener {
}
@Override
public ILabelProvider getContentLabelProvider()
public IGridLabelProvider getContentLabelProvider()
{
return contentLabelProvider;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册