/* * Created on 04.03.2005 * by Richard Birenheide (D035816) * * Copyright SAP AG 2005 */ package org.eclipse.swt.custom; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableItem; /** * TODO add type comment *

* @author Richard Birenheide (D035816) */ public class SapTableEditor extends TableEditor { private final Table table; private final boolean[] placeEditorOnImage; public SapTableEditor(final Table table, final boolean[] placeEditorOnImage) { super(table); this.table = table; if (placeEditorOnImage == null) { this.placeEditorOnImage = null; } else { this.placeEditorOnImage = (boolean[]) placeEditorOnImage.clone(); } } public SapTableEditor(Table table) { this(table, null); } Rectangle computeBounds () { if (this.placeEditorOnImage == null) { return super.computeBounds(); } TableItem item = super.getItem(); int column = super.getColumn(); if (item == null || column == -1 || item.isDisposed()) return new Rectangle(0, 0, 0, 0); Rectangle cell = item.getBounds(column); Rectangle rect = item.getImageBounds(column); if (this.placeEditorOnImage()) { cell.x = rect.x; } else { cell.x = rect.x + rect.width; cell.width -= rect.width; } Rectangle area = table.getClientArea(); if (cell.x < area.x + area.width) { if (cell.x + cell.width > area.x + area.width) { cell.width = area.x + area.width - cell.x; } } Rectangle editorRect = new Rectangle(cell.x, cell.y, minimumWidth, minimumHeight); if (grabHorizontal) { editorRect.width = Math.max(cell.width, minimumWidth); } if (grabVertical) { editorRect.height = Math.max(cell.height, minimumHeight); } if (horizontalAlignment == SWT.RIGHT) { editorRect.x += cell.width - editorRect.width; } else if (horizontalAlignment == SWT.LEFT) { // do nothing - cell.x is the right answer } else { // default is CENTER editorRect.x += (cell.width - editorRect.width)/2; } if (verticalAlignment == SWT.BOTTOM) { editorRect.y += cell.height - editorRect.height; } else if (verticalAlignment == SWT.TOP) { // do nothing - cell.y is the right answer } else { // default is CENTER editorRect.y += (cell.height - editorRect.height)/2; } return editorRect; } private boolean placeEditorOnImage() { if (this.placeEditorOnImage == null) { return false; } int column = this.getColumn(); if (column < 0 || column >= this.placeEditorOnImage.length) { return false; } return this.placeEditorOnImage[column]; } }