package com.ubx1.pdpscanner.client.views.project;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.ubx1.pdpscanner.client.PdpScanner;
import com.ubx1.pdpscanner.client.views.AbstractView;
import com.ubx1.pdpscanner.shared.Project;
/**
* The project view
*
* @author wbraik
*
*/
public class ProjectView extends AbstractView {
/**
* The webapp
*/
protected final PdpScanner app;
/**
* The associated Project object
*/
private Project project = null;
// View components
private final HorizontalPanel versionPanel = new HorizontalPanel();
private final ListBox versionList = new ListBox();
private final TabPanel tabPanel = new TabPanel();
private GeneralTab generalTab = null;
private BadPracticeTab badPracticeTab = null;
private TestTab testTab = null;
private PerformanceTab performanceTab = null;
private ProjectManagementTab projectManagementTab = null;
/**
* The project view constructor
*
* @param app
* the application object
* @param project
* the project object associated with this view
*/
public ProjectView(PdpScanner app, Project project) {
super(new VerticalPanel());
this.app = app;
this.project = project;
// Initialize view components
this.generalTab = new GeneralTab(project);
this.badPracticeTab = new BadPracticeTab(project);
this.testTab = new TestTab(project);
this.performanceTab = new PerformanceTab(project);
this.projectManagementTab = new ProjectManagementTab(project);
}
@Override
public void buildView() {
// Set styles
this.viewPanel.setStyleName("projectViewPanel");
this.versionList.setStyleDependentName("versions", true);
this.tabPanel.setStyleName("statsPanel");
// Initialize the version list
buildVersionList();
// Initialize all tabs
buildTabs();
// Add all tabs to tab panel
this.tabPanel.add(this.generalTab.getViewPanel(), "Général");
this.tabPanel.add(this.badPracticeTab.getViewPanel(),
"Mauvaises pratiques");
this.tabPanel.add(this.testTab.getViewPanel(), "Tests");
this.tabPanel.add(this.performanceTab.getViewPanel(), "Performances");
this.tabPanel.add(this.projectManagementTab.getViewPanel(),
"Gérer le projet");
this.tabPanel.setAnimationEnabled(true);
this.tabPanel.selectTab(0);
this.versionPanel.add(this.versionList);
this.viewPanel.add(versionPanel);
this.viewPanel.add(tabPanel);
}
/**
* Create the version list
*/
private void buildVersionList() {
Project p = this.project;
// Clear the version list
this.versionList.clear();
// The project must have at least one version for the version list to
// have purpose
if (p.getVersionCount() > 0) {
this.versionList.setEnabled(true);
this.versionList.addItem("Dernière version (" + p.getVersionCount()
+ ")", String.valueOf(p.getVersionCount()));
for (int i = p.getVersionCount() - 1; i > 0; i--) {
this.versionList.addItem("Version " + i, String.valueOf(i));
}
// If there are more than a single version, the user can use a chart
if (p.getVersionCount() > 1) {
this.versionList.addItem("Toutes les versions",
String.valueOf(-1));
}
this.versionList.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
int version = Integer.parseInt(versionList
.getValue(versionList.getSelectedIndex()));
ProjectView.this.generalTab.setVersion(version);
ProjectView.this.badPracticeTab.setVersion(version);
ProjectView.this.testTab.setVersion(version);
ProjectView.this.performanceTab.setVersion(version);
buildTabs();
}
});
} else {
this.versionList.addItem("Pas de version...");
this.versionList.setEnabled(false);
}
}
/**
* Create all tabs of the tab panel
*/
private void buildTabs() {
this.generalTab.buildView();
this.badPracticeTab.buildView();
this.testTab.buildView();
this.performanceTab.buildView();
this.projectManagementTab.buildView();
}
}