Search in sources :

Example 16 with EventListener

use of org.zkoss.zk.ui.event.EventListener in project spatial-portal by AtlasOfLivingAustralia.

the class LayerLegendGeneralComposer method afterCompose.

@Override
public void afterCompose() {
    super.afterCompose();
    MapLayer llc2MapLayer = null;
    Map m = Executions.getCurrent().getArg();
    if (m != null) {
        for (Object o : m.entrySet()) {
            if (((Map.Entry) o).getKey() instanceof String && "map_layer".equals(((Map.Entry) o).getKey())) {
                llc2MapLayer = (MapLayer) ((Map.Entry) o).getValue();
            }
        }
    }
    cbColour.setSelectedIndex(0);
    getMapComposer().setFacetsOpenListener(new EventListener() {

        @Override
        public void onEvent(Event event) throws Exception {
            cbColour.open();
        }
    });
    getMapComposer().setLayerLegendNameRefresh(new EventListener() {

        @Override
        public void onEvent(Event event) throws Exception {
            txtLayerName.setValue((String) event.getData());
        }
    });
    init(llc2MapLayer, llc2MapLayer.getSpeciesQuery(), llc2MapLayer.getRedVal(), llc2MapLayer.getGreenVal(), llc2MapLayer.getBlueVal(), llc2MapLayer.getSizeVal(), (int) (llc2MapLayer.getOpacity() * 100), llc2MapLayer.getColourMode(), (StringConstants.GRID.equals(llc2MapLayer.getColourMode())) ? 0 : ((llc2MapLayer.isClustered()) ? 1 : 2), llc2MapLayer.getSizeUncertain());
    getFellow("btnSearch").addEventListener(StringConstants.ONCLICK, new EventListener() {

        @Override
        public void onEvent(Event event) throws Exception {
            List<String[]> legendLinesFiltered = new ArrayList<String[]>();
            String txt = ((Textbox) getFellow("txtSearch")).getValue().toLowerCase();
            if (txt.length() > 0) {
                Integer groupCount = mapLayer.getClassificationGroupCount();
                JSONArray groupObjects = mapLayer.getClassificationObjects();
                List<JSONObject> model = new ArrayList<JSONObject>();
                for (int i = 0; i < groupCount; i++) {
                    if (((JSONObject) groupObjects.get(i)).get("name").toString().toLowerCase().contains(txt)) {
                        model.add((JSONObject) groupObjects.get(i));
                    }
                }
                lbClassificationGroup.setModel(new SimpleListModel(model));
                lbClassificationGroup.setActivePage(0);
                ((Button) getFellow("btnClear")).setDisabled(false);
            }
        }
    });
    getFellow("btnClear").addEventListener(StringConstants.ONCLICK, new EventListener() {

        @Override
        public void onEvent(Event event) throws Exception {
            ((Textbox) getFellow("txtSearch")).setValue("");
            ((Button) getFellow("btnClear")).setDisabled(true);
            Integer groupCount = mapLayer.getClassificationGroupCount();
            JSONArray groupObjects = mapLayer.getClassificationObjects();
            List<JSONObject> model = new ArrayList<JSONObject>();
            for (int i = 0; i < groupCount; i++) {
                model.add((JSONObject) groupObjects.get(i));
            }
            lbClassificationGroup.setModel(new SimpleListModel(model));
            lbClassificationGroup.setActivePage(0);
        }
    });
}
Also used : MapLayer(au.org.emii.portal.menu.MapLayer) JSONArray(org.json.simple.JSONArray) ParseException(org.json.simple.parser.ParseException) JSONObject(org.json.simple.JSONObject) CheckEvent(org.zkoss.zk.ui.event.CheckEvent) Event(org.zkoss.zk.ui.event.Event) JSONObject(org.json.simple.JSONObject) LegendObject(au.org.ala.legend.LegendObject) List(java.util.List) EventListener(org.zkoss.zk.ui.event.EventListener)

Example 17 with EventListener

use of org.zkoss.zk.ui.event.EventListener in project spatial-portal by AtlasOfLivingAustralia.

the class LayerLegendGeneralComposer method setupForClassificationLayers.

