Example usage for com.google.gwt.event.logical.shared BeforeSelectionHandler BeforeSelectionHandler

List of usage examples for com.google.gwt.event.logical.shared BeforeSelectionHandler BeforeSelectionHandler

Introduction

In this page you can find the example usage for com.google.gwt.event.logical.shared BeforeSelectionHandler BeforeSelectionHandler.

Prototype

BeforeSelectionHandler

Source Link

Usage

From source file:org.jboss.as.console.client.domain.groups.deployment.ContentRepositoryView.java

License:Open Source License

@Override
public Widget createWidget() {
    DefaultTabLayoutPanel tabLayoutPanel = new DefaultTabLayoutPanel(40, Style.Unit.PX);
    tabLayoutPanel.addStyleName("default-tabpanel");

    groupOverview = new GroupDeploymentsOverview(presenter);

    tabLayoutPanel.add(makeDeploymentsPanel(), "Content Repository", true);
    tabLayoutPanel.add(groupOverview.asWidget(), "Server Groups", true);

    tabLayoutPanel.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
        @Override//from  ww  w .  j a  v a  2  s .  c  om
        public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
            if (event.getItem() == 1) {
                groupOverview.resetPages();
            }
        }
    });
    return tabLayoutPanel;
}

From source file:org.jboss.as.console.client.shared.viewframework.TabbedFormLayoutPanel.java

License:Open Source License

public Widget asWidget() {

    // populate tabs
    Set<String> keys = forms.keySet();
    for (String key : keys) {

        VerticalPanel layout = new VerticalPanel();
        layout.setStyleName("fill-layout-width");

        final FormAdapter<T> form = forms.get(key);

        // toolstrip
        final FormToolStrip<T> toolStrip = new FormToolStrip<T>(form, new FormToolStrip.FormCallback<T>() {
            @Override/*from w  ww .j a  va  2s . c  o  m*/
            public void onSave(Map<String, Object> changeset) {
                bridge.onSaveDetails(form.getEditedEntity(), form.getChangedValues());
            }

            @Override
            public void onDelete(T entity) {
                bridge.onRemove(entity);
            }
        });
        tools.put(key, toolStrip);

        // belongs to top level tools
        toolStrip.providesDeleteOp(false);
        toolStrip.providesEditSaveOp(!hideButtons.contains(FrameworkButton.EDIT_SAVE));

        layout.add(toolStrip.asWidget());

        // help widget
        if (address != null) {
            layout.add(HelpWidgetFactory.makeHelpWidget(address, form));
        }

        layout.add(form);

        // add to tab panel
        tabPanel.add(layout, key);
    }

    // cancel when switching forms
    tabPanel.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
        @Override
        public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
            cancel();
        }
    });

    // additional views
    for (SingleEntityView tabView : additionalViews)
        tabPanel.add(tabView.asWidget(), tabView.getTitle());

    tabPanel.selectTab(0);

    return tabPanel;
}

From source file:org.ned.server.nedadminconsole.client.NedMainPage.java

License:Open Source License

@Override
public void onModuleLoad() {
    model = new NedDataModel();
    itemEditor = new NedItemEditor(model);
    treeLibrary = new NedLibraryTree(model);
    moveButtonsPanel = new VerticalPanel();

    RootPanel rootPanel = RootPanel.get();
    rootPanel.setStyleName("gwt-DecoratorPanel");

    flowPanel = new FlowPanel();
    flowPanel.setStyleName("NedMainPanel");
    rootPanel.add(flowPanel);//w w w.  j  a  v  a  2  s.  c  o m
    flowPanel.setHeight("");

    Image imageHeader = new Image("images/header.png");
    imageHeader.setStyleName("Ned-Image");
    flowPanel.add(imageHeader);
    imageHeader.setSize("842px", "73px");

    tabPanelMain = new TabPanel();

    tabPanelMain.setStyleName("main-page-background");
    flowPanel.add(tabPanelMain);
    tabPanelMain.setSize("100%", "650px");

    librarySelector = new NedLibrarySelectorWidget(model);
    tabPanelMain.add(librarySelector, NedRes.instance().libDlgSelectLibrary(), false);

    verticalPanel = new VerticalPanel();
    tabPanelMain.add(verticalPanel, NedRes.instance().mainTabLibraryManager(), false);
    verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    verticalPanel.setSize("100%", "100%");

    horizontalPanelMain = new HorizontalPanel();
    verticalPanel.add(horizontalPanelMain);
    horizontalPanelMain.setSize("95%", "560px");
    horizontalPanelMain.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    horizontalPanelMain.setStyleName("gwt-Ned-DecoratorPanel");

    horizontalPanelMain.add(treeLibrary);
    horizontalPanelMain.setCellWidth(treeLibrary, "40%");
    horizontalPanelMain.setCellHorizontalAlignment(treeLibrary, HasHorizontalAlignment.ALIGN_LEFT);

    PushButton moveUpButton = new PushButton(new Image("images/up_button_idle.png"),
            new Image("images/up_button_pressed.png"));
    moveButtonsPanel.add(moveUpButton);
    moveUpButton.setSize("52px", "48px");
    moveUpButton.setStylePrimaryName("NedDeleteButton");
    moveButtonsPanel.setCellVerticalAlignment(moveUpButton, HasVerticalAlignment.ALIGN_TOP);
    moveButtonsPanel.setCellHeight(moveUpButton, "60px");
    moveUpButton.addClickHandler(new MoveItemCommand(true));

    PushButton moveDownButton = new PushButton(new Image("images/down_button_idle.png"),
            new Image("images/down_button_pressed.png"));
    moveButtonsPanel.add(moveDownButton);
    moveDownButton.setSize("52px", "48px");
    moveDownButton.setStylePrimaryName("NedDeleteButton");
    moveButtonsPanel.setCellVerticalAlignment(moveDownButton, HasVerticalAlignment.ALIGN_TOP);
    moveButtonsPanel.setCellHeight(moveDownButton, "60px");

    moveDownButton.addClickHandler(new MoveItemCommand(false));

    horizontalPanelMain.add(moveButtonsPanel);
    horizontalPanelMain.setSize("100%", "100%");

    horizontalPanelMain.setCellWidth(moveButtonsPanel, "20%");
    horizontalPanelMain.setCellHorizontalAlignment(moveButtonsPanel, HasHorizontalAlignment.ALIGN_CENTER);

    horizontalPanelMain.add(itemEditor);
    horizontalPanelMain.setCellWidth(itemEditor, "40%");
    horizontalPanelMain.setCellHorizontalAlignment(itemEditor, HasHorizontalAlignment.ALIGN_RIGHT);

    Widget widgetUserManagement = new NedUserManagementWidget();
    tabPanelMain.add(widgetUserManagement, NedRes.instance().userManagement(), false);

    Widget messageOfTheDay = new NedMotdWidget();
    tabPanelMain.add(messageOfTheDay, NedRes.instance().mainMOTD(), false);

    Widget widgetStatistics = new NedStatisticsWidget();
    tabPanelMain.add(widgetStatistics, NedRes.instance().mainStatistics(), false);

    Widget widgetLanguage = new NedLanguageWidget();
    tabPanelMain.add(widgetLanguage, NedRes.instance().mainLanguage(), false);

    decoratorPanelFill = new SimplePanel();
    flowPanel.add(decoratorPanelFill);
    decoratorPanelFill.setPixelSize(imageHeader.getWidth(),
            Window.getClientHeight() - imageHeader.getHeight() - flowPanel.getOffsetHeight());
    decoratorPanelFill.setStyleName("gwt-DecoratorPanel-gradient");
    model.addListener(this);
    tabPanelMain.selectTab(0);

    tabPanelMain.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
        public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
            int selectedIndex = event.getItem().intValue();
            if (selectedIndex == 1 && model.getCurrentLibrary() == null) {
                NedAlert.showAlert(NedRes.instance().msgErrorNoLibrarySelected());
                event.cancel();
            } else if (tabPanelMain.getWidget(currentTabIndex) instanceof NedUserManagementWidget) {
                NedUserManagementWidget userManagement = (NedUserManagementWidget) tabPanelMain
                        .getWidget(currentTabIndex);
                if (userManagement.isBlocked()) {
                    userManagement.tryPersist(selectedIndex, tabPanelMain);
                    event.cancel();
                }
            }
        }
    });
    tabPanelMain.addSelectionHandler(new SelectionHandler<Integer>() {
        @Override
        public void onSelection(SelectionEvent<Integer> event) {
            currentTabIndex = event.getSelectedItem().intValue();
            if (tabPanelMain.getWidget(currentTabIndex) instanceof NedUserManagementWidget) {
                ((NedUserManagementWidget) tabPanelMain.getWidget(currentTabIndex)).refreshBlockNavigation();
            }
        }
    });
}

From source file:org.opencms.gwt.client.property.CmsVfsModePropertyEditor.java

License:Open Source License

/**
 * @see org.opencms.gwt.client.property.A_CmsPropertyEditor#setupFieldContainer()
 *//*from  w  w w  .jav a  2 s  .c o m*/
@Override
protected void setupFieldContainer() {

    CmsListInfoBean info = m_handler.getPageInfo();
    m_panel = new CmsPropertyPanel(m_showResourceProperties, info);
    String modeClass = m_handler.getModeClass();
    if (modeClass != null) {
        m_panel.addStyleName(modeClass);
    }
    m_panel.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {

        public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {

            int target = event.getItem().intValue();
            handleSwitchTab(target);
        }
    });

    m_form.setWidget(m_panel);
}

From source file:org.opendatakit.aggregate.client.AggregateUI.java

License:Apache License

