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.openelis.modules.orderFill.client.OrderFillScreen.java

License:Open Source License

private void initialize() {
    ////from   w w w. ja  v a  2s.co m
    // 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);
        }
    });

    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);
        }
    });

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

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

    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).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.UPDATE).contains(event.getState()));
        }
    });

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

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

    orderTable = (TableWidget) def.getWidget("orderTable");

    addScreenHandler(orderTable, new ScreenEventHandler<ArrayList<TableDataRow>>() {
        public void onStateChange(StateChangeEvent<State> event) {
            TableColumn process;
            ArrayList list;

            orderTable.enable(true);
            orderTable.setQueryMode(event.getState() == State.QUERY);

            if (state == State.QUERY) {
                process = orderTable.getColumns().get(0);
                process.enable(false);

                list = new ArrayList<Integer>();
                list.add(Constants.dictionary().ORDER_STATUS_PENDING);
                orderTable.setCell(0, 2, list);
            }
        }
    });

    orderTable.addSelectionHandler(new SelectionHandler<TableRow>() {
        public void onSelection(SelectionEvent<TableRow> event) {
            TableDataRow row;
            IOrderManager man;
            IOrderViewDO data;

            row = orderTable.getSelection();
            data = orderMap.get(row);
            if (row.data == null)
                row.data = fetchById(data);

            man = (IOrderManager) row.data;
            shipNoteTab.setManager(man);
            itemTab.setManager(man, combinedMap);
            custNoteTab.setManager(man);

            drawTabs();
        }
    });

    orderTable.addBeforeCellEditedHandler(new BeforeCellEditedHandler() {
        public void onBeforeCellEdited(BeforeCellEditedEvent event) {
            int r, c;
            TableDataRow row;
            IOrderViewDO data, prevData;
            String val, type;
            Integer status;

            if (orderMap == null) {
                event.cancel();
                return;
            }

            c = event.getCol();
            r = event.getRow();
            row = orderTable.getRow(r);
            data = orderMap.get(row);
            val = (String) orderTable.getObject(r, 0);
            status = data.getStatusId();
            type = data.getType();

            if (state == State.UPDATE) {
                if (c > 0) {
                    //
                    // if the order has been selected for processing, then
                    // we set the state of the tab showing customer notes to
                    // Update, so that the data in the widgets in it can be
                    // edited, otherwise we set the state to Display, so
                    // that
                    // the data can't be edited
                    //
                    if ("Y".equals(val))
                        custNoteTab.setState(State.UPDATE);
                    else
                        custNoteTab.setState(State.DISPLAY);
                    event.cancel();
                } else {
                    prevData = getProcessShipData();
                    /*
                     * only orders with the same ship to, status and type
                     * can be combined together
                     */
                    if (prevData != null && "N".equals(val)
                            && (DataBaseUtil.isDifferent(data.getOrganizationId(), prevData.getOrganizationId())
                                    || !DataBaseUtil.isSame(data.getStatusId(), prevData.getStatusId())
                                    || !DataBaseUtil.isSame(data.getType(), prevData.getType()))) {
                        Window.alert(Messages.get().sameShipToStatusTypeOrderCombined());
                        custNoteTab.setState(State.DISPLAY);
                        event.cancel();
                    }
                }
            } else {
                if (Constants.dictionary().ORDER_STATUS_PROCESSED.equals(status)
                        && IOrderManager.TYPE_SEND_OUT.equals(type))
                    shippingInfo.enable(true);
                else
                    shippingInfo.enable(false);
                event.cancel();
            }

            shipNoteTab.setState(State.DISPLAY);
        }
    });

    orderTable.addCellEditedHandler(new CellEditedHandler() {
        public void onCellUpdated(CellEditedEvent event) {
            int r, c;
            String val;
            TableDataRow row;
            IOrderViewDO data;
            IOrderManager man;
            Datetime now;

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

            if (c == 0) {
                val = (String) orderTable.getObject(r, c);
                row = orderTable.getRow(r);
                data = orderMap.get(row);

                if ("Y".equals(val) && (combinedMap.get(data.getId()) == null)) {
                    try {
                        man = (IOrderManager) row.data;
                        if (man == null) {
                            man = IOrderManager.getInstance();
                            man.setIorder(data);
                        }

                        window.setBusy(Messages.get().lockForUpdate());
                        row.data = man.fetchForUpdate();
                        man = (IOrderManager) row.data;
                        window.clearStatus();

                        combinedMap.put(data.getId(), man);
                        itemTab.setManager(man, combinedMap);

                        //
                        // we do this here in order to make sure that the
                        // tree showing order items always gets loaded so
                        // that
                        // validation for processing orders always takes
                        // place
                        // because it relies on the data in the tree
                        //
                        if (tab != Tabs.ITEM)
                            itemTab.draw();

                        shipNoteTab.setManager(man);

                        if (IOrderManager.TYPE_SEND_OUT.equals(data.getType()))
                            custNoteTab.setState(State.UPDATE);
                        else
                            custNoteTab.setState(State.DISPLAY);
                        custNoteTab.setManager(man);
                        drawTabs();
                    } catch (Exception e) {
                        Window.alert(e.getMessage());
                        e.printStackTrace();
                    }
                } else if ("N".equals(val) && (combinedMap.get(data.getId()) != null)) {
                    custNoteTab.setState(State.DISPLAY);
                    now = null;
                    try {
                        now = CalendarService.get().getCurrentDatetime(Datetime.YEAR, Datetime.DAY);
                    } catch (Exception e) {
                        Window.alert("OrderFill Datetime: " + e.getMessage());
                    }

                    try {
                        man = (IOrderManager) row.data;
                        man = man.abortUpdate();
                        reloadRow(man, row, now);
                        combinedMap.remove(data.getId());
                        shipNoteTab.setManager(man);
                        itemTab.setManager(man, combinedMap);
                        custNoteTab.setManager(man);
                        window.setDone(Messages.get().updateAborted());
                        drawTabs();
                    } catch (Exception e) {
                        Window.alert(e.getMessage());
                        e.printStackTrace();
                        window.clearStatus();
                    }

                }
            }
        }
    });

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

            // 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();
            row = orderTable.getSelection();
            if (row != null) {
                man = (IOrderManager) row.data;
                if (i == 0 && !treeValid && combinedMap != null
                        && combinedMap.get(man.getIorder().getId()) != null)
                    itemTab.validate();
            }
            window.clearStatus();
        }
    });

    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());
        }
    });

    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());
        }
    });

    itemsTree = (TreeWidget) def.getWidget("itemsTree");

    custNoteTab = new CustomerNoteTab(def, window, "customerNotesPanel", "editNoteButton");
    addScreenHandler(custNoteTab, new ScreenEventHandler<Object>() {
        public void onDataChange(DataChangeEvent event) {
            if (tab == Tabs.CUSTOMER_NOTE)
                drawTabs();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            custNoteTab.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());
            }
        }
    });
}

From source file:org.openelis.modules.patient.client.PatientLookupUI.java

License:Open Source License

/**
 * Setup state and data change handles for every widget on the screen
 *//*from w  w w  .ja  v a 2 s.  com*/
