package org.gcube.portlets.user.speciesdiscovery.client.cluster; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import org.gcube.portlets.user.speciesdiscovery.client.SpeciesDiscovery; import org.gcube.portlets.user.speciesdiscovery.client.resources.Resources; import org.gcube.portlets.user.speciesdiscovery.client.util.TaxonomyGridField; import org.gcube.portlets.user.speciesdiscovery.shared.CommonName; import org.gcube.portlets.user.speciesdiscovery.shared.ItemParameter; import org.gcube.portlets.user.speciesdiscovery.shared.TaxonomyRow; import org.gcube.portlets.user.speciesdiscovery.shared.util.NormalizeString; import com.allen_sauer.gwt.log.client.Log; import com.extjs.gxt.ui.client.widget.ContentPanel; import com.extjs.gxt.ui.client.widget.Html; import com.extjs.gxt.ui.client.widget.Info; import com.extjs.gxt.ui.client.widget.LayoutContainer; import com.extjs.gxt.ui.client.widget.TabPanel; import com.extjs.gxt.ui.client.widget.Text; import com.extjs.gxt.ui.client.widget.VerticalPanel; import com.extjs.gxt.ui.client.widget.layout.ColumnLayout; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.shared.EventBus; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.AbstractImagePrototype; import com.google.gwt.user.client.ui.Anchor; import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Label; /** * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * */ public class TabItemForTaxonomyRow { private TabPanel tabPanel; private AbstractImagePrototype imageLoading = AbstractImagePrototype.create(Resources.INSTANCE.loadingBalls()); private EventBus eventBus; // private List parents = null; private TablesForTaxonomyRow tablesForTaxonomyRow; private TaxonomyRow currentTaxonomy; public void setCurrentTaxonomy(TaxonomyRow taxonomy){ this.currentTaxonomy = taxonomy; } public TabItemForTaxonomyRow(TablesForTaxonomyRow tablesForTaxonomyRow, TabPanel tabPanel2, EventBus eventBus2) { this.tablesForTaxonomyRow = tablesForTaxonomyRow; this.tabPanel = tabPanel2; this.eventBus = eventBus2; } /** * * @param taxonomy * @param isNewTab - set true if has been clicked a classification link, or false otherwise * @return */ public VerticalPanel getPanelClassificationForTaxonomy(TaxonomyRow taxonomy, String dataSource, boolean isNewTab){ VerticalPanel vpClassification = new VerticalPanel(); vpClassification.setSpacing(5); if(taxonomy!=null){ //CREATE CLASSIFICATION FOR PARENT ITEM int parentsSize = taxonomy.getParents().size(); for(int i=parentsSize-1; i>=0; i--){ createPanelForParentTaxonomy(taxonomy.getParents().get(i), vpClassification, taxonomy.getServiceId(), isNewTab, dataSource, i+1); } //CREATE CLASSIFICATION FOR ITEM createPanelForParentTaxonomy(taxonomy, vpClassification, taxonomy.getServiceId(), isNewTab, dataSource, 0); } return vpClassification; } /** * Create a scientific classification: for each parent rank create a link, for current search item create a label * @param taxon * @param vpClassification * @param taxonomyServiceId * @param isNewTab * @param parentIndex */ public void createPanelForParentTaxonomy(TaxonomyRow taxon, VerticalPanel vpClassification, String taxonomyServiceId, boolean isNewTab, String dataSource, int parentIndex){ if(taxon==null) return; // createPanelForParentTaxonomy(taxon.getParents(), vpClassification, taxonomyServiceId, isNewTab, dataSource); HorizontalPanel hp = new HorizontalPanel(); Text labelRank; if(!NormalizeString.isUndefined(taxon.getRank())) labelRank = new Text(taxon.getRank()+":"); else labelRank = new Text("Rank not found"+":"); // labelRank.setStyleAttribute("margin-right", "10px"); hp.add(labelRank); hp.setCellWidth(labelRank, "120px"); Anchor anchor = getAnchorByTaxonomy(taxon, dataSource, parentIndex); hp.add(anchor); hp.setCellHorizontalAlignment(anchor, HorizontalPanel.ALIGN_LEFT); vpClassification.add(hp); //DEBUG // System.out.println("taxon.getName()" +taxon.getName() + " serviceid : "+taxon.getServiceId() + " taxonomyServiceId "+taxonomyServiceId); // System.out.println("taxon.getServiceId().compareTo(taxonomyServiceId)==0 "+ taxon.getServiceId().compareTo(taxonomyServiceId)); // System.out.println("isNewTab"+ isNewTab); if((taxon.getServiceId().compareTo(taxonomyServiceId)==0) && isNewTab){ loadChildrenListOfItem(vpClassification, taxon, dataSource, taxon.getName(), -1); //parentIndex == -1 means that parent is currentTaxonomy } } private void loadChildrenListOfItem(final VerticalPanel vpClassification, final TaxonomyRow taxonomyItem, final String dataSource, final String parentName, final int parentIndex){ final ContentPanel cp = new ContentPanel(); cp.setId("cp" + taxonomyItem.getId()); cp.setHeaderVisible(false); cp.setBodyBorder(false); cp.add(imageLoading.createImage()); vpClassification.add(cp); //FOR DEBUG // TaxonomyRow printParent = taxonomyItem; System.out.println("Load child of item name: " + parentName + " parent id: " + taxonomyItem.getServiceId()); // while(printParent!=null){ // // System.out.println("Parent Name: " + printParent.getName() + " parent id: " +printParent.getServiceId()); // printParent = printParent.getParent(); // } SpeciesDiscovery.taxonomySearchService.loadListChildByParentId(taxonomyItem.getServiceId(), new AsyncCallback>() { @Override public void onSuccess(ArrayList result) { Log.trace("Children returned in client: " + result.size() + " for parentName " +parentName); LayoutContainer lc = new LayoutContainer(); lc.setLayout(new ColumnLayout()); vpClassification.remove(cp); HorizontalPanel hp = new HorizontalPanel(); Text labelRank = new Text("Rank not found:"); hp.add(labelRank); hp.setCellWidth(labelRank, "120px"); boolean setRank = false; if(result.size()>0){ for (int i=0; i"+taxon.getName()+"", true); anchor.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { System.out.println("parent index: "+parentIndex + " size "+currentTaxonomy.getParents().size()); if(parentIndex >=0 && parentIndex<=currentTaxonomy.getParents().size()){ System.out.println("set parent true"); taxon.setParent(currentTaxonomy.getParents().subList(parentIndex, currentTaxonomy.getParents().size())); } else if(parentIndex == -1){ //items loaded from get children - the current Taxonomy item is the parent List list = new ArrayList(); list.add(currentTaxonomy); list.addAll(currentTaxonomy.getParents()); System.out.println("parentIndex == -1"); printParents(taxon); taxon.setParent(list); } printParents(taxon); tablesForTaxonomyRow.addTabItem(taxon, dataSource); } }); } return anchor; } void printParents(TaxonomyRow taxon){ System.out.println("principal "+taxon.getName()); int i = 0; for (TaxonomyRow tax : taxon.getParents()) { System.out.println(++i + " parent name " + tax.getName()); } } private Text getLabelByTaxonomy(final TaxonomyRow taxon) { Text label = null; if(taxon!=null){ if(!NormalizeString.isUndefined(taxon.getName())) label = new Text(taxon.getName()); else label = new Text("Name not found"); } return label; } public Html getHTMLTableForTaxonomy(TaxonomyRow row, boolean isNewTab){ //Init values String dataProviderName = ""; String dataSetCitation= ""; String matchingAccordionTo= ""; String rank= ""; // String matchingCredits= ""; String statusName = ""; String dateModified = ""; String statusRemark = ""; String author = ""; String lsid = ""; String credits = ""; String propertiesHtml = ""; if(row.getDataProviderName()!=null) dataProviderName = row.getDataProviderName(); if(row.getStatusName()!=null) statusName = row.getStatusName(); if(row.getDateModified()!=null) dateModified = row.getDateModified(); if(row.getDataSetCitation()!=null) dataSetCitation = row.getDataSetCitation(); if(row.getRank()!=null) rank = row.getRank(); if(row.getAccordingTo()!=null) matchingAccordionTo = row.getAccordingTo(); if(row.getStatusRemarks()!=null) statusRemark = row.getStatusRemarks(); if(row.getAuthor()!=null) author = row.getAuthor(); if(row.getLsid()!=null) lsid = row.getLsid(); if(row.getCredits()!=null) credits = row.getCredits(); if(row.getProperties()!=null){ List hashProperties = row.getProperties(); Collections.sort(hashProperties, ItemParameter.COMPARATOR); propertiesHtml+=""; for (ItemParameter itemParameter : hashProperties) { propertiesHtml+= "" + " " + " " + ""; } propertiesHtml+="
"+itemParameter.getKey()+""+itemParameter.getValue()+"
"; } //Create list common name String commonNames = ""; // if(isNewTab){ if(row.getCommonNames()!=null){ for (CommonName comName : row.getCommonNames()) { commonNames+= ""+comName.getName()+"" +" ("+comName.getLanguage()+") - "; } } // } String table = ""; // if(isNewTab) table+= "" + " " + " " + ""; table+="" + " " + " " + "" + "" + " " + " " + "" + "" + " " + " " + "" + "" + " " + " " + "" + "" + " " + " " + "" + "" + " " + " " + "" + // "" + // " " + // " " + // "" + "" + " " + " " + "" + "" + " " + " " + "" + "" + " " + " " + "" + "" + " " + " " + "" + "
"+TaxonomyGridField.COMMON_NAMES.getName()+" (Language)"+commonNames+"
"+TaxonomyGridField.STATUSREFNAME.getName()+""+statusName+"
"+TaxonomyGridField.STATUS_REMARKS.getName()+""+statusRemark+"
"+TaxonomyGridField.DATASOURCE.getName()+""+dataProviderName+"
"+TaxonomyGridField.DATEMODIFIED.getName()+""+dateModified+"
"+TaxonomyGridField.MATCHING_RANK.getName()+""+rank+"
"+TaxonomyGridField.CITATION.getName()+""+dataSetCitation+"
"+TaxonomyGridField.MATCHING_AUTHOR.getName()+""+matchingAccordionTo+"
"+TaxonomyGridField.LSID.getName()+""+lsid+"
"+TaxonomyGridField.AUTHOR.getName()+""+author+"
"+TaxonomyGridField.CREDITS.getName()+""+credits+"
"+TaxonomyGridField.PROPERTIES.getName()+""+propertiesHtml+"
"; return new Html(table); } public FlexTable getHTMLTableForTaxonomyWithRef(final TaxonomyRow row,boolean isNewTab, final String dataSource) { // Init values String dataProviderName = ""; String dataSetCitation = ""; String matchingAccordionTo = ""; String rank = ""; // String matchingCredits= ""; String statusName = ""; String dateModified = ""; String statusRemark = ""; String author = ""; String lsid = ""; String credits = ""; String refId = null; String propertiesHtml = ""; if (row.getDataProviderName() != null) dataProviderName = row.getDataProviderName(); if (row.getStatusName() != null) statusName = row.getStatusName(); if (row.getDateModified() != null) dateModified = row.getDateModified(); if (row.getDataSetCitation() != null) dataSetCitation = row.getDataSetCitation(); if (row.getRank() != null) rank = row.getRank(); if (row.getAccordingTo() != null) matchingAccordionTo = row.getAccordingTo(); if (row.getStatusRemarks() != null) statusRemark = row.getStatusRemarks(); if (row.getAuthor() != null) author = row.getAuthor(); if (row.getLsid() != null) lsid = row.getLsid(); if (row.getCredits() != null) credits = row.getCredits(); if (row.getStatusRefId() != null && !row.getStatusRefId().isEmpty()) refId = row.getStatusRefId(); if (row.getProperties() != null) { List hashProperties = row.getProperties(); Collections.sort(hashProperties, ItemParameter.COMPARATOR); propertiesHtml += ""; for (ItemParameter itemParameter : hashProperties) { propertiesHtml += "" + " " + " " + ""; } propertiesHtml += "
" + itemParameter.getKey() + "" + itemParameter.getValue() + "
"; } // Create list common name String commonNames = ""; // if(isNewTab){ if (row.getCommonNames() != null) { for (CommonName comName : row.getCommonNames()) { commonNames += "" + comName.getName() + "" + " (" + comName.getLanguage() + ") - "; } } // } final FlexTable flexTable = new FlexTable(); flexTable.setStyleName("imagetable"); flexTable.setWidget(0, 0,new Label(TaxonomyGridField.COMMON_NAMES.getName())); flexTable.setWidget(0, 1, new Html(commonNames)); flexTable.setWidget(1, 0,new Label(TaxonomyGridField.STATUSREFNAME.getName())); flexTable.setWidget(1, 1, new Label(statusName)); if (refId != null) { final String status; if(!statusRemark.isEmpty()) status = statusRemark; else status = statusName; final String referenceId = refId; flexTable.setWidget(2, 0, new Label(TaxonomyGridField.STATUS_REMARKS.getName())); AbstractImagePrototype synonyms = AbstractImagePrototype.create(Resources.INSTANCE.getSearch()); final Image imageStatusRemark = synonyms.createImage(); imageStatusRemark.setStyleName("image-load-synonyms"); imageStatusRemark.setAltText("show accepted name"); imageStatusRemark.setTitle("show accepted name"); final LayoutContainer layoutContainer = new LayoutContainer(); final Label labelStatusRemark = new Label(statusRemark); labelStatusRemark.addStyleName("status-of"); layoutContainer.add(labelStatusRemark); imageStatusRemark.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { flexTable.remove(layoutContainer); if(row.getParents().size()>0) getTaxonomyByReferenceId(flexTable, 2, 1, status, referenceId, dataSource, row.getParents()); } }); layoutContainer.add(labelStatusRemark); layoutContainer.add(imageStatusRemark); flexTable.setWidget(2, 1, layoutContainer); } else { flexTable.setWidget(2, 0, new Label(TaxonomyGridField.STATUS_REMARKS.getName())); flexTable.setWidget(2, 1, new Label(statusRemark)); } //Create row get synonyms flexTable.setWidget(3, 0,new Label(TaxonomyGridField.SYNONYMS.getName())); AbstractImagePrototype synonyms = AbstractImagePrototype.create(Resources.INSTANCE.getSearch()); final Image imageSynonyms = synonyms.createImage(); imageSynonyms.setStyleName("image-load-synonyms"); imageSynonyms.setAltText("show synonyms"); imageSynonyms.setTitle("show synonyms"); imageSynonyms.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { flexTable.remove(imageSynonyms); // DEBUG // System.out.println("getSynonyms of "+row.getName() + " serviceId "+row.getServiceId()); if(row.getParents().size()>0){ //TODO getSynonymsByReferenceId(flexTable, 3, 1, row.getServiceId(),dataSource, row.getParents()); } } }); flexTable.setWidget(3, 1, imageSynonyms); flexTable.setWidget(4, 0,new Label(TaxonomyGridField.DATASOURCE.getName())); flexTable.setWidget(4, 1, new Label(dataProviderName)); flexTable.setWidget(5, 0,new Label(TaxonomyGridField.DATEMODIFIED.getName())); flexTable.setWidget(5, 1, new Label(dateModified)); flexTable.setWidget(6, 0, new Label(TaxonomyGridField.MATCHING_RANK.getName())); flexTable.setWidget(6, 1, new Label(rank)); flexTable.setWidget(7, 0, new Label(TaxonomyGridField.CITATION.getName())); flexTable.setWidget(7, 1, new Label(dataSetCitation)); flexTable.setWidget(8, 0, new Label(TaxonomyGridField.LSID.getName())); flexTable.setWidget(8, 1, new Label(lsid)); flexTable .setWidget(9, 0, new Label(TaxonomyGridField.AUTHOR.getName())); flexTable.setWidget(9, 1, new Label(author)); flexTable.setWidget(10, 0, new Label(TaxonomyGridField.CREDITS.getName())); flexTable.setWidget(10, 1, new Label(credits)); flexTable.setWidget(11, 0, new Label(TaxonomyGridField.PROPERTIES.getName())); flexTable.setWidget(11, 1, new Html(propertiesHtml)); for (int i = 0; i < flexTable.getRowCount(); i++) { flexTable.getFlexCellFormatter().setStyleName(i, 0, "title"); } return flexTable; } public void getSynonymsByReferenceId(FlexTable flexTable, int row, int col, String refId, final String dataSource, final List parents){ final LayoutContainer layoutContainer = new LayoutContainer(); final Image loading = AbstractImagePrototype.create(Resources.INSTANCE.loadingBalls()).createImage(); layoutContainer.add(loading); flexTable.setWidget(row, col, layoutContainer); SpeciesDiscovery.taxonomySearchService.retrieveSynonymsByRefId(refId, new AsyncCallback>() { @Override public void onFailure(Throwable caught) { Info.display("Error laoding child", "An error occurred in loading, retry."); Log.error("Error laoding child", "An error occurred in loading, retry." +caught); } @Override public void onSuccess(List result) { Log.trace("getReferenceById return " +result.size() + " items"); // System.out.println("getReferenceById return " +result.size() + " items"); if(result.size()>0){ layoutContainer.remove(loading); LayoutContainer lc = new LayoutContainer(); lc.setLayout(new ColumnLayout()); if(result.size()>0){ for (int i=0; i parents){ final LayoutContainer layoutContainer = new LayoutContainer(); // hp.getElement().getStyle().setBorderStyle(BorderStyle.NONE); // hp.getElement().getStyle().setBorderWidth(0, Unit.PX); final Label status = new Label(statusRemark); layoutContainer.add(status); // hp.setCellWidth(status, "160px"); final Image loading = AbstractImagePrototype.create(Resources.INSTANCE.loadingBalls()).createImage(); layoutContainer.add(loading); flexTable.setWidget(row, col, layoutContainer); List listId = new ArrayList(); listId.add(refId); SpeciesDiscovery.taxonomySearchService.retrieveTaxonomyByIds(listId, new AsyncCallback>() { @Override public void onFailure(Throwable caught) { Info.display("Error laoding child", "An error occurred in loading, retry."); Log.error("Error laoding child", "An error occurred in loading, retry." +caught); } @Override public void onSuccess(List result) { Log.trace("getReferenceById return " +result.size() + " items"); // System.out.println("getReferenceById return " +result.size() + " items"); if(result.size()>0){ layoutContainer.remove(status); layoutContainer.remove(loading); Label labelOf = new Label(statusRemark + " for "); layoutContainer.add(labelOf); LayoutContainer lc = new LayoutContainer(); lc.setLayout(new ColumnLayout()); if(result.size()>0){ for (int i=0; i

" + taxon.getName() + "


")); // contentPanel.add(new Html("

Scientific Classification


")); // // contentPanel.add(getPanelClassificationForTaxonomy(taxon, dataSource, isNewTab)); // // contentPanel.add(getHTMLTableForTaxonomyWithRef(taxon, isNewTab, dataSource,parentIndex)); // // return contentPanel; // // } // protected void addTabItem(final TaxonomyRow taxon, final String dataSource, final int parentIndex){ // // // TabItem tabItem = new TabItem(); //// tabItem.setLayout(new FitLayout()); // tabItem.setScrollMode(Scroll.AUTO); // tabItem.setClosable(true); // // // ContentPanel cp = new ContentPanel(); // cp.setHeaderVisible(false); // ToolBar toolbar = new ToolBar(); // // // Button btnSaveTaxonomyChildren = new Button(ConstantsSpeciesDiscovery.SAVE_TAXONOMY_CHILDREN); // Menu formatSubMenu = new Menu(); // btnSaveTaxonomyChildren.setMenu(formatSubMenu); // btnSaveTaxonomyChildren.setScale(ButtonScale.SMALL); // btnSaveTaxonomyChildren.setIconAlign(IconAlign.TOP); // btnSaveTaxonomyChildren.setIcon(AbstractImagePrototype.create(Resources.INSTANCE.getSaveProducts())); // btnSaveTaxonomyChildren.setToolTip(new ToolTipConfig(ConstantsSpeciesDiscovery.SAVE_TAXONOMY_CHILDREN, ConstantsSpeciesDiscovery.SAVES_TAXONOMY_CHILDREN_FROM_RESULT)); // // MenuItem darwinCoreArchiveItem = new MenuItem(ConstantsSpeciesDiscovery.DARWIN_CORE_ARCHIVE); // darwinCoreArchiveItem.setToolTip(new ToolTipConfig(ConstantsSpeciesDiscovery.SAVES_IN_DARWIN_CORE_ARCHIVE_FORMAT)); // darwinCoreArchiveItem.addSelectionListener(new SelectionListener() { // // @Override // public void componentSelected(MenuEvent ce) { // eventBus.fireEvent(new CreateTaxonomyJobEvent(taxon, dataSource, TaxonomyJobType.BYCHILDREN)); // } // }); // // formatSubMenu.add(darwinCoreArchiveItem); // toolbar.add(btnSaveTaxonomyChildren); // // cp.setTopComponent(toolbar); // cp.setBodyBorder(false); //// cp.setScrollMode(Scroll.AUTOY); // // String tabName = taxon.getName() + " ("+ dataSource + ")"; // tabItem.setText(tabName); // // cp.add(getPanelForTaxonomy(taxon, dataSource, true, parentIndex)); // // tabItem.add(cp); // // tabPanel.add(tabItem); // // } }