Example usage for com.google.gwt.core.client JsArray get

List of usage examples for com.google.gwt.core.client JsArray get

Introduction

In this page you can find the example usage for com.google.gwt.core.client JsArray get.

Prototype

public final native T get(int index) ;

Source Link

Document

Gets the object at a given index.

Usage

From source file:app.service.JSHttpDelegate.java

License:GNU General Public License

public void doExecute(String action, String url, String[][] headers, boolean binaryInput, boolean binaryOutput,
        byte[] contents, Callback callback) throws Exception {
    try {/*  w w  w .j  av  a 2s.co m*/
        JSInvoker.invoke(delegate, "executeURL",
                new Object[] { action, url, headers, binaryInput, binaryOutput,
                        binaryInput ? ((contents != null) ? Base64.encode(contents) : null)
                                : ((contents != null) ? Strings.toString(contents) : null),

                        new CallbackDefault(url, binaryOutput) {
                            @Override
                            public void onSuccess(Object... arguments) throws Exception {
                                String data = (String) arguments[0];
                                JsArray jsHeaders = (JsArray) arguments[1];
                                String[][] headers = new String[jsHeaders.length()][];
                                for (int i = 0; i < jsHeaders.length(); ++i) {
                                    JsArray header = jsHeaders.get(i).cast();
                                    headers[i] = new String[] { header.get(0).toString(),
                                            header.get(1).toString() };
                                }

                                String url = V(0);
                                boolean binaryOutput = V(1);

                                log.debug("doExecute callback ", url, binaryOutput);

                                if (data == null) {
                                    log.debug("failed to acquire resource", url);
                                    next(new IOException("Failed to acquire resource"));
                                } else {
                                    log.debug("succeeded in acquiring resource", url);

                                    if (binaryOutput) {
                                        byte[] bin = data != null ? Base64.decode(data) : null;
                                        next(bin, headers);
                                    } else {
                                        next(data, headers);
                                    }
                                }
                            }
                        }.setReturn(callback) });
    } catch (Throwable e) {
        callback.invoke(e);
    }
}

From source file:cc.alcina.framework.gwt.client.util.ClientUtils.java

License:Apache License

public static <T extends JavaScriptObject> List<T> jsArrayToTypedArray(JsArray<T> typedArray) {
    List<T> result = new ArrayList<T>();
    for (int i = 0; i < typedArray.length(); i++) {
        result.add(typedArray.get(i));
    }/*  www .j  a  v a2s .  c  o m*/
    return result;
}

From source file:ch.sebastienzurfluh.swissmuseum.core.client.model.io.CakeConnector.java

License:Open Source License

private <T> void asyncRequest(final Requests request, final int referenceId, String args,
        final AsyncCallback<T> callback) {

    final StringBuilder url = new StringBuilder(cakePath + request.getURL());

    url.append(CAKE_ARGS_SEPARATOR).append(args);
    url.append(CAKE_ARGS_SEPARATOR).append(referenceId);

    url.append(CAKE_SUFFIX);//from   www  .  j  av a  2s. com

    System.out.println("Making async request on " + url);

    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url.toString());

    try {
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request httpRequest, Throwable exception) {
                System.out.println("JSON request failure. " + exception.getLocalizedMessage());
                // we do nothing else than log
                callback.onFailure(exception);
            }

            @SuppressWarnings("unchecked")
            public void onResponseReceived(Request httpRequest, Response response) {
                if (200 == response.getStatusCode()) {
                    System.out.println("Got answer from async request.");

                    JsArray<Entry> entries = evalJson(response.getText().trim());

                    // BLACKBOX!!!
                    DataType dataType = DataType.PAGE;

                    switch (request) {
                    case GETALLGROUPMENUS:
                        dataType = DataType.GROUP;
                    case GETALLPAGEMENUSFROMGROUP:
                        // menu collection
                        LinkedList<MenuData> dataList = new LinkedList<MenuData>();
                        for (int i = 0; i < entries.length(); i++) {
                            Entry entry = entries.get(i);
                            dataList.add(parseMenuData(entry, referenceId, dataType));
                        }
                        // give callback
                        callback.onSuccess((T) dataList);
                        break;
                    case GETDATA:
                    case GETFIRSTDATAOFGROUP:
                        // single data
                        Data parsedData = parseData(entries.get(0), referenceId, DataType.PAGE);
                        callback.onSuccess((T) parsedData);
                        break;
                    case GETRESOURCE:
                        ResourceData parsedData2 = parseResourceData(entries.get(0), referenceId);
                        callback.onSuccess((T) parsedData2);
                    }
                }
            }
        });
    } catch (Exception e) {
        callback.onFailure(e);
    }
}

