Axapta: Update FormTreeControl after image change - icons

In my other methods (data, text, etc.) the setItem method works fine to display changes made to a tree item. However, calling setItem after changing an item's icon doesn't seem to have any effect. What is the best way to update the tree item so the new icon appears?
Thanks
public void modified()
{
FormTreeItem workingItem;
;
super();
//find the current item
workingItem = FormTreeControl.getItem(FormTreeControl.getSelection());
//update the value
workingItem.Image(1);
//update the item in the list
FormTreeControl.setItem(workingItem);
}

Found a couple of issues here:
1. Never found a way to update the icon on a tree item effectively.
2. Found out some of the tree control objects aren't initialized if you try to add/delete from a datasource method, so deleting items throws Object Not Initialized errors.
Fixed it by:
1. Create a new item (addAfterIdx of the old item).
2. Delete the old item.
3. Select the new item.
3. Move the method from the datasource to the actual form control.
Here's the code that worked for me:
public boolean modified()
{
boolean ret;
FormTreeItem workingItem = FormTreeControl.getItem(currentEditingIdx);
TreeItemIdx newItemIdx;
;
ret = super();
//create a new item
newItemIdx = SysFormTreeControl::addTreeItem(FormTreeControl, workingItem.text(), FormTreeControl.getParent(workingItem.idx()), workingItem.data(), element.imageIdx(ABC_Icon.text()));
//delete the old item
FormTreeControl.delete(currentEditingIdx);
//select the new item
FormTreeControl.selectionChanged(FormTreeControl.getItem(FormTreeControl.getRoot()), FormTreeControl.getItem(newItemIdx), FormTreeSelect::Unknown);
return ret;
}

Related

JavaFX ComboBox store selected item in csv file

