public void run() {
      if (rootband) {
        final int result =
            JOptionPane.showOptionDialog(
                dragContext.getRepresentationContainer(),
                Messages.getInstance()
                    .getString("TocElementDragHandler.BandedOrInlineSubreportQuestion"),
                Messages.getInstance().getString("TocElementDragHandler.InsertSubreport"),
                JOptionPane.YES_NO_CANCEL_OPTION,
                JOptionPane.PLAIN_MESSAGE,
                null,
                new String[] {
                  Messages.getInstance().getString("TocElementDragHandler.Inline"),
                  Messages.getInstance().getString("TocElementDragHandler.Banded"),
                  Messages.getInstance().getString("TocElementDragHandler.Cancel")
                },
                Messages.getInstance().getString("TocElementDragHandler.Inline"));
        if (result == JOptionPane.CLOSED_OPTION || result == 2) {
          return;
        }

        if (result == 0) {
          final ReportDocumentContext context = dragContext.getRenderContext();
          final UndoManager undo = context.getUndo();
          undo.addChange(
              Messages.getInstance().getString("TocElementDragHandler.UndoEntry"),
              new ElementEditUndoEntry(
                  parent.getObjectID(), parent.getElementCount(), null, subReport));
          parent.addElement(subReport);
        } else {
          final AbstractRootLevelBand arb = (AbstractRootLevelBand) parent;

          final ReportDocumentContext context = dragContext.getRenderContext();
          final UndoManager undo = context.getUndo();
          undo.addChange(
              Messages.getInstance().getString("TocElementDragHandler.UndoEntry"),
              new BandedSubreportEditUndoEntry(
                  parent.getObjectID(), arb.getSubReportCount(), null, subReport));
          arb.addSubReport(subReport);
        }
      } else {
        final ReportDocumentContext context = dragContext.getRenderContext();
        final UndoManager undo = context.getUndo();
        undo.addChange(
            Messages.getInstance().getString("TocElementDragHandler.UndoEntry"),
            new ElementEditUndoEntry(
                parent.getObjectID(), parent.getElementCount(), null, subReport));
        parent.addElement(subReport);
      }

      dragContext
          .getRenderContext()
          .getSelectionModel()
          .setSelectedElements(new Object[] {subReport});
    }
    public void run() {
      final ReportDocumentContext context = dragContext.getRenderContext();
      if (rootband) {
        final int result =
            JOptionPane.showOptionDialog(
                dragContext.getRepresentationContainer(),
                Messages.getString(
                    "CrosstabReportElementDragHandler.BandedOrInlineSubreportQuestion"),
                Messages.getString("CrosstabReportElementDragHandler.InsertSubreport"),
                JOptionPane.YES_NO_CANCEL_OPTION,
                JOptionPane.PLAIN_MESSAGE,
                null,
                new String[] {
                  Messages.getString("CrosstabReportElementDragHandler.Inline"),
                  Messages.getString("CrosstabReportElementDragHandler.Banded"),
                  Messages.getString("CrosstabReportElementDragHandler.Cancel")
                },
                Messages.getString("CrosstabReportElementDragHandler.Inline"));
        if (result == JOptionPane.CLOSED_OPTION || result == 2) {
          return;
        }

        if (result == 0) {
          final UndoManager undo = context.getUndo();
          undo.addChange(
              Messages.getString("CrosstabReportElementDragHandler.UndoEntry"),
              new ElementEditUndoEntry(
                  parent.getObjectID(), parent.getElementCount(), null, subReport));
          parent.addElement(subReport);
        } else {
          final AbstractRootLevelBand arb = (AbstractRootLevelBand) parent;
          final UndoManager undo = context.getUndo();
          undo.addChange(
              Messages.getString("CrosstabReportElementDragHandler.UndoEntry"),
              new BandedSubreportEditUndoEntry(
                  parent.getObjectID(), arb.getSubReportCount(), null, subReport));
          arb.addSubReport(subReport);
        }
      } else {
        final UndoManager undo = context.getUndo();
        undo.addChange(
            Messages.getString("CrosstabReportElementDragHandler.UndoEntry"),
            new ElementEditUndoEntry(
                parent.getObjectID(), parent.getElementCount(), null, subReport));
        parent.addElement(subReport);
      }

      final ReportDesignerContext designerContext = dragContext.getDesignerContext();
      final Window window = LibSwingUtil.getWindowAncestor(designerContext.getView().getParent());
      final AbstractReportDefinition reportDefinition =
          designerContext.getActiveContext().getReportDefinition();

      try {
        // Create the new subreport tab - this is where the contents of the Crosstab
        // dialog will go.  Zoom the crosstab canvas to 150% as crosstab has a lot of elements to
        // display
        subReport.setDataFactory(reportDefinition.getDataFactory());
        subReport
            .getReportDefinition()
            .setAttribute(ReportDesignerBoot.DESIGNER_NAMESPACE, ReportDesignerBoot.ZOOM, 1.5f);

        final ResourceBundleFactory rbf = subReport.getResourceBundleFactory();
        subReport.setResourceBundleFactory(rbf);

        final int idx = designerContext.addSubReport(designerContext.getActiveContext(), subReport);
        designerContext.setActiveDocument(designerContext.getReportRenderContext(idx));
      } catch (ReportDataFactoryException e) {
        UncaughtExceptionsModel.getInstance().addException(e);
      }

      // Prompt user to either create or use an existing data-source.
      final SubReportDataSourceDialog crosstabDataSourceDialog;
      if (window instanceof Dialog) {
        crosstabDataSourceDialog = new SubReportDataSourceDialog((Dialog) window);
      } else if (window instanceof Frame) {
        crosstabDataSourceDialog = new SubReportDataSourceDialog((Frame) window);
      } else {
        crosstabDataSourceDialog = new SubReportDataSourceDialog();
      }

      // User has prompted to select a data-source.  Get the selected query
      final String queryName = crosstabDataSourceDialog.performSelection(designerContext);
      if (queryName != null) {
        subReport.setQuery(queryName);

        // Invoke Crosstab dialog
        final InsertCrosstabGroupAction crosstabAction = new InsertCrosstabGroupAction();
        crosstabAction.setReportDesignerContext(designerContext);
        crosstabAction.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, ""));
      }

      dragContext
          .getRenderContext()
          .getSelectionModel()
          .setSelectedElements(new Object[] {subReport});
    }