001: package org.contineo.web.document;
002:
003: import com.icesoft.faces.component.tree.IceUserObject;
004: import com.icesoft.faces.component.tree.Tree;
005:
006: import org.apache.commons.logging.Log;
007: import org.apache.commons.logging.LogFactory;
008:
009: import org.contineo.core.searchengine.comparision.SearchResult;
010: import org.contineo.core.searchengine.search.Result;
011: import org.contineo.core.security.Menu;
012: import org.contineo.core.security.dao.MenuDAO;
013:
014: import org.contineo.util.Context;
015:
016: import org.contineo.web.i18n.Messages;
017: import org.contineo.web.navigation.NavigationBean;
018: import org.contineo.web.navigation.PageContentBean;
019:
020: import java.util.Map;
021:
022: import javax.faces.application.Application;
023: import javax.faces.context.FacesContext;
024: import javax.faces.event.ActionEvent;
025:
026: import javax.swing.tree.DefaultMutableTreeNode;
027: import javax.swing.tree.DefaultTreeModel;
028:
029: /**
030: * <p>
031: * The TreeNavigation class is the backing bean for the documents navigation
032: * tree on the left hand side of the application. Each node in the tree is made
033: * up of a PageContent which is responsible for the navigation action when a
034: * tree node is selected.
035: * </p>
036: * <p>
037: * When the Tree component binding takes place the tree nodes are initialised
038: * and the tree is built. Any addition to the tree navigation must be made to
039: * this class.
040: * </p>
041: * <p>
042: * This bean also controls which panel is shown on the right side of the
043: * documents view
044: * </p>
045: *
046: * @author Marco Meschieri
047: * @version $Id: DocumentNavigation.java,v 1.14 2006/08/29 16:33:46 marco Exp $
048: * @since 3.0
049: */
050: public class DocumentNavigation extends NavigationBean {
051: protected static Log log = LogFactory
052: .getLog(DocumentNavigation.class);
053:
054: // binding to component
055: private Tree treeComponent;
056:
057: // bound to components value attribute
058: private DirectoryTreeModel model;
059:
060: /**
061: * Default constructor of the tree. The root node of the tree is created at
062: * this point.
063: */
064: public DocumentNavigation() {
065: model = new DirectoryTreeModel();
066: }
067:
068: /**
069: * Gets the default tree model. This model is needed for the value attribute
070: * of the tree component.
071: *
072: * @return default tree model used by the navigation tree
073: */
074: public DefaultTreeModel getModel() {
075: return model;
076: }
077:
078: /**
079: * Gets the tree component binding.
080: *
081: * @return tree component binding
082: */
083: public Tree getTreeComponent() {
084: return treeComponent;
085: }
086:
087: /**
088: * Sets the tree component binding.
089: *
090: * @param treeComponent tree component to bind to
091: */
092: public void setTreeComponent(Tree treeComponent) {
093: this .treeComponent = treeComponent;
094: }
095:
096: public Directory getSelectedDir() {
097: return model.getSelectedDir();
098: }
099:
100: public void refresh() {
101: selectDirectory(getSelectedDir());
102: model.reload(model.getSelectedNode());
103: }
104:
105: /**
106: * Changes the currently selected directory and updates the documents list.
107: *
108: * @param directoryId
109: */
110: public void selectDirectory(Directory directory) {
111: model.selectDirectory(directory);
112: model.reload(model.getSelectedNode());
113:
114: // Notify the records manager
115: Application application = FacesContext.getCurrentInstance()
116: .getApplication();
117: DocumentsRecordsManager recordsManager = ((DocumentsRecordsManager) application
118: .createValueBinding("#{documentsRecordsManager}")
119: .getValue(FacesContext.getCurrentInstance()));
120: recordsManager.selectDirectory(directory.getMenu().getMenuId());
121: setSelectedPanel(new PageContentBean("documents"));
122: }
123:
124: /**
125: * Opens the directory containing the selected search entry
126: */
127: public String openInFolder() {
128: model.reloadAll();
129:
130: Map map = FacesContext.getCurrentInstance()
131: .getExternalContext().getRequestMap();
132:
133: Object entry = (Object) map.get("entry");
134:
135: int menuId = Menu.MENUID_DOCUMENTS;
136:
137: if (entry instanceof Result) {
138: menuId = ((Result) entry).getMenuId();
139: } else if (entry instanceof SearchResult) {
140: menuId = ((SearchResult) entry).getMenuId();
141: } else if (entry instanceof DocumentRecord) {
142: menuId = ((DocumentRecord) entry).getMenuId();
143: }
144:
145: // Get the parent directory
146: MenuDAO menuDao = (MenuDAO) Context.getInstance().getBean(
147: MenuDAO.class);
148: Menu menu = menuDao.findByPrimaryKey(menuId);
149: Directory dir = model.getDirectory(menu.getMenuParent());
150: selectDirectory(dir);
151: setSelectedPanel(new PageContentBean("documents"));
152:
153: // Show the documents browsing panel
154: Application application = FacesContext.getCurrentInstance()
155: .getApplication();
156: NavigationBean navigation = ((NavigationBean) application
157: .createValueBinding("#{navigation}").getValue(
158: FacesContext.getCurrentInstance()));
159: Menu docMenu = menuDao.findByPrimaryKey(Menu.MENUID_DOCUMENTS);
160: PageContentBean panel = new PageContentBean("m-"
161: + docMenu.getMenuId(), "document/browse");
162: panel.setContentTitle(Messages
163: .getMessage(docMenu.getMenuText()));
164: navigation.setSelectedPanel(panel);
165:
166: return null;
167: }
168:
169: /**
170: * Retrieves the directory with the specified identifier
171: *
172: * @param direcoryId The directory identifier
173: * @return The found directory, null if not found
174: */
175: public Directory getDirectory(int direcoryId) {
176: return model.getDirectory(direcoryId);
177: }
178:
179: public String delete() {
180: model.deleteDirectory(model.getSelectedDir());
181:
182: // Notify the records manager
183: Application application = FacesContext.getCurrentInstance()
184: .getApplication();
185: DocumentsRecordsManager recordsManager = ((DocumentsRecordsManager) application
186: .createValueBinding("#{documentsRecordsManager}")
187: .getValue(FacesContext.getCurrentInstance()));
188: recordsManager.selectDirectory(model.getSelectedDir()
189: .getMenuId());
190: setSelectedPanel(new PageContentBean("documents"));
191:
192: return null;
193: }
194:
195: public String edit() {
196: setSelectedPanel(new PageContentBean("updateDir"));
197:
198: Application application = FacesContext.getCurrentInstance()
199: .getApplication();
200: DirectoryEditForm form = ((DirectoryEditForm) application
201: .createValueBinding("#{directoryForm}").getValue(
202: FacesContext.getCurrentInstance()));
203: form.setDirectory(model.getSelectedDir());
204:
205: return null;
206: }
207:
208: public String rights() {
209: setSelectedPanel(new PageContentBean("rights"));
210:
211: Application application = FacesContext.getCurrentInstance()
212: .getApplication();
213: RightsRecordsManager form = (RightsRecordsManager) application
214: .createValueBinding("#{rightsRecordsManager}")
215: .getValue(FacesContext.getCurrentInstance());
216: form.selectDirectory(model.getSelectedDir());
217:
218: return null;
219: }
220:
221: public String newDirectory() {
222: setSelectedPanel(new PageContentBean("newDir"));
223:
224: return null;
225: }
226:
227: public void addNewDir(Menu dir, Directory parent) {
228: model.addNewDir(dir, parent);
229: }
230:
231: public void nodeClicked(ActionEvent event) {
232: Tree tree = (Tree) event.getSource();
233: DefaultMutableTreeNode node = tree.getNavigatedNode();
234: IceUserObject userObject = (IceUserObject) node.getUserObject();
235:
236: if (userObject.isExpanded()) {
237: model.reload(node);
238: }
239: }
240: }
|