private void setupForClassificationLayers() {
    if (mapLayer.isPolygonLayer())
        return;
    String activeLayerName = StringConstants.NONE;
    JSONObject field = null;
    JSONObject layer = null;
    if (mapLayer != null && mapLayer.getUri() != null) {
        if (mapLayer.getBaseUri() != null) {
            activeLayerName = mapLayer.getBaseUri().replaceAll("^.*&style=", "").replaceAll("&.*", "").replaceAll("_style", "");
        } else {
            activeLayerName = mapLayer.getUri().replaceAll("^.*&style=", "").replaceAll("&.*", "").replaceAll("_style", "");
        }
        field = CommonData.getLayer(activeLayerName);
        if (field == null)
            return;
        layer = (JSONObject) field.get("layer");
    }
    LOGGER.debug("ACTIVE LAYER: " + activeLayerName);
    if (mapLayer != null && mapLayer.getSubType() == LayerUtilitiesImpl.ALOC) {
        divClassificationPicker.setVisible(true);
        //reset content
        Integer groupCount = mapLayer.getClassificationGroupCount();
        if (groupCount == null) {
            mapLayer.setClassificationGroupCount(getClassificationGroupCount(mapLayer.getName().replace("aloc_", "")));
            groupCount = 0;
        }
        for (int i = cbClassificationGroup.getItemCount() - 1; i >= 0; i--) {
            cbClassificationGroup.removeItemAt(i);
        }
        Comboitem ci = new Comboitem(StringConstants.NONE);
        ci.setParent(cbClassificationGroup);
        for (int i = 1; i <= groupCount; i++) {
            new Comboitem("Group " + i).setParent(cbClassificationGroup);
        }
        //is there a current selection?
        Integer groupSelection = mapLayer.getClassificationSelection();
        if (groupSelection == null) {
            groupSelection = 0;
            mapLayer.setClassificationSelection(groupSelection);
        }
        cbClassificationGroup.setSelectedIndex(groupSelection);
        getFellow("btnCreateArea").setVisible(false);
        cbClassificationGroup.setVisible(true);
        lbClassificationGroup.setVisible(false);
        hboxClassificationGroup.setVisible(false);
    } else if (layer != null && layer.containsKey("type") && layer.get("type").toString().equalsIgnoreCase("contextual")) {
        divClassificationPicker.setVisible(true);
        if (mapLayer.getClassificationGroupCount() == null || mapLayer.getClassificationGroupCount() == 0) {
            //build
            String fieldId = field.get(StringConstants.ID).toString();
            JSONParser jp = new JSONParser();
            JSONObject objJson = null;
            try {
                objJson = (JSONObject) jp.parse(Util.readUrl(CommonData.getLayersServer() + "/field/" + fieldId));
            } catch (ParseException e) {
                LOGGER.error("failed to parse for: " + fieldId);
            }
            JSONArray objects = (JSONArray) objJson.get("objects");
            //sort
            List<JSONObject> list = objects.subList(0, objects.size());
            Collections.sort(list, new Comparator<JSONObject>() {

                @Override
                public int compare(JSONObject o1, JSONObject o2) {
                    String s1 = (o1 == null || !o1.containsKey("name")) ? "" : o1.get("name").toString();
                    String s2 = (o2 == null || !o2.containsKey("name")) ? "" : o2.get("name").toString();
                    return s1.compareTo(s2);
                }
            });
            JSONArray obj = new JSONArray();
            obj.addAll(list);
            mapLayer.setClassificationGroupCount(obj.size());
            mapLayer.setClassificationObjects(obj);
        }
        //reset content
        Integer groupCount = mapLayer.getClassificationGroupCount();
        JSONArray groupObjects = mapLayer.getClassificationObjects();
        lbClassificationGroup.setItemRenderer(new ListitemRenderer<JSONObject>() {

            @Override
            public void render(Listitem item, JSONObject data, int index) throws Exception {
                Checkbox cb = new Checkbox();
                final int idx = index;
                cb.addEventListener("onCheck", new EventListener<Event>() {

                    @Override
                    public void onEvent(Event event) throws Exception {
                        if (mapLayer != null) {
                            lbClassificationGroup.setMultiple(true);
                            String v = ((Listcell) event.getTarget().getParent().getParent().getChildren().get(1)).getLabel();
                            if (((CheckEvent) event).isChecked()) {
                                selectedList.add(v);
                            } else {
                                selectedList.remove(v);
                            }
                            lblSelectedCount.setValue(selectedList.size() + " checked");
                            getFellow("clearSelection").setVisible(selectedList.size() > 0);
                            getFellow("createInGroup").setVisible(selectedList.size() > 0);
                            if (getFellowIfAny("createOutGroup") != null)
                                getFellow("createOutGroup").setVisible(selectedList.size() > 0);
                            highlightSelect(idx);
                        }
                    }
                });
                determineCheckboxState(cb, data.get("name").toString());
                Listcell lc;
                lc = new Listcell();
                cb.setParent(lc);
                lc.setParent(item);
                lc = new Listcell(data.get("name").toString());
                lc.setParent(item);
                lc = new Listcell();
                Image img = new Image();
                img.setTooltip("Create as an area layer");
                img.setClass("icon-plus-sign");
                img.setParent(lc);
                lc.setParent(item);
                final JSONObject j = data;
                img.addEventListener("onClick", new EventListener<Event>() {

                    @Override
                    public void onEvent(Event event) throws Exception {
                        createAreaEcho(j.get("pid").toString());
                    }
                });
                lc = new Listcell();
                img = new Image();
                img.setTooltip("Zoom to area");
                img.setClass("icon-zoom-in");
                img.setParent(lc);
                lc.setParent(item);
                img.addEventListener("onClick", new EventListener<Event>() {

                    @Override
                    public void onEvent(Event event) throws Exception {
                        List<Double> b = Util.getBoundingBox(j.get("bbox").toString());
                        BoundingBox bbox = new BoundingBox();
                        bbox.setMinLongitude(b.get(0).floatValue());
                        bbox.setMinLatitude(b.get(1).floatValue());
                        bbox.setMaxLongitude(b.get(2).floatValue());
                        bbox.setMaxLatitude(b.get(3).floatValue());
                        getMapComposer().getOpenLayersJavascript().execute(getMapComposer().getOpenLayersJavascript().zoomToBoundingBox(bbox, false));
                    }
                });
            }
        });
        lbClassificationGroup.addEventListener("onSelect", new EventListener<Event>() {

            @Override
            public void onEvent(Event event) throws Exception {
                if (mapLayer != null) {
                    highlightSelect(lbClassificationGroup.getSelectedIndex());
                }
            }
        });
        List<JSONObject> model = new ArrayList<JSONObject>();
        for (int i = 0; i < groupCount; i++) {
            model.add((JSONObject) groupObjects.get(i));
        }
        lbClassificationGroup.setModel(new SimpleListModel(model));
        //is there a current selection?
        Integer groupSelection = mapLayer.getClassificationSelection();
        if (groupSelection == null) {
            groupSelection = 0;
            mapLayer.setClassificationSelection(groupSelection);
        }
        getFellow("btnCreateArea").setVisible(true);
        getFellow("btnCreateArea").setVisible(false);
        cbClassificationGroup.setVisible(false);
        lbClassificationGroup.setVisible(true);
        hboxClassificationGroup.setVisible(true);
    } else {
        getFellow("btnCreateArea").setVisible(false);
        divClassificationPicker.setVisible(false);
    }
}
Also used : JSONArray(org.json.simple.JSONArray) Image(org.zkoss.zul.Image) ParseException(org.json.simple.parser.ParseException) JSONObject(org.json.simple.JSONObject) Checkbox(org.zkoss.zul.Checkbox) BoundingBox(au.org.emii.portal.value.BoundingBox) CheckEvent(org.zkoss.zk.ui.event.CheckEvent) Event(org.zkoss.zk.ui.event.Event) JSONParser(org.json.simple.parser.JSONParser) List(java.util.List) ParseException(org.json.simple.parser.ParseException) EventListener(org.zkoss.zk.ui.event.EventListener)