void setSubMenuSelectionHandler(final TabPanel menuTab, final Tabs menu, final SubTabs[] subMenus) {
    // add the mainNav selection handler for this menu...
    mainNav.addSelectionHandler(new SelectionHandler<Integer>() {
        @Override/*from w  ww  .  j a v  a2s  . co  m*/
        public void onSelection(SelectionEvent<Integer> event) {
            if (userInfo == null) {
                GWT.log("getSubMenuSelectionHandler: No userInfo - not setting selection");
                return;
            }

            int selected = event.getSelectedItem();
            String tabHash = menu.getHashString();

            Tabs tab = tabPosition.get(selected);

            if (tab == null) {
                return;
            }

            if (tabHash.equals(tab.getHashString())) {

                if (!authorizedForTab(tab)) {
                    return;
                }

                // and select the appropriate subtab...
                AggregateTabBase tabObj = tabMap.get(menu);
                if (tabObj != null) {
                    tabObj.selectTab(tabObj.findSubTabIndexFromHash(hash));
                }
            }
        }
    });

    menuTab.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {

        @Override
        public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
            // allow the currently-selected SubTab to refuse the tab selection.
            // refusal should only occur after user confirmation.
            if (!getTimer().canLeaveCurrentSubTab()) {
                event.cancel();
            }
        }

    });

    menuTab.addSelectionHandler(new SelectionHandler<Integer>() {
        @Override
        public void onSelection(SelectionEvent<Integer> event) {
            if (userInfo == null) {
                GWT.log("getSubMenuSelectionHandler: No userInfo - not setting subMenu selection");
                return;
            }
            int selected = event.getSelectedItem();
            clearError();
            hash.clear();
            hash.set(UrlHash.MAIN_MENU, menu.getHashString());
            hash.set(UrlHash.SUB_MENU, subMenus[selected].getHashString());
            getTimer().setCurrentSubTab(subMenus[selected]);
            hash.put();
            changeHelpPanel(subMenus[selected]);
        }
    });
}

From source file:org.openelis.modules.attachment.client.AttachmentScreenUI.java

License:Open Source License

protected void initialize() {
    ArrayList<Item<Integer>> model1, model2;

    screen = this;

    /*//from  ww  w .  j  a va  2 s  .co  m
     * screen fields and widgets
     */
    addScreenHandler(description, AttachmentMeta.getDescription(), new ScreenHandler<String>() {
        public void onStateChange(StateChangeEvent event) {
            description.setEnabled(isState(QUERY, DISPLAY));
            description.setQueryMode(isState(QUERY, DISPLAY));
        }

        public Widget onTab(boolean forward) {
            return forward ? createdDate : abortButton;
        }
    });

    addScreenHandler(createdDate, AttachmentMeta.getCreatedDate(), new ScreenHandler<Datetime>() {
        public void onStateChange(StateChangeEvent event) {
            createdDate.setEnabled(isState(QUERY, DISPLAY));
            createdDate.setQueryMode(isState(QUERY, DISPLAY));
        }

        public Widget onTab(boolean forward) {
            return forward ? querySection : description;
        }
    });

    addScreenHandler(querySection, AttachmentMeta.getSectionId(), new ScreenHandler<Integer>() {
        public void onStateChange(StateChangeEvent event) {
            querySection.setEnabled(isState(QUERY, DISPLAY));
            querySection.setQueryMode(isState(QUERY, DISPLAY));
        }

        public Widget onTab(boolean forward) {
            return forward ? issueText : createdDate;
        }
    });

    addScreenHandler(issueText, AttachmentMeta.getIssueText(), new ScreenHandler<String>() {
        public void onStateChange(StateChangeEvent event) {
            issueText.setEnabled(isState(QUERY, DISPLAY));
            issueText.setQueryMode(isState(QUERY, DISPLAY));
        }

        public Widget onTab(boolean forward) {
            return forward ? searchButton : querySection;
        }
    });

    addScreenHandler(searchButton, "searchButton", new ScreenHandler<Object>() {
        public void onStateChange(StateChangeEvent event) {
            searchButton.setEnabled(isState(QUERY, DISPLAY));
        }

        public Widget onTab(boolean forward) {
            return forward ? tree : issueText;
        }
    });

    addScreenHandler(tree, "tree", new ScreenHandler<Object>() {
        public void onStateChange(StateChangeEvent event) {
            tree.setEnabled(true);
        }

        public Widget onTab(boolean forward) {
            return forward ? attachButton : searchButton;
        }
    });

    tree.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
        @Override
        public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
            Integer id;
            Node node;

            if (!isState(UPDATE))
                return;

            /*
             * in Update state, only the nodes that belong to the locked
             * attachment can be selected
             */
            node = tree.getNodeAt(event.getItem());

            if (ATTACHMENT_LEAF.equals(node.getType()))
                id = node.getData();
            else if (ATTACHMENT_ITEM_LEAF.equals(node.getType()))
                id = node.getParent().getData();
            else
                id = null;

            if (!manager.getAttachment().getId().equals(id))
                event.cancel();
        }
    });

    tree.addSelectionHandler(new SelectionHandler<Integer>() {
        @Override
        public void onSelection(SelectionEvent<Integer> event) {
            nodeSelected(event.getSelectedItem());
        }
    });

    tree.addDoubleClickHandler(new DoubleClickHandler() {
        @Override
        public void onDoubleClick(DoubleClickEvent event) {
            if (!isState(UPDATE, DELETE))
                displayAttachment(tree.getNodeAt(tree.getSelectedNode()), null);
        }
    });

    tree.addBeforeCellEditedHandler(new BeforeCellEditedHandler() {
        @Override
        public void onBeforeCellEdited(BeforeCellEditedEvent event) {
            String name;
            Integer sectId;
            SystemUserPermission perm;
            Node node;

            node = tree.getNodeAt(tree.getSelectedNode());
            if (!ATTACHMENT_LEAF.equals(node.getType()) || !isState(UPDATE)
                    || (event.getCol() != 0 && event.getCol() != 2)) {
                event.cancel();
                return;
            }

            perm = UserCache.getPermission();
            sectId = manager.getAttachment().getSectionId();
            try {
                if (sectId != null) {
                    /*
                     * allow changing any field of the attachment only if
                     * the user has complete permission to the current
                     * section
                     */
                    name = SectionCache.getById(sectId).getName();
                    if (!perm.has(name, SectionFlags.COMPLETE)) {
                        event.cancel();
                        return;
                    }
                }

                /*
                 * make sure that the section can't be changed to one that
                 * the user doesn't have complete permission to
                 */
                for (Item<Integer> row : tableSection.getModel()) {
                    name = SectionCache.getById(row.getKey()).getName();
                    row.setEnabled(perm.has(name, SectionFlags.COMPLETE));
                }
            } catch (Exception e) {
                Window.alert(e.getMessage());
                logger.log(Level.SEVERE, e.getMessage(), e);
                event.cancel();
            }
        }
    });

    tree.addCellEditedHandler(new CellEditedHandler() {
        public void onCellUpdated(CellEditedEvent event) {
            Object val;
            AttachmentDO data;

            val = tree.getValueAt(event.getRow(), event.getCol());
            data = manager.getAttachment();
            switch (event.getCol()) {
            case 0:
                data.setDescription((String) val);
                break;
            case 2:
                data.setSectionId((Integer) val);
                break;
            }
        }
    });

    tree.setAllowMultipleSelection(true);

    addScreenHandler(attachButton, "attachButton", new ScreenHandler<Object>() {
        public void onStateChange(StateChangeEvent event) {
            attachButton.setEnabled(false);
        }

        public Widget onTab(boolean forward) {
            return forward ? updateButton : tree;
        }
    });

    addScreenHandler(updateButton, "updateButton", new ScreenHandler<Object>() {
        public void onStateChange(StateChangeEvent event) {
            updateButton.setEnabled(isState(DISPLAY, UPDATE) && manager != null);
            if (isState(UPDATE)) {
                updateButton.lock();
                updateButton.setPressed(true);
            }
        }

        public Widget onTab(boolean forward) {
            return forward ? deleteButton : tree;
        }
    });

    addShortcut(updateButton, 'u', CTRL);

    addScreenHandler(deleteButton, "deleteButton", new ScreenHandler<Object>() {
        public void onStateChange(StateChangeEvent event) {
            deleteButton.setEnabled(isState(DISPLAY, DELETE) && manager != null);
            if (isState(DELETE)) {
                deleteButton.lock();
                deleteButton.setPressed(true);
            }
        }

        public Widget onTab(boolean forward) {
            return forward ? commitButton : updateButton;
        }
    });

    addShortcut(deleteButton, 'd', CTRL);

    addScreenHandler(commitButton, "commitButton", new ScreenHandler<Object>() {
        public void onStateChange(StateChangeEvent event) {
            commitButton.setEnabled(isState(UPDATE, DELETE));
        }

        public Widget onTab(boolean forward) {
            return forward ? deleteButton : abortButton;
        }
    });

    addShortcut(commitButton, 'm', CTRL);

    addScreenHandler(abortButton, "abortButton", new ScreenHandler<Object>() {
        public void onStateChange(StateChangeEvent event) {
            abortButton.setEnabled(isState(UPDATE, DELETE));
        }

        public Widget onTab(boolean forward) {
            return forward ? description : commitButton;
        }
    });

    addShortcut(abortButton, 'o', CTRL);

    fileDrop = new FileDrop(screen, "openelis/upload") {
        public void onDrop(DropEvent event) {
            if (!fileDrop.isEnabled())
                return;

            if (dropIndicator != null) {
                dropIndicator.removeFromParent();
                dropIndicator = null;
            }

            super.onDrop(event);
        }

        public void onDropSuccess() {
            ArrayList<AttachmentManager> ams;

            try {
                /*
                 * don't let a file be dropped for upload if a record is
                 * locked
                 */
                if (isState(UPDATE, DELETE))
                    return;
                setBusy(Messages.get().gen_saving());
                /*
                 * create attachments for the newly uploaded files and get
                 * the managers for them
                 */
                ams = AttachmentService.get().put();
                if (managers == null)
                    managers = new HashMap<Integer, AttachmentManager>();

                for (AttachmentManager am : ams)
                    managers.put(am.getAttachment().getId(), am);
                previousManager = null;
                setState(DISPLAY);
                if (isLoadedFromQuery) {
                    /*
                     * the tree is showing the attachments returned by a
                     * previous search, so they are cleared and only the
                     * attachment created from the uploaded file is shown
                     */
                    isLoadedFromQuery = false;
                    loadTree(ams, true, false, isLoadedFromQuery);
                } else {
                    /*
                     * add the attachment created from uploaded file as the
                     * first one in the tree
                     */
                    loadTree(ams, false, false, isLoadedFromQuery);
                }
                tree.selectNodeAt(0);
                nodeSelected(0);
                setDone(Messages.get().gen_savingComplete());
            } catch (Exception e) {
                Window.alert(e.getMessage());
                logger.log(Level.SEVERE, e.getMessage(), e);
                clearStatus();
            }
        }
    };

    addStateChangeHandler(new StateChangeEvent.Handler() {
        public void onStateChange(StateChangeEvent event) {
            fileDrop.setEnabled(isState(QUERY, DISPLAY));

            if (isState(UPDATE, DELETE) && !closeHandlerAdded && window != null) {
                /*
                 * this handler is not added in initialize() because this
                 * screen can be shown in a modal window and in that case,
                 * the window is not available in initialize()
                 */
                window.addBeforeClosedHandler(new BeforeCloseHandler<WindowInt>() {
                    public void onBeforeClosed(BeforeCloseEvent<WindowInt> event) {
                        if (isState(UPDATE, DELETE)) {
                            event.cancel();
                            setError(Messages.get().gen_mustCommitOrAbort());
                        } else if (dropIndicator != null) {
                            dropIndicator.removeFromParent();
                            dropIndicator = null;
                        }
                    }
                });
                closeHandlerAdded = true;
            }
        }
    });

    fileDrop.addDragEnterHandler(new DragEnterHandler() {
        @Override
        public void onDragEnter(DragEnterEvent event) {
            LayoutPanel panel;

            if (dropIndicator == null) {
                dropIndicator = new DropIndicator();
                panel = (LayoutPanel) screen.getWidget();
                panel.add(dropIndicator);
                panel.setWidgetTopBottom(dropIndicator, 0, Unit.PX, 0, Unit.PX);
            }
        }
    });

    fileDrop.addDragLeaveHandler(new DragLeaveHandler() {
        @Override
        public void onDragLeave(DragLeaveEvent event) {
            if (dropIndicator != null) {
                dropIndicator.removeFromParent();
                dropIndicator = null;
            }
        }
    });

    /*
     * here two separate models are created for the two dropdowns to make
     * sure that any items disabled or enabled in one don't affect the other
     */
    model1 = new ArrayList<Item<Integer>>();
    model2 = new ArrayList<Item<Integer>>();
    for (SectionDO s : SectionCache.getList()) {
        model1.add(new Item<Integer>(s.getId(), s.getName()));
        model2.add(new Item<Integer>(s.getId(), s.getName()));
    }

    querySection.setModel(model1);
    tableSection.setModel(model2);

    /*
     * call for locking and fetching attachments
     */
    if (fetchForUpdateCall == null) {
        fetchForUpdateCall = new AsyncCallbackUI<AttachmentManager>() {
            public void success(AttachmentManager result) {
                Node node;

                manager = result;
                managers.put(manager.getAttachment().getId(), manager);
                setState(UPDATE);

                node = tree.getNodeAt(tree.getSelectedNode());
                if (ATTACHMENT_ITEM_LEAF.equals(node.getType()))
                    node = node.getParent();
                reloadAttachment(node);
                tree.selectNodeAt(node);
                tree.startEditing(tree.getSelectedNode(), 0);
            }

            public void failure(Throwable e) {
                Window.alert(e.getMessage());
                logger.log(Level.SEVERE, e.getMessage() != null ? e.getMessage() : "null", e);
            }

            public void finish() {
                clearStatus();
            }
        };
    }

    /*
     * call for updating an attachment
     */
    if (updateCall == null) {
        updateCall = new AsyncCallbackUI<AttachmentManager>() {
            public void success(AttachmentManager result) {
                Node node;

                manager = result;
                managers.put(manager.getAttachment().getId(), manager);
                setState(DISPLAY);

                node = tree.getNodeAt(tree.getSelectedNode());
                if (ATTACHMENT_ITEM_LEAF.equals(node.getType()))
                    node = node.getParent();
                reloadAttachment(node);
                tree.selectNodeAt(node);
                nodeSelected(tree.getSelectedNode());
                clearStatus();
            }

            public void validationErrors(ValidationErrorsList e) {
                showErrors(e);
            }

            public void failure(Throwable e) {
                Window.alert("commitUpdate(): " + e.getMessage());
                logger.log(Level.SEVERE, e.getMessage() != null ? e.getMessage() : "null", e);
                clearStatus();
            }
        };
    }

    /*
     * call for unlocking an attachment
     */
    if (unlockCall == null) {
        unlockCall = new AsyncCallbackUI<AttachmentManager>() {
            public void success(AttachmentManager result) {
                Node node;

                manager = result;
                managers.put(manager.getAttachment().getId(), manager);
                setState(DISPLAY);

                node = tree.getNodeAt(tree.getSelectedNode());
                if (ATTACHMENT_ITEM_LEAF.equals(node.getType()))
                    node = node.getParent();
                reloadAttachment(node);
                tree.selectNodeAt(node);
                nodeSelected(tree.getSelectedNode());
                setDone(Messages.get().gen_updateAborted());
            }

            public void failure(Throwable e) {
                Window.alert(e.getMessage());
                logger.log(Level.SEVERE, e.getMessage() != null ? e.getMessage() : "null", e);
                clearStatus();
            }
        };
    }

    /*
     * call for deleting attachments
     */
    if (deleteCall == null) {
        deleteCall = new AsyncCallbackUI<Void>() {
            public void success(Void result) {
                setState(DISPLAY);
                setDone(Messages.get().gen_deletingComplete());
            }

            public void validationErrors(ValidationErrorsList e) {
                showErrors(e);
            }

            public void failure(Throwable e) {
                Window.alert(e.getMessage());
                logger.log(Level.SEVERE, e.getMessage() != null ? e.getMessage() : "null", e);
                clearStatus();
            }
        };
    }
}

