Search in sources :

Example 6 with SourceData

use of com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource.SourceData in project convertigo by convertigo.

the class MobilePickerContentProvider method addSharedComponents.

private void addSharedComponents(TVObject tvi, Object object) {
    if (object != null) {
        List<? extends UIComponent> list = null;
        if (object instanceof ApplicationComponent) {
            list = ((ApplicationComponent) object).getSharedComponentList();
        } else if (object instanceof UISharedComponent) {
            list = new ArrayList<>(Arrays.asList((UISharedComponent) object));
        }
        if (list != null) {
            for (UIComponent uic : list) {
                if (uic instanceof UISharedComponent) {
                    // do not add to prevent selection on itself or children
                    if (uic.equals(selected)) {
                        return;
                    }
                    // do not add if not parent of selected (popped picker only)
                    boolean showInPicker = true;
                    if (selected != null && selected instanceof UIComponent) {
                        String selectedQName = ((UIComponent) selected).getQName();
                        String uicQName = uic.getQName() + ".";
                        if (!selectedQName.startsWith(uicQName)) {
                            showInPicker = false;
                        }
                    }
                    if (showInPicker) {
                        SourceData sd = null;
                        try {
                            sd = Filter.Shared.toSourceData(new JSONObject().put("priority", uic.priority));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        tvi.add(new TVObject(uic.toString(), uic, sd));
                    }
                }
            }
        }
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) ArrayList(java.util.ArrayList) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) JSONException(org.codehaus.jettison.json.JSONException) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) SourceData(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource.SourceData)

Example 7 with SourceData

use of com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource.SourceData in project convertigo by convertigo.

the class MobilePickerContentProvider method addFsObjects.

