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

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

Introduction

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

Prototype

public final native int get(int index) ;

Source Link

Document

Gets the value at a given index.

Usage

From source file:org.sigmah.offline.dao.OrgUnitAsyncDAO.java

License:Open Source License

/**
 * {@inheritDoc}/*  ww  w  .j  av  a  2 s.  c  o m*/
 */
@Override
public void get(final int id, final AsyncCallback<OrgUnitDTO> callback, final Transaction<Store> transaction) {
    if (transaction.useObjectFromCache(OrgUnitDTO.class, id, callback)) {
        return;
    }

    final ObjectStore orgUnitStore = transaction.getObjectStore(Store.ORG_UNIT);
    orgUnitStore.get(id).addCallback(new AsyncCallback<Request>() {

        @Override
        public void onFailure(Throwable caught) {
            callback.onFailure(caught);
        }

        @Override
        public void onSuccess(Request request) {
            final OrgUnitJS orgUnitJS = request.getResult();
            if (orgUnitJS != null) {
                final OrgUnitDTO orgUnitDTO = orgUnitJS.toDTO();

                transaction.getObjectCache().put(id, orgUnitDTO);

                final RequestManager<OrgUnitDTO> requestManager = new RequestManager<OrgUnitDTO>(orgUnitDTO,
                        callback);

                if (orgUnitJS.hasOrgUnitModel()) {
                    orgUnitModelAsyncDAO.get(orgUnitJS.getOrgUnitModel(),
                            new RequestManagerCallback<OrgUnitDTO, OrgUnitModelDTO>(requestManager) {

                                @Override
                                public void onRequestSuccess(OrgUnitModelDTO result) {
                                    orgUnitDTO.setOrgUnitModel(result);
                                }
                            }, transaction);
                }

                if (orgUnitJS.getChildren() != null) {
                    orgUnitDTO.setChildrenOrgUnits(new HashSet<OrgUnitDTO>());

                    final JsArrayInteger children = orgUnitJS.getChildren();
                    final int length = children.length();

                    for (int index = 0; index < length; index++) {
                        final int child = children.get(index);
                        get(child, new RequestManagerCallback<OrgUnitDTO, OrgUnitDTO>(requestManager) {

                            @Override
                            public void onRequestSuccess(OrgUnitDTO result) {
                                result.setParent(orgUnitDTO);
                                orgUnitDTO.getChildrenOrgUnits().add(result);
                                orgUnitDTO.getChildren().add(result);
                            }
                        }, transaction);
                    }
                }

                if (orgUnitJS.hasCountry()) {
                    countryAsyncDAO.get(orgUnitJS.getOfficeLocationCountry(),
                            new RequestManagerCallback<OrgUnitDTO, CountryDTO>(requestManager) {

                                @Override
                                public void onRequestSuccess(CountryDTO result) {
                                    orgUnitDTO.setOfficeLocationCountry(result);
                                }
                            }, transaction);
                }

                requestManager.ready();

            } else {
                callback.onSuccess(null);
            }
        }
    });
}

From source file:org.sigmah.offline.dao.PhaseModelAsyncDAO.java

License:Open Source License

/**
 * {@inheritDoc}/*from   w w  w. j  a  v a2s . com*/
 */
@Override
public void get(final int id, final AsyncCallback<PhaseModelDTO> callback,
        final Transaction<Store> transaction) {
    if (transaction.useObjectFromCache(PhaseModelDTO.class, id, callback)) {
        return;
    }

    final ObjectStore phaseModelStore = transaction.getObjectStore(Store.PHASE_MODEL);

    phaseModelStore.get(id).addCallback(new AsyncCallback<Request>() {

        @Override
        public void onFailure(Throwable caught) {
            callback.onFailure(caught);
        }

        @Override
        public void onSuccess(Request request) {
            final PhaseModelJS phaseModelJS = request.getResult();
            if (phaseModelJS != null) {
                final PhaseModelDTO phaseModelDTO = phaseModelJS.toDTO();
                transaction.getObjectCache().put(id, phaseModelDTO);

                final RequestManager<PhaseModelDTO> requestManager = new RequestManager<PhaseModelDTO>(
                        phaseModelDTO, callback);

                final JsArrayInteger successors = phaseModelJS.getSuccessors();
                if (successors != null) {
                    final ArrayList<PhaseModelDTO> dtos = new ArrayList<PhaseModelDTO>();
                    phaseModelDTO.setSuccessors(dtos);

                    for (int index = 0; index < successors.length(); index++) {
                        get(successors.get(index),
                                new RequestManagerCallback<PhaseModelDTO, PhaseModelDTO>(requestManager) {

                                    @Override
                                    public void onRequestSuccess(PhaseModelDTO result) {
                                        dtos.add(result);
                                    }
                                }, transaction);
                    }
                }

                requestManager.ready();

            } else {
                callback.onSuccess(null);
            }
        }
    });
}

