Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Cell Editors
Cell Editors [message #459236] Wed, 03 August 2005 23:52
Bhadri Madapusi is currently offline Bhadri MadapusiFriend
Messages: 18
Registered: July 2009
Junior Member
I created a multi line / wrappable text in a table cell using
TextCellEditor(SWT.MULTI | SWT.WRAP). But whenever there is a text with muti
line I want to increase the height of the cell. I am posting my solution, if
anybody has a better solution please let me know. Your help would be
appreciated. Thx.

For some reason CellEditor.LayourData does not have maximumHeight and
verticalAlignment . So I did creatde a subclass of CellEditor called
TextAreaCellEditor provided an extension to LayoutData as follows

/**
* Struct-like layout data for cell editors, with reasonable defaults
* for all fields.
*/
public static class TextAreaLayoutData extends LayoutData{
/**
* Horizontal alignment; <code>SWT.LEFT</code> by default.
*/
public int horizontalAlignment = SWT.LEFT;

/**
* Indicates control grabs additional space; <code>true</code> by default.
*/
public boolean grabHorizontal = true;

/**
* Minimum width in pixels; <code>50</code> pixels by default.
*/
public int minimumWidth = 50;

/**
* Minimum width in pixels; <code>50</code> pixels by default.
*/
public int minimumHeight = 50;

public int verticalAlignment = SWT.TOP;
}

and created a new version of TableViewer to pass in the the height and
vertical alignment to TableEditor. I modified the
TableViewer.initTableViewerImpl to set the height and vertical alignment
when the layoutdata is of type TextAreaCellEditor.TextAreaLayoutData

/**
* Initializes the table viewer implementation.
*/
private void initTableViewerImpl() {
tableViewerImpl = new MyTableViewerImpl(this) {
Rectangle getBounds(Item item, int columnNumber) {
return ((TableItem) item).getBounds(columnNumber);
}

int getColumnCount() {
return getTable().getColumnCount();
}

Item[] getSelection() {
return getTable().getSelection();
}

void setEditor(Control w, Item item, int columnNumber) {
tableEditor.setEditor(w, (TableItem) item, columnNumber);
}

void setSelection(StructuredSelection selection, boolean b) {
BesoTableViewer.this.setSelection(selection, b);
}

void showSelection() {
getTable().showSelection();
}

void setLayoutData(CellEditor.LayoutData layoutData) {
tableEditor.grabHorizontal = layoutData.grabHorizontal;
tableEditor.horizontalAlignment =
layoutData.horizontalAlignment;
tableEditor.minimumWidth = layoutData.minimumWidth;
//TODO extra changes.
if(layoutData instanceof
TextAreaCellEditor.TextAreaLayoutData){
tableEditor.minimumHeight =
((TextAreaCellEditor.TextAreaLayoutData) layoutData).minimumHeight;
tableEditor.grabVertical = true;
tableEditor.verticalAlignment =
((TextAreaCellEditor.TextAreaLayoutData) layoutData).verticalAlignment;
}else{
tableEditor.minimumHeight = 0;
}
}

Final result: When MyViewerImpl.activateCellEditor is executed, this inturn
will call setLayout method with the current celleditor's LayoutData. So if
the cell editor is TextAreaCelleditor then setLayoutData will be called with
TextAreaLayoutData thus setting the height to my desired height.
Previous Topic:folding / unfolding composite
Next Topic:detecting popup trigger for mouse event
Goto Forum:
  


Current Time: Wed Apr 24 23:37:56 GMT 2024

Powered by FUDForum. Page generated in 0.03105 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top