I'm workin on a web app using gwt, I have a celltable with textcolumns
I want to add a column that will contain links, once the user clicks on a cell of this column he is forwaded to the link.
How can I do such a thing in gwt?
You would have to use a cell of appropriate type such as ClickableTextCell or ButtonCell as well as a FieldUpdater.
Basically you can add a FieldUpdater to your column as such:
column.setFieldUpdater(new FieldUpdater<YourObject, String>() {
#Override
public void update(int index, YourObject object, String value) {
Window.open(value, "_blank", ""); //This will open link in a new tab or window
}
});
Where value in this case is the url. update() will be called when the column is clicked.
Related
I'm noob in javafx and scene builder. I want to populate tableview by selecting one item from combobox. It is possible?
i try with String val = combobox.getValue() and i put the string in SQL query in preparedStatement for directly sort but app stops at the null string value and tableview is not updated.
Thank you guys!
It is possible that the String is being initialized with the ComboBox value even before the ComboBox gets an input. In that case, the ComboBox will return a null value.
You should add an onAction event for the ComboBox which will update the string.
You can use the following code segment to do that
comboBox.setOnAction((event) -> {
val = comboBox.getValue();
//Any other action you want to carry out when an item of the combo box is selected
});
Or if you are using an FXML file and want to add the onAction event in the controller, you can use this.
public void comboBoxEvent(ActionEvent event){
val = comboBox.getValue();
} // Use this code when working with FXML files
Both these examples assume that the String var was defined globally. Just to be on the safer side, when you are comparing var to another value or storing it somewhere else, you should put it under an if condition
if(var != null)
//Code segment here
I am using this link for creating a ContextMenu for each table row. Right now I'm running into problems because I'm not sure how to attach a ContextMenu after the 'type' has been inserted into a row.
Lets say I'm using a .zip editor program, and it lists the contents. I have an Image, and a text file, and some other stuff, all of them are under a class called Entry. My table's generic type is 'Entry', and I'd like to be able to create a context menu for each entry based on it's underlying subclass type (like an ImageEntry might return a menu item to open it up in an image editor...etc).
Right now I have a generic context menu for everything, but it's not great displaying a menu item about opening a text file with an image editor...
Is this possible to do? If so, what is the proper way to go about doing it?
Add a listener to the row's itemProperty (which represents the item displayed in the row) and update the context menu when it changes:
table.setRowFactory(new Callback<TableView<Person>, TableRow<Person>>() {
#Override
public TableRow<Person> call(TableView<Person> tableView) {
final TableRow<Person> row = new TableRow<>();
final ContextMenu contextMenu = new ContextMenu();
row.itemProperty().addListener((obs, oldPerson, newPerson) -> {
contextMenu.getItems().clear();
// add items to context menu depending on value of newPerson
// ...
});
// Set context menu on row, but use a binding to make it only show for non-empty rows:
row.contextMenuProperty().bind(
Bindings.when(row.emptyProperty())
.then((ContextMenu)null)
.otherwise(contextMenu)
);
return row ;
}
});
I want to completely view updates when a row is selected in a CellTable. How can this be done? In the following test case, using NoSelectionModel, the view is still updated: clicking on a row changes the background and border colors of the row until another row is clicked.
CellTable<String> table = new CellTable<String>();
TextColumn<String> column = new TextColumn<String>()
{
#Override
public String getValue(String string)
{
return string;
}
};
table.addColumn(column);
List<String> sampleData = Arrays.asList("foo", "bar", "baz");
table.setRowData(sampleData);
final NoSelectionModel<String> selectionModel = new NoSelectionModel<String>();
table.setSelectionModel(selectionModel);
RootPanel.get().add(table);
I've also attempted to subclass SingleSelectionModel with empty override methods, without success.
I can fake the behavior I want by providing empty CSS stylings for selected rows, but that method seems hack-ish.
What you're seeing is the keyboard-selection highlighting (really useful when you're not using the mouse to interact with the table).
You can disable it using setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED)
I want to used editableNumbercell like intger,decimal etc..
But there is no such gwt widget present so I am using editable text cell and using validation for numbers when user update value in cell.
How to avoid cell editing when validation fails.
if validation fail then editabletext cell value restored to old value.How to do that?
intgerColumn.setFieldUpdater(new FieldUpdater<RecordInfo, String>() {
public void update(int index, RecordInfo object, String value) {
// Called when the user changes the value.
if(value.matches("(-)?(\\d){1,8}")){
object.setColumnInRecordEdited(true);
object.setValue(value);
RecordData.get().refreshDisplays();
}else{
Window.alert("Specify valid integer value for parameter");
// How to rest old value here? currently update value set to cell
}
}
});
Any help or guidance in this matter would be appreciated.
You can do it like this:
// clear incorrect data
cell.clearViewData(KEY_PROVIDER.getKey(object));
cellTable.redraw();
Where cell is the TextEditCell that you're using for that column.
It´s usefull for me.
Requirement:
I have a list of strings displayed in the ComboBox. Each of these Strings can have some properties. These properties are displayed in PropertyTable. ComboBox's selected Item's properties are displayed in the table. In addition, we use PropertyTable for editing or setting property values to the selected item in the comboBox.
Problem:
The moment I de-select the comboBox Item,say item1, all the existing property values in the PropertyTable are set as new property values to item1. Again, when I select this item1 back, I should get above property values(i.e values before item1 is Deselected) back in to the PropertyTable?
Current Implementation Logic:
I am having TableCellListner for each PropertyTableCell, whenever cell content is changed, it takes the cell's new value and assigns this as new property value to the combo box's selected item. whenever new item is selected, table is refreshed with the selected Item's property values.
//before is Table initialization code
Action action = new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
TableCellListener table = (TableCellListener)e.getSource();
String selectedItem=(String)ComponentPropComboBox.getSelectedItem();
if(table.getColumn()==1 && selectedItem!=null)
{
Property property=propertyMap.get(selectedItem);
else if(table.getRow()==0)
{
property.setProperty("MIN_LENGTH", (String)table.getNewValue());
propertyMap.put(selectedItem, property);
}
else if(table.getRow()==1)
{
property.setProperty("STARTS_WITH_STRING", (String)table.getNewValue());
propertyMap.put(selectedItem, property);
}
}
}
};
TableCellListener tcl = new TableCellListener(PropertiesTable, action);
How do i implement this requirement by overcoming the above challenge?
PS:
TableCellListner is a Not a java generic library. You can view code and its explanation at the following links:
http://www.camick.com/java/source/TableCellListener.java
http://tips4java.wordpress.com/2009/06/07/table-cell-listener/
I believe the question is obvious! Pls do let me know if question is not clear.Thanks in advance for your help & donating the knowledge!
In the code that listens for JComboBox selections. At its start have it set a boolean that the item is being changed. Then have your table refresh code ignore events that come while the boolean is set. After you are finished refreshing then set the boolean back.