IUiSelectionManager - Current selection manager
IUiSelectionManager
- an interface to get or change the current selection.
Possibilities
getSelection()
- returns theIRangeAddress
of the currently selected cellssetSelection(IRangeAddress target)
- sets a newIRangeAddress
as a current selectionsetSelection(int worksheetId, IRangeAddress target)
- switches to a given worksheet by ID and sets a newIRangeAddress
as a current selectiongetActiveWorksheetId()
- returns the ID of the current worksheet
Usage example
import com.intechcore.scomponents.scell.api.fx.IScellUiApi;
import com.intechcore.scomponents.scell.api.fx.IScellUiApiBuilder;
import com.intechcore.scomponents.scell.api.fx.IScellUiFxApiBuilder;
import com.intechcore.scomponents.scell.api.init.ScellApiEntryPoint;
import com.intechcore.scomponents.scell.api.spreadsheet.IScellCoreApiFactory;
import com.intechcore.scomponents.scell.api.spreadsheet.service.builder.IRangeAddressBuilder;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class TestAppUi extends Application {
@Override
public void start(Stage primaryStage) {
BorderPane root = new BorderPane(new Label("Initializing ..."));
ScellApiEntryPoint.getApiResolverAsync().thenApplyAsync(resolver -> {
IScellCoreApiFactory apiFactory = resolver.resolve(IScellCoreApiFactory.class);
IScellUiApiBuilder<Node> uiBuilder = resolver.resolve(IScellUiFxApiBuilder.class);
IScellUiApi<Node> uiApi = uiBuilder
.readOnly(false)
.create(apiFactory.createNew());
IRangeAddressBuilder addressBuilder = resolver.resolve(IRangeAddressBuilder.class);
// Clear all content example (it is similar to creation a new spreadsheet)
Button createNewButton = new Button("Set selection to range B3:D5");
createNewButton.setOnAction(event -> {
createNewButton.setDisable(true);
// Set new active selection area
uiApi.getSelectionManager().setSelection(addressBuilder.fromA1String("B3:D5").buildRange());
createNewButton.setDisable(false);
});
root.setTop(createNewButton);
return uiApi.getControl();
}, Platform::runLater).whenCompleteAsync((node, throwable) -> {
if (throwable != null) {
node = new Label("Failed to init: " + throwable.getCause().getMessage());
}
root.setCenter(node);
}, Platform::runLater);
primaryStage.setScene(new Scene(root, 800, 600));
primaryStage.show();
}
}
See also
IUiContentManager - Changing current UI content