IUiContentManager - changing current UI content

IUiContentManager - interface to change current UI-displayed spreadsheet.

Possibilities

Usage example

import com.intechcore.scomponents.scell.api.IScellApiResolver;
import com.intechcore.scomponents.scell.api.ScellApiProvider;
import com.intechcore.scomponents.scell.api.ui.fx.IScellUiApi;
import com.intechcore.scomponents.scell.api.ui.fx.IScellUiApiProvider;
import com.intechcore.scomponents.scell.api.ui.fx.IScellUiFxApiProvider;
import com.intechcore.scomponents.scell.api.spreadsheet.ISpreadsheetApiProvider;

import com.intechcore.scomponents.scell.api.ui.fx.control.IUiContentManager;
import javafx.application.Application;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.stage.Stage;

import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;

public class App extends Application {

    private static final CompletableFuture<Optional<IScellApiResolver>> apiResolverFuture
            = ScellApiProvider.getApiResolverAsync();

    private Optional<IScellApiResolver> apiResolver;

    @Override
    public void start(Stage stage) {
        //...
        Pane someRootPane = new Pane();
        // ...
        this.apiResolver.ifPresent(resolver -> {
            // Resolve APIs providers
            ISpreadsheetApiProvider coreProvider = resolver.resolve(ISpreadsheetApiProvider.class);
            IScellUiApiProvider<Node> uiFxApiProvider = resolver.resolve(IScellUiFxApiProvider.class);

            CompletableFuture<IWorkbook> workbook = coreProvider.createNew(); // SCell core API entry point
            IScellUiApi<Node> uiApi = uiFxApiProvider.create(workbook);       // SCell UI API entry point
            Node scellJavaFxNode = uiApi.createControl();                     // SCell UI control
            someRootPane.getChildren().add(scellJavaFxNode);                  // Adding the SCell UI control

            IUiContentManager uiContentManager = uiApi.getContentManager();   // Getting the content manager

            // Clear all content example (it is similar to creation a new spreadsheet)
            Button createNewButton = new Button();
            createNewButton.setOnAction(event -> {
                createNewButton.setDisable(true);
                
                uiContentManager.clear() // Clears all the existing content of the SCell UI control
                        .thenRun(() -> createNewButton.setDisable(false));
            });
            someRootPane.getChildren().add(createNewButton);

            
            // Load an existing xlsx-file example
            Button loadButton = new Button();
            loadButton.setOnAction(event -> {
                FileChooser fileChooser = new FileChooser();
                fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("XLSX files (*.xlsx)", "*.xlsx"));
                File fileToLoad =  fileChooser.showSaveDialog(stage);
                if (fileToLoad == null) {
                    return;
                }
                
                loadButton.setDisable(true);
                uiContentManager.load(fileToLoad) // loads a xlsx-file to the SCell UI component
                        .thenRun(() -> loadButton.setDisable(false));
            });
        });
        // ...
    }

    @Override
    public void init() throws Exception {
        this.apiResolver = apiResolverFuture.join();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Next (IUiSelectionManager - Current selection manager)

See also

IUiControlSettings - Changing UI at runtime

IUiContentManager - Changing current UI content