private void runVisibilityTest(Map map, Layer layer, Layer layer2, boolean isShapefileTest)
      throws PartInitException, Exception {
    map.getLayersInternal().add(layer);
    map.setProjectInternal(ProjectPlugin.getPlugin().getProjectRegistry().getCurrentProject());
    map.setName("SetVisibilityTest"); // $NON-NLS-1$
    assertFalse(layer.getGeoResources().isEmpty());

    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(LayersView.ID);

    ApplicationGIS.openMap(map, true);
    map.getRenderManagerInternal().refresh(null);
    Thread.yield();
    waitInUI(map);

    int expectedlayers = isShapefileTest ? 2 : 1;
    assertion(map, expectedlayers);

    map.getLayersInternal().add(layer2);
    map.getRenderManagerInternal().refresh(null);
    waitInUI(map);

    expectedlayers = isShapefileTest ? 4 : 1;
    assertion(map, expectedlayers);

    layer.setVisible(false);
    waitInUI(map);
    assertion(map, expectedlayers);

    layer.setVisible(true);
    waitInUI(map);
    assertion(map, expectedlayers);

    layer.setVisible(false);
    layer2.setVisible(false);
    waitInUI(map);
    assertion(map, expectedlayers);
    //		assertBlank(map.getRenderManagerInternal());

    layer.setVisible(true);
    layer2.setVisible(true);
    waitInUI(map);
    assertion(map, expectedlayers);

    layer2.setVisible(false);
    waitInUI(map);
    assertion(map, expectedlayers);
    // TESTING - currently this causes a random failure.  Something to do with waitInUI
    //		assertNotBlank(map.getRenderManagerInternal());

    layer.setVisible(false);
    waitInUI(map);
    assertion(map, expectedlayers);
    //		assertBlank(map.getRenderManagerInternal());
  }
예제 #2
0
  @SuppressWarnings("unchecked")
  @Before
  public void setUp() throws Exception {
    ProjectRegistry registry = ProjectPlugin.getPlugin().getProjectRegistry();
    List<Project> projects = registry.getProjects();
    registry.getProjects().removeAll(projects);

    EList list = registry.eResource().getResourceSet().getResources();
    Set<Resource> toRemove = new HashSet<Resource>();
    for (Iterator iter = list.iterator(); iter.hasNext(); ) {
      Resource element = (Resource) iter.next();
      if (element != registry.eResource()) {
        element.unload();
        toRemove.add(element);
      }
    }

    project = registry.getDefaultProject();
    file = new File(project.eResource().getURI().toFileString());
    if (file.exists()) {
      if (file.isFile()) {
        file.delete();
        File parent = file.getParentFile();
        File[] files = parent.listFiles();
        for (File file : files) {
          file.delete();
        }
        parent.delete();
      }
      file.delete();
    }

    registry.eResource().getResourceSet().getResources().removeAll(toRemove);

    project =
        registry.getProject(
            FileLocator.toFileURL(Platform.getInstanceLocation().getURL()).getFile());

    resource1 =
        MapTests.createGeoResource(UDIGTestUtil.createDefaultTestFeatures(type1Name, 4), false);
    Map map = MapTests.createNonDynamicMapAndRenderer(resource1, new Dimension(512, 512));
    map.setName(firstMapName);
    map.getLayersInternal().get(0).setName(firstMapLayerName);

    resource2 =
        MapTests.createGeoResource(UDIGTestUtil.createDefaultTestFeatures(type2Name, 6), false);
    map = MapTests.createNonDynamicMapAndRenderer(resource2, new Dimension(512, 512));
    map.setName(secondMapName);
    map.getLayersInternal().get(0).setName(secondMapLayerName);
  }
  /**
   * Creates A geometry filter for the given layer.
   *
   * @param boundingBox in the same crs as the viewport model.
   * @return a Geometry filter in the correct CRS or null if an exception occurs.
   */
  public Filter createBBoxFilter(
      ReferencedEnvelope boundingBox, ILayer layer, Class<? extends Filter> filterType) {
    FilterFactory2 factory = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
    if (!layer.hasResource(FeatureSource.class)) return Filter.EXCLUDE;
    try {

      SimpleFeatureType schema = layer.getSchema();
      Name geom = getGeometryAttDescriptor(schema).getName();

      Filter bboxFilter = factory.bbox(factory.property(geom), boundingBox);

      return bboxFilter;
    } catch (Exception e) {
      ProjectPlugin.getPlugin().log(e);
      return Filter.EXCLUDE;
    }
  }