public void initialize() {
    ArrayList<DictionaryDO> list;
    ArrayList<Item<Integer>> model;
    ArrayList<Item<String>> smodel;

    //
    // screen fields and buttons
    //
    addScreenHandler(lastName, PatientMeta.getLastName(), new ScreenHandler<String>() {
        public void onStateChange(StateChangeEvent event) {
            lastName.setEnabled(!queryByNId && isState(QUERY));
            lastName.setQueryMode(!queryByNId && isState(QUERY));
        }

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

    addScreenHandler(firstName, PatientMeta.getFirstName(), new ScreenHandler<String>() {
        public void onStateChange(StateChangeEvent event) {
            firstName.setEnabled(!queryByNId && isState(QUERY));
            firstName.setQueryMode(!queryByNId && isState(QUERY));
        }

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

    addScreenHandler(birthDate, PatientMeta.getBirthDate(), new ScreenHandler<Datetime>() {
        public void onStateChange(StateChangeEvent event) {
            birthDate.setEnabled(!queryByNId && isState(QUERY));
            birthDate.setQueryMode(!queryByNId && isState(QUERY));
        }

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

    addScreenHandler(nationalId, PatientMeta.getNationalId(), new ScreenHandler<String>() {
        public void onStateChange(StateChangeEvent event) {
            nationalId.setEnabled(!queryByNId && isState(QUERY));
        }

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

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

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

    //
    // patient table
    //
    addScreenHandler(patientTable, "patientTable", new ScreenHandler<ArrayList<Row>>() {
        public void onStateChange(StateChangeEvent event) {
            patientTable.setEnabled(true);
        }

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

    patientTable.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
        @Override
        public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
            PatientDO data;

            data = patientTable.getRowAt(0).getData();
            if (queryByNId && (queriedPatient.getId() != null && !queriedPatient.getId().equals(data.getId())))
                event.cancel();
        }
    });

    patientTable.addSelectionHandler(new SelectionHandler<Integer>() {
        public void onSelection(SelectionEvent<Integer> event) {
            patientSelected();
        }
    });

    patientTable.addBeforeCellEditedHandler(new BeforeCellEditedHandler() {
        public void onBeforeCellEdited(BeforeCellEditedEvent event) {
            // this table cannot be edited
            event.cancel();
        }
    });

    //
    // next of kin table
    //
    addScreenHandler(nextOfKinTable, "nextOfKinTable", new ScreenHandler<ArrayList<Row>>() {
        public void onStateChange(StateChangeEvent event) {
            nextOfKinTable.setEnabled(!queryByNId);
        }
    });

    nextOfKinTable.addSelectionHandler(new SelectionHandler<Integer>() {
        public void onSelection(SelectionEvent<Integer> event) {
            selectedNextOfKin = nextOfKinTable.getRowAt(nextOfKinTable.getSelectedRow()).getData();
        }
    });

    nextOfKinTable.addBeforeCellEditedHandler(new BeforeCellEditedHandler() {
        public void onBeforeCellEdited(BeforeCellEditedEvent event) {
            // this table cannot be edited
            event.cancel();
        }
    });

    //
    // sample table
    //
    addScreenHandler(sampleTable, "sampleTable", new ScreenHandler<ArrayList<Row>>() {
        public void onStateChange(StateChangeEvent event) {
            sampleTable.setEnabled(true);
        }
    });

    sampleTable.addBeforeCellEditedHandler(new BeforeCellEditedHandler() {
        public void onBeforeCellEdited(BeforeCellEditedEvent event) {
            // this table cannot be edited
            event.cancel();
        }
    });

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

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

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

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

    //
    // load gender dropdown model
    //
    list = CategoryCache.getBySystemName("gender");
    model = new ArrayList<Item<Integer>>();
    for (DictionaryDO resultDO : list)
        model.add(new Item<Integer>(resultDO.getId(), resultDO.getEntry()));
    gender.setModel(model);

    //
    // load patient relation dropdown model
    //
    list = CategoryCache.getBySystemName("patient_relation");
    model = new ArrayList<Item<Integer>>();
    for (DictionaryDO resultDO : list)
        model.add(new Item<Integer>(resultDO.getId(), resultDO.getEntry()));
    patientRelation.setModel(model);

    //
    // load state dropdown model
    //
    list = CategoryCache.getBySystemName("state");
    smodel = new ArrayList<Item<String>>();
    for (DictionaryDO resultDO : list)
        model.add(new Item<Integer>(resultDO.getId(), resultDO.getEntry()));
    patientState.setModel(smodel);
}

From source file:org.openelis.modules.pws.client.PWSScreen.java

License:Open Source License

public void initialize() {
    queryButton = (AppButton) def.getWidget("query");
    addScreenHandler(queryButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            query();//  w  w  w.j  a  v  a 2  s . c o m
        }

        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()));
        }
    });

    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).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).contains(event.getState()));
        }
    });

    selectButton = (AppButton) def.getWidget("select");
    if (pwsNumber0 != null) {
        addScreenHandler(selectButton, new ScreenEventHandler<Object>() {
            public void onClick(ClickEvent event) {
                select();
            }

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

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

        public void onStateChange(StateChangeEvent<State> event) {
            parse.enable(userPermission.hasAddPermission());
        }
    });

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

        public void onStateChange(StateChangeEvent<State> event) {
            violationScan.enable(true);
        }
    });

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

        public void onStateChange(StateChangeEvent<State> event) {
            additionalScan.enable(true);
        }
    });

    number0 = (TextBox) def.getWidget(PWSMeta.getNumber0());
    addScreenHandler(number0, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            number0.setValue(manager.getPWS().getNumber0());
        }

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

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

    alternateStNum = (TextBox) def.getWidget(PWSMeta.getAlternateStNum());
    addScreenHandler(alternateStNum, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            alternateStNum.setValue(manager.getPWS().getAlternateStNum());
        }

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

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

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

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

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

    dPrinCitySvdNm = (TextBox) def.getWidget(PWSMeta.getDPrinCitySvdNm());
    addScreenHandler(dPrinCitySvdNm, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            dPrinCitySvdNm.setValue(manager.getPWS().getDPrinCitySvdNm());
        }

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

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

    dPrinCntySvdNm = (TextBox) def.getWidget(PWSMeta.getDPrinCntySvdNm());
    addScreenHandler(dPrinCntySvdNm, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            dPrinCntySvdNm.setValue(manager.getPWS().getDPrinCntySvdNm());
        }

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

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

    dPwsStTypeCd = (TextBox) def.getWidget(PWSMeta.getDPwsStTypeCd());
    addScreenHandler(dPwsStTypeCd, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            dPwsStTypeCd.setValue(manager.getPWS().getDPwsStTypeCd());
        }

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

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

    activityStatusCd = (TextBox) def.getWidget(PWSMeta.getActivityStatusCd());
    addScreenHandler(activityStatusCd, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            activityStatusCd.setValue(manager.getPWS().getActivityStatusCd());
        }

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

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

    dPopulationCount = (TextBox<Integer>) def.getWidget(PWSMeta.getDPopulationCount());
    addScreenHandler(dPopulationCount, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            dPopulationCount.setFieldValue(manager.getPWS().getDPopulationCount());
        }

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

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

    activityRsnTxt = (TextArea) def.getWidget(PWSMeta.getActivityRsnTxt());
    addScreenHandler(activityRsnTxt, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            activityRsnTxt.setValue(manager.getPWS().getActivityRsnTxt());
        }

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

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

    startDay = (TextBox<Integer>) def.getWidget(PWSMeta.getStartDay());
    addScreenHandler(startDay, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            startDay.setFieldValue(manager.getPWS().getStartDay());
        }

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

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

    startMonth = (TextBox<Integer>) def.getWidget(PWSMeta.getStartMonth());
    addScreenHandler(startMonth, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            startMonth.setFieldValue(manager.getPWS().getStartMonth());
        }

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

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

    effBeginDt = (CalendarLookUp) def.getWidget(PWSMeta.getEffBeginDt());
    addScreenHandler(effBeginDt, new ScreenEventHandler<Datetime>() {
        public void onDataChange(DataChangeEvent event) {
            effBeginDt.setValue(manager.getPWS().getEffBeginDt());
        }

        public void onValueChange(ValueChangeEvent<Datetime> event) {
            manager.getPWS().setEffBeginDt(event.getValue());
        }

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

    endDay = (TextBox<Integer>) def.getWidget(PWSMeta.getEndDay());
    addScreenHandler(endDay, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            endDay.setFieldValue(manager.getPWS().getEndDay());
        }

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

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

    endMonth = (TextBox<Integer>) def.getWidget(PWSMeta.getEndMonth());
    addScreenHandler(endMonth, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            endMonth.setFieldValue(manager.getPWS().getEndMonth());
        }

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

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

    effEndDt = (CalendarLookUp) def.getWidget(PWSMeta.getEffEndDt());
    addScreenHandler(effEndDt, new ScreenEventHandler<Datetime>() {
        public void onDataChange(DataChangeEvent event) {
            effEndDt.setValue(manager.getPWS().getEffEndDt());
        }

        public void onValueChange(ValueChangeEvent<Datetime> event) {
            manager.getPWS().setEffEndDt(event.getValue());
        }

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

    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();
        }
    });

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

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

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

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

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

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

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

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

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

            query.setRowsPerPage(20);
            PWSService.get().query(query, new AsyncCallback<ArrayList<IdNameVO>>() {
                public void onSuccess(ArrayList<IdNameVO> 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(Messages.get().noMoreRecordInDir());
                    } else {
                        Window.alert("Error: Pws call query failed; " + error.getMessage());
                        window.setError(Messages.get().queryFailed());
                    }
                }
            });
        }

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

        public ArrayList<TableDataRow> getModel() {
            ArrayList<IdNameVO> list;
            ArrayList<TableDataRow> model;

            list = nav.getQueryResult();
            model = null;
            if (list != null) {
                model = new ArrayList<TableDataRow>();
                for (IdNameVO entry : list)
                    model.add(new TableDataRow(entry.getId(), entry.getName()));
            }
            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(PWSMeta.getName());
            field.setQuery(((AppButton) event.getSource()).action);
            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());
            }
        }
    });

    setState(State.DEFAULT);
    DataChangeEvent.fire(this);

    if (pwsNumber0 != null)
        queryByPwsNumer0();
}

