/** * Override error. * * <p>Description ... * * @see org.geotools.validation.ValidationResults#error(org.geotools.feature.SimpleFeature, * java.lang.String) * @param feature * @param message */ public void error(SimpleFeature feature, String message) { // add the error to our list of failed features + failure messages if (message == null) message = ""; // $NON-NLS-1$ failedFeatures.add(feature); failureMessages.add(feature.getID() + ": " + message); // $NON-NLS-1$ // find the layer of the current feature IMap activeMap = ApplicationGIS.getActiveMap(); List<ILayer> layers = new ArrayList<ILayer>(); if (activeMap != ApplicationGIS.NO_MAP) { layers.addAll(activeMap.getMapLayers()); } Layer layer = null; for (Iterator i = layers.listIterator(); i.hasNext(); ) { Layer thisLayer = (Layer) i.next(); if (feature.getName().getLocalPart().equals(thisLayer.getName())) { layer = thisLayer; break; } } // add the error to the issues list FeatureIssue issue = new FeatureIssue( Priority.HIGH, message, layer, feature, Messages.GenericValidationResults_validationError); issues.add(issue); }
public void rollback(IProgressMonitor monitor) throws Exception { Layer editLayer = (Layer) handler.getEditLayer(); editLayer.setFilter(oldFilter); EditBlackboard editBlackboard = handler.getEditBlackboard(editLayer); editBlackboard.startBatchingEvents(); for (EditGeom geom : geoms) { copyFeature(editBlackboard, geom); } handler.setCurrentState(this.currentState); editBlackboard.fireBatchedEvents(); handler.repaint(); }
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()); }
public void perform() { Layer selectedLayer = getSelectedLayer(); original = selectedLayer.getStyleBlackboard(); EditorPageManager manager = EditorPageManager.loadManager(PrintingPlugin.getDefault(), selectedLayer); Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); StyleEditorDialog dialog = StyleEditorDialog.createDialogOn(parentShell, null, selectedLayer, manager); dialog.setBlockOnOpen(true); int returnCode = dialog.open(); if (returnCode != Window.OK) { selectedLayer.setStyleBlackboard(original); original = null; } }
public void run(IProgressMonitor monitor) throws Exception { Layer editLayer = (Layer) handler.getEditLayer(); if (currentShape != null) { this.currentShape = handler.getCurrentShape(); this.currentState = handler.getCurrentState(); this.geoms = handler.getEditBlackboard(editLayer).getGeoms(); } handler.setCurrentShape(null); handler.setCurrentState(EditState.NONE); oldFilter = (Filter) editLayer.getFilter(); editLayer.setFilter(Filter.EXCLUDE); EditUtils.instance.cancelHideSelection(editLayer); EditBlackboard editBlackboard = handler.getEditBlackboard(editLayer); editBlackboard.startBatchingEvents(); editBlackboard.clear(); editBlackboard.fireBatchedEvents(); handler.repaint(); }
/** * Creates a query that requests the features in sourceLayer as dictated by filter. Query only * requests the attributes that can be mapped from sourceLayer to targetLayer. * * @param queryAttributes populates with a mapping of attributeTypeNames from targetLayer to * sourcelayer * @return */ @SuppressWarnings("unchecked") private Query createQuery( ILayer sourceLayer, Filter filter, Layer targetLayer, Map<String, String> queryAttributes) { SimpleFeatureType sourceSchema = sourceLayer.getSchema(); SimpleFeatureType targetSchema = targetLayer.getSchema(); // Maps type names to type names since we are ignoring case queryAttributes.putAll(FeatureUtils.createAttributeMapping(sourceSchema, targetSchema)); Set<String> properties = new HashSet(queryAttributes.values()); return new DefaultQuery( sourceSchema.getName().getLocalPart(), filter, properties.toArray(new String[properties.size()])); }
public void refresh() { Layer layer = getSelectedLayer(); IGeoResource resource = layer.getGeoResource(); if (!resource.canResolve(FeatureSource.class)) { return; } StyleBlackboard styleBlackboard = layer.getStyleBlackboard(); oldStyle = (Style) styleBlackboard.get(SLDContent.ID); if (oldStyle == null) { oldStyle = Utilities.createDefaultPointStyle(); } DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor(); dsv.visit(oldStyle); style = (Style) dsv.getCopy(); if (!isPointStyle(style)) { stackLayout.topControl = noFeatureLabel; } else { stackLayout.topControl = propertiesEditor.getControl(); propertiesEditor.updateStyle(style); } mainComposite.layout(); }
public Command getCommand() { final StyleBlackboard originalStyleBlackboard = this.original; this.original = null; final Layer layer = getSelectedLayer(); final StyleBlackboard newBlackboard = layer.getStyleBlackboard(); return new Command() { @Override public String getLabel() { return "Change Style"; } @Override public void execute() { layer.setStyleBlackboard(newBlackboard); } @Override public void undo() { layer.setStyleBlackboard(originalStyleBlackboard); } }; }
/** * Creates a page based on the template selected in the wizard **Note: this function may swap the * width and height if the template prefers different page orientation. * * @return a page */ protected Page makePage(Rectangle pageSize, Document doc, Template template) { Map mapOnlyRasterLayers = null; Map mapNoRasterLayers = null; // **Note: the iText API doesn't render rasters at a high enough resolution if // they are written to the PDF via graphics2d. To work around this problem, I // create two copies of the map: one with only the raster layers, and one with // everything else. // The "everything else" map gets drawn by a graphics2d. The other layer must be // rasterized and inserted into the PDF via iText's API. // make one copy of the map with no raster layers mapNoRasterLayers = (Map) ApplicationGIS.copyMap(map); List<Layer> layersNoRasters = mapNoRasterLayers.getLayersInternal(); List<Layer> toRemove = new ArrayList<Layer>(); for (Layer layer : layersNoRasters) { for (IGeoResource resource : layer.getGeoResources()) { if (resource.canResolve(GridCoverageReader.class)) { toRemove.add(layer); } } } layersNoRasters.removeAll(toRemove); // adjust scale double currentViewportScaleDenom = map.getViewportModel().getScaleDenominator(); if (currentViewportScaleDenom == -1) throw new IllegalStateException( "no scale denominator is available from the viewport model"); //$NON-NLS-1$ if (page1.getScaleOption() == PrintWizardPage1.CUSTOM_MAP_SCALE) { float customScale = page1.getCustomScale(); template.setMapScaleHint(customScale); } else if (page1.getScaleOption() == PrintWizardPage1.CURRENT_MAP_SCALE) { template.setMapScaleHint(currentViewportScaleDenom); } else if (page1.getScaleOption() == PrintWizardPage1.ZOOM_TO_SELECTION) { template.setZoomToSelectionHint(true); template.setMapScaleHint(currentViewportScaleDenom); } // 3. make the page itself Page page = ModelFactory.eINSTANCE.createPage(); page.setSize(new Dimension((int) pageSize.getWidth(), (int) pageSize.getHeight())); // page name stuff not required, because this page will just get discarded MessageFormat formatter = new MessageFormat(Messages.CreatePageAction_newPageName, Locale.getDefault()); if (page.getName() == null || page.getName().length() == 0) { page.setName(formatter.format(new Object[] {mapNoRasterLayers.getName()})); } template.init(page, mapNoRasterLayers); if (page1.getRasterEnabled()) { // make another copy with only raster layers mapOnlyRasterLayers = (Map) ApplicationGIS.copyMap(map); List<Layer> layersOnlyRasters = mapOnlyRasterLayers.getLayersInternal(); List<Layer> toRemove2 = new ArrayList<Layer>(); for (Layer layer : layersOnlyRasters) { for (IGeoResource resource : layer.getGeoResources()) { if (!resource.canResolve(GridCoverageReader.class)) { toRemove2.add(layer); } } } layersOnlyRasters.removeAll(toRemove2); // set bounds to match the other map SetViewportBBoxCommand cmdBbox = new SetViewportBBoxCommand(mapNoRasterLayers.getViewportModel().getBounds()); mapOnlyRasterLayers.sendCommandSync(cmdBbox); if (layersNoRasters.size() > 0) { writeRasterLayersOnlyToDocument( mapOnlyRasterLayers, template.getMapBounds(), doc, page.getSize(), /*currentViewportScaleDenom*/ mapNoRasterLayers.getViewportModel().getScaleDenominator()); } } // copy the boxes from the template into the page Iterator<Box> iter = template.iterator(); while (iter.hasNext()) { page.getBoxes().add(iter.next()); } return page; // TODO Throw some sort of exception if the page can't be created }
@Override public boolean canStyle(Layer aLayer) { return aLayer.hasResource(LegendGraphic.class); }
@Override public boolean canStyle(Layer aLayer) { return aLayer.hasResource(ActiveRegionMapGraphic.class); }
public void run(Layer layer) { System.out.println( layer.getName() + " has been removed from a map. This is a test interceptor. "); //$NON-NLS-1$ }
@SuppressWarnings("unchecked") private void copyFeatures( ILayer sourceLayer, Filter filter, final Layer targetLayer, final IProgressMonitor monitor) { monitor.beginTask(Messages.CopyFeaturesCommand_name, 104); final int[] worked = new int[] {-3}; monitor.worked(1); try { SubProgressMonitor subProgressMonitor = new SubProgressMonitor(monitor, 2); FeatureStore<SimpleFeatureType, SimpleFeature> destination = targetLayer.getResource(FeatureStore.class, subProgressMonitor); subProgressMonitor.done(); worked[0] += 2; subProgressMonitor = new SubProgressMonitor(monitor, 2); FeatureSource<SimpleFeatureType, SimpleFeature> source = sourceLayer.getResource(FeatureSource.class, subProgressMonitor); subProgressMonitor.done(); worked[0] += 2; // If no FeatureStore then features can't be copied // If no FeatureSource then features can't be copied if (destination == null || source == null) { targetLayer.setFilter(filter); return; } // Create a query that will get the attributes that are compatible // what is compatible? Do the attribute names and types have to be the same or // just the types. // Executive decision: // Match both name and type, the rest must be customized. final HashMap<String, String> attributeMap = new HashMap<String, String>(); Query query = createQuery(sourceLayer, filter, targetLayer, attributeMap); if (attributeMap.isEmpty()) { targetLayer.setFilter(filter); return; } MathTransform mt = createMathTransform(sourceLayer, targetLayer); FeatureCollection<SimpleFeatureType, SimpleFeature> features = source.getFeatures(query); SimpleFeatureType schema = targetLayer.getSchema(); CopyFeatureCollection c = new CopyFeatureCollection( schema, features, monitor, worked, mt, attributeMap, targetLayer.layerToMapTransform()); Envelope env = c.env; targetLayer.eSetDeliver(false); try { List<FeatureId> fids = destination.addFeatures(c); displayCopiedFeatures(env); FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints()); addedFeaturesFilter = filterFactory.id(new HashSet(fids)); } finally { targetLayer.eSetDeliver(true); } getMap().getRenderManager().refresh(targetLayer, env); } catch (IOException e) { throw (RuntimeException) new RuntimeException().initCause(e); } finally { monitor.done(); } }
public void run(IProgressMonitor monitor) throws Exception { if (sourceLayer == null || destinationLayer == null) return; previousEnvelope = getMap().getViewportModel().getBounds(); previousDesinationLayerFilter = destinationLayer.getFilter(); copyFeatures(sourceLayer, filter, destinationLayer, monitor); }