Search in sources :

Example 11 with Comboitem

use of org.zkoss.zul.Comboitem in project adempiere by adempiere.

the class RolePanel method updateWarehouseList.

private void updateWarehouseList() {
    lstWarehouse.getItems().clear();
    lstWarehouse.setText("");
    Comboitem lstItemOrganisation = lstOrganisation.getSelectedItem();
    if (lstItemOrganisation != null) {
        //  initial warehouse - Elaine 2009/02/06
        UserPreference userPreference = SessionManager.getSessionApplication().getUserPreference();
        String initDefault = userPreference.getProperty(UserPreference.P_WAREHOUSE);
        KeyNamePair organisationKNPair = new KeyNamePair(new Integer((String) lstItemOrganisation.getValue()), lstItemOrganisation.getLabel());
        KeyNamePair[] warehouseKNPairs = login.getWarehouses(organisationKNPair);
        if (warehouseKNPairs != null && warehouseKNPairs.length > 0) {
            for (int i = 0; i < warehouseKNPairs.length; i++) {
                ComboItem ci = new ComboItem(warehouseKNPairs[i].getName(), warehouseKNPairs[i].getID());
                lstWarehouse.appendChild(ci);
                if (warehouseKNPairs[i].getID().equals(initDefault))
                    lstWarehouse.setSelectedItem(ci);
            }
            if (lstWarehouse.getSelectedIndex() == -1 && lstWarehouse.getItemCount() > 0)
                lstWarehouse.setSelectedIndex(0);
        }
    //
    }
}
Also used : Comboitem(org.zkoss.zul.Comboitem) UserPreference(org.adempiere.webui.util.UserPreference) KeyNamePair(org.compiere.util.KeyNamePair) ComboItem(org.adempiere.webui.component.ComboItem)

Example 12 with Comboitem

use of org.zkoss.zul.Comboitem in project adempiere by adempiere.

the class RolePanel method updateOrganisationList.

private void updateOrganisationList() {
    lstOrganisation.getItems().clear();
    lstOrganisation.setText("");
    Comboitem lstItemClient = lstClient.getSelectedItem();
    if (lstItemClient != null) {
        //  initial organisation - Elaine 2009/02/06
        UserPreference userPreference = SessionManager.getSessionApplication().getUserPreference();
        String initDefault = userPreference.getProperty(UserPreference.P_ORG);
        KeyNamePair clientKNPair = new KeyNamePair(new Integer((String) lstItemClient.getValue()), lstItemClient.getLabel());
        KeyNamePair[] orgKNPairs = login.getOrgs(clientKNPair);
        if (orgKNPairs != null && orgKNPairs.length > 0) {
            for (int i = 0; i < orgKNPairs.length; i++) {
                ComboItem ci = new ComboItem(orgKNPairs[i].getName(), orgKNPairs[i].getID());
                lstOrganisation.appendChild(ci);
                if (orgKNPairs[i].getID().equals(initDefault))
                    lstOrganisation.setSelectedItem(ci);
            }
            if (lstOrganisation.getSelectedIndex() == -1 && lstOrganisation.getItemCount() > 0)
                lstOrganisation.setSelectedIndex(0);
        }
    //
    }
    updateWarehouseList();
}
Also used : Comboitem(org.zkoss.zul.Comboitem) UserPreference(org.adempiere.webui.util.UserPreference) KeyNamePair(org.compiere.util.KeyNamePair) ComboItem(org.adempiere.webui.component.ComboItem)

Example 13 with Comboitem

use of org.zkoss.zul.Comboitem in project adempiere by adempiere.

the class RolePanel method updateClientList.

private void updateClientList() {
    lstClient.getItems().clear();
    Comboitem lstItemRole = lstRole.getSelectedItem();
    if (lstItemRole != null) {
        //  initial client - Elaine 2009/02/06
        UserPreference userPreference = SessionManager.getSessionApplication().getUserPreference();
        String initDefault = userPreference.getProperty(UserPreference.P_CLIENT);
        KeyNamePair roleKNPair = new KeyNamePair(new Integer((String) lstItemRole.getValue()), lstItemRole.getLabel());
        KeyNamePair[] clientKNPairs = login.getClients(roleKNPair);
        if (clientKNPairs != null && clientKNPairs.length > 0) {
            for (int i = 0; i < clientKNPairs.length; i++) {
                ComboItem ci = new ComboItem(clientKNPairs[i].getName(), clientKNPairs[i].getID());
                lstClient.appendChild(ci);
                if (clientKNPairs[i].getID().equals(initDefault))
                    lstClient.setSelectedItem(ci);
            }
            if (lstClient.getSelectedIndex() == -1 && lstClient.getItemCount() > 0)
                lstClient.setSelectedIndex(0);
        }
        //
        //force reload of default role
        MRole.getDefault(m_ctx, true);
    }
    login.getRoles(m_userName, m_password);
    updateOrganisationList();
}
Also used : Comboitem(org.zkoss.zul.Comboitem) UserPreference(org.adempiere.webui.util.UserPreference) KeyNamePair(org.compiere.util.KeyNamePair) ComboItem(org.adempiere.webui.component.ComboItem)