From source file:org.openelis.modules.qaevent.client.QaeventLookupScreen.java

License:Open Source License

private void initialize() {
    qaEventTable = (TableWidget) def.getWidget("qaEventTable");
    addScreenHandler(qaEventTable, new ScreenEventHandler<ArrayList<TableDataRow>>() {
        public void onDataChange(DataChangeEvent event) {
            qaEventTable.load(getTableModel());
        }/*  w ww.jav  a2  s. c  om*/

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

    qaEventTable.addBeforeSelectionHandler(new BeforeSelectionHandler<TableRow>() {
        public void onBeforeSelection(BeforeSelectionEvent<TableRow> event) {
            // do nothing
        };
    });

    qaEventTable.addBeforeCellEditedHandler(new BeforeCellEditedHandler() {
        public void onBeforeCellEdited(BeforeCellEditedEvent event) {
            event.cancel();
        }
    });

    okButton = (AppButton) def.getWidget("ok");
    addScreenHandler(okButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            if (okButton.isEnabled())
                ok();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            okButton.enable(true);
        }
    });

    cancelButton = (AppButton) def.getWidget("cancel");
    addScreenHandler(cancelButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            if (cancelButton.isEnabled())
                cancel();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            cancelButton.enable(true);
        }
    });
}

From source file:org.openelis.modules.qc.client.QcScreen.java

License:Open Source License

/**
 * Setup state and data change handles for every widget on the screen
 *///from w  ww.j  a v a 2  s. co m
@SuppressWarnings("unchecked")
private void initialize() {
    //
    // 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())
                    && userModulePermission.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())
                    && userModulePermission.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())
                    && userModulePermission.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())
                    && userModulePermission.hasAddPermission());
        }
    });

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

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

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

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

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

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

    //
    // screen fields
    //
    id = (TextBox<Integer>) def.getWidget(QcMeta.getId());
    addScreenHandler(id, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            id.setFieldValue(manager.getQc().getId());
        }

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

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

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

        public void onValueChange(ValueChangeEvent<String> event) {
            manager.getQc().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);
        }
    });

    typeId = (Dropdown) def.getWidget(QcMeta.getTypeId());
    addScreenHandler(typeId, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            typeId.setSelection(manager.getQc().getTypeId());
        }

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

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

    inventoryItem = (AutoComplete) def.getWidget(QcMeta.getInventoryItemName());
    addScreenHandler(inventoryItem, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            inventoryItem.setSelection(manager.getQc().getInventoryItemId(),
                    manager.getQc().getInventoryItemName());
        }

        public void onValueChange(ValueChangeEvent<Integer> event) {
            manager.getQc().setInventoryItemId(event.getValue());
            manager.getQc().setInventoryItemName(inventoryItem.getTextBoxDisplay());
        }

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

    inventoryItem.addGetMatchesHandler(new GetMatchesHandler() {
        public void onGetMatches(GetMatchesEvent event) {
            DictionaryDO dict;
            ArrayList<InventoryItemDO> list;
            ArrayList<TableDataRow> model;

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

                for (InventoryItemDO data : list) {
                    dict = DictionaryCache.getById(data.getStoreId());
                    model.add(new TableDataRow(data.getId(), data.getName(), dict.getEntry()));
                }
                inventoryItem.showAutoMatches(model);
            } catch (Exception e) {
                Window.alert(e.getMessage());
            }
        }
    });

    source = (TextBox) def.getWidget(QcMeta.getSource());
    addScreenHandler(source, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            source.setValue(manager.getQc().getSource());
        }

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

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

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

        public void onValueChange(ValueChangeEvent<String> event) {
            manager.getQc().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);
        }
    });

    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();
        }
    });

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

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

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

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

    internalNoteTab = new InternalNoteTab(def, window, userPermission.getLoginName(),
            userPermission.getSystemUserId());
    addScreenHandler(internalNoteTab, new ScreenEventHandler<Object>() {
        public void onDataChange(DataChangeEvent event) {
            internalNoteTab.setManager(manager);
            if (tab == Tabs.INTERNAL_NOTE)
                drawTabs();
        }

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

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

            query.setRowsPerPage(20);
            QcService.get().query(query, new AsyncCallback<ArrayList<IdNameVO>>() {
                public void onSuccess(ArrayList<IdNameVO> 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(Messages.get().noMoreRecordInDir());
                    } else {
                        Window.alert("Error: QC call query failed; " + error.getMessage());
                        window.setError(Messages.get().queryFailed());
                    }
                }
            });
        }

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

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

            model = null;
            result = nav.getQueryResult();
            if (result != null) {
                model = new ArrayList<TableDataRow>();
                for (IdNameVO entry : result)
                    model.add(new TableDataRow(entry.getId(), entry.getName()));
            }
            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())
                    && userModulePermission.hasSelectPermission();
            atoz.enable(enable);
            nav.enable(enable);
        }

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

            field = new QueryData();
            field.setKey(QcMeta.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.shipping.client.ShippingScreen.java

License:Open Source License

private void initialize() {
    ////from   w w  w .  ja  va 2 s .c o m
    // button panel buttons
    //
    screen = this;

    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(null);
        }

        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()));
        }
    });

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

        public void onStateChange(StateChangeEvent<State> event) {
            processShipping.enable(EnumSet.of(State.DISPLAY, State.DEFAULT).contains(event.getState())
                    && userPermission.hasUpdatePermission());
        }
    });

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

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

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

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

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

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

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

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

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

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

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

    statusId = (Dropdown) def.getWidget(ShippingMeta.getStatusId());
    addScreenHandler(statusId, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            statusId.setSelection(manager.getShipping().getStatusId());
        }

        public void onValueChange(ValueChangeEvent<Integer> event) {
            if (!Constants.dictionary().SHIPPING_STATUS_SHIPPED.equals(event.getValue())) {
                manager.getShipping().setShippedDate(null);
                shippedDate.setValue(manager.getShipping().getShippedDate());
            }

            manager.getShipping().setStatusId(event.getValue());
        }

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

    shippedDate = (CalendarLookUp) def.getWidget(ShippingMeta.getShippedDate());
    addScreenHandler(shippedDate, new ScreenEventHandler<Datetime>() {
        public void onDataChange(DataChangeEvent event) {
            shippedDate.setValue(manager.getShipping().getShippedDate());
        }

        public void onValueChange(ValueChangeEvent<Datetime> event) {
            manager.getShipping().setShippedDate(event.getValue());
        }

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

    numberOfPackages = (TextBox<Integer>) def.getWidget(ShippingMeta.getNumberOfPackages());
    addScreenHandler(numberOfPackages, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            numberOfPackages.setFieldValue(manager.getShipping().getNumberOfPackages());
        }

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

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

    cost = (TextBox) def.getWidget(ShippingMeta.getCost());
    addScreenHandler(cost, new ScreenEventHandler<Double>() {
        public void onDataChange(DataChangeEvent event) {
            cost.setFieldValue(manager.getShipping().getCost());
        }

        public void onValueChange(ValueChangeEvent<Double> event) {
            manager.getShipping().setCost(event.getValue());
        }

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

    shippedFromId = (Dropdown) def.getWidget(ShippingMeta.getShippedFromId());
    addScreenHandler(shippedFromId, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            shippedFromId.setSelection(manager.getShipping().getShippedFromId());
        }

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

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

    shippedToAttention = (TextBox) def.getWidget(ShippingMeta.getShippedToAttention());
    addScreenHandler(shippedToAttention, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            shippedToAttention.setValue(manager.getShipping().getShippedToAttention());
        }

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

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

    shippedToName = (AutoComplete) def.getWidget(ShippingMeta.getShippedToName());
    addScreenHandler(shippedToName, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            ShippingViewDO data;

            data = manager.getShipping();
            if (data.getShippedTo() != null) {
                shippedToName.setSelection(data.getShippedTo().getId(), data.getShippedTo().getName());
            } else {
                shippedToName.setSelection(null, "");
            }
        }

        public void onValueChange(ValueChangeEvent<Integer> event) {
            OrganizationDO data;

            if (shippedToName.getSelection() != null) {
                data = (OrganizationDO) shippedToName.getSelection().data;

                manager.getShipping().setShippedToId(data.getId());
                manager.getShipping().setShippedTo(data);

                shippedToAddressMultipleUnit.setValue(data.getAddress().getMultipleUnit());
                shippedToAddressStreetAddress.setValue(data.getAddress().getStreetAddress());
                shippedToAddressCity.setValue(data.getAddress().getCity());
                shippedToAddressState.setValue(data.getAddress().getState());
                shippedToAddressZipCode.setValue(data.getAddress().getZipCode());
            } else {
                manager.getShipping().setShippedToId(null);
                manager.getShipping().setShippedTo(null);

                shippedToAddressMultipleUnit.setValue(null);
                shippedToAddressStreetAddress.setValue(null);
                shippedToAddressCity.setValue(null);
                shippedToAddressState.setValue(null);
                shippedToAddressZipCode.setValue(null);
            }
        }

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

    shippedToName.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).setValue(data.getName());
                    row.cells.get(1).setValue(data.getAddress().getStreetAddress());
                    row.cells.get(2).setValue(data.getAddress().getCity());
                    row.cells.get(3).setValue(data.getAddress().getState());

                    row.data = data;

                    model.add(row);
                }

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

        }

    });

    processedDate = (CalendarLookUp) def.getWidget(ShippingMeta.getProcessedDate());
    addScreenHandler(processedDate, new ScreenEventHandler<Datetime>() {
        public void onDataChange(DataChangeEvent event) {
            processedDate.setValue(manager.getShipping().getProcessedDate());
        }

        public void onValueChange(ValueChangeEvent<Datetime> event) {
            manager.getShipping().setProcessedDate(event.getValue());
        }

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

    shippedToAddressMultipleUnit = (TextBox) def.getWidget(ShippingMeta.getShippedToAddressMultipleUnit());
    addScreenHandler(shippedToAddressMultipleUnit, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            ShippingViewDO data;

            data = manager.getShipping();
            if (data.getShippedTo() != null)
                shippedToAddressMultipleUnit.setValue(data.getShippedTo().getAddress().getMultipleUnit());
            else
                shippedToAddressMultipleUnit.setValue(null);
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            // this is a read only and the value will not change
        }

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

    processedById = (TextBox) def.getWidget(ShippingMeta.getProcessedBy());
    addScreenHandler(processedById, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            processedById.setValue(manager.getShipping().getProcessedBy());
        }

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

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

    shippedToAddressStreetAddress = (TextBox) def.getWidget(ShippingMeta.getShippedToAddressStreetAddress());
    addScreenHandler(shippedToAddressStreetAddress, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            ShippingViewDO data;

            data = manager.getShipping();
            if (data.getShippedTo() != null)
                shippedToAddressStreetAddress.setValue(data.getShippedTo().getAddress().getStreetAddress());
            else
                shippedToAddressStreetAddress.setValue(null);
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            // this is a read only and the value will not change
        }

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

    shippedMethodId = (Dropdown) def.getWidget(ShippingMeta.getShippedMethodId());
    addScreenHandler(shippedMethodId, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            shippedMethodId.setSelection(manager.getShipping().getShippedMethodId());
        }

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

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

    shippedToAddressCity = (TextBox) def.getWidget(ShippingMeta.getShippedToAddressCity());
    addScreenHandler(shippedToAddressCity, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            ShippingViewDO data;

            data = manager.getShipping();
            if (data.getShippedTo() != null)
                shippedToAddressCity.setValue(data.getShippedTo().getAddress().getCity());
            else
                shippedToAddressCity.setValue(null);
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            // this is a read only and the value will not change
        }

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

    shippedToAddressState = (TextBox) def.getWidget(ShippingMeta.getShippedToAddressState());
    addScreenHandler(shippedToAddressState, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            ShippingViewDO data;

            data = manager.getShipping();
            if (data.getShippedTo() != null)
                shippedToAddressState.setValue(data.getShippedTo().getAddress().getState());
            else
                shippedToAddressState.setValue(null);
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            // this is a read only and the value will not change
        }

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

    shippedToAddressZipCode = (TextBox) def.getWidget(ShippingMeta.getShippedToAddressZipCode());
    addScreenHandler(shippedToAddressZipCode, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            ShippingViewDO data;

            data = manager.getShipping();
            if (data.getShippedTo() != null)
                shippedToAddressZipCode.setValue(data.getShippedTo().getAddress().getZipCode());
            else
                shippedToAddressZipCode.setValue(null);
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            // this is a read only and the value will not change
        }

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

    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) {
            itemTab.setManager(manager);
            if (tab == Tabs.ITEM)
                drawTabs();
        }

        public void onStateChange(StateChangeEvent<State> event) {
            itemTab.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.SHIP_NOTE)
                drawTabs();
        }

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

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

            query.setRowsPerPage(12);
            ShippingService.get().query(query, new AsyncCallback<ArrayList<IdNameVO>>() {
                public void onSuccess(ArrayList<IdNameVO> 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: Order call query failed; " + error.getMessage());
                        window.setError(Messages.get().queryFailed());
                    }
                }
            });
        }

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

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

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

    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.storage.client.CurrentTab.java

