Statistics
| Revision:

gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.lib / org.gvsig.vectorediting.lib.spi / src / main / java / org / gvsig / vectorediting / lib / spi / DefaultEditingServiceinfo.java @ 92

History | View | Annotate | Download (2.94 KB)

1
/*
2
 * Copyright 2014 DiSiD Technologies S.L.L. All rights reserved.
3
 * 
4
 * Project  : DiSiD org.gvsig.vectorediting.lib.spi 
5
 * SVN Id   : $Id$
6
 */
7
package org.gvsig.vectorediting.lib.spi;
8

    
9
import java.awt.Image;
10
import java.util.List;
11

    
12
import org.gvsig.fmap.dal.feature.FeatureStore;
13
import org.gvsig.fmap.geom.GeometryLocator;
14
import org.gvsig.fmap.geom.type.GeometryType;
15
import org.gvsig.vectorediting.lib.api.EditingServiceInfo;
16
import org.gvsig.vectorediting.lib.api.EditingServiceParameter;
17
import org.gvsig.vectorediting.lib.api.exceptions.ServiceInformationException;
18

    
19
public class DefaultEditingServiceinfo implements EditingServiceInfo {
20

    
21
  private String name;
22

    
23
  private String description;
24

    
25
  private boolean createsNewGeometries;
26

    
27
  private Image mouseCursor;
28

    
29
  private List<EditingServiceParameter> parameters;
30

    
31
  private int[] supportedPrimitiveGeometryType;
32

    
33
  public DefaultEditingServiceinfo(String name, String description,
34
      boolean createsNewGeometries, Image mouseCursor,
35
      List<EditingServiceParameter> parameters,
36
      int[] supportedPrimitiveGeometryType) {
37
    super();
38
    this.name = name;
39
    this.description = description;
40
    this.createsNewGeometries = createsNewGeometries;
41
    this.mouseCursor = mouseCursor;
42
    this.parameters = parameters;
43
    this.supportedPrimitiveGeometryType = supportedPrimitiveGeometryType;
44
  }
45

    
46
  public boolean createsNewGeometries() {
47
    return this.createsNewGeometries;
48
  }
49

    
50
  public String getDescription() {
51
    return this.description;
52
  }
53

    
54
  public Image getMouseIcon() {
55
    return this.mouseCursor;
56
  }
57

    
58
  public String getName() {
59
    return this.name;
60
  }
61

    
62
  public List<EditingServiceParameter> getParameters() {
63
    return this.parameters;
64
  }
65

    
66
  public int[] getSupportedPrimitiveGeometryTypes() {
67
    return this.supportedPrimitiveGeometryType;
68
  }
69

    
70
  public EditingServiceParameter getParameterInfo(String name) {
71
    // TODO Auto-generated method stub
72
    return null;
73
  }
74

    
75
  public boolean isCompatibleWith(FeatureStore featureStore)
76
      throws ServiceInformationException {
77
    int[] supportedTypes = getSupportedPrimitiveGeometryTypes();
78
    GeometryType featureGeomType;
79
    GeometryType supportedGeomtype;
80
    try {
81
      featureGeomType = featureStore.getDefaultFeatureType()
82
          .getDefaultGeometryAttribute().getGeomType();
83
    } catch (Exception e) {
84
      throw new ServiceInformationException("Can't get geometry type of "
85
          + featureStore.getName(), e);
86
    }
87
    for (int i = 0; i < supportedTypes.length; i++) {
88
      try {
89
        supportedGeomtype = GeometryLocator.getGeometryManager().getGeometryType(supportedTypes[i], featureGeomType.getSubType());
90
      }catch (Exception e){
91
        throw new ServiceInformationException("Can't get geometry type with type "
92
            + supportedTypes[i]  + " and subtype " + featureGeomType.getSubType(), e);
93
      }
94
      if (supportedGeomtype.isTypeOf(featureGeomType.getType())) {
95
        return true;
96
      }
97
    }
98
    return false;
99
  }
100

    
101
}