Limit amount of specific component per Container

How would I go about restricting any container within Vision to only allow one component of a specific class? I created an OutlineHandlerComponent, as seen in this topic:

I want to only allow one of these to be placed on each window.

So far I tried the following in the OutlineHandlerComponent itself:

protected void onStartup() {
  // Check for other Outline Handlers. If one already exists then remove this one, only one is allowed per Container.
  for (Component c : getParent().getComponents())
      if (c instanceof OutlineHandlerComponent && c != this) {
          JOptionPane.showMessageDialog(null, "An Outline Handler already exists on this Container.");
          SwingUtilities.invokeLater(() -> {
              Container root = getParent();
              root.remove(this);
          });
          break;
      }
}

The idea being that if an OutlineHandlerComponent already exists when this one is placed, then remove itself again. Though this does succesfully remove the newly placed component, it also causes a NullPointerException to be thrown.

I doubt you can prevent multiples. You can cause the duplicates to render an obvious and annoying error image.

Well, the NullPointerException is thrown because the just deleted component is still selected in the Designer. As soon as I select something else, there are no more exceptions. So I've been wanting to select the root container programmatically before removing the duplicate OutlineHandlerComponent, but I can't figure out how to actually select something via code.

Perhaps you can remove the other one. (:

Yeah, that does work. But the problem there is that all the components that need an outline are already subscribed to the first OutlineHandlerComponent, and if it is deleted, then they will complain.