From 0fc62789bd72d9d18a49227d9f4247d1977a70e9 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Mon, 21 Dec 2015 17:02:22 +0000 Subject: [PATCH] 1452: Implement a GUI for StatMan Algorithms Importer Task-Url: https://support.d4science.org/issues/1452 Added selected rows variable support git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@122042 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/codeparser/CodeParser.java | 99 ++++++++++++++ .../event/NewSelectedRowsVariableEvent.java | 68 ++++++++++ .../client/maindata/CodeEditPanel.java | 41 +++++- .../SelectedRowsVariablesProperties.java | 3 + .../tools/input/InputVariablePanel.java | 24 ++++ .../tools/input/InputVariableTabPanel.java | 9 ++ .../client/tools/input/SelectedRowsPanel.java | 125 ++++++++++++------ .../shared/input/DataType.java | 9 +- .../shared/input/SelectedRowsVariables.java | 31 ++++- 9 files changed, 352 insertions(+), 57 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/codeparser/CodeParser.java create mode 100644 src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/event/NewSelectedRowsVariableEvent.java diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/codeparser/CodeParser.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/codeparser/CodeParser.java new file mode 100644 index 0000000..f8279a8 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/codeparser/CodeParser.java @@ -0,0 +1,99 @@ +package org.gcube.portlets.user.statisticalalgorithmsimporter.client.codeparser; + +import java.util.regex.Pattern; + +import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.DataType; +import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.IOType; +import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.SelectedRowsVariables; + +/** + * + * @author Giancarlo Panichi email: g.panichi@isti.cnr.it + * + */ +public class CodeParser { + + private static final String IMAGE_PATTERN = "([^\\s]+(\\.(?i)(jpg|png|gif|bmp)\")$)"; + private static final String FILE_PATTERN = "([^\\s]+(\\.(?i)(txt|csv|pdf|doc)\")$)"; + private static final String ENUM1_PATTERN = "(c\\([^\\)]*\\))"; + private static final String ENUM2_PATTERN = "(\\{[^\\}]*\\})"; + + public CodeParser() { + + } + + public SelectedRowsVariables parse(String parameter, IOType ioType) { + SelectedRowsVariables selectedRowsVariables = null; + + if (parameter == null) { + return null; + } + + if (parameter.contains("<-")) { + String[] varDescription = parameter.split("<-"); + selectedRowsVariables = new SelectedRowsVariables( + varDescription[0].trim(), varDescription[0].trim(), varDescription[1].trim(), + checkDataType(varDescription[1].trim()), ioType, parameter); + + } else { + if (parameter.contains("=")) { + String[] varDescription = parameter.split("="); + selectedRowsVariables = new SelectedRowsVariables( + varDescription[0].trim(), varDescription[0].trim(), + varDescription[1].trim(), checkDataType(varDescription[1].trim()), + ioType, parameter); + } else { + return null; + } + } + + return selectedRowsVariables; + } + + private DataType checkDataType(String data) { + if (data == null || data.isEmpty()) { + return DataType.STRING; + } + + + Pattern patternFile = Pattern.compile(FILE_PATTERN); + if (patternFile.matcher(data).matches()) { + return DataType.FILE; + } + + Pattern patternImage = Pattern.compile(IMAGE_PATTERN); + if (patternImage.matcher(data).matches()) { + return DataType.FILE; + } + + Pattern patternEnum1 = Pattern.compile(ENUM1_PATTERN); + if (patternEnum1.matcher(data).matches()) { + return DataType.ENUMERATED; + } + + Pattern patternEnum2 = Pattern.compile(ENUM2_PATTERN); + if (patternEnum2.matcher(data).matches()) { + return DataType.ENUMERATED; + } + + + try { + Integer.parseInt(data); + return DataType.INTEGER; + } catch (NumberFormatException e) { + + } + + try { + Double.parseDouble(data); + return DataType.DOUBLE; + } catch (NumberFormatException e) { + + } + + return DataType.STRING; + + } + +} diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/event/NewSelectedRowsVariableEvent.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/event/NewSelectedRowsVariableEvent.java new file mode 100644 index 0000000..961ae4a --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/event/NewSelectedRowsVariableEvent.java @@ -0,0 +1,68 @@ +package org.gcube.portlets.user.statisticalalgorithmsimporter.client.event; + +import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.SelectedRowsVariables; + +import com.google.gwt.event.shared.EventHandler; +import com.google.gwt.event.shared.GwtEvent; +import com.google.gwt.event.shared.HandlerRegistration; +import com.google.gwt.event.shared.HasHandlers; + +/** + * Input Save Event + * + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class NewSelectedRowsVariableEvent + extends + GwtEvent { + + public static Type TYPE = new Type(); + private SelectedRowsVariables selectedRowsVariable; + + public interface NewSelectedRowsVariableEventHandler extends EventHandler { + void onNewVariable(NewSelectedRowsVariableEvent event); + } + + public interface HasNewSelectedRowsVariableEventHandler extends HasHandlers { + public HandlerRegistration addNewSelectedRowsVariableEventHandler( + NewSelectedRowsVariableEventHandler handler); + } + + public NewSelectedRowsVariableEvent( + SelectedRowsVariables selectedRowsVariable) { + this.selectedRowsVariable = selectedRowsVariable; + } + + @Override + protected void dispatch(NewSelectedRowsVariableEventHandler handler) { + handler.onNewVariable(this); + } + + @Override + public Type getAssociatedType() { + return TYPE; + } + + public static Type getType() { + return TYPE; + } + + public static void fire(HasHandlers source, + NewSelectedRowsVariableEvent newSelectedRowsVariableEvent) { + source.fireEvent(newSelectedRowsVariableEvent); + } + + public SelectedRowsVariables getSelectedRowsVariable() { + return selectedRowsVariable; + } + + @Override + public String toString() { + return "NewSelectedRowsVariableEvent [selectedRowsVariable=" + + selectedRowsVariable + "]"; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/maindata/CodeEditPanel.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/maindata/CodeEditPanel.java index c63be2e..267faed 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/maindata/CodeEditPanel.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/maindata/CodeEditPanel.java @@ -2,6 +2,8 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.client.maindata; import java.util.ArrayList; +import org.gcube.portlets.user.statisticalalgorithmsimporter.client.codeparser.CodeParser; +import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.NewSelectedRowsVariableEvent; import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.SessionExpiredEvent; import org.gcube.portlets.user.statisticalalgorithmsimporter.client.resource.StatAlgoImporterResources; import org.gcube.portlets.user.statisticalalgorithmsimporter.client.rpc.StatAlgoImporterServiceAsync; @@ -9,6 +11,8 @@ import org.gcube.portlets.user.statisticalalgorithmsimporter.client.type.Session import org.gcube.portlets.user.statisticalalgorithmsimporter.client.utils.UtilsGXT3; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.code.CodeData; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterSessionExpiredException; +import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.IOType; +import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.SelectedRowsVariables; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project; import com.allen_sauer.gwt.log.client.Log; @@ -92,7 +96,7 @@ public class CodeEditPanel extends ContentPanel { @Override public void onSelect(SelectEvent event) { - + saveVariable(IOType.INPUT); } }); @@ -107,7 +111,7 @@ public class CodeEditPanel extends ContentPanel { @Override public void onSelect(SelectEvent event) { - + saveVariable(IOType.OUTPUT); } }); @@ -149,6 +153,33 @@ public class CodeEditPanel extends ContentPanel { } + private void saveVariable(IOType ioType) { + String parameter = getSelectedText(); + Log.debug("Save Variable: " + ioType + ", " + parameter); + if (parameter == null) { + Log.debug("No text selected"); + UtilsGXT3.alert("Attention", "Select parameter in the code!"); + } else { + createSelectedRowVariable(parameter, ioType); + } + + } + + private void createSelectedRowVariable(String parameter, IOType ioType) { + CodeParser codeParser = new CodeParser(); + SelectedRowsVariables selectedRowsVariable = codeParser.parse( + parameter, ioType); + if (selectedRowsVariable == null) { + Log.debug("No valid selection, change selection and try again!"); + UtilsGXT3.alert("Attention", "No valid selected row, change selection and try again!"); + } else { + NewSelectedRowsVariableEvent newSelectedRowsVariableEvent = new NewSelectedRowsVariableEvent( + selectedRowsVariable); + eventBus.fireEvent(newSelectedRowsVariableEvent); + Log.debug("Fire: " + newSelectedRowsVariableEvent); + } + } + protected void saveCode() { String code = editor.getText(); StatAlgoImporterServiceAsync.INSTANCE.saveCode(code, @@ -250,7 +281,7 @@ public class CodeEditPanel extends ContentPanel { if (editorSelection.isMultiLine()) { String tempTest; - for (int i = startPosition.getRow(); i < endPosition.getRow() + 1; i++) { + for (int i = startPosition.getRow(); i < endPosition.getRow(); i++) { if (i == startPosition.getRow()) { tempTest = editor.getLine(i); tempTest.substring(startPosition.getColumn()); @@ -258,7 +289,7 @@ public class CodeEditPanel extends ContentPanel { } else { if (i == endPosition.getRow()) { tempTest = editor.getLine(i); - tempTest.substring(0, endPosition.getColumn() + 1); + tempTest.substring(0, endPosition.getColumn()); selectedText += tempTest; } else { selectedText += editor.getLine(i); @@ -269,7 +300,7 @@ public class CodeEditPanel extends ContentPanel { String tempTest; tempTest = editor.getLine(startPosition.getRow()); selectedText = tempTest.substring(startPosition.getColumn(), - endPosition.getColumn() + 1); + endPosition.getColumn()); } } diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/properties/SelectedRowsVariablesProperties.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/properties/SelectedRowsVariablesProperties.java index 97839b2..0b30541 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/properties/SelectedRowsVariablesProperties.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/properties/SelectedRowsVariablesProperties.java @@ -29,4 +29,7 @@ public interface SelectedRowsVariablesProperties extends ValueProvider ioType(); + ValueProvider sourceSelection(); + + } diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/InputVariablePanel.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/InputVariablePanel.java index 407cd2d..72062a6 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/InputVariablePanel.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/InputVariablePanel.java @@ -1,8 +1,10 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.client.tools.input; import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.InputSaveEvent; +import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.NewSelectedRowsVariableEvent; import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.ProjectStatusEvent; import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.UIStateEvent; +import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.SelectedRowsVariables; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project; import com.allen_sauer.gwt.log.client.Log; @@ -84,7 +86,29 @@ public class InputVariablePanel extends ContentPanel { } }); + + eventBus.addHandler( + NewSelectedRowsVariableEvent.TYPE, + new NewSelectedRowsVariableEvent.NewSelectedRowsVariableEventHandler() { + @Override + public void onNewVariable(NewSelectedRowsVariableEvent event) { + addNewSelectedRowsVariable(event + .getSelectedRowsVariable()); + + } + + }); + + + + + } + + protected void addNewSelectedRowsVariable( + SelectedRowsVariables selectedRowsVariable) { + inputVariableTabPanel.addSelectedRowsVariable(selectedRowsVariable); + } protected void manageInputSaveEvents(InputSaveEvent event) { diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/InputVariableTabPanel.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/InputVariableTabPanel.java index 541aad9..74f0596 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/InputVariableTabPanel.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/InputVariableTabPanel.java @@ -1,6 +1,7 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.client.tools.input; import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.InputSaveReadyEvent; +import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.SelectedRowsVariables; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.InputData; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project; @@ -124,4 +125,12 @@ public class InputVariableTabPanel extends TabPanel { add(enviromentVariablesPanel, enviromentVariablePanelItemConf); } + public void addSelectedRowsVariable( + SelectedRowsVariables selectedRowsVariable) { + setActiveWidget(selectedRowsPanel); + selectedRowsPanel.addNewSelectedRowsVariable(selectedRowsVariable); + + + } + } diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/SelectedRowsPanel.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/SelectedRowsPanel.java index 9ad2412..1ef0db1 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/SelectedRowsPanel.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/SelectedRowsPanel.java @@ -1,6 +1,7 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.client.tools.input; import java.util.ArrayList; +import java.util.List; import org.gcube.portlets.user.statisticalalgorithmsimporter.client.properties.DataTypePropertiesCombo; import org.gcube.portlets.user.statisticalalgorithmsimporter.client.properties.IOTypePropertiesCombo; @@ -27,7 +28,6 @@ import com.sencha.gxt.data.shared.ListStore; import com.sencha.gxt.widget.core.client.ContentPanel; import com.sencha.gxt.widget.core.client.button.ButtonBar; import com.sencha.gxt.widget.core.client.button.TextButton; -import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData; import com.sencha.gxt.widget.core.client.container.MarginData; import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer; import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData; @@ -47,7 +47,6 @@ import com.sencha.gxt.widget.core.client.grid.Grid; import com.sencha.gxt.widget.core.client.grid.Grid.GridCell; import com.sencha.gxt.widget.core.client.grid.GridSelectionModel; import com.sencha.gxt.widget.core.client.grid.editing.GridRowEditing; -import com.sencha.gxt.widget.core.client.toolbar.ToolBar; /** * @@ -80,7 +79,6 @@ public class SelectedRowsPanel extends ContentPanel { SafeHtml format(String value); } - public SelectedRowsPanel(Project project, EventBus eventBus) { super(); Log.debug("SelectedRowsPanel"); @@ -104,6 +102,13 @@ public class SelectedRowsPanel extends ContentPanel { } private void create(Project project) { + if (project != null && project.getInputData() != null + && project.getInputData().getListSelectedRows() != null) { + seq = project.getInputData().getListSelectedRows().size(); + } else { + seq = 0; + } + // Grid SelectedRowsVariablesProperties props = GWT .create(SelectedRowsVariablesProperties.class); @@ -133,8 +138,7 @@ public class SelectedRowsPanel extends ContentPanel { ColumnConfig defaultValueColumn = new ColumnConfig( props.defaultValue(), 100, "Default"); // defaColumn.setMenuDisabled(true); - - + ColumnConfig ioTypeColumn = new ColumnConfig( props.ioType(), 100, "I/O"); // inputTypeColumn.setMenuDisabled(true); @@ -148,8 +152,6 @@ public class SelectedRowsPanel extends ContentPanel { sb.append(ioTypeTemplates.format(ioType.getLabel())); } }); - - ArrayList> l = new ArrayList>(); l.add(nameColumn); @@ -161,8 +163,7 @@ public class SelectedRowsPanel extends ContentPanel { ColumnModel columns = new ColumnModel( l); - storeSelectedRows = new ListStore( - props.id()); + storeSelectedRows = new ListStore(props.id()); /* * ArrayList list = new ArrayList<>(); for (int i @@ -174,14 +175,15 @@ public class SelectedRowsPanel extends ContentPanel { if (project != null && project.getInputData() != null && project.getInputData().getListSelectedRows() != null) { - storeSelectedRows.addAll(project.getInputData().getListSelectedRows()); + storeSelectedRows.addAll(project.getInputData() + .getListSelectedRows()); } final GridSelectionModel sm = new GridSelectionModel(); sm.setSelectionMode(SelectionMode.SINGLE); - gridSelectedRows = new Grid( - storeSelectedRows, columns); + gridSelectedRows = new Grid(storeSelectedRows, + columns); gridSelectedRows.setSelectionModel(sm); gridSelectedRows.getView().setStripeRows(true); gridSelectedRows.getView().setColumnLines(true); @@ -207,7 +209,7 @@ public class SelectedRowsPanel extends ContentPanel { */ // EDITING // - + // DataType DataTypePropertiesCombo dataTypePropertiesCombo = GWT .create(DataTypePropertiesCombo.class); @@ -222,13 +224,16 @@ public class SelectedRowsPanel extends ContentPanel { comboDataType.setTriggerAction(TriggerAction.ALL); addHandlersForComboDataType(dataTypePropertiesCombo.label()); - + + storeComboDataType.clear(); + storeComboDataType.addAll(DataType.asList()); + storeComboDataType.commitChanges(); + // IOType IOTypePropertiesCombo ioTypePropertiesCombo = GWT .create(IOTypePropertiesCombo.class); - storeComboIOType = new ListStore( - ioTypePropertiesCombo.id()); + storeComboIOType = new ListStore(ioTypePropertiesCombo.id()); comboIOType = new ComboBox(storeComboIOType, ioTypePropertiesCombo.label()); @@ -238,22 +243,20 @@ public class SelectedRowsPanel extends ContentPanel { comboIOType.setTriggerAction(TriggerAction.ALL); addHandlersForComboIOType(ioTypePropertiesCombo.label()); - + storeComboIOType.clear(); + storeComboIOType.addAll(IOType.asList()); + storeComboIOType.commitChanges(); + // - + gridSelectedRowsEditing = new GridRowEditing( gridSelectedRows); gridSelectedRowsEditing.addEditor(nameColumn, new TextField()); - gridSelectedRowsEditing.addEditor(descriptionColumn, - new TextField()); - gridSelectedRowsEditing.addEditor(dataTypeColumn, - comboDataType); - gridSelectedRowsEditing.addEditor(defaultValueColumn, - new TextField()); - - gridSelectedRowsEditing.addEditor(ioTypeColumn, - comboIOType); - + gridSelectedRowsEditing.addEditor(descriptionColumn, new TextField()); + gridSelectedRowsEditing.addEditor(dataTypeColumn, comboDataType); + gridSelectedRowsEditing.addEditor(defaultValueColumn, new TextField()); + + gridSelectedRowsEditing.addEditor(ioTypeColumn, comboIOType); btnAdd = new TextButton(); btnAdd.setIcon(StatAlgoImporterResources.INSTANCE.add16()); @@ -279,12 +282,27 @@ public class SelectedRowsPanel extends ContentPanel { storeSelectedRows.remove(rowIndex); storeSelectedRows.commitChanges(); - gridSelectedRowsEditing.getCancelButton().setVisible( - true); + gridSelectedRowsEditing.getCancelButton().setVisible(true); btnAdd.setEnabled(true); if (addStatus) { addStatus = false; } + + List listSelected=storeSelectedRows.getAll(); + List listNewSelected= new ArrayList(); + for(int i=0; i