I am trying to pass a parameter to the view and open it. and I try something like this.
MyView view = new MyView(parameter);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(viewID);
but get an error message "Plug-in was unable to instantiate class 'view'"
How can I solve it?
Thanks
showView always creates a new instance of the view and requires that the class has a no parameter constructor, you can't create the view class in the way you show.
showView returns the IViewPart that it created so you can do:
IViewPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(viewID);
((MyView)part).setParameter(parameter);
where setParameter is a method you add to your view class.
Related
I have upgraded to the latest version of MvvmCross (6.4.1) from 4.2.3. I and using Xamarin Android not Xamarin forms
In the view which initiates the dialog I do the following
Create dialog fragment derived from MvxDialogFragment
Assign a view model to it
Then call ShowView on the fragment
However when I rotate the device it fails in OnCreate with the message
Your fragment is not generic and it does not have MvxFragmentPresentationAttribute attribute set!
This did not happen in 4.2.3. The reason I create dialog this way is that I want it to use different view models depending on where I need this dialog. For example I want to show a different list of data, but in the same format in the dialog.
It seems this will only work if we apply the MvxFragmentPresentationAttribute which needs the type of view model to be defined at design time rather than run time.
Is there anything I can do to achieve this
Any help will be appreciated
If you somehow need to specify the ViewModel type at runtime, you can instead of decorating the class with the MvxFragmentPresentationAttribute let it implement, IMvxOverridePresentationAttribute and return it there with the appropriate ViewModel to be presented in.
Something like:
public class MyDialog : MvxDialogFragment, IMvxOverridePresentationAttribute
{
public MvxBasePresentationAttribute PresentationAttribute(MvxViewModelRequest request)
{
return new MvxFragmentPresentationAttribute
{
ActivityHostViewModelType = myDynamicType
};
}
}
Where you implement some kind of logic to get the myDynamicType somewhere.
However, you should be able to use MvxDialogFragmentPresentationAttribute instead though and the presenter will attempt to use the topmost Android Activity to present it in if you provide a null ref as the ActivityHostViewModelType.
I have created a root FXML which is a BorderPane and it has his own root controller.
I want to dynamicly add FXML's to the center of this borderpane.
Each of these fxml's share the same controller, root controller. I have done this in netbeans by choosing an exsisting controller when creating an empty FXML file.
I also have gave the nodes different id names, but the root controller does not recognize the nodes in these fxml's.
Is it possible to share the same controller for different fxml's?
Thanks in advance
Background
I don't know that sharing a controller instance is really recommended, at least I've never seen it done before.
Even if you set the controller class in each of the fxml's you are loading to the same value, it isn't going to share the same controller instance, because every time you load a controller, it will create a new instance (object) of the controller class (which doesn't seem to be what you want).
Potential Solutions
I haven't tried either of these solutions, but believe they will work.
The initialize method will probably be called each time you load a new fxml file. So you will want to account for that in your logic by making initialize idempotent.
A. Manually set the controller instance.
Remove all of the references to your controller class from your fxml files.
Manually create an instance of your controller class.
MyController controller = new MyController();
Set the controller to your controller instance before you load each fxml.
FXMLLoader loader = new FXMLLoader();
loader.setController(controller);
Panel panel = (Panel) loader.load("myfxml.fxml");
Repeat step 3 for each of your fxml files, using the same controller reference each time.
B. Use a controller factory.
You can set a controller factory on your fxml loaders and have the controller factory always return the same controller instance.
have 1st view = index.js
2nd view = another.js
global file alloy.js
I have called the global class (alloy.js) method from index.js and now i want to move to another.js view but after httpRequest method finishes (which is declared and implemented in alloy.js).
---alloy.js---
Alloy.Global.httpMethod=function(){
//xml response is achieved, now from here i want to navigate to another.js view
}
---index.js---
Alloy.Global.httpMethod();
---another.js---
//some UI objects.
The first thing you want to do is create a controller, your another.js must be a Controller, it can be created by doing Right click on app and creating a new controller from there.
Once your controller is created, you can easily do what Phil said in the comment. i.e
Alloy.createController('another').getView().open();
This has to be placed in your onload function of HttpClient.
Hope it Helps.
I have no idea what am I missing here but I'm not able to pass additional parameter to a CollectionView, like so:
View definition is very basic:
class UI.Elements extends App.Views.CollectionView
itemView: UI.Element
And then instantiated with these options:
getUIsView: (uiobjects, itemView) ->
options =
collection: uiobjects
variationView: itemView
new App.VariationsApp.UI.Elements options
With this code the view is being created fine, except the variationView is no where to be found. From backbone documentation:
When creating a new View, the options you pass — after being merged into any default options already present on the view — are attached to the view as this.options for future reference
But my CollectionView doesn't have options property on itself.
Really, I don't have any idea what am I doing wrong. Any help would be greatly appreciated because I'm stuck.
Any parameter you provide your view that aren't recognized as Backbone/Marionette options will be attached to this.options within the view. So you should have access to the variationView by accessing this.options.variationView.
If you need to access that information in the template, you need to pass it along by writing a serializeData function.
You can see an example of this in practice here: https://github.com/davidsulc/marionette-gentle-introduction/blob/master/assets/js/common/views.js
I have a tabbed application where I want the user to be able to search for a person and then, in a new view, show the person's details. The user should be able to have multiple person detail views open for different people.
I was a little unsure if I am following the correct procedure for creating my new view. Using Unity (which I am not) it seems you would call Container.Resolve(view) however I am doing the following, the satisfyImports was necessary in order for my imports in the view / viewmodel to be created.
PersonDetailView view = new PersonDetailView();
_container.SatisfyImportsOnce(view);
_regionManager.Regions["MainRegion"].Add(view, this.SelectedPerson.Name);
_regionManager.RequestNavigate("MainRegion", new Uri("PersonDetailView", UriKind.Relative));
In the code for my PersonDetailView I have the following property to set the data context.
[Import]
public PersonDetailsViewModel ViewModel
{
set
{
this.DataContext = value;
}
}
This seems to work but the trouble I am having is that when I create a second person view, the new view is getting the same instance of the datacontext as the view that is already created.
Is this because I am creating my views incorrectly or is there a way that I tell MEF to create a new oject when it fulfills the imports for my new view?
When you export a part, by default it used a CreationPolicy of Shared. This essentially makes the exported instance a singleton in the container. With your export, add another attribute:
[Export, PartCreationPolicy(CreationPolicy.NonShared)]
public class Foo { }
This will ensure a new instance is created each time you call to compose the consumer instance.