Package org.thechiselgroup.choosel.core.client.resources

Examples of org.thechiselgroup.choosel.core.client.resources.DefaultResourceSet


    public ResourceSet createResources(StringTable table) throws ParseException {
        assert table != null;

        String uriType = uriHeaderProvider.nextLabel();

        ResourceSet resources = new DefaultResourceSet();
        resources.setLabel("import"); // TODO changeable, inc number

        if (table.getRowCount() == 0) {
            return resources;
        }

        // use first row to determine types
        DataType[] columnTypes = new DataType[table.getColumnCount()];
        for (int column = 0; column < table.getColumnCount(); column++) {
            String stringValue = table.getValue(0, column);

            if (NUMBER_DETECTION_REGEX.test(stringValue)) {
                columnTypes[column] = DataType.NUMBER;
            } else if (DATE_FORMAT_1_REGEX.test(stringValue)) {
                columnTypes[column] = DataType.DATE;
            } else if (DATE_FORMAT_2_REGEX.test(stringValue)) {
                columnTypes[column] = DataType.DATE;
            } else if (LOCATION_DETECTION_REGEX.test(stringValue)) {
                columnTypes[column] = DataType.LOCATION;
            } else {
                columnTypes[column] = DataType.TEXT;
            }
        }

        for (int row = 0; row < table.getRowCount(); row++) {
            String uri = uriType + ":" + row;
            Resource resource = new Resource(uri);

            for (int column = 0; column < table.getColumnCount(); column++) {
                String stringValue = table.getValue(row, column);

                /*
                 * TODO should not be parsed at this point - change once setting
                 * property types possible
                 */
                Serializable value;

                switch (columnTypes[column]) {
                case NUMBER:
                    if (!NUMBER_DETECTION_REGEX.test(stringValue)) {
                        throw new ParseException("Invalid number", stringValue,
                                row + 1);
                    }
                    value = new Double(stringValue);
                    break;
                case DATE:
                    if (DATE_FORMAT_1_REGEX.test(stringValue)) {
                        value = parseDate1(stringValue);
                    } else if (DATE_FORMAT_2_REGEX.test(stringValue)) {
                        value = parseDate2(stringValue);
                    } else {
                        throw new ParseException("Invalid date", stringValue,
                                row + 1);
                    }
                    break;
                case LOCATION:
                    if (!LOCATION_DETECTION_REGEX.test(stringValue)) {
                        throw new ParseException("Invalid location",
                                stringValue, row + 1);
                    }

                    Resource locationResource = new Resource();
                    String[] split = stringValue.split("\\/");
                    locationResource.putValue(ResourceSetUtils.LATITUDE,
                            Double.parseDouble(split[0]));
                    locationResource.putValue(ResourceSetUtils.LONGITUDE,
                            Double.parseDouble(split[1]));
                    value = locationResource;
                    break;
                default:
                    value = stringValue;
                    break;
                }

                resource.putValue(table.getColumnName(column), value);
            }

            resources.add(resource);
        }

        return resources;
    }
View Full Code Here


    public void init() {
        selectionPresenter.init();
        selectionDropPresenter.init();

        // TODO refactor: move to somewhere else (e.g. decorator)
        DefaultResourceSet resources = new DefaultResourceSet();
        resources.setLabel("add selection");
        selectionDropPresenter.addResourceSet(resources);

        initSelectionModelLink();
    }
View Full Code Here

                                .getDelegate());
            }
        }

        // 2. store sets
        ResourceSet resourceCollector = new DefaultResourceSet();
        ResourceSetDTO[] resourceSetDTOs = new ResourceSetDTO[persistanceManager
                .getResourceSets().size()];
        for (int i = 0; i < persistanceManager.getResourceSets().size(); i++) {
            ResourceSetDTO dto = new ResourceSetDTO();
            ResourceSet resourceSet = persistanceManager.getResourceSets().get(
                    i);

            if (resourceSet.hasLabel()) {
                dto.setLabel(resourceSet.getLabel());
            }

            dto.setId(i);

            if (resourceSet instanceof UnmodifiableResourceSet) {
                ResourceSet sourceSet = ((UnmodifiableResourceSet) resourceSet)
                        .getDelegate();

                dto.setDelegateSetId(persistanceManager
                        .storeResourceSet(sourceSet));
            } else {
                List<String> resourceIds = new ArrayList<String>();
                for (Resource resource : resourceSet) {
                    resourceCollector.add(resource);
                    resourceIds.add(resource.getUri());
                }
                dto.setResourceIds(resourceIds);
            }

            resourceSetDTOs[i] = dto;
        }
        viewDTO.setResourceSets(resourceSetDTOs);

        Resource[] resources = new Resource[resourceCollector.size()];
        int count = 0;
        for (Resource resource : resourceCollector) {
            resources[count++] = resource;
        }