From source file:org.openelis.modules.attachment.client.IssuesTabUI.java

License:Open Source License

protected void initialize() {
    screen1 = this;
    ///*w w  w  .  j  ava 2s  .  co m*/
    // button panel buttons
    //
    addStateChangeHandler(new StateChangeEvent.Handler() {
        public void onStateChange(StateChangeEvent event) {
            updateButton.setEnabled(isState(UPDATE, DISPLAY));
            if (isState(UPDATE)) {
                updateButton.lock();
                updateButton.setPressed(true);
            }
        }
    });
    addShortcut(updateButton, 'u', CTRL);

    addStateChangeHandler(new StateChangeEvent.Handler() {
        public void onStateChange(StateChangeEvent event) {
            deleteButton.setEnabled(isState(DELETE, DISPLAY));
            if (isState(DELETE)) {
                deleteButton.lock();
                deleteButton.setPressed(true);
            }
        }
    });

    addShortcut(deleteButton, 'd', CTRL);

    addStateChangeHandler(new StateChangeEvent.Handler() {
        public void onStateChange(StateChangeEvent event) {
            commitButton.setEnabled(isState(UPDATE, DELETE));
        }
    });
    addShortcut(commitButton, 'm', CTRL);

    addStateChangeHandler(new StateChangeEvent.Handler() {
        public void onStateChange(StateChangeEvent event) {
            abortButton.setEnabled(isState(UPDATE, DELETE));
        }
    });
    addShortcut(abortButton, 'o', CTRL);

    addScreenHandler(table, "table", new ScreenHandler<ArrayList<Row>>() {
        public void onDataChange(DataChangeEvent event) {
            loadTable();
        }

        public void onStateChange(StateChangeEvent event) {
            table.setEnabled(true);
        }

        public Widget onTab(boolean forward) {
            return forward ? displayButton : refreshButton;
        }
    });

    table.addUnselectionHandler(new UnselectionHandler<Integer>() {
        public void onUnselection(UnselectionEvent<Integer> event) {
            /*
             * the selected row is not allowed to be unselected in Update or
             * Delete states because its manager is locked
             */
            if (isState(UPDATE, DELETE))
                event.cancel();
        }
    });

    table.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
        public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
            /*
             * no other row is allowed to be selected in Update or Delete
             * states because the selected row's manager is locked
             */
            if (isState(UPDATE, DELETE))
                event.cancel();
        }
    });

    table.addBeforeCellEditedHandler(new BeforeCellEditedHandler() {
        @Override
        public void onBeforeCellEdited(BeforeCellEditedEvent event) {
            if (event.getCol() != 2 || !isState(UPDATE))
                event.cancel();
        }
    });

    table.addCellEditedHandler(new CellEditedHandler() {
        @Override
        public void onCellUpdated(CellEditedEvent event) {
            int r, c;
            Object val;
            AttachmentIssueViewDO data;

            r = event.getRow();
            c = event.getCol();

            val = table.getValueAt(r, c);
            data = table.getRowAt(r).getData();

            switch (c) {
            case 2:
                data.setText((String) val);
                break;
            }
        }
    });

    addScreenHandler(displayButton, "displayButton", new ScreenHandler<ArrayList<Row>>() {
        public void onStateChange(StateChangeEvent event) {
            displayButton.setEnabled(isState(UPDATE, DISPLAY));
        }

        public Widget onTab(boolean forward) {
            return forward ? refreshButton : refreshButton;
        }
    });

    addScreenHandler(refreshButton, "refreshButton", new ScreenHandler<ArrayList<Row>>() {
        public void onStateChange(StateChangeEvent event) {
            refreshButton.setEnabled(isState(DEFAULT, DISPLAY));
        }

        public Widget onTab(boolean forward) {
            return forward ? table : displayButton;
        }
    });

    addVisibleHandler(new VisibleEvent.Handler() {
        public void onVisibleOrInvisible(VisibleEvent event) {
            if (event.isVisible() && autoLoadIssues) {
                issueList = null;
                issueMap = null;
                autoLoadIssues = false;
                fireAttachmentIssue(AttachmentIssueEvent.Action.FETCH, null);
            }
        }
    });

    parentBus.addHandler(AttachmentIssueEvent.getType(), new AttachmentIssueEvent.Handler() {
        @Override
        public void onAttachmentIssue(AttachmentIssueEvent event) {
            int r;
            Row row;
            AttachmentIssueViewDO data;

            if (parentScreen != event.getSource())
                return;

            /*
             * the tab fires events to the main screen to request it to do
             * various operations e.g. fetch, lock, unlock etc; that's
             * because the main screen maintains the data structures used by
             * all tabs; if the operation was successful, the main screen
             * fires an event to let the tab know; that event is handled
             * here; the tab can find out if this event was fired to respond
             * to a previous event fired by it or some other tab by checking
             * if it's the event's "originalSource"; it can then perform
             * some operation or ignore the event
             */
            r = table.getSelectedRow();
            row = null;
            if (r >= 0)
                row = table.getRowAt(r);

            issueList = event.getIssueList();
            issueMap = event.getIssueMap();
            data = null;
            switch (event.getAction()) {
            case FETCH:
            case ADD:
            case UPDATE:
            case DELETE:
                /*
                 * attachment issues were fetched, added etc; refresh
                 * the tab; find which attachment issue is selected in
                 * the table before reloading the table
                 */
                if (row != null)
                    data = row.getData();
                loadTable();
                refresh(data);
                break;
            case LOCK:
                if (screen1 == event.getOriginalSource()) {
                    /*
                     * an issue is locked to be updated or deleted;
                     * refresh the tab to show the latest data; set the
                     * state based on which operation is to be performed
                     */
                    if (lockForUpdate) {
                        setState(UPDATE);
                        data = issueMap.get(event.getAttachmentId());
                        row.setData(data);
                        table.setValueAt(r, 2, data.getText());
                        table.startEditing(r, 2);
                    } else if (lockForDelete) {
                        setState(DELETE);
                        table.removeRowAt(r);
                    }
                }
                break;
            case UNLOCK:
                if (screen1 == event.getOriginalSource()) {
                    /*
                     * an issue was unlocked;refresh the tab to show the
                     * previously deleted or changed issues again
                     */
                    if (removed != null)
                        removed = null;
                    data = issueMap.get(event.getAttachmentId());
                    loadTable();
                    refresh(data);
                    lockForUpdate = false;
                    lockForDelete = false;
                }
                break;
            }
        }
    });
}

