2016-05-26 18:12:53 +02:00
|
|
|
package org.gcube.portlets.widgets.ckandatapublisherwidget.client;
|
|
|
|
|
2016-09-14 16:29:52 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2016-06-08 18:31:54 +02:00
|
|
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.CreateDatasetForm;
|
2016-09-14 16:29:52 +02:00
|
|
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.MetaDataFieldSkeleton;
|
2016-10-22 17:29:59 +02:00
|
|
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DataType;
|
2016-09-14 16:29:52 +02:00
|
|
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper;
|
2016-05-26 18:12:53 +02:00
|
|
|
|
2016-09-14 16:29:52 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
2016-11-17 14:08:22 +01:00
|
|
|
import com.github.gwtbootstrap.client.ui.ListBox;
|
2016-05-26 18:12:53 +02:00
|
|
|
import com.google.gwt.core.client.EntryPoint;
|
2016-09-14 16:29:52 +02:00
|
|
|
import com.google.gwt.core.shared.GWT;
|
2016-11-17 14:08:22 +01:00
|
|
|
import com.google.gwt.dom.client.SelectElement;
|
2016-09-14 16:29:52 +02:00
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
2016-07-14 12:16:39 +02:00
|
|
|
import com.google.gwt.event.shared.HandlerManager;
|
2016-09-14 16:29:52 +02:00
|
|
|
import com.google.gwt.user.client.Window;
|
2016-05-26 18:12:53 +02:00
|
|
|
import com.google.gwt.user.client.ui.RootPanel;
|
2016-09-14 16:29:52 +02:00
|
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
2016-05-26 18:12:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Entry point classes define <code>onModuleLoad()</code>.
|
|
|
|
*/
|
|
|
|
public class CKanMetadataPublisher implements EntryPoint {
|
|
|
|
|
2016-09-14 16:29:52 +02:00
|
|
|
private HandlerManager eventBus = new HandlerManager(null);
|
|
|
|
|
2016-11-09 19:13:39 +01:00
|
|
|
// Create a remote service proxy to talk to the server-side ckan service.
|
|
|
|
public static final CKanPublisherServiceAsync ckanServices = GWT.create(CKanPublisherService.class);
|
|
|
|
|
2016-05-26 18:12:53 +02:00
|
|
|
/**
|
|
|
|
* This is the entry point method.
|
|
|
|
*/
|
|
|
|
public void onModuleLoad() {
|
|
|
|
|
|
|
|
// remove comment to the below line for testing the widget
|
2016-11-16 10:25:35 +01:00
|
|
|
//startExample();
|
2016-11-06 22:02:59 +01:00
|
|
|
//testMetadata();
|
|
|
|
//testSelectionPanel();
|
2016-11-17 14:08:22 +01:00
|
|
|
//testHideOption();
|
|
|
|
}
|
2016-11-06 22:02:59 +01:00
|
|
|
|
2016-11-17 14:08:22 +01:00
|
|
|
@SuppressWarnings("unused")
|
|
|
|
private void testHideOption() {
|
|
|
|
|
|
|
|
ListBox listBox = new ListBox(true);
|
|
|
|
listBox.addItem("A");
|
|
|
|
listBox.addItem("B");
|
|
|
|
listBox.addItem("C");
|
|
|
|
listBox.addItem("D");
|
|
|
|
listBox.addItem("E");
|
|
|
|
listBox.addItem("F");
|
|
|
|
|
|
|
|
List<String> toHide = new ArrayList<String>();
|
|
|
|
toHide.add("A");
|
|
|
|
toHide.add("D");
|
|
|
|
|
|
|
|
RootPanel.get("ckan-metadata-publisher-div").add(listBox);
|
|
|
|
SelectElement se = listBox.getElement().cast();
|
|
|
|
|
|
|
|
// hide
|
|
|
|
for (int i = 0; i < listBox.getItemCount(); i++) {
|
|
|
|
if(toHide.contains(listBox.getItemText(i))){
|
|
|
|
GWT.log("to hide " + listBox.getItemText(i));
|
|
|
|
se.getOptions().getItem(i).getStyle().setProperty("display", "none");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-06 22:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
private void testSelectionPanel() {
|
|
|
|
|
2016-11-09 19:13:39 +01:00
|
|
|
// List<ResourceElementBean> listLeft = new ArrayList<ResourceElementBean>();
|
|
|
|
// listLeft.add(new ResourceElementBean(null, "File A", false, null, "File A"));
|
|
|
|
// listLeft.add(new ResourceElementBean(null, "File B", false, null, "File B"));
|
|
|
|
// listLeft.add(new ResourceElementBean(null, "File C", false, null, "File C"));
|
|
|
|
// listLeft.add(new ResourceElementBean(null, "File D", false, null, "File D"));
|
|
|
|
// listLeft.add(new ResourceElementBean(null, "File E", false, null, "File E"));
|
|
|
|
// listLeft.add(new ResourceElementBean(null, "File F", false, null, "File F"));
|
|
|
|
// listLeft.add(new ResourceElementBean(null, "File G", false, null, "File G"));
|
|
|
|
// listLeft.add(new ResourceElementBean(null, "File H", false, null, "File H"));
|
|
|
|
// listLeft.add(new ResourceElementBean(null, "File I", false, null, "File I"));
|
|
|
|
//
|
|
|
|
// // test with folder and childs
|
|
|
|
// ArrayList<ResourceElementBean> childrenOfA = new ArrayList<ResourceElementBean>();
|
|
|
|
// ArrayList<ResourceElementBean> childrenOfW = new ArrayList<ResourceElementBean>();
|
|
|
|
//
|
|
|
|
// ResourceElementBean elementA = new ResourceElementBean(null, "Folder A", true, childrenOfA, "Folder A");
|
|
|
|
// childrenOfA.add(new ResourceElementBean(elementA, "File X", false, null, "Folder A:File X"));
|
|
|
|
// childrenOfA.add(new ResourceElementBean(elementA, "File Y", false, null, "Folder A:File Y"));
|
|
|
|
// childrenOfA.add(new ResourceElementBean(elementA, "File Z", false, null, "Folder A:File Z"));
|
|
|
|
// childrenOfA.add(new ResourceElementBean(elementA, "File V", false, null, "Folder A:File V"));
|
|
|
|
// ResourceElementBean elementW = new ResourceElementBean(elementA, "Folder W", true, childrenOfW, "Folder A:File W");
|
|
|
|
// childrenOfA.add(elementW);
|
|
|
|
// childrenOfW.add(new ResourceElementBean(elementW, "File J", false, null, "Folder A:File W: File J"));
|
|
|
|
// listLeft.add(elementA);
|
2016-11-14 17:07:03 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
|
2016-11-17 14:08:22 +01:00
|
|
|
// String folderId = "e87bfc7d-4fb0-4795-9c79-0c495500ca9c";
|
|
|
|
// ckanServices.getTreeFolder(folderId, new AsyncCallback<ResourceElementBean>() {
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public void onSuccess(ResourceElementBean result) {
|
|
|
|
// if(result != null){
|
|
|
|
// RootPanel.get("ckan-metadata-publisher-div").add(new TwinColumnSelectionMainPanel(result));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public void onFailure(Throwable caught) {
|
|
|
|
//
|
|
|
|
// Window.alert("Failed to retrieve ResourceElementBean");
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
// });
|
2016-09-14 16:29:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
private void testMetadata() {
|
|
|
|
|
|
|
|
VerticalPanel panel = new VerticalPanel();
|
|
|
|
panel.setWidth("95%");
|
|
|
|
RootPanel.get("ckan-metadata-publisher-div").add(panel);
|
|
|
|
|
|
|
|
// prepare the data
|
|
|
|
List<MetadataFieldWrapper> fields = new ArrayList<MetadataFieldWrapper>();
|
|
|
|
|
|
|
|
// checkbox
|
|
|
|
//fields.add(new MetadataFieldWrapper("CheckBox", true, DataType.Boolean, "false", "Checkbox example", null, null));
|
|
|
|
|
|
|
|
// number
|
|
|
|
//fields.add(new MetadataFieldWrapper("Number", true, DataType.Number, "52", "Number example", null, null));
|
|
|
|
|
|
|
|
// other number
|
|
|
|
//fields.add(new MetadataFieldWrapper("Number2", true, DataType.Number, null, "Number example 2", null, "[0-9]+"));
|
|
|
|
|
|
|
|
// other number
|
|
|
|
//fields.add(new MetadataFieldWrapper("Number3", false, DataType.Number, null, "Number example 3", null, "[0-9]+"));
|
|
|
|
|
|
|
|
// text area
|
|
|
|
//fields.add(new MetadataFieldWrapper("Text Area", false, DataType.Text, "This is the default value", "Text Area", null, "^#\\w+\\.$"));
|
|
|
|
|
|
|
|
// textbox
|
2016-10-21 19:01:59 +02:00
|
|
|
// fields.add(new MetadataFieldWrapper("TextBox", true, DataType.String, null, "TextBox", null, "^#\\w+\\.$"));
|
2016-09-14 16:29:52 +02:00
|
|
|
|
|
|
|
// listbox
|
2016-10-21 19:01:59 +02:00
|
|
|
// fields.add(new MetadataFieldWrapper("ListBox", true, DataType.String, "prova4", "ListBox", Arrays.asList("prova1", "prova2", "prova3"), null));
|
2016-09-14 16:29:52 +02:00
|
|
|
|
|
|
|
// single date
|
2016-10-21 19:01:59 +02:00
|
|
|
// fields.add(new MetadataFieldWrapper("Single date", true, DataType.Time, null, "Single date", null, null));
|
2016-09-14 16:29:52 +02:00
|
|
|
|
|
|
|
// single date
|
2016-10-21 19:01:59 +02:00
|
|
|
// fields.add(new MetadataFieldWrapper("Single date 2", true, DataType.Time, "2045-12-01 21:32", "Single date 2", null, null));
|
2016-09-14 16:29:52 +02:00
|
|
|
|
|
|
|
// time interval
|
2016-10-21 19:01:59 +02:00
|
|
|
// fields.add(new MetadataFieldWrapper("Time interval 1", false, DataType.Time_Interval, "2045-12-01 21:32/2045-12-01 21:32", "Time interval 1", null, null));
|
2016-09-14 16:29:52 +02:00
|
|
|
|
|
|
|
// time interval
|
2016-10-21 19:01:59 +02:00
|
|
|
// fields.add(new MetadataFieldWrapper("Time interval 2", true, DataType.Time_Interval, null, "Time interval 2", null, null));
|
2016-09-14 16:29:52 +02:00
|
|
|
|
|
|
|
// time interval
|
2016-10-21 19:01:59 +02:00
|
|
|
// fields.add(new MetadataFieldWrapper("Time intervals 2", true, DataType.Time_Interval, null, "Time intervals 2", null, null));
|
2016-09-14 16:29:52 +02:00
|
|
|
|
|
|
|
// time interval lists
|
2016-10-22 17:29:59 +02:00
|
|
|
fields.add(new MetadataFieldWrapper("Time intervals 2", false, DataType.Times_ListOf, "2010-10-12 15:23", "Time intervals 2", null, null));
|
2016-09-14 16:29:52 +02:00
|
|
|
|
|
|
|
final ArrayList<MetaDataFieldSkeleton> widgetsList = new ArrayList<MetaDataFieldSkeleton>();
|
|
|
|
for (MetadataFieldWrapper metadataFieldWrapper : fields) {
|
|
|
|
MetaDataFieldSkeleton widget;
|
|
|
|
try {
|
|
|
|
widget = new MetaDataFieldSkeleton(metadataFieldWrapper, eventBus);
|
|
|
|
widgetsList.add(widget);
|
|
|
|
panel.add(widget);
|
|
|
|
} catch (Exception e) {
|
|
|
|
GWT.log("Error!", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Button validator = new Button("Validate");
|
|
|
|
panel.add(validator);
|
|
|
|
|
|
|
|
validator.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
|
|
|
|
for (MetaDataFieldSkeleton field : widgetsList) {
|
|
|
|
String error = field.isFieldValueValid();
|
2016-10-21 19:01:59 +02:00
|
|
|
if(error != null)
|
2016-09-14 16:29:52 +02:00
|
|
|
Window.alert(field.getFieldName() + " is not valid. Suggestion: " + error);
|
2016-10-21 19:01:59 +02:00
|
|
|
else
|
|
|
|
Window.alert("No ERROR: " + field.getFieldCurrentValue());
|
2016-09-14 16:29:52 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-05-26 18:12:53 +02:00
|
|
|
|
2016-10-21 19:01:59 +02:00
|
|
|
Button freezeAll = new Button("Freeze");
|
|
|
|
panel.add(freezeAll);
|
|
|
|
|
|
|
|
freezeAll.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
for (MetaDataFieldSkeleton field : widgetsList)
|
|
|
|
field.freeze();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-05-26 18:12:53 +02:00
|
|
|
}
|
2016-09-12 18:00:00 +02:00
|
|
|
|
2016-05-26 18:12:53 +02:00
|
|
|
|
2016-06-13 11:02:53 +02:00
|
|
|
@SuppressWarnings("unused")
|
2016-05-26 18:12:53 +02:00
|
|
|
private void startExample() {
|
2016-09-12 18:00:00 +02:00
|
|
|
|
2016-11-14 17:07:03 +01:00
|
|
|
String idFolderWorkspace = "e87bfc7d-4fb0-4795-9c79-0c495500ca9c";
|
2016-09-14 16:29:52 +02:00
|
|
|
String owner = "costantino.perciante";
|
2016-09-23 18:50:16 +02:00
|
|
|
RootPanel.get("ckan-metadata-publisher-div").add(new CreateDatasetForm(idFolderWorkspace, eventBus));
|
2016-05-26 18:12:53 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|