diff --git a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/mapping/ColumnMappingDialog.java b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/mapping/ColumnMappingDialog.java index 7639007..7c32255 100644 --- a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/mapping/ColumnMappingDialog.java +++ b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/mapping/ColumnMappingDialog.java @@ -2,6 +2,7 @@ package org.gcube.portlets.user.td.columnwidget.client.mapping; import java.util.ArrayList; +import org.gcube.portlets.user.td.columnwidget.client.dimension.CodelistSelectionListener; import org.gcube.portlets.user.td.columnwidget.client.resources.ResourceBundle; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; @@ -104,5 +105,24 @@ public class ColumnMappingDialog extends Window { listeners.remove(listener); } + public void fireSelectedColumnMapping(ColumnMappingList columnMappingData) { + for (ColumnMappingListener listener : listeners) + listener.selectedColumnMapping(columnMappingData); + hide(); + } + + public void fireAbortedColumnMapping() { + for (ColumnMappingListener listener : listeners) + listener.abortedColumnMapping(); + hide(); + } + + public void fireFailedColumnMapping(String reason, String detail) { + for (ColumnMappingListener listener : listeners) + listener.failedColumnMapping(reason, detail); + hide(); + } + + } diff --git a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/mapping/ColumnMappingListener.java b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/mapping/ColumnMappingListener.java index 2761f10..530c493 100644 --- a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/mapping/ColumnMappingListener.java +++ b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/mapping/ColumnMappingListener.java @@ -14,7 +14,7 @@ public interface ColumnMappingListener { /** * Called when created column mapping without errors */ - public void selectedColumnMappingListener(ColumnMappingList columnMappingData); + public void selectedColumnMapping(ColumnMappingList columnMappingData); /** * Called when the column mapping operation is aborted by the user. diff --git a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/mapping/ColumnMappingPanel.java b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/mapping/ColumnMappingPanel.java index b970343..27e2581 100644 --- a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/mapping/ColumnMappingPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/mapping/ColumnMappingPanel.java @@ -18,16 +18,22 @@ 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.web.bindery.event.shared.EventBus; +import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign; import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction; import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode; import com.sencha.gxt.core.client.util.Margins; import com.sencha.gxt.data.shared.ListStore; import com.sencha.gxt.widget.core.client.FramedPanel; +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.BoxLayoutContainer.BoxLayoutPack; import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer; import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer.HBoxLayoutAlign; +import com.sencha.gxt.widget.core.client.container.SimpleContainer; 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.event.SelectEvent; +import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler; import com.sencha.gxt.widget.core.client.event.TriggerClickEvent; import com.sencha.gxt.widget.core.client.event.TriggerClickEvent.TriggerClickHandler; import com.sencha.gxt.widget.core.client.form.ComboBox; @@ -42,7 +48,8 @@ public class ColumnMappingPanel extends FramedPanel { protected static final String WIDTH = "560px"; protected static final String HEIGHT = "520px"; protected static final String COMBOWIDTH ="120px"; - + protected String CONTAINERHEIGHT = "520px"; + protected ColumnMappingPanel thisPanel; @@ -61,7 +68,10 @@ public class ColumnMappingPanel extends FramedPanel { protected ColumnMappingList columnMappingList; protected ArrayList mapping; - + + private TextButton btnSave; + private TextButton btnClose; + /** * * @@ -88,16 +98,77 @@ public class ColumnMappingPanel extends FramedPanel { + ", eventBus:" + eventBus + "]"); columnMappingList = new ColumnMappingList(); mapping = new ArrayList(); + create(); } - - protected void setup() { + + protected void create() { itemIdSourceValueArg = "SourceArg" + selectedColumn.getName(); itemIdTargetValueArg = "TargetArg" + selectedColumn.getName(); + SimpleContainer container = new SimpleContainer(); + container.setHeight(CONTAINERHEIGHT); + + btnSave = new TextButton("Save"); + btnSave.setIcon(ResourceBundle.INSTANCE.save()); + btnSave.setIconAlign(IconAlign.RIGHT); + btnSave.setTitle("Save"); + btnSave.addSelectHandler(new SelectHandler() { + + public void onSelect(SelectEvent event) { + Log.debug("Pressed Save"); + btnSave.disable(); + save(); + + } + }); + + btnClose = new TextButton("Close"); + btnClose.setIcon(ResourceBundle.INSTANCE.close()); + btnClose.setIconAlign(IconAlign.RIGHT); + btnClose.setTitle("Close"); + btnClose.addSelectHandler(new SelectHandler() { + + public void onSelect(SelectEvent event) { + Log.debug("Pressed Close"); + close(); + } + }); + + HBoxLayoutContainer flowButton = new HBoxLayoutContainer(); + flowButton.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE); + flowButton.setPack(BoxLayoutPack.CENTER); + + flowButton.add(btnSave, new BoxLayoutData(new Margins(2, 4, 2, 4))); + flowButton.add(btnClose, new BoxLayoutData(new Margins(2, 4, 2, 4))); + + vert = new VerticalLayoutContainer(); vert.setScrollMode(ScrollMode.AUTO); vert.setAdjustForScroll(true); + + setColumnMappingData(); + + container.add(vert); + container.forceLayout(); + + VerticalLayoutContainer vPanel = new VerticalLayoutContainer(); + vPanel.add(container, new VerticalLayoutData(1, -1)); + vPanel.add(flowButton, new VerticalLayoutData(1, -1, new Margins(1))); + add(vPanel); + + } + + protected void save(){ + + } + + protected void close(){ + + } + + protected void setColumnMappingData() { + final HBoxLayoutContainer horiz = new HBoxLayoutContainer(); // Source Combo @@ -249,7 +320,7 @@ public class ColumnMappingPanel extends FramedPanel { Log.debug("Clicked btnDel"); vert.remove(horiz); if (vert.getWidgetCount() == 0) { - setup(); + setColumnMappingData(); } else { } @@ -260,7 +331,179 @@ public class ColumnMappingPanel extends FramedPanel { }); btnDel.setVisible(false); + horiz.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE); + horiz.setPack(BoxLayoutPack.START); + + horiz.add(comboSourceValue, new BoxLayoutData(new Margins(2, 4, 2, 4))); + horiz.add(comboTargetValue, new BoxLayoutData(new Margins(2, 4, 2, 4))); + horiz.add(btnAdd, new BoxLayoutData(new Margins(2, 4, 2, 4))); + horiz.add(btnDel, new BoxLayoutData(new Margins(2, 4, 2, 4))); + vert.add(horiz); + } + + protected void addColumnMappingData() { + final HBoxLayoutContainer horiz = new HBoxLayoutContainer(); + + // Source Combo + DimensionRowsProperties propsSource = GWT + .create(DimensionRowsProperties.class); + ListStore storeComboSourceValue = new ListStore( + propsSource.rowId()); + + final ComboBox comboSourceValue = new ComboBox( + storeComboSourceValue, propsSource.value()); + comboSourceValue.setItemId(itemIdSourceValueArg); + + Log.debug("ComboSourceValue created"); + + final DimensionRowSelectionListener sourceValueSelectedListener = new DimensionRowSelectionListener() { + + @Override + public void selectedDimensionRow(DimensionRow dimensionRow) { + Log.debug("Source DimensionRow selected: " + dimensionRow); + comboSourceValue.setValue(dimensionRow, true); + + } + + @Override + public void abortedDimensionRowSelection() { + Log.debug("Source DimensionRow selection aborted"); + + } + + @Override + public void failedDimensionRowSelection(String reason, String detail) { + Log.error("Source DimensionRow selection error: " + reason); + + } + + }; + + comboSourceValue.addTriggerClickHandler(new TriggerClickHandler() { + + @Override + public void onTriggerClick(TriggerClickEvent event) { + Log.debug("ComboSourceValue TriggerClickEvent"); + comboSourceValue.collapse(); + + CellData cellData = new CellData("", selectedColumn.getName(), + selectedColumn.getColumnId(), + selectedColumn.getLabel(), null, 0, 0); + + DimensionRowSelectionDialog dimensionRowSelectionDialog = new DimensionRowSelectionDialog( + selectedColumn, cellData, false, eventBus); + dimensionRowSelectionDialog + .addListener(sourceValueSelectedListener); + dimensionRowSelectionDialog.show(); + + } + + }); + + comboSourceValue.setEmptyText("Select a source..."); + comboSourceValue.setWidth(COMBOWIDTH); + comboSourceValue.setEditable(false); + comboSourceValue.setTriggerAction(TriggerAction.ALL); + + //Target Combo + DimensionRowsProperties propsTarget = GWT + .create(DimensionRowsProperties.class); + ListStore storeComboTargetValue = new ListStore( + propsTarget.rowId()); + + final ComboBox comboTargetValue = new ComboBox( + storeComboTargetValue, propsTarget.value()); + comboTargetValue.setItemId(itemIdTargetValueArg); + + Log.debug("ComboTargetValue created"); + + final DimensionRowSelectionListener targetValueSelectedListener = new DimensionRowSelectionListener() { + + @Override + public void selectedDimensionRow(DimensionRow dimensionRow) { + Log.debug("Target DimensionRow selected: " + dimensionRow); + comboTargetValue.setValue(dimensionRow, true); + + } + + @Override + public void abortedDimensionRowSelection() { + Log.debug("Target DimensionRow selection aborted"); + + } + + @Override + public void failedDimensionRowSelection(String reason, String detail) { + Log.error("Target DimensionRow selection error: " + reason); + + } + + }; + + comboTargetValue.addTriggerClickHandler(new TriggerClickHandler() { + + @Override + public void onTriggerClick(TriggerClickEvent event) { + Log.debug("ComboTargetValue TriggerClickEvent"); + comboTargetValue.collapse(); + + CellData cellData = new CellData("", referenceColumn.getName(), + referenceColumn.getColumnId(), + referenceColumn.getLabel(), null, 0, 0); + + DimensionRowSelectionDialog dimensionRowSelectionDialog = new DimensionRowSelectionDialog( + referenceColumn, cellData, true, eventBus); + dimensionRowSelectionDialog + .addListener(targetValueSelectedListener); + dimensionRowSelectionDialog.show(); + + } + + }); + + comboTargetValue.setEmptyText("Select a target..."); + comboTargetValue.setWidth(COMBOWIDTH); + comboTargetValue.setEditable(false); + comboTargetValue.setTriggerAction(TriggerAction.ALL); + + + + + final IconButton btnAdd = new IconButton(); + btnAdd.setItemId(itemIdBtnAdd); + btnAdd.setIcon(ResourceBundle.INSTANCE.add()); + btnAdd.addClickHandler(new ClickHandler() { + + public void onClick(ClickEvent event) { + Log.debug("Clicked btnAdd"); + addColumnMappingData(); + thisPanel.forceLayout(); + vert.forceLayout(); + + } + }); + btnAdd.setVisible(true); + + final IconButton btnDel = new IconButton(); + btnDel.setItemId(itemIdBtnDel); + btnDel.setIcon(ResourceBundle.INSTANCE.delete()); + btnDel.addClickHandler(new ClickHandler() { + + public void onClick(ClickEvent event) { + Log.debug("Clicked btnDel"); + vert.remove(horiz); + if (vert.getWidgetCount() == 0) { + setColumnMappingData(); + } else { + + } + thisPanel.forceLayout(); + vert.forceLayout(); + + } + }); + btnDel.setVisible(false); horiz.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE); horiz.setPack(BoxLayoutPack.START); @@ -271,11 +514,6 @@ public class ColumnMappingPanel extends FramedPanel { horiz.add(btnDel, new BoxLayoutData(new Margins(2, 4, 2, 4))); vert.add(horiz); - add(vert); - } - - protected void addColumnMappingData() { - } }