diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/SampleBrowserGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/SampleBrowserGrid.java index 4c1dedd0eecaf0b6b142fdac37f5d887adc3353d..706d13168e4b630a2dc2bccf5c42128a2a9bff2c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/SampleBrowserGrid.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/SampleBrowserGrid.java @@ -600,30 +600,48 @@ public class SampleBrowserGrid extends AbstractEntityGrid<Sample> @Override protected void process(List<SampleChildrenInfo> sampleChildrenInfo) { - StringBuffer sampleSb = new StringBuffer(); - + int samplesWithChildren = 0; + int samplesWithDataSets = 0; + final int MAX_DISPLAY_SIZE = 10; + + Set<String> samplesWithChildrenToDisplay = new HashSet<String>(); + Set<String> samplesWithDataSetsToDisplay = new HashSet<String>(); + for(SampleChildrenInfo info: sampleChildrenInfo) { - if(info.getChildCount() > 0 || info.getDataSetCount() > 0) { - sampleSb.append("<br>" + techIdsToSampleIds.get(info.getSampleIdentifier())+ " : "); - if(info.getChildCount() > 0) { - sampleSb.append(info.getChildCount() + " derived samples"); + if(info.getChildCount() > 0) { + samplesWithChildren++; + if(samplesWithChildren <= MAX_DISPLAY_SIZE) { + samplesWithChildrenToDisplay.add(techIdsToSampleIds.get(info.getSampleIdentifier())); } - if(info.getDataSetCount() > 0) { - if(info.getChildCount() > 0) - sampleSb.append(","); - sampleSb.append(info.getDataSetCount() + " data sets"); + } + if(info.getDataSetCount() > 0) { + samplesWithDataSets++; + if(samplesWithDataSets <= MAX_DISPLAY_SIZE) { + samplesWithDataSetsToDisplay.add(techIdsToSampleIds.get(info.getSampleIdentifier())); } } } - String additionalMessage=""; - if(sampleSb.length() > 0) { - additionalMessage = "<br>The following samples have children or datasets:<br>"; - additionalMessage += sampleSb.toString(); + String additionalMessage=""; + if(samplesWithChildren > 0) { + additionalMessage += "<br>There are " + samplesWithChildren + " sample(s) with children samples, these relationships will be broken but the children will remain:<br>"; + for(String sample : samplesWithChildrenToDisplay) { + additionalMessage += "<br>" + sample; + } + if(samplesWithChildren > MAX_DISPLAY_SIZE) { + additionalMessage += "<br>and " + (samplesWithChildren-MAX_DISPLAY_SIZE) + " more"; + } + additionalMessage += "<br>"; } - if(sampleChildrenInfo.size() >= 10) { - additionalMessage += "<br>... and possibly more"; - } - additionalMessage += "<br>"; + if(samplesWithDataSets > 0) { + additionalMessage += "<br>There are " + samplesWithDataSets + " sample(s) with data sets, these will be deleted with the sample:<br>"; + for(String sample : samplesWithDataSetsToDisplay) { + additionalMessage += "<br>" + sample; + } + if(samplesWithDataSets > MAX_DISPLAY_SIZE) { + additionalMessage += "<br>and " + (samplesWithDataSets-MAX_DISPLAY_SIZE) + " more"; + } + additionalMessage += "<br>"; + } new SampleListDeletionConfirmationDialog<TableModelRowWithObject<Sample>>(viewContext.getCommonViewContext(), samples, callback, s, additionalMessage).show();; } }; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java index 301f0260a795d3e24e9707fc7dc20b53d63e53d2..a9ad5bcaf1911d6a694b0c82daac056e83f83fc1 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java @@ -2924,71 +2924,64 @@ public final class CommonClientService extends AbstractClientService implements List<AbstractExternalData> list = commonServer.listSampleExternalData(sessionToken, sampleId, showOnlyDirectlyConnected); return Code.extractCodes(list); } - - @Override - public List<SampleChildrenInfo> getSampleChildrenInfo(List<TechId> sampleIds, boolean showOnlyDirectlyConnected) - throws ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException - { + + private SampleChildrenInfo getSampleChildInfo(TechId sampleId, boolean showOnlyDirectlyConnected, boolean fillChildList) { final int MAX_INFO_SIZE = 10; - - List<SampleChildrenInfo> list = new ArrayList<SampleChildrenInfo>(); + final String sessionToken = getSessionToken(); - - // if we need info for just one sample send back the - // MAX_INFO_SIZE number of children and data sets - if(sampleIds.size() == 1) { - TechId sampleId = sampleIds.get(0); - SampleChildrenInfo childrenInfo = new SampleChildrenInfo(sampleId.toString()); - list.add(childrenInfo); - final ListSampleCriteria sampleCriteria = ListSampleCriteria.createForParent(sampleId); - List<Sample> results= commonServer.listSamples(sessionToken, sampleCriteria); - - int count = 0; - //get the derived samples + final ListSampleCriteria sampleCriteria = ListSampleCriteria.createForParent(sampleId); + List<Sample> results= commonServer.listSamples(sessionToken, sampleCriteria); + + SampleChildrenInfo childrenInfo = new SampleChildrenInfo(sampleId.toString()); + int count = 0; + //get the derived samples + if(fillChildList) { for (Sample child : results) { // after showing MAX_INFO_SIZE children/datasets we say // how many more is not shown - if(++count == MAX_INFO_SIZE) { + if(count++ == MAX_INFO_SIZE) { break; } childrenInfo.addDerivedSample(child.getIdentifier()); } - childrenInfo.setChildCount(results.size()); + } + childrenInfo.setChildCount(results.size()); - //get the data sets - List<AbstractExternalData> dataSetList = commonServer.listSampleExternalData(sessionToken, sampleId, showOnlyDirectlyConnected); - List<String> dataSetCodes = Code.extractCodes(dataSetList); - count = 0; + //get the data sets + List<AbstractExternalData> dataSetList = commonServer.listSampleExternalData(sessionToken, sampleId, showOnlyDirectlyConnected); + List<String> dataSetCodes = Code.extractCodes(dataSetList); + count = 0; + if(fillChildList) { for (String str : dataSetCodes) { - if(++count == MAX_INFO_SIZE) { + if(count++ == MAX_INFO_SIZE) { break; } childrenInfo.addDataSet(str); } - childrenInfo.setDataSetCount(dataSetCodes.size()); + } + childrenInfo.setDataSetCount(dataSetCodes.size()); + return childrenInfo; + } + + @Override + public List<SampleChildrenInfo> getSampleChildrenInfo(List<TechId> sampleIds, boolean showOnlyDirectlyConnected) + throws ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException + { + List<SampleChildrenInfo> list = new ArrayList<SampleChildrenInfo>(); + // if we need info for just one sample send back the + // MAX_INFO_SIZE number of children and data sets + if(sampleIds.size() == 1) { + TechId sampleId = sampleIds.get(0); + list.add(getSampleChildInfo(sampleId, showOnlyDirectlyConnected, true)); } else { //if we need info for multiple samples, send back the // children and data set count for the first MAX_INFO_SIZE - int count = 0; for (TechId sampleId : sampleIds) { - SampleChildrenInfo childrenInfo = new SampleChildrenInfo(sampleId.toString()); - list.add(childrenInfo); - final ListSampleCriteria sampleCriteria = ListSampleCriteria.createForParent(sampleId); - List<Sample> results= commonServer.listSamples(sessionToken, sampleCriteria); - childrenInfo.setChildCount(results.size()); - - List<AbstractExternalData> dataSetList = commonServer.listSampleExternalData(sessionToken, sampleId, showOnlyDirectlyConnected); - List<String> dataSetCodes = Code.extractCodes(dataSetList); - childrenInfo.setDataSetCount(dataSetCodes.size()); - if(childrenInfo.getChildCount() >0 || childrenInfo.getDataSetCount() > 0) { - if(++count == MAX_INFO_SIZE) { - break; - } - } + list.add(getSampleChildInfo(sampleId, showOnlyDirectlyConnected, false)); } } return list; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleViewer.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleViewer.java index f3783a268627b6c1462d411e9d912476a76e2324..ad2a629f4e90ed89ee9c5721aa5300ca892bf9e0 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleViewer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleViewer.java @@ -198,29 +198,29 @@ abstract public class GenericSampleViewer extends AbstractViewerWithVerticalSpli StringBuffer dataSetSb = new StringBuffer(); for (String child : sampleInfo.getDerivedSamples()) { - sampleSb.append(child + "<br>"); + sampleSb.append("<br>" + child); } for (String ds : sampleInfo.getDataSets()) { - dataSetSb.append(ds + "<br>"); + dataSetSb.append("<br>" + ds); } - if(sampleSb.length() > 0 || dataSetSb.length() > 0) { - additionalMessage.append("<br>Sample " + getOriginalData().getIdentifier() + " has the following:"); - } if(sampleSb.length() > 0) { - additionalMessage.append("<br><br>Derived Samples:<br>"); + additionalMessage.append("<br>The sample has " + sampleInfo.getChildCount() + " children samples, these relationships will be broken but the children will remain:"); + additionalMessage.append("<br>"); additionalMessage.append(sampleSb); - if(sampleInfo.getChildCount() > MAX_INFO_SIZE ) + if(sampleInfo.getChildCount() > MAX_INFO_SIZE ) { additionalMessage.append("<br> and " + (sampleInfo.getChildCount()-MAX_INFO_SIZE) + " more"); + } + additionalMessage.append("<br>"); } if(dataSetSb.length() > 0) { - additionalMessage.append("<br>Data Sets:<br>"); + additionalMessage.append("<br>The sample has " + sampleInfo.getDataSetCount() + " datasets, these will be deleted with the sample:"); + additionalMessage.append("<br>"); additionalMessage.append(dataSetSb); - if(sampleInfo.getDataSetCount() > MAX_INFO_SIZE) - additionalMessage.append("<br> and " + (sampleInfo.getDataSetCount()-MAX_INFO_SIZE) + " more"); - } - if(sampleSb.length() > 0 || dataSetSb.length() > 0) { + if(sampleInfo.getDataSetCount() > MAX_INFO_SIZE) { + additionalMessage.append("<br>and " + (sampleInfo.getDataSetCount()-MAX_INFO_SIZE) + " more"); + } additionalMessage.append("<br>"); } new SampleListDeletionConfirmationDialog(getViewContext()