From source file:org.openelis.modules.attachment.client.TRFTabUI.java

License:Open Source License

protected void initialize() {
    screen1 = this;

    ///*from  w  ww.  j  av  a 2s.c  o m*/
    // button panel buttons
    //
    addStateChangeHandler(new StateChangeEvent.Handler() {
        public void onStateChange(StateChangeEvent event) {
            queryButton.setEnabled(isState(QUERY, DEFAULT, DISPLAY));
            if (isState(QUERY)) {
                queryButton.lock();
                queryButton.setPressed(true);
            }
        }
    });
    addShortcut(queryButton, 'q', CTRL);

    addStateChangeHandler(new StateChangeEvent.Handler() {
        public void onStateChange(StateChangeEvent event) {
            updateButton.setEnabled(isState(UPDATE, DISPLAY));
            if (isState(UPDATE)) {
                updateButton.lock();
                updateButton.setPressed(true);
            }
        }
    });
    addShortcut(updateButton, 'u', CTRL);

    addStateChangeHandler(new StateChangeEvent.Handler() {
        public void onStateChange(StateChangeEvent event) {
            commitButton.setEnabled(isState(QUERY, UPDATE));
        }
    });
    addShortcut(commitButton, 'm', CTRL);

    addStateChangeHandler(new StateChangeEvent.Handler() {
        public void onStateChange(StateChangeEvent event) {
            abortButton.setEnabled(isState(QUERY, UPDATE));
        }
    });
    addShortcut(abortButton, 'o', CTRL);

    addScreenHandler(description, AttachmentMeta.getDescription(), new ScreenHandler<Object>() {
        public void onStateChange(StateChangeEvent event) {
            description.setEnabled(isState(QUERY));
        }

        public Widget onTab(boolean forward) {
            return forward ? unattached : unlockAllButton;
        }
    });

    addScreenHandler(unattached, "unattached", new ScreenHandler<Object>() {
        public void onStateChange(StateChangeEvent event) {
            unattached.setEnabled(isState(QUERY));
        }

        public Widget onTab(boolean forward) {
            return forward ? table : description;
        }
    });

    addScreenHandler(table, "table", new ScreenHandler<ArrayList<Row>>() {
        public void onDataChange(DataChangeEvent<ArrayList<Row>> event) {
            loadTable(null);
        }

        public void onStateChange(StateChangeEvent event) {
            table.setEnabled(true);
        }

        public Widget onTab(boolean forward) {
            return forward ? refreshButton : unattached;
        }
    });

    table.addUnselectionHandler(new UnselectionHandler<Integer>() {
        public void onUnselection(UnselectionEvent<Integer> event) {
            /*
             * the selected row is not allowed to be unselected in Update
             * state because its manager is locked
             */
            if (isState(UPDATE))
                event.cancel();
        }
    });

    table.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
        public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
            /*
             * no other row is allowed to be selected in Update state
             * because the selected row's manager is locked
             */
            if (isState(UPDATE))
                event.cancel();
        }
    });

    /*
     * screen fields and widgets
     */
    table.addBeforeCellEditedHandler(new BeforeCellEditedHandler() {
        @Override
        public void onBeforeCellEdited(BeforeCellEditedEvent event) {
            int r, c;
            Object val;

            r = event.getRow();
            c = event.getCol();

            if (c == 0) {
                val = table.getValueAt(r, c);
                if ((!isState(DISPLAY) || "Y".equals(val)) || !lock(r))
                    event.cancel();
                /*
                 * if this row got selected by clicking in the first column
                 * (the checkbox) instead of some other one, select the row
                 * whose TRF was shown the most recently, if any, otherwise
                 * unselect this row; the TRF is not shown if the first
                 * column is clicked, so if this row stayed selected, the
                 * user may assume that the TRF was shown and may not click
                 * in some other column to see it
                 */
                if (trfShownRow != r) {
                    if (trfShownRow >= 0)
                        table.selectRowAt(trfShownRow);
                    else
                        table.unselectRowAt(r);
                }
                return;
            }

            /*
             * this makes sure that the attachment for a row is not shown
             * more than once if different cells of the row are clicked one
             * after the other; displayAttachment is called from here
             * instead of from SelectionHandler because the TRF is not shown
             * if the user clicks in the first column (the checkbox) and the
             * column can't be known in SelectionHandler
             */
            if (trfShownRow != r) {
                displayAttachment(table.getRowAt(r));
                trfShownRow = r;
            }

            if (c != 3 || !isState(UPDATE))
                event.cancel();
        }
    });

    table.addCellEditedHandler(new CellEditedHandler() {
        @Override
        public void onCellUpdated(CellEditedEvent event) {
            int r, c;
            Integer id;
            String val;
            AttachmentIssueViewDO ai;
            AttachmentDO a;
            AttachmentManager am;

            r = event.getRow();
            c = event.getCol();

            val = (String) table.getValueAt(r, c);
            id = table.getRowAt(r).getData();
            am = managerMap.get(id);
            ai = issueMap.get(id);

            switch (c) {
            case 3:
                if (ai == null) {
                    /*
                     * if there's no attachment issue for this row's
                     * attachment and the user entered some text, create
                     * a new issue
                     */
                    if (!DataBaseUtil.isEmpty(val)) {
                        ai = new AttachmentIssueViewDO();
                        a = am.getAttachment();
                        ai.setAttachmentId(a.getId());
                        ai.setAttachmentDescription(a.getDescription());
                        ai.setText(val);
                        issueMap.put(id, ai);
                        table.getRowAt(r).setData(a.getId());
                    }
                } else {
                    ai.setText(val);
                }
                break;
            }
        }
    });

    addScreenHandler(refreshButton, "refreshButton", new ScreenHandler<ArrayList<Row>>() {
        public void onStateChange(StateChangeEvent event) {
            refreshButton.setEnabled(isState(DEFAULT, DISPLAY));
        }

        public Widget onTab(boolean forward) {
            return forward ? unlockAllButton : table;
        }
    });

    addScreenHandler(unlockAllButton, "unlockAllButton", new ScreenHandler<ArrayList<Row>>() {
        public void onStateChange(StateChangeEvent event) {
            unlockAllButton.setEnabled(isState(DISPLAY));
        }

        public Widget onTab(boolean forward) {
            return forward ? description : refreshButton;
        }
    });

    parentBus.addHandler(AttachmentIssueEvent.getType(), new AttachmentIssueEvent.Handler() {
        @Override
        public void onAttachmentIssue(AttachmentIssueEvent event) {
            Query q;

            if (parentScreen != event.getSource())
                return;

            /*
             * the tab fires events to the main screen to request it to do
             * various operations e.g. fetch, lock, unlock etc; that's
             * because the main screen maintains the data structures used by
             * all tabs; if the operation was successful, the main screen
             * fires an event to let the tab know; that event is handled
             * here; the tab can find out if this event was fired to respond
             * to a previous event fired by it or some other tab by checking
             * if it's the event's "originalSource"; it can then perform
             * some operation or ignore the event
             */
            issueMap = event.getIssueMap();
            switch (event.getAction()) {
            case FETCH:
                if (screen1 == event.getOriginalSource()) {
                    if (query) {
                        /*
                         * the user wants to query; set the screen in
                         * Query state
                         */
                        query = false;
                        description.setFocus(true);
                        setState(QUERY);
                        parentScreen.setDone(Messages.get().gen_enterFieldsToQuery());
                    } else if (refresh) {
                        /*
                         * the user wants to refresh the list of
                         * attachments; fetch unattached attachments for
                         * the default pattern
                         */
                        refresh = false;
                        description.setValue(getPattern());
                        unattached.setValue("Y");

                        managerMap = null;

                        q = new Query();
                        q.setFields(getQueryFields());
                        q.setRowsPerPage(MAX_ATTACHMENTS);

                        executeQuery(q);
                    }
                } else {
                    /*
                     * refresh the issues in the table because they were
                     * fetched from the database by some other tab
                     */
                    query = false;
                    refresh = false;
                    refreshIssues();
                }
                break;
            case ADD:
            case UPDATE:
            case DELETE:
                /*
                 * refresh the issues in the table because some were
                 * added, updated or deleted
                 */
                refreshIssues();
                setState(DISPLAY);
                break;
            case LOCK:
                if (screen1 == event.getOriginalSource()) {
                    /*
                     * an issue is locked to be updated; refresh the tab
                     * to show the latest data
                     */
                    refreshSelectedRow();
                    setState(UPDATE);
                    table.startEditing(table.getSelectedRow(), 3);
                }
                break;
            case UNLOCK:
                if (screen1 == event.getOriginalSource()) {
                    /*
                     * an issue was unlocked; refresh the tab to show
                     * the previously deleted or changed issues again
                     */
                    refreshIssues();
                    setState(DISPLAY);
                }
                break;
            }
        }

    });
}

