Custome activity buid by an activity file - workflow-foundation-4

How can I use custom code (activity file not codeactivity neither activitydesginer ) as an Activity inside a Reshosted workflow designer?
I was doing the following for any activity, which I build for each ( codeactivity & activitydesginer) files, and wirte:
new ToolboxCategory("new Toolbox")
{
Tools=
{
new ToolboxItemWrapper(typeof(Flowchart)),
new ToolboxItemWrapper(typeof(SimpleWebDesigner.TEST)),
....etc
AnyHelp?

If you're talking about loading an Activity loaded from a loose xaml file, you can do this.
You have to use the the ActivityXamlServices class to Load(filename) the file at runtime. When you do this, you get the deserialized Activity instance. Of course, you must have any relevant assemblies (any assembly referenced by Activities defined in the xaml file) either loaded in the AppDomain or available for loading where the Fusion loader can find them.
Once you do this, you can create a ToolboxItemWrapper passing in activityInstance.GetType().
One thing, since the Activity xaml file is an Activity which holds other Activities, you will get the default Designer, which only shows a blank header. There is no easy way* to expand the child Activities defined in the xaml file in the designer when you drop them on the design surface.
*I believe you can construct a class that implements IActivityTemplateFactory which you can pass to the ToolboxItemWrapper which can pass the root Activity defined within your xaml file, so that when you drag/drop the item from the toolbox it will automatically add all child Activities defined in the xaml file. But I've never done this and am not sure if you can.

Related

Can I automatically generate controller classes from FXML?

As I understand it, when using FXML to describe a Java FX scene, the controller class is written manually and it's member variables and methods can then be referenced from the .fxml file. When loading the scene using the FXMLLoader, member variables are set to the corresponding scene elements and methods are wired up to the corresponding events automatically. This works but is very cumbersome as changes need to be done in two places and any mistakes will only show up at runtime.
I've seen other GUI frameworks that allow you to instead generate the controller from a scene description as an abstract class which needs to be implemented to access the scene elements and handle the events. An example of what I mean:
I would create the following .fxml file (e.g. using the JavaFX Scene Builder):
<AnchorPane ... >
<children>
<Button fx:id="button" ... text="Button" onAction="#buttonPressed" />
</children>
</AnchorPane>
Somewhere in my build process, the following .java file would be created (e.g. using a Maven plugin):
abstract class TestController {
protected final Parent root;
protected final Button button;
{
// Load test.fxml file
// Assign scene elements to root and button
// Attach event handler to the button that calls buttonClicked()
}
protected abstract void buttonClicked(ActionEvent event);
}
I could then, possibly multiple times, create a concrete implementation of that controller:
final class TestControllerImpl extends TestController {
TestControllerImpl(String buttonLabel) {
button.setText(buttonLabel);
}
#Override
protected void buttonClicked(ActionEvent event) {
button.setText("I've been clicked! What a great day!");
}
}
Is there a project with the goal to do this? Or is there a problem with this approach applied to FXML?
I see the following benefits from this approach:
Declarations for member variables and methods for the controller are automatically generated.
All member variables are final and protected instead of non-final and either public or annotated.
The same for methods, they are protected instead of either public or annotated.
Not implementing a method or misspelling it's name will lead to a compiler error.
Programmatic setup of the scene can be done in the constructor instead of an initialize() method because the constructor will run after the scene has been loaded and its elements assigned to the member variables.
This is now supported in SceneBuilder, NetBeans and in Eclipse. Note this works out of the box in NetBeans and SceneBuilder, but in Eclipse you first need the e(fx)clipse plugin.
SceneBuilder:
With an FXML file open in the editor, enter the menu to select "View" and "Show Sample Controller Skeleton".
Eclipse:
Open the fxml file so the contents are displayed in the code editing pane (you should see the fxml as plaintext xml with syntax highlighting inside Eclipse, not rendered visually in SceneBuilder). Right-click on the code in Eclipse and select "Code" and then "Generate Controller".
NetBeans:
In NetBeans it is even easier, right-click the fxml file in the project explorer and select "Make Controller".
Update Nov 2020
This answer is now outdated.
As various more recent answers have pointed out, there are now a variety of additional different tools available for automatically generating FXML controller classes from FXML documents. Many of these are targeted as extensions, features or plugins to existing development tools, such as SceneBuilder, Idea, Eclipse or NetBeans.
I suggest that interested readers review both this answer and other answers to this question, then look at their individual use-case and toolset chain and choose the solution which is most appropriate for them from the available choices.
There is nothing I know that does exactly what you propose in your question.
Likely this answer will probably end up pretty outdated over time.
Alternate Technologies
JRuby achieves most of your outlined benefits using a slightly different approach - it uses jRuby's dynamic programming magic to automatically create Ruby class members from the FXML dynamically a runtime.
Tom Schindl wrote a tool which generates Java code from FXML. Of the approaches listed in this answer, Tom's tool seems closest to your question.
SceneBuilder Skeletons
A similar Java code generator from FXML is available in SceneBuilder View | Show Sample Controller Skeleton feature, which is described in this blog post. When I use SceneBuilder, I use this feature all the time and try to keep my controllers really light so they are almost all auto generated code from the SceneBuilder skeleton feature.
It is slightly annoying though because it doesn't achieve a clean separation of generated code from hand written code, so you need to be careful when you do updates to the FXML and want to generate a new skeleton and copy and paste it over parts of your existing Controller (plus that is a slightly error prone manual operation that takes a little bit of developer time).
Source code for SceneBuilder is available if you want to see how it works.
Potential Build Tool Plugins
Such a code generation feature might make a worthwhile addition to some of the existing build tools in the JavaFX ecosystem, such as the JavaFX Maven plugin or JavaFX Gradle plugin (or a separate plugin in it's own right).
Future Development
I believe that Oracle are also working on a feature extension for FXML for a future JavaFX release (post Java 8) which compiles FXML directly to Java byte code (class files), bypassing the Java source code step. This kind of feature would probably achieve most of your outlined benefits.
It is possible with NetBeans version 8.
Open FXML , go to Source and click generate controller.
Edit: Now can be done in any IDE , Eclipse needs a plugin thought.
For Intellij Idea IDE users, FXMLManager to the rescue. See the plugin homepage
"When clicking right mouse button on .fxml file, there is new menu item "Update Controller from FXML".
Clicking this item will modify FXML Java Controller:
Remove all #FXML fields that are missing in FXML and their getters/setters
Add all #FXML fields that are missing in Controller
#Deprecate all ActionEvent methods that are missing in FXML
Create all ActionEvent methods that are missing from Controller"
As I know, there are two kind of solutions exist in netbeans.
First, netbeans's internal feature "Make Controller", which you can see with right mouse click on the fxml document. it will generate controller class which will work with FXMLLoader. The controller's java file name should be indicated in the fxml document. (left panel -> Controller -> Controller class)
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Second, netbeans's plugin "FXML 2 JAVA Converter", which you can install from menu (Tool -> Plugin -> Available Plugin -> FXML 2 JAVA Converter). and you can see "Generate Abstract Class" menu item with right mouse click on the fxml document. It will generate source code from fxml document and you can use it as an abstract class without using FXMLLoader like normal JavaFX project not JavaFXML project.
Now you can easily do it with eclipse Just do these simple steps :
Go to your fxml file that you want to create Controller for
Right Click and Click source
Click Generate Controller
Click here to see the Picture of How to do it.
If you're using IntelliJ ide, you may have to try FXML Helper plugin.
First, install the plugin from the File | Settings... | Plugins. After the installation restart the ide, Now right click on the .fxml document and select the FXML Helper menu. That`s all.
#Feuermurmel
no there is not any ways to generate automatically controller class for particula .fxml file.
you should define dynamically declare variable and method with anotation #fxml and set(bind) in scence builder.

Opening a new tab and adding an mxml component to it

Hi
In our flex application we have tabs at the main level and under it we have subview.
e.g
Home / Tasks / Admin etc...
In one condition we have to click on a button and open a new tab, on this tab we have to add an existing mxml component and show it in the tab.
We are using parsley as the framework.
Inside the mxml component test.mxml (that is shown in the tab) i am configuring it with parsley using the tag
Now when i add the instance of this test.mxml i am getting an exception
I am deriving this test.mxml instance using teh parsley context
as
context.getObject(id of component) as DisplayObject and adding it to the tabNavigator...
But i am getting exception when i try to grab an instance of a view using parsley context.
How do i get an instance of a view or component that is configure through parsley using the parslye context.
posting some code
in parsley context mxml file
in mediator class
public class TestMediator {
[Inject(id="testViewID")]
public var testView:TestView;
and then i add this view object to a container....
Also the problem is occuring becuase of the view injection..because i get a parsley excepiton on startup of the application stating that there is some problem in the context.
What exception are you getting? Without this information it's hard to help you out.
Anyways, here are some thoughts:
creating views through the container should not be a problem
note that MXML components can't take constructor arguments, so make sure you don't have any in your object definition
children of the tab navigator should be containers, not just display objects

What's the base class of a Razor View in ASP.NET MVC3

I'm trying to have all my views inherit from a custom class so that I can add certain behaviour and values to all pages, but I'm having some issues. I tried subclassing System.Web.Mvc.WebViewPage but I'm forced to implement an Execute procedure that I don't know what it should do. Also, if I try to access the Context variable, I get a null reference (really weird). This leads me to think that I may have the wrong base class....
Any thoughts?
Diego, System.Web.Mvc.WebViewPage is the right base type (and you should have another class inheriting from System.Web.Mvc.WebViewPage<TModel> if you want strongly-typed views). You should mark your own class as abstract so that you are not forced to implement the Execute method.
Update: To configure all your views to use your custom base class, look into the ~\Views\Web.config file. Inside of it there's a Razor-specific section where you can use the pageBaseType attribute to configure your custom type.
As far as the Context property is concerned, it should be fully initialized once the view is executing. However, it might not be available if you try to access it too early (for example, from your classes constructor). When are you trying to access it?
The Execute method is something that is provided by the Razor compiler when your view is compiled. For example, given the following view file
Hello #Name!
The Razor compiler will behind the scenes generate the following class (this is a simplification, so the details might be off, but it should convey the point)
public class _Some_Generated_Class_Name_ : System.Web.Mvc.WebViewPage {
public void Execute() {
Write("Hello ");
Write(Name);
Write("!");
}
}
Then the framework calls the Execute method on your view class and your view gets executed.

Dynamically loading a flash movie from a flash movie

I have 2 mxml files, lets say main.mxml and child.mxml. Now lets say I want to load child.mxml inside main.mxml and pass it a complex object as a parameter. How would I go about doing this in AS3/Flex 3?
I have tried to search for this on Google and SO but either I am not searching with the right keywords or there is no info (unlikely).
Cheers
EDIT: I am not looking for the mxml to be JIT compiled, loading the compiled mxml as swf is fine.
You want to do this using Modules. You can keep main.mxml as your root Application but child.mxml needs to be defined a Module component. You can then use ModuleLoader to load the child app. Here's a good place to get started:
http://livedocs.adobe.com/flex/3/html/help.html?content=modular_2.html

Which event in the app's startup sequence is appropriate to trigger loading a config file in AIR/Flex?

I am working on a small AIR desktop application and I have some configuration infos that I want to store in a little file that's loaded at some point when the application starts and will be used to set public properties on the root application object. This should work just as if I had public variables declared in an <mx:Script> block at the beginning of my main MXML file.
I seem to have the choice of three events that could be used to initiate loading the configuration file:
invoke
initialize
creationComplete
Did I overlook some more? Which one is appropriate and why? Does it matter at all?
Example issues that come to my mind are:
are all components already accessible or will I get NULL references?
will some of my settings be overwritten in a phase that's coming after the event?
There's probably more.
If your handler needs to access UI components directly, you should wait for creationComplete; otherwise you'll get NULL references.
If you simply want to set properties on the root Application object, initialize seems the best place to do this. If you wait until creationComplete, and if the properties that you set are bound to your controls, then you might get a run-time resize or flicker as those components are updated.

Resources