Ejemplo n.º 1
0
  /** @see de.willuhn.jameica.gui.Part#paint(org.eclipse.swt.widgets.Composite) */
  public void paint(Composite parent) throws RemoteException {
    button = GUI.getStyleFactory().createButton(parent);
    button.setText(this.title == null ? "" : this.title);
    button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
    if (this.icon != null) button.setImage(SWTUtil.getImage(this.icon));

    try {
      if (this.isDefault) parent.getShell().setDefaultButton(button);
    } catch (IllegalArgumentException ae) {
      // Kann unter MacOS wohl passieren. Siehe Mail von
      // Jan Lolling vom 22.09.2006. Mal schauen, ob wir
      // Fehlertext: "Widget has the wrong parent"
      // Wir versuchen es mal mit der Shell der GUI.
      try {
        GUI.getShell().setDefaultButton(button);
      } catch (IllegalArgumentException ae2) {
        // Geht auch nicht? Na gut, dann lassen wir es halt bleiben
        Logger.warn("unable to set default button: " + ae2.getLocalizedMessage());
      }
    }

    button.setEnabled(this.enabled);

    button.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            GUI.startSync(
                new Runnable() {
                  public void run() {
                    try {
                      action.handleAction(context);
                    } catch (ApplicationException e) {
                      Application.getMessagingFactory()
                          .sendMessage(
                              new StatusBarMessage(e.getMessage(), StatusBarMessage.TYPE_ERROR));
                    }
                  }
                });
          }
        });
  }
Ejemplo n.º 2
0
  private void init() throws IOException {
    FileDialog fd = new FileDialog(GUI.getShell(), SWT.SAVE);
    fd.setText("Ausgabedatei wählen.");
    String path = settings.getString("lastdir", System.getProperty("user.home"));
    if (path != null && path.length() > 0) {
      fd.setFilterPath(path);
    }
    fd.setFileName(
        new Dateiname(
                "kontoauszug", "", Einstellungen.getEinstellung().getDateinamenmuster(), "PDF")
            .get());
    fd.setFilterExtensions(new String[] {"*.PDF"});

    String s = fd.open();
    if (s == null || s.length() == 0) {
      return;
    }
    if (!s.endsWith(".PDF")) {
      s = s + ".PDF";
    }
    file = new File(s);
    settings.setAttribute("lastdir", file.getParent());
  }
  /** @see de.willuhn.jameica.gui.Action#handleAction(java.lang.Object) */
  public void handleAction(Object context) {
    try {
      DBIterator it = Einstellungen.getDBService().createList(Mitglied.class);
      if (it.size() > 0) {
        SimpleDialog dialog = new SimpleDialog(SimpleDialog.POSITION_CENTER);
        dialog.setTitle("Fehler");
        dialog.setText("Datenbank ist nicht leer!");
        dialog.open();
        return;
      }

      // Vom System eingefügte Sätze löschen. Ansonsten gibt es duplicate keys
      it = Einstellungen.getDBService().createList(Adresstyp.class);
      while (it.hasNext()) {
        Adresstyp a = (Adresstyp) it.next();
        a.delete();
      }

    } catch (Exception e1) {
      Logger.error("Fehler: ", e1);
    }

    FileDialog fd = new FileDialog(GUI.getShell(), SWT.OPEN);
    fd.setFileName("jverein-" + new JVDateFormatJJJJMMTT().format(new Date()) + ".xml");
    fd.setFilterExtensions(new String[] {"*.xml"});
    fd.setText(JVereinPlugin.getI18n().tr("Bitte wählen Sie die Backup-Datei aus"));
    String f = fd.open();
    if (f == null || f.length() == 0) {
      return;
    }

    final File file = new File(f);
    if (!file.exists()) {
      return;
    }

    Application.getController()
        .start(
            new BackgroundTask() {

              private boolean cancel = false;

              /**
               * @see de.willuhn.jameica.system.BackgroundTask#run(de.willuhn.util.ProgressMonitor)
               */
              public void run(ProgressMonitor monitor) throws ApplicationException {
                monitor.setStatusText(JVereinPlugin.getI18n().tr("Importiere Backup"));
                Logger.info("importing backup " + file.getAbsolutePath());
                final ClassLoader loader =
                    Application.getPluginLoader()
                        .getPlugin(JVereinPlugin.class)
                        .getResources()
                        .getClassLoader();

                try {
                  EigenschaftGruppe eg =
                      (EigenschaftGruppe)
                          Einstellungen.getDBService().createObject(EigenschaftGruppe.class, "1");
                  eg.delete();
                } catch (RemoteException e1) {
                  Logger.error("EigenschaftGruppe mit id=1 kann nicht gelöscht werden", e1);
                }

                Reader reader = null;
                try {
                  InputStream is = new BufferedInputStream(new FileInputStream(file));
                  reader =
                      new XmlReader(
                          is,
                          new ObjectFactory() {

                            public GenericObject create(String type, String id, Map values)
                                throws Exception {
                              AbstractDBObject object =
                                  (AbstractDBObject)
                                      Einstellungen.getDBService()
                                          .createObject(loader.loadClass(type), null);
                              object.setID(id);
                              Iterator<?> i = values.keySet().iterator();
                              while (i.hasNext()) {
                                String name = (String) i.next();
                                object.setAttribute(name, values.get(name));
                              }
                              return object;
                            }
                          });

                  long count = 1;
                  GenericObject o = null;
                  while ((o = reader.read()) != null) {
                    try {
                      ((AbstractDBObject) o).insert();
                    } catch (Exception e) {
                      Logger.error(
                          "unable to import "
                              + o.getClass().getName()
                              + ":"
                              + o.getID()
                              + ", skipping",
                          e);
                      monitor.log(
                          JVereinPlugin.getI18n()
                              .tr(
                                  " {0} fehlerhaft: {1}, überspringe ",
                                  new String[] {BeanUtil.toString(o), e.getMessage()}));
                    }
                    if (count++ % 100 == 0) {
                      monitor.addPercentComplete(1);
                    }
                  }
                  monitor.setStatus(ProgressMonitor.STATUS_DONE);
                  monitor.setStatusText(JVereinPlugin.getI18n().tr("Backup importiert"));
                  monitor.setPercentComplete(100);
                } catch (Exception e) {
                  Logger.error("error while importing data", e);
                  throw new ApplicationException(e.getMessage());
                } finally {
                  if (reader != null) {
                    try {
                      reader.close();
                      Logger.info("backup imported");
                    } catch (Exception e) {
                      /* useless */
                    }
                  }
                }
              }

              /** @see de.willuhn.jameica.system.BackgroundTask#isInterrupted() */
              public boolean isInterrupted() {
                return this.cancel;
              }

              /** @see de.willuhn.jameica.system.BackgroundTask#interrupt() */
              public void interrupt() {
                this.cancel = true;
              }
            });
  }
