Apache Wicket - Implementing AbstractToolbar with DefaultDataTable - apache

I am trying to add an AbstractToolBar to a DefaultDataTable.
The toolbar has a button on click of which the selected rows should get deleted.
My table has a checkbox column, to select the rows.
AbstractToolBar implementation looks like this -
public class GridToolBar extends AbstractToolbar {
/**
*
*/
private static final long serialVersionUID = -2126515338632353253L;
Button btnDelete;
List<Contact> selected;
public GridToolBar(final DataTable<?> table) {
super(table);
// TODO Auto-generated constructor stub
btnDelete = new Button("delete",new Model("Delete"));
btnDelete.setOutputMarkupId(true);
btnDelete.add(new AjaxEventBehavior("onclick") {
private static final long serialVersionUID = 6720512493017210281L;
#Override
protected void onEvent(AjaxRequestTarget target) {
System.out.println(selected);
((UserProvider)table.getDataProvider()).remove(selected);
target.add(table);
}
});
add(btnDelete);
}
public void setSelected(List inList){
selected = inList;
}
}
The toolbar has been added to table as follows -
GridToolBar tb = new GridToolBar(table);
tb.setOutputMarkupId(true);
table.addTopToolbar(tb);
The code works fine, except on click of delete button it adds an additional delete button below the table. On inspecting it with firebug, the ids of both the buttons match exactly. On sorting the table though, the extra button is removed from the view.
Could someone help me how can I avoid creation of extra button on every click?
Why is it being created in the first place?
Any help is appreciated.
Thanks,
Sonam

You add the button directly to the table. This is incorrect, as you cannot have a button in a table. You need a <td> element. You can create one using a WebMarkupContainer. See also the source of for example NoRecordsToolbar

Related

Best way to intercept click event on table item

I'm using two tables, the first one contains "Teams", the second one "Team members" and is populating based on the first table selection. I'm also showing various stats depending on the selection, be it a team or a specific member. If no member is selected, team stats are showed, otherwise member stats are showed.
I'm using ItemChangeListeners on the tables to redraw the stats, but this prevents me to click on an already selected team to "deselect" a selected member from that team, since no event is triggered in that circumstance. As a solution I'm also using a ClickListener on the Team table, but it seems to work only if I click on the word (instead of working on the whole cell).
teamsTable.setClickListener("name", new Table.CellClickListener() {
#Override
public void onClick(Entity item, String columnId) {
if (teamsDs.getItem() == item) {
teamsDs.setItem(null);
teamsDs.setItem((Team) item);
} else {
teamsDs.setItem((Team) item);
teamsTable.setSelected((Team) item);
}
}
});
Is there a better way to catch a click on a table cell? Or is there a better way to approach the problem altogether?
Since CUBA Table is a wrapper of Vaadin table you can use ItemClickListener from Vaadin with CUBA table:
public class DemoScreen extends AbstractWindow {
#Inject
private Table<User> usersTable;
#Override
public void init(Map<String, Object> params) {
super.init(params);
com.vaadin.ui.Table vTable = usersTable.unwrap(com.vaadin.ui.Table.class);
vTable.addItemClickListener((ItemClickEvent.ItemClickListener) event ->
showNotification("Item " + event.getItemId())
);
}
}
It will be fired each time you click on a table cell.

Javafx: updating cell using choicebox in the GUI doesn't work

I have a problem in a Tableview created using javafx. I have set the edititable="true" on the fxml file of the tabel, then in the controller I execute
#FXML
private TableColumn<ARule,Object> rankCol;
rankCol.setCellValueFactory(new PropertyValueFactory<ARule, Object>("label")); rankCol.setCellFactory(ChoiceBoxTableCell.forTableColumn(Main.getlabelSample()));
rankCol.setOnEditCommit(e -> {System.out.println("something happens!");});
To create in the column rank, a choicebox to change te value of the property.
The ARule has a property field and the getter and setters:
private SimpleObjectProperty label;
public SimpleObjectProperty labelProperty() {
return label;
}
public void setLabel(Object label) {
this.label.set(label);
}
public Object getLabel(){
return this.label.getValue();
}
The function Main.getlabelSample() retrun this object filled with Strings or Integer
private static final ObservableList<Object> labelSample = FXCollections.observableArrayList();
The problem is that in the interface I can edit the column and it displays the correct value in the labelSample list, the problem is that it doesn't change the value of the ARule object, this is highlighted by the missing call of the setOnEditCommit handler. The value on the GUI is the new one selected but the value saved on the items in the table is the old one.
I have also a separated button to change the value of that column on the selected row and if I trigger that, the values changes for "real" (both on the GUI and on the model).
What could be the error in the code?
The default edit commit behavior of the column is set as the onEditCommit property. If you call
rankCol.setOnEditCommit(...);
then you set this property to something else, i.e. you remove the default behavior.
If you want to add additional behavior to the default, use addEventHandler(...) instead of setOnEditCommit(...):
rankCol.addEventHandler(TableColumn.editCommitEvent(), e -> {
System.out.println("Something happens");
});
Find the answer the line of code:
rankCol.setOnEditCommit(e -> {System.out.println("something happens!");});
for some reason overwrite the default behaviour of updating the cell changing the code into
rankCol.setOnEditCommit(e -> {
e.getTableView().getItems().get(e.getTablePosition().getRow()).setLabel(e.getNewValue());
System.out.println("Something happens!");});
Resolved the problem. At the moment I don't know why this is happening.

