Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message for missing required inputs #414

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/java/org/scijava/object/DefaultObjectService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

package org.scijava.object;

import java.util.HashMap;
import java.util.Map;

import org.scijava.event.EventHandler;
import org.scijava.event.EventService;
import org.scijava.object.event.ObjectCreatedEvent;
Expand Down Expand Up @@ -56,13 +59,17 @@
public final class DefaultObjectService extends AbstractService implements
ObjectService
{
private static String DEFAULT_OBJECT_NAME = "an object";

@Parameter
private EventService eventService;

/** Index of registered objects. */
private NamedObjectIndex<Object> objectIndex;

/** Map of human-friendly names */
private Map<Class<?>, String> aliasMap = new HashMap<>();

// -- ObjectService methods --

@Override
Expand All @@ -75,6 +82,16 @@ public NamedObjectIndex<Object> getIndex() {
return objectIndex;
}

@Override
public String getHumanFriendlyName(Class<?> c) {
return aliasMap.getOrDefault(c, DEFAULT_OBJECT_NAME);
}

@Override
public void addHumanFriendlyName(Class<?> c, String name) {
aliasMap.put(c, name);
}

// -- Service methods --

@Override
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/scijava/object/ObjectService.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ default void removeObject(final Object obj) {
eventService().publish(new ObjectsRemovedEvent(obj));
}

String getHumanFriendlyName(Class<?> c);

void addHumanFriendlyName(Class<?> c, String name);

// -- Deprecated methods --

/** @deprecated Use {@link #eventService()} instead. */
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/scijava/widget/AbstractInputHarvester.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ private <T> WidgetModel addInput(final InputPanel<P, W> inputPanel,
}

if (item.isRequired()) {
throw new ModuleException("A " + type.getSimpleName() +
" is required but none exist.");
throw new ModuleException("This operation requires " + objectService.getHumanFriendlyName(type)
+ " of type '" + type.getSimpleName() + "', but none was found.");
}

// item is not required; we can skip it
Expand Down