if (resource instanceof IProject) { activeProject = (IProject) resource; projectName = activeProject.getProject().getName(); xDocPath = (activeProject.getProject().getLocation()
if (resource != null) { IProject newActiveProject = resource.getProject(); if (newActiveProject != activeProject){  activeProject = newActiveProject; projectName = activeProject.getProject().getName(); xDocPath = (activeProject.getProject().getLocation()
    public void selectionChanged(IWorkbenchPart part, ISelection selection) {        if (selection instanceof IStructuredSelection) {            Object first = ((IStructuredSelection) selection).getFirstElement();            IResource resource = (IResource) first;            if (resource instanceof IProject) {                activeProject = (IProject) resource;                projectName = activeProject.getProject().getName();                xDocPath = (activeProject.getProject().getLocation()                        .toString()                        + java.io.File.separator);                path = xDocPath + getFilename();                document = DOMUtilities.loadDOM(path);                treeViewer.setInput(document);            }        }    }