Пример #1
0
  /**
   * ct.
   *
   * @throws RemoteException
   */
  public KontenrahmenList() throws RemoteException {
    super(init(), new KontoListe());
    this.setRememberColWidths(true);
    this.setRememberOrder(true);
    this.setSummary(false);
    this.addColumn(i18n.tr("Bezeichnung"), "name");
    this.addColumn(i18n.tr("Zugeordneter Mandant"), "mandant_id");

    ContextMenu menu = new ContextMenu();
    menu.addItem(
        new CheckedSingleContextMenuItem(
            i18n.tr("Duplizieren..."), new KontenrahmenClone(), "gtk-dnd-multiple.png"));

    // TODO: Support zum Loeschen von Kontenrahmen fehlt noch
    //    menu.addItem(ContextMenuItem.SEPARATOR);
    //    menu.addItem(new CheckedSingleContextMenuItem(i18n.tr("Löschen..."),new
    // DBObjectDelete(),"user-trash-full.png"));
    this.setContextMenu(menu);
  }
Пример #2
0
  /**
   * ct.
   *
   * @param trustManager der TrustManager, aus dem die Zertifikate geladen werden sollen.
   * @param changable true, wenn Zertifikate importiert/exportiert werden koennen.
   */
  public CertificateList(X509TrustManager trustManager, final boolean changable) {
    super(init(trustManager), new Open());

    addColumn(Application.getI18n().tr("Ausgestellt für"), "name");
    addColumn(Application.getI18n().tr("Organisation"), "organization");
    addColumn(Application.getI18n().tr("OU"), "ou");
    addColumn(Application.getI18n().tr("Aussteller"), "issuer");
    addColumn(Application.getI18n().tr("Gültig von"), "datefrom", new DateFormatter());
    addColumn(Application.getI18n().tr("Gültig bis"), "dateto", new DateFormatter());
    addColumn(Application.getI18n().tr("Seriennummer"), "serial");
    this.setMulti(false);
    this.setSummary(false);

    setFormatter(
        new TableFormatter() {

          public void format(TableItem item) {
            if (item == null || item.getData() == null) return;
            try {
              CertObject o = (CertObject) item.getData();
              if (Application.getSSLFactory().getSystemCertificate().equals(o.cert))
                item.setForeground(Color.COMMENT.getSWTColor());
              else item.setForeground(Color.FOREGROUND.getSWTColor());
            } catch (Exception e) {
              Logger.error("unable to check for system certificate", e);
            }
          }
        });

    ContextMenu menu = new ContextMenu();
    menu.addItem(
        new CheckedContextMenuItem(
            Application.getI18n().tr("Öffnen..."), new Open(), "document-open.png"));
    menu.addItem(
        new CheckedContextMenuItem(
            Application.getI18n().tr("Löschen..."),
            new Action() {
              public void handleAction(Object context) throws ApplicationException {
                if (context == null || !(context instanceof CertObject))
                  throw new ApplicationException(
                      Application.getI18n().tr("Bitte wählen Sie das zu löschende Zertifikat aus"));

                final X509Certificate c = ((CertObject) context).cert;
                CertificateTrustDialog d =
                    new CertificateTrustDialog(CertificateTrustDialog.POSITION_CENTER, c);
                d.setText(
                    Application.getI18n()
                        .tr(
                            "Sind Sie sicher, dass Sie dieses Zertifikat aus dem Stammspeicher löschen wollen?"));
                try {
                  Boolean b = (Boolean) d.open();
                  if (b != null && b.booleanValue()) {
                    Application.getSSLFactory().removeTrustedCertificate(c);

                    // jetzt noch aus der Tabelle loeschen
                    removeItem(context);
                  }
                } catch (OperationCanceledException oce) {
                  Logger.info(Application.getI18n().tr("Vorgang abgebrochen"));
                  return;
                } catch (Exception e) {
                  Logger.error("error while deleting certificate", e);
                  Application.getMessagingFactory()
                      .sendMessage(
                          new StatusBarMessage(
                              Application.getI18n().tr("Fehler beim Löschen des Zertifikats."),
                              StatusBarMessage.TYPE_ERROR));
                }
              }
            },
            "user-trash-full.png") {
          /** @see de.willuhn.jameica.gui.parts.ContextMenuItem#isEnabledFor(java.lang.Object) */
          public boolean isEnabledFor(Object o) {
            if (!changable) return false;
            try {
              if (Application.getSSLFactory().getSystemCertificate().equals(((CertObject) o).cert))
                return false;
            } catch (Exception e) {
              Logger.error("unable to check for system certificate", e);
            }
            return super.isEnabledFor(o);
          }
        });
    menu.addItem(ContextMenuItem.SEPARATOR);
    menu.addItem(
        new CheckedContextMenuItem(
            Application.getI18n().tr("Exportieren..."),
            new Action() {
              public void handleAction(Object context) throws ApplicationException {
                try {
                  X509Certificate cert = ((CertObject) context).cert;

                  Certificate myCert = new Certificate(cert);
                  String s = myCert.getSubject().getAttribute(Principal.COMMON_NAME);
                  String s2 = myCert.getSubject().getAttribute(Principal.ORGANIZATIONAL_UNIT);

                  FileDialog fd = new FileDialog(GUI.getShell(), SWT.SAVE);
                  fd.setText(
                      Application.getI18n()
                          .tr(
                              "Bitte geben Sie das Verzeichnis an, in dem Sie das Zertifikat speichern möchten"));
                  if (s2 != null && s2.length() > 0) fd.setFileName(s + "-" + s2 + ".crt");
                  else fd.setFileName(s + ".crt");
                  fd.setFilterPath(
                      mySettings.getString("lastdir", System.getProperty("user.home")));
                  String target = fd.open();
                  if (target == null) return;
                  File f = new File(target);
                  if (f.exists()) {
                    YesNoDialog d = new YesNoDialog(YesNoDialog.POSITION_CENTER);
                    d.setTitle(Application.getI18n().tr("Überschreiben?"));
                    d.setText(Application.getI18n().tr("Datei existiert bereits. Überschreiben?"));
                    Boolean b = (Boolean) d.open();
                    if (!b.booleanValue()) return;
                  }
                  OutputStream os = null;
                  try {
                    os = new FileOutputStream(f);
                    os.write(cert.getEncoded());
                    os.flush();
                    mySettings.setAttribute("lastdir", f.getParent());
                    Application.getMessagingFactory()
                        .sendMessage(
                            new StatusBarMessage(
                                Application.getI18n().tr("Zertifikate exportiert"),
                                StatusBarMessage.TYPE_SUCCESS));
                  } finally {
                    if (os != null) os.close();
                  }
                } catch (OperationCanceledException oce) {
                  Logger.info(oce.getMessage());
                  return;
                } catch (Exception e) {
                  Logger.error("unable to export certificate", e);
                  Application.getMessagingFactory()
                      .sendMessage(
                          new StatusBarMessage(
                              Application.getI18n().tr("Fehler beim Export des Zertifikates"),
                              StatusBarMessage.TYPE_ERROR));
                }
              }
            },
            "document-save.png"));
    menu.addItem(
        new ContextMenuItem(
            Application.getI18n().tr("Importieren..."),
            new Action() {
              public void handleAction(Object context) throws ApplicationException {
                new CertificateImport().handleAction(context);
                GUI.startView(
                    GUI.getCurrentView().getClass(), GUI.getCurrentView().getCurrentObject());
              }
            },
            "document-open.png") {
          public boolean isEnabledFor(Object o) {
            return changable && super.isEnabledFor(o);
          }
        });
    this.setContextMenu(menu);
  }