Search in sources :

Example 1 with DocumentDao

use of com.joliciel.jochre.doc.DocumentDao in project jochre by urieli.

the class JochreImage method getPage.

/**
 * The page containing this image (in multi-page documents).
 */
public JochrePage getPage() {
    if (this.page == null && this.pageId != 0) {
        DocumentDao documentDao = DocumentDao.getInstance(jochreSession);
        this.page = documentDao.loadJochrePage(this.pageId);
    }
    return page;
}
Also used : DocumentDao(com.joliciel.jochre.doc.DocumentDao)

Example 2 with DocumentDao

use of com.joliciel.jochre.doc.DocumentDao in project jochre by urieli.

the class UpdateDocumentController method doAfterCompose.

@Override
public void doAfterCompose(Window window) throws Exception {
    super.doAfterCompose(window);
    Session session = Sessions.getCurrent();
    User user = (User) session.getAttribute(LoginController.SESSION_JOCHRE_USER);
    if (user == null)
        Executions.sendRedirect("login.zul");
    DocumentDao documentDao = DocumentDao.getInstance(jochreSession);
    List<Author> authors = documentDao.findAuthors();
    List<Comboitem> authorItems = cmbAuthors.getItems();
    for (Author author : authors) {
        Comboitem item = new Comboitem(author.getFullName());
        item.setValue(author.getId());
        authorItems.add(item);
    }
    lstAuthors.setItemRenderer(new AuthorListItemRenderer());
    winUpdateDocument.addEventListener("onModalOpen", new UpdateDocumentControllerModalListener());
}
Also used : AuthorListItemRenderer(com.joliciel.jochre.web.DocumentController.AuthorListItemRenderer) User(com.joliciel.jochre.security.User) Author(com.joliciel.jochre.doc.Author) Comboitem(org.zkoss.zul.Comboitem) DocumentDao(com.joliciel.jochre.doc.DocumentDao) JochreSession(com.joliciel.jochre.JochreSession) Session(org.zkoss.zk.ui.Session)

Example 3 with DocumentDao

use of com.joliciel.jochre.doc.DocumentDao in project jochre by urieli.

the class UpdateDocumentController method onClick$btnAddNewAuthor.

@Listen("onClick = #btnAddNewAuthor")
public void onClick$btnAddNewAuthor(Event event) {
    LOG.debug("onClick$btnAddNewAuthor");
    try {
        Author author = currentAuthor;
        boolean isNew = false;
        if (author == null) {
            author = new Author(jochreSession);
            isNew = true;
        }
        author.setFirstName(txtAuthorFirstName.getValue());
        author.setLastName(txtAuthorLastName.getValue());
        author.setFirstNameLocal(txtAuthorFirstNameLocal.getValue());
        author.setLastNameLocal(txtAuthorLastNameLocal.getValue());
        author.save();
        currentAuthor = null;
        txtAuthorFirstName.setValue("");
        txtAuthorLastName.setValue("");
        txtAuthorFirstNameLocal.setValue("");
        txtAuthorLastNameLocal.setValue("");
        btnAddNewAuthor.setLabel(Labels.getLabel("docs.documentDetails.addAuthor"));
        if (isNew) {
            DocumentDao documentDao = DocumentDao.getInstance(jochreSession);
            List<Author> authors = documentDao.findAuthors();
            List<Comboitem> authorItems = cmbAuthors.getItems();
            authorItems.clear();
            for (Author oneAuthor : authors) {
                Comboitem item = new Comboitem(oneAuthor.getFullName());
                item.setValue(oneAuthor.getId());
                authorItems.add(item);
                if (oneAuthor.getId() == author.getId())
                    cmbAuthors.setSelectedItem(item);
            }
        } else {
            ListModelList<Author> model = new ListModelList<Author>(this.currentDoc.getAuthors(), true);
            lstAuthors.setModel(model);
        }
    } catch (Exception e) {
        LOG.error("Failure in onClick$btnAddNewAuthor", e);
        throw new RuntimeException(e);
    }
}
Also used : ListModelList(org.zkoss.zul.ListModelList) Author(com.joliciel.jochre.doc.Author) Comboitem(org.zkoss.zul.Comboitem) DocumentDao(com.joliciel.jochre.doc.DocumentDao) Listen(org.zkoss.zk.ui.select.annotation.Listen)

Example 4 with DocumentDao

use of com.joliciel.jochre.doc.DocumentDao in project jochre by urieli.

the class DocumentController method getDocumentTree.

