Quick Start

Add Intechcore repository's creds to the maven's settings.xml (by default this file is in <your_home_dir>/.m2/settings.xml)

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

<servers>
    <server>
        <id>intechcore-demo</id>
        <username>given_username</username>
        <password>given_password</password>
    </server>
</servers>

</settings>

(if there's no file, create it and place all the content above)

Add the SCell Public API dependency to the POM:

    ...
    <repositories>
        <repository>
            <id>intechcore-demo</id>
            <name>scalable components demo</name>
            <url>https://nexus.intechcore.online/repository/maven-scomponents-demo</url>
        </repository>
    </repositories>
    ...
    <dependencies>
        ...
        <dependency>
            <groupId>com.intechcore.scomponents.scell</groupId>
            <artifactId>api</artifactId>
            <version>1.0-Demo</version>
        </dependency>
        <dependency>
            <groupId>com.intechcore.scomponents.scell</groupId>
            <artifactId>api-impl</artifactId>
            <version>1.0-Demo</version>
            <scope>runtime</scope>
        </dependency>
        ...
    </dependencies>
    ...

Start the API-library initialization:

    public class App extends Application {
        private static CompletableFuture<Optional<IScellApiResolver>> apiResolverFuture = ScellApiProvider.getApiResolverAsync();

        public static void main(String[] args) {
            apiResolverFuture.thenApply(apiResolver -> {
                //...
            });
            
            // ...
        }
    }

The call ScellApiProvider.getApiResolverAsync() return the IScellApiResolver implementation which will be used to resolve API entry points or register custom implementation of API interfaces.

After getting the resolver you can resolve the API entry points:


import javafx.scene.layout.Pane;

public class App extends Application {
    private static 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> coreApi = coreProvider.createNew(); // Core API entry point
            IScellUiApi<Node> fxApi = uiFxApiProvider.create(coreApi); // Java FX control API entry point

            someRootPane.getChildren().add(fxApi.createControl()); // adding the SCell UI control
            //...
        });
        // ...
    }

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

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

The API entry points are resolved through coreProvider and uiFxProvider.

SCell API main entry points are: IWorkbook - core API entry point, IScellUiApi<Node> - UI API entry point for Java FX.

To create the Java FX API entry point you need the implementation of core IWorkbook interface.

The IWorkbook accessible from the ISpreadsheetApiProvider by method createNew() (new spreadsheet) or load() (existing spreadsheet).

Example 1 - Adding content to cells and save workbook to file

public class App extends Application {
    private static CompletableFuture<Optional<IScellApiResolver>> apiResolverFuture = ScellApiProvider.getApiResolverAsync();
    private Optional<IScellApiResolver> apiResolver;

    @Override
    public void start(Stage stage) {
        //...
        apiResolver.ifPresent(resolver -> {
            ISpreadsheetApiProvider apiProvider = this.apiResolver.resolve(ISpreadsheetApiProvider.class);

            IWorkbook workbook = apiProvider.createNew().join();

            IRangeAddressBuilder addressBuilder = this.apiResolver.resolve(IRangeAddressBuilder.class);

            workbook.all().findFirst().ifPresent(worksheet -> {
                // Add data to cells
                worksheet.getContent().inputContent(
                        addressBuilder.setTopLeft(1, 2).buildCell(),
                        "Date");

                worksheet.getContent().inputContent(
                        addressBuilder.setTopLeft(1, 3).buildCell(),
                        "Signature");

                IntStream.range(2, 20).forEach(rowNumber -> {
                    int columnNumber = 2;
                    worksheet.getContent().inputContent(
                            addressBuilder.setTopLeft(rowNumber, columnNumber++).buildCell(),
                            LocalDate.now().plusDays(rowNumber).toString());

                    worksheet.getContent().inputContent(
                            addressBuilder.setTopLeft(rowNumber, columnNumber).buildCell(),
                            UUID.randomUUID().toString());
                });
            });

            // Save workbook to file
            workbook.createWriter().fileName("fillExample").save().join();
        });
    }

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

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

Example 2 - Creation simply spreadsheet desktop application

import com.intechcore.scomponents.scell.api.IScellApiResolver;
import com.intechcore.scomponents.scell.api.ScellApiProvider;
import com.intechcore.scomponents.scell.api.spreadsheet.ISpreadsheetApiProvider;
import com.intechcore.scomponents.scell.api.spreadsheet.model.IWorkbook;
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 javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.util.Optional;
import java.util.concurrent.CompletableFuture;

public class App extends javafx.application.Application
{
	private static final CompletableFuture<Optional<IScellApiResolver>> apiResolverFuture
			= ScellApiProvider.getApiResolverAsync();

	private Optional<IScellApiResolver> apiResolver;

	@Override
	public void start(Stage stage) {
		VBox mainContainer = new VBox(new Label("Please, wait..."), new ProgressBar());
		mainContainer.setAlignment(Pos.CENTER);

		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

			mainContainer.getChildren().clear(); // remove the progress bar
			mainContainer.getChildren().add(scellJavaFxNode);                // Adding the SCell UI control

		});

		stage.setScene(new Scene(mainContainer, 1755, 900));
		stage.show();
	}

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

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

See also

Reference