Skip to content

Commit d9a68ec

Browse files
committed
DisplayService: add a createDisplayQuietly method
This method creates a display without publishing a DisplayCreatedEvent. It is the caller's responsibility to deal with ramifications of that. This method is introduced to maintain backwards compatibility with the old behavior. The display framework will probably be substantially redesigned soon, at which point all of this will become moot. But in the meantime, it is handy to be able to create a display without showing it. This commit is dedicated to Richard Domander!
1 parent 3c8cf82 commit d9a68ec

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/main/java/org/scijava/display/DefaultDisplayService.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ public Display<?> createDisplay(final Object o) {
209209

210210
@Override
211211
public Display<?> createDisplay(final String name, final Object o) {
212+
final Display<?> display = createDisplayQuietly(o);
213+
if (display == null) return null;
214+
if (name != null) display.setName(name);
215+
eventService.publish(new DisplayCreatedEvent(display));
216+
return display;
217+
}
218+
219+
@Override
220+
public Display<?> createDisplayQuietly(final Object o) {
212221
// get available display plugins from the plugin service
213222
final List<PluginInfo<Display<?>>> displayPlugins = getDisplayPlugins();
214223

@@ -219,8 +228,6 @@ public Display<?> createDisplay(final String name, final Object o) {
219228
// TODO: how to handle multiple matches? prompt user with dialog box?
220229
if (display.canDisplay(o)) {
221230
display.display(o);
222-
if (name != null) display.setName(name);
223-
eventService.publish(new DisplayCreatedEvent(display));
224231
return display;
225232
}
226233
}

src/main/java/org/scijava/display/DisplayService.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ <DT extends Display<?>> List<PluginInfo<DT>> getDisplayPluginsOfType(
123123
* <li>The {@link ObjectService} will add the new display to its index, until
124124
* a corresponding {@link DisplayDeletedEvent} is later published.</li>
125125
* </ul>
126+
* <p>
127+
* To create a {@link Display} without publishing an event, see
128+
* {@link #createDisplayQuietly}.
129+
* </p>
126130
*
127131
* @param o The object for which a display should be created. The object is
128132
* then added to the display.
@@ -144,6 +148,10 @@ <DT extends Display<?>> List<PluginInfo<DT>> getDisplayPluginsOfType(
144148
* <li>The {@link ObjectService} will add the new display to its index, until
145149
* a corresponding {@link DisplayDeletedEvent} is later published.</li>
146150
* </ul>
151+
* <p>
152+
* To create a {@link Display} without publishing an event, see
153+
* {@link #createDisplayQuietly}.
154+
* </p>
147155
*
148156
* @param name The name to be assigned to the display.
149157
* @param o The object for which a display should be created. The object is
@@ -158,4 +166,21 @@ <DT extends Display<?>> List<PluginInfo<DT>> getDisplayPluginsOfType(
158166
*/
159167
Display<?> createDisplay(String name, Object o);
160168

169+
/**
170+
* Creates a display for the given object, without publishing a
171+
* {@link DisplayCreatedEvent}. Hence, the display will not be automatically
172+
* shown or tracked.
173+
*
174+
* @param o The object for which a display should be created. The object is
175+
* then added to the display.
176+
* @return Newly created {@code Display<?>} containing the given object. The
177+
* Display is typed with ? rather than T matching the Object because
178+
* it is possible for the Display to be a collection of some other
179+
* sort of object than the one being added. For example, ImageDisplay
180+
* is a {@code Display<DataView>} with the DataView wrapping a
181+
* Dataset, yet the ImageDisplay supports adding Datasets directly,
182+
* taking care of wrapping them in a DataView as needed.
183+
*/
184+
Display<?> createDisplayQuietly(Object o);
185+
161186
}

0 commit comments

Comments
 (0)