package org.gcube.portlets.widgets.wsthreddssync.client.view.binder; import java.util.HashMap; import java.util.List; import java.util.Map; import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; import org.gcube.portlets.widgets.wsthreddssync.client.WsThreddsWidget; import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeVRE; import org.gcube.portlets.widgets.wsthreddssync.shared.WsFolder; import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor; import com.github.gwtbootstrap.client.ui.ControlGroup; import com.github.gwtbootstrap.client.ui.ListBox; import com.github.gwtbootstrap.client.ui.Pager; import com.github.gwtbootstrap.client.ui.TextBox; import com.github.gwtbootstrap.client.ui.constants.ControlGroupType; 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.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Widget; // TODO: Auto-generated Javadoc /** * The Class ShowThreddsFolderInfoView. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * Feb 15, 2018 */ public abstract class ShowThreddsFolderInfoView extends Composite { private static final String DATE_FORMAT_YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; /** The ui binder. */ private static ShowThreddsFolderInfoViewUiBinder uiBinder = GWT.create(ShowThreddsFolderInfoViewUiBinder.class); /** * The Interface ShowThreddsFolderInfoViewUiBinder. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * Feb 15, 2018 */ interface ShowThreddsFolderInfoViewUiBinder extends UiBinder { } @UiField TextBox field_folder_status; @UiField ListBox field_select_vre; @UiField TextBox field_catalogue_name; @UiField TextBox field_remote_path; @UiField TextBox field_folder_path; @UiField TextBox field_folder_locked; /*@UiField TextBox field_last_sync; */ @UiField ControlGroup cg_catalogue_name; @UiField ControlGroup cg_remote_path; @UiField HTMLPanel form_unit_fields; @UiField Pager pager; /** The folder id. */ private String folderId; /** The map VR es. */ private Map mapVREs = new HashMap(); private boolean isCreateConfiguration; public static enum SUBMIT_ACTION {CREATE_UPDATE_CONFIGURATION, DO_SYNC}; /** * Submit handler. */ public abstract void submitHandler(SUBMIT_ACTION action); /** * Sets the error. * * @param visible the visible * @param error the error */ public abstract void setError(boolean visible, String error); /** * Because this class has a default constructor, it can * be used as a binder template. In other words, it can be used in other * *.ui.xml files as follows: * * Hello! * * Note that depending on the widget that is used, it may be necessary to * implement HasHTML instead of HasText. * * @param folderId the folder id * @param isCreateConfiguration the is create configuration */ public ShowThreddsFolderInfoView(String folderId, boolean isCreateConfiguration) { this.folderId = folderId; this.isCreateConfiguration = isCreateConfiguration; initWidget(uiBinder.createAndBindUi(this)); pager.getLeft().addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { setError(false, ""); submitHandler(SUBMIT_ACTION.CREATE_UPDATE_CONFIGURATION); } }); pager.getRight().addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { setError(false, ""); //boolean isValid = validateSubmit(); //if(isValid) submitHandler(SUBMIT_ACTION.DO_SYNC); } }); if(isCreateConfiguration) { WsThreddsWidget.wsThreddsSyncService.getListOfVREsForLoggedUser(new AsyncCallback>() { @Override public void onSuccess(List result) { for (GcubeVRE gcubeVRE : result) { mapVREs.put(gcubeVRE.getVreScope(), gcubeVRE); field_select_vre.addItem(gcubeVRE.getVreScope(), gcubeVRE.getVreName()); } } @Override public void onFailure(Throwable caught) { // TODO Auto-generated method stub } }); } } /** * Update view to result. * * @param folder the folder * @param syncFolderDesc the sync folder desc */ public void updateViewToResult(WsFolder folder, WsThreddsSynchFolderDescriptor syncFolderDesc) { this.field_select_vre.clear(); if(syncFolderDesc==null) { pager.getRight().setVisible(false); return; } if(syncFolderDesc.getSyncStatus()!=null) { this.field_folder_status.setValue(syncFolderDesc.getSyncStatus().toString()); } if(syncFolderDesc.getSelectedVRE()!=null) { this.field_select_vre.addItem(syncFolderDesc.getSelectedVRE().getVreScope(), syncFolderDesc.getSelectedVRE().getVreName()); this.field_select_vre.setValue(0, syncFolderDesc.getSelectedVRE().getVreName()); this.field_select_vre.setSelectedValue(syncFolderDesc.getSelectedVRE().getVreName()); } ThSyncFolderDescriptor sfd = syncFolderDesc.getServerFolderDescriptor(); if(sfd!=null) { this.field_folder_path.setValue(sfd.getFolderPath()); this.field_folder_path.setTitle(sfd.getFolderPath()); this.field_folder_locked.setValue(sfd.isLocked()+""); ThSynchFolderConfiguration config = sfd.getConfiguration(); if(config!=null) { this.field_catalogue_name.setValue(config.getToCreateCatalogName()); this.field_catalogue_name.setTitle(config.getToCreateCatalogName()); this.field_remote_path.setValue(config.getRemotePath()); this.field_remote_path.setTitle(config.getRemotePath()); } ThProcessDescriptor lpd = sfd.getLocalProcessDescriptor(); if(lpd!=null) { //this.field_last_sync.setValue(DateTimeFormat.getFormat(DATE_FORMAT_YYYY_MM_DD_HH_MM_SS).format(new Date(lpd.getLaunchTime()))); ThSynchFolderConfiguration sc = lpd.getSynchConfiguration(); if(sc!=null) { //this.field_select_vre.setValue(sc.get, value); } } } } public boolean isCreateConfiguration() { return isCreateConfiguration; } /** * Validate submit. * * @return true, if successful */ protected boolean validateSubmit() { cg_catalogue_name.setType(ControlGroupType.NONE); cg_remote_path.setType(ControlGroupType.NONE); if(field_catalogue_name.getValue()==null || field_catalogue_name.getValue().isEmpty()){ cg_catalogue_name.setType(ControlGroupType.ERROR); setError(true, "Unit Title field is required"); return false; } if(field_remote_path.getValue()==null || field_remote_path.getValue().isEmpty()){ cg_remote_path.setType(ControlGroupType.ERROR); setError(true, "Folder Name field is required"); return false; } return true; } /** * Gets the remote path. * * @return the remote path */ public String getRemotePath() { return field_remote_path.getValue(); } /** * Gets the catalogue name. * * @return the catalogue name */ public String getCatalogueName(){ return field_catalogue_name.getValue(); } /** * Gets the unit description. * * @return the unit description */ public GcubeVRE getSelectedVRE(){ String item = field_select_vre.getSelectedItemText(); String text = field_select_vre.getSelectedValue(); return mapVREs.get(item); } public Pager getPager() { return pager; } public HTMLPanel getMainPanel(){ return form_unit_fields; } }