Flex ContextMenu Change the items dynamically - apache-flex

I am using a ContextMenu for an AdvancedDataGrid in my application. I could implement the normal context menu for the grid. Now, I am planning to make the context menu dynamic.
For example, if I click on a particular cell, I need to see only the items related to that cell in the Context Menu. Is there any way we can do that?

ContextMenu class contains a customItems property which is (quoting from Adobe livedocs):
An array of ContextMenuItem objects. Each object in the array represents a context menu item that you have defined. Use this property to add, remove, or modify these custom menu items.
To add new menu items, you create a ContextMenuItem object and then add it to the customItems array (for example, by using Array.push()). For more information about creating menu items, see the ContextMenuItem class entry.

I found the solution for this. Quite simple:
http://www.pubbs.net/flex/200905/73331/

Related

NSTableView (or NSOutlineView) column hiding through contextual menu : a "no code" solution

I searched SO for the best solution to this question, found several clues, while not fully satisfying IMO. So I post below my no-code solution.
The goal is to have, as in Finder or other native applications, a contextual menu on the header bar of a table or outline, allowing to select which columns are visibles.
In IB storyboard, add all the columns you need into the table view.
You may set some of them hidden by default.
Ctrl-drag each column from the IB document outline view to the scene controller code view, in order to automatically create weak IBOutlets for each column. The purpose is to be able to target a given column in bindings.
__weak IBOutlet NSTableColumn *my_column;
Add a menu to the storyboard scene with the same number of item as the columns you plan to hide. You do not have to give title to menu items (see next point).
For each menu item, in the bindings pane, add two bindings :
Bind the item title to the column title property through your controller outlet : controller_name.my_column.title. This way the menu item will stay in sync with column title, should the code need to change it.
THIS ONE IS KEY : Bind the value of the menu item to the column hidden property : controller_name.my_column.hidden. Add a NSNegateBoolean transformer for the menu tick to be meaningful.
Attach the menu to header menu : ctrl-click on the table header view and make connection from the menu outlet to the menu created in #3.
That it's. No code beside the IBOutlets added in #2.
The bindings being two ways, un-ticking a menu item will hide the bound column. Also, if the code hides a column the bound menu item will reflect its state.

Specifying the index of dynamically created QML components within a Layout?

I'm using Javascript to dynamically create a QML component via:
var component = Qt.createComponent(qmlURL)
var item = component.createObject(parentLayout, properties)
In this case, the parentLayout is a ColumnLayout and it always creates the object at the end of the children list (which means it is displayed at the bottom of the column).
How can I specify the index position within the children of where the object is placed, or how can I move it in the children list post instantiation?
(I tried assigning parentLayout.children[i] to no avail)
Use case: I have a large existing multi-level (nested) Menu system that is static, but I'd like insert and remove custom submenu items in the hierarchy in response to external plugins registering/unregistering via a service API. While we could completely re-implement the menu system as a dynamic treeview, that seems overkill just to insert a couple menu subitems dynamically.

javafx deleting contents of an accordion pane

I have an accordion pane which contains three titled panes. I wish to delete these in the java program, however the Accordion object doesn't seem to have a clear or remove method to do this.
I have tried some ways to get around this such as the following:
if (!measureAccordion.getChildrenUnmodifiable().isEmpty()) {
ObservableList<javafx.scene.Node> accordionContent = measureAccordion.getChildrenUnmodifiable();
accordionContent.clear();
}
But this raised an UnsupportedOperationException.
If you check here accordion in javaFX , you will see that the accordion object has a method, getPanes(), which returns an ObservableList of TitledPane. The ObservableList has a lot of methods that you could use such as removeAll. You can see here the documentation for ObservableList.
Accordion is a control that can contain only TitledPane components. So if you want to modify content of Accordion then use Accordion#getPanes method.

Different context menu for every TreeView Node

I created context menu for TreeView Node but I face a problem how I can create context menu for different tree nodes?
Is there any way to solve this?
See https://www.marshall.edu/genomicjava/2013/12/30/javafx-tableviews-with-contextmenus/ which does something similar for TableViews. You can adapt the ideas there to work with a TreeView.
You can define a custom TreeCell factory on your TreeView. This custom factory will build a custom TreeCell, and, this custom cell can define the context menu as expected.
This answer shows how to create these custom pieces of building blocks :-).

Referencing and setting a single item renderer instance in a Flex Tree at runtime

Anyone know how to change a single instance of an item renderer for a Flex tree item at runtime? To reiterate, I'm not trying to change the entire tree's item renderer like this:
tree.itemRenderer = new ClassFactory(ItemRenderer2);
I'm trying to change the item renderer of a single tree item like this (the following code does not work):
tree.selectedItem.itemRenderer = new ClassFactory(ItemRenderer2);
To put it more simply, does anyone know how to reference an instance of an item renderer and set it to a new item renderer class? I've tried using the Tree's itemToItemRenderer() method with no success.
I'd appreciate any help. Thanks!
Aaron
I don't know, but on what does the choice of item renderer depend? Data? If so you could make your item renderer a ViewStack that changes depending on the data it receives.

Resources