com.ephesoft.dcma.gwt.rv.client.view.PageMovePanel.java Source code

Java tutorial

Introduction

Here is the source code for com.ephesoft.dcma.gwt.rv.client.view.PageMovePanel.java

Source

/********************************************************************************* 
* Ephesoft is a Intelligent Document Capture and Mailroom Automation program 
* developed by Ephesoft, Inc. Copyright (C) 2010-2012 Ephesoft Inc. 
* 
* This program is free software; you can redistribute it and/or modify it under 
* the terms of the GNU Affero General Public License version 3 as published by the 
* Free Software Foundation with the addition of the following permission added 
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK 
* IN WHICH THE COPYRIGHT IS OWNED BY EPHESOFT, EPHESOFT DISCLAIMS THE WARRANTY 
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. 
* 
* This program is distributed in the hope that it will be useful, but WITHOUT 
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
* FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more 
* details. 
* 
* You should have received a copy of the GNU Affero General Public License along with 
* this program; if not, see http://www.gnu.org/licenses or write to the Free 
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
* 02110-1301 USA. 
* 
* You can contact Ephesoft, Inc. headquarters at 111 Academy Way, 
* Irvine, CA 92617, USA. or at email address info@ephesoft.com. 
* 
* The interactive user interfaces in modified source and object code versions 
* of this program must display Appropriate Legal Notices, as required under 
* Section 5 of the GNU Affero General Public License version 3. 
* 
* In accordance with Section 7(b) of the GNU Affero General Public License version 3, 
* these Appropriate Legal Notices must retain the display of the "Ephesoft" logo. 
* If the display of the logo is not reasonably feasible for 
* technical reasons, the Appropriate Legal Notices must display the words 
* "Powered by Ephesoft". 
********************************************************************************/

package com.ephesoft.dcma.gwt.rv.client.view;

import java.util.List;

import com.ephesoft.dcma.batch.schema.Batch;
import com.ephesoft.dcma.batch.schema.Document;
import com.ephesoft.dcma.batch.schema.Page;
import com.ephesoft.dcma.gwt.core.client.i18n.LocaleDictionary;
import com.ephesoft.dcma.gwt.core.client.ui.ScreenMaskUtility;
import com.ephesoft.dcma.gwt.core.shared.BatchDTO;
import com.ephesoft.dcma.gwt.core.shared.ConfirmationDialogUtil;
import com.ephesoft.dcma.gwt.core.shared.ConfirmationDialog.DialogListener;
import com.ephesoft.dcma.gwt.rv.client.ReviewValidateDocService;
import com.ephesoft.dcma.gwt.rv.client.ReviewValidateDocServiceAsync;
import com.ephesoft.dcma.gwt.rv.client.i18n.ReviewValidateConstants;
import com.ephesoft.dcma.gwt.rv.client.i18n.ReviewValidateMessages;
import com.ephesoft.dcma.gwt.rv.client.presenter.ReviewValidatePresenter;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.VerticalPanel;

public class PageMovePanel extends VerticalPanel {

    protected Button movePageButton;
    protected Button cancelButton;
    protected ListBox listBox1;
    protected ListBox listBox2;
    protected HorizontalPanel horizontalPanel;
    private BatchDTO batchDTO;
    private final List<String> listOfDocumentId;
    private List<Page> listOfPages;
    private final DialogBox confirmationDialog;
    protected RadioButton rb0;
    protected RadioButton rb1;
    private final String selectedPageId;
    private final String selectedDocumentId;
    private String moveToDocumentId;
    private final ReviewValidateDocServiceAsync rpcService = GWT.create(ReviewValidateDocService.class);
    private DialogListener listener;

