Project

General

Profile

« Previous | Next » 

Revision 47387

branching to add new theme footer in old theme...

View differences:

modules/uoa-repository-manager-gui/branches/footerHack/src/main/java/eu/dnetlib/repo/manager/client/widgets/wizard/WizardStepWidget.java
1
package eu.dnetlib.repo.manager.client.widgets.wizard;
2

  
3
import com.google.gwt.user.client.ui.IsWidget;
4
import eu.dnetlib.repo.manager.shared.WizardState;
5

  
6
/**
7
 * Created by stefania on 12/17/15.
8
 */
9
public abstract class WizardStepWidget implements IsWidget {
10

  
11
    private String id;
12
    private String title;
13
    private String mode;
14

  
15
    private WizardStepCompletedListener wizardStepCompletedListener;
16

  
17
    public WizardStepWidget(String id, String title, String mode) {
18
        this.id = id;
19
        this.title = title;
20
        this.mode = mode;
21
    }
22

  
23
    public String getId() {
24
        return id;
25
    }
26

  
27
    public String getTitle() {
28
        return title;
29
    }
30

  
31
    public String getMode() {
32
        return mode;
33
    }
34

  
35
    public abstract void clear();
36

  
37
    public abstract void updateState(WizardState wizardState);
38

  
39
    public abstract void loadContent(WizardState wizardState);
40

  
41
    public abstract void completeStep();
42

  
43
    public interface WizardStepCompletedListener {
44
        void setStepCompleted();
45
    }
46

  
47
    public WizardStepCompletedListener getWizardStepCompletedListener() {
48
        return wizardStepCompletedListener;
49
    }
50

  
51
    public void setWizardStepCompletedListener(WizardStepCompletedListener wizardStepCompletedListener) {
52
        this.wizardStepCompletedListener = wizardStepCompletedListener;
53
    }
54
}
modules/uoa-repository-manager-gui/branches/footerHack/src/main/java/eu/dnetlib/repo/manager/client/widgets/wizard/NavigationWidget.java
1
package eu.dnetlib.repo.manager.client.widgets.wizard;
2

  
3
import com.google.gwt.event.dom.client.ClickEvent;
4
import com.google.gwt.event.dom.client.ClickHandler;
5
import com.google.gwt.user.client.ui.FlowPanel;
6
import com.google.gwt.user.client.ui.IsWidget;
7
import com.google.gwt.user.client.ui.Widget;
8
import org.gwtbootstrap3.client.ui.Button;
9
import org.gwtbootstrap3.client.ui.constants.IconPosition;
10
import org.gwtbootstrap3.client.ui.constants.IconType;
11

  
12
/**
13
 * Created by stefania on 12/17/15.
14
 */
15
public class NavigationWidget implements IsWidget {
16

  
17
    private FlowPanel fundingNavigationPanel = new FlowPanel();
18

  
19
    private Button back = new Button();
20
    private Button next = new Button();
21

  
22
    private int currentActiveStep = 0;
23

  
24
    private NextButtonListener nextButtonListener;
25
    private BackButtonListener backButtonListener;
26

  
27
    public NavigationWidget() {
28

  
29
        fundingNavigationPanel.addStyleName("wizardActions");
30

  
31
        back.setText("Back");
32
        back.addStyleName("btn-grey-light");
33
        back.removeStyleName("btn-default");
34
        back.setIcon(IconType.ANGLE_DOUBLE_LEFT);
35
        back.setIconPosition(IconPosition.LEFT);
36
        back.addClickHandler(new ClickHandler() {
37
            @Override
38
            public void onClick(ClickEvent event) {
39
                fireBackEvent();
40
            }
41
        });
42

  
43
        next.setText("Next Step");
44
        next.addStyleName("btn-grey-light");
45
        next.removeStyleName("btn-default");
46
        next.setIcon(IconType.ANGLE_DOUBLE_RIGHT);
47
        next.setIconPosition(IconPosition.RIGHT);
48
        next.addClickHandler(new ClickHandler() {
49
            @Override
50
            public void onClick(ClickEvent event) {
51
                fireNextEvent();
52
            }
53
        });
54

  
55
        fundingNavigationPanel.add(back);
56
        fundingNavigationPanel.add(next);
57
    }
58

  
59

  
60
    @Override
61
    public Widget asWidget() {
62
        return fundingNavigationPanel;
63
    }
64

  
65
    public void setActiveStep(int stepNumber) {
66

  
67
        currentActiveStep = stepNumber;
68

  
69
        if(currentActiveStep==0)
70
            fundingNavigationPanel.remove(back);
71
        else
72
            fundingNavigationPanel.insert(back, 0);
73
    }
74

  
75
    public void hideNavigationButtons() {
76
        fundingNavigationPanel.clear();
77
    }
78

  
79
    public void setNextButtonText(String text) {
80
        next.setText(text);
81
    }
82

  
83
    public interface NextButtonListener {
84
        void nextClicked(int newActiveStep);
85
    }
86

  
87
    public void setNextButtonListener(NextButtonListener nextButtonListener) {
88
        this.nextButtonListener = nextButtonListener;
89
    }
90

  
91
    public interface BackButtonListener {
92
        void backClicked(int newActiveStep);
93
    }
94

  
95
    public void setBackButtonListener(BackButtonListener backButtonListener) {
96
        this.backButtonListener = backButtonListener;
97
    }
98

  
99
    private void fireNextEvent() {
100
        if(nextButtonListener !=null) {
101
            nextButtonListener.nextClicked(currentActiveStep+1);
102
        }
103
    }
104

  
105
    private void fireBackEvent() {
106
        if(backButtonListener !=null) {
107
            backButtonListener.backClicked(currentActiveStep-1);
108
        }
109
    }
110
}
modules/uoa-repository-manager-gui/branches/footerHack/src/main/java/eu/dnetlib/repo/manager/client/widgets/TextArea.java
1
package eu.dnetlib.repo.manager.client.widgets;
2

  
3
import com.google.gwt.user.client.Event;
4
import com.google.gwt.user.client.Timer;
5

  
6
/**
7
 * Created by stefania on 12/22/15.
8
 */
9
public class TextArea extends org.gwtbootstrap3.client.ui.TextArea implements ValueChangeCancelField {
10

  
11
    private String oldValue = "";
12
    private ValueChangeHandler handler = null;
13

  
14
    public TextArea() {
15
        super();
16
        sinkEvents(Event.ONPASTE | Event.ONKEYUP);
17
    }
18

  
19
    @Override
20
    public void onBrowserEvent(Event event) {
21

  
22
        super.onBrowserEvent(event);
23

  
24
        switch (event.getTypeInt()) {
25
            case Event.ONPASTE:
26
            case Event.ONKEYUP:
27

  
28
                Timer t = new Timer() {
29

  
30
                    @Override
31
                    public void run() {
32
                        if (handler != null) {
33
                            ValueChangeEvent valueChangeEvent = new ValueChangeEvent(TextArea.this, getId(), oldValue, getText());
34

  
35
                            handler.handle(valueChangeEvent);
36

  
37
                            oldValue = getText();
38
                        }
39
                    }
40
                };
41
                t.schedule(0);
42

  
43
                break;
44
            default:
45
        }
46
    }
47

  
48
    @Override
49
    public void cancel() {
50
        this.setText(oldValue);
51
//        focus();
52
    }
53

  
54
    public void setValueChangeHandler(ValueChangeHandler handler) {
55
        this.handler = handler;
56
    }
57
}
modules/uoa-repository-manager-gui/branches/footerHack/src/main/java/eu/dnetlib/repo/manager/client/widgets/ValueChangeEvent.java
1
package eu.dnetlib.repo.manager.client.widgets;
2

  
3
/**
4
 * Created by stefania on 2/27/15.
5
 */