private void addFsObjects(Map<String, Set<String>> map, TVObject tvd, Object object, boolean isReferenced) {
    if (object != null) {
        if (object instanceof Project) {
            Project project = (Project) object;
            for (Connector c : project.getConnectorsList()) {
                if (c instanceof FullSyncConnector) {
                    String label = isReferenced ? c.getQName() : c.getName();
                    TVObject tvc = tvd.add(new TVObject(label));
                    for (Document d : c.getDocumentsList()) {
                        if (d instanceof DesignDocument) {
                            TVObject tdd = tvc.add(new TVObject(d.getName()));
                            JSONObject views = CouchKey.views.JSONObject(((DesignDocument) d).getJSONObject());
                            if (views != null) {
                                for (Iterator<String> it = GenericUtils.cast(views.keys()); it.hasNext(); ) {
                                    try {
                                        Set<String> infos = null;
                                        String view = it.next();
                                        String key = c.getQName() + "." + d.getName() + "." + view;
                                        TVObject tvv = tdd.add(new TVObject(view));
                                        SourceData sd = null;
                                        try {
                                            sd = Filter.Database.toSourceData(new JSONObject().put("connector", c.getQName()).put("document", d.getQName()).put("queryview", view).put("verb", "get"));
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                        tvv.add(new TVObject("get", d, sd));
                                        infos = map.get(key + ".get");
                                        if (infos == null) {
                                            infos = map.get(c.getQName() + ".get");
                                        }
                                        if (infos != null) {
                                            for (String info : infos) {
                                                try {
                                                    JSONObject jsonInfo = new JSONObject(info);
                                                    boolean includeDocs = false;
                                                    if (jsonInfo.has("include_docs")) {
                                                        includeDocs = Boolean.valueOf(jsonInfo.getString("include_docs")).booleanValue();
                                                    }
                                                    if (jsonInfo.has("marker")) {
                                                        String marker = jsonInfo.getString("marker");
                                                        if (!marker.isEmpty()) {
                                                            String name = "get" + "#" + marker;
                                                            sd = Filter.Database.toSourceData(new JSONObject().put("connector", c.getQName()).put("document", d.getQName()).put("queryview", view).put("verb", "get").put("marker", marker).put("includeDocs", includeDocs));
                                                            tvv.add(new TVObject(name, d, sd, jsonInfo));
                                                        }
                                                    }
                                                } catch (JSONException e) {
                                                    e.printStackTrace();
                                                }
                                            }
                                        }
                                        try {
                                            sd = Filter.Database.toSourceData(new JSONObject().put("connector", c.getQName()).put("document", d.getQName()).put("queryview", view).put("verb", "view"));
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                        tvv.add(new TVObject("view", d, sd));
                                        infos = map.get(key + ".view");
                                        if (infos != null) {
                                            for (String info : infos) {
                                                try {
                                                    JSONObject jsonInfo = new JSONObject(info);
                                                    boolean includeDocs = false;
                                                    if (jsonInfo.has("include_docs")) {
                                                        includeDocs = Boolean.valueOf(jsonInfo.getString("include_docs")).booleanValue();
                                                    }
                                                    if (jsonInfo.has("marker")) {
                                                        String marker = jsonInfo.getString("marker");
                                                        if (!marker.isEmpty()) {
                                                            String name = "view" + "#" + marker;
                                                            sd = Filter.Database.toSourceData(new JSONObject().put("connector", c.getQName()).put("document", d.getQName()).put("queryview", view).put("verb", "view").put("marker", marker).put("includeDocs", includeDocs));
                                                            tvv.add(new TVObject(name, d, sd, jsonInfo));
                                                        }
                                                    }
                                                } catch (JSONException e) {
                                                    e.printStackTrace();
                                                }
                                            }
                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) JSONException(org.codehaus.jettison.json.JSONException) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) Document(com.twinsoft.convertigo.beans.core.Document) SourceData(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource.SourceData) JSONException(org.codehaus.jettison.json.JSONException) Project(com.twinsoft.convertigo.beans.core.Project) JSONObject(org.codehaus.jettison.json.JSONObject) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument)

Example 8 with SourceData

use of com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource.SourceData in project convertigo by convertigo.

the class MobilePickerContentProvider method addSequences.

private void addSequences(Map<String, Set<String>> map, TVObject tvs, Object object, boolean isReferenced) {
    if (object != null) {
        if (object instanceof Project) {
            Project project = (Project) object;
            for (Sequence s : project.getSequencesList()) {
                String label = isReferenced ? s.getQName() : s.getName();
                SourceData sd = null;
                try {
                    sd = Filter.Sequence.toSourceData(new JSONObject().put("sequence", s.getQName()));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                tvs.add(new TVObject(label, s, sd));
                Set<String> infos = map.get(s.getQName());
                if (infos != null) {
                    for (String info : infos) {
                        try {
                            JSONObject jsonInfo = new JSONObject(info);
                            if (jsonInfo.has("marker")) {
                                String marker = jsonInfo.getString("marker");
                                if (!marker.isEmpty()) {
                                    sd = Filter.Sequence.toSourceData(new JSONObject().put("sequence", s.getQName()).put("marker", marker));
                                    tvs.add(new TVObject(label + "#" + marker, s, sd, jsonInfo));
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) JSONObject(org.codehaus.jettison.json.JSONObject) JSONException(org.codehaus.jettison.json.JSONException) Sequence(com.twinsoft.convertigo.beans.core.Sequence) SourceData(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource.SourceData)

Aggregations

SourceData (com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource.SourceData)8 JSONObject (org.codehaus.jettison.json.JSONObject)8 JSONException (org.codehaus.jettison.json.JSONException)7 UIComponent (com.twinsoft.convertigo.beans.mobile.components.UIComponent)4 ApplicationComponent (com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent)3 PageComponent (com.twinsoft.convertigo.beans.mobile.components.PageComponent)3 ArrayList (java.util.ArrayList)3 Project (com.twinsoft.convertigo.beans.core.Project)2 UISharedComponent (com.twinsoft.convertigo.beans.mobile.components.UISharedComponent)2 FullSyncConnector (com.twinsoft.convertigo.beans.connectors.FullSyncConnector)1 Connector (com.twinsoft.convertigo.beans.core.Connector)1 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)1 Document (com.twinsoft.convertigo.beans.core.Document)1 MobileObject (com.twinsoft.convertigo.beans.core.MobileObject)1 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)1 Sequence (com.twinsoft.convertigo.beans.core.Sequence)1 DesignDocument (com.twinsoft.convertigo.beans.couchdb.DesignDocument)1 IAction (com.twinsoft.convertigo.beans.mobile.components.IAction)1 UIActionEvent (com.twinsoft.convertigo.beans.mobile.components.UIActionEvent)1 UIActionStack (com.twinsoft.convertigo.beans.mobile.components.UIActionStack)1