Example 18 with EventListener

use of org.zkoss.zk.ui.event.EventListener in project spatial-portal by AtlasOfLivingAustralia.

the class LayerLegendScatterplotController method afterCompose.

@Override
public void afterCompose() {
    super.afterCompose();
    this.addEventListener("onSize", new EventListener() {

        @Override
        public void onEvent(Event event) throws Exception {
            redraw();
        }
    });
}
Also used : Event(org.zkoss.zk.ui.event.Event) EventListener(org.zkoss.zk.ui.event.EventListener)

Example 19 with EventListener

use of org.zkoss.zk.ui.event.EventListener in project spatial-portal by AtlasOfLivingAustralia.

the class UtilityComposer method afterCompose.

@Override
public void afterCompose() {
    super.afterCompose();
    LOGGER.debug("registered UtilityComposer event listeners");
    addEventListener("onMove", new EventListener() {

        public void onEvent(Event event) throws Exception {
            onNudgeToView();
        }
    });
    //args may be lost if not used in afterCompose
    args = Executions.getCurrent().getArg();
}
Also used : Event(org.zkoss.zk.ui.event.Event) EventListener(org.zkoss.zk.ui.event.EventListener)

Example 20 with EventListener

use of org.zkoss.zk.ui.event.EventListener in project adempiere by adempiere.