License:Open Source License

private void initialize() {
    idItemMap = new HashMap<Integer, TreeDataItem>();
    storageCache = new HashMap<Integer, StorageManager>();
    storageLocationCache = new HashMap<Integer, StorageLocationManager>();

    storageCurrentTree = (TreeWidget) def.getWidget("storageCurrentTree");
    addScreenHandler(storageCurrentTree, new ScreenEventHandler<ArrayList<TableDataRow>>() {
        public void onDataChange(DataChangeEvent event) {
            storageCurrentTree.load(getTreeModel());
        }// ww w  .  j av  a  2s. c o m

        public void onStateChange(StateChangeEvent<State> event) {
            storageCurrentTree.enable(true);
        }
    });

    storageCurrentTree.addBeforeCellEditedHandler(new BeforeCellEditedHandler() {
        public void onBeforeCellEdited(BeforeCellEditedEvent event) {
            event.cancel();
        }
    });

    storageCurrentTree.addBeforeSelectionHandler(new BeforeSelectionHandler<TreeDataItem>() {
        public void onBeforeSelection(BeforeSelectionEvent<TreeDataItem> event) {
            TreeDataItem item;
            boolean isStorage;
            StorageViewDO data;

            item = event.getItem();
            isStorage = "storage".equals(item.leafType);

            if (state == State.UPDATE) {
                moveItemsButton.enable(isStorage);
                discardItemsButton.enable(isStorage);

                if (isStorage) {
                    data = (StorageViewDO) item.data;
                    if (data.getCheckout() != null) {
                        window.setError(Messages.get().cantSelectItem());
                        event.cancel();
                    } else {
                        window.clearStatus();
                    }
                }
            }
        }
    });

    storageCurrentTree.multiSelect(true);

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

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

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

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

}

From source file:org.openelis.modules.storage.client.StorageScreen.java

License:Open Source License

/**
 * Setup state and data change handles for every widget on the screen
 *///from   w  w  w .  ja va2s  . c om
