Presentation and text box
Hello to the forum members,
I am trying to create a presentation with a table and text box underneath it. I test the resize behavior of the presentation when I click on "Maximize\Resize Down" button. When the box is empty, the behavior is ok. When it is filled with data, once the button is clicked, it is enlarged in size and stays that way in the next clicks. My colleague found out that creating a subclass of Text with customized computeSize methods solves this problem (see ReasonableySizableText class in the code below).
If anyone knows whether this is a bug or wrong usage, I'll be grateful for your comments. I attach below the presentation class. If anyone knows how to upload file instead, please let me know.
Thanks,
Gidi
-------------------------------------------------------------
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import com.ibm.team.ui.editor.ITeamFormConfiguration;
import com.ibm.team.ui.editor.ITeamFormData;
import com.ibm.team.ui.editor.ITeamFormLayout;
import com.ibm.team.ui.editor.TeamFormLayouts;
import com.ibm.team.workitem.ide.ui.internal.editor.WorkItemEditorToolkit;
import com.ibm.team.workitem.ide.ui.internal.editor.presentations.PresentationPart;
@SuppressWarnings("restriction")
public class TextBoxIAndTablePresentationPart extends PresentationPart implements MouseListener {
private class ReasonableySizableText extends Text {
public ReasonableySizableText(Composite comp, int val) {
super(comp, val);
}
public Point computeSize(int x, int y, boolean b) {
String tmpTxt = getText();
setText("");
Point retVal = super.computeSize(x, y, b);
setText(tmpTxt);
return retVal;
}
public Point computeSize(int x, int y) {
String tmpTxt = getText();
setText("");
Point retVal = super.computeSize(x, y);
setText(tmpTxt);
return retVal;
}
public void checkSubclass() {
return;
}
}
private Table table;
private Text textBox = null;
@Override
protected boolean isDirty() {
// TODO Auto-generated method stub
return false;
}
@Override
public void setInput(Object arg0) {
// TODO Auto-generated method stub
}
@Override
public void createContent(final ITeamFormLayout formLayout) {
final WorkItemEditorToolkit toolkit = (WorkItemEditorToolkit) this.getSite().getToolkit();
final Composite container = formLayout.getContainer();
final Composite mainComposite = new Composite(container, SWT.NULL);
mainComposite.setLayout(new GridLayout(1, false));
TeamFormLayouts.setLayoutData(mainComposite, ITeamFormData.LIST);
formLayout.add(mainComposite, ITeamFormConfiguration.CONTENT_GUIDE);
addTable(mainComposite, toolkit);
addTextBox(mainComposite, toolkit);
}
private void addTable(Composite parent, WorkItemEditorToolkit toolkit) {
table = toolkit.createTable(parent, SWT.VIRTUAL | SWT.BORDER | SWT.FULL_SELECTION);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final String columnLabels[] = {"Name", "ID"};
//Create columns
for (String label : columnLabels) {
TableColumn column = new TableColumn(table, SWT.NULL, table.getColumnCount());
column.setText(label);
column.pack();
}
table.setHeaderVisible(true);
//Add some data to the table
final String names[] = {"AAA", "BBB", "CCC"};
final String IDs[] = {"111", "222", "333"};
for (int i = 0; i < 3; ++i) {
TableItem item = new TableItem(table, SWT.NULL, table.getItemCount());
item.setText(0, names[i]);
item.setText(0, IDs[i]);
}
}
private void addTextBox(Composite parent, WorkItemEditorToolkit toolkit) {
textBox = new Text(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
//textBox = new ReasonableySizableText(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
textBox.setEditable(false);
textBox.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
textBox.addMouseListener(this);
}
@Override
public void mouseDoubleClick(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseDown(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseUp(MouseEvent e) {
String addition = "Some Text \n";
String addedLongText = "";
for (int i = 0; i < 20; ++i) {
addedLongText+= addition;
}
textBox.setText(addedLongText);
}
}
I am trying to create a presentation with a table and text box underneath it. I test the resize behavior of the presentation when I click on "Maximize\Resize Down" button. When the box is empty, the behavior is ok. When it is filled with data, once the button is clicked, it is enlarged in size and stays that way in the next clicks. My colleague found out that creating a subclass of Text with customized computeSize methods solves this problem (see ReasonableySizableText class in the code below).
If anyone knows whether this is a bug or wrong usage, I'll be grateful for your comments. I attach below the presentation class. If anyone knows how to upload file instead, please let me know.
Thanks,
Gidi
-------------------------------------------------------------
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import com.ibm.team.ui.editor.ITeamFormConfiguration;
import com.ibm.team.ui.editor.ITeamFormData;
import com.ibm.team.ui.editor.ITeamFormLayout;
import com.ibm.team.ui.editor.TeamFormLayouts;
import com.ibm.team.workitem.ide.ui.internal.editor.WorkItemEditorToolkit;
import com.ibm.team.workitem.ide.ui.internal.editor.presentations.PresentationPart;
@SuppressWarnings("restriction")
public class TextBoxIAndTablePresentationPart extends PresentationPart implements MouseListener {
private class ReasonableySizableText extends Text {
public ReasonableySizableText(Composite comp, int val) {
super(comp, val);
}
public Point computeSize(int x, int y, boolean b) {
String tmpTxt = getText();
setText("");
Point retVal = super.computeSize(x, y, b);
setText(tmpTxt);
return retVal;
}
public Point computeSize(int x, int y) {
String tmpTxt = getText();
setText("");
Point retVal = super.computeSize(x, y);
setText(tmpTxt);
return retVal;
}
public void checkSubclass() {
return;
}
}
private Table table;
private Text textBox = null;
@Override
protected boolean isDirty() {
// TODO Auto-generated method stub
return false;
}
@Override
public void setInput(Object arg0) {
// TODO Auto-generated method stub
}
@Override
public void createContent(final ITeamFormLayout formLayout) {
final WorkItemEditorToolkit toolkit = (WorkItemEditorToolkit) this.getSite().getToolkit();
final Composite container = formLayout.getContainer();
final Composite mainComposite = new Composite(container, SWT.NULL);
mainComposite.setLayout(new GridLayout(1, false));
TeamFormLayouts.setLayoutData(mainComposite, ITeamFormData.LIST);
formLayout.add(mainComposite, ITeamFormConfiguration.CONTENT_GUIDE);
addTable(mainComposite, toolkit);
addTextBox(mainComposite, toolkit);
}
private void addTable(Composite parent, WorkItemEditorToolkit toolkit) {
table = toolkit.createTable(parent, SWT.VIRTUAL | SWT.BORDER | SWT.FULL_SELECTION);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final String columnLabels[] = {"Name", "ID"};
//Create columns
for (String label : columnLabels) {
TableColumn column = new TableColumn(table, SWT.NULL, table.getColumnCount());
column.setText(label);
column.pack();
}
table.setHeaderVisible(true);
//Add some data to the table
final String names[] = {"AAA", "BBB", "CCC"};
final String IDs[] = {"111", "222", "333"};
for (int i = 0; i < 3; ++i) {
TableItem item = new TableItem(table, SWT.NULL, table.getItemCount());
item.setText(0, names[i]);
item.setText(0, IDs[i]);
}
}
private void addTextBox(Composite parent, WorkItemEditorToolkit toolkit) {
textBox = new Text(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
//textBox = new ReasonableySizableText(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
textBox.setEditable(false);
textBox.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
textBox.addMouseListener(this);
}
@Override
public void mouseDoubleClick(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseDown(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseUp(MouseEvent e) {
String addition = "Some Text \n";
String addedLongText = "";
for (int i = 0; i < 20; ++i) {
addedLongText+= addition;
}
textBox.setText(addedLongText);
}
}