From source file:ch.sebastienzurfluh.swissmuseum.parcours.client.model.DatabaseHandle.java

License:Open Source License

public static void updateAffiliations(final JsArray<Affiliation> affiliations) {
    if (affiliations.get(0) == null)
        return;// w ww. jav  a  2  s.c om

    // Keep this if the SQLite implementation is updated on the browser.
    //      String query = "INSERT OR REPLACE INTO \'affiliations\' VALUES ";
    //      for (int i = 0; i < affiliations.length(); i++) {
    //         query += "(\'" + affiliations.get(i).getId() +
    //               "\',\'" + affiliations.get(i).getPageId() +
    //               "\',\'" + affiliations.get(i).getGroupId() +
    //               "\',\'" + affiliations.get(i).getOrder() + "\'),";
    //      }
    //      // remove the last ","
    //      query = query.substring(0, query.length()-1) + ";";

    String query = "INSERT OR REPLACE INTO \'affiliations\' SELECT ";
    query += "\'" + affiliations.get(0).getId() + "\' AS \'id" + "\',\'" + affiliations.get(0).getPageId()
            + "\' AS \'page_id" + "\',\'" + affiliations.get(0).getGroupId() + "\' AS \'group_id" + "\',\'"
            + affiliations.get(0).getOrder() + "\' AS \'order" + "\'";
    for (int i = 1; i < affiliations.length(); i++) {
        query += " UNION SELECT \'" + affiliations.get(i).getId() + "\',\'" + affiliations.get(i).getPageId()
                + "\',\'" + affiliations.get(i).getGroupId() + "\',\'" + affiliations.get(i).getOrder() + "\'";
    }
    query += ";";

    execute(query);
}

From source file:ch.sebastienzurfluh.swissmuseum.parcours.client.model.DatabaseHandle.java

License:Open Source License

public static void updateGroups(final JsArray<Group> groups) {
    if (groups.get(0) == null)
        return;/*from   ww  w .  ja v  a2s.  com*/

    //      String query = "INSERT OR REPLACE INTO groups VALUES ";
    //      for (int i = 0; i < groups.length(); i++) {
    //         query += "(\'" + groups.get(i).getId() +
    //               "\',\'" + groups.get(i).getName() +
    //               "\',\'" + groups.get(i).getMenuId() + "\'),";
    //      }
    //      // remove the last ","
    //      query = query.substring(0, query.length()-1) + ";";

    String query = "INSERT OR REPLACE INTO \'groups\' SELECT ";
    query += "\'" + groups.get(0).getId() + "\' AS \'id\'" + ",\"" + groups.get(0).getName() + "\" AS \'name\'"
            + ",\'" + groups.get(0).getMenuId() + "\' AS \'menu_id\'";
    for (int i = 1; i < groups.length(); i++) {
        query += "UNION SELECT \'" + groups.get(i).getId() + "\',\'" + groups.get(i).getName() + "\',\'"
                + groups.get(i).getMenuId() + "\'";
    }
    query += ";";
    execute(query);
}

From source file:ch.sebastienzurfluh.swissmuseum.parcours.client.model.DatabaseHandle.java

License:Open Source License

