@Test
  public void testSelectDeselectFeature() {
    org.geomajas.layer.feature.Feature dto1 = new org.geomajas.layer.feature.Feature();
    dto1.setId("feat1");
    Feature feature1 = new Feature(dto1, layer1);

    org.geomajas.layer.feature.Feature dto2 = new org.geomajas.layer.feature.Feature();
    dto2.setId("feat2");
    Feature feature2 = new Feature(dto2, layer1);

    Assert.assertFalse(feature1.isSelected());
    Assert.assertFalse(feature2.isSelected());
    Assert.assertEquals(0, selectedCount);
    Assert.assertEquals(0, deselectedCount);
    Assert.assertNull(lastFeatureId);

    layer1.selectFeature(feature1);
    Assert.assertTrue(feature1.isSelected());
    Assert.assertFalse(feature2.isSelected());
    Assert.assertEquals(1, selectedCount);
    Assert.assertEquals(0, deselectedCount);
    Assert.assertEquals("feat1", lastFeatureId);
    lastFeatureId = null;

    layer1.selectFeature(feature2);
    Assert.assertTrue(feature1.isSelected());
    Assert.assertTrue(feature2.isSelected());
    Assert.assertEquals(2, selectedCount);
    Assert.assertEquals(0, deselectedCount);
    Assert.assertEquals("feat2", lastFeatureId);

    layer1.deselectFeature(feature1);
    Assert.assertFalse(feature1.isSelected());
    Assert.assertTrue(feature2.isSelected());
    Assert.assertEquals(2, selectedCount);
    Assert.assertEquals(1, deselectedCount);
    Assert.assertEquals("feat1", lastFeatureId);
  }
  @Before
  public void setUp() {
    ClientMapInfo info = new ClientMapInfo();
    info.setCrs("EPSG:4326");
    info.setInitialBounds(new Bbox(0, 0, 180, 180));
    mapModel = new MapModel(info);

    VectorLayerInfo serverLayerInfo1 = new VectorLayerInfo();
    ClientVectorLayerInfo layerInfo1 = new ClientVectorLayerInfo();
    layerInfo1.setLayerInfo(serverLayerInfo1);
    layerInfo1.setMaxExtent(new Bbox(0, 0, 200, 100));
    layerInfo1.setId("layer1");
    layerInfo1.setServerLayerId("layer1");
    layer1 = new VectorLayer(mapModel, layerInfo1);

    VectorLayerInfo serverLayerInfo2 = new VectorLayerInfo();
    ClientVectorLayerInfo layerInfo2 = new ClientVectorLayerInfo();
    layerInfo2.setLayerInfo(serverLayerInfo2);
    layerInfo2.setMaxExtent(new Bbox(0, 0, 250, 125));
    layerInfo2.setId("layer2");
    layerInfo2.setServerLayerId("layer2");
    layer2 = new VectorLayer(mapModel, layerInfo2);

    mapModel.getLayers().add(layer1);
    mapModel.getLayers().add(layer2);

    selectedCount = 0;
    deselectedCount = 0;
    lastFeatureId = null;
    layer1.addFeatureSelectionHandler(
        new FeatureSelectionHandler() {
          public void onFeatureSelected(FeatureSelectedEvent event) {
            selectedCount++;
            lastFeatureId = event.getFeature().getId();
          }

          public void onFeatureDeselected(FeatureDeselectedEvent event) {
            deselectedCount++;
            lastFeatureId = event.getFeature().getId();
          }
        });
  }
  @Test
  public void testDeselectLayer() {
    org.geomajas.layer.feature.Feature dto1 = new org.geomajas.layer.feature.Feature();
    dto1.setId("feat1");
    Feature feature1 = new Feature(dto1, layer1);

    org.geomajas.layer.feature.Feature dto2 = new org.geomajas.layer.feature.Feature();
    dto2.setId("feat2");
    Feature feature2 = new Feature(dto2, layer1);

    Assert.assertFalse(feature1.isSelected());
    Assert.assertFalse(feature2.isSelected());
    Assert.assertEquals(0, selectedCount);
    Assert.assertEquals(0, deselectedCount);

    mapModel.selectLayer(layer1);
    Assert.assertFalse(feature1.isSelected());
    Assert.assertFalse(feature2.isSelected());
    Assert.assertEquals(0, selectedCount);
    Assert.assertEquals(0, deselectedCount);

    layer1.selectFeature(feature1);
    layer1.selectFeature(feature2);
    Assert.assertTrue(feature1.isSelected());
    Assert.assertTrue(feature2.isSelected());
    Assert.assertEquals(2, selectedCount);
    Assert.assertEquals(0, deselectedCount);

    mapModel.selectLayer(layer1);
    Assert.assertTrue(feature1.isSelected());
    Assert.assertTrue(feature2.isSelected());
    Assert.assertEquals(2, selectedCount);
    Assert.assertEquals(0, deselectedCount);

    mapModel.selectLayer(layer2);
    Assert.assertTrue(feature1.isSelected());
    Assert.assertTrue(feature2.isSelected());
    Assert.assertEquals(2, selectedCount);
    Assert.assertEquals(0, deselectedCount);
  }
