How to check and uncheck all items when checking or unckeck some of the items - javafx-2

JavaFX CheckComboBox
How to check and uncheck all items when checking or unckeck some of the items.
Check all when ckeck item All
Uncheck all when unckeck item All
ObservableList<String> list = FXCollections.observableArrayList("All","Item 1", "Item 2", "Item 3", "Item 4");
checkBoxCombo.getItems().addAll(list);
checkBoxCombo.getCheckModel().getCheckedItems().addListener(new ListChangeListener<String>() {
public void onChanged(ListChangeListener.Change<? extends String> c) {
if(checkBoxCombo.getCheckModel().isChecked(0))
checkBoxCombo.getCheckModel().checkAll();
}
});

Add a boolean field to the listener to prevent recursion:
checkBoxCombo.getCheckModel().getCheckedItems().addListener(new ListChangeListener<String>() {
private boolean changing = false;
#Override
public void onChanged(ListChangeListener.Change<? extends String> c) {
if (!changing && checkBoxCombo.getCheckModel().isChecked(0)) {
// trigger no more calls to checkAll when the selected items are modified by checkAll
changing = true;
checkBoxCombo.getCheckModel().checkAll();
changing = false;
}
}
});

Related

Reordering header buttons

I have added a custom save button in Sales Order screen in place of my current one. How do I reorder the main toolbar so that new save button is in place of the old one? You can do this easily for grid buttons, but for header ones it is not so obvious.
The order of the buttons is based on the order of the PXActions in the graph.
(1) In this example my save button is first, then cancel button second.
public class MyGraph : PXGraph<MyGraph>
{
public PXSave<MyPrimaryDac> Save;
public PXCancel<MyPrimaryDac> Cancel;
}
(2) In this example my cancel button is first, then save button second.
public class MyGraph : PXGraph<MyGraph>
{
public PXCancel<MyPrimaryDac> Cancel;
public PXSave<MyPrimaryDac> Save;
}
Note that PXSave and PXCancel are PXActions.
Edit: from comments and question edits if you are extending another graph you should be able to use a new class inherited from PXSave and set the property name the same ("Save" in the example of sales order). Here is something that should work for an override to the save button and asking the user a question and keeps the save button in the same button location...
public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
public SalesPXSave<SOOrder> Save;
public class SalesPXSave<TNode> : PXSave<TNode> where TNode : class, IBqlTable, new()
{
public SalesPXSave(PXGraph graph, string name) : base(graph, name)
{
}
public SalesPXSave(PXGraph graph, Delegate handler) : base(graph, handler)
{
}
[PXSaveButton]
[PXUIField(DisplayName = "Save", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
protected override IEnumerable Handler(PXAdapter adapter)
{
bool someCondition = true;
if (someCondition)
{
if (adapter.View.Ask(adapter.View.Graph.Caches[typeof(TNode)].Current, "Hi User",
MessageButtons.YesNo) != WebDialogResult.Yes)
{
return adapter.Get();
}
}
return base.Handler(adapter);
}
}
}
Edit: For reference here are some quick untested examples of extending RowPersisting or the Persist in an extension if this is preferred vs extending the buttons...
[PXOverride]
public virtual void Persist(Action del)
{
if (Base.Document.Ask(Base.Document.Current, "Question", "Continue?",
MessageButtons.YesNo) != WebDialogResult.Yes)
{
return;
}
del?.Invoke();
}
protected virtual void SOOrder_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting del)
{
var row = (SOOrder)e.Row;
if (row == null)
{
return;
}
if ((e.Operation == PXDBOperation.Insert || e.Operation == PXDBOperation.Update || e.Operation == PXDBOperation.Delete) &&
Base.Document.Ask(row, "Question", "Continue ?", MessageButtons.YesNo, true) != WebDialogResult.Yes)
{
e.Cancel = true;
return;
}
del?.Invoke(cache, e);
}

In JavaFX, binding comboBox items and table Column sort