public static void updateMenus(final JsArray<Menu> menus) {
    if (menus.get(0) == null)
        return;/*from   w w w .  ja v a  2s .  com*/

    //      String query = "INSERT OR REPLACE INTO menus VALUES ";
    //      for (int i = 0; i < menus.length(); i++) {
    //         query += "(\'" + menus.get(i).getId() +
    //               "\',\'" + menus.get(i).getTitle() +
    //               "\',\'" + menus.get(i).getDescription() +
    //               "\',\'" + menus.get(i).getThumbImgURL() +
    //               "\',\'" + menus.get(i).getImgURL() +"\'),";
    //      }
    //      // remove the last ","
    //      query = query.substring(0, query.length()-1) + ";";

    String query = "INSERT OR REPLACE INTO \'menus\' SELECT ";
    query += "\'" + menus.get(0).getId() + "\' AS \'id\'" + ",\"" + menus.get(0).getTitle() + "\" AS \'title\'"
            + ",\"" + menus.get(0).getDescription() + "\" AS \'description\'" + ",\""
            + menus.get(0).getThumbImgURL() + "\" AS \'thumb_img_url\'" + ",\"" + menus.get(0).getImgURL()
            + "\" AS \'img_url\'";
    for (int i = 1; i < menus.length(); i++) {
        query += "UNION SELECT \'" + menus.get(i).getId() + "\',\"" + menus.get(i).getTitle() + "\",\""
                + menus.get(i).getDescription() + "\",\"" + menus.get(i).getThumbImgURL() + "\",\""
                + menus.get(i).getImgURL() + "\"";
    }
    query += ";";

    execute(query);
}

From source file:ch.sebastienzurfluh.swissmuseum.parcours.client.model.DatabaseHandle.java

License:Open Source License

public static void updatePages(final JsArray<Page> pages) {
    if (pages.get(0) == null)
        return;/*  w  ww  .  j  a va 2 s.  co m*/

    //      String query = "INSERT OR REPLACE INTO pages VALUES ";
    //      for (int i = 0; i < pages.length(); i++) {
    //         query += "(\'" + pages.get(i).getId() +
    //               "\',\'" + pages.get(i).getTitle() +
    //               "\',\'" + pages.get(i).getSubtitle() +
    //               "\',\'" + pages.get(i).getContent() +
    //               "\',\'" + pages.get(i).getMenuId() + "\'),";
    //      }
    //      // remove the last ","
    //      query = query.substring(0, query.length()-1) + ";";

    String query = "INSERT OR REPLACE INTO \'pages\' SELECT ";
    query += "\'" + pages.get(0).getId() + "\' AS \'id\'" + ",\"" + pages.get(0).getTitle() + "\" AS \'title\'"
            + ",\"" + pages.get(0).getSubtitle() + "\" AS \'subtitle\'" + ",\"" + pages.get(0).getContent()
            + "\" AS \'content\'" + ",\'" + pages.get(0).getMenuId() + "\' AS \'menu_id\'";
    for (int i = 1; i < pages.length(); i++) {
        query += " UNION SELECT \'" + pages.get(i).getId() + "\',\"" + pages.get(i).getTitle() + "\",\""
                + pages.get(i).getSubtitle() + "\",\"" + pages.get(i).getContent() + "\",\'"
                + pages.get(i).getMenuId() + "\'";
    }
    query += ";";

    execute(query);
}

From source file:ch.sebastienzurfluh.swissmuseum.parcours.client.model.DatabaseHandle.java

License:Open Source License

