Project

General

Profile

1
package eu.dnetlib.repo.manager.client.datasources.register.wizard;
2

    
3
import com.google.gwt.core.client.GWT;
4
import com.google.gwt.user.client.rpc.AsyncCallback;
5
import com.google.gwt.user.client.ui.FlowPanel;
6
import com.google.gwt.user.client.ui.Widget;
7
import eu.dnetlib.repo.manager.client.datasources.utils.RepositoryInterfacesFormWidget;
8
import eu.dnetlib.repo.manager.client.services.RepositoryService;
9
import eu.dnetlib.repo.manager.client.services.RepositoryServiceAsync;
10
import eu.dnetlib.repo.manager.client.widgets.wizard.WizardStepWidget;
11
import eu.dnetlib.repo.manager.shared.DatasourceRegistrationState;
12
import eu.dnetlib.repo.manager.shared.WizardState;
13
import org.gwtbootstrap3.client.ui.Alert;
14
import org.gwtbootstrap3.client.ui.constants.AlertType;
15

    
16
import java.util.Map;
17

    
18
/**
19
 * Created by stefania on 12/17/15.
20
 */
21
public class DatasourceInterfacesStepWidget extends WizardStepWidget {
22

    
23
    private FlowPanel datasourceInterfacesStepPanel = new FlowPanel();
24

    
25
    private Alert errorAlert = new Alert();
26

    
27
    private RepositoryInterfacesFormWidget repositoryInterfacesFormWidget;
28

    
29
    private RepositoryServiceAsync repositoryService = GWT.create(RepositoryService.class);
30

    
31
    public DatasourceInterfacesStepWidget(String id, String title, final String mode) {
32

    
33
        super(id, title, mode);
34

    
35
        errorAlert.setType(AlertType.DANGER);
36
        errorAlert.setDismissable(false);
37
        errorAlert.setVisible(false);
38

    
39
        datasourceInterfacesStepPanel.add(errorAlert);
40

    
41
        datasourceInterfacesStepPanel.addStyleName("animated fadeInRight stepContent");
42

    
43
        repositoryService.getCompatibilityClasses(mode, new AsyncCallback<Map<String, String>>() {
44

    
45
            @Override
46
            public void onFailure(Throwable caught) {
47

    
48
                errorAlert.setText("System error retrieving compatibility classes");
49
                errorAlert.setVisible(true);
50
            }
51

    
52
            @Override
53
            public void onSuccess(Map<String, String> compatibilityClasses) {
54

    
55
                repositoryInterfacesFormWidget = new RepositoryInterfacesFormWidget(mode, false, compatibilityClasses, false);
56
                datasourceInterfacesStepPanel.add(repositoryInterfacesFormWidget.asWidget());
57
            }
58
        });
59
    }
60

    
61
    @Override
62
    public void clear() {
63

    
64
    }
65

    
66
    @Override
67
    public void updateState(WizardState wizardState) {
68

    
69
        DatasourceRegistrationState datasourceRegistrationState = (DatasourceRegistrationState) wizardState;
70

    
71
        if(datasourceRegistrationState.getRepository()!=null)
72
            datasourceRegistrationState.getRepository().setInterfaces(repositoryInterfacesFormWidget.getRepositoryInterfaces());
73
    }
74

    
75
    @Override
76
    public void loadContent(WizardState wizardState) {
77

    
78
        DatasourceRegistrationState datasourceRegistrationState = (DatasourceRegistrationState) wizardState;
79

    
80
        if(datasourceRegistrationState.getRepository()!=null && datasourceRegistrationState.getRepository().getInterfaces()!=null)
81
            repositoryInterfacesFormWidget.loadRepositoryInterfaces(datasourceRegistrationState.getRepository().getInterfaces(), datasourceRegistrationState.getRepository().getId());
82
    }
83

    
84
    @Override
85
    public void completeStep() {
86

    
87
        if(repositoryInterfacesFormWidget!=null && repositoryInterfacesFormWidget.getRepositoryInterfaces()!=null
88
                && !repositoryInterfacesFormWidget.getRepositoryInterfaces().isEmpty() && !repositoryInterfacesFormWidget.hasInvalid()) {
89

    
90
            if(getWizardStepCompletedListener()!=null)
91
                getWizardStepCompletedListener().setStepCompleted();
92
        }
93
    }
94

    
95
    @Override
96
    public Widget asWidget() {
97
        return datasourceInterfacesStepPanel;
98
    }
99
}
(2-2/5)