private void fillModuleItemStructure() { // If two or more asset editors (that are associated with different formats) have same titles, // we group them together and display them as one node on the package tree. String[] registeredFormats = clientFactory .getPerspectiveFactory() .getRegisteredAssetEditorFormats(packageConfigData.getFormat()); // Use list to preserve the order of asset editors defined in configuration. List<FormatList> formatListGroupedByTitles = new ArrayList<FormatList>(); for (String format : registeredFormats) { boolean found = false; for (FormatList formatListWithSameTitle : formatListGroupedByTitles) { found = formatListWithSameTitle.titleAlreadyExists(format); if (found) { formatListWithSameTitle.add(format); break; } } if (!found) { FormatList formatListWithSameTile = new FormatList(); formatListWithSameTile.add(format); formatListGroupedByTitles.add(formatListWithSameTile); } } addTitleItems(formatListGroupedByTitles); }
private List<String> getFormatsInList(FormatList formatList) { List<String> formatsInList = null; if (formatList.getFormats() != null && formatList.getFormats().length > 0) { formatsInList = Arrays.asList(formatList.getFormats()); } return formatsInList; }
private Boolean getFormatIsRegistered(FormatList formatList) { Boolean formatIsRegistered = null; if (formatList.getFormats() == null || formatList.getFormats().length == 0) { formatIsRegistered = false; } return formatIsRegistered; }
private void addTitleItems(List<FormatList> formatListGroupedByTitles) { // Record the number of groups expected to have assets, if all are found to be empty we show a // warning final AssetGroupSemaphore s = new AssetGroupSemaphore(formatListGroupedByTitles.size()); final AssetViewerSection[] sections = new AssetViewerSection[formatListGroupedByTitles.size()]; for (int i = 0; i < formatListGroupedByTitles.size(); i++) { final FormatList formatList = formatListGroupedByTitles.get(i); final int sectionIndex = i; // Only add a section to the view if the Format Group contains Format Types if (formatList.size() == 0) { continue; } final List<String> formatsInList = getFormatsInList(formatList); final Boolean formatIsRegistered = getFormatIsRegistered(formatList); // Check if there are any assets for the group AssetPageRequest request = new AssetPageRequest(packageConfigData.getUuid(), formatsInList, formatIsRegistered); clientFactory .getAssetService() .getAssetCount( request, new GenericCallback<Long>() { public void onSuccess(Long count) { s.recordProcessedGroup(); if (count > 0) { // If the group contains assets add a section String title = getGroupTitle(formatList.getFirst()); Image icon = getGroupIcon(formatList.getFirst()); AssetViewerSection section = new AssetViewerSection(title, icon, formatsInList, formatIsRegistered); sections[sectionIndex] = section; } else { // Otherwise record empty group and show warning, if applicable s.recordEmptyGroup(); if (s.areAllGroupsEmpty()) { view.showHasNoAssetsWarning(true); } } // If all groups have been processed add sections to UI if (s.areAllGroupsProcessed()) { for (AssetViewerSection section : sections) { if (section != null) { view.addAssetFormat( section.formatsInList, section.formatIsRegistered, section.title, section.icon, packageConfigData, clientFactory); } } } } }); } }