private void handleTemplateSelected(ISelection selection) {
    templateOpening = true;
    Display.getCurrent()
        .asyncExec(
            new Runnable() {
              public void run() {
                if (viewer == null
                    || viewer.getControl() == null
                    || viewer.getControl().isDisposed()) return;

                viewer.setSelection(StructuredSelection.EMPTY);
              }
            });

    if (selection == null || selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
      templateOpening = false;
      return;
    }

    Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
    if (selectedElement == null || !(selectedElement instanceof ITemplate)) return;

    ITemplate template = (ITemplate) selectedElement;
    IEditorInput editorInput =
        MindMapUI.getEditorInputFactory().createEditorInput(template.createWorkbookRef());
    getContext().openEditor(editorInput, MindMapUI.MINDMAP_EDITOR_ID);

    templateOpening = false;
  }