JavaFX Check Cell background of specific Cell (random access)

I just started to develop a JavaFX application. Maybe I didn't get how JavaFX uses the TableView and I should use something different instead.
Currently my TableView displays data in multiple columns an when I double-click a cell the background color changes (by setCellFactory(customFactory)).
Now I want to access different cells of the table by using indices (column,row) and checking the background color.
The cells with a changed background color should be stored after a certain button was clicked.
I would like to get every cell with changed background(get celltext) for each row and store this for later use in a data structure like a Map>.
Would be really nice if somebody can give me a hint. Thank for your Help.
I suppose, you are adding an EventHandler to the TableCell, which is returned by your customFactory. This EventHandler is handling the doubleclick-event and sets the background color, right?
This handler has access to the parameter which is passed to the Callbacks/CustomFactories call-method, which contains the model-bean of the current row. You could set a flag or the columns name in that model-bean when a doubleClickEvent occurs.
Then
after a certain button was clicked
you can get your info, by checking the tables items. The row-index of each item is equivalent to the index of this item in the List of TableView#getItems
Also have a look at http://controlsfx.bitbucket.org/org/controlsfx/control/spreadsheet/SpreadsheetView.html if you need more TableFunctions.
EDITED
This is a code-example:
The Model-Bean used in TableView:
class Model {
private String propertyA;
private String propertyB;
#lombok.Getter
private Set<String> propertiesClicked = new HashSet<>();
The javafx-controls, annotate them with #FXML if you use FXMLs:
private TableView<Model> tableView;
private TableColumn<Model, String> propertyAColumn;
private TableColumn<Model, String> propertyBColumn;
and the the CellFactory. Create a more generic CellFactory if you need it for multiple columns:
propertyAColumn.setCellFactory((value) -> {
TableCell<Model, String> tableCell = new TableCell<Model, String>() {
//Override the Methods which you need
};
tableCell.setOnMouseClicked((mouseEvent) -> {
if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
if (mouseEvent.getClickCount() == 2 && !tableCell.getStyleClass().contains("buttonClicked")) {
tableCell.getStyleClass().add("buttonClicked");
tableView.getSelectionModel().getSelectedItem().getPropertiesClicked().add("propertyA");
}
}
});
return tableCell;
});

How to click back button programatically in IWizardPage in Eclipse

I'm writing an Eclipse plugin, I want to create a wizard for my new project type. I created pages by classes extends org.eclipse.jface.wizard.WizardPage. My requirement is, based on some condition in one page, I need to go back to previous page without pressing back button on page(programmatically).
Is it possible?
Thanks a million in advance!
I don't think this is a good idea. The user will be confused by doing this. I would disable the finish and the next button and give an error, telling the user that he has to go back to the first page.
If you want to reuse some UI from the first page, define the UI as a new class and reuse it.
I implemented something similar using the WizardDialog:showPage() method:
MyWizard.java
public void createPageControls(Composite pageContainer) {
// TODO Auto-generated method stub
super.createPageControls(pageContainer);
wizardDialog = (WizardDialog) getContainer();
}
public void skipProcessPage() {
wizardDialog.showPage(workPage == arisDbPage ? focusPage : arisDbPage);
}
public void setWorkPage(IWizardPage workPage) {
this.workPage = workPage;
}
here the processPage does the lengthy db lookup!
HTH thomas

Inserting an Action button from an AbstractPropertySection

I have a tabbed propertiesContributor (and a few propertySections to go with it) using the org.eclipse.ui.views.properties.tabbed.propertySections extension point
I should like to place a tab-specific 'refresh' action-button into the action-bar, and cannot see how it should be done. There is a very tantalising method ..
TabbedPropertySheetPage.setActionBars( ... )
... available in 'createControls()' but I cannot see how I make use of that.
Can anyone point me at some working example code on how to achieve this?
Your clues & boos are most welcome.
M.
The solution was to use an instance of org.eclipse.ui.SubActionBars and add the tab-specific Actions to it, like this ...
#Override
public void createControls(Composite parent, final TabbedPropertySheetPage aTabbedPropertySheetPage)
{
...
makeActions();
subActionBars = new SubActionBars( tabbedPropertySheetPage.getSite().getActionBars() );
subActionBars.getToolBarManager().add( refreshAction );
subActionBars.getMenuManager().add( refreshAction );
}
.. then override aboutToBeShown() and aboutToBeHidden() like this ...
#Override
public void aboutToBeShown()
{
super.aboutToBeShown();
subActionBars.activate();
subActionBars.updateActionBars();
}
#Override
public void aboutToBeHidden()
{
super.aboutToBeHidden();
subActionBars.deactivate();
subActionBars.updateActionBars();
}
I don't think there is a way to add a Tab specific action to the view's action bar. You may have to add the action in a section of that tab only.