From source file:org.sigmah.offline.dao.ProjectAsyncDAO.java

License:Open Source License

private <M> void loadProjectDTO(final ProjectJS projectJS, final boolean loadChildren,
        final RequestManager<M> requestManager, final ProjectDTO projectDTO,
        final Transaction<Store> transaction) {

    // Loading categories
    final int categoriesRequest = requestManager.prepareRequest();

    final RequestManager<ProjectDTO> categoryRequestManager = new RequestManager<ProjectDTO>(projectDTO,
            new RequestManagerCallback<M, ProjectDTO>(requestManager) {
                @Override//from   ww  w.j a  v a 2  s  . co  m
                public void onRequestSuccess(final ProjectDTO project) {
                    project.setCategoryElements(new HashSet<CategoryElementDTO>());

                    for (final FlexibleElementDTO element : project.getProjectModel().getAllElements()) {
                        if (element.getElementType() == ElementTypeEnum.QUESTION
                                && ((QuestionElementDTO) element).getCategoryType() != null) {
                            valueAsyncDAO.get(
                                    ValueJSIdentifierFactory.toIdentifier(element.getEntityName(),
                                            projectDTO.getId(), element.getId(), null),
                                    new RequestManagerCallback<M, ValueResult>(requestManager) {

                                        @Override
                                        public void onRequestSuccess(ValueResult result) {
                                            project.getCategoryElements().addAll(
                                                    getCategoryElements(result, (QuestionElementDTO) element));
                                        }
                                    });
                        }
                    }
                    requestManager.setRequestSuccess(categoriesRequest);
                }
            });
    final int projectModelRequest = categoryRequestManager.prepareRequest();
    categoryRequestManager.ready();

    // Loading project model
    projectModelAsyncDAO.get(projectJS.getProjectModel(),
            new RequestManagerCallback<M, ProjectModelDTO>(requestManager) {
                @Override
                public void onRequestSuccess(ProjectModelDTO result) {
                    projectDTO.setProjectModel(result);
                    projectDTO.setVisibilities(result.getVisibilities());

                    categoryRequestManager.setRequestSuccess(projectModelRequest);

                    if (loadChildren) {
                        transaction.getObjectCache().put(projectDTO.getId(), projectDTO);

                        final RequestManager<Void> fundedsAndFundingsRequestManager = new RequestManager<Void>(
                                null, new RequestManagerCallback<M, Void>(requestManager) {

                                    @Override
                                    public void onRequestSuccess(Void result) {
                                        // Sets children projects.
                                        setChildrenProjects(projectDTO);
                                    }
                                });

                        // Loading related projects
                        final JsArray<ProjectFundingJS> fundeds = projectJS.getFunded();
                        if (fundeds != null) {
                            final ArrayList<ProjectFundingDTO> dtos = new ArrayList<ProjectFundingDTO>();
                            projectDTO.setFunded(dtos);

                            loadProjectFundings(fundeds, dtos, fundedsAndFundingsRequestManager, transaction);
                        }

                        final JsArray<ProjectFundingJS> fundings = projectJS.getFunding();
                        if (fundings != null) {
                            final ArrayList<ProjectFundingDTO> dtos = new ArrayList<ProjectFundingDTO>();
                            projectDTO.setFunding(dtos);

                            loadProjectFundings(fundings, dtos, fundedsAndFundingsRequestManager, transaction);
                        }

                        fundedsAndFundingsRequestManager.ready();
                    }
                }
            }, transaction);

    // Loading phases
    if (projectJS.getPhases() != null) {
        final ArrayList<PhaseDTO> phases = new ArrayList<PhaseDTO>();
        projectDTO.setPhases(phases);

        final JsArrayInteger phaseIds = projectJS.getPhases();
        final int size = phaseIds.length();

        for (int index = 0; index < size; index++) {
            phaseAsyncDAO.get(phaseIds.get(index), new RequestManagerCallback<M, PhaseDTO>(requestManager) {
                @Override
                public void onRequestSuccess(PhaseDTO result) {
                    result.setParentProject(projectDTO);
                    phases.add(result);
                }
            }, transaction);
        }
    }

    if (Values.isDefined(projectJS, "currentPhase")) {
        phaseAsyncDAO.get(projectJS.getCurrentPhase(), new RequestManagerCallback<M, PhaseDTO>(requestManager) {
            @Override
            public void onRequestSuccess(PhaseDTO result) {
                projectDTO.setCurrentPhase(result);
                projectDTO.setCurrentPhaseName(result.getPhaseModel().getName());
            }
        }, transaction);
    }

    // Loading log frame
    if (Values.isDefined(projectJS, "logFrame")) {
        logFrameAsyncDAO.get(projectJS.getLogFrame(),
                new RequestManagerCallback<M, LogFrameDTO>(requestManager) {
                    @Override
                    public void onRequestSuccess(LogFrameDTO result) {
                        projectDTO.setLogFrame(result);
                    }
                }, transaction);
    }

    // Loading monitored points and reminders
    if (projectDTO.getPointsList() != null && projectDTO.getPointsList().getId() != null) {
        monitoredPointAsyncDAO.getAllByParentListId(projectDTO.getPointsList().getId(),
                new RequestManagerCallback<M, List<MonitoredPointDTO>>(requestManager) {

                    @Override
                    public void onRequestSuccess(List<MonitoredPointDTO> result) {
                        projectDTO.getPointsList().setPoints(result);
                    }
                }, transaction);
    }

    if (projectDTO.getRemindersList() != null && projectDTO.getRemindersList().getId() != null) {
        reminderAsyncDAO.getAllByParentListId(projectDTO.getRemindersList().getId(),
                new RequestManagerCallback<M, List<ReminderDTO>>(requestManager) {

                    @Override
                    public void onRequestSuccess(List<ReminderDTO> result) {
                        projectDTO.getRemindersList().setReminders(result);
                    }
                }, transaction);
    }

    // Loading OrgUnit name.
    if (Values.isDefined(projectJS, "orgUnit")) {
        orgUnitAsyncDAO.get(projectJS.getOrgUnit(), new RequestManagerCallback<M, OrgUnitDTO>(requestManager) {
            @Override
            public void onRequestSuccess(OrgUnitDTO result) {
                if (result != null) {
                    projectDTO.setOrgUnitName(result.getName() + " - " + result.getFullName());
                }
            }
        }, transaction);
    }
}

