/*
* Created on May 17, 2005 by Michael Spiegel
*
*/
package net.sf.cvschangelog.view;
import net.sf.cvschangelog.CVSChangeLogPlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.part.IPageSite;
import org.eclipse.ui.part.Page;
/**
* @author Michael Spiegel
*
*/
public class ChangeLogPage extends Page {
private CVSChangeLogPlugin plugin = CVSChangeLogPlugin.getDefault();
private IProject project;
private TableViewer tableViewer;
private SashForm sashForm;
private TextViewer textViewer;
private final String[] COLUMN_NAMES = {"Date","Author","Comment"};
private final int[] COLUMN_WIDTHS = {20,20,60};
public ChangeLogPage(IProject project) {
super();
this.project = project;
}
public void init(IPageSite pageSite) {
super.init(pageSite);
}
/**
* @return Returns the project.
*/
public IProject getProject() {
return project;
}
/* (non-Javadoc)
* @see org.eclipse.ui.part.Page#createControl(org.eclipse.swt.widgets.Composite)
*/
public void createControl(Composite parent) {
sashForm = new SashForm(parent, SWT.VERTICAL);
sashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
this.createTable(sashForm);
textViewer = new TextViewer(sashForm, SWT.H_SCROLL | SWT.V_SCROLL
| SWT.MULTI | SWT.BORDER | SWT.READ_ONLY);
sashForm.setWeights(new int[]{70, 30});
}
protected void createTable(Composite parent) {
Table table = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI
| SWT.FULL_SELECTION);
table.setHeaderVisible(true);
table.setLinesVisible(true);
GridData data = new GridData(GridData.FILL_BOTH);
table.setLayoutData(data);
TableLayout layout = new TableLayout();
table.setLayout(layout);
this.tableViewer = new TableViewer(table);
// set columns
for(int i=0; i < COLUMN_NAMES.length; i++) {
TableColumn col = new TableColumn(table, SWT.NONE);
col.setResizable(true);
col.setText(COLUMN_NAMES[i]);
layout.addColumnData(new ColumnWeightData(COLUMN_WIDTHS[i], true));
}
}
/* (non-Javadoc)
* @see org.eclipse.ui.part.Page#getControl()
*/
public Control getControl() {
if (tableViewer == null)
return null;
return tableViewer.getControl();
}
/**
* @return
*/
public TableViewer getTableViewer() {
return tableViewer;
}
/* (non-Javadoc)
* @see org.eclipse.ui.part.Page#setFocus()
*/
public void setFocus() {
tableViewer.getControl().setFocus();
}
}