How to cancel BeforeEdit event in gxt EditorGrid based on data stored in model for the selected row - gxt

I have an EditorGrid. I would like to cancel the edit (using the BeforeEdit event) if the user does not have edit rights to that specific column. This data (a "canEdit" value), is in the data store for the row, but has not been added a column to the grid.
I think the best way to go about this is by cancelling the edit in the BeforeEdit event. I am having trouble, however, getting the data from the selected row in the BeforeEdit event. If someone could point me in the right direction with a small code snippet for how to grab data values from the selected row in a BeforeEdit event, I would be most appreciative! Or, if there is a better way to proceed, would love to hear from you.
Thank you!
Jennifer

final EditorGrid<Plant> grid = new EditorGrid<Plant>(store, cm);
grid.addListener(Events.BeforeEdit, new Listener<GridEvent<Plant>>(){
#Override
public void handleEvent(GridEvent<Plant> be) {
//This retrieves the model being edited.
Plant model = be.getModel();
GWT.log("Model edited "+model.getName());
}
});
This snippet uses the sample program provided by GXT. You can see the demo of the original sample as well the full code here.

Here's what I used that worked:
grid.addListener(Events.BeforeEdit, new Listener<BaseEvent>() {
#Override
ModelData comment = ((EditorGrid)be.GetSource().getSelectionModel().getSelectedItem();
Boolean canEdit = Boolean.parseBoolean(comment.get("canEdit").toString());
be.setCancelled(!canEdit);
}

Related

In acumatica, how can I make changes in the Cost tab show up in the Revenue tab?

For example, if I change the "Original Budgeted Quantity" field to 9.00 (see first image below), I would like that to also change in the Revenue tab (see second image) without having to change the same thing twice.
Is there a way I can achieve this?
Cost Tab
Revenue Tab
Here are the details of the two fields I have highlighted in the images above:
Cost Tab Field
Revenue Tab Field
Let me know if I need to clarify anything or provide more information :)
Unfortunately I'm not very familiar with the Project Entry screen, and after a quick glance I couldn't find an easy way to tie the records from the Cost Budget tab to the Revenue Budget tab.
If you are planning on tying these two records together you may need some additional customization work to create the link that you are looking for if it doesn't already exist.
As far as the update itself, that is pretty straightforward and can be accomplished with a simple event handler, as demonstrated below.
namespace MyCompany.MyCustomization
{
public class ProjectEntryExtMyCustomization : PXGraphExtension<ProjectEntry>
{
public static bool IsActive() => true;
#region Actions
#endregion
#region Events
protected virtual void _(Events.FieldUpdated<PMCostBudget, PMCostBudget.qty> eventHandler)
{
PMCostBudget row = eventHandler.Row;
if (row is null) return;
// Replace the stub below with your PMRevenueBudget lookup
// using the link that you have defined.
PMRevenueBudget revenueDetail = new PMRevenueBudget();
// Assigns the PMRevenueBudget Qty field to match the PMCostBudget new value.
revenueDetail.Qty = eventHandler.NewValue as decimal?;
// Updates the PMRevenueBudget record in the cache.
Base.RevenueBudget.Update(revenueDetail);
}
#endregion
}
}
Don't forget to replace the line where I create a new PMRevenueBudget with the logic that you need for looking up the linked PMRevenueBudget record that you need. Let me know if you have any questions.

Trying to customize JAMS LaborEntry screen, looking for the line of code that will update the header

Brand new to Acumatica development and stuck on a simple thing. :(
I am customizing the LaborEntry screen of the JAMS MFG.
I have added a field to the header by extending the AMBatch DAC, called UsrTimeClocked.
For now I simply wish to set this field to a number right at the end of the RowInserted event at the detail level of the AMMTran and see my number on the screen, up on the header AMBatch.
public class LaborEntry_Extension : PXGraphExtension<LaborEntry>
{
protected virtual void _(Events.RowInserted<AMMTran> e)
{
AMBatchExt ext = Base.batch.Current.GetExtension<AMBatchExt>();
ext.UsrTimeClocked = 5.32;
//Insert line to update the correct object to see 5.32 in the TextBox, before RowSelected is done.
}
}
As is my value goes in the field and any refresh/save/delete of the row does update the correct object and I see my value where I want it. I wish to know the way to force this update.

TestFx - How to test validation dialogs with no ids

I have an application with grid of records and button insert. After clicking insert, there is a form, where you fill in data and click Ok for adding new record to the grid. After clicking Ok, there is validation which fires dialog with error informations, if any of the text fields do not match validation rules. Is there any posible way to test text on the dialog with textFx, if the dialog has no id?
This is an example for Alert based dialog:
In your test:
alert_dialog_has_header_and_content(
"Removing 'Almaty' location", "Are you sure to remove this record?");
In you helper test class:
public void alert_dialog_has_header_and_content(final String expectedHeader, final String expectedContent) {
final javafx.stage.Stage actualAlertDialog = getTopModalStage();
assertNotNull(actualAlertDialog);
final DialogPane dialogPane = (DialogPane) actualAlertDialog.getScene().getRoot();
assertEquals(expectedHeader, dialogPane.getHeaderText());
assertEquals(expectedContent, dialogPane.getContentText());
}
private javafx.stage.Stage getTopModalStage() {
// Get a list of windows but ordered from top[0] to bottom[n] ones.
// It is needed to get the first found modal window.
final List<Window> allWindows = new ArrayList<>(robot.robotContext().getWindowFinder().listWindows());
Collections.reverse(allWindows);
return (javafx.stage.Stage) allWindows
.stream()
.filter(window -> window instanceof javafx.stage.Stage)
.filter(window -> ((javafx.stage.Stage) window).getModality() == Modality.APPLICATION_MODAL)
.findFirst()
.orElse(null);
}
I know this issue is a little old and probably got fixed, but for documentation purpose in case someone else look for a fix for an issue alike, I see dialog.getDialogPane() in Dialog documentation, which would help lookup for specific controls inside the pane. So further on #plaidshirt query, we could retrieve buttons and input fields with:
dialog.getDialogPane().lookupAll()
Then narrow that down to buttons and input fields for example.

How to prevent a user from changing the selected row in an EditorGrid

Is there a way that I can prevent a user from changing the selected row? I was looking for something like a selectedRowChanging event that would either prevent or allow user from selecting a new row.
Kinda depends on how you have things set up...
I have a Grid to which I've added a CheckColumnConfig and RowEditor It's really a window into some DataBase tables. The user can modify any column 'except' the key columns. The user may also Add a new row. I defined 2 ColumConfigs. The EditColumnConfig has the various fileds disabled (i.e. if (column = keyColumn) {textField.disabled(); } the AddColumnConfig has all columns enabled.
Now if the user clicks the checkBox on a row and clicks an 'Add' button I reconfigure the grid with the addColumnModel : rowDataGrid.reconfigure(listStore, addStateColumnModel); When the user clicks the RowEditor 'Save' button I erconfigure the grid back : rowDataGrid.reconfigure(listStore, editStateColumnModel);
I 'spose you could define an uneditable ColumnConfig and swap it in and out. (or... catch the RowEditor 'BeforeEdit' event and disable to row).
That's an idea anyway... hope this helps.
grid.addListener(Events.BeforeEdit, new Listener<GridEvent<MyModel>>(){
#Override
public void handleEvent(GridEvent<MyModel> be) {
//This retrieves the model being edited.
MyModel model = be.getModel();
if (I do not want to edit this model){
be.setCancelled(true);
}
}
});

how to get the name of an object and change the text of a textbox with its' name?

Hi there (developers of wp7 apps).
The following problem already caused countless sleepless nights, so i hope anyone could provide me with a solution.
Elements grouped as a grid should call (on tap) a function that changes a textbox' text with one i declare.
I already have the function that reads the "name" of the object:
private void FunctionABC(object sender, System.Windows.Input.GestureEventArgs e)
{
//Objects name
string ObjectSender = (sender as Grid).Name.ToString();
//But how to continue, if I want kind of "this" result?:
this.ObjectSender.Text = "abc";
}
I appreciate any answer my problem. Thanks.
If your question is how to change the textbox.text property which is placed inside a grid if you tap the grid then you should iterate through the grids Children and find the textbox you are looking for and then change it's text property.
First of all you need to change the this line :
string ObjectSender = (sender as Grid).Name.ToString();
because this line gives you the name of the Grid and not the Grid itself.
Grid ObjectSender = (Grid) sender;
And then you can search through it's children.

Resources