From source file:org.sigmah.offline.dao.ProjectModelAsyncDAO.java

License:Open Source License

/**
 * {@inheritDoc}//from www .  jav  a  2 s . c o  m
 */
@Override
public void get(int id, final AsyncCallback<ProjectModelDTO> callback, final Transaction<Store> transaction) {
    if (transaction.useObjectFromCache(ProjectModelDTO.class, id, callback)) {
        return;
    }

    final ObjectStore projectModelStore = transaction.getObjectStore(Store.PROJECT_MODEL);

    projectModelStore.get(id).addCallback(new AsyncCallback<Request>() {

        @Override
        public void onFailure(Throwable caught) {
            callback.onFailure(caught);
        }

        @Override
        public void onSuccess(Request request) {
            final ProjectModelJS projectModelJS = request.getResult();
            if (projectModelJS != null) {
                final ProjectModelDTO projectModelDTO = projectModelJS.toDTO();

                final RequestManager<ProjectModelDTO> requestManager = new RequestManager<ProjectModelDTO>(
                        projectModelDTO, callback);

                final JsArrayInteger phaseModels = projectModelJS.getPhaseModels();
                if (phaseModels != null) {
                    final ArrayList<PhaseModelDTO> dtos = new ArrayList<PhaseModelDTO>();
                    projectModelDTO.setPhaseModels(dtos);

                    for (int index = 0; index < phaseModels.length(); index++) {
                        phaseModelAsyncDAO.get(phaseModels.get(index),
                                new RequestManagerCallback<ProjectModelDTO, PhaseModelDTO>(requestManager) {
                                    @Override
                                    public void onRequestSuccess(PhaseModelDTO result) {
                                        if (result != null) {
                                            dtos.add(result);
                                        }
                                    }
                                }, transaction);
                    }
                }

                requestManager.ready();

            } else {
                callback.onSuccess(null);
            }
        }
    });
}

