package org.drools.workbench.screens.testscenario.client.handler;

import com.google.gwt.core.client.Callback;
import com.google.gwt.user.client.ui.IsWidget;
import org.drools.workbench.models.testscenarios.shared.Scenario;
import org.jboss.errai.bus.client.api.RemoteCallback;
import org.jboss.errai.ioc.client.api.Caller;
import org.kie.workbench.common.widgets.client.callbacks.HasBusyIndicatorDefaultErrorCallback;
import org.kie.workbench.common.widgets.client.handlers.DefaultNewResourceHandler;
import org.kie.workbench.common.widgets.client.handlers.NewResourcePresenter;
import org.kie.workbench.common.widgets.client.resources.i18n.CommonConstants;
import org.kie.workbench.common.widgets.client.widget.BusyIndicatorView;
import org.drools.workbench.screens.testscenario.client.TestScenarioResourceType;
import org.drools.workbench.screens.testscenario.client.resources.i18n.TestScenarioConstants;
import org.drools.workbench.screens.testscenario.client.resources.images.TestScenarioAltedImages;
import org.drools.workbench.screens.testscenario.service.ScenarioTestEditorService;
import org.uberfire.backend.vfs.Path;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

@ApplicationScoped
public class NewTestScenarioHandler
        extends DefaultNewResourceHandler {

    @Inject
    private BusyIndicatorView busyIndicatorView;

    @Inject
    private Caller<ScenarioTestEditorService> service;

    @Inject
    private TestScenarioResourceType resourceType;

    @Override
    public String getDescription() {
        return TestScenarioConstants.INSTANCE.NewTestScenarioDescription();
    }

    @Override
    public IsWidget getIcon() {
        return TestScenarioAltedImages.INSTANCE.TestScenario();
    }

    @Override
    public void create(Path context, String baseFileName, NewResourcePresenter presenter) {
        busyIndicatorView.showBusyIndicator(CommonConstants.INSTANCE.Saving());

        service.call(
                getSuccessCallback(presenter),
                new HasBusyIndicatorDefaultErrorCallback(busyIndicatorView)
        ).create(context,
                buildFileName(resourceType, baseFileName),
                new Scenario(),
                "");
    }

    @Override
    public void acceptPath(final Path path,
                           final Callback<Boolean, Void> callback) {
        projectService.call(new RemoteCallback<Path>() {
            @Override
            public void callback(final Path path) {
                callback.onSuccess(path != null);
            }
        }).resolveTestPackage(path);
    }
}

@@ -1784,16 +1784,17 @@
  create(
+ 
 Path con
@@ -1802,29 +1802,77 @@
 ext,
- String baseFileName,
+%0A                        String baseFileName,%0A                       
  New
@@ -1898,16 +1898,17 @@
 resenter
+ 
 ) %7B%0A    
@@ -1947,16 +1947,17 @@
 dicator(
+ 
 CommonCo
@@ -1981,16 +1981,17 @@
 Saving()
+ 
 );%0A%0A    
@@ -2043,16 +2043,17 @@
 allback(
+ 
 presente
@@ -2053,16 +2053,17 @@
 resenter
+ 
 ),%0A     
@@ -2114,16 +2114,17 @@
 allback(
+ 
 busyIndi
@@ -2132,16 +2132,17 @@
 atorView
+ 
 )%0A      
@@ -2143,16 +2143,28 @@
         
+      
+      
 ).create
@@ -2164,16 +2164,17 @@
 .create(
+ 
 context,
@@ -2190,16 +2190,30 @@
         
+         
+     
 buildFil
@@ -2218,16 +2218,17 @@
 ileName(
+ 
 resource
@@ -2245,16 +2245,17 @@
 FileName
+ 
 ),%0A     
@@ -2261,24 +2261,38 @@
             
+        
+      
 new Scenario
@@ -2315,10 +2315,25 @@
     
+          
+    
 %22%22
+ 
 );%0A 
@@ -2379,16 +2379,17 @@
 eptPath(
+ 
 final Pa
@@ -2424,16 +2424,17 @@
         
+ 
 final Ca
@@ -2463,20 +2463,113 @@
 callback
+ 
 ) %7B%0A
+        if ( path == null ) %7B%0A            callback.onSuccess( false );%0A        %7D else %7B%0A    
         
@@ -2588,16 +2588,17 @@
 ce.call(
+ 
 new Remo
@@ -2626,24 +2626,28 @@
             
+    
 @Override%0A  
@@ -2652,24 +2652,28 @@
             
+   
+ 
 public void 
@@ -2681,16 +2681,17 @@
 allback(
+ 
 final Pa
@@ -2697,16 +2697,17 @@
 ath path
+ 
 ) %7B%0A    
@@ -2710,32 +2710,36 @@
                 
+ 
+   
 callback.onSucce
@@ -2741,16 +2741,17 @@
 Success(
+ 
 path != 
@@ -2754,16 +2754,17 @@
  != null
+ 
 );%0A     
@@ -2774,18 +2774,24 @@
     
-%7D%0A
+    %7D%0A  
         
 %7D).r
@@ -2786,17 +2786,20 @@
         
-%7D
+  %7D 
 ).resolv
@@ -2815,15 +2815,27 @@
 age(
+ 
 path
+ 
 );%0A
+        %7D%0A
     

Improve New Project Wizard to enable/disable 'Finish' button. Fixes to NewResourceHandlers.