Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2014-02-07 09:26:30 -0500
committervlorenzo2014-02-07 09:26:30 -0500
commitedb4caf6b97c8669137abd99accec986c7074bf6 (patch)
treeb5c72043ef3d4e89d5c83bc9b651f6fb6505a4fd /extraplugins
parentc4cb44ab3af3362771331b5a3dd510a45dbc041e (diff)
downloadorg.eclipse.papyrus-edb4caf6b97c8669137abd99accec986c7074bf6.tar.gz
org.eclipse.papyrus-edb4caf6b97c8669137abd99accec986c7074bf6.tar.xz
org.eclipse.papyrus-edb4caf6b97c8669137abd99accec986c7074bf6.zip
423675: ENTER & ALT-ENTER shortcuts in textual cells of the new tables
are counter-intuitive (opposite of Excel) https://bugs.eclipse.org/bugs/show_bug.cgi?id=423675 Add auto resize of the text widget when the user add a line
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/MultiLineTextCellEditorEx.java44
1 files changed, 43 insertions, 1 deletions
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/MultiLineTextCellEditorEx.java b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/MultiLineTextCellEditorEx.java
index e0f9f1be5ee..125a68e0082 100644
--- a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/MultiLineTextCellEditorEx.java
+++ b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/celleditor/MultiLineTextCellEditorEx.java
@@ -70,7 +70,35 @@ public class MultiLineTextCellEditorEx extends MultiLineTextCellEditor {
if(this.initialValueForFilteringKeyPress) {
service.setKeyFilterEnabled(false);
}
- return super.createEditorControl(parent);
+ final Text text = super.createEditorControl(parent);
+
+ //this listener allows us to initialize the text widget wit the best size in order to display the full lines of the text
+ text.addControlListener(new ControlListener() {
+
+ @Override
+ public void controlResized(ControlEvent e) {
+ final Rectangle bounds = text.getBounds();
+ final int nbLines = text.getLineCount();
+ text.removeControlListener(this);
+ if(nbLines > 1) {
+ text.setBounds(bounds.x, bounds.y, bounds.width, getBestHeight(text));
+ }
+ text.removeControlListener(this);
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.swt.events.ControlListener#controlMoved(org.eclipse.swt.events.ControlEvent)
+ *
+ * @param e
+ */
+ @Override
+ public void controlMoved(ControlEvent e) {
+ // nothing to do
+ }
+ });
+ return text;
}
/**
@@ -100,8 +128,22 @@ public class MultiLineTextCellEditorEx extends MultiLineTextCellEditor {
protected void keyPressed(Composite parent, Text text, KeyEvent event) {
if(event.stateMask == SWT.ALT && (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR)) {
text.insert(text.getLineDelimiter());
+ //we resize the text widget in order to display all lines
+ final Rectangle bounds = text.getBounds();
+ text.setBounds(bounds.x, bounds.y, bounds.width, getBestHeight(text));
} else {
super.keyPressed(parent, text, event);
}
}
+
+ /**
+ *
+ * @param text
+ * the text widget
+ * @return
+ * the best height for the text widget according to the number of new line in the text + the height ot a line
+ */
+ protected final int getBestHeight(final Text text){
+ return (text.getLineCount()+1)* text.getLineHeight();
+ }
}

Back to the top