public static void updateResources(final JsArray<Resource> resources) {
    if (resources.get(0) == null)
        return;//from   w  w w  .j  ava  2s . c o m

    //      String query = "INSERT OR REPLACE INTO resources VALUES ";
    //      for (int i = 0; i < resources.length(); i++) {
    //         query += "(\'" + resources.get(i).getId() +
    //               "\',\'" + resources.get(i).getTitle() +
    //               "\',\'" + resources.get(i).getURL() +
    //               "\',\'" + resources.get(i).getDescription() +
    //               "\',\'" + resources.get(i).getType() + "\'),";
    //      }
    //      
    //      // remove the last ","
    //      query = query.substring(0, query.length()-1) + ";";

    String query = "INSERT OR REPLACE INTO \'resources\' SELECT ";
    query += "\'" + resources.get(0).getId() + "\' AS \'id\'" + ",\"" + resources.get(0).getTitle()
            + "\" AS \'title\'" + ",\"" + resources.get(0).getURL() + "\" AS \'url\'" + ",\""
            + resources.get(0).getDescription() + "\" AS \'description\'" + ",\"" + resources.get(0).getType()
            + "\" AS \'type\'";
    for (int i = 1; i < resources.length(); i++) {
        query += " UNION SELECT \'" + resources.get(i).getId() + "\',\"" + resources.get(i).getTitle() + "\",\""
                + resources.get(i).getURL() + "\",\"" + resources.get(i).getDescription() + "\",\""
                + resources.get(i).getType() + "\"";
    }
    query += ";";

    execute(query);
}

From source file:ch.unifr.pai.mindmap.client.mindmap.BackgroundImgRepo.java

License:Apache License

/**
 * @param bgImg/*from www.  jav a2s.c  om*/
 *            - the image object that shall be adapted accordingly to the chosen data-url
 */