From source file:org.turbogwt.core.collections.JsArrays.java

License:Apache License

public static int[] toArray(JsArrayInteger values) {
    if (GWT.isScript()) {
        return reinterpretCast(values);
    } else {//from www  .  j  a v a  2s  .c  o m
        int length = values.length();
        int[] ret = new int[length];
        for (int i = 0, l = length; i < l; i++) {
            ret[i] = values.get(i);
        }
        return ret;
    }
}

From source file:org.uberfire.ext.widgets.common.client.colorpicker.SaturationLightnessPicker.java

License:Apache License

private String getColorAtPixel(int x, int y) {
    x = Math.max(Math.min(x, 179), 0);
    y = Math.max(Math.min(y, 179), 0);
    RenderingContext ctx = canvas.getContext();
    ImageData imageData = ctx.getImageData(x, y, 1, 1);
    JsArrayInteger data = imageData.getData();
    return ColorUtils.rgb2hex(data.get(0), data.get(1), data.get(2));
}

From source file:org.vectomatic.svg.chess.JSONBook.java

License:Open Source License

public void generateMoves(Board board) {
    String key2Find = "x" + Long.toHexString(board.getKey());
    totalWeight = 0;/*from w  w w. j a v  a 2 s  .  c o  m*/
    moves = new ArrayList<Integer>();
    weights = new ArrayList<Integer>();
    JsArray<JsArrayInteger> array = getData(key2Find);
    if (array != null) {
        JsArrayInteger moveArray = array.get(0);
        JsArrayInteger weightArray = array.get(1);
        for (int i = 0, size = moveArray.length(); i < size; i++) {
            int moveInt = moveArray.get(i);
            int weight = weightArray.get(i);
            int move = Move.getFromString(board, int2MoveString(moveInt));
            // Add only if it is legal
            if (board.isMoveLegal(move)) {
                GWT.log("JSONBook addMove(" + move + ", " + weight + ")", null);
                moves.add(move);
                weights.add(weight);
                totalWeight += weight;
            }
        }
    }
}

From source file:uk.co.thinkofdeath.mapviewer.worker.world.WorkerChunk.java

License:Apache License

private void sendChunk() {
    ChunkLoadedMessage message = ChunkLoadedMessage.create(getX(), getZ());
    ArrayList<Object> buffers = new ArrayList<>();
    // Copy sections
    for (int i = 0; i < 16; i++) {
        if (sections[i] != null) {
            TUint8Array data = TUint8Array.create(sections[i].getBuffer());
            buffers.add(data.getBuffer());
            message.setSection(i, sections[i].getCount(), data);
        }/*w  w w .j a  va 2s.  co m*/
    }

    message.setNextId(nextId);

    JsArrayInteger keys = idBlockMap.keys();
    for (int i = 0; i < keys.length(); i++) {
        int key = keys.get(i);
        message.addIdBlockMapping(key, idBlockMap.get(key));
    }

    for (Map.Entry<Block, Integer> e : blockIdMap.entrySet()) {
        message.addBlockIdMapping(e.getKey(), e.getValue());
    }

    world.worker.postMessage(WorkerMessage.create("chunk:loaded", message, false),
            buffers.toArray(new Object[buffers.size()]));
}