Example 14 with Comboitem

use of org.zkoss.zul.Comboitem in project spatial-portal by AtlasOfLivingAustralia.

the class ContextualLayersAutoComplete method refresh.

public void refresh(String val) {
    //don't do autocomplete when < 3 characters
    if (val.length() < 0) {
        return;
    }
    String baseUrl = CommonData.getLayersServer() + "/fields/";
    try {
        Iterator it = getItems().iterator();
        JSONArray results;
        String lsurl = baseUrl;
        if (val.length() == 0) {
            results = CommonData.getLayerListJSONArray();
        } else {
            lsurl += "search/?q=" + URLEncoder.encode(val, StringConstants.UTF_8);
            LOGGER.debug("nsurl: " + lsurl);
            HttpClient client = new HttpClient();
            GetMethod get = new GetMethod(lsurl);
            get.addRequestHeader(StringConstants.ACCEPT, StringConstants.JSON_JAVASCRIPT_ALL);
            client.executeMethod(get);
            String slist = get.getResponseBodyAsString();
            JSONParser jp = new JSONParser();
            results = (JSONArray) jp.parse(slist);
        }
        LOGGER.debug("got " + results.size() + " layers");
        Sessions.getCurrent().setAttribute("layerlist", results);
        if (!results.isEmpty()) {
            for (int i = 0; i < results.size(); i++) {
                JSONObject field = (JSONObject) results.get(i);
                JSONObject layer = (JSONObject) field.get("layer");
                if (!field.get(StringConstants.ENABLED).toString().equalsIgnoreCase("true") || !field.get(StringConstants.INDB).toString().equalsIgnoreCase("true") || (StringConstants.ENVIRONMENTAL.equalsIgnoreCase(layer.get(StringConstants.TYPE).toString()))) {
                    continue;
                }
                String displayName = field.get(StringConstants.NAME).toString();
                String type = layer.get(StringConstants.TYPE).toString();
                Comboitem myci;
                if (it != null && it.hasNext()) {
                    myci = ((Comboitem) it.next());
                    myci.setLabel(displayName);
                } else {
                    it = null;
                    myci = new Comboitem(displayName);
                    myci.setParent(this);
                }
                String c2 = "";
                if (layer.containsKey(StringConstants.CLASSIFICATION2) && !StringConstants.NULL.equals(layer.get(StringConstants.CLASSIFICATION2))) {
                    c2 = layer.get(StringConstants.CLASSIFICATION2) + ": ";
                }
                String c1 = "";
                if (layer.containsKey(StringConstants.CLASSIFICATION1) && !StringConstants.NULL.equals(layer.get(StringConstants.CLASSIFICATION1))) {
                    c1 = layer.get(StringConstants.CLASSIFICATION1) + ": ";
                }
                myci.setDescription(c1 + c2 + type);
                myci.setDisabled(false);
                myci.setValue(field);
            }
        }
        while (it != null && it.hasNext()) {
            it.next();
            it.remove();
        }
    } catch (Exception e) {
        LOGGER.error("Error searching for layers:", e);
    }
}
Also used : JSONObject(org.json.simple.JSONObject) HttpClient(org.apache.commons.httpclient.HttpClient) Iterator(java.util.Iterator) JSONArray(org.json.simple.JSONArray) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JSONParser(org.json.simple.parser.JSONParser) Comboitem(org.zkoss.zul.Comboitem)

Example 15 with Comboitem

use of org.zkoss.zul.Comboitem in project spatial-portal by AtlasOfLivingAustralia.

the class SpeciesAutoComplete method refresh.

/**
     * Refresh comboitem based on the specified value.
     */
