NPE when the method activate() is called before the view is opened

Before the view is opened, the viewPart is null, so if the method activate is called, the viewPart, which is null, is used to focus the view and it crashes with NPE. Because of that, viewPart should be checked before the operation is performed, as it is done in method close.