Programmatically remove/hide view during initialization - eclipse

I have a few stacked views, for one I would like to do some checks and in certain cases remove the View from the stack.
The view should be removed/hidden during initialization, before the user gets to see the view.
The views are registered using the org.eclipse.ui.views extension point and stacked using the org.eclipse.ui.perspectiveExtensions (relationship="stack").
I tried the following but the view is still visible:
#Override
public void init(IViewSite site) throws PartInitException {
site.getPage().hideView((IViewPart) site.getPart());
}
I guess there is a way using IPartListener or IPartListener2 but I would prefer some nicer way.

Related

Is there any type of functionality i can add to a movie app project? Swift, UIKit

I have created this personal project that is a movie mock up called Movly, I have mainly worked within storyboard and have yet to write any code to the app. There is multiple screens to the app accessible by the push of a button, but i am new to what kind of functions i can add in order to make my app an app, rather than just UI
In order to be able to programatically control the view controllers you will need to first create a custom view controller. You can do this by going to File > New > File > Cocoa Touch Class, you can name it whatever you want. Then go to the view controller in storyboard. Press the button 'Show the Identity Inspector' (the rextangle) and then you will see a section labelled custom class. By changing the drop down box next to Class and selecting the view controller you just made you now have access to the view controller programatically.
If you want to control things on the screen I recommend researching #IBOutlet and #IBAction (sounds complicated but it is quite simple really) and then you can write functions when textFields are changed/ buttons are pressed.
In order to write a function you need to use the following layout
func functionName() {
}
If you want to take in some kind of data you can put what it is in the bracket, e.g.
func functionName(name: String) {
}
and if you want to return something from the function you can use
func functionName() -> String {
}
When you want to call the function you just do functionName()

Navigating to a Page versus a View

I am playing around with Xamarin.Forms (mvvm) with Prism and have noticed that some tutorials show navigating to another Page while others show navigating to a View.
At a high level, I understand the literal difference... however I do not understand when I should use one over the other? I have an inclination that some of the reasoning is around dependencies, for example:
A Page has the instance of User > navigate to a view = User is still present when the back operation is used... meanwhile if you want this same behavior in navigating to and from a page, you'll need to pass the instance around via parameters... Is this correct/the reasoning behind navigating to and from views instead of pages?
In X.Forms View's are only visual objects, they do not support any navigation or any kind of infrastructure. They can only be showed when you navigate to a Page that hosts them, it doest not make sense the phrasing navigate to a View. So you should only use Page's.. In your example project they also only navigate to Page's. In the one you say they are navigating to "Views" it is only in the name, because ViewA is a ContentPage
Technically, in pure MVVM, the ViewModel should know completely nothing about the View and vice versa. When you use Page First Navigation approach you violate the first sentence. Here is an example:
class MyViewModel
{
}
class MyView
{
public MyView()
{
InitializeComponent();
// Alternatively you can do the same thing in XAML
this.BindingContext = new MyViewModel();
}
}
As you see the View is aware of the ViewModel.
When you use a ViewModel First Navigation approach, the decision of which
View should have witch ViewModel is delegated to a dedicated class. This class then is used in a custom NavigationService to match a ViewModel to a View. So it will be possible to navigate from a ViewModel to a ViewModel. This way both ViewModel and the View know nothing about each other. The disadvantage of this approach is complexity.
This is a very short answer, however, I hope you will get the key point. There are many examples of both approaches:
ViewModel First Navigation
Page First Navigation
P.S.: Prism has very nice mechanism that handle navigation. What I wrote above and the examples that I provided are just for low level understanding of this approach. If you want to use Prism you definitely have to be familiar with it.

UIPageViewController vs UIViewControllerInteractiveTransitioning