From source file:org.openelis.modules.inventoryItem.client.InventoryItemScreen.java

License:Open Source License

/**
 * Setup state and data change handles for every widget on the screen
 *///from   w  w w .j a v a  2 s .  c o m
@SuppressWarnings("unchecked")
private void initialize() {
    queryButton = (AppButton) def.getWidget("query");
    addScreenHandler(queryButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            query();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            queryButton.enable(EnumSet.of(State.DEFAULT, State.DISPLAY).contains(event.getState())
                    && userPermission.hasSelectPermission());
            if (event.getState() == State.QUERY)
                queryButton.setState(ButtonState.LOCK_PRESSED);
        }
    });

    previousButton = (AppButton) def.getWidget("previous");
    addScreenHandler(previousButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            previous();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            previousButton.enable(EnumSet.of(State.DISPLAY).contains(event.getState()));
        }
    });

    nextButton = (AppButton) def.getWidget("next");
    addScreenHandler(nextButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            next();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            nextButton.enable(EnumSet.of(State.DISPLAY).contains(event.getState()));
        }
    });

    addButton = (AppButton) def.getWidget("add");
    addScreenHandler(addButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            add();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            addButton.enable(EnumSet.of(State.DEFAULT, State.DISPLAY).contains(event.getState())
                    && userPermission.hasAddPermission());
            if (event.getState() == State.ADD)
                addButton.setState(ButtonState.LOCK_PRESSED);
        }
    });

    updateButton = (AppButton) def.getWidget("update");
    addScreenHandler(updateButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            update();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            updateButton.enable(EnumSet.of(State.DISPLAY).contains(event.getState())
                    && userPermission.hasUpdatePermission());
            if (event.getState() == State.UPDATE)
                updateButton.setState(ButtonState.LOCK_PRESSED);
        }
    });

    commitButton = (AppButton) def.getWidget("commit");
    addScreenHandler(commitButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            commit();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            commitButton.enable(
                    EnumSet.of(State.QUERY, State.ADD, State.UPDATE, State.DELETE).contains(event.getState()));
        }
    });

    abortButton = (AppButton) def.getWidget("abort");
    addScreenHandler(abortButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            abort();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            abortButton.enable(
                    EnumSet.of(State.QUERY, State.ADD, State.UPDATE, State.DELETE).contains(event.getState()));
        }
    });

    duplicate = (MenuItem) def.getWidget("duplicateRecord");
    addScreenHandler(duplicate, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            duplicate();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            duplicate.enable(
                    EnumSet.of(State.DISPLAY).contains(event.getState()) && userPermission.hasAddPermission());
        }
    });

    invItemHistory = (MenuItem) def.getWidget("invItemHistory");
    addScreenHandler(invItemHistory, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            invItemHistory();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            invItemHistory.enable(EnumSet.of(State.DISPLAY).contains(event.getState()));
        }
    });

    invComponentHistory = (MenuItem) def.getWidget("invComponentHistory");
    addScreenHandler(invComponentHistory, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            invComponentHistory();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            invComponentHistory.enable(EnumSet.of(State.DISPLAY).contains(event.getState()));
        }
    });

    invLocationHistory = (MenuItem) def.getWidget("invLocationHistory");
    addScreenHandler(invLocationHistory, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            invLocationHistory();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            invLocationHistory.enable(EnumSet.of(State.DISPLAY).contains(event.getState()));
        }
    });

    id = (TextBox<Integer>) def.getWidget(InventoryItemMeta.getId());
    addScreenHandler(id, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            id.setFieldValue(manager.getInventoryItem().getId());
        }

        public void onValueChange(ValueChangeEvent<Integer> event) {
            manager.getInventoryItem().setId(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            id.enable(event.getState() == State.QUERY);
            id.setQueryMode(event.getState() == State.QUERY);
        }
    });

    name = (TextBox) def.getWidget(InventoryItemMeta.getName());
    addScreenHandler(name, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            name.setValue(manager.getInventoryItem().getName());
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            manager.getInventoryItem().setName(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            name.enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            name.setQueryMode(event.getState() == State.QUERY);
        }
    });

    description = (TextBox) def.getWidget(InventoryItemMeta.getDescription());
    addScreenHandler(description, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            description.setValue(manager.getInventoryItem().getDescription());
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            manager.getInventoryItem().setDescription(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            description.enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            description.setQueryMode(event.getState() == State.QUERY);
        }
    });

    categoryId = (Dropdown) def.getWidget(InventoryItemMeta.getCategoryId());
    addScreenHandler(categoryId, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            categoryId.setSelection(manager.getInventoryItem().getCategoryId());
        }

        public void onValueChange(ValueChangeEvent<Integer> event) {
            manager.getInventoryItem().setCategoryId(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            categoryId.enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            categoryId.setQueryMode(event.getState() == State.QUERY);
        }
    });

    storeId = (Dropdown) def.getWidget(InventoryItemMeta.getStoreId());
    addScreenHandler(storeId, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            storeId.setSelection(manager.getInventoryItem().getStoreId());
        }

        public void onValueChange(ValueChangeEvent<Integer> event) {
            manager.getInventoryItem().setStoreId(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            storeId.enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            storeId.setQueryMode(event.getState() == State.QUERY);
        }
    });

    quantityMinLevel = (TextBox<Integer>) def.getWidget(InventoryItemMeta.getQuantityMinLevel());
    addScreenHandler(quantityMinLevel, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            quantityMinLevel.setFieldValue(manager.getInventoryItem().getQuantityMinLevel());
        }

        public void onValueChange(ValueChangeEvent<Integer> event) {
            manager.getInventoryItem().setQuantityMinLevel(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            quantityMinLevel
                    .enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            quantityMinLevel.setQueryMode(event.getState() == State.QUERY);
        }
    });

    quantityToReorder = (TextBox<Integer>) def.getWidget(InventoryItemMeta.getQuantityToReorder());
    addScreenHandler(quantityToReorder, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            quantityToReorder.setFieldValue(manager.getInventoryItem().getQuantityToReorder());
        }

        public void onValueChange(ValueChangeEvent<Integer> event) {
            manager.getInventoryItem().setQuantityToReorder(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            quantityToReorder
                    .enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            quantityToReorder.setQueryMode(event.getState() == State.QUERY);
        }
    });

    quantityMaxLevel = (TextBox<Integer>) def.getWidget(InventoryItemMeta.getQuantityMaxLevel());
    addScreenHandler(quantityMaxLevel, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            quantityMaxLevel.setFieldValue(manager.getInventoryItem().getQuantityMaxLevel());
        }

        public void onValueChange(ValueChangeEvent<Integer> event) {
            manager.getInventoryItem().setQuantityMaxLevel(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            quantityMaxLevel
                    .enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            quantityMaxLevel.setQueryMode(event.getState() == State.QUERY);
        }
    });

    dispensedUnitsId = (Dropdown) def.getWidget(InventoryItemMeta.getDispensedUnitsId());
    addScreenHandler(dispensedUnitsId, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            dispensedUnitsId.setSelection(manager.getInventoryItem().getDispensedUnitsId());
        }

        public void onValueChange(ValueChangeEvent<Integer> event) {
            manager.getInventoryItem().setDispensedUnitsId(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            dispensedUnitsId
                    .enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            dispensedUnitsId.setQueryMode(event.getState() == State.QUERY);
        }
    });

    isActive = (CheckBox) def.getWidget(InventoryItemMeta.getIsActive());
    addScreenHandler(isActive, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            isActive.setValue(manager.getInventoryItem().getIsActive());
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            manager.getInventoryItem().setIsActive(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            isActive.enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            isActive.setQueryMode(event.getState() == State.QUERY);
        }
    });

    isReorderAuto = (CheckBox) def.getWidget(InventoryItemMeta.getIsReorderAuto());
    addScreenHandler(isReorderAuto, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            isReorderAuto.setValue(manager.getInventoryItem().getIsReorderAuto());
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            manager.getInventoryItem().setIsReorderAuto(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            isReorderAuto.enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            isReorderAuto.setQueryMode(event.getState() == State.QUERY);
        }
    });

    isLotMaintained = (CheckBox) def.getWidget(InventoryItemMeta.getIsLotMaintained());
    addScreenHandler(isLotMaintained, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            isLotMaintained.setValue(manager.getInventoryItem().getIsLotMaintained());
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            manager.getInventoryItem().setIsLotMaintained(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            isLotMaintained.enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            isLotMaintained.setQueryMode(event.getState() == State.QUERY);
        }
    });

    isSerialMaintained = (CheckBox) def.getWidget(InventoryItemMeta.getIsSerialMaintained());
    addScreenHandler(isSerialMaintained, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            isSerialMaintained.setValue(manager.getInventoryItem().getIsSerialMaintained());
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            manager.getInventoryItem().setIsSerialMaintained(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            isSerialMaintained
                    .enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            isSerialMaintained.setQueryMode(event.getState() == State.QUERY);
        }
    });

    isBulk = (CheckBox) def.getWidget(InventoryItemMeta.getIsBulk());
    addScreenHandler(isBulk, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            isBulk.setValue(manager.getInventoryItem().getIsBulk());
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            manager.getInventoryItem().setIsBulk(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            isBulk.enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            isBulk.setQueryMode(event.getState() == State.QUERY);
        }
    });

    isNotForSale = (CheckBox) def.getWidget(InventoryItemMeta.getIsNotForSale());
    addScreenHandler(isNotForSale, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            isNotForSale.setValue(manager.getInventoryItem().getIsNotForSale());
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            manager.getInventoryItem().setIsNotForSale(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            isNotForSale.enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            isNotForSale.setQueryMode(event.getState() == State.QUERY);
        }
    });

    isSubAssembly = (CheckBox) def.getWidget(InventoryItemMeta.getIsSubAssembly());
    addScreenHandler(isSubAssembly, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            isSubAssembly.setValue(manager.getInventoryItem().getIsSubAssembly());
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            manager.getInventoryItem().setIsSubAssembly(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            isSubAssembly.enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            isSubAssembly.setQueryMode(event.getState() == State.QUERY);
        }
    });

    isLabor = (CheckBox) def.getWidget(InventoryItemMeta.getIsLabor());
    addScreenHandler(isLabor, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            isLabor.setValue(manager.getInventoryItem().getIsLabor());
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            manager.getInventoryItem().setIsLabor(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            isLabor.enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            isLabor.setQueryMode(event.getState() == State.QUERY);
        }
    });

    isNotInventoried = (CheckBox) def.getWidget(InventoryItemMeta.getIsNotInventoried());
    addScreenHandler(isNotInventoried, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            isNotInventoried.setValue(manager.getInventoryItem().getIsNotInventoried());
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            manager.getInventoryItem().setIsNotInventoried(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            isNotInventoried
                    .enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            isNotInventoried.setQueryMode(event.getState() == State.QUERY);
        }
    });

    productUri = (TextBox) def.getWidget(InventoryItemMeta.getProductUri());
    addScreenHandler(productUri, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            productUri.setValue(manager.getInventoryItem().getProductUri());
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            manager.getInventoryItem().setProductUri(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            productUri.enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            productUri.setQueryMode(event.getState() == State.QUERY);
        }
    });

    parentInventoryItemId = (AutoComplete) def.getWidget(InventoryItemMeta.getParentInventoryItemName());
    addScreenHandler(parentInventoryItemId, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            parentInventoryItemId.setSelection(manager.getInventoryItem().getParentInventoryItemId(),
                    manager.getInventoryItem().getParentInventoryItemName());
        }

        public void onValueChange(ValueChangeEvent<Integer> event) {
            manager.getInventoryItem().setParentInventoryItemId(event.getValue());
            manager.getInventoryItem().setParentInventoryItemName(parentInventoryItemId.getTextBoxDisplay());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            parentInventoryItemId
                    .enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            parentInventoryItemId.setQueryMode(event.getState() == State.QUERY);
        }
    });

    parentInventoryItemId.addGetMatchesHandler(new GetMatchesHandler() {
        public void onGetMatches(GetMatchesEvent event) {
            InventoryItemDO data;
            TableDataRow row;
            ArrayList<InventoryItemDO> list;
            ArrayList<TableDataRow> model;
            DictionaryDO store, units;

            try {
                list = InventoryItemService.get().fetchActiveByName(event.getMatch());
                model = new ArrayList<TableDataRow>();

                for (int i = 0; i < list.size(); i++) {
                    data = (InventoryItemDO) list.get(i);
                    store = DictionaryCache.getById(data.getStoreId());
                    units = DictionaryCache.getById(data.getDispensedUnitsId());
                    row = new TableDataRow(data.getId(), data.getName(), store.getEntry(), units.getEntry());
                    row.data = data;
                    model.add(row);
                }
                parentInventoryItemId.showAutoMatches(model);
            } catch (Exception e) {
                Window.alert(e.getMessage());
            }
        }
    });

    parentRatio = (TextBox<Integer>) def.getWidget(InventoryItemMeta.getParentRatio());
    addScreenHandler(parentRatio, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            parentRatio.setFieldValue(manager.getInventoryItem().getParentRatio());
        }

        public void onValueChange(ValueChangeEvent<Integer> event) {
            manager.getInventoryItem().setParentRatio(event.getValue());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            parentRatio.enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
            parentRatio.setQueryMode(event.getState() == State.QUERY);
        }
    });

    averageLeadTime = (TextBox<Integer>) def.getWidget(InventoryItemMeta.getAverageLeadTime());
    addScreenHandler(averageLeadTime, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            averageLeadTime.setFieldValue(manager.getInventoryItem().getAverageLeadTime());
        }

        public void onValueChange(ValueChangeEvent<Integer> event) {
        }

        public void onStateChange(StateChangeEvent<State> event) {
            averageLeadTime.enable(false);
        }
    });

    averageCost = (TextBox) def.getWidget(InventoryItemMeta.getAverageCost());
    addScreenHandler(averageCost, new ScreenEventHandler<Double>() {
        public void onDataChange(DataChangeEvent event) {
            averageCost.setFieldValue(manager.getInventoryItem().getAverageCost());
        }

        public void onValueChange(ValueChangeEvent<Double> event) {
        }

        public void onStateChange(StateChangeEvent<State> event) {
            averageCost.enable(false);
        }
    });

    averageDailyUse = (TextBox<Integer>) def.getWidget(InventoryItemMeta.getAverageDailyUse());
    addScreenHandler(averageDailyUse, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            averageDailyUse.setFieldValue(manager.getInventoryItem().getAverageDailyUse());
        }

        public void onValueChange(ValueChangeEvent<Integer> event) {
        }

        public void onStateChange(StateChangeEvent<State> event) {
            averageDailyUse.enable(false);
        }
    });

    //
    // tabs
    //
    tabPanel = (TabPanel) def.getWidget("tabPanel");
    tabPanel.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
        public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
            int i;

            // tab screen order should be the same as enum or this will
            // not work
            i = event.getItem().intValue();
            tab = Tabs.values()[i];

            window.setBusy();
            drawTabs();
            window.clearStatus();
        }
    });

    componentTab = new ComponentTab(def, window);
    addScreenHandler(componentTab, new ScreenEventHandler<Object>() {
        public void onDataChange(DataChangeEvent event) {
            componentTab.setManager(manager);
            if (tab == Tabs.COMPONENT)
                drawTabs();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            componentTab.setState(event.getState());
        }
    });

    locationTab = new LocationTab(def, window);
    addScreenHandler(locationTab, new ScreenEventHandler<Object>() {
        public void onDataChange(DataChangeEvent event) {
            locationTab.setManager(manager);
            if (tab == Tabs.LOCATION)
                drawTabs();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            locationTab.setState(event.getState());
        }
    });

    manufacturingTab = new ManufacturingTab(def, window, "manufacturingPanel", "editManufacturingButton");
    addScreenHandler(manufacturingTab, new ScreenEventHandler<Object>() {
        public void onDataChange(DataChangeEvent event) {
            manufacturingTab.setManager(manager);
            if (tab == Tabs.MANUFACTURING)
                drawTabs();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            manufacturingTab.setState(event.getState());
        }
    });

    noteTab = new NotesTab(def, window, "notesPanel", "standardNoteButton");
    addScreenHandler(noteTab, new ScreenEventHandler<Object>() {
        public void onDataChange(DataChangeEvent event) {
            noteTab.setManager(manager);
            if (tab == Tabs.NOTE)
                drawTabs();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            noteTab.setState(event.getState());
        }
    });

    //
    // left hand navigation panel
    //
    nav = new ScreenNavigator<IdNameStoreVO>(def) {
        public void executeQuery(final Query query) {
            window.setBusy(Messages.get().querying());

            query.setRowsPerPage(23);
            InventoryItemService.get().query(query, new AsyncCallback<ArrayList<IdNameStoreVO>>() {
                public void onSuccess(ArrayList<IdNameStoreVO> result) {
                    setQueryResult(result);
                }

                public void onFailure(Throwable error) {
                    setQueryResult(null);
                    if (error instanceof NotFoundException) {
                        window.setDone(Messages.get().noRecordsFound());
                        setState(State.DEFAULT);
                    } else if (error instanceof LastPageException) {
                        window.setError("No more records in this direction");
                    } else {
                        Window.alert("Error: InventoryItem call query failed; " + error.getMessage());
                        window.setError(Messages.get().queryFailed());
                    }
                }
            });
        }

        public boolean fetch(IdNameStoreVO entry) {
            return fetchById((entry == null) ? null : ((IdNameStoreVO) entry).getId());
        }

        public ArrayList<TableDataRow> getModel() {
            ArrayList<IdNameStoreVO> result;
            ArrayList<TableDataRow> model;

            model = null;
            result = nav.getQueryResult();
            if (result != null) {
                model = new ArrayList<TableDataRow>();
                for (IdNameStoreVO entry : result)
                    model.add(new TableDataRow(entry.getId(), entry.getName(), entry.getStore()));
            }
            return model;
        }
    };

    atoz = (ButtonGroup) def.getWidget("atozButtons");
    addScreenHandler(atoz, new ScreenEventHandler<Object>() {
        public void onStateChange(StateChangeEvent<State> event) {
            boolean enable;
            enable = EnumSet.of(State.DEFAULT, State.DISPLAY).contains(event.getState())
                    && userPermission.hasSelectPermission();
            atoz.enable(enable);
            nav.enable(enable);
        }

        public void onClick(ClickEvent event) {
            Query query;
            QueryData field;

            field = new QueryData();
            field.setKey(InventoryItemMeta.getName());
            field.setQuery(((AppButton) event.getSource()).getAction());
            field.setType(QueryData.Type.STRING);

            query = new Query();
            query.setFields(field);
            nav.setQuery(query);
        }
    });

    window.addBeforeClosedHandler(new BeforeCloseHandler<WindowInt>() {
        public void onBeforeClosed(BeforeCloseEvent<WindowInt> event) {
            if (EnumSet.of(State.ADD, State.UPDATE).contains(state)) {
                event.cancel();
                window.setError(Messages.get().mustCommitOrAbort());
            }
        }
    });
}