so I am using JavFX to create a form that stores all the answers in a csv file. I need to create a dropdown menu that allows the users to select an option, which is then recorded in the csv file. I have tried a lot of different options, however I think comboBox is the best option.
I have no problem creating the ComboBox, I only run into problems when it comes to the method to get the value of the box.
Can someone help me find a solution, or suggest what another JavaFX menu I can use?
This is the code I have right now:
public VBox setFamiliar(){
Button button = new Button();
button.setOnAction(e -> toString());
familiarComboBox = new ComboBox<>();
familiarVBox = new VBox();
familiarComboBox.getItems().addAll("Irmão", "Irmã", "Avó", "Avô", "Tio", "Tia", "Pai", "Mãe");
familiarVBox.getChildren().add(familiarComboBox);
familiarVBox.getChildren().add(button);
return familiarVBox;
}
Here I set the ComboBox, this part doesnt seem to have a problem because it appears and I can select an item. I created a separate void toString() method that sets the value of a variable to the current selected item
public void toString(ActionEvent e){
familiar = familiarComboBox.getSelectionModel().getSelectedItem().toString();
}
The problem is then in the get method to get the value that was selected.
public String getIrmao(){
if(familiar.equals("Irmão")){
return "2";
}
return "0";
I also tried to do familiarComboBox.getSelectionModel().getSelectedItem().equals(), and other variations of this combination.
If I understand your requirement -- that when a user makes a choice from the "Familiar" combo box, a value should be written immediately to a CSV file -- you don't need the getIrmao() method. You simply write the value out in the action which you are calling toString(...) (not a good choice of names), but which we will rename to handleFamiliarChange(...).
Now the method becomes
public void handleFamiliarChange(ActionEvent e){
final String familiar =
familiarComboBox.getSelectionModel().getSelectedItem().toString();
FileUtils.writeToCsvFile(familiar.equals("Irmão") ? 2 : 0);
}
where FileUtils.writeToCsvFile(...) is a method that does the file writing. Note that FileUtils is a class you have created to separate out file handling concerns -- your JavaFX view class should only concern itself with views.

Can't clear all items (elements) in an ObservableList

I've a couple of copied elements in an observablelist which I use for copy/paste operations in a TableView. The name of the table is cpTable (copy and paste Table) for storing copied elements and to paste elements that are stored in the table. After each paste operation I want to clear the contents of cpTable before I copy other selected items with Ctrl+C.
But I always get the error:
JavaFX Application Thread" java.lang.UnsupportedOperationException:
Not supported.
at com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList.remove(ReadOnlyUnbackedObservableList.java:246)
Here is my pseudocode:
if (cpTable !=null) {
//first, get all copied items for removing all elements
ObservableList<String> copiedItems = cpTable.getItems();
int size = copiedItems.size();
// remove all elements
for(int i=0;i<size;i++) {
copiedItems.remove(i);
}
cpTable.setItems(copiedItems); //clear cpTable by setting an empty list
}
This is a method that copies the contents of selected items and puts it in a cpTable
public TableView<String> copySelectionToClipboard(TableView<String> table) {
ObservableList<String> data = table.getSelectionModel().getSelectedItems();
TableView<String> tmp = new TableView<>();
tmp.setItems(data);
return tmp;
}
When Ctrl+C is pressed the following line puts all copied items in a cpTable:
cpTable = copySelectionToClipboard( (TableView<String>) keyEvent.getSource());
As mentioned I want to clear all cpTable contents immediately after pasting
the items in a table.
Just clear your Observable List. It looks like you should use copiedItems.clear();
That should clear your table.
As James_D already mentioned, you haven't cleared exactly what's the point.
If you want to delete selected items from a table, you need to delete them from the table item list itself and not from the selection model.
A possible solution looks like this:
TableView<String> table = new TableView<>();
ObservableList<String> tableItems = table.getItems();
// needs multirowselection is set to true
ObservableList<String> readOnlyItems = table.getSelectionModel().getSelectedItems();
// removes all selected elements for the table
readOnlyItems.stream().forEach((item) -> {
tableItems.remove(item);
});
// clear the selection
table.getSelectionModel().clearSelection();
Update
This method get's an TableView, calls it's selection model to get all selected items. And then you add the data to a new TableView. And there is the problem! It's an unmodifiable read only list that you attached to your new table. First make it modifiable, like in the code below:
public TableView<String> copySelectionToClipboard(TableView<String> table) {
ObservableList<String> readOnlyData = table.getSelectionModel().getSelectedItems();
ObservableList<String> writableData = FXCollections.<String>observableArrayList(readOnlyData);
TableView<String> tmp = new TableView<>();
tmp.setItems(writableData);
return tmp;
The next problem is in your call to this method. You call it with a TableView<CsvData> and with a TableView<String> as your method needs. If CsvData is a subtype of String, than you have to change your method signature to TableView<? extends String>
If you are trying to clear all the items from your tableView and want just an empty tableView. You can use this:
myTableView.getItems().clear();
This basically gets all the items from your table view which is nothing but just the observable list now it performs clear operations to remove all the items in tableView.
Assuming you mean
table.getSelectionModel().getSelectedItems()
(since the selection model has no getItems() method), according to the Javadocs, this returns a read-only list. Thus attempting to modify the list will throw an UnsupportedOperationException.
To clear the selection, do
table.getSelectionModel().clearSelection();
(And similarly, if you want to manipulate the selection in any other way, you use methods on the selection model, rather than on the list.)

How to set position on caller when the child with open mode new is closing?

I have a form with record. To create new one I have menuitem button which opens a new Form where you can create new record (and there is lots of logic which will not be easy to move into new record action on parent datasource). This menuitem has OpenMode = New so the new record is created in datasource.
When I am closing this new form I want to set caller to newly created record. I was trying to do it by.
TableName TableName;
FormDataSource FormDataSource;
boolean test;
#Task
element.args().caller().task(#taskF5);
FormDataSource = element.args().caller().dataSource('CallerDataSourceName');
FormDataSource.research();
TableName= getFirstSelection('ThisDatasourceName');
test = FormDataSource.findRecord(TableName);
The result of the findRecord is true and it looks like it is set the position for a second after second the position on grid switch to the 1. (And the result of the test is true.)
I move the seting position to the caller but it does not help. Is the problem in the menuitem open mode property? How can I ensure the position on the caller?
I am using AX2012
I end up with this solution. I am not setting position on the child but on the caller.
On a child I have this (+ hasMethod):
tableToFind = getFirstSelection(SQLTables_DS);
element.args().caller().setRecord(tableToFind);
it is in close under the super();
On the caller I have method:
public void setRecord(TableName _TableName)
{
boolean test;
CallerDataSourceName_DS.research();
test = CallerDataSourceName_DS.findRecord(_TableName);
CallerDataSourceName.refresh();
}
The same trick on the child in close does not work. I guess it is due to the OpenMode property.

In javaFX need object reference to node under mouse cursor

I need a reference to the object under the mouse cursor in a javaFX Pane (or ScrollPane)
The following code removes the node under the cursor from the Pane.
The node object is stored in an ArrayList and has a unique id. If I had a reference to the node object, it would be a simple matter to remove it from the list. I'd be happy just to be able to pull the id of the node object out of the target description supplied by the MouseEvent's description of the target, and use it to find my node in the list. Note: I am creating these nodes dynamically and they are nameless: myList.add(new TYPE()).
Here's the snippet that I'm using to remove the node in the Pane;
root.setOnMouseClicked(new EventHandler<MouseEvent>() {
#Override
public void handle (MouseEvent me) {
// would like a line here that grabbed the reference to the target
pane.getChildren().remove(me.getTarget());
}
});
It would be better for you to put the setOnMouseClicked listener to the node on which you want to remove from the list.
List<Node> listOfNodes = new ArrayList();
Node node = new Node();
listOfNodes.add(node);
node.setOnMouseClicked((event) -> {
listOfNodes.remove(node);
});
Note: Better use ObservableList than the ordinary ArrayList especially if you want that node to be removed also out from the root pane.
To James_D: Reason for disbelief: the syntax that fails to get past the compiler is the statement containing the expression me.getTarget().getText() which is commented out. It seemed to me that that ought to have worked.
for (Text tl : textList)
if ( (me.getTarget()) == (tl) )
{
System.out.println("HuRah!");
System.out.println("text is " + tl.getText());
//System.out.println("text is " + me.getTarget().getText());
textList.remove(me.getTarget());
}

TreeView manipulation, saving adding etc

Here is what I am trying to do. I have a TreeView server side control (asp.net 2.0) and I need the user to be able to add nodes to it, then after all the nodes desired are added, the data should be saved to the database.
Here are some things I would like to pay attention to:
1) I don't want to save the tree data each time the new node is added, but rather keep the data in session until the user decides to save the entire tree. The question here is: can I bind the tree to ArrayList object and keep that object in session (rather than keeping the whole tree in session)? Then each time the node is added I will have to rebind the tree to the ArrayList rather than database.
2) I wish to minimize ViewState, any tips? What works best: compressing viewstate or keeping it all on the server at all times?
Thanks!
Use TreeNodeCollection as your internal array to hold in either ViewState or Session. Here's a rough mock-up of an approach you can use; far from perfect, but should set you on the right track.
TreeView tv = new TreeView();
// Button click event for 'Add Node' button
protected void AddNode(object sender, EventArgs e)
{
if (SaveNodeToDb(txtNewNode.Text, txtNavUrl.Text))
{
// Store user input details for new node in Session
Nodes.Add(new TreeNode() { Text = txtNewNode.Text, NavigateUrl = txtNavUrl.Text });
// Clear and re-add
tv.Nodes.Clear();
foreach (TreeNode n in Nodes)
tv.Nodes.Add(n);
}
}
public bool SaveNodeToDb(string name, string url)
{
// DB save action here.
}
public TreeNodeCollection Nodes
{
get
{
if (Session["UserNodes"] ! = null)
return (TreeNodeCollection) Session["UserNodes"];
else
return new TreeNodeCollection();
}
set
{
Session["UserNodes"] = value;
}
}

Resources