예제 #4
0
  @Ignore
  @Test
  public void testSaveAndLoad() throws Exception {
    EList list = project.eResource().getResourceSet().getResources();

    for (Iterator iter = list.iterator(); iter.hasNext(); ) {
      Resource element = (Resource) iter.next();
      try {
        element.save(null);
      } catch (Exception e) {
      }
      if (!element.getContents().contains(ProjectPlugin.getPlugin().getProjectRegistry()))
        element.unload();
    }

    ResourceSet set = new ResourceSetImpl();
    Project project =
        (Project)
            set.getResource(URI.createURI("file://" + file.getAbsolutePath()), true)
                .getAllContents()
                .next(); //$NON-NLS-1$
    assertFalse(project.eIsProxy());
    assertNotNull(project);
    int maps = 0;
    boolean foundFirstMap = false;
    boolean foundSecondMap = false;

    List resources = project.getElements();
    for (Iterator iter = resources.iterator(); iter.hasNext(); ) {
      Map map = (Map) iter.next();

      assertFalse(map.eIsProxy());
      assertEquals(1, map.getLayersInternal().size());
      assertNotNull(map.getLayersInternal().get(0).getGeoResources().get(0));
      assertNotNull(
          map.getLayersInternal()
              .get(0)
              .getResource(FeatureSource.class, new NullProgressMonitor()));

      if (map.getName().equals(firstMapName)) {
        foundFirstMap = true;
        assertEquals(firstMapLayerName, map.getLayersInternal().get(0).getName());
        FeatureSource<SimpleFeatureType, SimpleFeature> source =
            map.getLayersInternal().get(0).getResource(FeatureSource.class, null);
        assertEquals(4, source.getCount(Query.ALL));
        assertEquals(firstMapLayerName, map.getLayersInternal().get(0).getName());
      }
      if (map.getName().equals(secondMapName)) {
        foundSecondMap = true;
        assertEquals(secondMapLayerName, map.getLayersInternal().get(0).getName());
        FeatureSource<SimpleFeatureType, SimpleFeature> source =
            map.getLayersInternal().get(0).getResource(FeatureSource.class, null);
        assertEquals(6, source.getCount(Query.ALL));
        assertEquals(secondMapLayerName, map.getLayersInternal().get(0).getName());
      }
      maps++;
    }
    assertEquals(2, maps);
    assertTrue(foundFirstMap);
    assertTrue(foundSecondMap);
  }
예제 #5
0
  /**
   * Start editing the provided symbolizer.
   *
   * @param schema
   * @param sym
   * @param mode
   */
  public void set(SimpleFeatureType schema, TextSymbolizer sym, Mode mode) {
    listen(false);
    try {
      this.schema = schema;
      this.enabled = (mode != Mode.NONE && sym != null);

      this.font = SLDs.textFont(sym);
      if (this.font == null || this.font.length == 0) {
        this.font = new FontData[] {new FontData("Arial", 12, SWT.NORMAL)}; // $NON-NLS-1$
      }
      this.labelType = SLDs.textLabelString(sym);
      this.colour = SLDs.textFontFill(sym);
      if (this.colour == null) {
        this.colour = Color.BLACK;
      }

      this.on.setEnabled(mode != Mode.NONE);
      this.fonter.setColorValue(this.colour);
      this.fonter.setFontList(this.font);

      if (schema != null) {
        AttributeDescriptor[] attrs =
            schema.getAttributeDescriptors().toArray(new AttributeDescriptor[0]);
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < attrs.length; i++) {
          Class cls = attrs[i].getType().getBinding();
          if (String.class.isAssignableFrom(cls)) {
            list.add(attrs[i].getName().getLocalPart());
          } else if (Number.class.isAssignableFrom(cls)) {
            list.add(attrs[i].getName().getLocalPart());
          }
        }
        this.field.removeAll();
        this.field.setItems(list.toArray(new String[0]));
        if (this.labelType == null) {
          this.field.select(0);
        } else {
          this.field.setText(this.labelType);
        }
      }

      this.on.setSelection(this.enabled);
      this.field.setEnabled(this.enabled);
      this.fonter.setEnabled(this.enabled);

      if (schema != null && (SLD.isLine(schema) == pointPlacement || this.place == null)) {
        pointPlacement = !SLD.isLine(schema);
        if (pointPlacement) {
          initPlacementContentsPoint();
        } else {
          initPlacementContentsLine();
        }
      }
      this.place.setEnabled(this.enabled);
      if (pointPlacement) {
        // PointPlacement
        this.place2.setEnabled(this.enabled);
        this.place3.setEnabled(this.enabled);
        if (this.labelPlacement == null || !(this.labelPlacement instanceof PointPlacement)) {
          // defaults
          if (mode == Mode.POINT) {
            // don't cover the point!
            this.place.select(2); // top
            this.place2.select(2); // right
          } else {
            this.place.select(1); // middle
            this.place2.select(1); // center
          }
          this.place3.select(0); // 0 degrees rotation
        } else {
          AnchorPoint anchor = ((PointPlacement) labelPlacement).getAnchorPoint();
          String anchorX = anchor.getAnchorPointX().toString();
          String anchorY = anchor.getAnchorPointY().toString();
          // use labels if 0, 0.5, or 1, otherwise use value for align
          if (anchorX.equals(Double.toString(SLDs.ALIGN_LEFT))) {
            this.place2.select(0);
          } else if (anchorX.equals(Double.toString(SLDs.ALIGN_CENTER))) {
            this.place2.select(1);
          } else if (anchorX.equals(Double.toString(SLDs.ALIGN_RIGHT))) {
            this.place2.select(2);
          } else {
            this.place2.setText(anchorX);
          }
          if (anchorY.equals(Double.toString(SLDs.ALIGN_BOTTOM))) {
            this.place.select(0);
          } else if (anchorY.equals(Double.toString(SLDs.ALIGN_MIDDLE))) {
            this.place.select(1);
          } else if (anchorY.equals(Double.toString(SLDs.ALIGN_TOP))) {
            this.place.select(2);
          } else {
            this.place.setText(anchorY);
          }
          // rotation
          this.place3.setText(((PointPlacement) labelPlacement).getRotation().toString());
        }
      } else {
        // LinePlacement
        if (this.labelPlacement == null || !(this.labelPlacement instanceof LinePlacement)) {
          // defaults
          this.place.setText(
              ProjectPlugin.getPlugin()
                  .getPreferenceStore()
                  .getString(PreferenceConstants.P_STYLE_DEFAULT_PERPENDICULAR_OFFSET));
        } else {
          String offset = ((LinePlacement) labelPlacement).getPerpendicularOffset().toString();
          this.place.setText(offset);
        }
      }
    } finally {
      listen(true);
    }
  }