/** * */ package org.gcube.portlets.user.td.mapwidget.client; import java.util.ArrayList; import java.util.Date; import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; import org.gcube.portlets.user.td.gwtservice.shared.licenses.LicenceData; import org.gcube.portlets.user.td.gwtservice.shared.map.MapCreationSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent; import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; import org.gcube.portlets.user.td.wizardwidget.client.WizardCard; import org.gcube.portlets.user.td.wizardwidget.client.util.UtilsGXT3; import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.VerticalPanel; import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction; import com.sencha.gxt.data.client.loader.RpcProxy; import com.sencha.gxt.data.shared.ListStore; import com.sencha.gxt.data.shared.loader.ListLoadConfig; import com.sencha.gxt.data.shared.loader.ListLoadConfigBean; import com.sencha.gxt.data.shared.loader.ListLoadResult; import com.sencha.gxt.data.shared.loader.ListLoadResultBean; import com.sencha.gxt.data.shared.loader.ListLoader; import com.sencha.gxt.data.shared.loader.LoadResultListStoreBinding; 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.ComboBox; import com.sencha.gxt.widget.core.client.form.DateField; 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; /** * * @author "Giancarlo Panichi" g.panichi@isti.cnr.it * */ public class MapWidgetDetailCard extends WizardCard { protected DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd"); protected final String TABLEDETAILPANELWIDTH = "100%"; protected final String TABLEDETAILPANELHEIGHT = "100%"; protected final String FORMWIDTH = "538px"; protected MapCreationSession mapCreationSession; protected MapWidgetDetailCard thisCard; protected VerticalLayoutContainer p; protected VerticalPanel tableDetailPanel; private TextField name; private TextField userName; private TextField metaAbstract; private TextField metaPurpose; private TextField metaCredits; private TextField metaKeywords; protected ListLoader> loader; protected ComboBox comboLicences; public MapWidgetDetailCard(final MapCreationSession mapCreationSession) { super("Tabular Resource Detail", ""); this.mapCreationSession = mapCreationSession; thisCard = this; tableDetailPanel = new VerticalPanel(); tableDetailPanel.setSpacing(4); tableDetailPanel.setWidth(TABLEDETAILPANELWIDTH); tableDetailPanel.setHeight(TABLEDETAILPANELHEIGHT); FramedPanel form = new FramedPanel(); form.setHeadingText("Details"); form.setWidth(FORMWIDTH); FieldSet fieldSet = new FieldSet(); fieldSet.setHeadingText("Information"); fieldSet.setCollapsible(false); form.add(fieldSet); p = new VerticalLayoutContainer(); fieldSet.add(p); name = new TextField(); name.setAllowBlank(false); name.setEmptyText("Enter a name..."); name.setValue(mapCreationSession.getName()); p.add(new FieldLabel(name, "Name"), new VerticalLayoutData(1, -1)); userName = new TextField(); userName.setAllowBlank(false); userName.setEmptyText("Enter a user name..."); userName.setValue(mapCreationSession.getUsername()); p.add(new FieldLabel(userName, "User Name"), new VerticalLayoutData(1, -1)); metaAbstract = new TextField(); metaAbstract.setAllowBlank(false); metaAbstract.setEmptyText("Enter a abstract..."); metaAbstract.setValue(""); p.add(new FieldLabel(metaAbstract, "Abstract"), new VerticalLayoutData(1, -1)); metaPurpose = new TextField(); metaPurpose.setAllowBlank(false); metaPurpose.setEmptyText("Enter a purpose..."); metaPurpose.setValue(""); p.add(new FieldLabel(metaPurpose, "Purpose"), new VerticalLayoutData(1, -1)); metaCredits = new TextField(); metaCredits.setAllowBlank(false); metaCredits.setEmptyText("Enter credits..."); metaCredits.setValue(""); p.add(new FieldLabel(metaCredits, "Credits"), new VerticalLayoutData(1, -1)); metaKeywords = new TextField(); metaKeywords.setAllowBlank(false); metaKeywords.setEmptyText("Enter keywords..."); metaKeywords.setValue(""); p.add(new FieldLabel(metaKeywords, "Keywords"), new VerticalLayoutData(1, -1)); tableDetailPanel.add(form); setContent(tableDetailPanel); } protected void loadData(ListLoadConfig loadConfig, final AsyncCallback> callback) { TDGWTServiceAsync.INSTANCE .getLicences(new AsyncCallback>() { public void onFailure(Throwable caught) { if (caught instanceof TDGWTSessionExpiredException) { getEventBus() .fireEvent( new SessionExpiredEvent( SessionExpiredType.EXPIREDONSERVER)); } else { Log.error("load combo failure:" + caught.getLocalizedMessage()); UtilsGXT3.alert("Error", "Error retrieving licences."); } callback.onFailure(caught); } public void onSuccess(ArrayList result) { Log.trace("loaded " + result.size() + " ColumnData"); callback.onSuccess(new ListLoadResultBean( result)); } }); } @Override public void setup() { Command sayNextCard = new Command() { public void execute() { checkData(); } }; getWizardWindow().setNextButtonCommand(sayNextCard); Command sayPreviousCard = new Command() { public void execute() { try { getWizardWindow().previousCard(); getWizardWindow().removeCard(thisCard); Log.info("Remove CSVTableDetailCard"); } catch (Exception e) { Log.error("sayPreviousCard :" + e.getLocalizedMessage()); } } }; getWizardWindow().setPreviousButtonCommand(sayPreviousCard); getWizardWindow().setEnableNextButton(true); } protected void checkData() { getWizardWindow().setEnableNextButton(false); getWizardWindow().setEnableBackButton(false); AlertMessageBox d; HideHandler hideHandler = new HideHandler() { public void onHide(HideEvent event) { getWizardWindow().setEnableNextButton(true); getWizardWindow().setEnableBackButton(false); } }; if (name.getValue() == null || name.getValue().isEmpty() || !name.isValid()) { d = new AlertMessageBox("Attention!", "Fill in name field"); d.addHideHandler(hideHandler); d.show(); } else { name.setReadOnly(true); goNext(); } } protected void goNext() { try { /* detail= new TabResource(); detail.setName(name.getCurrentValue()); detail.setDescription(description.getCurrentValue()); detail.setRight(rights.getCurrentValue()); Date vFrom = validFrom.getCurrentValue(); if (vFrom == null) { Log.debug("Valid From is null"); } else { try { detail.setValidFrom(sdf.format(vFrom)); } catch (Throwable e) { Log.error("Error parsing Valid From " + e.getLocalizedMessage()); } } Date vUntilTo = validUntilTo.getCurrentValue(); if (vUntilTo == null) { Log.debug("Valid Until To is null"); } else { try { detail.setValidUntilTo(sdf.format(vUntilTo)); } catch (Throwable e) { Log.error("Error parsing Valid Until To " + e.getLocalizedMessage()); } } if(comboLicences.getCurrentValue()!=null&& comboLicences.getCurrentValue().getLicence()!=null && !comboLicences.getCurrentValue().getLicence().isEmpty()){ detail.setLicence(comboLicences.getCurrentValue().getLicence()); } mapCreationSession.setTabResource(detail); */ MapWidgetOperationInProgressCard mapWidgetOperationInProgressCard = new MapWidgetOperationInProgressCard( mapCreationSession); getWizardWindow().addCard(mapWidgetOperationInProgressCard); Log.info("NextCard MapWidgetOperationInProgressCard"); getWizardWindow().nextCard(); } catch (Exception e) { Log.error("sayNextCard :" + e.getLocalizedMessage()); e.printStackTrace(); } } }