    public PageMovePanel(String selectedPageId, String selectedDocumentId, final List<String> listOfDocumentId,
            BatchDTO batchDTO, DialogBox confirmationDialog,
            final ReviewValidatePresenter reviewValidatePresenter) {
        super();
        this.selectedPageId = selectedPageId;
        this.selectedDocumentId = selectedDocumentId;
        this.confirmationDialog = confirmationDialog;
        this.listOfDocumentId = listOfDocumentId;
        this.batchDTO = batchDTO;
        int selectedIndex = 0;
        listBox1 = new ListBox();
        listBox2 = new ListBox();

        for (String documentId : listOfDocumentId) {

            listBox1.addItem(documentId);

        }
        listBox1.setSelectedIndex(selectedIndex);
        String moveToDocumentId = PageMovePanel.this.listOfDocumentId.get(0);
        populateListOfPages(moveToDocumentId);
        listBox1.addChangeHandler(new ChangeHandler() {

            @Override
            public void onChange(ChangeEvent changeEvent) {
                int selectedIndex = PageMovePanel.this.listBox1.getSelectedIndex();
                String selectedDocumentId = PageMovePanel.this.listOfDocumentId.get(selectedIndex);
                populateListOfPages(selectedDocumentId);
                listBox2.clear();

                for (Page currPage : listOfPages) {
                    if (currPage.getIdentifier().equals(PageMovePanel.this.selectedPageId)) {
                        continue;
                    }
                    listBox2.addItem(
                            LocaleDictionary.get().getConstantValue(ReviewValidateConstants.TITLE_MOVEPANEL_PAGE)
                                    + " " + currPage.getIdentifier());
                }

                if (listBox2.getItemCount() == 0) {
                    listBox2.setEnabled(false);
                } else {
                    listBox2.setEnabled(true);
                }

            }

        });

        for (Page currPage : listOfPages) {
            if (currPage.getIdentifier().equals(PageMovePanel.this.selectedPageId)) {
                continue;
            }
            listBox2.addItem(LocaleDictionary.get().getConstantValue(ReviewValidateConstants.TITLE_MOVEPANEL_PAGE)
                    + " " + currPage.getIdentifier());
        }

        if (listBox2.getItemCount() == 0) {
            listBox2.setEnabled(false);
        } else {
            listBox2.setEnabled(true);
        }

        // listBox2.addClickHandler(new ClickHandler(){
        //
        // @Override
        // public void onClick(ClickEvent arg0) {
        // listBox2.clear();
        // listBox2.addItem("Select");
        // for(PageType currPage:listOfPages){
        // listBox2.addItem("Page "+currPage.getIdentifier());
        // }
        //            
        // }});
        rb0 = new RadioButton("myRadioGroup",
                LocaleDictionary.get().getConstantValue(ReviewValidateConstants.TITLE_MOVEPANEL_MOVE_BEFORE));
        rb1 = new RadioButton("myRadioGroup",
                LocaleDictionary.get().getConstantValue(ReviewValidateConstants.TITLE_MOVEPANEL_MOVE_AFTER));
        movePageButton = new Button(
                LocaleDictionary.get().getConstantValue(ReviewValidateConstants.TITLE_MOVEPANEL_MOVE_PAGE));
        movePageButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent arg0) {

                int moveToIndexDoc = PageMovePanel.this.listBox1.getSelectedIndex();
                final String moveToDocumentId1 = PageMovePanel.this.listOfDocumentId.get(moveToIndexDoc);
                PageMovePanel.this.setMoveToDocumentId(moveToDocumentId1);
                int moveToIndexPage = PageMovePanel.this.listBox2.getSelectedIndex();
                String moveToPageId1 = PageMovePanel.this.listOfPages.get(moveToIndexPage).getIdentifier();
                Boolean moveAfterchecked = PageMovePanel.this.rb1.getValue();

                Batch batch = PageMovePanel.this.batchDTO.getBatch();
                ScreenMaskUtility.maskScreen();
                rpcService.movePageOfDocument(batch, PageMovePanel.this.selectedPageId,
                        PageMovePanel.this.selectedDocumentId, moveToDocumentId1, moveToPageId1, moveAfterchecked,
                        new AsyncCallback<BatchDTO>() {

                            @Override
                            public void onFailure(Throwable arg0) {
                                ScreenMaskUtility.unmaskScreen();
                                if (!reviewValidatePresenter.displayErrorMessage(arg0)) {
                                    ConfirmationDialogUtil.showConfirmationDialogError(LocaleDictionary.get()
                                            .getMessageValue(ReviewValidateMessages.MSG_MOVEPANEL_MOVE_ERROR,
                                                    PageMovePanel.this.selectedPageId, moveToDocumentId1,
                                                    arg0.getMessage()));
                                }
                            }

                            @Override
                            public void onSuccess(BatchDTO batchDTO) {
                                PageMovePanel.this.batchDTO = batchDTO;
                                listener.onOkClick();
                                PageMovePanel.this.confirmationDialog.hide();
                                ScreenMaskUtility.unmaskScreen();
                            }

                        });

            }

        });
        cancelButton = new Button(
                LocaleDictionary.get().getConstantValue(ReviewValidateConstants.TITLE_MOVEPANEL_CANCEL_BUTTON));
        cancelButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent arg0) {
                PageMovePanel.this.confirmationDialog.hide();
                if (reviewValidatePresenter != null) {
                    reviewValidatePresenter.setFocus();
                }
            }
        });
        rb1.setChecked(true);
        horizontalPanel = new HorizontalPanel();
        Label labelDocument = new Label(
                LocaleDictionary.get().getConstantValue(ReviewValidateConstants.TITLE_MOVEPANEL_DOCUMENT) + ":");
        this.add(labelDocument);
        this.add(listBox1);
        Label labelPage = new Label(
                LocaleDictionary.get().getConstantValue(ReviewValidateConstants.TITLE_MOVEPANEL_PAGE) + ":");
        this.add(labelPage);
        this.add(listBox2);
        this.add(rb0);
        this.add(rb1);
        horizontalPanel.add(movePageButton);
        horizontalPanel.add(cancelButton);
        horizontalPanel.setSpacing(5);
        this.add(horizontalPanel);

    }

    public void setListener(DialogListener listener) {
        this.listener = listener;
    }

    private void populateListOfPages(String selectedDocumentId) {
        List<Document> listOfDocuments = batchDTO.getBatch().getDocuments().getDocument();
        for (Document document : listOfDocuments) {
            if (document.getIdentifier().equals(selectedDocumentId)) {
                listOfPages = document.getPages().getPage();
            }
        }
    }

    public BatchDTO getBatch() {
        return batchDTO;
    }

    public void setMoveToDocumentId(String moveToDocumentId) {
        this.moveToDocumentId = moveToDocumentId;
    }

    public String getMoveToDocumentId() {
        return moveToDocumentId;
    }
}