public BackgroundImgRepo(Image bgImg) {
    super();
    add(fp);
    add(previewImage);
    getElement().getStyle().setOverflow(Overflow.VISIBLE);
    this.bgImg = bgImg;
    this.setHeight("100%");
    this.setWidth("100%");
    fp.getElement().getStyle().setBackgroundColor("grey");
    fp.setWidth("100%");
    fp.setHeight("100%");
    fp.setWidget(hp);
    hp.setWidth("100%");
    hp.setHeight("100%");
    fp.setWidget(hp);
    previewImage.getElement().getStyle().setPosition(Position.ABSOLUTE);
    previewImage.getElement().getStyle().setTop(-120, Unit.PX);
    previewImage.getElement().getStyle().setHeight(110, Unit.PX);
    previewImage.getElement().getStyle().setBorderWidth(2, Unit.PX);
    previewImage.getElement().getStyle().setBorderColor("black");
    previewImage.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
    previewImage.getElement().getStyle().setDisplay(Display.NONE);

    // Add a button for cleaning the browser as well
    PushButton emptyBg = new PushButton(new Image(GWT.getModuleBaseURL() + "images/emptyscreen.png")) {
        @Override
        public void onBrowserEvent(Event event) {
            if (MultiCursorController.isDefaultCursor(event)) {
                super.onBrowserEvent(event);
            }
        }
    };
    emptyBg.setTitle("Remove background-image");
    emptyBg.getElement().getStyle().setDisplay(Display.INLINE_BLOCK);
    emptyBg.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (MultiCursorController.isDefaultCursor(event.getNativeEvent())) {
                BackgroundImgRepo.this.bgImg.setVisible(false);
            }
        }
    });
    hp.add(emptyBg);
    fp.addDragOverHandler(new DragOverHandler() {

        @Override
        public void onDragOver(DragOverEvent event) {
            fp.getElement().getStyle().setBackgroundColor("darkgrey");
        }
    });
    fp.addDragLeaveHandler(new DragLeaveHandler() {

        @Override
        public void onDragLeave(DragLeaveEvent event) {
            fp.getElement().getStyle().setBackgroundColor("grey");
        }

    });
    fp.addDropHandler(new DropHandler() {

        /**
         * Prevents the default behavior of the browser (otherwise, the browser would open the image in the current tab), reads the dragged files and adds
         * them as {@link PushButton} to the panel.
         * 
         * @see com.google.gwt.event.dom.client.DropHandler#onDrop(com.google.gwt.event.dom.client.DropEvent)
         */
        /*
         * (non-Javadoc)
         * @see com.google.gwt.event.dom.client.DropHandler#onDrop(com.google.gwt.event.dom.client.DropEvent)
         */
        @Override
        public void onDrop(DropEvent event) {
            // event.stopPropagation();
            event.preventDefault();
            fp.getElement().getStyle().setBackgroundColor("grey");
            JsArray<JavaScriptObject> files = getDataTransferFiles(event.getDataTransfer());
            for (int i = 0; i < files.length(); i++) {
                final Image img = new Image();
                PushButton button = new PushButton(img) {
                    @Override
                    public void onBrowserEvent(Event event) {
                        if (MultiCursorController.isDefaultCursor(event)) {
                            super.onBrowserEvent(event);
                        }
                    }

                };
                button.setTitle("Set this image as background");
                button.addClickHandler(new ClickHandler() {

                    /**
                     * Set the image of the button as the current background image
                     * 
                     * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent)
                     */
                    @Override
                    public void onClick(ClickEvent event) {
                        if (MultiCursorController.isDefaultCursor(event.getNativeEvent())) {
                            BackgroundImgRepo.this.bgImg.setVisible(true);
                            BackgroundImgRepo.this.bgImg.getElement().setAttribute("src",
                                    img.getElement().getAttribute("src"));
                        }
                    }
                });
                button.addMouseOverHandler(new MouseOverHandler() {

                    /**
                     * Show the preview image at the appropriate position and replace the data-url
                     * 
                     * @see com.google.gwt.event.dom.client.MouseOverHandler#onMouseOver(com.google.gwt.event.dom.client.MouseOverEvent)
                     */
                    @Override
                    public void onMouseOver(MouseOverEvent event) {
                        if (MultiCursorController.isDefaultCursor(event.getNativeEvent())) {
                            BackgroundImgRepo.this.previewImage.getElement().getStyle()
                                    .setDisplay(Display.BLOCK);
                            BackgroundImgRepo.this.previewImage.getElement().setAttribute("src",
                                    img.getElement().getAttribute("src"));
                            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                                @Override
                                public void execute() {
                                    previewImage.getElement().getStyle().setLeft(img.getAbsoluteLeft()
                                            - BackgroundImgRepo.this.getAbsoluteLeft()
                                            - previewImage.getOffsetWidth() / 2 + img.getOffsetWidth() / 2,
                                            Unit.PX);
                                }
                            });
                        }
                    }
                });
                button.addMouseOutHandler(new MouseOutHandler() {

                    /**
                     * Hide the preview image
                     * 
                     * @see com.google.gwt.event.dom.client.MouseOutHandler#onMouseOut(com.google.gwt.event.dom.client.MouseOutEvent)
                     */
                    @Override
                    public void onMouseOut(MouseOutEvent event) {
                        if (MultiCursorController.isDefaultCursor(event.getNativeEvent())) {

                            BackgroundImgRepo.this.previewImage.getElement().getStyle()
                                    .setDisplay(Display.NONE);
                        }
                    }
                });
                // img.getElement().getStyle().setMargin(5, Unit.PX);
                // img.getElement().getStyle().setDisplay(Display.INLINE_BLOCK);
                img.setHeight("35px");
                button.getElement().getStyle().setDisplay(Display.INLINE_BLOCK);
                hp.add(button);
                addBackgroundImage(img.getElement(), files.get(i));
            }

        }
    });
}

From source file:cl.uai.client.chat.NodeChat.java

License:Open Source License

/**
 * This event is linked to the userJoin (emit)
 * @param connectedUsers a collection of one UserData per connected user
 *///  ww  w.ja  v a  2  s  . c  o  m
private void onJoinServer(JsArray<UserJS> connectedUsers) {
    // Add every user to the interface
    for (int i = 0; i < connectedUsers.length(); i++) {
        EMarkingWeb.markingInterface.chat.getUsersConnectedPanel().addUser(connectedUsers.get(i));
        EMarkingWeb.markingInterface.wall.getUsersConnectedPanel().addUser(connectedUsers.get(i));
        EMarkingWeb.markingInterface.help.getUsersConnectedPanel().addUser(connectedUsers.get(i));
    }
    // Load previous messages
    EMarkingWeb.markingInterface.chat.loadHistoryMessages();
    EMarkingWeb.markingInterface.wall.loadHistoryMessages();
    EMarkingWeb.markingInterface.help.loadHistoryMessages();
}