private void initialize() {
    //
    // 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);
        }
    });

    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()));
        }
    });

    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.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.UPDATE).contains(event.getState()));
        }
    });

    name = (TextBox) def.getWidget(StorageMeta.getStorageLocationName());
    addScreenHandler(name, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            StorageLocationManager slm;

            slm = manager.getStorageLocation();
            if (slm != null)
                name.setValue(slm.getStorageLocation().getName());
            else
                name.setValue(null);

        }

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

    location = (TextBox) def.getWidget(StorageMeta.getStorageLocationLocation());
    addScreenHandler(location, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            StorageLocationManager slm;

            slm = manager.getStorageLocation();
            if (slm != null)
                location.setValue(slm.getStorageLocation().getLocation());
            else
                location.setValue(null);

        }

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

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

    storageUnitDescription = (TextBox) def.getWidget(StorageMeta.getStorageLocationStorageUnitDescription());
    addScreenHandler(storageUnitDescription, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            StorageLocationManager slm;

            slm = manager.getStorageLocation();
            if (slm != null)
                storageUnitDescription.setValue(slm.getStorageLocation().getStorageUnitDescription());
            else
                storageUnitDescription.setValue(null);

        }

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

    isAvailable = (CheckBox) def.getWidget(StorageMeta.getStorageLocationIsAvailable());
    addScreenHandler(isAvailable, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            StorageLocationManager slm;

            slm = manager.getStorageLocation();
            if (slm != null)
                isAvailable.setValue(slm.getStorageLocation().getIsAvailable());
            else
                isAvailable.setValue(null);

        }

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

    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();
        }
    });

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

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

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

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

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

            query.setRowsPerPage(19);
            StorageLocationService.get().query(query, new AsyncCallback<ArrayList<IdNameVO>>() {
                public void onSuccess(ArrayList<IdNameVO> 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(Messages.get().noMoreRecordInDir());
                    } else {
                        Window.alert("Error: Storage call query failed; " + error.getMessage());
                        window.setError(Messages.get().queryFailed());
                    }
                }
            });
        }

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

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

            model = null;
            result = nav.getQueryResult();
            if (result != null) {
                model = new ArrayList<TableDataRow>();
                for (IdNameVO entry : result)
                    model.add(new TableDataRow(entry.getId(), entry.getName()));
            }
            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(StorageMeta.getStorageLocationName());
            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, State.DELETE).contains(state)) {
                event.cancel();
                window.setError(Messages.get().mustCommitOrAbort());
            }
        }
    });
}

From source file:org.openelis.modules.test.client.AnalyteAndResultTab.java

License:Open Source License

