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 4e20990..4424663 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 @@ -7,6 +7,7 @@ import org.gcube.portlets.user.statisticalalgorithmsimporter.client.codeparser.C import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.NewSelectedRowsVariableEvent; import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.NewCodeEvent; import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.SessionExpiredEvent; +import org.gcube.portlets.user.statisticalalgorithmsimporter.client.monitor.StatAlgoImporterMonitor; import org.gcube.portlets.user.statisticalalgorithmsimporter.client.resource.StatAlgoImporterResources; import org.gcube.portlets.user.statisticalalgorithmsimporter.client.rpc.StatAlgoImporterServiceAsync; import org.gcube.portlets.user.statisticalalgorithmsimporter.client.type.SessionExpiredType; @@ -216,38 +217,16 @@ public class CodeEditPanel extends ContentPanel { } } - protected void saveCode() { + private void saveCode() { if (project != null) { if (project.getProjectConfig() != null) { if (project.getProjectConfig().getProjectSupport() != null) { if (project.getProjectConfig().getProjectSupport() instanceof ProjectSupportREdit) { if (project.getMainCode() != null && project.getMainCode().getItemDescription() != null) { - String code = editor.getText(); - StatAlgoImporterServiceAsync.INSTANCE.saveCode(code, new AsyncCallback() { - - @Override - public void onFailure(Throwable caught) { - if (caught instanceof StatAlgoImporterSessionExpiredException) { - eventBus.fireEvent(new SessionExpiredEvent(SessionExpiredType.EXPIREDONSERVER)); - } else { - Log.error("Error on save code: " + caught.getLocalizedMessage()); - UtilsGXT3.alert(msgsCommon.error(), caught.getLocalizedMessage()); - } - caught.printStackTrace(); - - } - - @Override - public void onSuccess(Void result) { - Log.debug("Code is saved!"); - UtilsGXT3.info(msgs.codeSavedHead(), msgs.codeSaved()); - } - - }); - + saveCodeOnServer(); } else { - saveNewMainCode(); + saveNewCode(); } } else { if (project.getProjectConfig().getProjectSupport() instanceof ProjectSupportBashEdit) { @@ -256,35 +235,13 @@ public class CodeEditPanel extends ContentPanel { if (projectSupportBashEdit != null && projectSupportBashEdit.getBinaryItem() != null) { - String code = editor.getText(); - StatAlgoImporterServiceAsync.INSTANCE.saveCode(code, new AsyncCallback() { - - @Override - public void onFailure(Throwable caught) { - if (caught instanceof StatAlgoImporterSessionExpiredException) { - eventBus.fireEvent( - new SessionExpiredEvent(SessionExpiredType.EXPIREDONSERVER)); - } else { - Log.error("Error on save code: " + caught.getLocalizedMessage()); - UtilsGXT3.alert(msgsCommon.error(), caught.getLocalizedMessage()); - } - caught.printStackTrace(); - - } - - @Override - public void onSuccess(Void result) { - Log.debug("Code is saved!"); - UtilsGXT3.info(msgs.codeSavedHead(), msgs.codeSaved()); - } - - }); + saveCodeOnServer(); } else { - saveNewMainCode(); + saveNewCode(); } } else { - saveNewMainCode(); + saveNewCode(); } } } else { @@ -301,6 +258,35 @@ public class CodeEditPanel extends ContentPanel { } } + private void saveCodeOnServer() { + final StatAlgoImporterMonitor monitor = new StatAlgoImporterMonitor(); + + String code = editor.getText(); + StatAlgoImporterServiceAsync.INSTANCE.saveCode(code, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + monitor.hide(); + if (caught instanceof StatAlgoImporterSessionExpiredException) { + eventBus.fireEvent(new SessionExpiredEvent(SessionExpiredType.EXPIREDONSERVER)); + } else { + Log.error("Error on save code: " + caught.getLocalizedMessage()); + UtilsGXT3.alert(msgsCommon.error(), caught.getLocalizedMessage()); + } + caught.printStackTrace(); + + } + + @Override + public void onSuccess(Void result) { + monitor.hide(); + Log.debug("Code is saved!"); + UtilsGXT3.info(msgs.codeSavedHead(), msgs.codeSaved()); + } + + }); + } + private void loadCode() { StatAlgoImporterServiceAsync.INSTANCE.getCode(new AsyncCallback>() { @@ -326,7 +312,7 @@ public class CodeEditPanel extends ContentPanel { } } else { - + } if (project != null) { @@ -410,7 +396,7 @@ public class CodeEditPanel extends ContentPanel { } } - protected String getSelectedText() { + private String getSelectedText() { String selectedText = null; AceSelection editorSelection = editor.getSelection(); @@ -456,7 +442,7 @@ public class CodeEditPanel extends ContentPanel { return selectedText; } - private void saveNewMainCode() { + private void saveNewCode() { final PromptMessageBox messageBox = new PromptMessageBox("Code", "File name:"); // First option: Listening for the hide event and then figuring which // button was pressed. @@ -475,7 +461,7 @@ public class CodeEditPanel extends ContentPanel { public void onSelect(SelectEvent event) { String fileName = messageBox.getTextField().getCurrentValue(); if (fileName != null && !fileName.isEmpty()) { - saveNewMainCodeOnServer(fileName); + saveNewCodeOnServer(fileName); } else { Log.debug("Attention invalid file name for Code!"); UtilsGXT3.alert(msgsCommon.attention(), msgs.attentionInvalidFileNameForMainCode()); @@ -486,7 +472,7 @@ public class CodeEditPanel extends ContentPanel { messageBox.show(); } - private void saveNewMainCodeOnServer(String fileName) { + private void saveNewCodeOnServer(String fileName) { ItemDescription file = new ItemDescription(); file.setName(fileName); String code = editor.getText(); diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/maindata/CodeViewerPanel.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/maindata/CodeViewerPanel.java deleted file mode 100644 index 507b4a1..0000000 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/maindata/CodeViewerPanel.java +++ /dev/null @@ -1,492 +0,0 @@ -package org.gcube.portlets.user.statisticalalgorithmsimporter.client.maindata; - -import java.util.ArrayList; -import java.util.List; - -import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.SessionExpiredEvent; -import org.gcube.portlets.user.statisticalalgorithmsimporter.client.properties.CodeDataProperties; -import org.gcube.portlets.user.statisticalalgorithmsimporter.client.resource.StatAlgoImporterResources; -import org.gcube.portlets.user.statisticalalgorithmsimporter.client.rpc.StatAlgoImporterServiceAsync; -import org.gcube.portlets.user.statisticalalgorithmsimporter.client.type.SessionExpiredType; -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 com.allen_sauer.gwt.log.client.Log; -import com.google.gwt.cell.client.AbstractCell; -import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.Style.TextAlign; -import com.google.gwt.event.logical.shared.SelectionEvent; -import com.google.gwt.event.logical.shared.SelectionHandler; -import com.google.gwt.event.shared.EventBus; -import com.google.gwt.event.shared.HandlerRegistration; -import com.google.gwt.safecss.shared.SafeStylesBuilder; -import com.google.gwt.safehtml.shared.SafeHtmlBuilder; -import com.google.gwt.user.client.rpc.AsyncCallback; -import com.sencha.gxt.core.client.IdentityValueProvider; -import com.sencha.gxt.core.client.Style.SelectionMode; -import com.sencha.gxt.core.client.util.Margins; -import com.sencha.gxt.data.shared.ListStore; -import com.sencha.gxt.dnd.core.client.DND.Operation; -import com.sencha.gxt.dnd.core.client.GridDragSource; -import com.sencha.gxt.dnd.core.client.GridDropTarget; -import com.sencha.gxt.widget.core.client.ContentPanel; -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; -import com.sencha.gxt.widget.core.client.form.FieldLabel; -import com.sencha.gxt.widget.core.client.grid.CheckBoxSelectionModel; -import com.sencha.gxt.widget.core.client.grid.ColumnConfig; -import com.sencha.gxt.widget.core.client.grid.ColumnModel; -import com.sencha.gxt.widget.core.client.grid.Grid; -import com.sencha.gxt.widget.core.client.grid.RowNumberer; -import com.sencha.gxt.widget.core.client.menu.Item; -import com.sencha.gxt.widget.core.client.menu.Menu; -import com.sencha.gxt.widget.core.client.menu.MenuItem; - -/** - * - * @author Giancarlo Panichi - * - * - */ -public class CodeViewerPanel extends ContentPanel { - private static final String GRID_CODE_HEIGHT = "300px"; - private static final String GRID_IO_HEIGHT = "100px"; - private static final String SET_INPUT = "SetInput"; - - private EventBus eventBus; - - private ListStore storeCode; - private Grid gridCode; - - private ListStore storeInput; - private Grid gridInput; - - private ListStore storeOutput; - private Grid gridOutput; - - - public CodeViewerPanel(EventBus eventBus) { - super(); - Log.debug("CodeViewerPanel"); - this.eventBus = eventBus; - - // msgs = GWT.create(ServiceCategoryMessages.class); - init(); - create(); - - } - - private void init() { - forceLayoutOnResize = true; - setBodyBorder(false); - setBorders(false); - setHeaderVisible(false); - setResize(true); - - } - - private void create() { - /* - * ToolBar toolBar = new ToolBar(); - * - * toolBar.add(new LabelToolItem("File: ")); fileNameField=new - * TextField(); fileNameField.setWidth("250px"); - * toolBar.add(fileNameField); - */ - - /* - * toolBar.add(new LabelToolItem("Search: ")); final TextField - * searchField = new TextField(); toolBar.add(searchField); - * - * TextButton btnReload = new TextButton(); // - * btnReload.setText("Reload"); - * btnReload.setIcon(StatisticalRunnerResources.INSTANCE.reload24()); - * btnReload.setToolTip("Reload"); toolBar.add(btnReload); - */ - - - CodeDataProperties props = GWT.create(CodeDataProperties.class); - - /* - * storeCode.addFilter(new StoreFilter() { - * - * public boolean select(Store store, CodeData parent, - * CodeData item) { String searchTerm = searchField.getCurrentValue(); - * if (searchTerm == null) return true; return - * CodeViewerPanel.this.select(item, searchTerm); } }); - * - * storeCode.setEnableFilters(true); - */ - - // The row numberer for the first column - RowNumberer numbererColumn = new RowNumberer(); - numbererColumn.setSortable(false); - numbererColumn.setHeader("N."); - numbererColumn.setWidth(80); - numbererColumn.setResizable(true); - - // numbererColumn.setHorizontalAlignment(HorizontalAlignmentConstant.endOf(Direction.LTR)); - // numbererColumn.setColumnStyle(ss.toSafeStyles()); - - SafeStylesBuilder ss = new SafeStylesBuilder() - .textAlign(TextAlign.CENTER); - ColumnConfig codeIdColumn = new ColumnConfig( - props.id(), 80, "N."); - codeIdColumn.setSortable(false); - codeIdColumn.setColumnStyle(ss.toSafeStyles()); - - ColumnConfig codeLineColumn = new ColumnConfig( - props.codeLine(), 100, "Code"); - - - codeLineColumn.setCell(new AbstractCell(){ - - @Override - public void render(Context context, - String value, SafeHtmlBuilder sb) { - Log.debug(value); - SafeHtmlBuilder shb=new SafeHtmlBuilder(); - shb.appendEscaped(value); - sb.appendHtmlConstant("
"+shb.toSafeHtml().asString()+"
"); - } - - }); - - codeLineColumn.setSortable(false); - - // Grid Code - List> gridCodeColumns = new ArrayList>(); - gridCodeColumns.add(numbererColumn); - gridCodeColumns.add(codeLineColumn); - - ColumnModel gridCodeColumnModel = new ColumnModel( - gridCodeColumns); - - IdentityValueProvider identityCode = new IdentityValueProvider(); - final CheckBoxSelectionModel smCode = new CheckBoxSelectionModel( - identityCode); - smCode.setSelectionMode(SelectionMode.SINGLE); - - storeCode = new ListStore(props.code()); - - gridCode = new Grid(storeCode, gridCodeColumnModel) { - @Override - protected void onAfterFirstAttach() { - // TODO Auto-generated method stub - super.onAfterFirstAttach(); - loadData(); - } - }; - - gridCode.setSelectionModel(smCode); - gridCode.getView().setStripeRows(true); - gridCode.getView().setColumnLines(true); - gridCode.getView().setAutoFill(true); - gridCode.setBorders(false); - gridCode.setLoadMask(true); - gridCode.setHeight(GRID_CODE_HEIGHT); - gridCode.setColumnReordering(false); - gridCode.setColumnResize(false); - // gridCode.getView().setAutoExpandColumn(codeLineColumn); - - // Initialize the row numberer - numbererColumn.initPlugin(gridCode); - - // GridFilters filtersSelectedRules = new - // GridFilters(); - // filtersSelectedRules.initPlugin(gridInput); - // filtersSelectedRules.setLocal(true); - // filtersSelectedRules.addFilter(nameFilter); - // filtersSelectedRules.addFilter(descriptionFilter); - - /* - * grid.addRowDoubleClickHandler(new RowDoubleClickHandler() { - * - * @Override public void onRowDoubleClick(RowDoubleClickEvent event) { - * int rowIndex = event.getRowIndex(); requestOpen(rowIndex); } - * - * }); - */ - /* - * SelectHandler sh = new SelectHandler() { public void - * onSelect(SelectEvent event) { loadData(); } }; - * - * btnReload.addSelectHandler(sh); - */ - - createContextMenuGridCode(); - - // Grid Input - List> gridInputColumns = new ArrayList>(); - gridInputColumns.add(codeIdColumn); - gridInputColumns.add(codeLineColumn); - - ColumnModel gridInputColumnModel = new ColumnModel( - gridInputColumns); - - IdentityValueProvider identityInput = new IdentityValueProvider(); - final CheckBoxSelectionModel smInput = new CheckBoxSelectionModel( - identityInput); - smInput.setSelectionMode(SelectionMode.SINGLE); - - storeInput = new ListStore(props.code()); - - gridInput = new Grid(storeInput, gridInputColumnModel); - - gridInput.setSelectionModel(smInput); - gridInput.getView().setStripeRows(true); - gridInput.getView().setColumnLines(true); - gridInput.getView().setAutoFill(true); - gridInput.setBorders(false); - gridInput.setLoadMask(true); - gridInput.setHeight(GRID_IO_HEIGHT); - gridInput.setColumnReordering(false); - gridInput.setColumnResize(false); - gridInput.getView().setAutoExpandColumn(codeLineColumn); - - createContextMenuGridInput(); - - // Output - List> gridOutputColumns = new ArrayList>(); - gridOutputColumns.add(codeIdColumn); - gridOutputColumns.add(codeLineColumn); - - ColumnModel gridOutputColumnModel = new ColumnModel( - gridOutputColumns); - - IdentityValueProvider identityOutput = new IdentityValueProvider(); - final CheckBoxSelectionModel smOutput = new CheckBoxSelectionModel( - identityOutput); - smOutput.setSelectionMode(SelectionMode.SINGLE); - - storeOutput = new ListStore(props.code()); - - gridOutput = new Grid(storeOutput, gridOutputColumnModel); - - gridOutput.setSelectionModel(smOutput); - gridOutput.getView().setStripeRows(true); - gridOutput.getView().setColumnLines(true); - gridOutput.getView().setAutoFill(true); - gridOutput.setBorders(false); - gridOutput.setLoadMask(true); - gridOutput.setHeight(GRID_IO_HEIGHT); - gridOutput.setColumnReordering(false); - gridOutput.setColumnResize(false); - gridOutput.getView().setAutoExpandColumn(codeLineColumn); - - createContextMenuGridOutput(); - - // DND - GridDragSource sourceCode = new GridDragSource( - gridCode); - sourceCode.setGroup(SET_INPUT); - - GridDropTarget targetInput = new GridDropTarget( - gridInput); - targetInput.setGroup(SET_INPUT); - targetInput.setOperation(Operation.COPY); - - GridDropTarget targetOutput = new GridDropTarget( - gridOutput); - targetOutput.setGroup(SET_INPUT); - targetOutput.setOperation(Operation.COPY); - - // Label - FieldLabel gridCodeLabel = new FieldLabel(gridCode, "Code"); - gridCodeLabel.setLabelWidth(50); - FieldLabel gridInputLabel = new FieldLabel(gridInput, "Input"); - gridInputLabel.setLabelWidth(50); - FieldLabel gridOutputLabel = new FieldLabel(gridOutput, "Output"); - gridOutputLabel.setLabelWidth(50); - - // - VerticalLayoutContainer con = new VerticalLayoutContainer(); - // con.setAdjustForScroll(false); - // con.setScrollMode(ScrollMode.AUTO); - - con.add(gridCodeLabel, new VerticalLayoutData(1, 1, new Margins(0))); - con.add(gridInputLabel, new VerticalLayoutData(1, -1, new Margins(0))); - con.add(gridOutputLabel, new VerticalLayoutData(1, -1, new Margins(0))); - - add(con, new MarginData(new Margins(0))); - // add(gridCode, new MarginData(new Margins(0))); - - } - - private void createContextMenuGridCode() { - Menu contextMenuGridCode = new Menu(); - MenuItem inputItem = new MenuItem("Input"); - inputItem.setId("InputStatement"); - inputItem.setIcon(StatAlgoImporterResources.INSTANCE.input16()); - inputItem.addSelectionHandler(new SelectionHandler() { - - @Override - public void onSelection(SelectionEvent event) { - if (gridCode != null) { - CodeData codeData = getGridCodeSelectedItem(); - if (storeInput.findModel(codeData) == null) { - storeInput.add(new CodeData(codeData.getId(), codeData - .getCodeLine())); - storeInput.commitChanges(); - } - // UtilsGXT3.info("Input", "Row " + codeData.getId() - // + " is set as input statement!"); - - } - - } - }); - contextMenuGridCode.add(inputItem); - - MenuItem outputItem = new MenuItem("Output"); - outputItem.setId("OutputStatement"); - outputItem.setIcon(StatAlgoImporterResources.INSTANCE.output16()); - outputItem.addSelectionHandler(new SelectionHandler() { - - @Override - public void onSelection(SelectionEvent event) { - if (gridCode != null) { - CodeData codeData = getGridCodeSelectedItem(); - if (storeOutput.findModel(codeData) == null) { - storeOutput.add(new CodeData(codeData.getId(), codeData - .getCodeLine())); - storeOutput.commitChanges(); - } - // UtilsGXT3.info("Output", "Row " + codeData.getId() - // + " is set as otuput statement!"); - - } - - } - }); - contextMenuGridCode.add(outputItem); - - gridCode.setContextMenu(contextMenuGridCode); - - } - - private void createContextMenuGridInput() { - Menu contextMenuGridInput = new Menu(); - MenuItem deleteItem = new MenuItem("Delete"); - deleteItem.setId("Delete"); - deleteItem.setIcon(StatAlgoImporterResources.INSTANCE.input16()); - deleteItem.addSelectionHandler(new SelectionHandler() { - - @Override - public void onSelection(SelectionEvent event) { - if (gridInput != null) { - CodeData codeData = getGridInputSelectedItem(); - storeInput.remove(codeData); - storeInput.commitChanges(); - - } - - } - }); - contextMenuGridInput.add(deleteItem); - - gridInput.setContextMenu(contextMenuGridInput); - - } - - private void createContextMenuGridOutput() { - Menu contextMenuGridOutput = new Menu(); - MenuItem deleteItem = new MenuItem("Delete"); - deleteItem.setId("Delete"); - deleteItem.setIcon(StatAlgoImporterResources.INSTANCE.input16()); - deleteItem.addSelectionHandler(new SelectionHandler() { - - @Override - public void onSelection(SelectionEvent event) { - if (gridOutput != null) { - CodeData codeData = getGridOutputSelectedItem(); - storeOutput.remove(codeData); - storeOutput.commitChanges(); - - } - - } - }); - contextMenuGridOutput.add(deleteItem); - - gridOutput.setContextMenu(contextMenuGridOutput); - - } - - private void loadData() { - StatAlgoImporterServiceAsync.INSTANCE - .getCode(new AsyncCallback>() { - - public void onFailure(Throwable caught) { - if (caught instanceof StatAlgoImporterSessionExpiredException) { - eventBus.fireEvent(new SessionExpiredEvent( - SessionExpiredType.EXPIREDONSERVER)); - } else { - Log.error("Error retrieving code: " - + caught.getLocalizedMessage()); - UtilsGXT3.alert("Error", - caught.getLocalizedMessage()); - } - caught.printStackTrace(); - - } - - public void onSuccess(ArrayList result) { - Log.debug("loaded " + result.size() + " code lines"); - ArrayList availables = new ArrayList(); - for (CodeData codeData : result) { - Log.debug("Read: " + codeData); - availables.add(codeData); - } - storeCode.clear(); - storeCode.addAll(availables); - storeCode.commitChanges(); - - forceLayout(); - } - }); - } - - /* - * private boolean select(CodeData item, String searchTerm) { if - * (item.getCodeLine() != null && item.getCodeLine().toLowerCase() - * .contains(searchTerm.toLowerCase())) return true; return false; } - */ - - public HandlerRegistration addSelectionHandler( - SelectionHandler handler) { - return gridCode.getSelectionModel().addSelectionHandler(handler); - } - - public CodeData getGridCodeSelectedItem() { - return gridCode.getSelectionModel().getSelectedItem(); - - } - - public CodeData getGridInputSelectedItem() { - return gridInput.getSelectionModel().getSelectedItem(); - - } - - public CodeData getGridOutputSelectedItem() { - return gridOutput.getSelectionModel().getSelectedItem(); - - } - - public void gridReload() { - storeCode.clear(); - storeCode.commitChanges(); - storeInput.clear(); - storeInput.commitChanges(); - storeOutput.clear(); - storeOutput.commitChanges(); - gridCode.getSelectionModel().deselectAll(); - gridInput.getSelectionModel().deselectAll(); - gridOutput.getSelectionModel().deselectAll(); - - loadData(); - } - -}