public void refresh(String val) {
    // Start by constraining the search to a min 3-chars
    if (val.length() < 3) {
        return;
    }
    //High limit because geoOnly=true cuts out valid matches, e.g. "Macropus"
    try {
        LOGGER.debug("Looking for common name: " + isSearchCommon());
        getItems().clear();
        Iterator it = getItems().iterator();
        if (val.length() == 0) {
            Comboitem myci;
            if (it.hasNext()) {
                myci = ((Comboitem) it.next());
                myci.setLabel("Please start by typing in a species name...");
            } else {
                it = null;
                myci = new Comboitem("Please start by typing in a species name...");
                myci.setParent(this);
            }
            myci.setDescription("");
            myci.setDisabled(true);
        } else {
            StringBuilder sb = new StringBuilder();
            if (biocacheQuery != null) {
                sb.append(biocacheQuery.getAutoComplete("raw_taxon_name", val, 50));
            } else {
                //sb.append(autoService(val));
                sb.append(searchService(val));
            }
            if (!biocacheOnly) {
                sb.append(loadUserPoints(val));
            }
            String sslist = sb.toString();
            LOGGER.debug("SpeciesAutoComplete: \n" + sslist);
            String[] aslist = sslist.split("\n");
            if (aslist.length > 0 && aslist[0].length() > 0) {
                Arrays.sort(aslist);
                for (int i = 0; i < aslist.length; i++) {
                    String[] spVal = aslist[i].split("\\|");
                    String taxon = spVal[0].trim();
                    Comboitem myci;
                    if (it != null && it.hasNext()) {
                        myci = ((Comboitem) it.next());
                        myci.setLabel(taxon);
                    } else {
                        it = null;
                        myci = new Comboitem(taxon);
                        myci.setParent(this);
                    }
                    String desc;
                    if (spVal.length >= 4) {
                        desc = spVal[2] + " - " + spVal[3];
                    } else {
                        desc = spVal[2];
                    }
                    String[] wmsDistributions = CommonData.getSpeciesDistributionWMS(spVal[1]);
                    if (wmsDistributions.length > 0) {
                        if (wmsDistributions.length == 1) {
                            desc += " +1 expert distribution";
                        } else {
                            desc += " +" + wmsDistributions.length + " expert distributions";
                        }
                    }
                    String[] wmsChecklists = CommonData.getSpeciesChecklistWMS(spVal[1]);
                    if (wmsChecklists.length > 0) {
                        if (wmsChecklists.length == 1) {
                            desc += " +1 checklist area";
                        } else {
                            desc += " +" + wmsChecklists.length + " checklist areas";
                        }
                    }
                    myci.setDescription(desc);
                    myci.setDisabled(false);
                    myci.setValue(taxon);
                    myci.setDisabled(false);
                    if (myci.getAnnotations() != null) {
                        myci.getAnnotations().clear();
                    }
                    if (org.apache.commons.lang.StringUtils.isNotBlank(spVal[1])) {
                        myci.addAnnotation(spVal[1], "LSID", null);
                    } else if (org.apache.commons.lang.StringUtils.isNotBlank(spVal[0])) {
                        //add the scientific name as the annotation
                        myci.addAnnotation(spVal[0], StringConstants.VALUE, null);
                    } else {
                        myci.setParent(null);
                    }
                }
            }
        }
        while (it != null && it.hasNext()) {
            it.next();
            it.remove();
        }
    } catch (Exception e) {
        LOGGER.error("Oopss! something went wrong in SpeciesAutoComplete.refresh", e);
    }
}
Also used : Iterator(java.util.Iterator) Comboitem(org.zkoss.zul.Comboitem) WrongValueException(org.zkoss.zk.ui.WrongValueException)

Aggregations

Comboitem (org.zkoss.zul.Comboitem)21 UserPreference (org.adempiere.webui.util.UserPreference)5 Iterator (java.util.Iterator)4 HttpClient (org.apache.commons.httpclient.HttpClient)4 GetMethod (org.apache.commons.httpclient.methods.GetMethod)4 KeyNamePair (org.compiere.util.KeyNamePair)4 JSONArray (org.json.simple.JSONArray)4 JSONObject (org.json.simple.JSONObject)4 JSONParser (org.json.simple.parser.JSONParser)4 ComboItem (org.adempiere.webui.component.ComboItem)3 MapLayer (au.org.emii.portal.menu.MapLayer)2 WrongValueException (org.zkoss.zk.ui.WrongValueException)2 FieldDTO (au.org.ala.spatial.dto.FieldDTO)1 LayerSelection (au.org.ala.spatial.util.LayerSelection)1 ValueChangeEvent (org.adempiere.exceptions.ValueChangeEvent)1 Combobox (org.adempiere.webui.component.Combobox)1 Label (org.adempiere.webui.component.Label)1 Textbox (org.adempiere.webui.component.Textbox)1 Language (org.compiere.util.Language)1 Event (org.zkoss.zk.ui.event.Event)1