6
public class ValueChangeEvent {
7

  
8
    private ValueChangeCancelField valueChangeCancelField;
9

  
10
    private String id;
11
    private String previousValue;
12
    private String newValue;
13

  
14
    public ValueChangeEvent(ValueChangeCancelField valueChangeCancelField, String id, String previousValue, String newValue) {
15

  
16
        this.valueChangeCancelField = valueChangeCancelField;
17

  
18
        this.id = id;
19
        this.previousValue = previousValue;
20
        this.newValue = newValue;
21
    }
22

  
23
    public String getId() {
24
        return id;
25
    }
26

  
27
    public String getPreviousValue() {
28
        return previousValue;
29
    }
30

  
31
    public String getNewValue() {
32
        return newValue;
33
    }
34

  
35
    public void cancel() {
36
        valueChangeCancelField.cancel();
37
    }
38
}
39

  
modules/uoa-repository-manager-gui/branches/footerHack/src/main/java/eu/dnetlib/repo/manager/client/datasources/utils/RepositoryRegistrationCompleteWidget.java
1
package eu.dnetlib.repo.manager.client.datasources.utils;
2

  
3
import com.google.gwt.user.client.ui.FlowPanel;
4
import com.google.gwt.user.client.ui.HTML;
5
import com.google.gwt.user.client.ui.IsWidget;
6
import com.google.gwt.user.client.ui.Widget;
7
import eu.dnetlib.repo.manager.client.widgets.OpenAIRECompliantLogoDownloadWidget;
8

  
9
/**
10
 * Created by stefania on 1/11/16.
11
 */
12
public class RepositoryRegistrationCompleteWidget implements IsWidget {
13

  
14
    private FlowPanel repositoryRegistrationCompletePanel = new FlowPanel();
15

  
16
    private FlowPanel contentPanel = new FlowPanel();
17

  
18
    public RepositoryRegistrationCompleteWidget(String mode) {
19

  
20
        repositoryRegistrationCompletePanel.addStyleName("animated fadeInRight");
21
        repositoryRegistrationCompletePanel.addStyleName("stepContent");
22

  
23
        repositoryRegistrationCompletePanel.add(contentPanel);
24
//        contentPanel.addStyleName("success");
25

  
26
        HTML html = new HTML();
27
        html.setHTML("<div class=\"success\"><i class=\"fa fa-check-circle\"></i></div>");
28
        contentPanel.add(html);
29

  
30
        OpenAIRECompliantLogoDownloadWidget openAIRECompliantLogoDownloadWidget = new OpenAIRECompliantLogoDownloadWidget();
31
        contentPanel.add(openAIRECompliantLogoDownloadWidget.asWidget());
32
    }
33

  
34
    @Override
35
    public Widget asWidget() {
36
        return repositoryRegistrationCompletePanel;
37
    }
38
}
modules/uoa-repository-manager-gui/branches/footerHack/src/main/java/eu/dnetlib/repo/manager/client/widgets/TextBox.java
1
package eu.dnetlib.repo.manager.client.widgets;
2

  
3
import com.google.gwt.user.client.Event;
4
import com.google.gwt.user.client.Timer;
5

  
6
/**
7
 * Created by stefania on 2/27/15.
8
 */
9
public class TextBox extends org.gwtbootstrap3.client.ui.TextBox implements ValueChangeCancelField {
10

  
11
    private String oldValue = "";
12
    private ValueChangeHandler handler = null;
13

  
14
    public TextBox() {
15
        super();
16
        sinkEvents(Event.ONPASTE | Event.ONKEYUP);
17
    }
18

  
19
    @Override
20
    public void onBrowserEvent(Event event) {
21

  
22
        super.onBrowserEvent(event);
23

  
24
        switch (event.getTypeInt()) {
25
            case Event.ONPASTE:
26
            case Event.ONKEYUP:
27

  
28
                Timer t = new Timer() {
29

  
30
                    @Override
31
                    public void run() {
32
                        if (handler != null) {
33
                            ValueChangeEvent valueChangeEvent = new ValueChangeEvent(TextBox.this, getId(), oldValue, getText());
34

  
35
                            handler.handle(valueChangeEvent);
36

  
37
                            oldValue = getText();
38
                        }
39
                    }
40
                };
41
                t.schedule(0);
42

  
43
                break;
44
            default:
45
        }
46
    }
47

  
48
    @Override
49
    public void cancel() {
50
        this.setText(oldValue);
51
//        focus();
52
    }
53

  
54
    public void setValueChangeHandler(ValueChangeHandler handler) {
55
        this.handler = handler;
56
    }
57
}
modules/uoa-repository-manager-gui/branches/footerHack/src/main/java/eu/dnetlib/repo/manager/client/datasources/utils/InterfaceFields.java
1
package eu.dnetlib.repo.manager.client.datasources.utils;
2

  
3
import com.google.gwt.core.client.GWT;
4
import com.google.gwt.event.dom.client.ChangeEvent;
5
import com.google.gwt.event.dom.client.ChangeHandler;
6
import com.google.gwt.event.dom.client.ClickEvent;
7
import com.google.gwt.event.dom.client.ClickHandler;
8
import com.google.gwt.user.client.rpc.AsyncCallback;
9
import com.google.gwt.user.client.ui.*;
10
import eu.dnetlib.domain.data.RepositoryInterface;
11
import eu.dnetlib.repo.manager.client.services.RepositoryService;
12
import eu.dnetlib.repo.manager.client.services.RepositoryServiceAsync;
13
import eu.dnetlib.repo.manager.client.services.ValidationService;
14
import eu.dnetlib.repo.manager.client.services.ValidationServiceAsync;
15
import eu.dnetlib.gwt.client.MyFormGroup;
16
import eu.dnetlib.repo.manager.client.widgets.TextBox;
17
import eu.dnetlib.repo.manager.client.widgets.ValueChangeEvent;
18
import eu.dnetlib.repo.manager.client.widgets.ValueChangeHandler;
19
import eu.dnetlib.repo.manager.shared.Constants;
20
import eu.dnetlib.repo.manager.shared.InterfaceInformation;
21
import org.gwtbootstrap3.client.ui.*;
22
import org.gwtbootstrap3.client.ui.Anchor;
23
import org.gwtbootstrap3.client.ui.ListBox;
24
import org.gwtbootstrap3.client.ui.RadioButton;
25
import org.gwtbootstrap3.client.ui.constants.*;
26

  
27
import java.util.HashMap;
28
import java.util.Map;
29

  
30
/**
31
 * Created by stefania on 12/23/15.
32
 */
