Conditional commands - robotlegs

I have three main views in my application: A, B and C. Each of these views contain a view called X. Clicking a button in the X view dispatches a FooEvent to the event pool.
I would like to map multiple commands to the FooEvent and execute one of them depending on which main view (A, B or C) is currentry visible. I would have to add an if clause to every command mapped to FooEvent checking if the correct view is visible and I don't like this. Distributing logic across commands makes them hard to manage.
What is the best way to conditionally call commands in the context my application?

Inside X mediator you can create a listener for a FooEvent.
and then based on X parent you dispatch new Event.
Or inside A,B and C you listen for FooEvent, and when you catch it you mediate it from A,B or C mediator to specific command.
The goal is to keep view events inside views, and to mediate new communication further
You can also use Signals

Related

Programmatically initialize number of buttons

I have a parameter b that depends on the program execution and I need to create b buttons (gbutton). However, I don't know how to do that.

JavaFX - How to use multiple same type of event handlers on a single node

I've got 2 ListViews (A and B) of the same base type. What I need to implement is:
- user drags items from A, drops them into B
- user drags items from B, drops them into B(rearrangement).
The changes has to be saved in an sqlite table. 2 different sql query runs, so the drag and drops must have a different outcome.
If I do 2X B.setOnDragDropped, can I differentiate the 2 depending on where did the drag start?
Thanks for your help, much apprich folks
If you call setOnDragDropped(...) twice on the same node, the second handler will replace the first one (it is a set method, and works the same way as any other set method: it sets the value of a property).
You need something along the lines of
listViewB.addEventHandler(DragEvent.DRAG_DROPPED, e -> {
// handler code here...
});
You can determine the source of the drag inside the handler with
e.getGestureSource()
and see which node it matches to determine the course of action.

How can fragment pass data to calling fragment

I have an activity with two fragments say F1 and F2. On clicking the list view of F2 , a new fragment is called say F3 (Its single activity multi fragments design).
I have back button on right side of dual pane layout. On hitting this button i need to pass data from fragment F3 to F2, so that F2 views are updated based on data received(something like onActivityForResult for activity to activity interaction).
How can i achieve this?
Fragment class has setTargetFragment(), according to docs:
Optional target for this fragment. This may be used, for example, if
this fragment is being started by another, and when done wants to give
a result back to the first. The target set here is retained across
instances via FragmentManager.putFragment().

How to assign Custom Activity Result to a Root level variable at Runtime (in Custom Activity Execute method) in workflow?

Assume that I have a workflow with 3 Custom Activities which are placed in a Sequence Activity. And I created a Boolean variable (name it as “FinalResult”) at Sequence Activity level (Root) to hold the Result. My Intention is, I want to assign each Custom Activity Result to Root level variable (“FinalResult”) within the Custom Activity Execute method after finishing the activity.
I can get this by declaring the output argument in Custom Activity and placing the variable name at design time in the properties window of activity manually while designing the policy.
But I don’t want to do this by the end user. I want just the end user drag and drop the activities and write conditions on the” FinalResult” variable. Internally I have to maintain the Activity Result in “FinalResult” Variable through programmatically.
Finally I want to maintain the workflow state in “FinalResult” variable and access it anytime and anywhere in the workflow.
I tried like this below getting error "Property does not exist".
WorkflowDataContext dataContext = context.DataContext;
PropertyDescriptorCollection propertyDescriptorCollection = dataContext.GetProperties();
foreach (PropertyDescriptor propertyDesc in propertyDescriptorCollection)
{
if (propertyDesc.Name == "FinalResult")
{
object data = propertyDesc.GetValue(dataContext);// as WorkUnitSchema;
propertyDesc.SetValue(dataContext, "anil");
break;
}
}
Please let us know the possible solutions for the same.
I do this all the time.
Simply implement IActivityTemplateFactory in your activity. When dragged and dropped onto the design surface, the designer will determine if your activity (or whatever is being dropped) implements this interface. If it does, it will construct an instance and call the Create method.
Within this method you can 1) instantiate your Activity and 2) configure it. Part of configuring it is binding your Activities' properties to other Activities' arguments and/or variables within the workflow.
There are a few ways to do this. Most simply, require these arguments/variables have well known names. In this case, you can simply bind to them via
return new MyActivity
{
MyInArgument = new VisualBasicValue<object>(MyActivity.MyInArgumentDefaultName),
};
where MyActivity.MyInArgumentDefaultName is the name of the argument or variable you are binding to.
Alternatively, if that variable/argument is named by the user... you're in for a world of hurt. Essentially, you have to
Cast the DependencyObject target passed to the Create method to an ActivityDesigner
Get the ModelItem from that AD
Walk up the ModelItem tree until you find the argument/value of the proper type
Use its name to create your VisualBasicValue
Walking up the ModelItem tree is super duper hard. Its kind of like reflecting up an object graph, but worse. You can expect, if you must do this, that you'll have to fully learn how the ModelItem works, and do lots of debugging (write everything down--hell, video it) in order to see how you must travel up the graph, what types you encounter along the way, and how to get their "names" (hint--it often isn't the Name property on the ModelItem!). I've had to develop a lot of custom code to walk the ModelItem tree looking for args/vars in order to implement a drag-drop-forget user experience. Its not fun, and its not perfect. And I can't release that code, sorry.

PyQt, Qt, one event handler working with many items

I have a couple of checkboxes on my form, and I don't want to write separate event handler for each, because they all will implement the same logic. Instead I want to write just one event handler that will know about what checkbox has been clicked.
E.g. in Delphi I can use it this way:
function click_handler(sender):
begin
checked_box := sender.tag;
end;
Here I remember current checked box number in some variable (tag property was manually set in Delphi IDE).
I searched and can't find how I can implement this using Qt, because event handlers don't have sender argument.
I implemented it like this, but it's not convenient:
# assign handlers (n assignments)
checkbox_1.clicked.connect(self.cb_1_click)
...
checkbox_<n>.clicked.connect(self.cb_<n>_click)
# separate handler for each check box (n functions, doing the same stupid work)
def cb_1_click:
self.cb_click(sender=1)
...
def cb_<n>_click:
self.cb_click(sender=n)
# main check box click logic (1 function)
def cb_click(sender):
# do something common for all checkboxes
Thank you.
You may use QObject::sender() in slots to find out who emitted the signal.
Also you might want to check out QSignalMapper which is intended exactly for solving these problems.

Resources