001: package org.contineo.web.document;
002:
003: import org.contineo.core.document.Document;
004: import org.contineo.core.document.Version;
005:
006: import org.contineo.web.navigation.PageContentBean;
007:
008: import java.util.ArrayList;
009: import java.util.Arrays;
010: import java.util.Collection;
011:
012: import javax.faces.application.Application;
013: import javax.faces.context.FacesContext;
014:
015: /**
016: * Control that allows the user to navigate document's versions
017: *
018: * @author Marco Meschieri
019: * @version $Id: VersionsRecordsManager.java,v 1.3 2007/08/20 12:19:37 marco Exp $
020: * @since 3.0
021: */
022: public class VersionsRecordsManager {
023: private ArrayList<Version> versions = new ArrayList<Version>();
024: private Document selectedDocument;
025: private boolean showList = true;
026:
027: /**
028: * Changes the currently selected document and updates the versions list.
029: *
030: * @param directoryId
031: */
032: public void selectDocument(Document doc) {
033: selectedDocument = doc;
034:
035: // initiate the list
036: if (versions != null) {
037: versions.clear();
038: } else {
039: versions = new ArrayList<Version>(10);
040: }
041:
042: // get the versions and sort them
043: Collection<Version> tmp = doc.getVersions();
044: Version[] sortIt = (Version[]) tmp.toArray(new Version[0]);
045:
046: // clear collection and add sorted elements
047: Arrays.sort(sortIt);
048:
049: for (int i = sortIt.length - 1; i >= 0; i--) {
050: VersionRecord versionTmp = new VersionRecord(sortIt[i]);
051: versions.add(versionTmp);
052:
053: if (i == (sortIt.length - 1)) {
054: versionTmp.setCurrentVersion(true);
055: }
056: }
057: }
058:
059: /**
060: * Cleans up the resources used by this class. This method could be called
061: * when a session destroyed event is called.
062: */
063: public void dispose() {
064: versions.clear();
065: }
066:
067: /**
068: * Gets the list of versions which will be used by the ice:dataTable
069: * component.
070: *
071: * @return array list of versions
072: */
073: public ArrayList getVersions() {
074: return versions;
075: }
076:
077: public String back() {
078: Application application = FacesContext.getCurrentInstance()
079: .getApplication();
080: DocumentNavigation documentNavigation = ((DocumentNavigation) application
081: .createValueBinding("#{documentNavigation}").getValue(
082: FacesContext.getCurrentInstance()));
083: documentNavigation.setSelectedPanel(new PageContentBean(
084: "documents"));
085:
086: return null;
087: }
088:
089: public String edit() {
090: showList = false;
091:
092: return null;
093: }
094:
095: public String backToList() {
096: showList = true;
097:
098: return null;
099: }
100:
101: public Document getSelectedDocument() {
102: return selectedDocument;
103: }
104:
105: public void setSelectedDocument(Document selectedDocument) {
106: this .selectedDocument = selectedDocument;
107: }
108:
109: public boolean isShowList() {
110: return showList;
111: }
112: }
|