From ff9935200aae352def458c293ef5f8abc8ab2970 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Tue, 19 Jun 2018 13:27:47 +0000 Subject: [PATCH] Manage enum case as Task Parameter git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/ws-task-executor-widget@169329 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/WsTaskExecutorWidget.java | 38 +++++++++++++++++-- .../binder/CreateTaskConfigurationView.java | 19 ++++++---- .../client/view/binder/CustomFieldEntry.java | 36 +++++++++++++++--- .../view/binder/CustomFieldEntry.ui.xml | 12 +++++- 4 files changed, 86 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/WsTaskExecutorWidget.java b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/WsTaskExecutorWidget.java index 58a3d0f..07cedc3 100644 --- a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/WsTaskExecutorWidget.java +++ b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/WsTaskExecutorWidget.java @@ -40,6 +40,7 @@ import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.shared.HandlerManager; +import com.google.gwt.regexp.shared.RegExp; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Button; @@ -289,12 +290,11 @@ public class WsTaskExecutorWidget { return; List listMessages = result.getOutputMessages(); - - String outMsg = ""; + String outMsg = ""; final DialogResult dResult = new DialogResult(null, "Computation results are:", outMsg); dResult.center(); @@ -309,6 +309,36 @@ public class WsTaskExecutorWidget { } +// private String addHtmlLink(String text){ +// +// if(text==null || text.isEmpty()) +// return text; +// +// MatchResult matcher = urlPattern.exec(text); +// boolean matchFound = matcher != null; // equivalent to regExp.test(inputStr); +// +// String msgWithHref = text; +// if (matchFound) { +// // Get all groups for this match +// for (int i = 0; i < matcher.getGroupCount(); i++) { +// String groupStr = matcher.getGroup(i); +// System.out.println(groupStr); +// msgWithHref= msgWithHref.replace(groupStr, ""); +// +// } +// } +// +// GWT.log("Replace html: "+msgWithHref); +// +// return msgWithHref; +// } + + // Pattern for recognizing a URL, based off RFC 3986 + private static final RegExp urlPattern = RegExp.compile( + "(?:^|[\\W])((ht|f)tp(s?):\\/\\/|www\\.)" + + "(([\\w\\-]+\\.){1,}?([\\w\\-.~]+\\/?)*" + + "[\\p{Alnum}.,%_=?&#\\-+()\\[\\]\\*$~@!:/{};']*)"); + /** * Perform run task. diff --git a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/binder/CreateTaskConfigurationView.java b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/binder/CreateTaskConfigurationView.java index 46c2f52..e098ae9 100644 --- a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/binder/CreateTaskConfigurationView.java +++ b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/binder/CreateTaskConfigurationView.java @@ -2,6 +2,7 @@ package org.gcube.portlets.widgets.wstaskexecutor.client.view.binder; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -193,7 +194,7 @@ public abstract class CreateTaskConfigurationView extends Composite { List params = editConfiguration.getListParameters(); for (TaskParameter taskParameter : params) { - appendCustomField(taskParameter.getKey(), taskParameter.getValue(), taskParameter.getType().getType(), false); + appendCustomField(taskParameter.getKey(), Arrays.asList(taskParameter.getValue()), taskParameter.getType().getType(), false); } pager.getRight().setText("Update Configuration"); @@ -255,13 +256,13 @@ public abstract class CreateTaskConfigurationView extends Composite { * Append custom field. * * @param key the key - * @param value the value + * @param values the values * @param parameterType the parameter type * @param removable the removable */ - private void appendCustomField(String key, String value, String parameterType, boolean removable){ + private void appendCustomField(String key, List values, String parameterType, boolean removable){ - CustomFieldEntry toAdd = new CustomFieldEntry(eventBus, key, value, parameterType, removable); + CustomFieldEntry toAdd = new CustomFieldEntry(eventBus, key, values, parameterType, removable); customFieldEntriesList.add(toAdd); cg_parameters_control.add(toAdd); } @@ -284,19 +285,23 @@ public abstract class CreateTaskConfigurationView extends Composite { if(operator.getType().getType().equals("FILE")){ countFileParameter++; if(countFileParameter==1){ - appendCustomField("publicLink", wsItem.getPublicLink(), operator.getType().getType(), false); + List pLink = new ArrayList(1); + pLink.add(wsItem.getPublicLink()); + appendCustomField("publicLink", pLink, operator.getType().getType(), false); addedPublicLink = true; } } } if(!addedPublicLink) - appendCustomField(operator.getKey(), operator.getDefaultValue(), operator.getType().getType(), false); + appendCustomField(operator.getKey(), operator.getDefaultValues(), operator.getType().getType(), false); } if(wsItem.isFolder()){ - appendCustomField("folderId", wsItem.getItemId(), "OBJECT", true); + List pItemId = new ArrayList(1); + pItemId.add(wsItem.getItemId()); + appendCustomField("folderId", pItemId, "OBJECT", true); } diff --git a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/binder/CustomFieldEntry.java b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/binder/CustomFieldEntry.java index c3ff64b..a34a72f 100644 --- a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/binder/CustomFieldEntry.java +++ b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/binder/CustomFieldEntry.java @@ -8,6 +8,7 @@ import org.gcube.portlets.widgets.wstaskexecutor.client.event.DeleteCustomFieldE import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.ControlGroup; +import com.github.gwtbootstrap.client.ui.Controls; import com.github.gwtbootstrap.client.ui.InputAddOn; import com.github.gwtbootstrap.client.ui.ListBox; import com.github.gwtbootstrap.client.ui.TextBox; @@ -48,14 +49,18 @@ public class CustomFieldEntry extends Composite { @UiField InputAddOn keyFieldPrepend; @UiField InputAddOn valueFieldPrepend; + @UiField InputAddOn valuesSelectPrepend; @UiField Button removeCustomField; @UiField ListBox field_select_parameter; @UiField ControlGroup cg_parameter; + @UiField TextBox field_input_value; + //@UiField ListBox field_select_value; + @UiField Controls control_select_value; + @UiField Controls control_input_value; private List parameterTypes; - //inserted values - private String value; + private List values; private String key; //private boolean isCustomCreatedByUser; @@ -72,7 +77,7 @@ public class CustomFieldEntry extends Composite { * @param value the value * @param parameterType the parameter type */ - public CustomFieldEntry(HandlerManager eventBus, String key, String value, final String parameterType, boolean removable) { + public CustomFieldEntry(HandlerManager eventBus, String key, List values, final String parameterType, boolean removable) { initWidget(uiBinder.createAndBindUi(this)); this.getElement().getStyle().setMarginTop(10, Unit.PX); this.getElement().getStyle().setMarginBottom(20, Unit.PX); @@ -81,10 +86,12 @@ public class CustomFieldEntry extends Composite { keyFieldPrepend.setTitle("This is the key of the parameter"); valueFieldPrepend.setTitle("This is the value of the parameter"); + control_select_value.setVisible(false); + // save information this.eventBus = eventBus; this.key = key; - this.value = value; + this.values = values; this.parameterType = parameterType; @@ -92,8 +99,22 @@ public class CustomFieldEntry extends Composite { ((TextBox)this.keyFieldPrepend.getWidget(1)).setText(key); } - if(value!=null && !value.isEmpty()){ - ((TextBox)this.valueFieldPrepend.getWidget(1)).setText(value); + if(values!=null && !values.isEmpty()){ + //one default value is added + if(values.size()==1){ + control_input_value.setVisible(true); + ((TextBox)this.valueFieldPrepend.getWidget(1)).setText(values.get(0)); + } + else{ + //Many default value existing.. creating combo box to them + control_input_value.setVisible(false); + control_select_value.setVisible(true); + ListBox selectValues = (ListBox) this.valuesSelectPrepend.getWidget(1); + for (String value : values) { + selectValues.addItem(value, value); + } + } + } WsTaskExecutorWidget.wsTaskService.getAvailableParameterTypes(new AsyncCallback>() { @@ -167,6 +188,9 @@ public class CustomFieldEntry extends Composite { */ public String getValue(){ + if(values!=null && values.size()>1) + return ((ListBox) this.valuesSelectPrepend.getWidget(1)).getSelectedValue(); + return ((TextBox)this.valueFieldPrepend.getWidget(1)).getText(); } diff --git a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/binder/CustomFieldEntry.ui.xml b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/binder/CustomFieldEntry.ui.xml index 51bf193..f5f7ffa 100644 --- a/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/binder/CustomFieldEntry.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/wstaskexecutor/client/view/binder/CustomFieldEntry.ui.xml @@ -17,10 +17,18 @@ - + - + + + + + + +