the class WMRPDetailed method statInit.

private void statInit() throws Exception {
    //Resource Lookup 
    // Base Language
    Language language = Language.getLoginLanguage();
    MLookup resourceL = MLookupFactory.get(getCtx(), p_WindowNo, MColumn.getColumn_ID(MResource.Table_Name, MResource.COLUMNNAME_S_Resource_ID), DisplayType.TableDir, language, MResource.COLUMNNAME_S_Resource_ID, 0, false, MResource.Table_Name + "." + MResource.COLUMNNAME_ManufacturingResourceType + "= '" + MResource.MANUFACTURINGRESOURCETYPE_Plant + "'");
    fResource_ID = new WSearchEditor(MPPMRP.COLUMNNAME_S_Resource_ID, false, false, true, resourceL) {

        private final long serialVersionUID = 1L;

        public void setValue(Object arg0) {
            super.setValue(arg0);
        }

        ;
    };
    fPlanner_ID = new WSearchEditor(MPPMRP.COLUMNNAME_Planner_ID, false, false, true, MLookupFactory.get(getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MPPProductPlanning.Table_Name, MPPMRP.COLUMNNAME_Planner_ID), DisplayType.Table)) {

        private final long serialVersionUID = 1L;

        public void setValue(Object arg0) {
            super.setValue(arg0);
        }

        ;
    };
    fWarehouse_ID = new WSearchEditor(MPPMRP.COLUMNNAME_M_Warehouse_ID, false, false, true, MLookupFactory.get(getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MWarehouse.Table_Name, MPPMRP.COLUMNNAME_M_Warehouse_ID), DisplayType.TableDir)) {

        private final long serialVersionUID = 1L;

        public void setValue(Object arg0) {
            super.setValue(arg0);
        }

        ;
    };
    fMaster.setSelected(false);
    fMaster.setEnabled(false);
    fMRPReq.setSelected(false);
    fMRPReq.setEnabled(false);
    fCreatePlan.setSelected(false);
    fCreatePlan.setEnabled(false);
    lUOM.setText(Msg.translate(getCtx(), MUOM.COLUMNNAME_C_UOM_ID));
    fUOM.setReadonly(true);
    lType.setText(Msg.translate(getCtx(), MPPProductPlanning.COLUMNNAME_Order_Policy));
    fType.setReadonly(true);
    lOrderPeriod.setText(Msg.translate(getCtx(), MPPProductPlanning.COLUMNNAME_Order_Period));
    fOrderPeriod.setReadWrite(false);
    lTimefence.setText(Msg.translate(getCtx(), MPPProductPlanning.COLUMNNAME_TimeFence));
    fTimefence.setReadWrite(false);
    lLeadtime.setText(Msg.translate(getCtx(), MPPProductPlanning.COLUMNNAME_DeliveryTime_Promised));
    fLeadtime.setReadWrite(false);
    lMinOrd.setText(Msg.translate(getCtx(), MPPProductPlanning.COLUMNNAME_Order_Min));
    fMinOrd.setReadWrite(false);
    lMaxOrd.setText(Msg.translate(getCtx(), MPPProductPlanning.COLUMNNAME_Order_Max));
    fMaxOrd.setReadWrite(false);
    lOrdMult.setText(Msg.translate(getCtx(), MPPProductPlanning.COLUMNNAME_Order_Pack));
    fOrdMult.setReadWrite(false);
    lOrderQty.setText(Msg.translate(getCtx(), MPPProductPlanning.COLUMNNAME_Order_Qty));
    fOrderQty.setReadWrite(false);
    lYield.setText(Msg.translate(getCtx(), MPPProductPlanning.COLUMNNAME_Yield));
    fYield.setReadWrite(false);
    lOnhand.setText(Msg.translate(getCtx(), MStorage.COLUMNNAME_QtyOnHand));
    fOnhand.setReadWrite(false);
    lSafetyStock.setText(Msg.translate(getCtx(), MPPProductPlanning.COLUMNNAME_SafetyStock));
    fSafetyStock.setReadWrite(false);
    lReserved.setText(Msg.translate(getCtx(), MStorage.COLUMNNAME_QtyReserved));
    fReserved.setReadWrite(false);
    lAvailable.setText(Msg.translate(getCtx(), "QtyAvailable"));
    fAvailable.setReadWrite(false);
    lOrdered.setText(Msg.translate(getCtx(), MPPOrder.COLUMNNAME_QtyOrdered));
    fOrdered.setReadWrite(false);
    //Product Lookup
    fProduct_ID = new WSearchEditor(MPPMRP.COLUMNNAME_M_Product_ID, true, false, true, MLookupFactory.get(getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MProduct.Table_Name, MPPMRP.COLUMNNAME_M_Product_ID), DisplayType.Search)) {

        private final long serialVersionUID = 1L;

        public void setValue(Object arg0) {
            super.setValue(arg0);
        }

        ;
    };
    fMaster.setText(Msg.translate(getCtx(), MPPProductPlanning.COLUMNNAME_IsMPS));
    fMRPReq.setText(Msg.translate(getCtx(), MPPProductPlanning.COLUMNNAME_IsRequiredMRP));
    fCreatePlan.setText(Msg.translate(getCtx(), MPPProductPlanning.COLUMNNAME_IsCreatePlan));
    //AttributeSet Button
    fAttrSetInstance_ID = new Button() {

        private final long serialVersionUID = 1L;

        private Object m_value;

        public void setLabel(String text) {
            if (text == null) {
                text = "---";
            }
            if (text.length() > 23) {
                text = text.substring(0, 20) + "...";
            }
            super.setLabel(text);
        }

        public void setValue(Object arg0) {
            m_value = arg0;
            int i = (arg0 instanceof Integer) ? ((Integer) arg0).intValue() : 0;
            if (i == 0) {
                setLabel(null);
            }
        }

        public Object getValue() {
            return m_value;
        }
    };
    fAttrSetInstance_ID.addActionListener(new EventListener() {

        @Override
        public void onEvent(Event event) throws Exception {
            selectAttributeSetInstance();
        }
    });
    //
    fDateFrom.getComponent().setTooltiptext(Msg.translate(getCtx(), MLot.COLUMNNAME_DateFrom));
    fDateTo.getComponent().setTooltiptext(Msg.translate(getCtx(), MLot.COLUMNNAME_DateTo));
    fSupplyType = new WSearchEditor(MPPMRP.COLUMNNAME_TypeMRP, false, false, true, MLookupFactory.get(getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MPPMRP.Table_Name, MPPMRP.COLUMNNAME_TypeMRP), DisplayType.List));
    Rows rows = null;
    Row row = null;
    rows = new Rows();
    rows.setParent(parameterPanel);
    //  1st Row
    row = rows.newRow();
    row.appendChild(lProduct_ID.rightAlign());
    row.appendChild(fProduct_ID.getComponent());
    row.appendChild(lUOM.rightAlign());
    row.appendChild(fUOM);
    row.appendChild(lType.rightAlign());
    row.appendChild(fType);
    //  2nd Row
    row = rows.newRow();
    row.appendChild(lAttrSetInstance_ID.rightAlign());
    row.appendChild(fAttrSetInstance_ID);
    row.appendChild(lOnhand.rightAlign());
    row.appendChild(fOnhand.getComponent());
    row.appendChild(lOrderPeriod.rightAlign());
    row.appendChild(fOrderPeriod.getComponent());
    //  3rd Row
    row = rows.newRow();
    row.appendChild(lPlanner_ID.rightAlign());
    row.appendChild(fPlanner_ID.getComponent());
    row.appendChild(lSafetyStock.rightAlign());
    row.appendChild(fSafetyStock.getComponent());
    row.appendChild(lMinOrd.rightAlign());
    row.appendChild(fMinOrd.getComponent());
    //  4th Row
    row = rows.newRow();
    row.appendChild(lWarehouse_ID.rightAlign());
    row.appendChild(fWarehouse_ID.getComponent());
    row.appendChild(lReserved.rightAlign());
    row.appendChild(fReserved.getComponent());
    row.appendChild(lMaxOrd.rightAlign());
    row.appendChild(fMaxOrd.getComponent());
    //  5th Row
    row = rows.newRow();
    row.appendChild(lResource_ID.rightAlign());
    row.appendChild(fResource_ID.getComponent());
    row.appendChild(lAvailable.rightAlign());
    row.appendChild(fAvailable.getComponent());
    row.appendChild(lOrdMult.rightAlign());
    row.appendChild(fOrdMult.getComponent());
    //  6th Row
    row = rows.newRow();
    row.appendChild(lDateFrom.rightAlign());
    row.appendChild(fDateFrom.getComponent());
    row.appendChild(lOrdered.rightAlign());
    row.appendChild(fOrdered.getComponent());
    row.appendChild(lOrderQty.rightAlign());
    row.appendChild(fOrderQty.getComponent());
    //  7th Row
    row = rows.newRow();
    row.appendChild(lDateTo.rightAlign());
    row.appendChild(fDateTo.getComponent());
    row.appendChild(new Space());
    row.appendChild(new Space());
    row.appendChild(lTimefence.rightAlign());
    row.appendChild(fTimefence.getComponent());
    //  8th Row
    row = rows.newRow();
    row.appendChild(new Space());
    row.appendChild(fMaster);
    row.appendChild(new Space());
    row.appendChild(fCreatePlan);
    row.appendChild(lLeadtime.rightAlign());
    row.appendChild(fLeadtime.getComponent());
    //  9th Row
    row = rows.newRow();
    row.appendChild(new Space());
    row.appendChild(new Space());
    row.appendChild(new Space());
    row.appendChild(fMRPReq);
    row.appendChild(lYield.rightAlign());
    row.appendChild(fYield.getComponent());
}
Also used : Space(org.zkoss.zul.Space) MLookup(org.compiere.model.MLookup) DBException(org.adempiere.exceptions.DBException) SQLException(java.sql.SQLException) Language(org.compiere.util.Language) Button(org.adempiere.webui.component.Button) WSearchEditor(org.adempiere.webui.editor.WSearchEditor) Event(org.zkoss.zk.ui.event.Event) WTableModelEvent(org.adempiere.webui.event.WTableModelEvent) ListDataEvent(org.zkoss.zul.event.ListDataEvent) EventListener(org.zkoss.zk.ui.event.EventListener) Row(org.adempiere.webui.component.Row) Rows(org.adempiere.webui.component.Rows)

Aggregations

EventListener (org.zkoss.zk.ui.event.EventListener)50 Event (org.zkoss.zk.ui.event.Event)42 IOException (java.io.IOException)13 JSONObject (org.json.simple.JSONObject)11 CheckEvent (org.zkoss.zk.ui.event.CheckEvent)7 ForwardEvent (org.zkoss.zk.ui.event.ForwardEvent)7 LegendObject (au.org.ala.legend.LegendObject)5 Component (org.zkoss.zk.ui.Component)5 MapLayer (au.org.emii.portal.menu.MapLayer)4 SQLException (java.sql.SQLException)4 ValueChangeEvent (org.adempiere.exceptions.ValueChangeEvent)4 JSONArray (org.json.simple.JSONArray)4 Div (org.zkoss.zul.Div)4 DashboardPanel (org.adempiere.webui.dashboard.DashboardPanel)3 HeaderPanel (org.adempiere.webui.panel.HeaderPanel)3 SidePanel (org.adempiere.webui.panel.SidePanel)3 JSONParser (org.json.simple.parser.JSONParser)3 ParseException (org.json.simple.parser.ParseException)3 OpenEvent (org.zkoss.zk.ui.event.OpenEvent)3 Center (org.zkoss.zul.Center)3