2016-05-26 18:12:53 +02:00
|
|
|
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2016-05-27 19:08:03 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
2016-05-26 18:12:53 +02:00
|
|
|
import java.util.List;
|
2016-05-27 19:08:03 +02:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map.Entry;
|
2016-05-26 18:12:53 +02:00
|
|
|
|
2016-06-06 17:24:52 +02:00
|
|
|
import org.gcube.portlets.user.gcubewidgets.client.elements.Span;
|
2016-05-26 18:12:53 +02:00
|
|
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService;
|
|
|
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherServiceAsync;
|
2016-06-13 17:40:19 +02:00
|
|
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.Encoder;
|
2016-05-27 19:08:03 +02:00
|
|
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEvent;
|
|
|
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEventHandler;
|
|
|
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadataBean;
|
2016-05-26 18:12:53 +02:00
|
|
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean;
|
2016-06-09 18:58:19 +02:00
|
|
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataProfileBean;
|
|
|
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper;
|
2016-05-26 18:12:53 +02:00
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.AlertBlock;
|
2016-05-26 18:12:53 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
2016-06-06 17:24:52 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.CheckBox;
|
2016-05-26 18:12:53 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.ControlGroup;
|
2016-06-09 18:58:19 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.Form;
|
2016-05-26 18:12:53 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.ListBox;
|
2016-06-09 18:58:19 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.Paragraph;
|
2016-06-07 17:50:33 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.Tab;
|
|
|
|
import com.github.gwtbootstrap.client.ui.TabPanel;
|
2016-05-26 18:12:53 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.TextArea;
|
|
|
|
import com.github.gwtbootstrap.client.ui.TextBox;
|
2016-05-27 19:08:03 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.base.ListItem;
|
|
|
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
2016-06-10 12:10:18 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
|
2016-06-07 17:50:33 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.resources.Bootstrap.Tabs;
|
2016-05-26 18:12:53 +02:00
|
|
|
import com.google.gwt.core.client.GWT;
|
2016-06-09 18:58:19 +02:00
|
|
|
import com.google.gwt.event.dom.client.ChangeEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ChangeHandler;
|
2016-05-26 18:12:53 +02:00
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
2016-05-27 19:08:03 +02:00
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
|
import com.google.gwt.event.dom.client.KeyCodes;
|
|
|
|
import com.google.gwt.event.dom.client.KeyDownEvent;
|
|
|
|
import com.google.gwt.event.shared.HandlerManager;
|
2016-05-26 18:12:53 +02:00
|
|
|
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
|
import com.google.gwt.uibinder.client.UiField;
|
|
|
|
import com.google.gwt.uibinder.client.UiHandler;
|
2016-06-06 17:24:52 +02:00
|
|
|
import com.google.gwt.user.client.Timer;
|
2016-06-10 12:10:18 +02:00
|
|
|
import com.google.gwt.user.client.Window;
|
2016-05-26 18:12:53 +02:00
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
import com.google.gwt.user.client.ui.Composite;
|
2016-05-27 19:08:03 +02:00
|
|
|
import com.google.gwt.user.client.ui.FlowPanel;
|
2016-06-10 12:10:18 +02:00
|
|
|
import com.google.gwt.user.client.ui.HTMLPanel;
|
2016-06-07 17:50:33 +02:00
|
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
2016-05-26 18:12:53 +02:00
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
|
|
|
|
/**
|
2016-06-09 18:58:19 +02:00
|
|
|
* Create metadata form for ckan dataset.
|
2016-05-26 18:12:53 +02:00
|
|
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
|
|
|
*/
|
2016-06-08 18:31:54 +02:00
|
|
|
public class CreateDatasetForm extends Composite{
|
2016-05-27 19:08:03 +02:00
|
|
|
|
2016-05-26 18:12:53 +02:00
|
|
|
/**
|
|
|
|
* Create a remote service proxy to talk to the server-side ckan service.
|
|
|
|
*/
|
|
|
|
private final CKanPublisherServiceAsync ckanServices = GWT.create(CKanPublisherService.class);
|
|
|
|
|
|
|
|
private static EditMetadataFormUiBinder uiBinder = GWT
|
|
|
|
.create(EditMetadataFormUiBinder.class);
|
|
|
|
|
|
|
|
interface EditMetadataFormUiBinder extends
|
2016-06-08 18:31:54 +02:00
|
|
|
UiBinder<Widget, CreateDatasetForm> {
|
2016-05-26 18:12:53 +02:00
|
|
|
}
|
|
|
|
|
2016-06-10 12:10:18 +02:00
|
|
|
@UiField HTMLPanel createDatasetMainPanel;
|
2016-05-26 18:12:53 +02:00
|
|
|
@UiField TextBox titleTextBox;
|
|
|
|
@UiField TextArea descriptionTextarea;
|
2016-05-27 19:08:03 +02:00
|
|
|
@UiField TextBox tagsEnterTextBox;
|
|
|
|
@UiField FlowPanel tagsPanel;
|
2016-05-26 18:12:53 +02:00
|
|
|
@UiField ListBox licenseListbox;
|
|
|
|
@UiField ListBox visibilityListbox;
|
2016-06-06 17:24:52 +02:00
|
|
|
@UiField ListBox organizationsListbox;
|
2016-05-26 18:12:53 +02:00
|
|
|
@UiField TextBox versionTextbox;
|
|
|
|
@UiField TextBox authorTextbox;
|
|
|
|
@UiField TextBox authorEmailTextbox;
|
|
|
|
@UiField TextBox maintainerTextbox;
|
|
|
|
@UiField TextBox maintainerEmailTextbox;
|
|
|
|
@UiField ControlGroup customFields;
|
|
|
|
@UiField Button addCustomFieldButton;
|
2016-06-06 17:24:52 +02:00
|
|
|
@UiField CheckBox addResourcesCheckBox;
|
2016-06-07 17:50:33 +02:00
|
|
|
@UiField ControlGroup resourcesControlGroup;
|
2016-05-26 18:12:53 +02:00
|
|
|
@UiField Button createButton;
|
|
|
|
@UiField Button resetButton;
|
2016-05-27 19:08:03 +02:00
|
|
|
@UiField AlertBlock infoBlock;
|
2016-06-09 18:58:19 +02:00
|
|
|
@UiField AlertBlock onContinueAlertBlock;
|
2016-06-06 17:24:52 +02:00
|
|
|
@UiField AlertBlock onCreateAlertBlock;
|
2016-06-09 18:58:19 +02:00
|
|
|
@UiField VerticalPanel metadataFieldsPanel;
|
|
|
|
@UiField ListBox metadataProfilesFormatListbox;
|
|
|
|
@UiField Form formFirstStep;
|
|
|
|
@UiField Form formSecondStep;
|
|
|
|
@UiField Button continueButton;
|
|
|
|
@UiField Button goBackButton;
|
|
|
|
@UiField Paragraph selectedProfile;
|
2016-06-10 12:10:18 +02:00
|
|
|
@UiField Button goToDatasetButton;
|
|
|
|
@UiField Button addResourcesButton;
|
2016-06-07 17:50:33 +02:00
|
|
|
|
|
|
|
// tab panel
|
|
|
|
private TabPanel tabPanel;
|
|
|
|
|
|
|
|
// add resource form
|
2016-06-08 18:31:54 +02:00
|
|
|
private AddResourceToDataset resourceForm;
|
2016-05-27 19:08:03 +02:00
|
|
|
|
|
|
|
// tags list
|
|
|
|
private List<String> tagsList = new ArrayList<String>();
|
|
|
|
|
2016-05-26 18:12:53 +02:00
|
|
|
// the licenses
|
|
|
|
private LicensesBean licenseBean;
|
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
// event bus
|
|
|
|
private final HandlerManager eventBus = new HandlerManager(null);
|
|
|
|
|
2016-05-26 18:12:53 +02:00
|
|
|
// added custom field entries
|
2016-06-06 17:24:52 +02:00
|
|
|
List<CustomFieldEntry> customFieldEntriesList = new ArrayList<CustomFieldEntry>();
|
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
// dataset metadata bean
|
|
|
|
private DatasetMetadataBean receivedBean;
|
2016-05-26 18:12:53 +02:00
|
|
|
|
2016-06-07 17:50:33 +02:00
|
|
|
// the owner
|
|
|
|
private String owner;
|
2016-06-06 17:24:52 +02:00
|
|
|
|
2016-06-08 18:31:54 +02:00
|
|
|
// workspace request?
|
|
|
|
private boolean isWorkspaceRequest = false;
|
|
|
|
|
2016-06-09 18:58:19 +02:00
|
|
|
// the list of MetaDataFieldSkeleton added
|
|
|
|
List<MetaDataFieldSkeleton> listOfMetadataFields = new ArrayList<MetaDataFieldSkeleton>();
|
|
|
|
|
2016-06-06 17:24:52 +02:00
|
|
|
/**
|
|
|
|
* Invoked in the most general case
|
|
|
|
* @param owner
|
|
|
|
*/
|
2016-06-08 18:31:54 +02:00
|
|
|
public CreateDatasetForm(String owner) {
|
2016-06-06 17:24:52 +02:00
|
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
|
|
|
2016-06-07 17:50:33 +02:00
|
|
|
this.owner = owner;
|
|
|
|
|
2016-06-06 17:24:52 +02:00
|
|
|
// bind on events
|
|
|
|
bind();
|
|
|
|
|
|
|
|
// set info block
|
|
|
|
setAlertBlock("Retrieving information, please wait...", AlertType.INFO, true);
|
|
|
|
|
2016-06-09 18:58:19 +02:00
|
|
|
// disable continue/reset button
|
|
|
|
continueButton.setEnabled(false);
|
2016-06-06 17:24:52 +02:00
|
|
|
resetButton.setEnabled(false);
|
|
|
|
|
|
|
|
// get back the licenses and the metadata information
|
2016-06-07 17:50:33 +02:00
|
|
|
ckanServices.getDatasetBean(null, owner, new AsyncCallback<DatasetMetadataBean>() {
|
2016-06-06 17:24:52 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(DatasetMetadataBean bean) {
|
|
|
|
|
|
|
|
if(bean != null){
|
|
|
|
|
|
|
|
// save it
|
|
|
|
receivedBean = bean;
|
|
|
|
|
|
|
|
// fill the form
|
|
|
|
versionTextbox.setText(String.valueOf(bean.getVersion()));
|
|
|
|
authorTextbox.setText(bean.getAuthor());
|
|
|
|
authorEmailTextbox.setText(bean.getAuthorEmail());
|
|
|
|
maintainerTextbox.setText(bean.getMaintainer());
|
|
|
|
maintainerEmailTextbox.setText(bean.getMaintainerEmail());
|
2016-06-08 18:31:54 +02:00
|
|
|
prepareMetadataList(receivedBean);
|
2016-06-06 17:24:52 +02:00
|
|
|
|
|
|
|
// set organizations
|
|
|
|
List<String> organizations = bean.getOrganizationList();
|
|
|
|
|
|
|
|
for (String organization : organizations) {
|
|
|
|
organizationsListbox.addItem(organization);
|
|
|
|
}
|
|
|
|
|
|
|
|
// try to retrieve the licenses
|
|
|
|
setAlertBlock("Retrieving licenses, please wait...", AlertType.INFO, true);
|
|
|
|
ckanServices.getLicenses(new AsyncCallback<LicensesBean>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(LicensesBean lBean) {
|
|
|
|
|
|
|
|
if(lBean != null && !lBean.getLicenses().isEmpty()){
|
|
|
|
|
|
|
|
licenseBean = lBean;
|
|
|
|
|
|
|
|
// fill the listbox
|
|
|
|
for(String license: licenseBean.getLicenses()){
|
|
|
|
licenseListbox.addItem(license);
|
|
|
|
}
|
|
|
|
|
|
|
|
// everything went ok
|
|
|
|
setAlertBlock("", AlertType.ERROR, false);
|
2016-06-09 18:58:19 +02:00
|
|
|
continueButton.setEnabled(true);
|
2016-06-06 17:24:52 +02:00
|
|
|
resetButton.setEnabled(true);
|
|
|
|
|
|
|
|
}else{
|
|
|
|
setAlertBlock("Error while retrieving licenses, try to refresh the page", AlertType.ERROR, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
|
|
|
|
setAlertBlock("Error while retrieving licenses, try to refresh the page", AlertType.ERROR, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
setAlertBlock("Error while retrieving information, try to refresh the page", AlertType.ERROR, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
|
|
|
|
setAlertBlock("Error while retrieving information, try to refresh the page", AlertType.ERROR, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-07 17:50:33 +02:00
|
|
|
// hide the Add resources checkbox
|
2016-06-09 18:58:19 +02:00
|
|
|
resourcesControlGroup.removeFromParent();
|
2016-06-06 17:24:52 +02:00
|
|
|
|
2016-06-08 18:31:54 +02:00
|
|
|
}
|
|
|
|
|
2016-06-06 17:24:52 +02:00
|
|
|
/**
|
|
|
|
* Invoked when the workspace is used.
|
|
|
|
* @param idFolderWorkspace
|
|
|
|
* @param owner
|
|
|
|
*/
|
2016-06-08 18:31:54 +02:00
|
|
|
public CreateDatasetForm(String idFolderWorkspace, String owner) {
|
2016-05-26 18:12:53 +02:00
|
|
|
initWidget(uiBinder.createAndBindUi(this));
|
2016-05-27 19:08:03 +02:00
|
|
|
|
2016-06-07 17:50:33 +02:00
|
|
|
this.owner = owner;
|
|
|
|
|
2016-06-08 18:31:54 +02:00
|
|
|
// workspace request
|
|
|
|
isWorkspaceRequest = true;
|
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
// bind on events
|
|
|
|
bind();
|
2016-06-06 17:24:52 +02:00
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
// set info block
|
|
|
|
setAlertBlock("Retrieving information, please wait...", AlertType.INFO, true);
|
|
|
|
|
2016-06-09 18:58:19 +02:00
|
|
|
// disable continue button
|
|
|
|
continueButton.setEnabled(false);
|
2016-06-06 17:24:52 +02:00
|
|
|
resetButton.setEnabled(false);
|
2016-05-27 19:08:03 +02:00
|
|
|
|
2016-06-10 12:10:18 +02:00
|
|
|
// set to visible the checkbox to add resources of the workspace
|
|
|
|
resourcesControlGroup.setVisible(true);
|
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
// get back the licenses and the metadata information from the workspace
|
|
|
|
ckanServices.getDatasetBean(idFolderWorkspace, owner, new AsyncCallback<DatasetMetadataBean>() {
|
|
|
|
|
2016-05-26 18:12:53 +02:00
|
|
|
@Override
|
2016-05-27 19:08:03 +02:00
|
|
|
public void onSuccess(DatasetMetadataBean bean) {
|
|
|
|
|
|
|
|
if(bean != null){
|
2016-06-06 17:24:52 +02:00
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
// save it
|
|
|
|
receivedBean = bean;
|
|
|
|
|
|
|
|
// fill the form
|
|
|
|
titleTextBox.setText(bean.getTitle());
|
|
|
|
descriptionTextarea.setText(bean.getDescription());
|
|
|
|
versionTextbox.setText(String.valueOf(bean.getVersion()));
|
|
|
|
authorTextbox.setText(bean.getAuthor());
|
|
|
|
authorEmailTextbox.setText(bean.getAuthorEmail());
|
|
|
|
maintainerTextbox.setText(bean.getMaintainer());
|
|
|
|
maintainerEmailTextbox.setText(bean.getMaintainerEmail());
|
2016-06-08 18:31:54 +02:00
|
|
|
prepareMetadataList(receivedBean);
|
2016-05-27 19:08:03 +02:00
|
|
|
|
2016-06-06 17:24:52 +02:00
|
|
|
// set organizations
|
|
|
|
List<String> organizations = bean.getOrganizationList();
|
|
|
|
|
|
|
|
for (String organization : organizations) {
|
|
|
|
|
|
|
|
organizationsListbox.addItem(organization);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
// retrieve custom fields
|
|
|
|
Map<String, String> customFieldsMap = bean.getCustomFields();
|
|
|
|
|
2016-06-06 17:24:52 +02:00
|
|
|
if(customFieldsMap != null){
|
2016-05-27 19:08:03 +02:00
|
|
|
|
|
|
|
// get the keys and put them as tags
|
|
|
|
Iterator<Entry<String, String>> iteratorOverCustomField = customFieldsMap.entrySet().iterator();
|
|
|
|
|
|
|
|
while (iteratorOverCustomField.hasNext()) {
|
|
|
|
Map.Entry<String, String> entry = (Map.Entry<String, String>) iteratorOverCustomField
|
|
|
|
.next();
|
|
|
|
|
|
|
|
// these are fixed key, variable value custom fields
|
2016-06-06 17:24:52 +02:00
|
|
|
CustomFieldEntry toAdd = new CustomFieldEntry(eventBus, entry.getKey(), entry.getValue(), false);
|
|
|
|
customFieldEntriesList.add(toAdd);
|
2016-05-27 19:08:03 +02:00
|
|
|
customFields.add(toAdd);
|
|
|
|
|
2016-06-06 17:24:52 +02:00
|
|
|
// add as tag
|
|
|
|
addTagElement(entry.getKey());
|
2016-05-27 19:08:03 +02:00
|
|
|
|
|
|
|
}
|
2016-05-26 18:12:53 +02:00
|
|
|
}
|
2016-05-27 19:08:03 +02:00
|
|
|
|
|
|
|
// try to retrieve the licenses
|
|
|
|
setAlertBlock("Retrieving licenses, please wait...", AlertType.INFO, true);
|
|
|
|
ckanServices.getLicenses(new AsyncCallback<LicensesBean>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(LicensesBean lBean) {
|
|
|
|
|
|
|
|
if(lBean != null && !lBean.getLicenses().isEmpty()){
|
|
|
|
|
|
|
|
licenseBean = lBean;
|
|
|
|
|
|
|
|
// fill the listbox
|
|
|
|
for(String license: licenseBean.getLicenses()){
|
|
|
|
|
|
|
|
licenseListbox.addItem(license);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// everything went ok
|
|
|
|
setAlertBlock("", AlertType.ERROR, false);
|
2016-06-09 18:58:19 +02:00
|
|
|
continueButton.setEnabled(true);
|
2016-06-06 17:24:52 +02:00
|
|
|
resetButton.setEnabled(true);
|
2016-05-27 19:08:03 +02:00
|
|
|
|
|
|
|
}else{
|
|
|
|
setAlertBlock("Error while retrieving licenses, try to refresh the page", AlertType.ERROR, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
|
|
|
|
setAlertBlock("Error while retrieving licenses, try to refresh the page", AlertType.ERROR, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
setAlertBlock("Error while retrieving information, try to refresh the page", AlertType.ERROR, true);
|
2016-05-26 18:12:53 +02:00
|
|
|
}
|
2016-05-27 19:08:03 +02:00
|
|
|
|
2016-05-26 18:12:53 +02:00
|
|
|
}
|
2016-05-27 19:08:03 +02:00
|
|
|
|
2016-05-26 18:12:53 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2016-05-27 19:08:03 +02:00
|
|
|
|
|
|
|
setAlertBlock("Error while retrieving information, try to refresh the page", AlertType.ERROR, true);
|
|
|
|
|
2016-05-26 18:12:53 +02:00
|
|
|
}
|
|
|
|
});
|
2016-05-27 19:08:03 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-06-09 18:58:19 +02:00
|
|
|
/**
|
|
|
|
* Add the items to the listbox and put data into the metadataPanel
|
|
|
|
* @param receivedBean
|
|
|
|
*/
|
|
|
|
protected void prepareMetadataList(DatasetMetadataBean receivedBean) {
|
|
|
|
|
|
|
|
List<MetaDataProfileBean> beans = receivedBean.getMetadataList();
|
|
|
|
|
|
|
|
for(MetaDataProfileBean metadataBean: beans){
|
|
|
|
|
|
|
|
metadataProfilesFormatListbox.addItem(metadataBean.getType().getName());
|
|
|
|
|
|
|
|
// add handler on select
|
|
|
|
metadataProfilesFormatListbox.addChangeHandler(new ChangeHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChange(ChangeEvent event) {
|
|
|
|
|
|
|
|
String selectedItem = metadataProfilesFormatListbox.getSelectedItemText();
|
|
|
|
|
|
|
|
if(selectedItem.equals("none")){
|
|
|
|
// hide the panel
|
|
|
|
metadataFieldsPanel.clear();
|
|
|
|
metadataFieldsPanel.setVisible(false);
|
|
|
|
}else{
|
|
|
|
|
|
|
|
metadataFieldsPanel.clear();
|
|
|
|
addFields(selectedItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void addFields(String selectedItem) {
|
|
|
|
|
|
|
|
for(MetaDataProfileBean bean: receivedBean.getMetadataList()){
|
|
|
|
|
|
|
|
if(bean.getType().getName().equals(selectedItem)){
|
|
|
|
|
|
|
|
// prepare the data
|
|
|
|
List<MetadataFieldWrapper> fields = bean.getMetadataFields();
|
|
|
|
|
|
|
|
// clear old data
|
|
|
|
listOfMetadataFields.clear();
|
|
|
|
|
|
|
|
for (MetadataFieldWrapper field : fields) {
|
|
|
|
MetaDataFieldSkeleton fieldWidget = new MetaDataFieldSkeleton(field);
|
|
|
|
metadataFieldsPanel.add(fieldWidget);
|
|
|
|
listOfMetadataFields.add(fieldWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
metadataFieldsPanel.setVisible(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
/**
|
|
|
|
* Bind on events
|
|
|
|
*/
|
|
|
|
private void bind() {
|
|
|
|
|
|
|
|
// when a custom field is removed, remove it from the list
|
|
|
|
eventBus.addHandler(DeleteCustomFieldEvent.TYPE, new DeleteCustomFieldEventHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRemoveEntry(DeleteCustomFieldEvent event) {
|
|
|
|
|
2016-06-06 17:24:52 +02:00
|
|
|
customFieldEntriesList.remove(event.getRemovedEntry());
|
2016-05-27 19:08:03 +02:00
|
|
|
customFields.remove(event.getRemovedEntry());
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-05-26 18:12:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@UiHandler("addCustomFieldButton")
|
|
|
|
void addCustomFieldEvent(ClickEvent e){
|
|
|
|
|
2016-06-06 17:24:52 +02:00
|
|
|
CustomFieldEntry toAdd = new CustomFieldEntry(eventBus, "", "", true);
|
|
|
|
customFieldEntriesList.add(toAdd);
|
2016-05-26 18:12:53 +02:00
|
|
|
customFields.add(toAdd);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-06-09 18:58:19 +02:00
|
|
|
@UiHandler("continueButton")
|
|
|
|
void onContinueButton(ClickEvent e){
|
2016-06-06 17:24:52 +02:00
|
|
|
|
2016-06-08 18:31:54 +02:00
|
|
|
// validate data
|
2016-06-09 18:58:19 +02:00
|
|
|
String errorMsg = validateDataOnContinue();
|
|
|
|
|
|
|
|
if(errorMsg == null){
|
|
|
|
formFirstStep.setVisible(false);
|
|
|
|
formSecondStep.setVisible(true);
|
|
|
|
selectedProfile.setText("Selected Profile is " + metadataProfilesFormatListbox.getSelectedItemText());
|
|
|
|
}else{
|
|
|
|
alertOnContinue("Please check inserted data [" + errorMsg + "]", AlertType.ERROR);
|
|
|
|
}
|
2016-05-27 19:08:03 +02:00
|
|
|
|
2016-06-09 18:58:19 +02:00
|
|
|
}
|
2016-06-08 18:31:54 +02:00
|
|
|
|
2016-06-09 18:58:19 +02:00
|
|
|
@UiHandler("goBackButton")
|
|
|
|
void onGoBackButton(ClickEvent e){
|
2016-06-08 18:31:54 +02:00
|
|
|
|
2016-06-09 18:58:19 +02:00
|
|
|
// swap forms
|
|
|
|
formFirstStep.setVisible(true);
|
|
|
|
formSecondStep.setVisible(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@UiHandler("createButton")
|
|
|
|
void createDatasetEvent(ClickEvent e){
|
|
|
|
|
|
|
|
boolean profileDataValid = areProfileDataValid();
|
|
|
|
|
|
|
|
if(profileDataValid){
|
2016-06-06 17:24:52 +02:00
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
String title = titleTextBox.getValue();
|
|
|
|
String description = descriptionTextarea.getText();
|
|
|
|
String selectedLicense = licenseListbox.getSelectedItemText();
|
2016-06-06 17:24:52 +02:00
|
|
|
String visibility = visibilityListbox.getSelectedItemText();
|
2016-05-27 19:08:03 +02:00
|
|
|
long version = Long.valueOf(versionTextbox.getValue());
|
|
|
|
String author = authorTextbox.getValue();
|
|
|
|
String authorEmail = authorEmailTextbox.getValue();
|
|
|
|
String maintainer = maintainerTextbox.getValue();
|
|
|
|
String maintainerEmail = maintainerEmailTextbox.getValue();
|
2016-06-06 17:24:52 +02:00
|
|
|
String chosenOrganization = organizationsListbox.getSelectedItemText();
|
|
|
|
boolean addResources = addResourcesCheckBox.getValue();
|
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
// fill the bean
|
|
|
|
receivedBean.setAuthor(author);
|
|
|
|
receivedBean.setAuthorEmail(authorEmail);
|
|
|
|
receivedBean.setDescription(description);
|
|
|
|
receivedBean.setLicense(selectedLicense);
|
|
|
|
receivedBean.setMaintainer(maintainer);
|
|
|
|
receivedBean.setMaintainerEmail(maintainerEmail);
|
|
|
|
receivedBean.setVersion(version);
|
|
|
|
receivedBean.setVisibility(visibility.equals("Public"));
|
|
|
|
receivedBean.setTitle(title);
|
|
|
|
receivedBean.setTags(tagsList);
|
2016-06-06 17:24:52 +02:00
|
|
|
receivedBean.setSelectedOrganization(chosenOrganization);
|
|
|
|
receivedBean.setAddResources(addResources);
|
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
Map<String, String> customFieldsMap = new HashMap<String, String>();
|
2016-06-06 17:24:52 +02:00
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
// prepare custom fields
|
2016-06-09 18:58:19 +02:00
|
|
|
for (MetaDataFieldSkeleton field : listOfMetadataFields) {
|
|
|
|
|
|
|
|
customFieldsMap.put(field.getFieldName(), field.getFieldCurrentValue());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-06-06 17:24:52 +02:00
|
|
|
for(CustomFieldEntry customEntry : customFieldEntriesList){
|
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
String key = customEntry.getKey();
|
|
|
|
String value = customEntry.getValue();
|
|
|
|
customFieldsMap.put(key, value);
|
|
|
|
|
|
|
|
}
|
2016-06-06 17:24:52 +02:00
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
receivedBean.setCustomFields(customFieldsMap);
|
2016-06-13 18:29:57 +02:00
|
|
|
|
|
|
|
// alert
|
|
|
|
alertOnCreate("Trying to create dataset, please wait", AlertType.INFO);
|
2016-06-06 17:24:52 +02:00
|
|
|
|
|
|
|
// invoke the create method
|
|
|
|
createButton.setEnabled(false);
|
2016-06-09 18:58:19 +02:00
|
|
|
goBackButton.setEnabled(false);
|
2016-06-06 17:24:52 +02:00
|
|
|
|
2016-06-10 12:10:18 +02:00
|
|
|
ckanServices.createCKanDataset(receivedBean, isWorkspaceRequest, new AsyncCallback<DatasetMetadataBean>() {
|
2016-06-06 17:24:52 +02:00
|
|
|
|
|
|
|
@Override
|
2016-06-10 12:10:18 +02:00
|
|
|
public void onSuccess(final DatasetMetadataBean createdDatasetBean) {
|
2016-06-06 17:24:52 +02:00
|
|
|
|
2016-06-10 12:10:18 +02:00
|
|
|
if(createdDatasetBean != null){
|
2016-06-06 17:24:52 +02:00
|
|
|
|
|
|
|
alertOnCreate("Dataset correctly created!", AlertType.SUCCESS);
|
|
|
|
|
2016-06-07 17:50:33 +02:00
|
|
|
// disable dataset fields
|
|
|
|
disableDatasetFields();
|
2016-06-10 17:16:42 +02:00
|
|
|
|
2016-06-10 12:30:54 +02:00
|
|
|
// disable reset
|
|
|
|
resetButton.setEnabled(false);
|
2016-06-07 17:50:33 +02:00
|
|
|
|
2016-06-10 12:10:18 +02:00
|
|
|
// show the go to dataset button
|
|
|
|
final String datasetUrl = createdDatasetBean.getSource();
|
|
|
|
goToDatasetButton.setVisible(true);
|
|
|
|
goToDatasetButton.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
|
2016-06-13 17:40:19 +02:00
|
|
|
String currentPath = Window.Location.getHref();
|
|
|
|
int datasetIndex = datasetUrl.indexOf("/dataset");
|
|
|
|
if(datasetIndex == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
String finalPart = datasetUrl.substring(datasetIndex);
|
2016-06-13 18:21:15 +02:00
|
|
|
String finalPath = currentPath + "?" + Encoder.encode("goDataset") + "=" + Encoder.encode(finalPart);
|
2016-06-13 17:40:19 +02:00
|
|
|
Window.Location.assign(finalPath);
|
2016-06-10 12:10:18 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-07 17:50:33 +02:00
|
|
|
// if we are in the "general case" we need to show a form for adding resources
|
2016-06-10 12:10:18 +02:00
|
|
|
if(isWorkspaceRequest)
|
|
|
|
{
|
|
|
|
|
|
|
|
// leave to back button, but remove create and add go to dataset
|
|
|
|
createButton.removeFromParent();
|
2016-06-10 17:16:42 +02:00
|
|
|
|
2016-06-10 12:10:18 +02:00
|
|
|
// set go to dataset as primary
|
|
|
|
goToDatasetButton.setType(ButtonType.PRIMARY);
|
2016-06-10 17:16:42 +02:00
|
|
|
|
2016-06-10 12:10:18 +02:00
|
|
|
}else{
|
2016-06-07 17:50:33 +02:00
|
|
|
|
2016-06-10 12:10:18 +02:00
|
|
|
// remove create button
|
|
|
|
createButton.removeFromParent();
|
2016-06-07 17:50:33 +02:00
|
|
|
|
|
|
|
// show the add resources button
|
|
|
|
addResourcesButton.setVisible(true);
|
2016-06-10 12:10:18 +02:00
|
|
|
|
2016-06-07 17:50:33 +02:00
|
|
|
addResourcesButton.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
|
2016-06-10 12:10:18 +02:00
|
|
|
// remove content of the main panel
|
|
|
|
createDatasetMainPanel.clear();
|
2016-06-07 17:50:33 +02:00
|
|
|
|
|
|
|
// TabPanel
|
|
|
|
tabPanel = new TabPanel(Tabs.ABOVE);
|
|
|
|
tabPanel.setWidth("100%");
|
|
|
|
|
|
|
|
// add the form
|
2016-06-10 12:30:54 +02:00
|
|
|
resourceForm = new AddResourceToDataset(eventBus, createdDatasetBean.getId(), owner, datasetUrl);
|
2016-06-07 17:50:33 +02:00
|
|
|
|
|
|
|
// tab for the form
|
|
|
|
Tab formContainer = new Tab();
|
|
|
|
formContainer.add(resourceForm);
|
|
|
|
formContainer.setHeading("Add New Resource");
|
|
|
|
tabPanel.add(formContainer);
|
|
|
|
|
|
|
|
// tab for the added resources
|
|
|
|
Tab addedResources = new Tab();
|
2016-06-08 18:31:54 +02:00
|
|
|
addedResources.add(new AddedResourcesSummary(eventBus, owner));
|
2016-06-07 17:50:33 +02:00
|
|
|
addedResources.setHeading("Added Resource");
|
|
|
|
tabPanel.add(addedResources);
|
2016-06-08 18:31:54 +02:00
|
|
|
|
2016-06-07 17:50:33 +02:00
|
|
|
// add tabs to resources panel
|
|
|
|
tabPanel.selectTab(0);
|
|
|
|
|
2016-06-10 12:10:18 +02:00
|
|
|
|
|
|
|
// form container
|
|
|
|
AddResourceContainer container = new AddResourceContainer(datasetUrl);
|
|
|
|
container.add(tabPanel);
|
|
|
|
|
|
|
|
// add the new content of the main panel
|
|
|
|
createDatasetMainPanel.add(container);
|
2016-06-07 17:50:33 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-06-06 17:24:52 +02:00
|
|
|
}else{
|
|
|
|
|
2016-06-10 12:30:54 +02:00
|
|
|
alertOnCreate("Unable to create this dataset, maybe it already exists?", AlertType.ERROR);
|
2016-06-06 17:24:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
|
2016-06-10 12:30:54 +02:00
|
|
|
alertOnCreate("Unable to create this dataset, maybe it already exists?", AlertType.ERROR);
|
2016-06-06 17:24:52 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2016-06-09 18:58:19 +02:00
|
|
|
}else{
|
|
|
|
|
2016-06-10 12:10:18 +02:00
|
|
|
alertOnCreate("Please check the inserted values and the mandatory fields", AlertType.ERROR);
|
2016-06-09 18:58:19 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if profile data are valid
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private boolean areProfileDataValid() {
|
|
|
|
|
|
|
|
for (MetaDataFieldSkeleton field : listOfMetadataFields) {
|
|
|
|
|
|
|
|
if(!field.isFieldValueValid())
|
|
|
|
return false;
|
2016-05-27 19:08:03 +02:00
|
|
|
}
|
2016-06-09 18:58:19 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On continue show alert box and enable buttons
|
|
|
|
* @param text
|
|
|
|
* @param type
|
|
|
|
*/
|
|
|
|
private void alertOnContinue(String text, AlertType type){
|
|
|
|
|
|
|
|
onContinueAlertBlock.setText(text);
|
|
|
|
onContinueAlertBlock.setType(type);
|
|
|
|
onContinueAlertBlock.setVisible(true);
|
|
|
|
continueButton.setEnabled(true);
|
|
|
|
resetButton.setEnabled(true);
|
|
|
|
|
|
|
|
// hide after some seconds
|
|
|
|
Timer t = new Timer() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
onContinueAlertBlock.setVisible(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
t.schedule(4000);
|
2016-06-06 17:24:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-06-09 18:58:19 +02:00
|
|
|
* On continue show alert box and enable buttons
|
2016-06-06 17:24:52 +02:00
|
|
|
* @param text
|
|
|
|
* @param type
|
|
|
|
*/
|
|
|
|
private void alertOnCreate(String text, AlertType type){
|
|
|
|
|
|
|
|
onCreateAlertBlock.setText(text);
|
|
|
|
onCreateAlertBlock.setType(type);
|
|
|
|
onCreateAlertBlock.setVisible(true);
|
|
|
|
createButton.setEnabled(true);
|
2016-06-09 18:58:19 +02:00
|
|
|
goBackButton.setEnabled(true);
|
2016-05-26 18:12:53 +02:00
|
|
|
|
2016-06-06 17:24:52 +02:00
|
|
|
// hide after some seconds
|
|
|
|
Timer t = new Timer() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
onCreateAlertBlock.setVisible(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-09 18:58:19 +02:00
|
|
|
t.schedule(4000);
|
2016-05-27 19:08:03 +02:00
|
|
|
}
|
2016-05-26 18:12:53 +02:00
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
/**
|
|
|
|
* Validate data
|
2016-06-08 18:31:54 +02:00
|
|
|
* @return true on success, false otherwise
|
2016-05-27 19:08:03 +02:00
|
|
|
*/
|
2016-06-09 18:58:19 +02:00
|
|
|
private String validateDataOnContinue() {
|
|
|
|
|
|
|
|
String errorMessage = null;
|
|
|
|
|
|
|
|
if(titleTextBox.getText().isEmpty()){
|
|
|
|
errorMessage = "Missing title";
|
|
|
|
return errorMessage;
|
|
|
|
}
|
2016-06-10 17:16:42 +02:00
|
|
|
|
2016-06-10 12:10:18 +02:00
|
|
|
// name reg expression
|
|
|
|
String regexName = "^[a-zA-Z\\s]+";
|
|
|
|
if(!validateByRegExpression(maintainerTextbox.getText(), regexName)){
|
2016-06-10 17:16:42 +02:00
|
|
|
errorMessage = "Not valid maintainer name";
|
2016-06-10 12:10:18 +02:00
|
|
|
return errorMessage;
|
|
|
|
}
|
2016-06-08 18:31:54 +02:00
|
|
|
|
|
|
|
// email reg expression
|
|
|
|
String regexMail = "\\b[\\w.%-]+@[-.\\w]+\\.[A-Za-z]{2,4}\\b";
|
2016-06-09 18:58:19 +02:00
|
|
|
if(!validateByRegExpression(maintainerEmailTextbox.getText(), regexMail)){
|
|
|
|
errorMessage = "Not valid maintainer email";
|
|
|
|
return errorMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if metadata profile is different from none and its mandatory fields have been fulfilled
|
|
|
|
if(checkSelectedMetaDataProfile()){
|
|
|
|
errorMessage = "You must select a metadata profile different frome none";
|
|
|
|
}
|
2016-06-13 17:40:19 +02:00
|
|
|
|
2016-06-10 18:06:31 +02:00
|
|
|
if(organizationsListbox.getSelectedItemText() == null){
|
|
|
|
errorMessage = "You must select an organization in which you want to publish";
|
|
|
|
}
|
2016-06-09 18:58:19 +02:00
|
|
|
|
|
|
|
return errorMessage;
|
2016-05-26 18:12:53 +02:00
|
|
|
}
|
|
|
|
|
2016-06-09 18:58:19 +02:00
|
|
|
/**
|
|
|
|
* Checks if a metadata profile has been chosen and its fields have been fulfilled
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private boolean checkSelectedMetaDataProfile() {
|
|
|
|
return metadataProfilesFormatListbox.getSelectedItemText().equals("none");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate a text against a regular expression.
|
|
|
|
* @param textToValidate
|
|
|
|
* @param regex
|
|
|
|
* @return
|
|
|
|
*/
|
2016-06-08 18:31:54 +02:00
|
|
|
private boolean validateByRegExpression(String textToValidate, String regex){
|
2016-06-10 12:10:18 +02:00
|
|
|
return textToValidate.matches(regex);
|
2016-06-08 18:31:54 +02:00
|
|
|
}
|
2016-06-09 18:58:19 +02:00
|
|
|
|
2016-05-26 18:12:53 +02:00
|
|
|
@UiHandler("resetButton")
|
|
|
|
void resetFormEvent(ClickEvent e){
|
|
|
|
|
|
|
|
// reset main fields
|
|
|
|
titleTextBox.setText("");
|
|
|
|
descriptionTextarea.setText("");
|
|
|
|
versionTextbox.setText("");
|
|
|
|
maintainerTextbox.setText("");
|
|
|
|
maintainerEmailTextbox.setText("");
|
2016-05-27 19:08:03 +02:00
|
|
|
removeTags();
|
2016-05-26 18:12:53 +02:00
|
|
|
|
|
|
|
// delete custom fields
|
2016-06-06 17:24:52 +02:00
|
|
|
for (CustomFieldEntry customField : customFieldEntriesList) {
|
2016-05-26 18:12:53 +02:00
|
|
|
customField.removeFromParent();
|
|
|
|
}
|
2016-06-06 17:24:52 +02:00
|
|
|
customFieldEntriesList.clear();
|
2016-05-27 19:08:03 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-06-07 17:50:33 +02:00
|
|
|
/**
|
2016-06-08 18:31:54 +02:00
|
|
|
* Disable dataset editable fields once the dataset has been
|
|
|
|
* Successfully created.
|
2016-06-07 17:50:33 +02:00
|
|
|
*/
|
|
|
|
protected void disableDatasetFields() {
|
2016-06-08 18:31:54 +02:00
|
|
|
|
2016-06-07 17:50:33 +02:00
|
|
|
titleTextBox.setEnabled(false);
|
|
|
|
descriptionTextarea.setEnabled(false);
|
|
|
|
versionTextbox.setEnabled(false);
|
|
|
|
maintainerTextbox.setEnabled(false);
|
|
|
|
maintainerEmailTextbox.setEnabled(false);
|
|
|
|
visibilityListbox.setEnabled(false);
|
|
|
|
tagsEnterTextBox.setEnabled(false);
|
|
|
|
licenseListbox.setEnabled(false);
|
|
|
|
organizationsListbox.setEnabled(false);
|
|
|
|
addCustomFieldButton.setEnabled(false);
|
2016-06-08 18:31:54 +02:00
|
|
|
|
|
|
|
// freeze tags
|
|
|
|
for(int i = 0; i < tagsList.size(); i++){
|
|
|
|
|
|
|
|
// get tag widget
|
|
|
|
ListItem tagWidget = (ListItem)tagsPanel.getWidget(i);
|
|
|
|
|
|
|
|
// get the "x" span
|
|
|
|
tagWidget.getWidget(1).removeFromParent();
|
|
|
|
|
|
|
|
}
|
2016-06-09 18:58:19 +02:00
|
|
|
|
|
|
|
// disable profile fields
|
|
|
|
for (MetaDataFieldSkeleton field : listOfMetadataFields) {
|
|
|
|
|
|
|
|
field.freeze();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-06-07 17:50:33 +02:00
|
|
|
}
|
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
/**
|
|
|
|
* change alert block behavior.
|
|
|
|
* @param textToShow
|
|
|
|
* @param type
|
|
|
|
* @param visible
|
|
|
|
*/
|
|
|
|
private void setAlertBlock(String textToShow, AlertType type, boolean visible){
|
|
|
|
|
|
|
|
infoBlock.setText(textToShow);
|
|
|
|
infoBlock.setType(type);
|
|
|
|
infoBlock.setVisible(visible);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@UiHandler("tagsEnterTextBox")
|
|
|
|
void onAddTag(KeyDownEvent event){
|
|
|
|
|
|
|
|
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
|
|
|
|
if (!"".equals(tagsEnterTextBox.getValue().trim())) {
|
|
|
|
|
|
|
|
addTagElement(tagsEnterTextBox);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the tag as an element
|
|
|
|
*/
|
|
|
|
private void addTagElement(TextBox itemBox){
|
|
|
|
|
|
|
|
if (itemBox.getValue() != null && !"".equals(itemBox.getValue().trim())) {
|
|
|
|
|
|
|
|
if(tagsList.contains(itemBox.getValue()))
|
|
|
|
return;
|
|
|
|
|
2016-06-10 17:16:42 +02:00
|
|
|
// ckan accepts only alphanumeric values
|
|
|
|
if(!itemBox.getValue().matches("^[a-zA-Z0-9]*$"))
|
|
|
|
return;
|
2016-06-13 17:40:19 +02:00
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
final String value = itemBox.getValue();
|
|
|
|
final ListItem displayItem = new ListItem();
|
|
|
|
displayItem.setStyleName("tag-style");
|
2016-06-08 18:31:54 +02:00
|
|
|
Span tagText = new Span(itemBox.getValue());
|
2016-05-27 19:08:03 +02:00
|
|
|
|
2016-06-08 18:31:54 +02:00
|
|
|
Span tagRemove = new Span("x");
|
|
|
|
tagRemove.setTitle("Remove this tag");
|
|
|
|
tagRemove.addClickHandler(new ClickHandler() {
|
2016-05-27 19:08:03 +02:00
|
|
|
public void onClick(ClickEvent clickEvent) {
|
2016-06-08 18:31:54 +02:00
|
|
|
removeTag(displayItem, value);
|
2016-05-27 19:08:03 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-08 18:31:54 +02:00
|
|
|
tagRemove.setStyleName("tag-style-x");
|
|
|
|
displayItem.add(tagText);
|
|
|
|
displayItem.add(tagRemove);
|
2016-05-27 19:08:03 +02:00
|
|
|
itemBox.setValue("");
|
|
|
|
itemBox.setFocus(true);
|
|
|
|
tagsPanel.add(displayItem);
|
|
|
|
tagsList.add(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-06 17:24:52 +02:00
|
|
|
/**
|
|
|
|
* Add the tag as an element
|
|
|
|
*/
|
|
|
|
private void addTagElement(final String tag){
|
|
|
|
|
|
|
|
if(tagsList.contains(tag))
|
|
|
|
return;
|
|
|
|
|
|
|
|
final ListItem displayItem = new ListItem();
|
|
|
|
displayItem.setStyleName("tag-style");
|
|
|
|
Span p = new Span(tag);
|
|
|
|
|
|
|
|
Span span = new Span("x");
|
|
|
|
span.setTitle("Remove this tag");
|
|
|
|
span.addClickHandler(new ClickHandler() {
|
|
|
|
public void onClick(ClickEvent clickEvent) {
|
2016-06-08 18:31:54 +02:00
|
|
|
removeTag(displayItem, tag);
|
2016-06-06 17:24:52 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
span.setStyleName("tag-style-x");
|
|
|
|
displayItem.add(p);
|
|
|
|
displayItem.add(span);
|
|
|
|
tagsPanel.add(displayItem);
|
|
|
|
tagsList.add(tag);
|
|
|
|
}
|
2016-05-27 19:08:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a tag from the list
|
|
|
|
* @param displayItem
|
|
|
|
*/
|
2016-06-08 18:31:54 +02:00
|
|
|
private void removeTag(ListItem displayItem, String value) {
|
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
tagsList.remove(value);
|
|
|
|
tagsPanel.remove(displayItem);
|
2016-06-08 18:31:54 +02:00
|
|
|
|
2016-05-27 19:08:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove all inserted tags
|
|
|
|
*/
|
|
|
|
private void removeTags(){
|
|
|
|
|
|
|
|
tagsList.clear();
|
|
|
|
tagsPanel.clear();
|
|
|
|
|
2016-05-26 18:12:53 +02:00
|
|
|
}
|
|
|
|
}
|