GP-2321: Only exporters that support the current domain object are

presented in list now
This commit is contained in:
Ryan Kurtz 2022-12-08 04:28:42 -05:00
parent db932d2228
commit b14804b295
3 changed files with 23 additions and 5 deletions

View file

@ -295,13 +295,12 @@ public class ExporterDialog extends DialogComponentProvider implements AddressFa
return comboBox;
}
@SuppressWarnings("unchecked")
private List<Exporter> getApplicableExporters() {
List<Exporter> list = new ArrayList<>(ClassSearcher.getInstances(Exporter.class));
Class<?> domainObjectClass = domainFile.getDomainObjectClass();
DomainObject domainObj = getDomainObject(TaskMonitor.DUMMY);
if (DomainObject.class.isAssignableFrom(domainObjectClass)) {
list.removeIf(exporter -> !exporter
.canExportDomainObject((Class<? extends DomainObject>) domainObjectClass));
list.removeIf(exporter -> !exporter.canExportDomainObject(domainObj));
Collections.sort(list, (o1, o2) -> o1.toString().compareTo(o2.toString()));
}
return list;

View file

@ -101,16 +101,27 @@ abstract public class Exporter implements ExtensionPoint {
}
/**
* Returns true if this exporter knows how to export the given domain object. For example,
* Returns true if this exporter knows how to export the given domain object type. For example,
* some exporters know how to export programs, other exporters can export project data type
* archives.
* @param domainObjectClass the class of the domain object to test for exporting.
* @return true if this exporter knows how to export the given domain object.
* @return true if this exporter knows how to export the given domain object type.
* @deprecated use {@link #canExportDomainObject(DomainObject)}
*/
@Deprecated(since = "10.3", forRemoval = true)
public boolean canExportDomainObject(Class<? extends DomainObject> domainObjectClass) {
return Program.class.isAssignableFrom(domainObjectClass);
}
/**
* Returns true if this exporter knows how to export the given domain object.
* @param domainObject the domain object to test for exporting.
* @return true if this exporter knows how to export the given domain object.
*/
public boolean canExportDomainObject(DomainObject domainObject) {
return canExportDomainObject(domainObject.getClass());
}
/**
* Returns true if this exporter can export less than the entire domain file.
* @return true if this exporter can export less than the entire domain file.

View file

@ -62,6 +62,14 @@ public class OriginalFileExporter extends Exporter {
return false;
}
@Override
public boolean canExportDomainObject(DomainObject domainObject) {
if (domainObject instanceof Program program) {
return !program.getMemory().getAllFileBytes().isEmpty();
}
return false;
}
@Override
public boolean export(File file, DomainObject domainObj, AddressSetView addrSet,
TaskMonitor monitor) throws IOException, ExporterException {