diff --git a/src/main/java/org/gcube/portlets/user/td/informationwidget/client/TabularResourceProperties.java b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/TabularResourceProperties.java index 4607275..274efac 100644 --- a/src/main/java/org/gcube/portlets/user/td/informationwidget/client/TabularResourceProperties.java +++ b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/TabularResourceProperties.java @@ -5,6 +5,7 @@ import java.util.HashMap; import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; import org.gcube.portlets.user.td.gwtservice.shared.tr.TableData; +import org.gcube.portlets.user.td.informationwidget.client.util.InfoMessageBox; import org.gcube.portlets.user.td.metadatawidget.client.TRMetadataAccordionPanel; import org.gcube.portlets.user.td.metadatawidget.client.TableMetadataAccordionPanel; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; @@ -13,12 +14,16 @@ import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.web.bindery.event.shared.EventBus; import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode; +import com.sencha.gxt.core.client.util.Margins; import com.sencha.gxt.widget.core.client.FramedPanel; import com.sencha.gxt.widget.core.client.box.AlertMessageBox; +import com.sencha.gxt.widget.core.client.button.TextButton; 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.HideEvent; import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler; +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.form.FieldLabel; import com.sencha.gxt.widget.core.client.form.FieldSet; import com.sencha.gxt.widget.core.client.form.TextArea; @@ -33,30 +38,32 @@ public class TabularResourceProperties extends FramedPanel { protected FieldSet trFieldSet; protected FieldSet tableFieldSet; + protected TabResource tabResource; protected TextField nameField; protected TextArea descriptionField; protected TextField agencyField; protected TextField dateField; protected TextArea rightField; - + protected TRMetadataAccordionPanel trMetadataPanel; protected VerticalLayoutContainer layoutTabularResource; protected TextField tableTypeNameField; protected TableMetadataAccordionPanel tableMetadataPanel; protected VerticalLayoutContainer layoutTable; + protected TextButton saveButton; public TabularResourceProperties(String name, EventBus eventBus) { super(); setId(name); this.eventBus = eventBus; - forceLayoutOnResize=true; + forceLayoutOnResize = true; vl = new VerticalLayoutContainer(); vl.setScrollMode(ScrollMode.AUTO); vl.setAdjustForScroll(true); - initInformation(); + initInformation(); this.add(vl); } @@ -100,18 +107,32 @@ public class TabularResourceProperties extends FramedPanel { layoutTabularResource.add(new FieldLabel(rightField, "Rights"), new VerticalLayoutData(1, -1)); + // Save Button + saveButton = new TextButton("Save"); + SelectHandler saveHandler = new SelectHandler() { + + public void onSelect(SelectEvent event) { + onSave(); + + } + }; + saveButton.addSelectHandler(saveHandler); + layoutTabularResource.add(saveButton, + new VerticalLayoutData(-1, -1,new Margins(2))); + vl.add(trFieldSet); } protected void updateTabularResource(TabResource tabResource) { + this.tabResource=tabResource; Log.debug(tabResource.toString()); nameField.setValue(tabResource.getName()); descriptionField.setValue(tabResource.getDescription()); agencyField.setValue(tabResource.getAgency()); dateField.setValue(tabResource.getDate()); rightField.setValue(tabResource.getRight()); - + } public void addTable() { @@ -119,7 +140,7 @@ public class TabularResourceProperties extends FramedPanel { tableFieldSet.setHeadingText("Table"); tableFieldSet.setCollapsible(true); tableFieldSet.setResize(true); - + layoutTable = new VerticalLayoutContainer(); tableFieldSet.add(layoutTable); @@ -128,30 +149,29 @@ public class TabularResourceProperties extends FramedPanel { tableTypeNameField.setReadOnly(true); tableTypeNameField.setValue(""); layoutTable.add(new FieldLabel(tableTypeNameField, "Type"), - new VerticalLayoutData(1, -1)); - + new VerticalLayoutData(1, -1)); + vl.add(tableFieldSet); } - + protected void updateTable(TableData tableData) { tableTypeNameField.setValue(tableData.getTypeName()); - if(tableMetadataPanel!=null){ + if (tableMetadataPanel != null) { tableFieldSet.remove(layoutTable); layoutTable.remove(tableMetadataPanel); } - TRId trId=tableData.getTrId(); - - tableMetadataPanel= new TableMetadataAccordionPanel("TableInformation", trId, eventBus); + TRId trId = tableData.getTrId(); + + tableMetadataPanel = new TableMetadataAccordionPanel( + "TableInformation", trId, eventBus); layoutTable.add(tableMetadataPanel, new VerticalLayoutData(-1, -1)); tableFieldSet.add(layoutTable); } - public void update() { TDGWTServiceAsync.INSTANCE .getTabResourceInformation(new AsyncCallback() { - public void onSuccess(TabResource result) { updateTabularResource(result); Log.info("Retrived TR:" + result.getId()); @@ -176,11 +196,10 @@ public class TabularResourceProperties extends FramedPanel { }); } - protected void getLastTable(TRId trId) { - TDGWTServiceAsync.INSTANCE - .getLastTable(trId,new AsyncCallback() { + TDGWTServiceAsync.INSTANCE.getLastTable(trId, + new AsyncCallback() { public void onSuccess(TableData result) { updateTable(result); @@ -206,11 +225,62 @@ public class TabularResourceProperties extends FramedPanel { }); } - + public void initInformation() { addTabularResource(); addTable(); update(); } + + + protected void onSave(){ + + /*TDGWTServiceAsync.INSTANCE.setTabResourceInfo(tabResource, + new AsyncCallback() { + + public void onFailure(Throwable caught) { + Log.debug("Share Error: " + + caught.getLocalizedMessage()); + alert("Error sharing tabular resource", + "Error shareing tabular resource"); + + } + + public void onSuccess(Void result) { + Log.debug("Tabular Resource Shared: " + + shareInfo.getTabResource().getTrId() + .toString()); + info("Shared", + "Tabular Resource is shared"); + + } + + }); + */ + } + + private void alert(String title, String message) { + final AlertMessageBox d = new AlertMessageBox(title, message); + d.addHideHandler(new HideHandler() { + + public void onHide(HideEvent event) { + + } + }); + d.show(); + + } + + private void info(String title, String message) { + final InfoMessageBox d = new InfoMessageBox(title, message); + d.addHideHandler(new HideHandler() { + + public void onHide(HideEvent event) { + + } + }); + d.show(); + + } } diff --git a/src/main/java/org/gcube/portlets/user/td/informationwidget/client/util/InfoMessageBox.java b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/util/InfoMessageBox.java new file mode 100644 index 0000000..fa9461e --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/util/InfoMessageBox.java @@ -0,0 +1,22 @@ +package org.gcube.portlets.user.td.informationwidget.client.util; + +import com.sencha.gxt.widget.core.client.box.MessageBox; + +public class InfoMessageBox extends MessageBox { + + /** + * Creates a message box with an info icon and the specified title and + * message. + * + * @param title + * the message box title + * @param message + * the message displayed in the message box + */ + public InfoMessageBox(String title, String message) { + super(title, message); + + setIcon(ICONS.info()); + } + +} \ No newline at end of file