Skip to content

Commit 35a1d20

Browse files
authored
Merge pull request #3055 from daykin/resource-opened-listener
Basic listener so interested parties can see who opened a given resource
2 parents 3c74eb1 + e432998 commit 35a1d20

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

app/display/representation/src/main/java/org/csstudio/display/builder/representation/ToolkitListener.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,12 @@ public interface ToolkitListener
4444
* @param value The value
4545
*/
4646
default public void handleWrite(Widget widget, Object value) {};
47+
48+
/**
49+
* A method was called from the UI that other listeners might be interested in.
50+
* @param user_args Zero or more objects relevant to what was called.
51+
* Case-specific Implementations should expect and check these.
52+
*/
53+
default public void handleMethodCalled(Object... user_args) {};
54+
4755
}

app/display/representation/src/main/java/org/csstudio/display/builder/representation/ToolkitRepresentation.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,20 @@ public void fireWrite(final Widget widget, final Object value)
689689
}
690690
}
691691

692+
public void fireMethodCall(Object... user_args) {
693+
for (final ToolkitListener listener : listeners)
694+
{
695+
try
696+
{
697+
listener.handleMethodCalled(user_args);
698+
}
699+
catch (final Throwable ex)
700+
{
701+
logger.log(Level.WARNING, "Failure when firing method-call event for " + Thread.currentThread().getStackTrace()[1].getMethodName(), ex);
702+
}
703+
}
704+
};
705+
692706
/** Close the toolkit's "window" that displays a model
693707
* @param model Model that has been represented in this toolkit
694708
* @throws Exception on error

app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/app/DisplayRuntimeInstance.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212

1313
import java.awt.geom.Rectangle2D;
14+
import java.util.ArrayList;
1415
import java.util.Objects;
1516
import java.util.Optional;
1617
import java.util.concurrent.Callable;
@@ -276,7 +277,7 @@ void close()
276277
}
277278

278279
/** @return Current display info or <code>null</code> */
279-
DisplayInfo getDisplayInfo()
280+
public DisplayInfo getDisplayInfo()
280281
{
281282
return display_info.orElse(null);
282283
}
@@ -286,14 +287,19 @@ DisplayInfo getDisplayInfo()
286287
*/
287288
public void loadDisplayFile(final DisplayInfo info)
288289
{
290+
DisplayInfo old_info = display_info.orElse(null);
289291
// If already executing another display, shut it down
290292
disposeModel();
291293

294+
ArrayList<DisplayInfo> dst_src = new ArrayList<>();
295+
292296
// Set input ASAP so that other requests to open this
293297
// resource will find this instance and not start
294298
// another instance
295299
dock_item.setInput(info.toURI());
296300

301+
StackTraceElement[] applicationThreadStackTrace = Thread.currentThread().getStackTrace();
302+
297303
// Now that old model is no longer represented,
298304
// show info.
299305
// Showing this info before disposeModel()
@@ -322,6 +328,9 @@ public void loadDisplayFile(final DisplayInfo info)
322328
{
323329
representation.awaitRepresentation(30, TimeUnit.SECONDS);
324330
representation_init.run();
331+
dst_src.add(info);
332+
dst_src.add(old_info);
333+
representation.fireMethodCall(dst_src, applicationThreadStackTrace);
325334
logger.log(Level.FINE, "Done with representing model of " + info.getPath());
326335
}
327336
catch (TimeoutException | InterruptedException ex)

0 commit comments

Comments
 (0)