Ejemplo n.º 4
0
  /**
   * Importiert die Daten.
   *
   * @throws ApplicationException
   */
  private void doImport() throws ApplicationException {
    Imp imp = null;

    try {
      imp = (Imp) getImporterList().getValue();
    } catch (Exception e) {
      Logger.error("error while saving import file", e);
      throw new ApplicationException(i18n.tr("Fehler beim Starten des Imports"), e);
    }

    if (imp == null || imp.importer == null)
      throw new ApplicationException(i18n.tr("Bitte wählen Sie ein Import-Format aus"));

    Settings settings = new Settings(this.getClass());
    settings.setStoreWhenRead(true);

    FileDialog fd = new FileDialog(GUI.getShell(), SWT.OPEN);
    fd.setText(
        i18n.tr("Bitte wählen Sie die Datei aus, welche für den Import verwendet werden soll."));
    fd.setFilterNames(imp.format.getFileExtensions());

    String path = settings.getString("lastdir", System.getProperty("user.home"));
    if (path != null && path.length() > 0) fd.setFilterPath(path);

    final String s = fd.open();

    if (s == null || s.length() == 0) {
      close();
      return;
    }

    final File file = new File(s);
    if (!file.exists() || !file.isFile())
      throw new ApplicationException(i18n.tr("Datei existiert nicht oder ist nicht lesbar"));

    // Wir merken uns noch das Verzeichnis vom letzten mal
    settings.setAttribute("lastdir", file.getParent());

    // Dialog schliessen
    close();

    final Importer importer = imp.importer;
    final IOFormat format = imp.format;

    BackgroundTask t =
        new BackgroundTask() {
          public void run(ProgressMonitor monitor) throws ApplicationException {
            try {
              InputStream is = new BufferedInputStream(new FileInputStream(file));
              importer.doImport(context, format, is, monitor);
              monitor.setPercentComplete(100);
              monitor.setStatus(ProgressMonitor.STATUS_DONE);
              GUI.getStatusBar().setSuccessText(i18n.tr("Daten importiert aus {0}", s));
              GUI.getCurrentView().reload();
            } catch (ApplicationException ae) {
              monitor.setStatus(ProgressMonitor.STATUS_ERROR);
              monitor.setStatusText(ae.getMessage());
              GUI.getStatusBar().setErrorText(ae.getMessage());
              throw ae;
            } catch (Exception e) {
              monitor.setStatus(ProgressMonitor.STATUS_ERROR);
              Logger.error("error while reading objects from " + s, e);
              ApplicationException ae =
                  new ApplicationException(
                      i18n.tr("Fehler beim Importieren der Daten aus {0}", s), e);
              monitor.setStatusText(ae.getMessage());
              GUI.getStatusBar().setErrorText(ae.getMessage());
              throw ae;
            }
          }

          public void interrupt() {}

          public boolean isInterrupted() {
            return false;
          }
        };

    Application.getController().start(t);
  }