/** Initialise. */
  public synchronized void initialise() {

    // wait until application is properly initialised
    while (applicationService == null) {
      // idle in this thread
      try {
        this.wait(6000);
      } catch (InterruptedException e) {
        logger.warn("e.getMessage() = " + e.getMessage());
      }

      if (applicationService != null && applicationService.getErrorLoggerService() != null) {
        this.applicationService.getErrorLoggerService().registerListener(this);
      }
    }

    // set LNF first to avoid component UI errors
    LookAndFeelUtils.setDefaultLNF();

    errorPane = new JXErrorPane();
    errorPane.setPreferredSize(new Dimension(400, 300));
    errorPane.setIcon(ImageUtils.getIcon(ImageUtils.IconName.WARNING_ICON_48));
    errorPane.setErrorReporter(this);
    errorDialog = JXErrorPane.createDialog(null, errorPane);
    errorDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    errorDialog.pack();
  }
  /**
   * The aggregate components which compise the combo box are unregistered and uninitialized. This
   * method is called as part of the UI uninstallation process.
   */
  protected void uninstallComponents() {
    iconLabel = null;
    errorMessage = null;
    closeButton = null;
    reportButton = null;

    detailButton.removeActionListener(detailListener);
    detailButton = null;

    details.setTransferHandler(null);
    details = null;

    detailsScrollPane.removeAll();
    detailsScrollPane = null;

    detailsPanel.setLayout(null);
    detailsPanel.removeAll();
    detailsPanel = null;

    copyToClipboardButton.removeActionListener(copyToClipboardListener);
    copyToClipboardButton = null;

    pane.removeAll();
    pane.setLayout(null);
    pane.setBorder(null);
  }
 /**
  * modificar un cliente
  *
  * <p>Devuelve el cliente que se va a modificar
  *
  * <p>Si el cliente pasado es null, intenta crear un nuevo cliente
  */
 public Cliente editCliente(Cliente cliente, Component parent) {
   Assert.notNull(dataService);
   Cliente eCliente = cliente;
   if (eCliente == null) {
     eCliente = new Cliente();
     String s = getMessage("ui.ClienteUIService.DefaultName", null, "New customer");
     eCliente.setNombre(s);
   }
   boolean error = false;
   Throwable excep = null;
   if (eCliente.getId() != null) {
     try {
       eCliente = dataService.getById(eCliente.getId());
     } catch (DataAccessException e) {
       excep = e;
       error = true;
     } catch (Throwable t) {
       excep = t;
       error = true;
     }
     if (error) {
       logger.error("Error retrieving customer from persistence service", excep);
       String t =
           getMessage(
               "ui.ClienteUIService.ErrorLoadClienteTitle", null, "Error retrieving customer");
       String m =
           getMessage(
               "ui.ClienteUIService.ErrorLoadClienteMessage",
               null,
               "Error retrieving customer data");
       ErrorInfo err = new ErrorInfo(t, m, excep.getMessage(), null, excep, null, null);
       JXErrorPane.showDialog(parent == null ? getParentWindow() : parent, err);
       return null;
     }
     // Si el cliente es null, no se ha encontrado
     // Podría haber sido borrado
     if (eCliente == null) {
       logger.error("Error retrieving customer from persistence service. Not found.");
       String t =
           getMessage(
               "ui.ClienteUIService.ErrorNotExistClienteTitle", null, "Error retrieving customer");
       String m =
           getMessage(
               "ui.ClienteUIService.ErrorNotExistClienteMessage",
               null,
               "Customer not found. Please, refresh data");
       ErrorInfo err = new ErrorInfo(t, m, m, null, null, null, null);
       JXErrorPane.showDialog(getParentWindow(), err);
       return null;
     }
   }
   ClienteEditDialog dialog =
       new ClienteEditDialog(parent == null ? getParentWindow() : parent, eCliente, this);
   dialog.setDataService(dataService);
   dialog.setModalityType(ModalityType.MODELESS);
   dialog.pack();
   dialog.setLocationRelativeTo(dialog.getOwner());
   dialog.setVisible(true);
   return eCliente;
 }
 private void exitIfFatal() {
   ErrorInfo info = pane.getErrorInfo();
   // FYI: info can be null
   if (info != null && info.getErrorLevel() == ErrorLevel.FATAL) {
     Action fatalAction = pane.getActionMap().get(JXErrorPane.FATAL_ACTION_KEY);
     if (fatalAction == null) {
       System.exit(1);
     } else {
       ActionEvent ae = new ActionEvent(closeButton, -1, "fatal");
       fatalAction.actionPerformed(ae);
     }
   }
 }
    public JXInternalErrorFrame(JXErrorPane p) {
      setTitle(p.getErrorInfo().getTitle());

      setLayout(new BorderLayout());
      add(p, BorderLayout.CENTER);
      final Action closeAction =
          new AbstractAction() {
            public void actionPerformed(ActionEvent evt) {
              setVisible(false);
              dispose();
            }
          };
      closeButton.addActionListener(closeAction);
      addComponentListener(
          new ComponentAdapter() {
            public void componentHidden(ComponentEvent e) {
              // remove the action listener
              closeButton.removeActionListener(closeAction);
              exitIfFatal();
            }
          });

      getRootPane().setDefaultButton(closeButton);
      setResizable(false);
      setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
      KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
      getRootPane().registerKeyboardAction(closeAction, ks, JComponent.WHEN_IN_FOCUSED_WINDOW);
      // setPreferredSize(calculatePreferredDialogSize());
    }
  /* (non-Javadoc)
   * @see uk.nhs.cfh.dsp.srth.desktop.appservice.error.ErrorLoggerServiceListener#errorThrown(org.jdesktop.swingx.error.ErrorInfo)
   */
  public void errorThrown(ErrorInfo errorInfo) {
    // set LNF first to avoid component UI errors
    LookAndFeelUtils.setDefaultLNF();

    errorPane.setErrorInfo(errorInfo);
    errorDialog.setVisible(true);
  }
  /**
   * Reconfigures the dialog if settings have changed, such as the errorInfo, errorIcon,
   * warningIcon, etc
   */
  protected void reinit() {
    setDetailsVisible(false);
    Action reportAction = pane.getActionMap().get(JXErrorPane.REPORT_ACTION_KEY);
    reportButton.setAction(reportAction);
    reportButton.setVisible(
        reportAction != null && reportAction.isEnabled() && pane.getErrorReporter() != null);
    reportButton.setEnabled(reportButton.isVisible());
    ErrorInfo errorInfo = pane.getErrorInfo();
    if (errorInfo == null) {
      iconLabel.setIcon(pane.getIcon());
      setErrorMessage("");
      closeButton.setText(
          UIManagerExt.getString(CLASS_NAME + ".ok_button_text", closeButton.getLocale()));
      setDetails("");
      // TODO Does this ever happen? It seems like if errorInfo is null and
      // this is called, it would be an IllegalStateException.
    } else {
      // change the "closeButton"'s text to either the default "ok"/"close" text
      // or to the "fatal" text depending on the error level of the incident info
      if (errorInfo.getErrorLevel() == ErrorLevel.FATAL) {
        closeButton.setText(
            UIManagerExt.getString(CLASS_NAME + ".fatal_button_text", closeButton.getLocale()));
      } else {
        closeButton.setText(
            UIManagerExt.getString(CLASS_NAME + ".ok_button_text", closeButton.getLocale()));
      }

      // if the icon for the pane has not been specified by the developer,
      // then set it to the default icon based on the error level
      Icon icon = pane.getIcon();
      if (icon == null || icon instanceof UIResource) {
        if (errorInfo.getErrorLevel().intValue() <= Level.WARNING.intValue()) {
          icon = getDefaultWarningIcon();
        } else {
          icon = getDefaultErrorIcon();
        }
      }
      iconLabel.setIcon(icon);
      setErrorMessage(errorInfo.getBasicErrorMessage());
      String details = errorInfo.getDetailedErrorMessage();
      if (details == null) {
        details = getDetailsAsHTML(errorInfo);
      }
      setDetails(details);
    }
  }
  /* (non-Javadoc)
   * @see uk.nhs.cfh.dsp.srth.desktop.appservice.error.ErrorLoggerServiceListener#errorThrown(java.lang.Object, java.lang.String, java.lang.Throwable)
   */
  public void errorThrown(Object source, String errorMessage, Throwable cause, Level level) {

    // set LNF first to avoid component UI errors
    LookAndFeelUtils.setDefaultLNF();
    errorPane.setErrorInfo(
        new ErrorInfo(
            "Error",
            errorMessage,
            cause.fillInStackTrace().getMessage(),
            "",
            cause,
            level,
            new HashMap<String, String>(0)));
    errorDialog.setVisible(true);
  }
 @Override
 public void dispatchEvent(AWTEvent event) {
   try {
     super.dispatchEvent(event);
   } catch (RuntimeException e) {
     JXErrorPane.showDialog(
         null,
         new ErrorInfo(
             "Event Queue Exception!", //$NON-NLS-1$
             e.toString(),
             null,
             null,
             e,
             Level.SEVERE,
             null));
     e.printStackTrace();
   }
 }
 /**
  * Elimina un cliente
  *
  * <p>Devuelve el cliente eliminado o null si no se elimino
  *
  * <p>Pide confirmación si así se requiere
  */
 public Cliente removeCliente(Cliente cliente, boolean askConfirmation, Component parent) {
   Assert.notNull(dataService);
   if (askConfirmation) {
     String ti = getMessage("ui.ClienteUIService.ConfirmDeleteTitle", null, "Remove Customer");
     String me =
         getMessage(
             "ui.ClienteUIService.ConfirmDeleteQuestion",
             new String[] {cliente.getNombre()},
             "Do you want to remove customer {0}?");
     int code =
         JOptionPane.showConfirmDialog(
             parent == null ? getParentWindow() : parent, me, ti, JOptionPane.YES_NO_OPTION);
     if (code != JOptionPane.YES_OPTION) return null;
   }
   boolean error = false;
   Throwable excep = null;
   try {
     dataService.remove(cliente);
   } catch (DataAccessException e) {
     excep = e;
     error = true;
   } catch (Throwable t) {
     excep = t;
     error = true;
   }
   if (error) {
     logger.error("Error deleting customer in persistence service", excep);
     String t =
         getMessage(
             "ui.ClienteUIService.ErrorDeleteClienteTitle", null, "Error deleting customer");
     String m =
         getMessage(
             "ui.ClienteUIService.ErrorDeleteClienteMessage",
             null,
             "Error trying to delete customer data");
     ErrorInfo err = new ErrorInfo(t, m, excep.getMessage(), null, excep, null, null);
     JXErrorPane.showDialog(parent == null ? getParentWindow() : parent, err);
     return null;
   }
   return cliente;
 }
  /**
   * Set the details section to be either visible or invisible. Set the text of the Details button
   * accordingly.
   *
   * @param b if true details section will be visible
   */
  private void setDetailsVisible(boolean b) {
    if (b) {
      collapsedHeight = pane.getHeight();
      pane.setSize(
          pane.getWidth(),
          expandedHeight == 0 ? collapsedHeight + getDetailsHeight() : expandedHeight);
      detailsPanel.setVisible(true);
      configureDetailsButton(true);
      detailsPanel.applyComponentOrientation(detailButton.getComponentOrientation());

      // workaround for bidi bug, if the text is not set "again" and the component orientation has
      // changed
      // then the text won't be aligned correctly. To reproduce this (in JDK 1.5) show two dialogs
      // in one
      // use LTOR orientation and in the second use RTOL orientation and press "details" in both.
      // Text in the text box should be aligned to right/left respectively, without this line this
      // doesn't
      // occure I assume because bidi properties are tested when the text is set and are not updated
      // later
      // on when setComponentOrientation is invoked.
      details.setText(details.getText());
      details.setCaretPosition(0);
    } else if (collapsedHeight != 0) { // only collapse if the dialog has been expanded
      expandedHeight = pane.getHeight();
      detailsPanel.setVisible(false);
      configureDetailsButton(false);
      // Trick to force errorMessage JTextArea to resize according
      // to its columns property.
      errorMessage.setSize(0, 0);
      errorMessage.setSize(errorMessage.getPreferredSize());
      pane.setSize(pane.getWidth(), collapsedHeight);
    } else {
      detailsPanel.setVisible(false);
    }

    pane.doLayout();
  }
  /**
   * Creates and initializes the components which make up the aggregate combo box. This method is
   * called as part of the UI installation process.
   */
  protected void installComponents() {
    iconLabel = new JLabel(pane.getIcon());

    errorMessage = new JEditorPane();
    errorMessage.setEditable(false);
    errorMessage.setContentType("text/html");
    errorMessage.setEditorKitForContentType("text/plain", new StyledEditorKit());
    errorMessage.setEditorKitForContentType("text/html", new HTMLEditorKit());

    errorMessage.setOpaque(false);
    errorMessage.putClientProperty(JXEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);

    closeButton =
        new JButton(
            UIManagerExt.getString(CLASS_NAME + ".ok_button_text", errorMessage.getLocale()));

    reportButton = new EqualSizeJButton(pane.getActionMap().get(JXErrorPane.REPORT_ACTION_KEY));

    detailButton =
        new EqualSizeJButton(
            UIManagerExt.getString(CLASS_NAME + ".details_expand_text", errorMessage.getLocale()));

    details = new JXEditorPane();
    details.setContentType("text/html");
    details.putClientProperty(JXEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
    details.setTransferHandler(createDetailsTransferHandler(details));
    detailsScrollPane = new JScrollPane(details);
    detailsScrollPane.setPreferredSize(new Dimension(10, 250));
    details.setEditable(false);
    detailsPanel = new JPanel();
    detailsPanel.setVisible(false);
    copyToClipboardButton =
        new JButton(
            UIManagerExt.getString(
                CLASS_NAME + ".copy_to_clipboard_button_text", errorMessage.getLocale()));
    copyToClipboardListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            details.copy();
          }
        };
    copyToClipboardButton.addActionListener(copyToClipboardListener);

    detailsPanel.setLayout(createDetailPanelLayout());
    detailsPanel.add(detailsScrollPane);
    detailsPanel.add(copyToClipboardButton);

    // Create error scroll pane. Make sure this happens before call to createErrorPaneLayout() in
    // case any extending
    // class wants to manipulate the component there.
    errorScrollPane = new JScrollPane(errorMessage);
    errorScrollPane.setBorder(new EmptyBorder(0, 0, 5, 0));
    errorScrollPane.setOpaque(false);
    errorScrollPane.getViewport().setOpaque(false);

    // initialize the gui. Most of this code is similar between Mac and PC, but
    // where they differ protected methods have been written allowing the
    // mac implementation to alter the layout of the dialog.
    pane.setLayout(createErrorPaneLayout());

    // An empty border which constitutes the padding from the edge of the
    // dialog to the content. All content that butts against this border should
    // not be padded.
    Insets borderInsets = new Insets(16, 24, 16, 17);
    pane.setBorder(
        BorderFactory.createEmptyBorder(
            borderInsets.top, borderInsets.left, borderInsets.bottom, borderInsets.right));

    // add the JLabel responsible for displaying the icon.
    // TODO: in the future, replace this usage of a JLabel with a JXImagePane,
    // which may add additional "coolness" such as allowing the user to drag
    // the image off the dialog onto the desktop. This kind of coolness is common
    // in the mac world.
    pane.add(iconLabel);
    pane.add(errorScrollPane);
    pane.add(closeButton);
    pane.add(reportButton);
    reportButton.setVisible(false); // not visible by default
    pane.add(detailButton);
    pane.add(detailsPanel);

    // make the buttons the same size
    EqualSizeJButton[] buttons =
        new EqualSizeJButton[] {(EqualSizeJButton) detailButton, (EqualSizeJButton) reportButton};
    ((EqualSizeJButton) reportButton).setGroup(buttons);
    ((EqualSizeJButton) detailButton).setGroup(buttons);

    reportButton.setMinimumSize(reportButton.getPreferredSize());
    detailButton.setMinimumSize(detailButton.getPreferredSize());

    // set the event handling
    detailListener = new DetailsClickEvent();
    detailButton.addActionListener(detailListener);
  }