public TreeModel<TreeNode<DocOrImage>> getDocumentTree() {
    LOG.debug("getDocumentTree2");
    DocumentDao documentDao = DocumentDao.getInstance(jochreSession);
    List<JochreDocument> docs = documentDao.findDocuments();
    List<TreeNode<DocOrImage>> docNodeList = new ArrayList<>();
    for (JochreDocument doc : docs) {
        List<TreeNode<DocOrImage>> imageNodeList = new ArrayList<>();
        for (JochrePage page : doc.getPages()) {
            LOG.debug("page " + page.getIndex());
            for (JochreImage image : page.getImages()) {
                DefaultTreeNode<DocOrImage> imageNode = new DefaultTreeNode<DocumentController.DocOrImage>(new DocOrImage(image));
                imageNodeList.add(imageNode);
                if (imageId == image.getId())
                    currentImage = image;
            }
        // have images?
        }
        boolean open = docId == doc.getId();
        if (open)
            currentDoc = doc;
        DefaultTreeNode<DocOrImage> docNode = new DirectoryTreeNode<DocumentController.DocOrImage>(new DocOrImage(doc), imageNodeList, open);
        docNodeList.add(docNode);
    }
    DefaultTreeNode<DocOrImage> root = new DefaultTreeNode<DocumentController.DocOrImage>(null, docNodeList);
    TreeModel<TreeNode<DocOrImage>> docTree = new DefaultTreeModel<>(root);
    this.reloadDoc();
    this.reloadImage();
    return docTree;
}
Also used : JochreImage(com.joliciel.jochre.graphics.JochreImage) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode) ArrayList(java.util.ArrayList) DocumentDao(com.joliciel.jochre.doc.DocumentDao) JochreDocument(com.joliciel.jochre.doc.JochreDocument) DefaultTreeModel(org.zkoss.zul.DefaultTreeModel) JochrePage(com.joliciel.jochre.doc.JochrePage) TreeNode(org.zkoss.zul.TreeNode) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode)

Example 5 with DocumentDao

use of com.joliciel.jochre.doc.DocumentDao in project jochre by urieli.

the class TextController method doAfterCompose.

@Override
public void doAfterCompose(Window window) throws Exception {
    try {
        super.doAfterCompose(window);
        Session session = Sessions.getCurrent();
        currentUser = (User) session.getAttribute(LoginController.SESSION_JOCHRE_USER);
        if (currentUser == null)
            Executions.sendRedirect("login.zul");
        HttpServletRequest request = (HttpServletRequest) Executions.getCurrent().getNativeRequest();
        if (request.getParameter("imageId") != null) {
            int imageId = Integer.parseInt(request.getParameter("imageId"));
            GraphicsDao graphicsDao = GraphicsDao.getInstance(jochreSession);
            currentImage = graphicsDao.loadJochreImage(imageId);
            currentDoc = currentImage.getPage().getDocument();
            uploadPanel.setVisible(false);
            progressBox.setVisible(true);
            startRenderTimer.setRunning(true);
        } else if (request.getParameter("docId") != null) {
            int docId = Integer.parseInt(request.getParameter("docId"));
            DocumentDao documentDao = DocumentDao.getInstance(jochreSession);
            currentDoc = documentDao.loadJochreDocument(docId);
            if (request.getParameter("addPages") != null) {
                uploadPanel.setVisible(true);
                // progressBox.setVisible(false);
                lblAwaitingFile.setVisible(true);
            } else {
                uploadPanel.setVisible(false);
                progressBox.setVisible(true);
                startRenderTimer.setRunning(true);
            }
        } else {
            uploadPanel.setVisible(true);
            // progressBox.setVisible(false);
            lblAwaitingFile.setVisible(true);
        }
        if (currentDoc != null && !currentDoc.isLeftToRight())
            htmlContent.setSclass("rightToLeft");
        if (currentDoc != null) {
            documentGrid.setVisible(true);
            lblDocName.setValue(currentDoc.getName());
        }
    } catch (Exception e) {
        LOG.error("Failure in TextController$doAfterCompose", e);
        throw new RuntimeException(e);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) GraphicsDao(com.joliciel.jochre.graphics.GraphicsDao) DocumentDao(com.joliciel.jochre.doc.DocumentDao) JochreSession(com.joliciel.jochre.JochreSession) Session(org.zkoss.zk.ui.Session)

Aggregations

DocumentDao (com.joliciel.jochre.doc.DocumentDao)7 Author (com.joliciel.jochre.doc.Author)3 Comboitem (org.zkoss.zul.Comboitem)3 JochreSession (com.joliciel.jochre.JochreSession)2 JochreDocument (com.joliciel.jochre.doc.JochreDocument)2 Session (org.zkoss.zk.ui.Session)2 Listen (org.zkoss.zk.ui.select.annotation.Listen)2 ListModelList (org.zkoss.zul.ListModelList)2 JochrePage (com.joliciel.jochre.doc.JochrePage)1 GraphicsDao (com.joliciel.jochre.graphics.GraphicsDao)1 JochreImage (com.joliciel.jochre.graphics.JochreImage)1 PdfDocumentProcessor (com.joliciel.jochre.pdf.PdfDocumentProcessor)1 User (com.joliciel.jochre.security.User)1 AuthorListItemRenderer (com.joliciel.jochre.web.DocumentController.AuthorListItemRenderer)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 DefaultTreeModel (org.zkoss.zul.DefaultTreeModel)1 DefaultTreeNode (org.zkoss.zul.DefaultTreeNode)1 TreeNode (org.zkoss.zul.TreeNode)1