JavaFX: Disable multiple rows in TableView based on other TableView - javafx

I'm creating an application in JavaFx. Right now I have two tableviews next to each other:
------------------------------------------------------------------------------
| TableView 1 | TableView 2 |
| | |
| | Entry 1 |
| | Entry 2 |
| | Entry 3 |
| | Entry ... |
| | Entry N |
------------------------------------------------------------------------------
I would like to copy items from TableView 2 to TableView 1, but at the same time, the entries that have been copied from TableView 2 need to be disabled (disable the row with setDisable or something similar). I do know how to copy the items from one tableview to another. The problem is that I do not know how to disable multiple rows when one or multiple entries have been copied to TableView 1.
I tried this with a RowFactory, like this:
productsInTransaction.setRowFactory(tv -> {
TableRow<Product> row = new TableRow<>();
row.disableProperty().bind(???);
return row;
});
Any help is much appreciated!

I'm not quite sure of the logic you're wanting, but if your row factory is attached to table 1, and you are disabling the row when the item is present in table 2, do:
row.disableProperty().bind(Bindings.createBooleanBinding(() ->
table2.getItems().contains(row.getItem()), table2.getItems(), row.itemProperty()));

Related

Update foreign key in Qt QSqlRelationalTableModel

I'm coding in python (PySide2), but the overall concept concerns the Qt Framework.
Here are two tables of mine:
Table "recordings":
| Column | Type |
| -------- | -------------------|
| id | int (primary key) |
| param1 | int |
| param2 | int |
| ... | int |
| paramN | int |
Table "analyzed_recs":
| Column | Type |
| -------- | -------------------|
| id | int (primary key) |
| rec_id | int (foreign key) | <-- Points to recordings.id
| paramN | int |
I need in my program to display param1 and param2 from the former. In Qt I used a QSqlRelationalTable to fulfill this objective:
def _init_db_models(self):
self.analyzed_recs_sql_model = QSqlTableModel(self, self.db)
self.analyzed_recs_sql_model.setTable("analyzed_recs")
rec_id = self.analyzed_recs_sql_model.fieldIndex('rec_id')
self.analyzed_recs_sql_model.setRelation(rec_id, QSqlRelation("recordings", "id", "param1"))
self.analyzed_recs_sql_model.setRelation(rec_id, QSqlRelation("recordings", "id", "param2"))
self.analyzed_recs_sql_model.select()
self.analyzed_data_table.setModel(self.analyzed_recs_sql_model)
This code works fine in displaying the desired fields.
However, when it comes to update a record in analyzed_recs:
record = self.analyzed_recs_sql_model.record()
record.remove(record.indexOf("id"))
record.setValue("rec_id", self.current_rec_id)
record.setValue("param1", self.param1)
record.setValue("param2", param2)
self.analyzed_recs_sql_model.insertRecord(-1, record)
self.analyzed_recs_sql_model.submitAll()
The column rec_id is not set (NULL) into the table (the other params are correctly inserted into the table).
On the contrary, if I avoid using QSqlRelationalTableModel and take QSqlTableModel instead, the insertion is performed correctly (as I expected), but I lose the INNER JOIN display feature.
I was thinking as a work around to create two distinct models, a QSqlRelationalTableModel only for displaying and a QSqlTableModel only for editing the data. However I don't like the extra workload of syncing the two.
I'm sure there is a Qt feature to achieve this, but unfortunately I'm missing it.
Any suggestion?
I've had the same problem using PYQT.
The record object returned by calling record() method has no fields named 'rec_id' because the QSqlRelationalTableModel changes it with the referenced field name 'param1'. We can verify the field names using:
fieldcount = record.count()
for i in range(fieldcount):
logging.info("field %s %s", i, record.fieldName(i))
so we need to add the field before assigning it:
record = self.analyzed_recs_sql_model.record()
record.remove(record.indexOf("id"))
record.append(QSqlField("rec_id"))
record.setValue("rec_id", self.current_rec_id)

Summarizing amount of times options are selected true/false in a concatenated string