Beispiel #13
0
  public Collection<Action> getSecuritiesActions() {

    if (securitiesActions == null) {

      securitiesActions = new ArrayList<Action>();
      Action firstTitle =
          new ShowSecuritiesAction(
              translations.getString("EXCHANGESMENUITEM"), createImageIcon("money.png"), true);
      firstTitle.putValue(Layout.LEAVE_SPACE, false);
      securitiesActions.add(firstTitle);
      Collection<Exchange> exchanges = null;
      try {
        exchanges = financeFactory.getAllExchanges();

        for (Exchange exch : exchanges) {

          securitiesActions.add(
              new ShowSecuritiesByExchangeAction(
                  exch.getName(), createImageIcon("money_euro.png"), exch));
        }
      } catch (StockPlayException ex) {
        JXErrorPane.showDialog(
            MainFrame.getInstance(),
            new ErrorInfo(
                translations.getString("ERROR_COMMUNICATION"),
                translations.getString("ERROR_FETCH_EXCHANGES"),
                null,
                null,
                ex,
                null,
                null));
      }

      securitiesActions.add(
          new ShowSecuritiesAction(
              translations.getString("INDEXESMENUITEM"), createImageIcon("money.png"), true));
      Collection<Index> indexes = null;
      try {
        indexes = financeFactory.getAllIndexes();

        for (Index index : indexes) {

          securitiesActions.add(
              new ShowSecuritiesByIndexAction(
                  index.getName(), createImageIcon("money_euro.png"), index));
        }
      } catch (StockPlayException ex) {
        JXErrorPane.showDialog(
            MainFrame.getInstance(),
            new ErrorInfo(
                translations.getString("ERROR_COMMUNICATION"),
                translations.getString("ERROR_FETCH_EXCHANGES"),
                null,
                null,
                ex,
                null,
                null));
      }
    }

    return securitiesActions;
  }
 public JXErrorFrame(JXErrorPane p) {
   setTitle(p.getErrorInfo().getTitle());
   initWindow(this, p);
 }
 protected void init(JXErrorPane p) {
   // FYI: info can be null
   setTitle(p.getErrorInfo() == null ? null : p.getErrorInfo().getTitle());
   initWindow(this, p);
 }
 /**
  * Create and install the listeners for the Error Pane. This method is called when the UI is
  * installed.
  */
 protected void installListeners() {
   // add a listener to the pane so I can reinit() whenever the
   // bean properties change (particularly error info)
   errorPaneListener = new ErrorPaneListener();
   pane.addPropertyChangeListener(errorPaneListener);
 }
 protected void configureReportAction(AbstractActionExt reportAction) {
   reportAction.setName(
       UIManagerExt.getString(CLASS_NAME + ".report_button_text", pane.getLocale()));
 }
 /**
  * Remove the installed listeners from the Error Pane. The number and types of listeners removed
  * and in this method should be the same that was added in <code>installListeners</code>
  */
 protected void uninstallListeners() {
   // remove the property change listener from the pane
   pane.removePropertyChangeListener(errorPaneListener);
 }