I have a combo Box and a table-view. ComboBox items are filled with tables column-names. I want to bind comboBox item selection and the table column sort.
Example: If I select item say "Name" from comboBox which is at index 0 of comboBox, the 0th column of table is sorted.
Again if I sort a column in the table, comboBox selected item should update with the corresponding column name.
Right now i am achieving the table column sort based on comboBox item slection with below code.
private void bindComboBoxAndTableColumnSort() {
ComboBox combo = topComboBarController.getSortCombo();
combo.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
#Override
public void changed(ObservableValue<? extends Number> arg0,
Number oldVal, Number newVal) {
System.out.println("oldVal = "+ oldVal + " and newVal = "+ newVal);
TableColumn sortColumn = null;
SortType st = null ;
sortColumn = table.getColumns().get( newVal.intValue() ) ;
st = table.getColumns().get( newVal.intValue() ).getSortType() ;
table.getSortOrder().clear();
if(sortColumn != null){
table.getSortOrder().add(sortColumn);
sortColumn.setSortType(SortType.ASCENDING);
}
}
});
}
If someone can share some demo code, it will be helpful.
You need a second Listener which listens to the change to the changeorder of your TableView. Notice the need of the while loop to listen to the paramChange. Replace the ... with your binding to your ComboBox
tableView.getSortOrder().addListener(new ListChangeListener<TableColumn<ColumnClass, ?>>() {
#Override public void onChanged(Change<? extends TableColumn<ColumnClass, ?>> paramChange) {
while(paramChange.next()) {
if (paramChange.wasPermutated()) {
final TableColumn<ColumnClass, ?> first = paramChange.getList().get(0);
final String tableColumnName = first.getText();
...
}
}
}
});
Edit
According to the request some other approach
final ComboBox<String> box = new ComboBox<>();
table.getSortOrder().get(0).textProperty().bindBidirectional(box.valueProperty());
With below code, i am able to achieve what #thatslch suggested.
table.getSortOrder().addListener(new ListChangeListener<TableColumn<Person, ?>>(){
#Override
//public void onChanged( javafx.collections.ListChangeListener.Change<? extends TableColumn<Person, ?>> paramChange) {
public void onChanged( Change<? extends TableColumn<Person, ?>> paramChange) {
// TODO Auto-generated method stub
while(paramChange.next()) {
if (paramChange.wasAdded()) {
System.out.println("paramChanged.wasAdded() ");
ComboBox combo = topComboBarController.getSortCombo();
combo.valueProperty().bind( paramChange.getList().get(0).textProperty() );
}
}
}

How to get Menu object with ActionBarCompat (showing progress bar in ActionBar)

I am switching from Sherlock to AppCompat, and I am used to do this thing where I replace refresh action item with a progress bar while something is loading like this
public void setRefreshButtonState(boolean refreshing) {
if (mOptionsMenu == null) {
return;
}
final MenuItem refreshItem = mOptionsMenu.findItem(R.id.action_refresh);
if (refreshItem != null) {
if (refreshing) {
refreshItem.setActionView(R.layout.actionbar_indeterminate_progress);
} else {
refreshItem.setActionView(null);
}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
mOptionsMenu = menu;
return super.onCreateOptionsMenu(menu);
}
But since Menu is the regular menu in AppCompat (unlike Sherlock), it obviously throws
Call requires API level 11 (current min is 9): android.view.MenuItem#setActionView
I tried all the MenuItemCompat static methods, but no luck
Thanks!
I was searching for the wrong thing. You dont want to comapt menu object but the menu item, like this
MenuItemCompat.setActionView(refreshItem, R.layout.actionbar_indeterminate_progress);
public void setActionItemInProgress(MenuItem menuItem, boolean refreshing) {
if (refreshing) {
MenuItemCompat.setActionView(menuItem, R.layout.actionbar_indeterminate_progress);
} else {
MenuItemCompat.setActionView(menuItem, null);
}
}

Java FX: how to update ComboTableCell on change of another

im stuck into some problem, need guidance !
i have a TableView that has 2 ComboBoxTableCells, my requirement is to update the list in combobox of 2nd cell on change of the first.
i have tried it the following way,no luck so far.
public class Test{
private StringProperty name;
private StringProperty city;
public Test(String name, String city){
this.name = new SimpleStringProperty(name);
this.city = new SimpleStringProperty(city);
}
public String getName() {
return name.get();
}
public void setName(String name) {
this.name.setValue(name);
}
public String getCity() {
return city.get();
}
public void setCity(String city) {
this.city.setValue(city);
}
public StringProperty nameProperty() {return name;}
public StringProperty cityProperty() {return city;}
}
TableView _table= new TableView();
final ObservableList list = FXCollections.observableArrayList();
list.add("name 1");
list.add("name 2");
list.add("name 3");
list.add("name 4");
final ObservableList list2 = FXCollections.observableArrayList();
list2.add("city 1");
list2.add("city 2");
list2.add("city 3");
list2.add("city 4");
TableColumn firstNameCol = new TableColumn("First Name");
firstNameCol.setMinWidth(100);
firstNameCol.setCellValueFactory(new PropertyValueFactory<Test, String>("name"));
firstNameCol.setCellFactory(ComboBoxTableCell.forTableColumn(list));
firstNameCol.setOnEditCommit(
new EventHandler<CellEditEvent<Test, String>>() {
#Override
public void handle(CellEditEvent<Test, String> t) {
((Test) t.getTableView().getItems().get(t.getTablePosition().getRow())).setName(t.getNewValue());
System.out.println(t.getTableColumn().getCellData(t.getTablePosition().getRow()));
i guess have to do something here, tried the following line to see the impact on the respective cell
list2.clear();
it updated data for the whole column i just want it to be updated for the respective cell only.
}
}
);
TableColumn lastNameCol = new TableColumn("City");
lastNameCol.setMinWidth(100);
lastNameCol.setCellValueFactory(
new PropertyValueFactory<Test, String>("city"));
lastNameCol.setCellFactory(ComboBoxTableCell.forTableColumn(list2));
lastNameCol.setOnEditCommit(
new EventHandler<CellEditEvent<Test, String>>() {
#Override
public void handle(CellEditEvent<Test, String> t) {
((Test) t.getTableView().getItems().get(
t.getTablePosition().getRow())
).setName(t.getNewValue());
}
}
);
_table.setEditable(true);
_table.getColumns().addAll(firstNameCol,lastNameCol);
ObservableList listItems = FXCollections.observableArrayList();
listItems.add(new Test("name 4", "city 2"));
listItems.add(new Test("name 2", "city 3"));
table.getTableView().setItems(listItems);
_table.setItems(listItems);
any help will be highly appreciated. thanks
Here's a hacky approach that I haven't tested:
Add a dummy (boolean?) property on the data items that you will use to communicate between firstNameCol and lastNameCol
In the onEditCommit handler for firstNameCol, change the value of the dummy property. Be sure it changes.
Have lastNameCol be a column for the dummy property. Register a cell factory for lastNameCol that returns a TableCell with an overriden updateItem() method (pseudo-code below)
lastNameCol.setCellFactory(new Callback() {
#Override
public TableCell call(TableColumn col) {
return new TableCell() {
#Override
public void updateItem(Boolean item, boolean empty) {
if (!empty) {
// Don't care about the value of item
// Just look up the value of firstNameCol using
// getTablePosition(), then create and populate
// a ComboBox with the appropriate items and set
// it as the graphic for this cell via this.setGraphic()
// Add handler to ComboBox control to update data item when
// selection changes
}
}
};
}
});

Can we Create alert Dialog With Radiobuttons and Checkboxes in Blackberry

i want to create a alert dialog with radiobuttons for single selection or alert dialog with Checkboxes for Multiselection in blackberry.it is possible in android.but i want in blackberry.i searched in google.but i didn't got any solution.please give any suggestions r usefull links for this problem.
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.component.CheckboxField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.DialogFieldManager;
public class CheckboxInputDialog extends Dialog{
private CheckboxField checkboxEditField;
public CheckboxInputDialog(String choices[],int values[], String label){
super(label, choices,values,Dialog.OK, Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), Dialog.GLOBAL_STATUS);
checkboxEditField = new CheckboxField("Lablel",false);
net.rim.device.api.ui.Manager delegate = getDelegate();
if( delegate instanceof DialogFieldManager){
DialogFieldManager dfm = (DialogFieldManager)delegate;
net.rim.device.api.ui.Manager manager =dfm.getCustomManager();
if( manager != null ){
manager.insert(checkboxEditField, 0);
}
}
}
}
Now Call this dialog at following way...
String choices[] = { "OK", "CANCEL" };
int values[] = { Dialog.OK, Dialog.CANCEL };
CheckboxInputDialog d = new CheckboxInputDialog(choices,values,"Dialog Label");
d.show();
Output will Be:
Get Event of OK and Cancel Button.
String choices[] = { "OK", "CANCEL" };
int values[] = { Dialog.OK, Dialog.CANCEL };
final CheckboxInputDialog d = new CheckboxInputDialog(choices, values,"Dialog Label");
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
int iResponse = d.doModal();
if (iResponse == 0) {
System.out.println("Press Ok");
}else{
System.out.println("Press Cancel");
}
}
});
Hope Help full..
Create popupScreen and in this screen you can add radiobuttons and Checkboxes.
public class Custom_Popup extends PopupScreen {
public Custom_Popup() {
// TODO Auto-generated constructor stub
super( new VerticalFieldManager(Manager.VERTICAL_SCROLL),
Field.NON_FOCUSABLE | Field.USE_ALL_WIDTH );
}
}
On your event, push this screen.
UiApplication.getUiApplication().pushScreen(new MyPopup());
public class MyPopup extends PopupScreen{
public MyPopup() {
super(new VerticalFieldManager(), Field.FOCUSABLE);
add();//add checkbox , radio buttons here.
}

Resources