I'm pretty new to KQL and I'm having a difficult time with it (I don't have a background in stats, and I'm not very good at SQL either). I have telemetry data coming in from Microsoft AppCenter that I want to parse out into some charts but I'm trying to first figure out how to split a concatenated string that is essentially a dictionary that has two possible values: true and false. I want to count the number of each, so every key would have 2 values (true/false) which would also each have a numerical count value.
The input string I'm trying to get this data from is of the format Remove Splash/Main Menu Branding=True;Disable Aim Assist=False - unique items are split by ; and each pair is split by =. I am trying to figure out which options my users are using this way. The example string here would be split into:
Remove Splash/Main Menu Branding = True (count 1)
Disable Aim Assist = False (count 1).
If a new item came in that was Remove Splash/Main Menu Branding=True;Disable Aim Assist=True the summarized data would be
Remove Splash/Main Menu Branding = True (count 2)
Disable Aim Assist = False (count 1).
Disable Aim Assist = True (count 1).
So far I've got a query that selects a single item, but I don't know how to count this across multiple rows:
customEvents
| where timestamp > ago(7d)
| where name == "Installed a mod"
| extend Properties = todynamic(tostring(customDimensions.Properties))
| where isnotnull(Properties.["Alternate Options Selected"])
| extend OptionsStr = Properties.["Alternate Options Selected"] //The example string in above
| extend ModName = Properties.["Mod name"]
| where ModName startswith "SP Controller Support" //want to filter only to one mod's options
| extend optionsSplit = split(OptionsStr, ";")
| summarize any(optionsSplit)
I'm not sure how to make counts of it in a dictionary though. If anyone has any suggestions or tips or examples on something like this, I would really appreciate it, thanks.
Here you go:
let MyTable = datatable(Flags:string) [
"Remove Splash/Main Menu Branding=True;Disable Aim Assist=False",
"Remove Splash/Main Menu Branding=True;Disable Aim Assist=True"
];
MyTable
| extend Flags = split(Flags, ";")
| mv-expand Flag = Flags to typeof(string)
| summarize Count = count() by Flag
The output of this is:
| Flag | Count |
|---------------------------------------|-------|
| Remove Splash/Main Menu Branding=True | 2 |
| Disable Aim Assist=False | 1 |
| Disable Aim Assist=True | 1 |
Explanation:
First you split every input string (that contains multiple flags) into substrings, so that each will only have a single flag - you achieve this by using split.
Now your new Flags column has a list of strings (each one containing a single flag), and you want to create a record with every string, so you use the mv-expand operator
Lastly, you want to count how many times every key=value pair appears, and you do it with summarize count() by Flag
In case you want to see one record (in the output) per Key, then you can use the following query instead:
let MyTable = datatable(Flags:string) [
"Remove Splash/Main Menu Branding=True;Disable Aim Assist=False",
"Remove Splash/Main Menu Branding=True;Disable Aim Assist=True"
];
MyTable
| extend Flags = split(Flags, ";")
| mv-expand Flag = Flags to typeof(string)
| parse Flag with Key "=" Value
| project Key, Value
| evaluate pivot(Value, count(Value))
Its output is:
| Key | False | True |
|----------------------------------|-------|------|
| Remove Splash/Main Menu Branding | 0 | 2 |
| Disable Aim Assist | 1 | 1 |
You wrote that you're new to KQL, so you might find the following free Pluralsight courses interesting:
How to start with Microsoft Azure Data Explorer
Basic KQL
Azure Data Explorer – Advanced KQL
P.S. In the future please provide sample input in datatable format (if you're using Kusto Explorer, just select the relevant query results, right-click on the selection, and click Copy as datatable() literal), and also the expected output in a table format, so that it will be easier to understand what you want to achieve.

SQLite sort by position in a String [] , when that String [] is a field

I have a table like below in Room, in a Android application, I use Raw Query to get data. Can it be sorted by second value in array sorting_field?
---------------------------------------------
| id | other_fields | sorting_field |
---------------------------------------------
| 1001 | … | ["24","0.02","2"] |
---------------------------------------------
Initially I did the sorting part in Repository with Transformations.switchMap, inside the function a MutableLiveData> and applied Collections.sort.
It worked like a charm:
Collections.sort(list, (o1, o2) -> Double.compare(Double.valueOf(o1.sorting_field().get(positionInList)), Double.valueOf(o2.sorting_field().get(positionInList))));
After Paging implementation, I took the sorting logic out, moved to queries builder and here I am.

Querying adjacent rows in Azure Mobile Services

I'm working with Azure Mobile Services and have a table with GUIDs as its Primary Key (RecordId). I need to retrieve the previous and next rows of the table based on an ID.
Example of table:
| RecordId | RecordText |
|--------------------------------------|------------|
| 25892e17-80f6-415f-9c65-7395632f0223 | Hello |
| a53e98e4-0197-4513-be6d-49836e406aaa | Bye |
| e33898de-6302-4756-8f0c-5f6c5218e02e | Byebye |
| 3a768eea-cbda-4926-a82d-831cb89092aa | Wow |
Sample Input:
1) I enter a53e98e4-0197-4513-be6d-49836e406aaa
2) I enter e33898de-6302-4756-8f0c-5f6c5218e02e
Sample Output:
1) I'll get three results: 25892e17-80f6-415f-9c65-7395632f0223 (Previous), a53e98e4-0197-4513-be6d-49836e406aaa (Current), e33898de-6302-4756-8f0c-5f6c5218e02e (Next)
2) I'll get three results: a53e98e4-0197-4513-be6d-49836e406aaa (Previous), e33898de-6302-4756-8f0c-5f6c5218e02e (Current), 3a768eea-cbda-4926-a82d-831cb89092aa (Next)
How would I go about implementing this, and would I do this from the Node.js backend of from my ASP.NET? The use case here is a webpage where I can click Previous or Next buttons to go to the corresponding records.