33
public class InterfaceFields implements IsWidget {
34

  
35
    private boolean isValid = true;
36

  
37
    private FlowPanel interfacePanel = new FlowPanel();
38
    private FlowPanel interfaceBoxPanel = new FlowPanel();
39
    private FlowPanel interfaceBoxContentPanel = new FlowPanel();
40
    private FlowPanel interfaceBoxTitlePanel = new FlowPanel();
41
    private HTML title = new HTML();
42

  
43
    private FlowPanel actionsPanel = new FlowPanel();
44

  
45
    private Anchor deleteIcon = new Anchor();
46
    private Anchor saveIcon = new Anchor();
47

  
48
    private Form interfaceForm = new Form();
49

  
50
    private Alert interfaceErrorAlert = new Alert();
51
    private Alert interfaceSuccessAlert = new Alert();
52

  
53
    private TextBox baseURL = new TextBox();
54
    private MyFormGroup baseURLFormGroup = new MyFormGroup(true, "Base OAI-PMH URL (*)", baseURL);
55

  
56
    private RadioButton addACustomValidationSetRadio = new RadioButton("validationSet", "or a custom one", false);
57
    private TextBox validationSetTextBox = new TextBox();
58
    private RadioButton chooseExistingValidationSetRadio = new RadioButton("validationSet", "Choose existing", false);
59
    private ListBox existingValidationSetsListBox = new ListBox();
60
    private Map<String, Integer> existingValidationSetsValuesMap = new HashMap<String, Integer>();
61

  
62
    private ListBox desiredCompatibilityLevelListBox = new ListBox();
63
    private MyFormGroup desiredCompatibilityLevelFormGroup = new MyFormGroup(false, "Desired Compatibility Level (*)", desiredCompatibilityLevelListBox);
64
    private Map<String, Integer> desiredCompatibilityValuesMap = new HashMap<String, Integer>();
65

  
66
    private HTML currentCompatibilityLevel = new HTML();
67

  
68
    private RepositoryInterface existingRepositoryInterface;
69
    private String repositoryId;
70

  
71
    private DeleteInterfaceListener deleteInterfaceListener;
72

  
73
    private ValidationServiceAsync validationService = GWT.create(ValidationService.class);
74
    private RepositoryServiceAsync repositoryService = GWT.create(RepositoryService.class);
75

  
76
    private String mode;
77
    private boolean isUpdate;
78

  
79
    public InterfaceFields(boolean hasSave, Map<String, String> compatibilityClasses, String mode, final boolean isUpdate) {
80

  
81
        this.mode = mode;
82
        this.isUpdate = isUpdate;
83

  
84
        interfacePanel.addStyleName("col-md-6");
85
        interfacePanel.add(interfaceBoxPanel);
86

  
87
        interfaceBoxPanel.addStyleName("ibox interface-box");
88
        interfaceBoxPanel.add(interfaceBoxTitlePanel);
89
        interfaceBoxPanel.add(interfaceBoxContentPanel);
90

  
91
        interfaceBoxContentPanel.addStyleName("ibox-content");
92

  
93
        interfaceBoxTitlePanel.addStyleName("ibox-title");
94
        interfaceBoxTitlePanel.add(title);
95
        interfaceBoxTitlePanel.add(actionsPanel);
96

  
97
        actionsPanel.addStyleName("interfaceActionsPanel");
98

  
99
        deleteIcon.setIcon(IconType.REMOVE);
100
        deleteIcon.setIconSize(IconSize.LARGE);
101
        deleteIcon.addClickHandler(new ClickHandler() {
102
            @Override
103
            public void onClick(ClickEvent event) {
104
                if(deleteInterfaceListener!=null)
105
                    deleteInterfaceListener.deleteInterface(isUpdate);
106
            }
107
        });
108

  
109
        saveIcon.setIcon(IconType.SAVE);
110
        saveIcon.setIconSize(IconSize.LARGE);
111
        saveIcon.addClickHandler(new ClickHandler() {
112
            @Override
113
            public void onClick(ClickEvent event) {
114
                saveInterface();
115
            }
116
        });
117

  
118
        if(hasSave)
119
            actionsPanel.add(saveIcon);
120
        actionsPanel.add(deleteIcon);
121

  
122
        interfaceSuccessAlert.setType(AlertType.SUCCESS);
123
        interfaceSuccessAlert.setDismissable(false);
124
        interfaceSuccessAlert.setVisible(false);
125
        interfaceBoxContentPanel.add(interfaceSuccessAlert);
126

  
127
        interfaceErrorAlert.setType(AlertType.DANGER);
128
        interfaceErrorAlert.setDismissable(false);
129
        interfaceErrorAlert.setVisible(false);
130
        interfaceBoxContentPanel.add(interfaceErrorAlert);
131

  
132
        interfaceBoxContentPanel.add(interfaceForm);
133

  
134
        desiredCompatibilityLevelListBox.addItem("-- none selected --", "noneSelected");
135
        int counter = 1;
136
        for(String compatibility : compatibilityClasses.keySet()) {
137
            desiredCompatibilityLevelListBox.addItem(compatibilityClasses.get(compatibility), compatibility);
138
            desiredCompatibilityValuesMap.put(compatibility, counter);
139
            counter++;
140
        }
141

  
142
        baseURL.addChangeHandler(new ChangeHandler() {
143
            @Override
144
            public void onChange(ChangeEvent event) {
145

  
146
                baseURLFormGroup.setFormGroupValidationState(ValidationState.NONE);
147
                getInterfaceInformation(null);
148
            }
149
        });
150

  
151
        interfaceForm.add(baseURLFormGroup);
152

  
153
        FlowPanel customValidationRadioPanel = new FlowPanel();
154
        addACustomValidationSetRadio.setType(ButtonType.LINK);
155
        addACustomValidationSetRadio.addStyleName("validationSetRadio");
156
        addACustomValidationSetRadio.addChangeHandler(new ChangeHandler() {
157
            @Override
158
            public void onChange(ChangeEvent event) {
159
                if(addACustomValidationSetRadio.getValue()) {
160
                    validationSetTextBox.setEnabled(true);
161
                    existingValidationSetsListBox.setEnabled(false);
162
                }
163
            }
164
        });
165
        addACustomValidationSetRadio.setEnabled(false);
166
        customValidationRadioPanel.add(addACustomValidationSetRadio);
167

  
168
        validationSetTextBox.setEnabled(false);
169

  
170
        FlowPanel chooseExistingValidationRadioPanel = new FlowPanel();
171
        chooseExistingValidationSetRadio.setValue(true);
172
        chooseExistingValidationSetRadio.setType(ButtonType.LINK);
173
        chooseExistingValidationSetRadio.addStyleName("validationSetRadio");
174
        chooseExistingValidationSetRadio.addChangeHandler(new ChangeHandler() {
175
            @Override
176
            public void onChange(ChangeEvent event) {
177
                existingValidationSetsListBox.setEnabled(true);
178
                validationSetTextBox.setEnabled(false);
179
            }
180
        });
181
        chooseExistingValidationSetRadio.setEnabled(false);
182
        chooseExistingValidationRadioPanel.add(chooseExistingValidationSetRadio);
183

  
184
        existingValidationSetsListBox.addItem("-- none selected --", "noneSelected");
185
        existingValidationSetsListBox.setEnabled(false);
186

  
187
        interfaceForm.add(new MyFormGroup(false, "Validation Set", chooseExistingValidationRadioPanel, existingValidationSetsListBox,
188
                customValidationRadioPanel, validationSetTextBox));
189

  
190
        interfaceForm.add(desiredCompatibilityLevelFormGroup);
191

  
192
        currentCompatibilityLevel.setText("not available");
193
        interfaceForm.add(new MyFormGroup(false, "Current Compatibility Level", currentCompatibilityLevel));
194

  
195
        addValueChangeHandlersToFormFields();
196
    }
197

  
198
    @Override
199
    public Widget asWidget() {
200
        return interfacePanel;
201
    }
202

  
203
    public void setRepositoryId(String repositoryId) {
204
        this.repositoryId = repositoryId;
205
    }
206

  
207
    public interface DeleteInterfaceListener {
208
        void deleteInterface(boolean checkForLastOne);
209
    }
210

  
211
    public void setDeleteInterfaceListener(DeleteInterfaceListener deleteInterfaceListener) {
212
        this.deleteInterfaceListener = deleteInterfaceListener;
213
    }
214

  
215
    public void loadRepositoryInterface(RepositoryInterface repositoryInterface, String repositoryId) {
216

  
217
        this.existingRepositoryInterface = repositoryInterface;
218
        this.repositoryId = repositoryId;
219

  
220
        if(repositoryInterface!=null) {
221

  
222
            if(!repositoryInterface.isRemovable()) {
223

  
224
                if(mode.equals(Constants.REPOSITORY_MODE_OPENDOAR))
225
                    title.setHTML("<h5>OpenDOAR Interface (non-removable)</h5>");
226
                else if(mode.equals(Constants.REPOSITORY_MODE_RE3DATA))
227
                    title.setHTML("<h5>Re3data Interface (non-removable)</h5>");
228

  
229
                actionsPanel.remove(deleteIcon);
230
            }
231

  
232
            baseURL.setValue(repositoryInterface.getBaseUrl());
233
            getInterfaceInformation(repositoryInterface.getAccessSet());
234

  
235
            if(repositoryInterface.getDesiredCompatibilityLevel()!=null)
236
                desiredCompatibilityLevelListBox.setSelectedIndex(desiredCompatibilityValuesMap.get(repositoryInterface.getDesiredCompatibilityLevel()));
237

  
238
            if(repositoryInterface.getComplianceName()!=null && !repositoryInterface.getComplianceName().isEmpty())
239
                currentCompatibilityLevel.setText(repositoryInterface.getComplianceName());
240
        }
241

  
242
        if(existingRepositoryInterface!=null && existingRepositoryInterface.getId()!=null) {
243
            baseURL.setEnabled(false);
244
            addACustomValidationSetRadio.setEnabled(false);
245
            chooseExistingValidationSetRadio.setEnabled(false);
246
            validationSetTextBox.setEnabled(false);
247
            existingValidationSetsListBox.setEnabled(false);
248
        }
249
    }
250

  
251
    private void saveInterface() {
252

  
253
        interfaceErrorAlert.setVisible(false);
254
        interfaceSuccessAlert.setVisible(false);
255

  
256
        RepositoryInterface repositoryInterface = getRepositoryInterface(false);
257
        if(repositoryInterface!=null && isValid) {
258

  
259
            final HTML loadingWheel = new HTML("<div class=\"loader-small\" style=\"text-align: center; padding-top: 35%; " +
260
                    "color: rgb(47, 64, 80); font-weight: bold;\">Saving interface information</div><div class=\"whiteFilm\"></div>");
261
            interfaceBoxContentPanel.addStyleName("loading");
262
            interfaceBoxContentPanel.add(loadingWheel);
263

  
264
            if (repositoryInterface.getId() == null) {
265

  
266
                repositoryService.insertInterface(repositoryInterface, repositoryId, mode, new AsyncCallback<RepositoryInterface>() {
267

  
268
                    @Override
269
                    public void onFailure(Throwable caught) {
270

  
271
                        interfaceBoxContentPanel.removeStyleName("loading");
272
                        interfaceBoxContentPanel.remove(loadingWheel);
273

  
274
                        interfaceErrorAlert.setText("System error saving interface information ");
275
                        interfaceErrorAlert.setVisible(true);
276
                    }
277

  
278
                    @Override
279
                    public void onSuccess(RepositoryInterface repositoryInterface) {
280

  
281
                        interfaceBoxContentPanel.removeStyleName("loading");
282
                        interfaceBoxContentPanel.remove(loadingWheel);
283

  
284
                        interfaceSuccessAlert.setText("Interface saved successfully");
285
                        interfaceSuccessAlert.setVisible(true);
286

  
287
                        existingRepositoryInterface.setId(repositoryInterface.getId());
288
                        desiredCompatibilityLevelListBox.setSelectedIndex(0);
289
                        currentCompatibilityLevel.setText(repositoryInterface.getComplianceName());
290

  
291
                        baseURL.setEnabled(false);
292
                        addACustomValidationSetRadio.setEnabled(false);
293
                        chooseExistingValidationSetRadio.setEnabled(false);
294
                        validationSetTextBox.setEnabled(false);
295
                        existingValidationSetsListBox.setEnabled(false);
296
                    }
297
                });
298

  
299
            } else {
300

  
301
                repositoryService.updateInterface(repositoryInterface, repositoryId, mode, new AsyncCallback<RepositoryInterface>() {
302

  
303
                    @Override
304
                    public void onFailure(Throwable caught) {
305

  
306
                        interfaceBoxContentPanel.removeStyleName("loading");
307
                        interfaceBoxContentPanel.remove(loadingWheel);
308

  
309
                        interfaceErrorAlert.setText("System error updating interface information ");
310
                        interfaceErrorAlert.setVisible(true);
311
                    }
312

  
313
                    @Override
314
                    public void onSuccess(RepositoryInterface repositoryInterface) {
315

  
316
                        interfaceBoxContentPanel.removeStyleName("loading");
317
                        interfaceBoxContentPanel.remove(loadingWheel);
318

  
319
                        interfaceSuccessAlert.setText("Interface updated successfully");
320
                        interfaceSuccessAlert.setVisible(true);
321

  
322
                        existingRepositoryInterface.setId(repositoryInterface.getId());
323

  
324
                        desiredCompatibilityLevelListBox.setSelectedIndex(0);
325
                        currentCompatibilityLevel.setText(repositoryInterface.getComplianceName());
326
                    }
327
                });
328
            }
329
        }
330
    }
331

  
332
    private void getInterfaceInformation(final String validationSet) {
333

  
334
        interfaceErrorAlert.setVisible(false);
335

  
336
        final HTML loadingWheel = new HTML("<div class=\"loader-small\" style=\"text-align: center; padding-top: 35%; " +
337
                "color: rgb(47, 64, 80); font-weight: bold;\">Fetching interface information</div><div class=\"whiteFilm\"></div>");
338
        interfaceBoxContentPanel.addStyleName("loading");
339
        interfaceBoxContentPanel.add(loadingWheel);
340

  
341
        validationService.getInterfaceInformation(baseURL.getValue(), new AsyncCallback<InterfaceInformation>() {
342

  
343
            @Override
344
            public void onFailure(Throwable caught) {
345

  
346
                interfaceBoxContentPanel.removeStyleName("loading");
347
                interfaceBoxContentPanel.remove(loadingWheel);
348

  
349
                interfaceErrorAlert.setText("System error fetching interface information ");
350
                interfaceErrorAlert.setVisible(true);
351
            }
352

  
353
            @Override
354
            public void onSuccess(InterfaceInformation interfaceInformation) {
355

  
356
                interfaceBoxContentPanel.removeStyleName("loading");
357
                interfaceBoxContentPanel.remove(loadingWheel);
358

  
359
                if(interfaceInformation.isIdentified()) {
360

  
361
                    baseURLFormGroup.displayInlineSuccess("Identified");
362

  
363
                    if(existingRepositoryInterface==null || existingRepositoryInterface.getId()==null) {
364
                        chooseExistingValidationSetRadio.setEnabled(true);
365
                        addACustomValidationSetRadio.setEnabled(true);
366

  
367
                        if (chooseExistingValidationSetRadio.getValue())
368
                            existingValidationSetsListBox.setEnabled(true);
369
                        else
370
                            validationSetTextBox.setEnabled(true);
371
                    }
372

  
373
                    existingValidationSetsListBox.clear();
374
                    existingValidationSetsListBox.addItem("-- none selected --", "noneSelected");
375
                    int counter = 1;
376
                    for(String validationSet : interfaceInformation.getSets()) {
377
                        existingValidationSetsListBox.addItem(validationSet, validationSet);
378
                        existingValidationSetsValuesMap.put(validationSet, counter);
379
                        counter++;
380
                    }
381

  
382
                } else {
383
                    baseURLFormGroup.displayInlineError("Not Identified");
384
                }
385

  
386
                if(validationSet!=null) {
387

  
388
                    if (interfaceInformation.getSets().contains(validationSet)) {
389
                        existingValidationSetsListBox.setSelectedIndex(existingValidationSetsValuesMap.get(validationSet));
390
                    } else {
391

  
392
                        chooseExistingValidationSetRadio.setValue(false);
393
                        addACustomValidationSetRadio.setValue(true);
394
                        if(existingRepositoryInterface==null || existingRepositoryInterface.getId()==null) {
395
                            existingValidationSetsListBox.setEnabled(false);
396
                            validationSetTextBox.setEnabled(true);
397
                        }
398
                        validationSetTextBox.setValue(validationSet);
399
                    }
400
                }
401
            }
402
        });
403
    }
404

  
405
    public RepositoryInterface getRepositoryInterface(boolean forDeletion) {
406

  
407
        if(!forDeletion) {
408

  
409
            isValid = true;
410

  
411
            if (isEmpty()) {
412
                return null;
413
            }
414

  
415
            if (isComplete()) {
416

  
417
                if (existingRepositoryInterface == null) {
418
                    existingRepositoryInterface = new RepositoryInterface();
419
                }
420

  
421
                existingRepositoryInterface.setCompliance("UNKNOWN");
422

  
423
                existingRepositoryInterface.setBaseUrl(baseURL.getValue().trim());
424

  
425
                if (chooseExistingValidationSetRadio.getValue() && !existingValidationSetsListBox.getSelectedValue().equals("noneSelected"))
426
                    existingRepositoryInterface.setAccessSet(existingValidationSetsListBox.getSelectedValue());
427
                else if (addACustomValidationSetRadio.getValue() && validationSetTextBox.getValue() != null && !validationSetTextBox.getValue().trim().isEmpty())
428
                    existingRepositoryInterface.setAccessSet(validationSetTextBox.getValue().trim());
429
                else
430
                    existingRepositoryInterface.setAccessSet("");
431

  
432
                existingRepositoryInterface.setDesiredCompatibilityLevel(desiredCompatibilityLevelListBox.getSelectedValue());
433

  
434
                return existingRepositoryInterface;
435
            }
436

  
437
            isValid = false;
438
            return new RepositoryInterface();
439

  
440
        } else {
441

  
442
            if (isEmpty()) {
443
                return null;
444
            }
445

  
446
            return existingRepositoryInterface;
447
        }
448
    }
449

  
450
    private boolean isEmpty() {
451

  
452
        if(chooseExistingValidationSetRadio.getValue()) {
453

  
454
            if ((baseURL.getValue() == null || baseURL.getValue().trim().equals(""))
455
                    && existingValidationSetsListBox.getSelectedValue().equals("noneSelected")
456
                    && desiredCompatibilityLevelListBox.getSelectedValue().equals("noneSelected")) {
457
                return true;
458
            }
459

  
460
        } else {
461

  
462
            if ((baseURL.getValue() == null || baseURL.getValue().trim().equals(""))
463
                    && (validationSetTextBox.getValue() == null || validationSetTextBox.getValue().trim().equals(""))
464
                    && desiredCompatibilityLevelListBox.getSelectedValue().equals("noneSelected")) {
465
                return true;
466
            }
467
        }
468

  
469
        return false;
470
    }
471

  
472
    private boolean isComplete() {
473

  
474
        boolean isComplete = true;
475

  
476
        interfaceErrorAlert.setVisible(false);
477

  
478
        if(baseURL.getValue()==null || baseURL.getValue().trim().isEmpty()) {
479
            isComplete = false;
480
            baseURLFormGroup.setFormGroupValidationState(ValidationState.ERROR);
481
        }
482

  
483
        if(desiredCompatibilityLevelListBox.getSelectedValue().equals("noneSelected")) {
484
            isComplete = false;
485
            desiredCompatibilityLevelFormGroup.setFormGroupValidationState(ValidationState.ERROR);
486
        }
487

  
488
        if(!isComplete) {
489
            interfaceErrorAlert.setText("All fields marked with * are mandatory.");
490
            interfaceErrorAlert.setVisible(true);
491
        }
492

  
493
        return isComplete;
494
    }
495

  
496
    private void addValueChangeHandlersToFormFields() {
497

  
498
        baseURL.setValueChangeHandler(new ValueChangeHandler() {
499
            @Override
500
            public void handle(ValueChangeEvent valueChangeEvent) {
501
                baseURLFormGroup.setFormGroupValidationState(ValidationState.NONE);
502
            }
503
        });
504

  
505
        desiredCompatibilityLevelListBox.addChangeHandler(new ChangeHandler() {
506
            @Override
507
            public void onChange(ChangeEvent event) {
508
                desiredCompatibilityLevelFormGroup.setFormGroupValidationState(ValidationState.NONE);
509
            }
510
        });
511
    }
512

  
513
    public boolean isValid() {
514
        return isValid;
515
    }
516
}
modules/uoa-repository-manager-gui/branches/footerHack/src/main/java/eu/dnetlib/repo/manager/client/datasources/utils/RepositoryInformationFormWidget.java
1
package eu.dnetlib.repo.manager.client.datasources.utils;
2

  
3
import com.google.gwt.core.client.GWT;
4
import com.google.gwt.editor.client.Editor;
5
import com.google.gwt.editor.client.EditorError;
6
import com.google.gwt.event.dom.client.ChangeEvent;
7
import com.google.gwt.event.dom.client.ChangeHandler;
8
import com.google.gwt.event.dom.client.ClickEvent;
9
import com.google.gwt.event.dom.client.ClickHandler;
10
import com.google.gwt.regexp.shared.RegExp;
11
import com.google.gwt.user.client.rpc.AsyncCallback;
12
import com.google.gwt.user.client.ui.*;
13
import com.google.gwt.user.client.ui.Label;
14
import eu.dnetlib.domain.data.Repository;
15
import eu.dnetlib.gwt.client.MyFormGroup;
16
import eu.dnetlib.repo.manager.client.services.RepositoryService;
17
import eu.dnetlib.repo.manager.client.services.RepositoryServiceAsync;
18
import eu.dnetlib.repo.manager.client.widgets.*;
19
import eu.dnetlib.repo.manager.client.widgets.TextArea;
20
import eu.dnetlib.repo.manager.client.widgets.TextBox;
21
import eu.dnetlib.repo.manager.shared.Constants;
22
import eu.dnetlib.repo.manager.shared.DatasourceVocabularies;
23
import org.gwtbootstrap3.client.ui.*;
24
import org.gwtbootstrap3.client.ui.Button;
25
import org.gwtbootstrap3.client.ui.ListBox;
26
import org.gwtbootstrap3.client.ui.constants.AlertType;
27
import org.gwtbootstrap3.client.ui.constants.ButtonType;
28
import org.gwtbootstrap3.client.ui.constants.ValidationState;
29
import org.gwtbootstrap3.client.ui.form.error.BasicEditorError;
30
import org.gwtbootstrap3.client.ui.form.validator.Validator;
31

  
32
import java.util.ArrayList;
33
import java.util.HashMap;
34
import java.util.List;
35
import java.util.Map;
36

  
37
/**
38
 * Created by stefania on 12/21/15.
39
 */
