001: package org.contineo.web.document;
002:
003: import org.apache.commons.logging.Log;
004: import org.apache.commons.logging.LogFactory;
005:
006: import org.contineo.core.document.Document;
007: import org.contineo.core.document.History;
008: import org.contineo.core.document.dao.DocumentDAO;
009: import org.contineo.core.document.dao.HistoryDAO;
010:
011: import org.contineo.util.Context;
012:
013: import org.contineo.web.i18n.Messages;
014: import org.contineo.web.navigation.PageContentBean;
015:
016: import java.util.ArrayList;
017: import java.util.Collection;
018:
019: import javax.faces.application.Application;
020: import javax.faces.application.FacesMessage;
021: import javax.faces.context.FacesContext;
022:
023: /**
024: * Control that allows the user to list history events
025: *
026: * @author Marco Meschieri
027: * @version $Id: HistoryRecordsManager.java,v 1.1 2006/08/23 08:09:52 marco Exp $
028: * @since 3.0
029: */
030: public class HistoryRecordsManager {
031: protected static Log log = LogFactory
032: .getLog(HistoryRecordsManager.class);
033: private Collection<History> histories = new ArrayList<History>();
034: private Document selectedDocument;
035:
036: /**
037: * Changes the currently selected document and updates the articles list.
038: *
039: * @param doc
040: */
041: public void selectDocument(Document doc) {
042: selectedDocument = doc;
043:
044: // initiate the list
045: if (histories != null) {
046: histories.clear();
047: } else {
048: histories = new ArrayList<History>(10);
049: }
050:
051: try {
052: int menuId = selectedDocument.getMenuId();
053: int docId = selectedDocument.getDocId();
054:
055: DocumentDAO docDao = (DocumentDAO) Context.getInstance()
056: .getBean(DocumentDAO.class);
057: Document document = docDao.findByMenuId(menuId);
058: docId = document.getDocId();
059:
060: HistoryDAO historyDAO = (HistoryDAO) Context.getInstance()
061: .getBean(HistoryDAO.class);
062: histories = historyDAO.findByDocId(doc.getDocId());
063: } catch (Exception e) {
064: log.error(e.getMessage(), e);
065: Messages.addMessage(FacesMessage.SEVERITY_ERROR, e
066: .getMessage(), e.getMessage());
067: }
068: }
069:
070: /**
071: * Cleans up the resources used by this class. This method could be called
072: * when a session destroyed event is called.
073: */
074: public void dispose() {
075: histories.clear();
076: }
077:
078: /**
079: * Gets the list of histories which will be used by the ice:dataTable
080: * component.
081: *
082: * @return array list of histories
083: */
084: public Collection<History> getHistories() {
085: return histories;
086: }
087:
088: public String back() {
089: Application application = FacesContext.getCurrentInstance()
090: .getApplication();
091: DocumentNavigation documentNavigation = ((DocumentNavigation) application
092: .createValueBinding("#{documentNavigation}").getValue(
093: FacesContext.getCurrentInstance()));
094: documentNavigation.setSelectedPanel(new PageContentBean(
095: "documents"));
096: selectedDocument = null;
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: }
|