package com.codenvy.ide.ext.datasource.client.sqllauncher;

import com.codenvy.ide.api.editor.EditorPartPresenter;
import com.codenvy.ide.api.editor.EditorProvider;
import com.codenvy.ide.api.notification.NotificationManager;
import com.codenvy.ide.api.preferences.PreferencesManager;
import com.codenvy.ide.dto.DtoFactory;
import com.codenvy.ide.ext.datasource.client.DatasourceClientService;
import com.codenvy.ide.ext.datasource.client.DatasourceManager;
import com.codenvy.ide.ext.datasource.client.sqleditor.SqlEditorProvider;
import com.google.gwt.core.shared.GWT;
import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;

public class SqlLauncherEditorProvider implements EditorProvider {

    private final NotificationManager   notificationManager;

    private final SqlEditorProvider     sqlEditorProvider;

    private SqlRequestLauncherConstants constants;

    private PreferencesManager          preferencesManager;

    private DatasourceManager           datasourceManager;

    private EventBus                    eventBus;

    private DatasourceClientService     service;

    private DtoFactory                  dtoFactory;


    @Inject
    public SqlLauncherEditorProvider(final NotificationManager notificationManager,
                                     final SqlEditorProvider sqlEditorProvider,
                                     final SqlRequestLauncherConstants constants,
                                     final PreferencesManager preferencesManager,
                                     final DatasourceManager datasourceManager,
                                     final EventBus eventBus,
                                     final DatasourceClientService service,
                                     final DtoFactory dtoFactory) {
        this.notificationManager = notificationManager;
        this.sqlEditorProvider = sqlEditorProvider;
        this.constants = constants;
        this.preferencesManager = preferencesManager;
        this.datasourceManager = datasourceManager;
        this.eventBus = eventBus;
        this.service = service;
        this.dtoFactory = dtoFactory;
    }

    @Override
    public EditorPartPresenter getEditor() {
        return new SqlRequestLauncherAdapter(GWT.<SqlRequestLauncherView> create(SqlRequestLauncherView.class),
                                             constants,
                                             preferencesManager,
                                             sqlEditorProvider,
                                             service,
                                             notificationManager,
                                             datasourceManager,
                                             eventBus,
                                             dtoFactory);

    }
}

@@ -529,47 +529,8 @@
 er;%0A
-import com.google.gwt.core.shared.GWT;%0A
 impo
@@ -1129,16 +1129,84 @@
 ctory;%0A%0A
+    private SqlRequestLauncherFactory   sqlRequestLauncherFactory;%0A%0A
 %0A    @In
@@ -1820,16 +1820,112 @@
 oFactory
+,%0A                                     final SqlRequestLauncherFactory sqlRequestLauncherFactory
 ) %7B%0A    
@@ -2274,16 +2274,84 @@
 actory;%0A
+        this.sqlRequestLauncherFactory = sqlRequestLauncherFactory;%0A
     %7D%0A%0A 
@@ -2457,14 +2457,9 @@
 ter(
-GWT.%3CS
+s
 qlRe
@@ -2475,21 +2475,22 @@
 cher
-View%3E 
+Factory.
 create
-(
 SqlR
@@ -2511,14 +2511,9 @@
 View
-.class
+(
 ),%0A 

Use launcher factory to build view instance in editor provider