예제 #4
0
  public ReferralLayerBlock(Layer<?> referral) {
    super(referral);
    this.layer = (VectorLayer) referral;

    final ChangedHandler filterChangedHandler = new FilterChangedHandler();
    dateForm1 = new ReferralDateFilterForm(filterChangedHandler);
    dateForm2 = new ReferralDateFilterForm(filterChangedHandler);

    FeatureInfo featureInfo = layer.getLayerInfo().getFeatureInfo();

    AssociationAttributeInfo statusInfo =
        (AssociationAttributeInfo)
            featureInfo.getAttributesMap().get(KtunaxaConstant.ATTRIBUTE_STATUS);
    AssociationAttributeInfo agencyTypeInfo =
        (AssociationAttributeInfo)
            featureInfo.getAttributesMap().get(KtunaxaConstant.ATTRIBUTE_EXTERNAL_AGENCY_TYPE);
    AssociationAttributeInfo typeInfo =
        (AssociationAttributeInfo)
            featureInfo.getAttributesMap().get(KtunaxaConstant.ATTRIBUTE_TYPE);

    clearStatus.setStartRow(false);
    clearStatus.setEndRow(false);
    clearStatus.addClickHandler(
        new ClickHandler() {

          @Override
          public void onClick(ClickEvent event) {
            status.clearValue();
            filterChangedHandler.onChanged(null);
          }
        });
    clearAgency.setStartRow(false);
    clearAgency.setEndRow(false);
    clearAgency.addClickHandler(
        new ClickHandler() {

          @Override
          public void onClick(ClickEvent event) {
            agency.clearValue();
            filterChangedHandler.onChanged(null);
          }
        });
    clearType.setStartRow(false);
    clearType.setEndRow(false);
    clearType.addClickHandler(
        new ClickHandler() {

          @Override
          public void onClick(ClickEvent event) {
            type.clearValue();
            filterChangedHandler.onChanged(null);
          }
        });

    form.setWidth100();
    status.getItem().setTitle("Status");
    status.getItem().addChangedHandler(filterChangedHandler);
    status.init(statusInfo, new DefaultAttributeProvider(layer, statusInfo.getName()));
    agency.getItem().setTitle("External Agency Type");
    agency.getItem().addChangedHandler(filterChangedHandler);
    agency.init(agencyTypeInfo, new DefaultAttributeProvider(layer, agencyTypeInfo.getName()));
    type.getItem().setTitle("Type");
    type.getItem().addChangedHandler(filterChangedHandler);
    type.init(typeInfo, new DefaultAttributeProvider(layer, typeInfo.getName()));
    form.setNumCols(4);
    form.setFields(
        status.getItem(), clearStatus, agency.getItem(), clearAgency, type.getItem(), clearType);
    addMember(form);
    addMember(dateForm1);
    addMember(dateForm2);
  }