1 |
40576
|
stefania.m
|
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.regexp.shared.RegExp;
|
7 |
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
8 |
|
|
import com.google.gwt.user.client.ui.FlowPanel;
|
9 |
|
|
import com.google.gwt.user.client.ui.HTML;
|
10 |
|
|
import com.google.gwt.user.client.ui.IsWidget;
|
11 |
|
|
import com.google.gwt.user.client.ui.Widget;
|
12 |
|
|
import eu.dnetlib.domain.data.Repository;
|
13 |
41093
|
stefania.m
|
import eu.dnetlib.repo.manager.client.services.RepositoryService;
|
14 |
|
|
import eu.dnetlib.repo.manager.client.services.RepositoryServiceAsync;
|
15 |
41617
|
stefania.m
|
import eu.dnetlib.gwt.client.MyFormGroup;
|
16 |
40576
|
stefania.m
|
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 |
40698
|
stefania.m
|
import eu.dnetlib.repo.manager.shared.Constants;
|
20 |
40576
|
stefania.m
|
import org.gwtbootstrap3.client.ui.Alert;
|
21 |
|
|
import org.gwtbootstrap3.client.ui.Form;
|
22 |
|
|
import org.gwtbootstrap3.client.ui.ListBox;
|
23 |
|
|
import org.gwtbootstrap3.client.ui.RadioButton;
|
24 |
|
|
import org.gwtbootstrap3.client.ui.constants.AlertType;
|
25 |
|
|
import org.gwtbootstrap3.client.ui.constants.ButtonType;
|
26 |
|
|
|
27 |
|
|
import java.util.ArrayList;
|
28 |
|
|
import java.util.List;
|
29 |
|
|
import java.util.Map;
|
30 |
|
|
|
31 |
|
|
/**
|
32 |
|
|
* Created by stefania on 12/17/15.
|
33 |
|
|
*/
|
34 |
|
|
public class SelectRepositoryWidget implements IsWidget {
|
35 |
|
|
|
36 |
|
|
private FlowPanel selectRepositoryPanel = new FlowPanel();
|
37 |
|
|
|
38 |
40698
|
stefania.m
|
private Alert errorAlert = new Alert();
|
39 |
|
|
|
40 |
40576
|
stefania.m
|
private HTML infoLabel = new HTML();
|
41 |
|
|
|
42 |
|
|
private Form form = new Form();
|
43 |
|
|
private ListBox countriesListBox = new ListBox();
|
44 |
|
|
private TextBox autocomplete = new TextBox();
|
45 |
|
|
|
46 |
|
|
private FlowPanel repositoriesPanel = new FlowPanel();
|
47 |
|
|
|
48 |
|
|
private List<Repository> repositoriesForCountryList = new ArrayList<Repository>();
|
49 |
|
|
private List<Repository> matchingRepositoriesForCountryList = new ArrayList<Repository>();
|
50 |
|
|
|
51 |
|
|
private Repository selectedRepository;
|
52 |
|
|
|
53 |
|
|
private RepositoryServiceAsync repositoryService = GWT.create(RepositoryService.class);
|
54 |
|
|
|
55 |
40698
|
stefania.m
|
private String mode;
|
56 |
|
|
|
57 |
40576
|
stefania.m
|
public SelectRepositoryWidget(Map<String, String> countries, final String mode) {
|
58 |
|
|
|
59 |
40698
|
stefania.m
|
this.mode = mode;
|
60 |
|
|
|
61 |
40576
|
stefania.m
|
selectRepositoryPanel.addStyleName("animated fadeInRight");
|
62 |
|
|
selectRepositoryPanel.addStyleName("stepContent");
|
63 |
|
|
|
64 |
40698
|
stefania.m
|
errorAlert.setType(AlertType.DANGER);
|
65 |
|
|
errorAlert.setDismissable(false);
|
66 |
|
|
errorAlert.setVisible(false);
|
67 |
|
|
selectRepositoryPanel.add(errorAlert);
|
68 |
|
|
|
69 |
40576
|
stefania.m
|
infoLabel.addStyleName("alert alert-info");
|
70 |
40698
|
stefania.m
|
if(mode.equals(Constants.REPOSITORY_MODE_OPENDOAR)) {
|
71 |
41640
|
stefania.m
|
|
72 |
|
|
repositoryService.getLatestUpdateDateOfList(mode, new AsyncCallback<String>() {
|
73 |
|
|
|
74 |
|
|
@Override
|
75 |
|
|
public void onFailure(Throwable caught) {
|
76 |
|
|
infoLabel.setHTML("Please make sure your repository is registered in <a href=\"http://www.opendoar.org\" " +
|
77 |
|
|
"target=\"_blank\"><i class=\"fa fa-external-link\" style=\"margin-right:3px\"></i>OpenDOAR</a>.");
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
@Override
|
81 |
|
|
public void onSuccess(String result) {
|
82 |
|
|
infoLabel.setHTML("Please make sure your repository is registered in <a href=\"http://www.opendoar.org\" " +
|
83 |
|
|
"target=\"_blank\"><i class=\"fa fa-external-link\" style=\"margin-right:3px\"></i>OpenDOAR</a>.<br>" +
|
84 |
|
|
"<b>Last Updated: </b>" + result);
|
85 |
|
|
}
|
86 |
|
|
});
|
87 |
|
|
|
88 |
40698
|
stefania.m
|
} else if(mode.equals(Constants.REPOSITORY_MODE_RE3DATA)) {
|
89 |
41640
|
stefania.m
|
|
90 |
|
|
repositoryService.getLatestUpdateDateOfList(mode, new AsyncCallback<String>() {
|
91 |
|
|
|
92 |
|
|
@Override
|
93 |
|
|
public void onFailure(Throwable caught) {
|
94 |
|
|
infoLabel.setHTML("Please make sure your repository is registered in <a href=\"http://www.re3data.org\" " +
|
95 |
|
|
"target=\"_blank\"><i class=\"fa fa-external-link\" style=\"margin-right:3px\"></i>Re3data</a>.");
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
@Override
|
99 |
|
|
public void onSuccess(String result) {
|
100 |
|
|
infoLabel.setHTML("Please make sure your repository is registered in <a href=\"http://www.re3data.org\" " +
|
101 |
|
|
"target=\"_blank\"><i class=\"fa fa-external-link\" style=\"margin-right:3px\"></i>Re3data</a>.<br>" +
|
102 |
|
|
"<b>Last Updated: </b>" + result);
|
103 |
|
|
}
|
104 |
|
|
});
|
105 |
40576
|
stefania.m
|
}
|
106 |
|
|
|
107 |
|
|
selectRepositoryPanel.add(infoLabel);
|
108 |
|
|
|
109 |
|
|
countriesListBox.addItem("-- none selected --", "noneSelected");
|
110 |
|
|
for(String country : countries.keySet()) {
|
111 |
|
|
countriesListBox.addItem(countries.get(country), country);
|
112 |
|
|
}
|
113 |
|
|
countriesListBox.addChangeHandler(new ChangeHandler() {
|
114 |
|
|
@Override
|
115 |
|
|
public void onChange(ChangeEvent event) {
|
116 |
|
|
|
117 |
|
|
repositoriesPanel.clear();
|
118 |
|
|
|
119 |
|
|
repositoriesForCountryList.clear();
|
120 |
|
|
matchingRepositoriesForCountryList.clear();
|
121 |
|
|
|
122 |
|
|
if(!countriesListBox.getSelectedValue().equals("noneSelected")) {
|
123 |
|
|
|
124 |
42070
|
stefania.m
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\" style=\"text-align: center; padding-top: 20px; " +
|
125 |
|
|
"color: rgb(47, 64, 80); font-weight: bold;\">Retrieving repositories for selected country</div>" +
|
126 |
|
|
"<div class=\"whiteFilm\"></div>");
|
127 |
|
|
repositoriesPanel.addStyleName("loading");
|
128 |
|
|
repositoriesPanel.add(loadingWheel);
|
129 |
|
|
|
130 |
40698
|
stefania.m
|
repositoryService.getRepositoriesByCountry(countriesListBox.getSelectedValue(), mode,
|
131 |
|
|
new AsyncCallback<List<Repository>>() {
|
132 |
40576
|
stefania.m
|
|
133 |
|
|
@Override
|
134 |
|
|
public void onFailure(Throwable caught) {
|
135 |
|
|
|
136 |
|
|
Alert errorLabel = new Alert();
|
137 |
|
|
errorLabel.setText("System error retrieving repositories for this country");
|
138 |
|
|
errorLabel.setType(AlertType.DANGER);
|
139 |
|
|
errorLabel.setDismissable(false);
|
140 |
|
|
|
141 |
40698
|
stefania.m
|
repositoriesPanel.removeStyleName("loading");
|
142 |
|
|
repositoriesPanel.remove(loadingWheel);
|
143 |
40576
|
stefania.m
|
repositoriesPanel.add(errorLabel);
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
@Override
|
147 |
40698
|
stefania.m
|
public void onSuccess(List<Repository> repositories) {
|
148 |
40576
|
stefania.m
|
|
149 |
40698
|
stefania.m
|
repositoriesPanel.removeStyleName("loading");
|
150 |
|
|
repositoriesPanel.remove(loadingWheel);
|
151 |
40576
|
stefania.m
|
|
152 |
40698
|
stefania.m
|
repositoriesForCountryList.addAll(repositories);
|
153 |
|
|
|
154 |
40576
|
stefania.m
|
if(autocomplete.getValue()!=null && !autocomplete.getValue().trim().equals("")) {
|
155 |
|
|
|
156 |
|
|
for (Repository repository : repositoriesForCountryList) {
|
157 |
|
|
if (repository.getOfficialName().toLowerCase().contains(autocomplete.getValue().toLowerCase())) {
|
158 |
|
|
matchingRepositoriesForCountryList.add(repository);
|
159 |
|
|
}
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
} else {
|
163 |
|
|
|
164 |
|
|
matchingRepositoriesForCountryList.addAll(repositoriesForCountryList);
|
165 |
|
|
}
|
166 |
|
|
|
167 |
|
|
repositoriesPanel.clear();
|
168 |
40698
|
stefania.m
|
drawRepositoriesPanel(matchingRepositoriesForCountryList);
|
169 |
40576
|
stefania.m
|
|
170 |
|
|
autocomplete.setEnabled(true);
|
171 |
|
|
}
|
172 |
|
|
});
|
173 |
|
|
} else {
|
174 |
|
|
autocomplete.setEnabled(false);
|
175 |
|
|
}
|
176 |
|
|
}
|
177 |
|
|
});
|
178 |
|
|
|
179 |
51030
|
panagiotis
|
form.add(new MyFormGroup(false, "Country", countriesListBox));
|
180 |
40576
|
stefania.m
|
|
181 |
|
|
autocomplete.setValueChangeHandler(new ValueChangeHandler() {
|
182 |
|
|
@Override
|
183 |
|
|
public void handle(ValueChangeEvent valueChangeEvent) {
|
184 |
|
|
|
185 |
|
|
matchingRepositoriesForCountryList.clear();
|
186 |
|
|
|
187 |
|
|
if(valueChangeEvent.getNewValue()!=null && !valueChangeEvent.getNewValue().trim().equals("")) {
|
188 |
|
|
|
189 |
|
|
for (Repository repository : repositoriesForCountryList) {
|
190 |
|
|
if (repository.getOfficialName().toLowerCase().contains(valueChangeEvent.getNewValue().toLowerCase())) {
|
191 |
|
|
matchingRepositoriesForCountryList.add(repository);
|
192 |
|
|
}
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
repositoriesPanel.clear();
|
196 |
40698
|
stefania.m
|
drawRepositoriesPanel(matchingRepositoriesForCountryList);
|
197 |
40576
|
stefania.m
|
|
198 |
|
|
} else {
|
199 |
|
|
|
200 |
|
|
matchingRepositoriesForCountryList.addAll(repositoriesForCountryList);
|
201 |
|
|
|
202 |
|
|
repositoriesPanel.clear();
|
203 |
40698
|
stefania.m
|
drawRepositoriesPanel(matchingRepositoriesForCountryList);
|
204 |
40576
|
stefania.m
|
}
|
205 |
|
|
}
|
206 |
|
|
});
|
207 |
|
|
autocomplete.setEnabled(false);
|
208 |
51030
|
panagiotis
|
form.add(new MyFormGroup(false, "Search by repository name", autocomplete));
|
209 |
40576
|
stefania.m
|
|
210 |
|
|
selectRepositoryPanel.add(form);
|
211 |
|
|
|
212 |
|
|
selectRepositoryPanel.add(repositoriesPanel);
|
213 |
|
|
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
@Override
|
217 |
|
|
public Widget asWidget() {
|
218 |
|
|
return selectRepositoryPanel;
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
public Repository getSelectedRepository() {
|
222 |
40698
|
stefania.m
|
|
223 |
|
|
errorAlert.setVisible(false);
|
224 |
|
|
|
225 |
|
|
if(selectedRepository==null) {
|
226 |
|
|
errorAlert.setVisible(true);
|
227 |
|
|
errorAlert.setText("You need to select a repository first.");
|
228 |
|
|
}
|
229 |
|
|
|
230 |
40576
|
stefania.m
|
return selectedRepository;
|
231 |
|
|
}
|
232 |
|
|
|
233 |
40698
|
stefania.m
|
private void drawRepositoriesPanel(List<Repository> matchingRepositoriesForCountryList) {
|
234 |
40576
|
stefania.m
|
|
235 |
40698
|
stefania.m
|
String modeName = "";
|
236 |
|
|
if(mode.equals(Constants.REPOSITORY_MODE_OPENDOAR))
|
237 |
|
|
modeName = "OpenDOAR";
|
238 |
|
|
else
|
239 |
|
|
modeName = "Re3data";
|
240 |
|
|
|
241 |
|
|
HTML labelForCountry = new HTML("<h2>" + modeName + " Repositories in " + countriesListBox.getSelectedValue() + "</h2>");
|
242 |
40576
|
stefania.m
|
repositoriesPanel.add(labelForCountry);
|
243 |
|
|
|
244 |
|
|
addRepositoriesRadioListToPanel(matchingRepositoriesForCountryList, repositoriesPanel);
|
245 |
|
|
}
|
246 |
|
|
|
247 |
|
|
private void addRepositoriesRadioListToPanel(List<Repository> repositories, FlowPanel panel) {
|
248 |
|
|
|
249 |
|
|
if(repositories.isEmpty()) {
|
250 |
|
|
|
251 |
|
|
Alert warningAlert = new Alert();
|
252 |
|
|
warningAlert.setType(AlertType.WARNING);
|
253 |
|
|
warningAlert.setDismissable(false);
|
254 |
|
|
warningAlert.setText("No repositories found");
|
255 |
|
|
|
256 |
|
|
panel.add(warningAlert);
|
257 |
|
|
|
258 |
|
|
} else {
|
259 |
|
|
|
260 |
|
|
Form repositoriesRadioButtonsForm = new Form();
|
261 |
|
|
repositoriesRadioButtonsForm.addStyleName("repositoriesRadioButtonForm");
|
262 |
|
|
|
263 |
|
|
for(final Repository repository : repositories) {
|
264 |
|
|
|
265 |
40601
|
stefania.m
|
String repositoryName = "";
|
266 |
|
|
if(autocomplete.getValue()!=null && !autocomplete.getValue().trim().equals("")) {
|
267 |
|
|
|
268 |
|
|
//TODO make it not lose case sensitivity
|
269 |
|
|
repositoryName = RegExp.compile(autocomplete.getValue(), "gi")
|
270 |
|
|
.replace(repository.getOfficialName(), "<mark>" + autocomplete.getValue() + "</mark>");
|
271 |
|
|
} else {
|
272 |
|
|
repositoryName = repository.getOfficialName();
|
273 |
|
|
}
|
274 |
|
|
|
275 |
|
|
final RadioButton radioButton;
|
276 |
40801
|
nikon.gasp
|
if(repository.isRegistered()) {
|
277 |
40775
|
stefania.m
|
radioButton = new RadioButton("repository", repositoryName +
|
278 |
|
|
"<span class=\"label label-warning registeredLabel\">Registered</span>" +
|
279 |
|
|
"<a target=\"_blank\" href=\"" + repository.getWebsiteUrl() + "\"><i class=\"fa " +
|
280 |
|
|
"fa-external-link externalLink\"></i></a>", true);
|
281 |
|
|
radioButton.setEnabled(false);
|
282 |
40601
|
stefania.m
|
} else {
|
283 |
40775
|
stefania.m
|
radioButton = new RadioButton("repository", repositoryName +
|
284 |
|
|
"<a target=\"_blank\" href=\"" + repository.getWebsiteUrl() + "\"><i class=\"fa " +
|
285 |
|
|
"fa-external-link externalLink\"></i></a>", true);
|
286 |
40601
|
stefania.m
|
}
|
287 |
40576
|
stefania.m
|
radioButton.setType(ButtonType.LINK);
|
288 |
|
|
radioButton.addChangeHandler(new ChangeHandler() {
|
289 |
|
|
@Override
|
290 |
|
|
public void onChange(ChangeEvent event) {
|
291 |
|
|
if(radioButton.getValue()) {
|
292 |
|
|
selectedRepository = repository;
|
293 |
|
|
}
|
294 |
|
|
}
|
295 |
|
|
});
|
296 |
41630
|
stefania.m
|
repositoriesRadioButtonsForm.add(new MyFormGroup(false, null, radioButton));
|
297 |
40576
|
stefania.m
|
}
|
298 |
|
|
|
299 |
|
|
panel.add(repositoriesRadioButtonsForm);
|
300 |
|
|
}
|
301 |
|
|
}
|
302 |
|
|
}
|