Select All text inside CellEditor - java

I have a tableViewer where I can edit 1 column. Everytime the cellEditor from this column gains focus I want all the text that is displayed to be selected. In a normal SWT text control, we would just do text.selectAll(); , so I've set this listener for the the cellEditor inside the column EditingSupport class:
editor.getControl().addFocusListener(new FocusListener() {
#Override
public void focusGained(FocusEvent e) {
Text text = (Text) editor.getControl();
text.selectAll();
}
});
I know I can cast the cellEditor control to a Text input because I've tested it with a normal setText(); and it Works! However, the selectAll(); is not working, how can I fix this?
SOLUTION
I found the error, the code in my question above works perfectly, the reason I wasn't able to see the selectAll(); doing something is in this method:
#Override
protected Object getValue(Object element) {
String valor = MathUTILS.getBigDecimalFormatted(((ColaboradoresDespesasDocumentosLinhas) element).getValor(), PatternVARS.PATTERN_BIGDECIMAL_MILLION);
Text text = InterfaceFormatUTILS.getControlNumberFormat(editor, PatternVARS.PATTERN_BIGDECIMAL_BILLION);
return valor;
}
This is also a method from the EditingSupport class, and for some reason formatting the text control (Text text = InterfaceFormatUTILS.getControlNumberFormat(editor, PatternVARS.PATTERN_BIGDECIMAL_BILLION);) deselects all the text. Also, doing the selectAll(); in this method doesn't work..

Related

Show button if input text field is not empty in Wicket

There is input text field and submit button. I would like to show button text field not empty and otherwise button should be not visible.
TextArea<String> textMessageField = new TextArea<>("textMessage", textMessageModel);
Button submitBtn = new Button("saveReminderButton") {
#Override
protected void onConfigure() {
super.onConfigure();
String text = textMessageField.getModelObject();
setVisible(text != null && !text.isEmpty());
}
};
textMessageField.add(new OnChangeAjaxBehavior() {
#Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(submitBtn);
}
});
submitBtn.setOutputMarkupId(true);
I'm trying to use setVisible method in onConfigure but it doesnt work. I tried to use instead setEnabled and it was working but I need the same functionality with hide/show button
Since you make the button invisible you need to use submitBtn.setOutputMarkupPlaceholderTag(true); instead of submitBtn.setOutputMarkupId(true);
This is important because without setOutputMarkupPlaceholderTag(true) Wicket Wicket will render nothing for this component. With setOutputMarkupPlaceholderTag(true) it will render <htmlElement id="someId"></htmlElement>. This way Wicket Ajax could find it in the DOM and replace it with the HTML of the visible one.

How do you listen for mouse paste done in a TextField using JavaFX?

Copy text into your clipboard, right click text field and press "paste", is there a way how to listen when paste was clicked? Or rather that input text in the field changed after something was pasted this way. Because these do not work in this particular case:
setOnKeyReleased()
setOnInputMethodTextChanged()
The "paste" functionality is implemented in the TextInputControl superclass of TextField in public void paste(). So, while it's not really an event-driven or MVC approach, you can react to a "paste" action (whether it's invoked by mouse or keyboard shortcut, typically ctrl-V) by overriding this method:
TextField tf = new TextField() {
#Override
public void paste() {
super.paste();
System.out.println("text pasted in");
}
}
you could just listen to text property changes.
example with a search text field:
tf_search.textProperty().addListener((observableValue, oldValue, newValue) -> {
onSearch();
});
The other approach would be to override the appropriate method using Clipboard.
TextField tf = new TextField() {
#Override
public void paste() {
Clipboard clipboard = Clipboard.getSystemClipboard();
if (clipboard.hasString()) {
replaceSelection(clipboard.getString());
}
}
};

Wicket text input disappears after setEnable on TextArea

I have a TextArea, and a associated CheckBox to disable and enable the TextArea (setEnabled(Boolean)), which is used to decide if it is a required field or not.
My problem is that Wicket does not keep the text in the TextArea when it is disabled (setEnabled(false)). It clears the input.
How do I keep the value in the TextArea before setEnabled is called on it? I need to update the Model serverside,
Can I do a AJAX request to update it? I haven't found any example.
checkBox.add(new AjaxFormComponentUpdatingBehavior("onchange") {
#Override
protected void onUpdate(AjaxRequestTarget target) {
if (textField.isEnabled()) {
textField.inputChanged();
// Update text input in PropertyModel….
}
textField.setEnabled(false); // This change in state does not include text that have been typed in
tekstFelt.setRequired(false);
target.add(textField);
}
});
You must add an AjaxFormComponentUpdatingBehavior for the blur event to the TextArea so that when you type in the textarea and leave the textarea (lose focus = blur) what you typed will be persisted by the model. Sample code:
private TextArea textarea() {
TextArea textarea = new TextArea("textarea", new PropertyModel<String>(this, "value")){
#Override
protected void onConfigure() {
setEnabled(condition());
}
};
textarea.setOutputMarkupId(true);
textarea.add(new AjaxFormComponentUpdatingBehavior("blur") {
#Override
protected void onUpdate(AjaxRequestTarget target) {
}
});
return textarea;
}
I also recommend that wheter the textarea is enabled or not you should set in onConfigure() of the textarea. When you want to updated the textarea you just add it to the AjaxRequestTarget and the textarea knows if it should be enabled. This is a best practice and is not directly correlated to your question.

How to get currently entering text in JTable?

i am developing a project. On that i need to get currently typing characters in a particular column of JTable.
If i am using,
table.getValueAt(table.getSelectedRow(), 1)
it will return nothing till i select another column. How can i get currently entering text in JTable?
You can use jcombobox with autocomplete decorator in a JTable column,here is how Using a Combo Box as an Editor. and on key typed set the DefaultComboBoxModel
with the JList
You can get the editor being used by calling the method:
Component component = table.getEditorComponent();
Use this editor to get the text being edited, or attach a document listener to it, or anything you like, as follows:
JTextComponent editor = (JTextEditor)component;
String text = editor.getText();
editor.getDocument().addDocumentListener(new DocumentListener() {
void changedUpdate(DocumentEvent e) { ... }
void insertUpdate(DocumentEvent e) { ... }
void removeUpdate(DocumentEvent e) { ... }
});

Nebula gridTableViewer cell content should wrap

I am using nebula gridTableViewer for my application, in its cell some time content is so lengthy, so I want to show as WRAP (in multiline). I did changes for it but it is not reflecting:
I added SWT.WRAP but not works, I tried to wrap the text in LabelProvider too but it also not works so how could i do it?
Should i need to add listener for this.
Adding SWT.WRAP to the gridTableViewer would not cause the Text in the grid cells to wrap.
gridColumn.setWordWrap(true) causes the text entered in the cell to be wrapped after the entered value is applied to the editor(setvalue called). To wrap the text interactively, SWT.WRAP should be added as a style to the TextCellEditor or to Text widget placed in the cells.
gridViewerColumn.getColumn.setWordWrap(true);
gridTableViewer.setEditingSupport(new EditingSupport(gridTableViewer) {
....
#Override
protected CellEditor getCellEditor(Object element) {
TextCellEditor cellEditor = new TextCellEditor(gridTableViewer.getGrid(),
SWT.WRAP)
return cellEditor;
}
Or
....
final GridItem item = grid.getItem(grid.getTopIndex());
for (int i = 0; i < grid.getColumnCount(); i++) {
final Text text = new Text(grid, SWT.WRAP);
Listener textListener = new Listener() {
public void handleEvent(final Event e) {
switch (e.type) {
case SWT.FocusOut:
item.setText(column, text.getText());
....
}
}
}
}
I have used the SWT.WRAP in the TextCellEditor before, and it works.

Categories

Resources