Search in sources :

Example 1 with CoverageExplorer

use of org.apache.sis.gui.coverage.CoverageExplorer in project sis by apache.

the class ResourceExplorer method getSelectedData.

/**
 * Returns the set of currently selected data, or {@code null} if none.
 * This is invoked when the user selects the "New window" menu item.
 */
@Override
final SelectedData getSelectedData() {
    final Resource resource = getSelectedResource();
    if (resource == null) {
        return null;
    }
    FeatureTable table = null;
    CoverageExplorer grid = null;
    if (resource instanceof GridCoverageResource) {
        /*
             * Want the full coverage in all bands (sample dimensions).
             */
        if (coverage == null) {
            // For forcing creation of CoverageExplorer.
            updateDataTab(resource);
        }
        grid = coverage;
    } else if (resource instanceof FeatureSet) {
        /*
             * We will not set features in an initially empty `FeatureTable` (to be newly created),
             * but instead share the `FeatureLoader` created by the feature table of this explorer.
             * We do that even if the feature table is not currently visible. This will not cause
             * useless data loading since they share the same `FeatureLoader`.
             */
        if (features == null) {
            // For forcing creation of FeatureTable.
            updateDataTab(resource);
        }
        table = features;
    } else {
        return null;
    }
    String text;
    try {
        text = ResourceTree.findLabel(resource, resources.locale, true);
    } catch (DataStoreException | RuntimeException e) {
        text = Vocabulary.getResources(resources.locale).getString(Vocabulary.Keys.Unnamed);
    }
    return new SelectedData(text, table, grid, localized());
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) Resource(org.apache.sis.storage.Resource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) CoverageExplorer(org.apache.sis.gui.coverage.CoverageExplorer) FeatureSet(org.apache.sis.storage.FeatureSet)

Example 2 with CoverageExplorer

use of org.apache.sis.gui.coverage.CoverageExplorer in project sis by apache.

the class ResourceExplorer method updateDataTab.

/**
 * Assigns the given resource into the {@link #viewTab} or {@link #tableTab}, depending which one is visible.
 * Shall be invoked with a non-null resource only if a data tab is visible because data loading may be costly.
 *
 * @param  resource  the resource to set, or {@code null} if none.
 * @return {@code true} if the resource has been recognized.
 *
 * @see #dataShown
 * @see #updateDataTabWithDefault(Resource)
 */
private boolean updateDataTab(final Resource resource) {
    Region image = null;
    Region table = null;
    FeatureSet data = null;
    ImageRequest grid = null;
    TitledPane[] cpanes = null;
    final CoverageExplorer.View type = getCoverageView();
    if (resource instanceof GridCoverageResource) {
        // A null `type` value here would be a violation of method contract.
        if (coverage == null) {
            coverage = new CoverageExplorer(type);
        } else {
            coverage.setViewType(type);
        }
        final Region view = coverage.getDataView(type);
        switch(type) {
            case IMAGE:
                image = view;
                break;
            case TABLE:
                table = view;
                break;
        }
        grid = new ImageRequest((GridCoverageResource) resource, null, null);
        cpanes = coverage.getControls(type);
    } else if (resource instanceof FeatureSet) {
        data = (FeatureSet) resource;
        if (features == null) {
            features = new FeatureTable();
        }
        table = features;
    }
    /*
         * At least one of `grid` or `data` will be null. Invoking the following
         * setter methods with a null argument will release memory.
         */
    if (coverage != null)
        coverage.setCoverage(grid);
    if (features != null)
        features.setFeatures(data);
    if (image != null)
        viewTab.setContent(image);
    if (table != null)
        tableTab.setContent(table);
    final boolean isEmpty = (image == null & table == null);
    setNewWindowDisabled(isEmpty);
    /*
         * Add or remove controls for the selected view.
         * Information about the expanded pane needs to be saved before to remove controls,
         * and restored (for a potentially different view) after new controls have been added.
         */
    TitledPane expanded = controls.getExpandedPane();
    if (expanded != null && coverageView != null) {
        expandedPane.put(coverageView, expanded);
    }
    final ObservableList<TitledPane> items = controls.getPanes();
    final int size = items.size();
    items.remove(1, size);
    if (cpanes != null) {
        items.addAll(cpanes);
        if (!items.contains(expanded)) {
            expanded = expandedPane.get(type);
            if (expanded != null) {
                controls.setExpandedPane(expanded);
            }
        }
    }
    coverageView = type;
    return !isEmpty | (resource == null);
}
Also used : TitledPane(javafx.scene.control.TitledPane) ImageRequest(org.apache.sis.gui.coverage.ImageRequest) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) Region(javafx.scene.layout.Region) CoverageExplorer(org.apache.sis.gui.coverage.CoverageExplorer) FeatureSet(org.apache.sis.storage.FeatureSet)

Aggregations

CoverageExplorer (org.apache.sis.gui.coverage.CoverageExplorer)2 FeatureSet (org.apache.sis.storage.FeatureSet)2 GridCoverageResource (org.apache.sis.storage.GridCoverageResource)2 TitledPane (javafx.scene.control.TitledPane)1 Region (javafx.scene.layout.Region)1 ImageRequest (org.apache.sis.gui.coverage.ImageRequest)1 DataStoreException (org.apache.sis.storage.DataStoreException)1 Resource (org.apache.sis.storage.Resource)1