Set<X509Certificate> (boolean addFromOrganization) { Set<X509Certificate> selected = new HashSet<>(); TreeUtil.collectSelectedUserObjects(myTree).forEach(o -> { if (o instanceof CertificateDescriptor) { selected.add(((CertificateDescriptor)o).getElement().getCertificate()); } else if (o instanceof OrganizationDescriptor) { if (addFromOrganization) { selected.addAll(getCertificatesByOrganization(((OrganizationDescriptor)o).getElement())); } } else if (o instanceof RootDescriptor) { // nop } else { Logger.getInstance(getClass()).error("Unknown tree node object of type: " + o.getClass().getName()); } }); return selected; }