40
public class RepositoryInformationFormWidget implements IsWidget {
41

  
42
    private FlowPanel repositoryInformationPanel = new FlowPanel();
43

  
44
    private Alert errorLabel = new Alert();
45
    private Alert successLabel = new Alert();
46

  
47
    private Form repositoryInformationForm = new Form();
48

  
49
    private HTML basicInfoWarningLabel = new HTML();
50

  
51
    private ListBox typologyListBox = new ListBox();
52
    private MyFormGroup typologyListFormGroup = new MyFormGroup(false, "Software Platform (*)", typologyListBox);
53
    private TextBox typologyTextBox = new TextBox();
54
    private MyFormGroup typologyTextFormGroup = new MyFormGroup(false, null, typologyTextBox);
55
    private TextBox officialName = new TextBox();
56
    private MyFormGroup officialNameFormGroup = new MyFormGroup(false, "Official Name (*)", officialName);
57
    private TextBox issn = new TextBox();
58
    private MyFormGroup issnFormGroup = new MyFormGroup(true, "ISSN (*)", issn);
59
    private TextBox eissn = new TextBox();
60
    private MyFormGroup eissnFormGroup = new MyFormGroup(true, "EISSN", eissn);
61
    private TextBox lissn = new TextBox();
62
    private MyFormGroup lissnFormGroup = new MyFormGroup(true, "LISSN", lissn);
63
    private TextArea description = new TextArea();
64
    private MyFormGroup descriptionFormGroup = new MyFormGroup(false, "Description (*)", description);
65
    private ListBox countryListBox = new ListBox();
66
    private MyFormGroup countryFormGroup = new MyFormGroup(false, "Country (*)", countryListBox);
67
    private TextBox longitude = new TextBox();
68
    private MyFormGroup longitudeFormGroup = new MyFormGroup(true, "Longitude (*)", longitude);
69
    private TextBox latitude = new TextBox();
70
    private MyFormGroup latitudeFormGroup = new MyFormGroup(true, "Latitude (*)", latitude);
71
    private TextBox entryURL = new TextBox();
72
    private MyFormGroup entryURLFormGroup = new MyFormGroup(false, "Entry URL (*)", entryURL);
73
    private TextBox institution = new TextBox();
74
    private MyFormGroup institutionFormGroup = new MyFormGroup(false, "Institution (*)", institution);
75

  
76
    private TextBox englishName = new TextBox();
77
    private MyFormGroup englishNameFormGroup = new MyFormGroup(false, "English Name (*)", englishName);
78
    private TextBox logoURL = new TextBox();
79
    private ListBox timezoneListBox = new ListBox();
80
    private MyFormGroup timezoneFormGroup = new MyFormGroup(false, "Timezone (*)", timezoneListBox);
81
    private ListBox datasourceClassListBox = new ListBox();
82
    private MyFormGroup datasourceClassFormGroup = new MyFormGroup(false, "Datasource Type (*)", datasourceClassListBox);
83

  
84
    private TextBox admin = new TextBox();
85
    private MyFormGroup adminFormGroup = new MyFormGroup(true, "Admin Email (*)", admin);
86

  
87
    private Map<String, Integer> typologyValuesMap = new HashMap<String, Integer>();
88
    private Map<String, Integer> countryValuesMap = new HashMap<String, Integer>();
89
    private Map<String, Integer> timezoneValuesMap = new HashMap<String, Integer>();
90
    private Map<String, Integer> datasourceClassValuesMap = new HashMap<String, Integer>();
91

  
92
    private String mode;
93

  
94
    private Repository repository;
95

  
96
    private RepositoryServiceAsync repositoryService = GWT.create(RepositoryService.class);
97

  
98
    public RepositoryInformationFormWidget(String mode, DatasourceVocabularies datasourceVocabularies, boolean isUpdate) {
99

  
100
        this.mode = mode;
101

  
102
        basicInfoWarningLabel.addStyleName("alert alert-warning");
103
        basicInfoWarningLabel.setVisible(false);
104

  
105
        errorLabel.setType(AlertType.DANGER);
106
        errorLabel.setDismissable(false);
107
        errorLabel.setVisible(false);
108

  
109
        successLabel.setType(AlertType.SUCCESS);
110
        successLabel.setDismissable(false);
111
        successLabel.setVisible(false);
112

  
113
        repositoryInformationPanel.add(successLabel);
114
        repositoryInformationPanel.add(errorLabel);
115
        repositoryInformationPanel.add(repositoryInformationForm);
116

  
117
        typologyListBox.addItem("-- none selected --", "noneSelected");
118
        for(int i=1; i<datasourceVocabularies.getTypologies().size(); i++) {
119
            if(datasourceVocabularies.getTypologies().get(i-1).equals("[Other]")) {
120
                typologyListBox.addItem("[Other] (enter name below)", "[Other]");
121
                typologyValuesMap.put("[Other]", i);
122
            } else {
123
                typologyListBox.addItem(datasourceVocabularies.getTypologies().get(i - 1), datasourceVocabularies.getTypologies().get(i - 1));
124
                typologyValuesMap.put(datasourceVocabularies.getTypologies().get(i - 1), i);
125
            }
126
        }
127

  
128
        countryListBox.addItem("-- none selected --", "noneSelected");
129
        int counter1 = 1;
130
        for(String country : datasourceVocabularies.getCountries().keySet()) {
131
            countryListBox.addItem(datasourceVocabularies.getCountries().get(country), country);
132
            countryValuesMap.put(country, counter1);
133
            counter1++;
134
        }
135

  
136
        timezoneListBox.addItem("-- none selected --", "noneSelected");
137
        for(int i=1; i<datasourceVocabularies.getTimezones().size(); i++) {
138
            timezoneListBox.addItem(datasourceVocabularies.getTimezones().get(i-1).name, datasourceVocabularies.getTimezones().get(i-1).offset+"");
139
            timezoneValuesMap.put(datasourceVocabularies.getTimezones().get(i-1).offset+"", i);
140
        }
141

  
142
        datasourceClassListBox.addItem("-- none selected --", "noneSelected");
143
        int counter2 = 1;
144
        for(String datasourceClass : datasourceVocabularies.getDatasourceClasses().keySet()) {
145
            datasourceClassListBox.addItem(datasourceVocabularies.getDatasourceClasses().get(datasourceClass), datasourceClass);
146
            datasourceClassValuesMap.put(datasourceClass, counter2);
147
            counter2++;
148
        }
149

  
150
        typologyTextBox.setVisible(false);
151

  
152

  
153
        Label logoURLComment = new Label("Please make sure that the maximum size of the uploaded image is width=360px, height=240px");
154
        logoURLComment.addStyleName("comment");
155
        logoURLComment.addStyleName("fontItalic");
156

  
157
        HTML basicInfoLabel = new HTML("<h2>Basic information</h2>");
158
        repositoryInformationForm.add(basicInfoLabel);
159
        repositoryInformationForm.add(basicInfoWarningLabel);
160
        repositoryInformationForm.add(typologyListFormGroup);
161
        repositoryInformationForm.add(typologyTextFormGroup);
162
        repositoryInformationForm.add(officialNameFormGroup);
163
        if(mode.equals(Constants.REPOSITORY_MODE_JOURNAL)) {
164
            repositoryInformationForm.add(issnFormGroup);
165
            repositoryInformationForm.add(eissnFormGroup);
166
            repositoryInformationForm.add(lissnFormGroup);
167
        }
168
        repositoryInformationForm.add(descriptionFormGroup);
169
        repositoryInformationForm.add(countryFormGroup);
170
        repositoryInformationForm.add(longitudeFormGroup);
171
        repositoryInformationForm.add(latitudeFormGroup);
172
        repositoryInformationForm.add(entryURLFormGroup);
173
        repositoryInformationForm.add(institutionFormGroup);
174

  
175
        HTML extraInfoLabel = new HTML("<h2>Extra information</h2>");
176
        repositoryInformationForm.add(extraInfoLabel);
177
        repositoryInformationForm.add(englishNameFormGroup);
178
        repositoryInformationForm.add(new MyFormGroup(false, "Logo URL", logoURL, logoURLComment));
179
        repositoryInformationForm.add(timezoneFormGroup);
180
        repositoryInformationForm.add(datasourceClassFormGroup);
181

  
182
        if(mode.equals(Constants.REPOSITORY_MODE_JOURNAL))
183
            datasourceClassFormGroup.setLabelText("Journal Type (*)");
184
        else if(mode.equals(Constants.REPOSITORY_MODE_AGGREGATOR))
185
            datasourceClassFormGroup.setLabelText("Aggregator Type (*)");
186

  
187
        HTML adminInfoLabel = new HTML("<h2>Administrator & contact information</h2>");
188
        repositoryInformationForm.add(adminInfoLabel);
189
        repositoryInformationForm.add(adminFormGroup);
190

  
191
        if(mode.equals(Constants.REPOSITORY_MODE_OPENDOAR) || mode.equals(Constants.REPOSITORY_MODE_RE3DATA)) {
192
            typologyListBox.setEnabled(false);
193
            typologyTextBox.setEnabled(false);
194
            officialName.setEnabled(false);
195
            description.setEnabled(false);
196
            countryListBox.setEnabled(false);
197
            longitude.setEnabled(false);
198
            latitude.setEnabled(false);
199
            entryURL.setEnabled(false);
200
            institution.setEnabled(false);
201
        }
202

  
203
        if(isUpdate) {
204

  
205
            Button updateInfoButton = new Button("Update Information");
206
            updateInfoButton.setType(ButtonType.PRIMARY);
207
            updateInfoButton.addStyleName("updateRepoInfoButton");
208
            updateInfoButton.addClickHandler(new ClickHandler() {
209
                @Override
210
                public void onClick(ClickEvent event) {
211

  
212
                    errorLabel.setVisible(false);
213
                    successLabel.setVisible(false);
214

  
215
                    Repository repositoryToUpdate = getRepository();
216
                    if(repositoryToUpdate!=null) {
217

  
218
                        final HTML loadingWheel = new HTML("<div class=\"loader-big\" style=\"text-align: center; padding-top: 35%; " +
219
                                "color: rgb(47, 64, 80); font-weight: bold;\">Updating repository information</div>" +
220
                                "<div class=\"whiteFilm\"></div>");
221
                        repositoryInformationPanel.addStyleName("loading-big");
222
                        repositoryInformationPanel.add(loadingWheel);
223

  
224
                        repositoryService.updateRepositoryInformation(repositoryToUpdate, new AsyncCallback<Void>() {
225

  
226
                            @Override
227
                            public void onFailure(Throwable caught) {
228

  
229
                                repositoryInformationPanel.removeStyleName("loading-big");
230
                                repositoryInformationPanel.remove(loadingWheel);
231

  
232
                                errorLabel.setText("System error updating repository information");
233
                                errorLabel.setVisible(true);
234
                            }
235

  
236
                            @Override
237
                            public void onSuccess(Void result) {
238

  
239
                                repositoryInformationPanel.removeStyleName("loading-big");
240
                                repositoryInformationPanel.remove(loadingWheel);
241

  
242
                                successLabel.setText("Repository information updated successfully");
243
                                successLabel.setVisible(true);
244
                            }
245
                        });
246
                    }
247
                }
248
            });
249
            repositoryInformationForm.add(new MyFormGroup(false, null, updateInfoButton));
250
        }
251

  
252
        addValueChangeHandlersToFormFields();
253
        addFieldValidators();
254
    }
255

  
256
    @Override
257
    public Widget asWidget() {
258
        return repositoryInformationPanel;
259
    }
260

  
261
    public void loadRepository(Repository repository) {
262

  
263
        errorLabel.setVisible(false);
264
        successLabel.setVisible(false);
265

  
266
        this.repository = repository;
267

  
268
        if(mode.equals(Constants.REPOSITORY_MODE_OPENDOAR)) {
269
            basicInfoWarningLabel.setHTML("The following fields are completed by OpenDOAR.<br>" +
270
                    "If you want to edit them, you can do it by using this <a target=\"_blank\" " +
271
                    "href=\"http://www.opendoar.org/suggest.php?rID=" + repository.getId().split("::")[1] + "\">OpenDOAR link</a>");
272
            basicInfoWarningLabel.setVisible(true);
273
        } else if(mode.equals(Constants.REPOSITORY_MODE_RE3DATA)) {
274
            basicInfoWarningLabel.setHTML("The following fields are completed by Re3data.<br>" +
275
                    "If you want to edit them, you can do it by using this <a target=\"_blank\" " +
276
                    "href=\"http://service.re3data.org/repository/" + repository.getId().split("::")[1] + "\">Re3data link</a>");
277
            basicInfoWarningLabel.setVisible(true);
278
        }
279

  
280
        if (repository.getTypology() != null) {
281
            if(timezoneValuesMap.get(repository.getTypology())!=null)
282
                typologyListBox.setSelectedIndex(typologyValuesMap.get(repository.getTypology()));
283
            else if(typologyValuesMap.containsKey("[Other]")){
284
                typologyListBox.setSelectedIndex(typologyValuesMap.get("[Other]"));
285
                typologyTextBox.setVisible(true);
286
                typologyTextBox.setValue(repository.getTypology());
287
            }
288
        }
289

  
290
        if (repository.getOfficialName() != null)
291
            officialName.setValue(repository.getOfficialName());
292

  
293
        if (mode.equals(Constants.REPOSITORY_MODE_JOURNAL)) {
294
            if (repository.getIssn() != null)
295
                issn.setValue(repository.getIssn());
296
            if (repository.getEissn() != null)
297
                eissn.setValue(repository.getEissn());
298
            if (repository.getLissn() != null)
299
                lissn.setValue(repository.getLissn());
300
        }
301

  
302
        if (repository.getDescription() != null)
303
            description.setValue(repository.getDescription());
304
        if (repository.getCountryName() != null)
305
            countryListBox.setSelectedIndex(countryValuesMap.get(repository.getCountryName()));
306
        if (repository.getLongitude() != null)
307
            longitude.setValue(repository.getLongitude() + "");
308
        if (repository.getLatitude() != null)
309
            latitude.setValue(repository.getLatitude() + "");
310
        if (repository.getWebsiteUrl() != null)
311
            entryURL.setValue(repository.getWebsiteUrl());
312
        if (repository.getOrganization() != null)
313
            institution.setValue(repository.getOrganization());
314

  
315
        if (repository.getEnglishName() != null)
316
            englishName.setValue(repository.getEnglishName());
317
        if (repository.getLogoUrl() != null)
318
            logoURL.setValue(repository.getLogoUrl());
319
        if(repository.getTimezone()!=null)
320
            timezoneListBox.setSelectedIndex(timezoneValuesMap.get(repository.getTimezone()+""));
321
        if(repository.getDatasourceClass()!=null && datasourceClassValuesMap.containsKey(repository.getDatasourceClass()))
322
            datasourceClassListBox.setSelectedIndex(datasourceClassValuesMap.get(repository.getDatasourceClass()));
323

  
324
        if (repository.getContactEmail() != null)
325
            admin.setValue(repository.getContactEmail());
326
    }
327

  
328
    public Repository getRepository() {
329

  
330
        if(isComplete()) {
331

  
332
            if(repositoryInformationForm.validate()) {
333

  
334
                if (typologyListBox.getSelectedValue().equals("[Other]"))
335
                    repository.setTypology(typologyTextBox.getValue().trim());
336
                else
337
                    repository.setTypology(typologyListBox.getSelectedValue());
338

  
339
                repository.setOfficialName(officialName.getValue().trim());
340

  
341
                if (mode.equals(Constants.REPOSITORY_MODE_JOURNAL)) {
342
                    repository.setIssn(issn.getValue().trim());
343
                    if (eissn.getValue() != null && !eissn.getValue().trim().isEmpty())
344
                        repository.setEissn(eissn.getValue().trim());
345
                    if (lissn.getValue() != null && !lissn.getValue().trim().isEmpty())
346
                        repository.setLissn(lissn.getValue().trim());
347
                }
348

  
349
                repository.setDescription(description.getValue().trim());
350
                repository.setCountryName(countryListBox.getSelectedValue());
351
                repository.setLongitude(Double.parseDouble(longitude.getValue().trim()));
352
                repository.setLatitude(Double.parseDouble(latitude.getValue().trim()));
353
                repository.setWebsiteUrl(entryURL.getValue().trim());
354
                repository.setOrganization(institution.getValue().trim());
355

  
356
                repository.setEnglishName(englishName.getValue().trim());
357
                repository.setLogoUrl(logoURL.getValue().trim());
358
                repository.setTimezone(Double.parseDouble(timezoneListBox.getSelectedValue()));
359
                repository.setDatasourceClass(datasourceClassListBox.getSelectedValue());
360

  
361
                repository.setContactEmail(admin.getValue());
362

  
363
                return repository;
364
            }
365
        }
366

  
367
        return null;
368
    }
369

  
370
    private boolean isComplete() {
371

  
372
        boolean isComplete = true;
373

  
374
        errorLabel.setVisible(false);
375
        successLabel.setVisible(false);
376

  
377
        if(typologyListBox.getSelectedValue().equals("noneSelected")) {
378
            isComplete = false;
379
            typologyListFormGroup.setFormGroupValidationState(ValidationState.ERROR);
380
        } else if(typologyListBox.getSelectedValue().equals("[Other]")
381
                && (typologyTextBox.getValue()==null || typologyTextBox.getValue().trim().isEmpty())) {
382
            isComplete = false;
383
            typologyTextFormGroup.setFormGroupValidationState(ValidationState.ERROR);
384
        }
385

  
386
        if(officialName.getValue()==null || officialName.getValue().trim().isEmpty()) {
387
            isComplete = false;
388
            officialNameFormGroup.setFormGroupValidationState(ValidationState.ERROR);
389
        }
390

  
391
        if(mode.equals(Constants.REPOSITORY_MODE_JOURNAL)
392
                && (issn.getValue()==null || issn.getValue().trim().isEmpty())) {
393
            isComplete = false;
394
            issnFormGroup.setFormGroupValidationState(ValidationState.ERROR);
395
        }
396

  
397
        if(description.getValue()==null || description.getValue().trim().isEmpty()) {
398
            isComplete = false;
399
            descriptionFormGroup.setFormGroupValidationState(ValidationState.ERROR);
400
        }
401

  
402
        if(countryListBox.getSelectedValue().equals("noneSelected")) {
403
            isComplete = false;
404
            countryFormGroup.setFormGroupValidationState(ValidationState.ERROR);
405
        }
406

  
407
        if(longitude.getValue()==null || longitude.getValue().trim().isEmpty()) {
408
            isComplete = false;
409
            longitudeFormGroup.setFormGroupValidationState(ValidationState.ERROR);
410
        }
411

  
412
        if(latitude.getValue()==null || latitude.getValue().trim().isEmpty()) {
413
            isComplete = false;
414
            latitudeFormGroup.setFormGroupValidationState(ValidationState.ERROR);
415
        }
416

  
417
        if(entryURL.getValue()==null || entryURL.getValue().trim().isEmpty()) {
418
            isComplete = false;
419
            entryURLFormGroup.setFormGroupValidationState(ValidationState.ERROR);
420
        }
421

  
422
        if(institution.getValue()==null || institution.getValue().trim().isEmpty()) {
423
            isComplete = false;
424
            institutionFormGroup.setFormGroupValidationState(ValidationState.ERROR);
425
        }
426

  
427
        if(englishName.getValue()==null || englishName.getValue().trim().isEmpty()) {
428
            isComplete = false;
429
            englishNameFormGroup.setFormGroupValidationState(ValidationState.ERROR);
430
        }
431

  
432
        if(timezoneListBox.getSelectedValue().equals("noneSelected")) {
433
            isComplete = false;
434
            timezoneFormGroup.setFormGroupValidationState(ValidationState.ERROR);
435
        }
436

  
437
        if(datasourceClassListBox.getSelectedValue().equals("noneSelected")) {
438
            isComplete = false;
439
            datasourceClassFormGroup.setFormGroupValidationState(ValidationState.ERROR);
440
        }
441

  
442
        if(admin.getValue()==null || admin.getValue().trim().isEmpty()) {
443
            isComplete = false;
444
            adminFormGroup.setFormGroupValidationState(ValidationState.ERROR);
445
        }
446

  
447
        if(!isComplete) {
448
            errorLabel.setText("All fields marked with * are mandatory.");
449
            errorLabel.setVisible(true);
450
        }
451

  
452
        return isComplete;
453
    }
454

  
455
    private void addFieldValidators() {
456

  
457
        longitude.addValidator(new Validator<String>() {
458

  
459
            @Override
460
            public int getPriority() {
461
                return 0;
462
            }
463

  
464
            @Override
465
            public List<EditorError> validate(Editor<String> editor, String value) {
466

  
467
                List<EditorError> result = new ArrayList<EditorError>();
468
                String valueStr = value == null ? "" : value.toString();
469

  
470
                RegExp regExp = RegExp.compile(Constants.LONGITUDE_PATTERN);
471
                if (!regExp.test(valueStr.trim().toLowerCase())) {
472

  
473
                    longitudeFormGroup.displayInlineError("Invalid longitude");
474
                    result.add(new BasicEditorError(longitude, value, "Invalid longitude"));
475
                    errorLabel.setText("Invalid fields!");
476
                    errorLabel.setVisible(true);
477
                }
478

  
479
                return result;
480
            }
481
        });
482

  
483
        latitude.addValidator(new Validator<String>() {
484

  
485
            @Override
486
            public int getPriority() {
487
                return 0;
488
            }
489

  
490
            @Override
491
            public List<EditorError> validate(Editor<String> editor, String value) {
492

  
493
                List<EditorError> result = new ArrayList<EditorError>();
494
                String valueStr = value == null ? "" : value.toString();
495

  
496
                RegExp regExp = RegExp.compile(Constants.LATITUDE_PATTERN);
497
                if (!regExp.test(valueStr.trim().toLowerCase())) {
498

  
499
                    latitudeFormGroup.displayInlineError("Invalid latitude");
500
                    result.add(new BasicEditorError(latitude, value, "Invalid latitude"));
501
                    errorLabel.setText("Invalid fields!");
502
                    errorLabel.setVisible(true);
503
                }
504

  
505
                return result;
506
            }
507
        });
508

  
509
        admin.addValidator(new Validator<String>() {
510

  
511
            @Override
512
            public int getPriority() {
513
                return 0;
514
            }
515

  
516
            @Override
517
            public List<EditorError> validate(Editor<String> editor, String value) {
518

  
519
                List<EditorError> result = new ArrayList<EditorError>();
520
                String valueStr = value == null ? "" : value.toString();
521

  
522
                RegExp regExp = RegExp.compile(Constants.EMAIL_PATTERN);
523
                if (!regExp.test(valueStr.trim().toLowerCase())) {
524

  
525
                    adminFormGroup.displayInlineError("Invalid email address");
526
                    result.add(new BasicEditorError(admin, value, "Invalid email address"));
527
                    errorLabel.setText("Invalid fields!");
528
                    errorLabel.setVisible(true);
529
                }
530

  
531
                return result;
532
            }
533
        });
534

  
535
        if(mode.equals(Constants.REPOSITORY_MODE_JOURNAL)) {
536

  
537
            issn.addValidator(new Validator<String>() {
538

  
539
                @Override
540
                public int getPriority() {
541
                    return 0;
542
                }
543

  
544
                @Override
545
                public List<EditorError> validate(Editor<String> editor, String value) {
546

  
547
                    List<EditorError> result = new ArrayList<EditorError>();
548
                    String valueStr = value == null ? "" : value.toString();
549

  
550
                    if (valueStr.length()!=8) {
551
                        issnFormGroup.displayInlineError("Issn length has to be 8 characters");
552
                        result.add(new BasicEditorError(issn, value, "Issn length has to be 8 characters"));
553
                        errorLabel.setText("Invalid fields!");
554
                        errorLabel.setVisible(true);
555
                    }
556

  
557
                    return result;
558
                }
559
            });
560

  
561
            eissn.addValidator(new Validator<String>() {
562

  
563
                @Override
564
                public int getPriority() {
565
                    return 0;
566
                }
567

  
568
                @Override
569
                public List<EditorError> validate(Editor<String> editor, String value) {
570

  
571
                    List<EditorError> result = new ArrayList<EditorError>();
572
                    String valueStr = value == null ? "" : value.toString();
573

  
574
                    if (valueStr.length()!=8) {
575
                        eissnFormGroup.displayInlineError("Eissn length has to be 8 characters");
576
                        result.add(new BasicEditorError(eissn, value, "Eissn length has to be 8 characters"));
577
                        errorLabel.setText("Invalid fields!");
578
                        errorLabel.setVisible(true);
579
                    }
580

  
581
                    return result;
582
                }
583
            });
584

  
585
            lissn.addValidator(new Validator<String>() {
586

  
587
                @Override
588
                public int getPriority() {
589
                    return 0;
590
                }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff