I want to add some functionality to the right arrow button, the one that puts the user selection into the selected elements panel. Specifically, when the user selects an element from the avaliable choices, I don't want the element to be taken to the selected elements panel if there are elements at the right panel of another palette. So basically, what I need is to execute custom java code when the button is pressed, and alter the default behavior of the palette when a condition occurs.
I found the solution somewhere else. Just in case someone needs it, here is what you have to do.
myPalette = new Palette<MyClass>(...) {
#Override
protected Recorder newRecorderComponent() {
Recorder<MyClass> recorder = super.newRecorderComponent();
recorder.add(new AjaxFormComponentUpdatingBehavior("onchange") {
protected void onUpdate(AjaxRequestTarget target) {
// Custom code
...
if (target != null)
// Update another component
target.add(anotherComponent);
}
}
);
return recorder;
}
};
Related
I found an article online that said to setup the toolbar button to be a type that stays pressed you just set a style TBBS_CHECKBOX on the button but it doesn't work for me (it still acts like a normal button). I confirmed the style is set, just after created and the SetWindowText() MFC wizard setup of CMainFrame::OnCreate(). What am I doing wrong?
for (int i=0; ; i++) {
int id=m_wndToolBar.GetItemID(i);
if (id==0) {
break;
}
if (id == ID_THE_ID) {
m_wndToolBar.SetButtonStyle(i, TBBS_CHECKBOX);
}
}
Using Command Handlers is the recommended implementation here. A command ID may be used in multiple UI items, eg a menu item and a toolbar button. A handler affects all items with the same ID, so you don't need a separate one for each item. The CCmdUI Class provides methods that can cause UI items like menus or toolbar buttons to behave as push-buttons, check-boxes or radio-buttons, in addition to enabling/disabling.
In your example, suppose that the option whether to filter is instantiated on a per document basis, ie all views of the document would be filtered or non-filtered, all at the same time. You should define a boolean variable in your document class:
BOOL m_bFilterData = FALSE;
Then the ON_COMMAND and ON_UPDATE_COMMAND_UI handlers for the toolbar button with the Filter pic (and possibly a menu item as well):
BEGIN_MESSAGE_MAP(CMyDoc, CDocument)
.
.
ON_COMMAND(ID_VIEW_FILTERDATA, OnViewFilterData)
ON_UPDATE_COMMAND_UI(ID_VIEW_FILTERDATA, OnUpdateViewFilterData)
.
.
END_MESSAGE_MAP()
void CMyDoc::OnViewFilterData()
{
// Toggle filtered state
m_bFilterData = !m_bFilterData;
// Tell all views to refresh - You can limit this using the lHint/pHint params
UpdateAllViews(NULL, 0L, NULL);
}
void CMyDoc::OnUpdateViewFilterData(CCmdUI* pCmdUI)
{
// Enable/Disable as needed
pCmdUI->Enable(m_nTotalItems>0);
// Show pressed/checked if data filtered
pCmdUI->SetCheck(m_bFilterData);
}
Now, if the filter option is instantiated per view, ie each view can indpendently be filtered or non-filtered, the above must go to your view class(-es):
void CMyView::OnViewFilterData()
{
// Toggle filtered state
m_bFilterData = !m_bFilterData;
// Refresh this view only
.
.
}
void CMyView::OnUpdateViewFilterData(CCmdUI* pCmdUI)
{
// Enable/Disable as needed
pCmdUI->Enable(GetDocument()->m_nTotalItems > 0);
// Show pressed/checked if data filtered
pCmdUI->SetCheck(m_bFilterData);
}
I would like to use the SlidingListTile, but I am having some issues.
I think that when we use the horizontal sliding the vertical scroll should be locked, because is getting hard to complete de slide on the phone.
Did someone get a situation like that?
Thanks in advance,
Here is part of my code:
slidingTile.swipedLeftProperty().addListener((obs, ov, nv) -> {
if (nv && edit != null) {
edit.accept(currentItem);
}
slidingTile.resetTilePosition();
});
slidingTile.swipedRightProperty().addListener((obs, ov, nv) -> {
if (nv && edit != null) {
edit.accept(currentItem);
}
slidingTile.resetTilePosition();
});
Indeed, there is an error in the Comments 2.0 sample.
The CommentsPresenter defines a custom ListCell for the ListView, and creates a binding from a single BooleanProperty to each of the cells in the list view:
commentsList.setCellFactory(cell -> {
final CommentListCell commentListCell = new CommentListCell(
service,...);
// notify view that cell is sliding
sliding.bind(commentListCell.slidingProperty());
return commentListCell;
});
Obviously, the sliding property of each cell may vary in time, but only the last one set will prevail, so it won't reflect the change of this property for any of the rest of the cells.
The fix is easy: don't use bindings, but a listener for each cell that will set the value when that cell is sliding:
commentsList.setCellFactory(cell -> {
final CommentListCell commentListCell = new CommentListCell(
service,...);
// notify view that cell is sliding
commentListCell.slidingProperty().addListener((obs, ov, nv) ->
sliding.set(nv));
return commentListCell;
});
I've filed an issue.
I have a TableView in JavaFX 8, which is editable. One of the fields is a CheckBoxTableCell.
I have noticed that the TAB key lands on the first CheckBoxTableCell in the grid and gets stuck there. I don't want this behavior. I like to navigate to the cell with the keyboard and activate with the SPACE. However I need tab to ignore this field - since it gets stuck.
I tried the following:
booleanColumn.setCellFactory (to -> {
CheckBoxTableCell<DTO, Boolean> cell = CheckBoxTableCell<>();
cell.setFocusTraversable(false);
return cell;
}
This however has no affect on the focus of the field, since it's editable, it lands on that control and gets stuck.
If I change to:
cell.setDisable(true);
Then TAB will skip the field, but I can land on the column with the arrow keys. However I can't select the checkbox with the mouse.
I am at a loss as what to do.
Thanks.
The workaround to get the TAB key working first implies consuming the event so the default TableView traversal engine doesn't process it, and selecting the next or previous cell instead.
This will move the selection from cell to cell:
table.getSelectionModel().setCellSelectionEnabled(true);
table.setOnKeyPressed(keyEvent -> {
switch (keyEvent.getCode()){
case TAB: {
keyEvent.consume();
if (keyEvent.isShiftDown()) {
personTable.getSelectionModel().selectPrevious();
} else {
personTable.getSelectionModel().selectNext();
}
break;
}
}
});
But it won't be enough to get the CheckBox focused, and the space key can't be used to select it. So a second step is required to move the focus from the selected cell to the inner checkbox.
When the cell gets the focus, its node will request it.
booleanColumn.setCellFactory (param -> {
CheckBoxTableCell<DTO, Boolean> cell = new CheckBoxTableCell<>();
cell.focusedProperty().addListener((obs, ov, nv) -> {
if (nv && cell.getGraphic() != null) {
cell.getGraphic().requestFocus();
}
});
return cell;
});
Notice you can't have both the cell and it's checkbox focused at the same time, so the cell will appear grey (selected but not focused), unless you modify its css.
I want to get the selected row in a GWT CellTable when the user pressed down the keys up or down. In my example I have a table with three columns (ID, name, date) and I have implemented the code to handle the click event. When clicking a row I get the selected object. Now I want to do the same when moving through the rows of the table using the arrows keys up and down.
This is my code:
// Create id column.
TextColumn<MyObject> idColumn = new TextColumn<MyObject>()
{
#Override
public String getValue(MyObject obj)
{
return String.valueOf(obj.getId());
}
};
// Create name column.
TextColumn<MyObject> nameColumn = new TextColumn<MyObject>()
{
#Override
public String getValue(MyObject obj)
{
return obj.getName();
}
};
// Create date column.
TextColumn<MyObject> dateColumn = new TextColumn<MyObject>()
{
#Override
public String getValue(MyObject obj)
{
return String.valueOf(obj.getDate());
}
};
// Create the CellTable element and add columns
CellTable<MyObject> table = new CellTable<MyObject>();
table.addColumn(idColumn, "ID");
table.addColumn(nameColumn, "Name");
table.addColumn(dateColumn, "Date");
// Create the selectioModel and the SelectionChangeEvent Handler
NoSelectionModel<MyObject> selectionModelMyObj = new NoSelectionModel<MyObject>();
Handler tableHandler = new SelectionChangeEvent.Handler()
{
#Override
public void onSelectionChange(SelectionChangeEvent event)
{
MyObject clickedObj = selectionModelMyObj.getLastSelectedObject();
Window.alert("Object selected: " + clickedObj);
}
};
// Add the handler to the selection model
selectionModelMyObj.addSelectionChangeHandler( tableHandler );
// Add the selection model to the table
table.setSelectionModel(selectionModelMyObj);
Thanks for all.
By default, keyboard navigation within a CellTable only updates the keyboard selected row. Only by hitting the enter key the row will become selected.
If you want the selection to follow the keyboard selection, the you can set the keyboard selection policy to be bound to selection. I'm not sure how it'll work with a NoSelectionModel though, would probably work better with a SingleSelectionModel.
You need to understand the Keyboard Selection policy w.r.t to GWT widgets and celltable.
The right way is to allow only row navigation with Keys "UP" and "Down" and cell navigation with Keys "Left" and "Right" . The selection of rows should be only on click of "Space" or "Enter" key.
All of this is already provided with GWT cell table. You can check the source code and demo http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwCellTable
You can get the row of a CellTable with the getKeyboardSelectedRow() method. This will return the int index of the row that is selected via either the keyboard or mouse.
GWT Javadoc for CellTable:
http://www.gwtproject.org/javadoc/latest/
public int getKeyboardSelectedRow()
Get the index of the row that is currently selected via the keyboard, relative to the page start index.
This is not same as the selected row in the SelectionModel. The keyboard selected row refers to the row that the user navigated to via the keyboard or mouse.
Returns: the currently selected row, or -1 if none selected
The title is pretty self-explanatory, i'm currently adding PaintListeners to all the children, grand-children and so on, of the control i'd like to paint on. I have graphical errors with Tables and Combos at the moment, the PaintListener apparently doesn't apply to the header or the button in the combo.
How can i do this?
This is the code i use to add the listeners:
List<Control> controls = Lists.newArrayList();
controls.add(composite);
while (! controls.isEmpty()) {
Control c = controls.remove(0);
if (c instanceof Composite) {
controls.addAll(Arrays.asList(((Composite) c).getChildren()));
}
c.addPaintListener(new ControlPaintListener());
}