From source file:org.openelis.modules.inventoryReceipt.client.InventoryReceiptScreen.java

License:Open Source License

private void initialize() {
    ///*from   w  w w  . j  av a 2  s .c  om*/
    // button panel buttons
    //
    queryButton = (AppButton) def.getWidget("query");
    addScreenHandler(queryButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            query();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            queryButton.enable(EnumSet.of(State.DEFAULT, State.DISPLAY).contains(event.getState())
                    && userPermission.hasSelectPermission());
            if (event.getState() == State.QUERY)
                queryButton.setState(ButtonState.LOCK_PRESSED);
        }
    });

    addButton = (AppButton) def.getWidget("add");
    addScreenHandler(addButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            add();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            addButton.enable(EnumSet.of(State.DEFAULT, State.DISPLAY).contains(event.getState())
                    && userPermission.hasAddPermission());
            if (event.getState() == State.ADD)
                addButton.setState(ButtonState.LOCK_PRESSED);
        }
    });

    updateButton = (AppButton) def.getWidget("update");
    addScreenHandler(updateButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            update();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            updateButton.enable(EnumSet.of(State.DISPLAY).contains(event.getState())
                    && userPermission.hasUpdatePermission());
            if (event.getState() == State.UPDATE)
                updateButton.setState(ButtonState.LOCK_PRESSED);
        }
    });

    commitButton = (AppButton) def.getWidget("commit");
    addScreenHandler(commitButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            commit();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            commitButton.enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
        }
    });

    abortButton = (AppButton) def.getWidget("abort");
    addScreenHandler(abortButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            abort();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            abortButton.enable(EnumSet.of(State.QUERY, State.ADD, State.UPDATE).contains(event.getState()));
        }
    });

    receiptTable = (TableWidget) def.getWidget("receiptTable");
    addScreenHandler(receiptTable, new ScreenEventHandler<ArrayList<TableDataRow>>() {
        public void onDataChange(DataChangeEvent event) {
            if (state != State.QUERY)
                receiptTable.load(receiptModel);
        }

        public void onStateChange(StateChangeEvent<State> event) {
            receiptTable.enable(true);
            receiptTable.setQueryMode(event.getState() == State.QUERY);
            upcQuery = null;
        }
    });

    receiptTable.addBeforeSelectionHandler(new BeforeSelectionHandler<TableRow>() {
        public void onBeforeSelection(BeforeSelectionEvent<TableRow> event) {
            //
            // this is done here in order to make sure that whenever a row 
            // is selected if some data for the previous row got changed
            // in one of the tabs then the last widget being edited in the 
            // tab will lose focus and ValueChangeEvent will be fired for it, 
            // so that the inventory receipt record associated with the 
            // previous row will get updated before the tabs get filled with
            // any new data that belongs to the current row
            // 
            if (state == State.ADD || state == State.UPDATE)
                ((Focusable) def.getPanel().focused).setFocus(false);
        }
    });

    receiptTable.addSelectionHandler(new SelectionHandler<TableRow>() {
        public void onSelection(SelectionEvent<TableRow> event) {
            int index;
            InventoryReceiptManager man;
            InventoryReceiptDataBundle bundle;
            IOrderManager order;
            TableDataRow row;

            row = receiptTable.getSelection();
            bundle = (InventoryReceiptDataBundle) row.data;
            man = bundle.getManager();
            index = bundle.getManagerIndex();

            itemTab.setManager(man, index, screen);
            vendorTab.setManager(man, index);

            try {
                order = man.getIorder();
                if (state == State.ADD || state == State.UPDATE) {
                    if (order != null)
                        shipNoteTab.setState(state);
                    else
                        shipNoteTab.setState(State.DISPLAY);
                } else {
                    shipNoteTab.setState(State.DISPLAY);
                }
                shipNoteTab.setManager(order);
            } catch (Exception ex) {
                ex.printStackTrace();
                Window.alert(ex.getMessage());
            }
            itemTab.setState(state);
            drawTabs();
        }
    });

    receiptTable.addBeforeCellEditedHandler(new BeforeCellEditedHandler() {
        public void onBeforeCellEdited(BeforeCellEditedEvent event) {
            int c;

            c = event.getCol();

            if (state == State.UPDATE) {
                if (c != 2 && c != 7 && c != 8)
                    event.cancel();
            } else if (state == State.ADD) {
                if (c == 0 || c == 1 || c == 6)
                    event.cancel();
            } else {
                event.cancel();
            }
        }
    });

    receiptTable.addCellEditedHandler(new CellEditedHandler() {
        public void onCellUpdated(CellEditedEvent event) {
            int r, c;
            Object val;
            TableDataRow tableRow, valRow, tmpRow;
            Integer numRec, index;
            InventoryReceiptViewDO data;
            InventoryReceiptManager man;
            InventoryReceiptDataBundle bundle;
            InventoryItemDO item;
            OrganizationDO org;
            IdNameVO upcData;
            Datetime dateRec;
            Exception ex;
            ArrayList<Exception> exceptions;

            r = event.getRow();
            c = event.getCol();
            tableRow = receiptTable.getRow(r);
            val = receiptTable.getObject(r, c);

            bundle = (InventoryReceiptDataBundle) tableRow.data;
            index = bundle.getManagerIndex();
            man = bundle.getManager();
            data = man.getReceiptAt(index);
            item = null;

            switch (c) {
            case 2:
                data.setReceivedDate((Datetime) val);
                break;
            case 3:
                valRow = (TableDataRow) val;
                if (valRow != null) {
                    upcData = (IdNameVO) valRow.data;
                    data.setUpc(upcData.getName());
                    if (!upcData.getId().equals(-1)) {
                        tmpRow = new TableDataRow(upcData.getId(), upcData.getDescription());
                        try {
                            item = InventoryItemCache.getById(upcData.getId());
                        } catch (Exception e) {
                            Window.alert("Inventory Item Cache error:" + e.getMessage());
                            e.printStackTrace();
                        }
                        tmpRow.data = item;
                        exceptions = tableRow.cells.get(4).getExceptions();
                        if (exceptions != null) {
                            for (int i = 0; i < exceptions.size(); i++) {
                                ex = exceptions.get(i);
                                if (Messages.get().fieldRequiredException().equals(ex.getMessage())) {
                                    exceptions.remove(i);
                                    break;
                                }
                            }

                            if (exceptions.size() == 0)
                                tableRow.cells.get(4).clearExceptions();
                        }
                        receiptTable.setCell(r, 4, tmpRow);
                        data.setInventoryItemId(upcData.getId());
                        itemTab.setManager(man, index, screen);
                        drawTabs();
                    }
                } else {
                    data.setUpc(null);
                }
                break;
            case 4:
                valRow = (TableDataRow) val;
                if (valRow != null) {
                    item = (InventoryItemDO) valRow.data;
                    data.setInventoryItemId(item.getId());
                } else {
                    data.setInventoryItemId(null);
                }
                itemTab.setManager(man, index, screen);
                drawTabs();
                break;
            case 5:
                valRow = (TableDataRow) val;
                if (valRow != null) {
                    org = (OrganizationDO) valRow.data;
                    data.setOrganizationId(org.getId());
                    data.setOrganization(org);
                } else {
                    data.setOrganizationId(null);
                    data.setOrganization(null);
                }
                vendorTab.setManager(man, index);
                drawTabs();
                break;
            case 7:
                numRec = (Integer) val;
                data.setQuantityReceived(numRec);
                if (numRec != null && numRec > 0) {
                    dateRec = data.getReceivedDate();
                    if (dateRec == null) {
                        try {
                            dateRec = CalendarService.get().getCurrentDatetime(Datetime.YEAR, Datetime.DAY);
                        } catch (Exception e) {
                            Window.alert("Inventory Receipt Datetime: " + e.getMessage());
                            return;
                        }
                        data.setReceivedDate(dateRec);
                        //
                        // this will get rid of any exceptions that were
                        // added to the column showing date recieved
                        // because of wrong formatting or a value not 
                        // being present
                        //
                        tableRow.cells.get(2).clearExceptions();
                        receiptTable.setCell(r, 2, dateRec);
                    }

                    if (data.getUnitCost() == null) {
                        data.setUnitCost(data.getIorderItemUnitCost());
                        receiptTable.setCell(r, 8, data.getUnitCost());
                    }
                }
                break;
            case 8:
                data.setUnitCost((Double) val);
                break;
            }
        }
    });

    receiptTable.addRowAddedHandler(new RowAddedHandler() {
        public void onRowAdded(RowAddedEvent event) {
            TableDataRow row;
            InventoryReceiptDataBundle bundle;
            InventoryReceiptManager manager;

            row = event.getRow();
            manager = InventoryReceiptManager.getInstance();
            manager.addReceipt(new InventoryReceiptViewDO());
            bundle = new InventoryReceiptDataBundle(0, null, manager);
            row.data = bundle;
        }
    });

    dateRecColumn = receiptTable.getColumns().get(2);
    upcColumn = receiptTable.getColumns().get(3);
    itemColumn = receiptTable.getColumns().get(4);
    orgColumn = receiptTable.getColumns().get(5);
    numRecColumn = receiptTable.getColumns().get(7);
    costColumn = receiptTable.getColumns().get(8);

    upc = (AutoComplete<Integer>) receiptTable.getColumnWidget(InventoryReceiptMeta.getUpc());
    upc.addGetMatchesHandler(new GetMatchesHandler() {
        public void onGetMatches(GetMatchesEvent event) {
            TableDataRow row;
            ArrayList<TableDataRow> model;
            IdNameVO data;
            ArrayList<IdNameVO> list;
            String match;

            list = null;
            match = event.getMatch();
            window.setBusy();

            try {
                model = new ArrayList<TableDataRow>();

                row = new TableDataRow(-1, match);
                row.data = new IdNameVO(-1, match, null);
                model.add(row);

                if (upcQuery == null || (!(match.indexOf(upcQuery) == 0))) {
                    list = InventoryReceiptService.get()
                            .fetchByUpc(QueryFieldUtil.parseAutocomplete(event.getMatch()));
                    for (int i = 0; i < list.size(); i++) {
                        data = list.get(i);
                        row = new TableDataRow(data.getId(), data.getName(), data.getDescription());
                        row.data = data;
                        model.add(row);
                    }

                    if (list.size() == 0)
                        upcQuery = match;
                }

                upc.showAutoMatches(model);
            } catch (Throwable e) {
                e.printStackTrace();
                Window.alert(e.getMessage());
            }
            window.clearStatus();
        }
    });

    inventoryItem = (AutoComplete<Integer>) receiptTable
            .getColumnWidget(InventoryReceiptMeta.getInventoryItemName());
    inventoryItem.addGetMatchesHandler(new GetMatchesHandler() {
        public void onGetMatches(GetMatchesEvent event) {
            InventoryItemDO data;
            TableDataRow row;
            ArrayList<InventoryItemDO> list;
            ArrayList<TableDataRow> model;
            DictionaryDO store, units;

            try {
                list = InventoryItemService.get().fetchActiveByName(event.getMatch());
                model = new ArrayList<TableDataRow>();

                for (int i = 0; i < list.size(); i++) {
                    data = (InventoryItemDO) list.get(i);
                    store = DictionaryCache.getById(data.getStoreId());
                    units = DictionaryCache.getById(data.getDispensedUnitsId());
                    row = new TableDataRow(data.getId(), data.getName(), store.getEntry(), units.getEntry());
                    row.data = data;
                    model.add(row);
                }
                inventoryItem.showAutoMatches(model);
            } catch (Exception e) {
                Window.alert(e.getMessage());
            }
        }
    });

    organization = (AutoComplete<Integer>) receiptTable
            .getColumnWidget(InventoryReceiptMeta.getOrganizationName());
    organization.addGetMatchesHandler(new GetMatchesHandler() {
        public void onGetMatches(GetMatchesEvent event) {
            TableDataRow row;
            OrganizationDO data;
            ArrayList<OrganizationDO> list;
            ArrayList<TableDataRow> model;

            window.setBusy();
            try {
                list = OrganizationService1Impl.INSTANCE
                        .fetchByIdOrName(QueryFieldUtil.parseAutocomplete(event.getMatch()));
                model = new ArrayList<TableDataRow>();
                for (int i = 0; i < list.size(); i++) {
                    row = new TableDataRow(4);
                    data = list.get(i);

                    row.key = data.getId();
                    row.cells.get(0).value = data.getName();
                    row.cells.get(1).value = data.getAddress().getStreetAddress();
                    row.cells.get(2).value = data.getAddress().getCity();
                    row.cells.get(3).value = data.getAddress().getState();

                    row.data = data;

                    model.add(row);
                }
                organization.showAutoMatches(model);
            } catch (Throwable e) {
                e.printStackTrace();
                Window.alert(e.getMessage());
            }
            window.clearStatus();
        }
    });

    addReceiptButton = (AppButton) def.getWidget("addReceiptButton");
    addScreenHandler(addReceiptButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            int n;
            IOrderManager order;

            order = null;
            receiptTable.addRow();
            n = receiptTable.numRows() - 1;
            receiptTable.selectRow(n);
            receiptTable.scrollToSelection();
            receiptTable.startEditing(n, 2);

            itemTab.setManager(null, -1, screen);
            vendorTab.setManager(null, -1);
            shipNoteTab.setManager(order);
            drawTabs();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            addReceiptButton.enable(EnumSet.of(State.ADD).contains(event.getState()));
        }
    });

    removeReceiptButton = (AppButton) def.getWidget("removeReceiptButton");
    addScreenHandler(removeReceiptButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            int r;
            IOrderManager order;

            r = receiptTable.getSelectedRow();
            order = null;
            if (r > -1 && receiptTable.numRows() > 0) {
                receiptTable.deleteRow(r);
                //
                // after a row is removed no row is in selected state,
                // thus there's no information to be shown in the tabs,
                // hence the values in the widgets in them need to be cleared out
                //
                itemTab.setManager(null, -1, screen);
                vendorTab.setManager(null, receiptTable.getSelectedRow());
                shipNoteTab.setManager(order);
            }
        }

        public void onStateChange(StateChangeEvent<State> event) {
            removeReceiptButton.enable(EnumSet.of(State.ADD).contains(event.getState()));
        }
    });

    tabPanel = (TabPanel) def.getWidget("tabPanel");
    tabPanel.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
        public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
            int i;

            i = event.getItem().intValue();
            tab = Tabs.values()[i];

            window.setBusy();
            drawTabs();
            window.clearStatus();
        }
    });

    itemTab = new ItemTab(def, window);
    addScreenHandler(itemTab, new ScreenEventHandler<Object>() {
        public void onDataChange(DataChangeEvent event) {
            if (tab == Tabs.ITEM)
                drawTabs();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            itemTab.setState(event.getState());
        }
    });

    itemTab.addActionHandler(new ActionHandler<ItemTab.Action>() {
        public void onAction(ActionEvent<ItemTab.Action> event) {
            int i, r;
            Exception ex;
            ArrayList<Exception> exceptions;
            TableDataRow row, val;

            r = receiptTable.getSelectedRow();
            row = receiptTable.getSelection();
            val = (TableDataRow) receiptTable.getObject(r, 4);
            exceptions = row.cells.get(4).getExceptions();
            if (event.getAction() == Action.LOT_NUMBER_CHANGED) {
                if (exceptions != null && event.getData() != null) {
                    for (i = 0; i < exceptions.size(); i++) {
                        ex = exceptions.get(i);
                        if (Messages.get().lotNumRequiredForOrderItemException().equals(ex.getMessage())) {
                            exceptions.remove(i);
                            break;
                        }
                    }

                    //
                    // this will redraw the exceptions
                    //
                    receiptTable.setCell(r, 4, val);

                    //
                    // the list of exceptions for this  cell is set to null if it is
                    // empty to make sure that in the method validate(), when checkValue()
                    // is called for this cell, an empty but non-null list of exceptions
                    // isn't confused with a list that contains exceptions and validate()
                    // isn't made to return false 
                    //
                    if (exceptions.size() == 0)
                        row.cells.get(4).clearExceptions();
                }
            } else if (event.getAction() == Action.STORAGE_LOCATION_CHANGED) {
                if (exceptions != null && event.getData() != null) {
                    for (i = 0; i < exceptions.size(); i++) {
                        ex = exceptions.get(i);
                        if (Messages.get().storageLocReqForItemException().equals(ex.getMessage())
                                || Messages.get().itemNotExistAtLocationException().equals(ex.getMessage())
                                || Messages.get().itemExistAtLocationException().equals(ex.getMessage())) {
                            exceptions.remove(i);
                            break;
                        }
                    }

                    //
                    // this will redraw the exceptions
                    //
                    receiptTable.setCell(r, 4, val);

                    //
                    // the list of exceptions for this  cell is set to null if it is
                    // empty to make sure that in the method validate(), when checkValue()
                    // is called for this cell, an empty but non-null list of exceptions
                    // isn't confused with a list that contains exceptions and validate()
                    // isn't made to return false 
                    //
                    if (exceptions.size() == 0)
                        row.cells.get(4).clearExceptions();
                }
            }
        }
    });

    vendorTab = new VendorAddressTab(def, window);
    addScreenHandler(vendorTab, new ScreenEventHandler<Object>() {
        public void onDataChange(DataChangeEvent event) {
            if (tab == Tabs.VENDOR_ADDRESS)
                drawTabs();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            vendorTab.setState(event.getState());
        }
    });

    shipNoteTab = new ShipNoteTab(def, window, "notesPanel", "standardNoteButton");
    addScreenHandler(shipNoteTab, new ScreenEventHandler<Object>() {
        public void onDataChange(DataChangeEvent event) {
            if (tab == Tabs.SHIP_NOTE)
                drawTabs();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            shipNoteTab.setState(event.getState());
        }
    });

    window.addBeforeClosedHandler(new BeforeCloseHandler<WindowInt>() {
        public void onBeforeClosed(BeforeCloseEvent<WindowInt> event) {
            if (EnumSet.of(State.ADD, State.UPDATE).contains(state)) {
                event.cancel();
                window.setError(Messages.get().mustCommitOrAbort());
            }
        }
    });

    screen = this;
}