Ejemplo n.º 1
0
  /** {@inheritDoc} */
  @Override
  public boolean execute(IActionHandler actionHandler, final Map<String, Object> context) {
    String chartUrl =
        ResourceProviderServlet.computeLocalResourceDownloadUrl(
            getChartDescriptor().getUrl(), true);
    String chartData =
        getJdbcTemplate()
            .execute(
                new ConnectionCallback<String>() {

                  @Override
                  public String doInConnection(Connection con) throws SQLException {
                    return getChartDescriptor()
                        .getData(
                            getChartModel(context),
                            con,
                            getTranslationProvider(context),
                            getLocale(context));
                  }
                });
    IResource resource;
    try {
      resource =
          new MemoryResource(
              null,
              "text/xml",
              StringUtils.prependUtf8Bom(chartData).getBytes(StandardCharsets.UTF_8.name()));
    } catch (UnsupportedEncodingException ex) {
      throw new ActionException(ex);
    }
    String resourceId = ResourceManager.getInstance().register(resource);
    Map<String, String> flashContext = new LinkedHashMap<>();
    Dimension d = getChartDescriptor().getDimension();
    flashContext.put("chartWidth", Integer.toString(d.getWidth() - 20));
    flashContext.put("chartHeight", Integer.toString(d.getHeight() - 100));
    flashContext.put("dataURL", ResourceProviderServlet.computeDownloadUrl(resourceId));
    List<G> chartActions = new ArrayList<>();
    for (IDisplayableAction action : getActions()) {
      IView<E> view = getView(context);
      chartActions.add(
          getActionFactory(context).createAction(action, actionHandler, view, getLocale(context)));
    }
    getController(context)
        .displayFlashObject(
            chartUrl,
            flashContext,
            chartActions,
            getTranslationProvider(context)
                .getTranslation(getChartDescriptor().getTitle(), getLocale(context)),
            getSourceComponent(context),
            context,
            d,
            false);
    return super.execute(actionHandler, context);
  }
Ejemplo n.º 2
0
  /** {@inheritDoc} */
  @Override
  public void displayDialog(
      JComponent mainView,
      List<Action> actions,
      String title,
      JComponent sourceComponent,
      Map<String, Object> context,
      Dimension dimension,
      boolean reuseCurrent,
      boolean modal) {
    displayModalDialog(mainView, context, reuseCurrent);
    final JDialog dialog;
    Window window = SwingUtil.getVisibleWindow(sourceComponent);
    boolean newDialog = true;
    if (window instanceof JDialog) {
      if (reuseCurrent) {
        dialog = (JDialog) window;
        dialog.getContentPane().removeAll();
        newDialog = false;
      } else {
        dialog = new JDialog((JDialog) window, title, modal);
      }
    } else {
      dialog = new JDialog((Frame) window, title, modal);
    }

    Box buttonBox = new Box(BoxLayout.LINE_AXIS);
    buttonBox.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));

    JButton defaultButton = null;
    for (Action action : actions) {
      JButton actionButton = new JButton();
      SwingUtil.configureButton(actionButton);
      actionButton.setAction(action);
      buttonBox.add(actionButton);
      buttonBox.add(Box.createHorizontalStrut(10));
      if (defaultButton == null) {
        defaultButton = actionButton;
      }
    }
    JPanel actionPanel = new JPanel();
    actionPanel.setLayout(new BorderLayout());
    actionPanel.add(buttonBox, BorderLayout.EAST);

    if (dimension != null) {
      mainView.setPreferredSize(
          new java.awt.Dimension(dimension.getWidth(), dimension.getHeight()));
    }
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(mainView, BorderLayout.CENTER);
    mainPanel.add(actionPanel, BorderLayout.SOUTH);
    dialog.getContentPane().add(mainPanel);
    dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    if (defaultButton != null) {
      dialog.getRootPane().setDefaultButton(defaultButton);
    }
    dialog.pack();
    if (newDialog) {
      SwingUtil.centerInParent(dialog);
    }
    dialog.setVisible(true);
  }