Package net.sf.cvschangelog.view

Source Code of net.sf.cvschangelog.view.ChangeLogView

/*
* Created on May 15, 2005
*
*/
package net.sf.cvschangelog.view;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.IPage;
import org.eclipse.ui.part.MessagePage;
import org.eclipse.ui.part.PageBook;
import org.eclipse.ui.part.PageBookView;
import org.eclipse.ui.views.navigator.ResourceNavigator;

/**
* @author Michael Spiegel
*
*/
public class ChangeLogView extends PageBookView {
 
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.ui.part.PageBookView#createDefaultPage(org.eclipse.ui.part.PageBook)
   */
  protected IPage createDefaultPage(PageBook book) {
    MessagePage page = new MessagePage();
    initPage(page);
    page.createControl(book);
    page.setMessage("A CVS Change Log is not available.");
    return page;
  }

 
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.ui.part.PageBookView#doCreatePage(org.eclipse.ui.IWorkbenchPart)
   */
  protected PageRec doCreatePage(IWorkbenchPart part) {
    // Try to get an outline page.
    IStructuredSelection selection = null;   
    if (part instanceof org.eclipse.ui.views.navigator.ResourceNavigator) {
        ResourceNavigator navigator = (ResourceNavigator) part;
        selection = (IStructuredSelection) navigator.getTreeViewer().getSelection();
    } else if (part instanceof org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart) {
      PackageExplorerPart packageExplorer = (PackageExplorerPart) part;
      selection = (IStructuredSelection) packageExplorer.getTreeViewer().getSelection();
    }
    if (selection != null && !selection.isEmpty()) {
        Object element = selection.getFirstElement();
        if (element instanceof IAdaptable) {
          IAdaptable adaptable = (IAdaptable) element;
          IResource resource = (IResource) adaptable.getAdapter(IResource.class);
          IProject project = resource.getProject();
          ChangeLogPage page = new ChangeLogPage(project);
          initPage(page);
          page.createControl(getPageBook());
          setupTableViewer(page);
          return new PageRec(part, page);
        }
    }
    return null;
  }

  /**
   * @param page
   */
  protected void setupTableViewer(ChangeLogPage page) {
    TableViewer tableViewer = page.getTableViewer();
    tableViewer.setContentProvider(new ChangeLogViewContentProvider());
    tableViewer.setLabelProvider(new ChangeLogViewLabelProvider());
    tableViewer.setInput(page.getProject());
  }

  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.ui.part.PageBookView#doDestroyPage(org.eclipse.ui.IWorkbenchPart,
   *      org.eclipse.ui.part.PageBookView.PageRec)
   */
  protected void doDestroyPage(IWorkbenchPart part, PageRec rec) {
    IPage page = (IPage) rec.page;
    page.dispose();
    rec.dispose();
  }
 
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.ui.part.PageBookView#getBootstrapPart()
   */
  protected IWorkbenchPart getBootstrapPart() {
      IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().
        getActivePage().findView("org.eclipse.ui.views.ResourceNavigator");
    return view;
 
 
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.ui.part.PageBookView#isImportant(org.eclipse.ui.IWorkbenchPart)
   */
  protected boolean isImportant(IWorkbenchPart part) {
    //We only care about the Resource Navigator
    return (part instanceof org.eclipse.ui.views.navigator.ResourceNavigator ||
        part instanceof org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart);
 
 

}
TOP

Related Classes of net.sf.cvschangelog.view.ChangeLogView

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.