2018-05-04 12:16:27 +02:00
|
|
|
package org.gcube.portlets.widgets.wstaskexecutor.client.view.binder;
|
|
|
|
|
|
|
|
|
2018-05-08 12:23:11 +02:00
|
|
|
import java.util.ArrayList;
|
2018-05-04 12:16:27 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2018-05-08 12:23:11 +02:00
|
|
|
import org.gcube.common.workspacetaskexecutor.shared.TaskParameter;
|
|
|
|
import org.gcube.common.workspacetaskexecutor.shared.TaskParameterType;
|
2018-05-04 12:16:27 +02:00
|
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.WsTaskExecutorWidget;
|
2018-05-08 12:23:11 +02:00
|
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.event.DeleteCustomFieldEvent;
|
|
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.event.DeleteCustomFieldEventHandler;
|
2018-05-04 12:16:27 +02:00
|
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.view.FormatUtil;
|
|
|
|
import org.gcube.portlets.widgets.wstaskexecutor.shared.GcubeScope;
|
2018-05-08 12:23:11 +02:00
|
|
|
import org.gcube.portlets.widgets.wstaskexecutor.shared.WsFolder;
|
2018-05-04 12:16:27 +02:00
|
|
|
|
2018-05-08 12:23:11 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
2018-05-04 12:16:27 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.ControlGroup;
|
2018-05-08 12:23:11 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.Controls;
|
|
|
|
import com.github.gwtbootstrap.client.ui.Form;
|
2018-05-04 12:16:27 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.ListBox;
|
|
|
|
import com.github.gwtbootstrap.client.ui.Pager;
|
|
|
|
import com.github.gwtbootstrap.client.ui.TextBox;
|
|
|
|
import com.github.gwtbootstrap.client.ui.constants.ControlGroupType;
|
|
|
|
import com.google.gwt.core.client.GWT;
|
|
|
|
import com.google.gwt.dom.client.Document;
|
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
|
import com.google.gwt.event.dom.client.DomEvent;
|
2018-05-08 12:23:11 +02:00
|
|
|
import com.google.gwt.event.shared.HandlerManager;
|
2018-05-04 12:16:27 +02:00
|
|
|
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
|
import com.google.gwt.uibinder.client.UiField;
|
2018-05-08 12:23:11 +02:00
|
|
|
import com.google.gwt.uibinder.client.UiHandler;
|
2018-05-04 12:16:27 +02:00
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class CreateTaskConfigurationView.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
* May 4, 2018
|
|
|
|
*/
|
|
|
|
public abstract class CreateTaskConfigurationView extends Composite {
|
|
|
|
|
|
|
|
/** The ui binder. */
|
|
|
|
private static CreateTaskConfigurationViewUiBinder uiBinder =
|
|
|
|
GWT.create(CreateTaskConfigurationViewUiBinder.class);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Interface CreateTaskConfigurationViewUiBinder.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
* May 4, 2018
|
|
|
|
*/
|
|
|
|
interface CreateTaskConfigurationViewUiBinder
|
|
|
|
extends UiBinder<Widget, CreateTaskConfigurationView> {
|
|
|
|
}
|
|
|
|
|
|
|
|
/** The pager. */
|
|
|
|
@UiField
|
|
|
|
Pager pager;
|
|
|
|
|
|
|
|
|
|
|
|
@UiField
|
|
|
|
ListBox field_select_scope;
|
|
|
|
|
|
|
|
@UiField
|
|
|
|
ControlGroup cg_input_task_id;
|
|
|
|
|
|
|
|
@UiField
|
|
|
|
ControlGroup cg_select_vre;
|
|
|
|
|
|
|
|
@UiField
|
2018-05-08 12:23:11 +02:00
|
|
|
ControlGroup cg_parameters_control;
|
2018-05-04 12:16:27 +02:00
|
|
|
|
|
|
|
@UiField
|
2018-05-08 12:23:11 +02:00
|
|
|
Form form_unit_fields;
|
2018-05-04 12:16:27 +02:00
|
|
|
|
|
|
|
@UiField
|
|
|
|
TextBox field_task_id;
|
|
|
|
|
2018-05-08 12:23:11 +02:00
|
|
|
@UiField
|
|
|
|
Controls task_parameters_control;
|
|
|
|
|
|
|
|
@UiField
|
|
|
|
Button addCustomFieldButton;
|
2018-05-04 12:16:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
/** The map VR es. */
|
|
|
|
private Map<String, GcubeScope> mapScopes = new HashMap<String, GcubeScope>();
|
|
|
|
|
2018-05-08 12:23:11 +02:00
|
|
|
private String currentScope;
|
2018-05-04 12:16:27 +02:00
|
|
|
|
2018-05-08 12:23:11 +02:00
|
|
|
public final static HandlerManager eventBus = new HandlerManager(null);
|
|
|
|
|
|
|
|
// added custom field entries (by the user)
|
|
|
|
private List<CustomFieldEntry> customFieldEntriesList = new ArrayList<CustomFieldEntry>();
|
2018-05-04 12:16:27 +02:00
|
|
|
|
|
|
|
|
2018-05-08 12:23:11 +02:00
|
|
|
private WsFolder folder;
|
2018-05-04 12:16:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Submit handler.
|
|
|
|
*/
|
|
|
|
public abstract void submitHandler();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the error.
|
|
|
|
*
|
|
|
|
* @param visible the visible
|
|
|
|
* @param error the error
|
|
|
|
*/
|
|
|
|
public abstract void setError(boolean visible, String error);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the confirm.
|
|
|
|
*
|
|
|
|
* @param visible the visible
|
|
|
|
* @param msg the msg
|
|
|
|
*/
|
|
|
|
public abstract void setConfirm(boolean visible, String msg);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Because this class has a default constructor, it can
|
|
|
|
* be used as a binder template. In other words, it can be used in other
|
|
|
|
* *.ui.xml files as follows:
|
|
|
|
* <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
|
|
|
|
* xmlns:g="urn:import:**user's package**">
|
|
|
|
* <g:**UserClassName**>Hello!</g:**UserClassName>
|
|
|
|
* </ui:UiBinder>
|
|
|
|
* Note that depending on the widget that is used, it may be necessary to
|
|
|
|
* implement HasHTML instead of HasText.
|
|
|
|
*
|
2018-05-08 12:23:11 +02:00
|
|
|
* @param folder the folder
|
2018-05-04 12:16:27 +02:00
|
|
|
*/
|
2018-05-08 12:23:11 +02:00
|
|
|
public CreateTaskConfigurationView(WsFolder folder) {
|
|
|
|
this.folder = folder;
|
2018-05-04 12:16:27 +02:00
|
|
|
|
|
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
|
|
|
2018-05-08 12:23:11 +02:00
|
|
|
bindEvents();
|
|
|
|
|
2018-05-04 12:16:27 +02:00
|
|
|
pager.getLeft().setVisible(false);
|
|
|
|
|
|
|
|
pager.getRight().addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
setError(false, "");
|
|
|
|
boolean isValid = validateSubmit();
|
|
|
|
if(isValid)
|
|
|
|
submitHandler();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-05-04 17:32:34 +02:00
|
|
|
WsTaskExecutorWidget.wsTaskService.getListOfScopesForLoggedUser(new AsyncCallback<List<GcubeScope>>() {
|
2018-05-04 12:16:27 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<GcubeScope> result) {
|
|
|
|
|
|
|
|
|
|
|
|
for (GcubeScope gcubeScope : result) {
|
|
|
|
String toValue = FormatUtil.toScopeValue(gcubeScope);
|
|
|
|
mapScopes.put(gcubeScope.getScopeName(), gcubeScope);
|
|
|
|
field_select_scope.addItem(toValue, gcubeScope.getScopeName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(result.size()>0){
|
|
|
|
field_select_scope.setSelectedValue(result.get(0).getScopeName());
|
|
|
|
//field_select_vre.setSelectedIndex(0);
|
|
|
|
//field_select_vre.fireEvent(DomEvent.fireNativeEvent(nativeEvent, handlerSource););
|
|
|
|
DomEvent.fireNativeEvent(Document.get().createChangeEvent(), field_select_scope);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-05-08 12:23:11 +02:00
|
|
|
CustomFieldEntry customFieldEntry;
|
|
|
|
if(folder.getPublicLink()!=null){
|
|
|
|
customFieldEntry = new CustomFieldEntry(eventBus, "publicLink", folder.getPublicLink(), false);
|
|
|
|
customFieldEntriesList.add(customFieldEntry);
|
|
|
|
task_parameters_control.add(customFieldEntry);
|
|
|
|
}else
|
|
|
|
addCustomFieldEvent(null);
|
2018-05-04 12:16:27 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-08 12:23:11 +02:00
|
|
|
/**
|
|
|
|
* Adds the custom field event.
|
|
|
|
*
|
|
|
|
* @param e the e
|
|
|
|
*/
|
|
|
|
@UiHandler("addCustomFieldButton")
|
|
|
|
void addCustomFieldEvent(ClickEvent e){
|
|
|
|
|
|
|
|
CustomFieldEntry toAdd = new CustomFieldEntry(eventBus, "", "", true);
|
|
|
|
customFieldEntriesList.add(toAdd);
|
|
|
|
task_parameters_control.add(toAdd);
|
|
|
|
|
|
|
|
}
|
2018-05-04 12:16:27 +02:00
|
|
|
|
|
|
|
/**
|
2018-05-08 12:23:11 +02:00
|
|
|
* Bind events.
|
2018-05-04 12:16:27 +02:00
|
|
|
*/
|
2018-05-08 12:23:11 +02:00
|
|
|
private void bindEvents() {
|
|
|
|
|
|
|
|
// when a custom field is removed, remove it from the list
|
|
|
|
eventBus.addHandler(DeleteCustomFieldEvent.TYPE, new DeleteCustomFieldEventHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRemoveEntry(DeleteCustomFieldEvent event) {
|
|
|
|
customFieldEntriesList.remove(event.getRemovedEntry());
|
|
|
|
task_parameters_control.remove(event.getRemovedEntry());
|
|
|
|
}
|
|
|
|
});
|
2018-05-04 12:16:27 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-08 12:23:11 +02:00
|
|
|
|
2018-05-04 12:16:27 +02:00
|
|
|
/**
|
|
|
|
* Validate submit.
|
|
|
|
*
|
|
|
|
* @return true, if successful
|
|
|
|
*/
|
|
|
|
protected boolean validateSubmit() {
|
|
|
|
cg_input_task_id.setType(ControlGroupType.NONE);
|
2018-05-08 12:23:11 +02:00
|
|
|
cg_parameters_control.setType(ControlGroupType.NONE);
|
2018-05-04 12:16:27 +02:00
|
|
|
//cg_remote_path.setType(ControlGroupType.NONE);
|
|
|
|
|
|
|
|
if(field_select_scope.getSelectedItemText()==null){
|
|
|
|
cg_select_vre.setType(ControlGroupType.ERROR);
|
|
|
|
setError(true, "You must select a Scope!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(field_task_id.getValue() == null || field_task_id.getValue().isEmpty()){
|
|
|
|
cg_input_task_id.setType(ControlGroupType.ERROR);
|
|
|
|
setError(true, "You must type an Algorithm Identifier!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-08 12:23:11 +02:00
|
|
|
for (CustomFieldEntry cFE : customFieldEntriesList) {
|
|
|
|
if(cFE.getKey()==null || cFE.getKey().isEmpty()){
|
|
|
|
cg_parameters_control.setType(ControlGroupType.ERROR);
|
|
|
|
setError(true, "You must type a valid key paramter!");
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-04 12:16:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the selected scope.
|
|
|
|
*
|
|
|
|
* @return the selected scope
|
|
|
|
*/
|
|
|
|
public GcubeScope getSelectedScope(){
|
|
|
|
//String item = field_select_scope.getSelectedItemText();
|
|
|
|
String text = field_select_scope.getSelectedValue();
|
|
|
|
return mapScopes.get(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-04 17:32:34 +02:00
|
|
|
/**
|
|
|
|
* Gets the task id.
|
|
|
|
*
|
|
|
|
* @return the task id
|
|
|
|
*/
|
|
|
|
public String getTaskId(){
|
|
|
|
return field_task_id.getValue();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the parameters.
|
|
|
|
*
|
|
|
|
* @return the parameters
|
|
|
|
*/
|
2018-05-08 12:23:11 +02:00
|
|
|
public List<TaskParameter> getParameters(){
|
2018-05-04 17:32:34 +02:00
|
|
|
|
2018-05-08 12:23:11 +02:00
|
|
|
List<TaskParameter> listParameters = new ArrayList<TaskParameter>();
|
|
|
|
for (CustomFieldEntry cFE : customFieldEntriesList) {
|
|
|
|
TaskParameter tp = new TaskParameter(cFE.getKey(), cFE.getValue(), null, new TaskParameterType(cFE.getType()));
|
|
|
|
listParameters.add(tp);
|
|
|
|
}
|
|
|
|
return listParameters;
|
2018-05-04 17:32:34 +02:00
|
|
|
}
|
|
|
|
|
2018-05-04 12:16:27 +02:00
|
|
|
}
|