Simple question, I've done a decent amount of exploration around custom navigation / transitions between UIViewControllers and am unclear about the following:
I'm looking for behavior similar to what UIPageViewController provides (non stack-based navigation forward and backwards through "pages" of content). But I want to be able to customize the transitions, and I want the transitions to be interactive linked to a custom UIPanGestureRecognizer.
It seems like the UIViewControllerInteractiveTransitioning protocol provides some of what I want (interactivity, custom transitions). But because transitions are invoked solely with presentViewController:animated: and dismissViewControllerAnimated: it seems like it's built exclusively for use with stack-based navigation (ie UINavigationController, UITabBarController, modal presentation). Ie it doesn't seem like it'll play nice with something like UIPageViewController.
If I use UIViewController containment to build a custom container similar to UIPageViewController (see in progress demo here) can I integrate the UIViewControllerInteractiveTransitioning protocol into this to drive the transitions? Or do I need to roll those on my own (currently I have a rough manual implementation of interactive transitions)?
I do a lot of custom animations in my apps that most developers shy away from because I use a lot of UIViewControlloer Containment in my work.
It's the simplest way to get the transitions that you're looking for.
Here's how I would go about it:
Create a base view controller; lets call it MainViewController. It will have references to all of the other view controllers and hold the logic for the transitions. It should also follow a protocol we'll define as ViewXControllerDelegate.
Create your other view controllers; lets call them View1Controller, View2Controller, View3Controller. Add an instance of each of them as private properties of MainViewController. In the init method of MainViewController, instantiate them and add their views as subviews of MainViewController's view. Should look something like this:
self.v1c = [[View1Controller alloc]init];
[self addChildViewController:self.v1c];
[self.v1c didMoveToParentViewController:self];
//Setup each subview so that its frame makes it off screen or
//On screen depending on the app state and where you want each
//subview to animate to/from
[self.view addSubview:self.v1c.view];
....
Setup up a UIPanGestureRecognizer in each of your ViewXControllers that has its target and selector set to the parent view controller (MainViewController).
Handle all logic in your MainViewController class where you take the distance swiped, application state, the locations of each of the views into account (using helper properties in the ViewXControllers like "inactiveFrame" or "activeFrame" where the animation between them happens based on the percentage of movement that's occurred in the pan gesture.

MVP with GWTP: Presenter is going out of proportion

I have a view which contains a menu, it allows you to browse 5 different sections depending on where you click. When you click you are not changing page, you are hiding the other sections and showing the one you asked. It is required that everything occurs under the same Place.
From the View is simple and clean as each section is a different class and visually they are mutually exclusive. I access the controls of each section by "getting" the section itself
From the Presenter is a mess, I am having to register the handlers on the onBind() method for all 5 sections on that single presenter class, and all the logic of the events goes there as well, event handlers are beginning to conflict with similar names.
How can I break down the Presenter as I'm doing with the Views?
view Example
public interface MyView extends View {
public DeviceSettings getDeviceSection();
public Reports getReportsSection();
public License getLicenseSection();
public Support getSupportSection();
}
You can create PresenterWidgets/Views for each of your sections and then inject them into your MainPresenter.
You add handlers to your menu and then based on what is clicked just add/remove the corresponding PresenterWidget to your content slot.
You can check out the nested presenter example.

Actionscript style events in Objective-C?

I'm a newbie doing Objective-C, coming from Flex/Actionscript development.
I have an iPhone app with an UIApplicationDelegate conforming delegate called MyAppDelegate - it has a UIWindow.
Instead of adding buttons, labels and whatnot directly to the window, I guess I'm supposed to make a child class of UIViewController for every screen I wanna make. When that screen should be displayed, I add the respective controller's view to the window as a subview. When another screen should be displayed, I should pop off any other view from the window and add the new view. Hope I got everything correct so far...
My intent is to make each view controller only know about its own things, so let's say I wanna call view A from view B, in ActionScript I'd add a button in A firing off an event which would be caught in view A's owning object (could be the application), which could take proper action (remove view A, instantiate view B and display it).
How do I do this in Objective-C?
A UIControl, such as UIButton, can have any number of event listeners registered with:
- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
The target would be the view controller you want to receive the method, and the action is the method you want called. For a button, events is usually just UIControlEventTouchUpInside. If the target is nil, the event will pass up the responder chain until a responder implements the action. If you pass #selector(buttonClicked:) then the target should have this method:
-(IBAction) buttonClicked:(id)sender;
The sender will be the button that was clicked. IBAction is equivalent to a void return type. You can bind the action in Interface Builder if you prefer that to doing it programmatically.
When another screen should be
displayed, I should pop off any other
view from the window and add the new
view.
This is basically correct, but usually you use a meta view controller like UINavigationController to manage view controllers. Even if you do not use the UI that a meta controller might present, it is convenient to have view switching managed for you.
If you're coming from Actionscript you may be interested in looking at the PureMVC framwork for objective C. Using PureMVC you'll create a combination of Mediators, Commands, and Models for application interaction.
With PureMVC you register notification with the facade, and you define listeners in your mediators to respond to these. This is pretty close to the event model you're used to in Actionscript. (At my last job we added some categories to the UIResponder to remove some of the cruft in doing this). If you're creating a considerably sized application, then I would recommend you give it a look; it certainly helped us keep everything manageable.
If you don't want to pull in a third party library then you should define your view manipulation code in your MyAppDelegate and use the [UIApplication sharedApplication] class method to access the globally shared instance.