Search in sources :

Example 1 with NewGuidedDecisionTableWizard

use of org.drools.workbench.screens.guided.dtable.client.wizard.table.NewGuidedDecisionTableWizard in project drools-wb by kiegroup.

the class NewGuidedDecisionTableWizardHelper method createNewGuidedDecisionTable.

/**
 * Presents the {@link NewGuidedDecisionTableWizard} to Users to creates a new Guided Decision Table.
 *
 * @param contextPath           The base path where the Decision Table will be created. Cannot be null.
 * @param baseFileName          The base file name of the new Decision Table. Cannot be null.
 * @param tableFormat           The format of the Decision Table. Cannot be null.
 * @param view                  A {@link HasBusyIndicator} to handle status messages. Cannot be null.
 * @param onSaveSuccessCallback Called when the new Decision Table has successfully been created. Cannot be null.
 */
public void createNewGuidedDecisionTable(final Path contextPath, final String baseFileName, final GuidedDecisionTable52.TableFormat tableFormat, final GuidedDecisionTable52.HitPolicy hitPolicy, final HasBusyIndicator view, final RemoteCallback<Path> onSaveSuccessCallback) {
    PortablePreconditions.checkNotNull("contextPath", contextPath);
    PortablePreconditions.checkNotNull("baseFileName", baseFileName);
    PortablePreconditions.checkNotNull("tableFormat", tableFormat);
    PortablePreconditions.checkNotNull("hitPolicy", hitPolicy);
    PortablePreconditions.checkNotNull("view", view);
    PortablePreconditions.checkNotNull("onSaveSuccessCallback", onSaveSuccessCallback);
    dtService.call(new RemoteCallback<PackageDataModelOracleBaselinePayload>() {

        @Override
        public void callback(final PackageDataModelOracleBaselinePayload dataModel) {
            final AsyncPackageDataModelOracle oracle = oracleFactory.makeAsyncPackageDataModelOracle(contextPath, dataModel);
            // NewGuidedDecisionTableHandler is @ApplicationScoped and so has a single instance of the NewGuidedDecisionTableWizard injected.
            // The Wizard maintains state and hence multiple use of the same Wizard instance leads to the Wizard UI showing stale values.
            // Rather than have the Wizard initialise fields when shown I elected to create new instances whenever needed.
            wizard = beanManager.lookupBean(NewGuidedDecisionTableWizard.class).getInstance();
            wizard.setContent(contextPath, baseFileName, tableFormat, hitPolicy, oracle, new NewGuidedDecisionTableWizard.GuidedDecisionTableWizardHandler() {

                @Override
                public void save(final Path contextPath, final String baseFileName, final GuidedDecisionTable52 model) {
                    destroyWizard();
                    oracleFactory.destroy(oracle);
                    view.showBusyIndicator(CommonConstants.INSTANCE.Saving());
                    dtService.call((Path path) -> {
                        view.hideBusyIndicator();
                        onSaveSuccessCallback.callback(path);
                    }, new HasBusyIndicatorDefaultErrorCallback(view)).create(contextPath, buildFileName(baseFileName), model, "");
                }

                private String buildFileName(final String baseFileName) {
                    final String suffix = dtResourceType.getSuffix();
                    final String prefix = dtResourceType.getPrefix();
                    final String extension = !(suffix == null || "".equals(suffix)) ? "." + dtResourceType.getSuffix() : "";
                    if (baseFileName.endsWith(extension)) {
                        return prefix + baseFileName;
                    }
                    return prefix + baseFileName + extension;
                }

                @Override
                public void destroyWizard() {
                    if (wizard != null) {
                        beanManager.destroyBean(wizard);
                        wizard = null;
                    }
                }
            });
            wizard.start();
        }
    }).loadDataModel(contextPath);
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) Path(org.uberfire.backend.vfs.Path) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) NewGuidedDecisionTableWizard(org.drools.workbench.screens.guided.dtable.client.wizard.table.NewGuidedDecisionTableWizard) HasBusyIndicatorDefaultErrorCallback(org.uberfire.ext.widgets.common.client.callbacks.HasBusyIndicatorDefaultErrorCallback) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback)

Aggregations

GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)1 NewGuidedDecisionTableWizard (org.drools.workbench.screens.guided.dtable.client.wizard.table.NewGuidedDecisionTableWizard)1 RemoteCallback (org.jboss.errai.common.client.api.RemoteCallback)1 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)1 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)1 Path (org.uberfire.backend.vfs.Path)1 HasBusyIndicatorDefaultErrorCallback (org.uberfire.ext.widgets.common.client.callbacks.HasBusyIndicatorDefaultErrorCallback)1