private void initialize() {
    analyteTable = (TableWidget) def.getWidget("analyteTable");
    addScreenHandler(analyteTable, new ScreenEventHandler<ArrayList<TableDataRow>>() {
        public void onDataChange(DataChangeEvent event) {
            ///*from  www  . jav a2 s . c  o  m*/
            // this table is not queried by,so it needs to be cleared in
            // query mode
            //
            analyteTable.load(getAnalyteTableModel());
        }

        public void onStateChange(StateChangeEvent<State> event) {
            analyteTable.enable(true);
        }
    });

    rangeNumeric = new ResultRangeNumeric();
    rangeTiter = new ResultRangeTiter();

    analyteTable.addBeforeSelectionHandler(new BeforeSelectionHandler<TableRow>() {
        public void onBeforeSelection(BeforeSelectionEvent<TableRow> event) {
            ArrayList<TableDataRow> selections;
            TableDataRow row, selRow;

            selections = analyteTable.getSelections();

            if (state != State.ADD && state != State.UPDATE)
                return;

            //
            // since this table supports multiple selection, we want to make
            // sure that if the first row selected is an analyte row then
            // all the subsequently selected rows are analyte rows and if
            // the
            // first row selected is a header row then all the
            // subsequently selected rows are header rows, so through this
            // code we prevent users from selecting the other kind of row
            //
            selRow = event.getItem().row;

            if (selections.size() > 0) {
                row = selections.get(selections.size() - 1);
                if (!(row.data.equals(selRow.data))) {
                    Window.alert(Messages.get().headerCantSelWithAnalytes());
                    event.cancel();
                }
                addButton.enable(false);
                removeButton.enable(false);
            } else {
                addButton.enable(true);
                removeButton.enable(true);
            }
        }
    });

    analyteTable.addBeforeCellEditedHandler(new BeforeCellEditedHandler() {
        public void onBeforeCellEdited(BeforeCellEditedEvent event) {
            int r, c;
            Integer key;
            TableDataRow row, val, prevVal;
            AutoComplete<Integer> auto;
            boolean cancel;

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

            if (state != State.ADD && state != State.UPDATE) {
                enableAnalyteWidgets(false);
                event.cancel();
            } else {
                enableAnalyteWidgets(true);
            }

            cancel = false;
            auto = (AutoComplete<Integer>) analyteTable.getColumns().get(c).getColumnWidget();

            try {
                row = analyteTable.getRow(r);
                if ((Boolean) row.data) {
                    //
                    // the first two columns of a header row are immutable
                    // and we also don't want to allow a user to be able to
                    // edit a header row column that's beyond the number of
                    // columns for the row group that the analyte rows under
                    // the header belong to; in addition to cancelling the
                    // edit event, we disable the three widgets, disallow
                    // adding or removing columns and set anaSelCol to -1
                    // such that the three widgets don't show any data when
                    // refreshAnalyteWidgets() is called
                    //
                    if (c < 2 || c > (displayManager.columnCount(r) + 1)) {
                        event.cancel();
                        cancel = true;
                        enableAnalyteWidgets(false);
                        canAddRemoveColumn = false;
                        anaSelCol = -1;
                    } else if (c != 2) {
                        val = (TableDataRow) row.cells.get(c - 1).getValue();
                        //
                        // we don't want to allow editing of a header cell
                        // if the
                        // cell to its left doesn't have any data in it
                        //
                        if (val == null || val.key == null) {
                            event.cancel();
                            cancel = true;
                            enableAnalyteWidgets(false);
                            anaSelCol = -1;
                        }

                        //
                        // since we cannot allow adding or removing of
                        // columns
                        // if col exceeds the number of columns that a given
                        // row group has for itself in the manager, we set
                        // canAddRemoveColumn to false if this is the case
                        // and to true otherwise
                        //
                        if (c <= displayManager.columnCount(r))
                            canAddRemoveColumn = true;
                        else
                            canAddRemoveColumn = false;
                    } else if (c == 2) {
                        //
                        // we always allow adding or removing of columns at
                        // the third column of a header row
                        //
                        canAddRemoveColumn = true;
                    }

                    //
                    // send DataChangeEvent to the three widgets to make
                    // them either show the data that corresponds to this
                    // cell or make them go blank
                    //
                    refreshAnalyteWidgets();
                } else {
                    if (c > displayManager.columnCount(r)) {
                        //
                        // for a header row, we allow editing of the cell
                        // that's next to last cell that has data in it but
                        // in the
                        // case of a non-header row, i.e. here, we don't;
                        // only cells under those header cells that have
                        // data in them can be edited; in addition to this,
                        // we
                        // disable the three widgets and disallow adding or
                        // removing
                        // columns
                        //
                        event.cancel();
                        cancel = true;
                        enableAnalyteWidgets(false);
                        canAddRemoveColumn = false;
                    } else if (c > 0) {
                        if (c == 1) {
                            prevVal = (TableDataRow) row.cells.get(c - 1).getValue();
                            //
                            // we disallow the editing of the first result
                            // group
                            // cell if there's no analyte selected in the
                            // first
                            // cell of the analyte row
                            //
                            if (prevVal == null || prevVal.key == null) {
                                event.cancel();
                                cancel = true;
                            }
                        }
                        val = (TableDataRow) row.cells.get(c).getValue();
                        if (val != null && val.key != null) {
                            //
                            // here we check to see if there was a result
                            // group
                            // selected and if there was we open the tab
                            // corresponding
                            // to it
                            key = (Integer) val.key;
                            if (key - 1 < resultTabPanel.getTabBar().getTabCount()) {
                                resultTabPanel.selectTab(key - 1);
                            }
                        }
                        //
                        // we disable the three widgets and disallow adding
                        // or removing columns and make the three widget to
                        // show no data
                        //
                        enableAnalyteWidgets(false);
                        canAddRemoveColumn = false;
                        anaSelCol = -1;
                        auto.setDelay(1);
                    }

                    //
                    // send DataChangeEvent to the three widgets to make
                    // them either show the data that corresponds to this
                    // cell or make them go blank
                    //
                    refreshAnalyteWidgets();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }

            if (analyteTable.getSelections().size() > 1 && !cancel)
                window.setStatus(Messages.get().multiSelRowEditCol() + c, "");
            else
                window.clearStatus();
        }

    });

    analyteTable.addCellEditedHandler(new CellEditedHandler() {
        public void onCellUpdated(CellEditedEvent event) {
            int i, r, c, numCol, dindex, rows[];
            String name;
            TableDataRow row, val;
            TestAnalyteViewDO data;
            Integer key;
            AutoComplete<Integer> auto;
            TestAnalyteManager man;

            key = null;
            man = null;
            r = event.getRow();
            c = event.getCol();
            row = analyteTable.getRow(r);
            val = (TableDataRow) analyteTable.getObject(r, c);
            if (val != null)
                key = (Integer) val.key;
            auto = (AutoComplete<Integer>) analyteTable.getColumns().get(c).getColumnWidget();
            rows = analyteTable.getSelectedRows();

            try {
                man = manager.getTestAnalytes();
            } catch (Exception e) {
                Window.alert(e.getMessage());
                e.printStackTrace();
            }

            try {
                if ((Boolean) row.data) {
                    numCol = displayManager.columnCount(r);
                    if (numCol < c) {
                        if (key != null) {
                            //
                            // we need to add a new column to the data grid
                            // if
                            // this column in the table in a sub header was
                            // edited for the first time and the key set as
                            // its value is not null
                            //
                            dindex = displayManager.getDataRowIndex(r);
                            man.addColumnAt(dindex, c - 1, key, auto.getTextBoxDisplay());
                            displayManager.setDataGrid(man.getAnalytes());
                        }
                    } else {
                        //
                        // we need to update all the cells in this column in
                        // the data grid if the column already exists in it
                        //
                        for (i = r + 1; i < analyteTable.numRows(); i++) {
                            if (displayManager.isHeaderRow(i))
                                break;
                            data = displayManager.getObjectAt(i, c - 1);
                            data.setAnalyteId(key);
                            data.setAnalyteName(auto.getTextBoxDisplay());
                        }
                    }

                    //
                    // since we cannot allow adding or removing of columns
                    // if col exceeds the number of columns that a given
                    // row group has for itself in the manager, we set
                    // canAddRemoveColumn to false if this is the case
                    // and to true otherwise
                    //
                    if (c <= displayManager.columnCount(r))
                        canAddRemoveColumn = true;
                    else
                        canAddRemoveColumn = false;
                } else {
                    if (c == 0) {
                        //
                        // if the updated cell was in a regular row, then
                        // we need to set the key as the test analyte's id
                        // in the DO at the appropriate location in the grid
                        //
                        data = displayManager.getObjectAt(r, c);
                        data.setAnalyteId(key);
                        data.setAnalyteName(auto.getTextBoxDisplay());
                        ActionEvent.fire(screen, Action.ANALYTE_CHANGED, data);
                    } else {
                        //
                        // otherwise we need to set the key as the result
                        // group number in the DO
                        //
                        for (i = 0; i < rows.length; i++) {
                            data = displayManager.getObjectAt(rows[i], c - 1);
                            if (data == null)
                                continue;
                            data.setResultGroup(key);
                            if (key == null)
                                name = "";
                            else
                                name = key.toString();
                            analyteTable.setCell(rows[i], c, new TableDataRow(key, name));
                        }
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });

    analyteTable.addBeforeRowAddedHandler(new BeforeRowAddedHandler() {
        public void onBeforeRowAdded(BeforeRowAddedEvent event) {
            TableDataRow row;
            int index;
            try {
                row = event.getRow();
                index = event.getIndex();

                //
                // if the table is empty and an analyte row is to be added
                // then a header row should be added before that row
                //
                if (!(Boolean) row.data && index == 0) {
                    addAnalyteRow = true;
                    event.cancel();
                    analyteTable.addRow(createHeaderRow());
                }

            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });

    analyteTable.addRowAddedHandler(new RowAddedHandler() {
        public void onRowAdded(RowAddedEvent event) {
            TableDataRow prow, row, nrow, addrow;
            int index, dindex;
            TestAnalyteManager man;

            man = null;

            try {
                man = manager.getTestAnalytes();
            } catch (Exception e) {
                Window.alert(e.getMessage());
                e.printStackTrace();
            }

            try {
                row = event.getRow();
                index = event.getIndex();

                //
                // if the row added to the table is an analyte row
                //
                if (!(Boolean) row.data) {
                    //
                    // the row above the current one in the table
                    //
                    prow = analyteTable.getRow(index - 1);

                    //
                    // the index of the list in TestAnalyteManager that
                    // corresponds to the row above the current one
                    //
                    dindex = displayManager.getDataRowIndex(index - 1);

                    //
                    // dindex can be returned as -1 if index-1 excceds the
                    // size of displayManager's index list because the list
                    // corresponding to the new row won't have been added to
                    // the grid maintained by TestAnalyteManager;so if the
                    // number of rows in the table is more than one (index >
                    // 0),
                    // we try to find dindex for the last row in
                    // displayManager's
                    // index list; if prow is a header and has been added in
                    // the middle of the table, (headerAddedInTheMiddle ==
                    // true),
                    // i.e. not at the end, then this means that the list
                    // corresponding to the row above this one which is the
                    // header row exists neither in TestAnalyteManager nor
                    // in
                    // displayManager,thus we need to look at the list
                    // corresponding to the row two places above (index-2)
                    // in the table
                    //
                    if ((dindex == -1 && index > 0) || headerAddedInTheMiddle) {
                        dindex = displayManager.getDataRowIndex(index - 2);
                        headerAddedInTheMiddle = false;
                    }

                    if ((Boolean) prow.data) {
                        //
                        // if there were rows after the header row in the
                        // table
                        // before the current row was added then we need to
                        // find out whether the next row after the current
                        // row is
                        // an analyte row and if it is then the current
                        // has not been added to a new row group but an
                        // existing one
                        // and thus the first boolean argument to addRowAt
                        // is false
                        //
                        if (index + 1 < analyteTable.numRows()) {
                            nrow = analyteTable.getRow(index + 1);
                            if (!(Boolean) nrow.data) {
                                man.addRowAt(dindex, false, false, getNextTempId());
                                displayManager.setDataGrid(man.getAnalytes());
                                analyteTable.selectRow(index);
                                return;
                            }
                        }
                        //
                        // otherwise the header row is for a new row group
                        // and thus the first boolean argument to addRowAt
                        // is true
                        //
                        man.addRowAt(dindex + 1, true, false, getNextTempId());
                    } else {
                        //
                        // if prow is an analyte row then the newly added
                        // row has
                        // not been added to a new group and it will have to
                        // look at row previous to it in the data grid to
                        // copy
                        // data from look
                        //
                        man.addRowAt(dindex + 1, false, true, getNextTempId());
                    }
                    displayManager.setDataGrid(man.getAnalytes());
                    analyteTable.selectRow(index);
                } else if (addAnalyteRow) {
                    //
                    // if the row added is a header row and it's the first
                    // one in the table then an analyte row should be added
                    // after it if the add button was clicked with "Header"
                    // selected
                    //
                    addrow = new TableDataRow(10);
                    addrow.data = new Boolean(false);
                    if (index + 1 >= analyteTable.numRows()) {
                        analyteTable.addRow(addrow);
                    } else {
                        analyteTable.addRow(index + 1, addrow);
                    }
                } else {
                    //
                    // if the row added is a header row and it's the first
                    // one in the table then an analyte row should be added
                    // after it
                    //
                    addAnalyteRow = true;
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });

    analyteTable.addRowDeletedHandler(new RowDeletedHandler() {
        public void onRowDeleted(RowDeletedEvent event) {
            int index, dindex;
            TableDataRow row;
            TestAnalyteViewDO data;
            TestAnalyteManager man;

            index = event.getIndex();
            row = event.getRow();
            man = null;

            try {
                man = manager.getTestAnalytes();
            } catch (Exception e) {
                Window.alert(e.getMessage());
                e.printStackTrace();
            }

            if (!(Boolean) row.data) {
                dindex = displayManager.getDataRowIndex(index);
                data = man.getAnalyteAt(dindex, 0);
                man.removeRowAt(dindex);
                displayManager.setDataGrid(man.getAnalytes());
                ActionEvent.fire(screen, Action.ANALYTE_DELETED, data);
            }
        }
    });

    addMatchesHandlerToAnalyteCells();

    typeId = (Dropdown<Integer>) def.getWidget(TestMeta.getAnalyteTypeId());
    addScreenHandler(typeId, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            TestAnalyteViewDO data;
            int r;

            r = analyteTable.getSelectedRow();

            if (displayManager != null && r != -1) {
                if (anaSelCol == 0)
                    data = displayManager.getObjectAt(r, anaSelCol);
                else
                    data = displayManager.getObjectAt(r, anaSelCol - 1);

                if (data != null)
                    typeId.setSelection(data.getTypeId());
                else
                    typeId.setSelection(null);

            } else {
                //
                // everytime the data on the screen changes, the model in
                // the analyte
                // table gets refreshed; thus there are no rows and columns
                // selected
                // at that point and hence this widget needs to be cleared
                // of any
                // previous selection
                //
                if (typeId.getData() != null)
                    typeId.setSelection(null);
            }
        }

        public void onValueChange(ValueChangeEvent<Integer> event) {
            TestAnalyteViewDO data;
            TableDataRow row, nrow;
            int i, j, index, r[];

            r = analyteTable.getSelectedRows();
            if (r != null && anaSelCol != -1) {
                analyteTable.finishEditing();
                index = r[0];
                row = analyteTable.getRow(index);
                if ((Boolean) row.data) {
                    for (i = 0; i < r.length; i++) {
                        index = r[i];
                        for (j = index; j < analyteTable.numRows(); j++) {
                            data = displayManager.getObjectAt(j, anaSelCol - 1);
                            if (data == null)
                                continue;

                            data.setTypeId(event.getValue());
                            analyteTable.clearCellExceptions(j, anaSelCol);

                            if (j + 1 < analyteTable.numRows()) {
                                nrow = analyteTable.getRow(j + 1);
                                if ((Boolean) nrow.data)
                                    j = analyteTable.numRows();
                            }
                        }
                    }
                } else {
                    for (j = 0; j < r.length; j++) {
                        nrow = analyteTable.getRow(r[j]);
                        if ((Boolean) nrow.data)
                            break;
                        data = displayManager.getObjectAt(r[j], anaSelCol);
                        data.setTypeId(event.getValue());
                        analyteTable.clearCellExceptions(r[j], anaSelCol);
                    }
                }
            }
        }

        public void onStateChange(StateChangeEvent<State> event) {
            //
            // everytime the state of the screen changes, the model in the
            // analyte
            // table gets refreshed; thus there are no rows and columns
            // selected
            // at that point and hence this widget needs to be cleared of
            // any
            // previous selection and disabled
            //
            if (typeId.getData() != null)
                typeId.setSelection(null);

            typeId.enable(false);
        }
    });

    isReportable = (CheckBox) def.getWidget(TestMeta.getAnalyteIsReportable());
    addScreenHandler(isReportable, new ScreenEventHandler<String>() {
        public void onDataChange(DataChangeEvent event) {
            TestAnalyteViewDO data;
            int ar;

            ar = analyteTable.getSelectedRow();

            if (displayManager != null && ar != -1) {
                if (anaSelCol == 0)
                    data = displayManager.getObjectAt(ar, anaSelCol);
                else
                    data = displayManager.getObjectAt(ar, anaSelCol - 1);

                if (data != null)
                    isReportable.setValue(data.getIsReportable());
                else
                    isReportable.setValue("N");

            } else {
                //
                // everytime the data on the screen changes, the model in
                // the analyte
                // table gets refreshed; thus there are no rows and columns
                // selected
                // at that point and hence this widget needs to be cleared
                // of any
                // previous affirmative choices made
                //
                isReportable.setValue("N");
            }

        }

        public void onValueChange(ValueChangeEvent<String> event) {
            TestAnalyteViewDO data;
            TableDataRow row, nrow;
            int i, j, index, r[];

            r = analyteTable.getSelectedRows();
            if (r != null && anaSelCol != -1) {
                analyteTable.finishEditing();
                index = r[0];
                row = analyteTable.getRow(index);
                if ((Boolean) row.data) {
                    for (i = 0; i < r.length; i++) {
                        index = r[i];
                        for (j = index; j < analyteTable.numRows(); j++) {
                            data = displayManager.getObjectAt(j, anaSelCol - 1);
                            if (data == null)
                                continue;

                            data.setIsReportable(event.getValue());

                            if (j + 1 < analyteTable.numRows()) {
                                nrow = analyteTable.getRow(j + 1);
                                if ((Boolean) nrow.data)
                                    j = analyteTable.numRows();
                            }
                        }
                    }
                } else {
                    for (j = 0; j < r.length; j++) {
                        nrow = analyteTable.getRow(r[j]);
                        if ((Boolean) nrow.data)
                            break;
                        data = displayManager.getObjectAt(r[j], anaSelCol);
                        data.setIsReportable(event.getValue());
                    }
                }
            }
        }

        public void onStateChange(StateChangeEvent<State> event) {
            //
            // everytime state of the screen changes, the model in the
            // analyte
            // table gets refreshed; thus there are no rows and columns
            // selected
            // at that point and hence this widget needs to be cleared of
            // any
            // previous affirmative choice made and disabled
            //
            isReportable.setValue("N");
            isReportable.enable(false);
        }
    });

    scriptletId = (Dropdown<Integer>) def.getWidget(TestMeta.getAnalyteScriptletId());
    addScreenHandler(scriptletId, new ScreenEventHandler<Integer>() {
        public void onDataChange(DataChangeEvent event) {
            TestAnalyteViewDO data;
            int r;

            r = analyteTable.getSelectedRow();

            if (displayManager != null && r != -1) {
                if (anaSelCol == 0)
                    data = displayManager.getObjectAt(r, anaSelCol);
                else
                    data = displayManager.getObjectAt(r, anaSelCol - 1);

                if (data != null)
                    scriptletId.setSelection(data.getScriptletId());
                else
                    scriptletId.setSelection(null);
            } else {
                //
                // everytime the data on the screen changes, the model in
                // the analyte
                // table gets refreshed; thus there are no rows and columns
                // selected
                // at that point and hence this widget needs to be cleared
                // of any
                // previous selection and disabled
                //
                scriptletId.setSelection(null);
            }
        }

        public void onValueChange(ValueChangeEvent<Integer> event) {
            TestAnalyteViewDO data;
            TableDataRow row, nrow;
            int i, j, index, r[];

            r = analyteTable.getSelectedRows();
            if (r != null && anaSelCol != -1) {
                analyteTable.finishEditing();
                index = r[0];
                row = analyteTable.getRow(index);
                if ((Boolean) row.data) {
                    for (i = 0; i < r.length; i++) {
                        index = r[i];
                        for (j = index; j < analyteTable.numRows(); j++) {
                            data = displayManager.getObjectAt(j, anaSelCol - 1);
                            if (data == null)
                                continue;

                            data.setScriptletId(event.getValue());

                            if (j + 1 < analyteTable.numRows()) {
                                nrow = analyteTable.getRow(j + 1);
                                if ((Boolean) nrow.data)
                                    j = analyteTable.numRows();
                            }
                        }
                    }
                } else {
                    for (j = 0; j < r.length; j++) {
                        nrow = analyteTable.getRow(r[j]);
                        if ((Boolean) nrow.data)
                            break;
                        data = displayManager.getObjectAt(r[j], anaSelCol);
                        data.setScriptletId(event.getValue());
                    }
                }
            }
        }

        public void onStateChange(StateChangeEvent<State> event) {
            //
            // everytime the state of the screen changes, the model in the
            // analyte
            // table gets refreshed; thus there are no rows and columns
            // selected
            // at that point and hence this widget needs to be cleared of
            // any
            // previous selection and disabled
            //
            scriptletId.setSelection(null);
            scriptletId.enable(false);
        }
    });

    tableActions = (Dropdown<String>) def.getWidget("tableActions");
    addScreenHandler(tableActions, new ScreenEventHandler<Integer>() {
        public void onStateChange(StateChangeEvent<State> event) {
            tableActions.enable(EnumSet.of(State.ADD, State.UPDATE).contains(event.getState()));
            tableActions.setQueryMode(false);
            if (tableActions.getData() != null
                    && EnumSet.of(State.ADD, State.UPDATE).contains(event.getState()))
                tableActions.setSelection("analyte");
        }
    });

    addButton = (AppButton) def.getWidget("addButton");
    addScreenHandler(addButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            analyteTable.finishEditing();
            if ("analyte".equals(tableActions.getValue())) {
                addAnalyte();
            } else if ("column".equals(tableActions.getValue())) {
                addColumn();
            } else {
                addHeader();
            }

            tableActions.setSelection("analyte");

        }

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

    removeButton = (AppButton) def.getWidget("removeButton");
    addScreenHandler(removeButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            analyteTable.finishEditing();
            if ("analyte".equals(tableActions.getValue())) {
                removeAnalyte();
            } else if ("column".equals(tableActions.getValue())) {
                removeColumn();
            } else {
                removeHeader();
            }

            tableActions.setSelection("analyte");
        }

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

    resultTabPanel = (ScrollableTabBar) def.getWidget("resultTabPanel");

    addScreenHandler(resultTabPanel, new ScreenEventHandler<Object>() {
        public void onDataChange(DataChangeEvent event) {
            int numTabs;
            TestResultManager man;

            man = null;
            try {
                man = manager.getTestResults();
            } catch (Exception e) {
                Window.alert(e.getMessage());
                e.printStackTrace();
            }

            resultTabPanel.clearTabs();
            numTabs = man.groupCount();

            for (int i = 0; i < numTabs; i++)
                resultTabPanel.addTab(String.valueOf(i + 1));
            if (numTabs > 0)
                resultTabPanel.selectTab(0);
        }

    });

    resultTabPanel.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
        public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
            resultTable.finishEditing();
        }
    });

    resultTabPanel.addSelectionHandler(new SelectionHandler<Integer>() {
        public void onSelection(SelectionEvent<Integer> event) {
            int tab;

            tab = resultTabPanel.getTabBar().getSelectedTab();
            resultTable.load(getResultTableModel(tab));
            showErrorsForResultGroup(tab);
        }
    });

    resultTable = (TableWidget) def.getWidget("resultTable");
    addScreenHandler(resultTable, new ScreenEventHandler<ArrayList<TableDataRow>>() {
        public void onDataChange(DataChangeEvent event) {
            int selTab;

            //
            // this table is not queried by,so it needs to be cleared in
            // query mode
            //
            if (state != State.QUERY) {
                selTab = resultTabPanel.getTabBar().getSelectedTab();
                resultTable.load(getResultTableModel(selTab));
            } else {
                resultTable.load(new ArrayList<TableDataRow>());
            }
        }

        public void onStateChange(StateChangeEvent<State> event) {
            resultTable.enable(true);
        }
    });

    resultTable.addBeforeCellEditedHandler(new BeforeCellEditedHandler() {
        public void onBeforeCellEdited(BeforeCellEditedEvent event) {
            int r, c, group;

            if (state != State.ADD && state != State.UPDATE)
                event.cancel();

            r = event.getRow();
            c = event.getCol();
            group = resultTabPanel.getTabBar().getSelectedTab();

            switch (c) {
            case 0:
                clearResultCellError(group, r, TestMeta.getResultUnitOfMeasureId());
                break;
            case 1:
                clearResultCellError(group, r, TestMeta.getResultTypeId());
                break;
            case 2:
                clearResultCellError(group, r, TestMeta.getResultValue());
                break;
            }
        }

    });

    resultTable.addCellEditedHandler(new CellEditedHandler() {
        public void onCellUpdated(CellEditedEvent event) {
            int r, c, group;
            TestResultViewDO data;
            Object val;
            TestResultManager man;

            r = event.getRow();
            c = event.getCol();
            val = resultTable.getObject(r, c);
            group = resultTabPanel.getTabBar().getSelectedTab();

            man = null;
            try {
                man = manager.getTestResults();
            } catch (Exception e) {
                Window.alert(e.getMessage());
                e.printStackTrace();
            }

            data = man.getResultAt(group + 1, r);

            switch (c) {
            case 0:
                if (val != null)
                    data.setUnitOfMeasureId((Integer) val);
                else
                    data.setUnitOfMeasureId(null);
                break;
            case 1:
                if (val != null)
                    data.setTypeId((Integer) val);
                else
                    data.setTypeId(null);

                resultTable.clearCellExceptions(r, 2);
                try {
                    validateValue(data, (String) resultTable.getObject(r, 2));
                } catch (Exception e) {
                    resultTable.setCellException(r, 2, e);
                    addToResultErrorList(group, r, TestMeta.getResultValue(), e.getMessage());
                }
                break;
            case 2:
                resultTable.clearCellExceptions(r, c);
                try {
                    validateValue(data, (String) val);
                } catch (Exception e) {
                    resultTable.setCellException(r, c, e);
                    addToResultErrorList(group, r, TestMeta.getResultValue(), e.getMessage());
                }
                ActionEvent.fire(screen, Action.RESULT_CHANGED, data);
                break;
            case 3:
                if (val != null)
                    data.setFlagsId((Integer) val);
                else
                    data.setFlagsId(null);
                break;
            case 4:
                if (val != null)
                    data.setSignificantDigits((Integer) val);
                else
                    data.setSignificantDigits(null);
                break;
            case 5:
                if (val != null)
                    data.setRoundingMethodId((Integer) val);
                else
                    data.setRoundingMethodId(null);
                break;
            }
        }
    });

    resultTable.addRowAddedHandler(new RowAddedHandler() {
        public void onRowAdded(RowAddedEvent event) {
            int selTab;
            TestResultManager man;

            man = null;
            try {
                man = manager.getTestResults();
            } catch (Exception e) {
                Window.alert(e.getMessage());
                e.printStackTrace();
            }

            if (man.groupCount() == 0)
                man.addResultGroup();

            selTab = resultTabPanel.getTabBar().getSelectedTab();
            man.addResult(selTab + 1, getNextTempId());
        }
    });

    resultTable.addRowDeletedHandler(new RowDeletedHandler() {
        public void onRowDeleted(RowDeletedEvent event) {
            int r, selTab;
            TestResultViewDO data;
            TestResultManager man;

            man = null;
            try {
                man = manager.getTestResults();
            } catch (Exception e) {
                Window.alert(e.getMessage());
                e.printStackTrace();
            }

            selTab = resultTabPanel.getTabBar().getSelectedTab();
            r = event.getIndex();
            data = man.getResultAt(selTab + 1, r);

            man.removeResultAt(selTab + 1, r);

            ActionEvent.fire(screen, Action.RESULT_DELETED, data);
        }
    });

    addResultTabButton = (AppButton) def.getWidget("addResultTabButton");
    addScreenHandler(addResultTabButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            int count;
            TestResultManager man;

            man = null;
            try {
                man = manager.getTestResults();
            } catch (Exception e) {
                Window.alert(e.getMessage());
                e.printStackTrace();
            }

            count = resultTabPanel.getTabBar().getTabCount();

            resultTabPanel.addTab(String.valueOf(count + 1));
            resultTabPanel.selectTab(count);
            man.addResultGroup();

        }

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

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

            r = resultTable.getSelectedRow();

            if (r != -1 && resultTable.numRows() > 0)
                resultTable.deleteRow(r);
        }

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

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

            numTabs = resultTabPanel.getTabBar().getTabCount();

            if (numTabs == 0) {
                resultTabPanel.addTab(String.valueOf(1));
                resultTabPanel.selectTab(0);
            }

            resultTable.addRow();
            n = resultTable.numRows() - 1;
            resultTable.selectRow(n);
            resultTable.scrollToSelection();
            resultTable.startEditing(n, 1);
        }

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

    dictionaryLookUpButton = (AppButton) def.getWidget("dictionaryLookUpButton");
    addScreenHandler(dictionaryLookUpButton, new ScreenEventHandler<Object>() {
        public void onClick(ClickEvent event) {
            resultTable.finishEditing();
            showDictionary(null, null);
        }

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

    addAnalyteRow = true;
    anaSelCol = -1;
    screen = this;
    tempId = -1;
    headerAddedInTheMiddle = false;
    resultErrorList = null;
    canAddRemoveColumn = false;

}

From source file:org.openelis.ui.screen.ScreenCellNavigator.java

License:Open Source License

protected void initialize() {

    if (table != null) {
        table.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
            public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
                // since we don't know if the fetch will succeed, we are
                // going
                // cancel this selection and select the table row ourselves.
                if (enable && selection != event.getItem())
                    select(event.getItem());
                // else
                // event.cancel();
            }/*from www .j av  a 2  s .co  m*/
        });
        table.addBeforeCellEditedHandler(new BeforeCellEditedHandler() {
            public void onBeforeCellEdited(BeforeCellEditedEvent event) {
                event.cancel();
            }
        });
        // we don't want the table to get focus; we can still select because
        // we will get the onBeforeSelection event.
        table.setEnabled(false);
    }

    if (atozNext != null) {
        atozNext.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                setPage(query.getPage() + 1);
            }
        });
    }

    if (atozPrev != null) {
        atozPrev.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                setPage(query.getPage() - 1);
            }
        });
    }
}