Search in sources :

Example 1 with DefaultProgressListener

use of org.geotools.util.DefaultProgressListener in project polymap4-core by Polymap4.

the class ColorMap2FilterEditor method createRandomColorMap.

/**
 * Creates a new #colorMap with default color for values of the current #propertyName.
 */
protected void createRandomColorMap() throws IOException {
    colorMap.clear();
    // count occurences; maps property value into count
    Map<Object, AtomicInteger> valueOccurences = new HashMap(MAX_VALUES * 2);
    ProgressListener progress = new DefaultProgressListener();
    site().featureStore.get().getFeatures().accepts(feature -> {
        // get value
        Object value = feature.getProperty(propertyName).getValue();
        valueOccurences.computeIfAbsent(value, v -> new AtomicInteger()).incrementAndGet();
        // check MAX_VALUES
        if (valueOccurences.size() > MAX_VALUES) {
            progress.setCanceled(true);
        }
    }, progress);
    log.info("Color map entries: " + valueOccurences.size());
    if (progress.isCanceled()) {
        StatusDispatcher.handle(new Status(IStatus.INFO, CorePlugin.PLUGIN_ID, i18n.get("tooManyEntries", MAX_VALUES), null), Style.SHOW, Style.LOG);
    } else {
        valueOccurences.entrySet().stream().sorted((e1, e2) -> e2.getValue().get() - e1.getValue().get()).forEach(entry -> colorMap.add(new Triple(entry.getKey(), entry.getValue().get(), DefaultStyle.randomColor())));
    }
}
Also used : Color(java.awt.Color) Config(org.polymap.core.runtime.config.Config) ColumnLayoutFactory(org.polymap.core.ui.ColumnLayoutFactory) StringUtils(org.apache.commons.lang3.StringUtils) Point(org.eclipse.swt.graphics.Point) StylePlugin(org.polymap.core.style.StylePlugin) ProgressListener(org.opengis.util.ProgressListener) StatusDispatcher(org.polymap.core.ui.StatusDispatcher) IStatus(org.eclipse.core.runtime.IStatus) PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) Button(org.eclipse.swt.widgets.Button) Status(org.eclipse.core.runtime.Status) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) DefaultStyle(org.polymap.core.style.DefaultStyle) List(java.util.List) IMessages(org.polymap.core.runtime.i18n.IMessages) ColorChooser(org.polymap.core.style.ui.ColorChooser) SWT(org.eclipse.swt.SWT) Literal(org.opengis.filter.expression.Literal) LogFactory(org.apache.commons.logging.LogFactory) Messages(org.polymap.core.style.Messages) Label(org.eclipse.swt.widgets.Label) RWT(org.eclipse.rap.rwt.RWT) Mapped(org.polymap.core.style.model.feature.MappedValues.Mapped) StylePropertyFieldSite(org.polymap.core.style.ui.StylePropertyFieldSite) StylePropertyEditor(org.polymap.core.style.ui.StylePropertyEditor) Configurable(org.polymap.core.runtime.config.Configurable) FormLayoutFactory(org.polymap.core.ui.FormLayoutFactory) HashMap(java.util.HashMap) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Mandatory(org.polymap.core.runtime.config.Mandatory) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ArrayList(java.util.ArrayList) Style(org.polymap.core.ui.StatusDispatcher.Style) UIUtils(org.polymap.core.ui.UIUtils) RGB(org.eclipse.swt.graphics.RGB) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Viewer(org.eclipse.jface.viewers.Viewer) IOException(java.io.IOException) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) CorePlugin(org.polymap.core.CorePlugin) PropertyName(org.opengis.filter.expression.PropertyName) FilterMappedColors(org.polymap.core.style.model.feature.FilterMappedColors) UIService(org.polymap.core.style.ui.UIService) Filter(org.opengis.filter.Filter) Log(org.apache.commons.logging.Log) FormDataFactory(org.polymap.core.ui.FormDataFactory) DefaultProgressListener(org.geotools.util.DefaultProgressListener) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) LabelProvider(org.eclipse.jface.viewers.LabelProvider) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ProgressListener(org.opengis.util.ProgressListener) DefaultProgressListener(org.geotools.util.DefaultProgressListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) DefaultProgressListener(org.geotools.util.DefaultProgressListener)

Aggregations

Color (java.awt.Color)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 RWT (org.eclipse.rap.rwt.RWT)1 SWT (org.eclipse.swt.SWT)1