View Full Code Here

        this.viewItemID = viewItemID;
        this.resources = resources;
        this.slotMappingConfiguration = slotMappingConfiguration;
        this.interactionHandler = interactionHandler;

        highlightedResources = new DefaultResourceSet();
        selectedResources = new DefaultResourceSet();

        initCacheCleaning(resources, slotMappingConfiguration);

        resources.addEventHandler(new ResourceSetChangedEventHandler() {
            @Override
View Full Code Here

         * the popup removes the resource a bit later.
         */
        highlightedSingleResources = new CountingResourceSet();

        combinedHighlightedResources = new UnionResourceSet(
                new DefaultResourceSet());
        combinedHighlightedResources
                .addResourceSet(highlightedResourceSetContainer);
        combinedHighlightedResources.addResourceSet(highlightedSingleResources);
    }
View Full Code Here

     * </p>
     */
    private ResourceSet getIntersectionWithViewResources(
            LightweightCollection<Resource> resources) {

        ResourceSet resourcesInThisView = new DefaultResourceSet();
        resourcesInThisView.addAll(resourceGrouping.getResourceSet()
                .getIntersection(resources));
        return resourcesInThisView;
    }
View Full Code Here

     * Creates an intersection of contained resources with highlighted resources
     * and registers for changes.
     */
    private void initHighlightingModel() {
        highlightedResourcesIntersection = new IntersectionResourceSet(
                new DefaultResourceSet());
        highlightedResourcesIntersection
                .addResourceSet(getContentResourceSet());
        highlightedResourcesIntersection.addResourceSet(highlightedResources);

        handlerRegistrations.addHandlerRegistration(highlightedResources
View Full Code Here

     * </p>
     */
    private ResourceSet getIntersectionWithVisualizationResources(
            LightweightCollection<Resource> resources) {

        ResourceSet resourcesInThisView = new DefaultResourceSet();
        resourcesInThisView.addAll(getContentResourceSet().getIntersection(
                resources));
        return resourcesInThisView;
    }
View Full Code Here

                                .getDelegate());
            }
        }

        // 2. store sets
        ResourceSet resourceCollector = new DefaultResourceSet();
        ResourceSetDTO[] resourceSetDTOs = new ResourceSetDTO[resourceSetCollector
                .getResourceSets().size()];
        for (int i = 0; i < resourceSetCollector.getResourceSets().size(); i++) {
            ResourceSetDTO dto = new ResourceSetDTO();
            ResourceSet resourceSet = resourceSetCollector.getResourceSets()
                    .get(i);

            if (resourceSet.hasLabel()) {
                dto.setLabel(resourceSet.getLabel());
            }

            dto.setId(i);

            if (resourceSet instanceof UnmodifiableResourceSet) {
                ResourceSet sourceSet = ((UnmodifiableResourceSet) resourceSet)
                        .getDelegate();

                dto.setDelegateSetId(resourceSetCollector
                        .storeResourceSet(sourceSet));
            } else {
                List<String> resourceIds = new ArrayList<String>();
                for (Resource resource : resourceSet) {
                    resourceCollector.add(resource);
                    resourceIds.add(resource.getUri());
                }
                dto.setResourceIds(resourceIds);
            }
View Full Code Here

         * the popup removes the resource a bit later.
         */
        highlightedSingleResources = new CountingResourceSet();

        combinedHighlightedResources = new UnionResourceSet(
                new DefaultResourceSet());
        combinedHighlightedResources
                .addResourceSet(highlightedResourceSetContainer);
        combinedHighlightedResources.addResourceSet(highlightedSingleResources);
    }
View Full Code Here

TOP

Related Classes of org.thechiselgroup.choosel.core.client.resources.DefaultResourceSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.