//	TODO move this to ImUtils (also from AnnotationActionProvider)
 private String getAnnotationShortValue(ImWord start, ImWord end) {
   if (start == end) return start.getString();
   else if (start.getNextWord() == end)
     return (start.getString()
         + (Gamta.insertSpace(start.getString(), end.getString()) ? " " : "")
         + end.getString());
   else return (start.getString() + " ... " + end.getString());
 }
  /* (non-Javadoc)
   * @see de.uka.ipd.idaho.im.imagine.plugins.SelectionActionProvider#getActions(de.uka.ipd.idaho.im.ImWord, de.uka.ipd.idaho.im.ImWord, de.uka.ipd.idaho.im.util.ImDocumentMarkupPanel)
   */
  public SelectionAction[] getActions(ImWord start, ImWord end, final ImDocumentMarkupPanel idmp) {

    //	we only work on individual text streams
    if (!start.getTextStreamId().equals(end.getTextStreamId())) return null;

    //	collect painted annotations spanning or overlapping whole selection
    ImAnnotation[] allOverlappingAnnots = idmp.document.getAnnotationsOverlapping(start, end);
    LinkedList spanningAnnotList = new LinkedList();
    for (int a = 0; a < allOverlappingAnnots.length; a++) {
      if (!idmp.areAnnotationsPainted(allOverlappingAnnots[a].getType())) continue;
      if (ImUtils.textStreamOrder.compare(start, allOverlappingAnnots[a].getFirstWord()) < 0)
        continue;
      if (ImUtils.textStreamOrder.compare(allOverlappingAnnots[a].getLastWord(), end) < 0) continue;
      spanningAnnotList.add(allOverlappingAnnots[a]);
    }

    //	anything to work with?
    if (spanningAnnotList.isEmpty()) return null;
    final ImAnnotation[] spanningAnnots =
        ((ImAnnotation[]) spanningAnnotList.toArray(new ImAnnotation[spanningAnnotList.size()]));

    //	collect available actions
    LinkedList actions = new LinkedList();

    //	show XML view of existing annotations
    if (spanningAnnots.length == 1)
      actions.add(
          new SelectionAction(
              "showXmlView",
              ("Show XML View of " + spanningAnnots[0].getType()),
              ("Show XML view of '" + spanningAnnots[0].getType() + "' annotation.")) {
            public boolean performAction(ImDocumentMarkupPanel invoker) {
              return showXmlView(idmp.document, spanningAnnots[0], idmp);
            }
          });

    //	show XML view of existing annotations
    else
      actions.add(
          new SelectionAction(
              "showXmlView", "Show XML View ...", "Show XML view of selected annotations.") {
            public boolean performAction(ImDocumentMarkupPanel invoker) {
              return false;
            }

            public JMenuItem getMenuItem(final ImDocumentMarkupPanel invoker) {
              JMenu pm = new JMenu("Show XML View ...");
              JMenuItem mi;
              for (int a = 0; a < spanningAnnots.length; a++) {
                final ImAnnotation spanningAnnot = spanningAnnots[a];
                mi =
                    new JMenuItem(
                        "- "
                            + spanningAnnot.getType()
                            + " '"
                            + getAnnotationShortValue(
                                spanningAnnot.getFirstWord(), spanningAnnot.getLastWord())
                            + "'");
                mi.addActionListener(
                    new ActionListener() {
                      public void actionPerformed(ActionEvent ae) {
                        if (showXmlView(idmp.document, spanningAnnot, idmp)) {
                          invoker.validate();
                          invoker.repaint();
                        }
                      }
                    });
                pm.add(mi);
              }
              return pm;
            }
          });

    //	finally ...
    return ((SelectionAction[]) actions.toArray(new SelectionAction[actions.size()]));
  }