package org.gcube.portlets.user.td.informationwidget.client; import java.util.HashMap; import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; import org.gcube.portlets.user.td.gwtservice.shared.tr.TRId; 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.metadatawidget.client.MetadataAccordionPanel; 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.cell.core.client.form.TextAreaInputCell.Resizable; import com.sencha.gxt.widget.core.client.FramedPanel; import com.sencha.gxt.widget.core.client.box.AlertMessageBox; 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.form.FieldLabel; import com.sencha.gxt.widget.core.client.form.FieldSet; import com.sencha.gxt.widget.core.client.form.TextArea; import com.sencha.gxt.widget.core.client.form.TextField; public class TabularResourceProperties extends FramedPanel { protected String headingTitle; protected HashMap tabularResourcePropertiesMap; protected VerticalLayoutContainer vl; protected EventBus eventBus; protected FieldSet trFieldSet; protected FieldSet tableFieldSet; protected TextField nameField; protected TextArea descriptionField; protected TextField agencyField; protected TextField dateField; protected TextArea rightField; protected TextField tableTypeNameField; protected MetadataAccordionPanel metadataPanel; protected VerticalLayoutContainer layoutTable; public TabularResourceProperties(String name, EventBus eventBus) { super(); setId(name); this.eventBus = eventBus; forceLayoutOnResize=true; vl = new VerticalLayoutContainer(); initInformation(); this.add(vl); } public void addTabularResource() { trFieldSet = new FieldSet(); trFieldSet.setHeadingText("Tabular Resource"); trFieldSet.setCollapsible(true); trFieldSet.setResize(true); VerticalLayoutContainer layoutTabularResource = new VerticalLayoutContainer(); trFieldSet.add(layoutTabularResource); nameField = new TextField(); nameField.setReadOnly(true); nameField.setValue(""); layoutTabularResource.add(new FieldLabel(nameField, "Name"), new VerticalLayoutData(1, -1)); descriptionField = new TextArea(); descriptionField.setReadOnly(true); descriptionField.setValue(""); layoutTabularResource.add(new FieldLabel(descriptionField, "Description"), new VerticalLayoutData(1, -1)); agencyField = new TextField(); agencyField.setReadOnly(true); agencyField.setValue(""); layoutTabularResource.add(new FieldLabel(agencyField, "Agency"), new VerticalLayoutData(1, -1)); dateField = new TextField(); dateField.setReadOnly(true); dateField.setValue(""); layoutTabularResource.add(new FieldLabel(dateField, "Date"), new VerticalLayoutData(1, -1)); rightField = new TextArea(); rightField.setReadOnly(true); rightField.setValue(""); layoutTabularResource.add(new FieldLabel(rightField, "Rights"), new VerticalLayoutData(1, -1)); vl.add(trFieldSet); } protected void updateTabularResource(TabResource tabResource) { nameField.setValue(tabResource.getName()); descriptionField.setValue(tabResource.getDescription()); agencyField.setValue(tabResource.getAgency()); dateField.setValue(tabResource.getDate()); rightField.setValue(tabResource.getRight()); } public void addTable() { tableFieldSet = new FieldSet(); tableFieldSet.setHeadingText("Table"); tableFieldSet.setCollapsible(true); tableFieldSet.setResize(true); layoutTable = new VerticalLayoutContainer(); tableFieldSet.add(layoutTable); tableTypeNameField = new TextField(); tableTypeNameField.setReadOnly(true); tableTypeNameField.setValue(""); layoutTable.add(new FieldLabel(tableTypeNameField, "Type"), new VerticalLayoutData(1, -1)); vl.add(tableFieldSet); } protected void updateTable(TableData tableData) { tableTypeNameField.setValue(tableData.getTypeName()); if(metadataPanel!=null){ layoutTable.remove(metadataPanel); } metadataPanel= new MetadataAccordionPanel("Information", tableData.getTrId(), eventBus); layoutTable.add(new FieldLabel(metadataPanel, "MetaData"), new VerticalLayoutData(-1, -1)); tableFieldSet.onResize(); } public void update() { TDGWTServiceAsync.INSTANCE .getTabResourceInformation(new AsyncCallback() { @Override public void onSuccess(TabResource result) { updateTabularResource(result); Log.info("Retrived TR:" + result.getId()); getLastTable(result.getTrId()); } @Override public void onFailure(Throwable caught) { AlertMessageBox d = new AlertMessageBox("Error", "Error retrienving properties: " + caught.getLocalizedMessage()); d.addHideHandler(new HideHandler() { @Override public void onHide(HideEvent event) { // } }); d.show(); } }); } protected void getLastTable(TRId trId) { TDGWTServiceAsync.INSTANCE .getLastTable(trId,new AsyncCallback() { @Override public void onSuccess(TableData result) { updateTable(result); Log.info("Retrived LastTable:" + result.getName()); } @Override public void onFailure(Throwable caught) { AlertMessageBox d = new AlertMessageBox("Error", "Error retrienving Last Table: " + caught.getLocalizedMessage()); d.addHideHandler(new HideHandler() { @Override public void onHide(HideEvent event) { // } }); d.show(); } }); } public void initInformation() { addTabularResource(); addTable(); update(); } }