DataGrid button - Invalid Postback or Callback

I have setup a DataGrid with a number of columns and a checkbox and column at the end of the row.
I am also changing the layout of the datagrid on the OnItemCreated event which changes the layout of the datagrid by expanding the rows with the "Rowspan" attribute and remove the extra columns and controls where they are no longer required.
The original datagrid layout was setup like this:
___________________________________________
| 1 | Employee Name | 01/08/10 |[] |[SAVE]|
| 1 | Employee Name | 02/08/10 |[] |[SAVE]|
___________________________________________
| 2 | Employee Name | 01/08/10 |[] |[SAVE]|
___________________________________________
| 3 | Employee Name | 04/08/10 |[] |[SAVE]|
| 3 | Employee Name | 05/08/10 |[] |[SAVE]|
| 3 | Employee Name | 06/08/10 |[] |[SAVE]|
___________________________________________
| 4 | Employee Name | 03/08/10 |[] |[SAVE]|
___________________________________________
And now it looks like this with the rows expanded, the controls removed and the datagrid columns deleted...
___________________________________________
| 1 | Employee Name | 01/08/10 |[] |[SAVE]|
| | | 02/08/10 | | |
___________________________________________
| 2 | Employee Name | 01/08/10 |[] |[SAVE]|
___________________________________________
| 3 | Employee Name | 04/08/10 |[] |[SAVE]|
| | | 05/08/10 | | |
| | | 06/08/10 | | |
___________________________________________
| 4 | Employee Name | 03/08/10 |[] |[SAVE]|
___________________________________________
The page displays when opened, and the paging control works as expected each time a user clicks on a page number.
However, when I click on the [SAVE] button for a particular employee, an error message shows a message similar "Invalid Postback or Callback". I understand that this is a result of the controls and columns that I have removed in the datagrid and the event validation does not match the orignal rendered items.
I do not want to remove the EnableEventValidation because it is a security issue.
I know I have to use the Render method to fix any changes that I have made before the page is displayed, but how do I resolve this postback issue?
Ok, lets see where the error comming from.
The GridView is use the __DoPostBack() javascript call and have no input by him self. So by him self is not send any input data from other cells.
Now I think that you do not have made custom DoPostBack calls - right ?
The second point that there is a validation is on ViewState Data.
Is by any change to use any UpdatePanel and in the middle you make any update that change this ViewState ?
What I suggest you to try is to send EnableViewState="false" on your GridView To see if you still get this error. This is not affect you because GridView in every update re-read the data that needs to created.
And the second point that you need to check, is the point that you change your data and afect the view state. Maybe by place it in other point solve the issue. From example if you have it on Page_Load maybe you need to move it on PageInit - or vise versa.
Hope this help.

Resources