Пример #1
0
 /**
  * get the folder where attachments are stored
  *
  * @return the attachment folder path
  */
 public static String attachmentFolder() {
   String dbtype = Prefs.getPref(PrefName.DBTYPE);
   if (dbtype.equals("hsqldb")) {
     String path = Prefs.getPref(PrefName.HSQLDBDIR) + "/attachments";
     File f = new File(path);
     if (!f.exists()) {
       if (!f.mkdir()) {
         Errmsg.getErrorHandler().notice(Resource.getResourceString("att_folder_err") + path);
         return null;
       }
     }
     return path;
   }
   if (dbtype.equals("h2")) {
     String path = Prefs.getPref(PrefName.H2DIR) + "/attachments";
     File f = new File(path);
     if (!f.exists()) {
       if (!f.mkdir()) {
         Errmsg.getErrorHandler().notice(Resource.getResourceString("att_folder_err") + path);
         return null;
       }
     }
     return path;
   }
   return null;
 }
  /*
   * (non-Javadoc)
   *
   * @see net.sf.borg.ui.options.OptionsView.OptionsPanel#applyChanges()
   */
  @Override
  public void applyChanges() {

    if (verboseLogging.isSelected()) log.setLevel(Level.ALL);
    else log.setLevel(Level.INFO);

    OptionsPanel.setBooleanPref(colorprint, PrefName.COLORPRINT);

    OptionsPanel.setBooleanPref(splashbox, PrefName.SPLASH);
    OptionsPanel.setBooleanPref(stackbox, PrefName.STACKTRACE);

    OptionsPanel.setBooleanPref(useSysTray, PrefName.USESYSTRAY);
    OptionsPanel.setBooleanPref(startToSysTray, PrefName.BACKGSTART);
    OptionsPanel.setBooleanPref(dateInSysTray, PrefName.SYSTRAYDATE);
    OptionsPanel.setBooleanPref(dynamicLoading, PrefName.DYNAMIC_LOADING);
    OptionsPanel.setBooleanPref(verboseLogging, PrefName.DEBUG);
    OptionsPanel.setBooleanPref(useProxy, PrefName.USE_PROXY);

    Prefs.putPref(PrefName.BACKUPDIR, backupDir.getText());

    if (shutdownAction.getSelectedIndex() == 0)
      Prefs.putPref(PrefName.SHUTDOWN_ACTION, SHUTDOWN_ACTION.PROMPT.toString());
    else if (shutdownAction.getSelectedIndex() == 1)
      Prefs.putPref(PrefName.SHUTDOWN_ACTION, SHUTDOWN_ACTION.NONE.toString());
    else if (shutdownAction.getSelectedIndex() == 2)
      Prefs.putPref(PrefName.SHUTDOWN_ACTION, SHUTDOWN_ACTION.BACKUP.toString());
    else if (shutdownAction.getSelectedIndex() == 3)
      Prefs.putPref(PrefName.SHUTDOWN_ACTION, SHUTDOWN_ACTION.EMAIL.toString());

    // validate that socket is a number
    try {
      int socket = Integer.parseInt(socketPort.getText());
      Prefs.putPref(PrefName.SOCKETPORT, new Integer(socket));
    } catch (NumberFormatException e) {
      Errmsg.getErrorHandler().notice(Resource.getResourceString("socket_warn"));
      socketPort.setText("-1");
      Prefs.putPref(PrefName.SOCKETPORT, new Integer(-1));
    }

    Prefs.putPref(PrefName.PROXY_HOST, proxyHostText.getText());

    try {
      int port = Integer.parseInt(proxyPortText.getText());
      Prefs.putPref(PrefName.PROXY_PORT, new Integer(port));
    } catch (NumberFormatException e) {
      Errmsg.getErrorHandler().notice(Resource.getResourceString("proxy_warn"));
    }
  }
Пример #3
0
  /**
   * Adds a link.
   *
   * @param owner the owning Entity
   * @param pathIn the path (url, filepath, or entity key)
   * @param linkType the link type
   * @throws Exception the exception
   */
  public void addLink(KeyedEntity<?> owner, String pathIn, LinkType linkType) throws Exception {
    String path = pathIn;
    if (owner == null) {
      Errmsg.getErrorHandler().notice(Resource.getResourceString("att_owner_null"));
      return;
    }

    if (linkType == LinkType.ATTACHMENT) {

      String atfolder = attachmentFolder();
      if (atfolder == null) throw new Exception("attachments not supported");

      // need to copy file and create new path
      File orig = new File(path);
      String fname = orig.getName();
      String newpath = atfolder + "/" + fname;

      int i = 1;
      while (true) {
        File newfile = new File(newpath);
        if (!newfile.exists()) break;

        fname = Integer.toString(i) + orig.getName();
        newpath = atfolder + "/" + fname;
        i++;
      }

      copyFile(path, newpath);
      path = fname;
    }

    Link at = newLink();
    at.setKey(-1);
    at.setOwnerKey(new Integer(owner.getKey()));
    LinkType type = typemap.get(owner.getClass());
    if (type == null) throw new Exception("illegal link owner type");
    at.setOwnerType(type.toString());
    at.setPath(path);
    at.setLinkType(linkType.toString());
    saveLink(at);

    // * modification for backtrace/2way link

    if (linkType == LinkType.ADDRESS
        || linkType == LinkType.APPOINTMENT
        || linkType == LinkType.PROJECT
        || linkType == LinkType.TASK) {
      Link at2way = newLink();
      at2way.setKey(-1);
      at2way.setOwnerKey(new Integer(at.getPath()));
      at2way.setOwnerType(at.getLinkType());
      at2way.setPath(at.getOwnerKey().toString());
      at2way.setLinkType(at.getOwnerType());
      saveLink(at2way);
    }
    // end of modification

  }
 /** if the reminder instance is a todo, then mark it as done/complete */
 @Override
 public void do_todo(boolean delete) {
   if (appt != null)
     try {
       AppointmentModel.getReference().do_todo(appt.getKey(), delete);
     } catch (Exception e) {
       Errmsg.getErrorHandler().errmsg(e);
     }
 }
Пример #5
0
  /**
   * constructor
   *
   * @param p the project
   * @param function the action being taken
   * @param parentId the parent project id, if any
   * @throws Exception the exception
   */
  public ProjectView(Project p, Action function, Integer parentId) {
    super();

    // listen for task model changes
    addModel(TaskModel.getReference());

    initComponents(); // init the GUI widgets

    // load the categories
    try {
      Collection<String> cats = CategoryModel.getReference().getCategories();
      Iterator<String> it = cats.iterator();
      while (it.hasNext()) {
        categoryBox.addItem(it.next());
      }
      categoryBox.setSelectedIndex(0);

      // show the project
      showProject(function, p, parentId);
    } catch (Exception e) {
      Errmsg.getErrorHandler().errmsg(e);
    }
  }
Пример #6
0
  /** Save project. */
  private void saveProject() {

    // validate that description is present
    if (description.getText() == null || description.getText().equals("")) {
      Errmsg.getErrorHandler().notice(Resource.getResourceString("empty_desc"));
      return;
    }
    try {

      String num = projectIdText.getText();

      Project p = new Project();

      if (!num.equals("NEW") && !num.equals("CLONE")) {
        p.setKey(Integer.parseInt(num));
      }

      // fill in the fields from the screen
      Calendar cal = startDateChooser.getCalendar();
      if (cal == null) cal = new GregorianCalendar();
      p.setStartDate(cal.getTime()); // start date

      cal = dueDateChooser.getCalendar();
      if (cal != null) {
        p.setDueDate(cal.getTime()); // due date

        // validate due date
        if (DateUtil.isAfter(p.getStartDate(), p.getDueDate())) {
          throw new Warning(Resource.getResourceString("sd_dd_warn"));
        }
      }

      p.setDescription(description.getText());
      p.setStatus((String) statusComboBox.getSelectedItem());

      String cat = (String) categoryBox.getSelectedItem();
      if (cat.equals("") || cat.equals(CategoryModel.UNCATEGORIZED)) {
        p.setCategory(null);
      } else {
        p.setCategory(cat);
      }

      p.setParent(null);
      String proj = (String) parentProjectComboBox.getSelectedItem();
      try {
        p.setParent(getProjectId(proj));

      } catch (Exception e) {
        // no project selected
      }

      TaskModel.getReference().saveProject(p);
      p.setKey(p.getKey());

      showProject(Action.CHANGE, p, null);
    } catch (Warning w) {
      Errmsg.getErrorHandler().notice(w.getMessage());
    } catch (Exception e) {
      Errmsg.getErrorHandler().errmsg(e);
    }
  }
Пример #7
0
  /**
   * Main UI initialization.
   *
   * @param trayname - name for the tray icon
   */
  public static void startUI(String trayname) {

    Errmsg.setErrorHandler(new UIErrorHandler());

    // check database timestamp
    try {
      JdbcDB.checkTimestamp();
    } catch (Warning e1) {
      Errmsg.getErrorHandler().notice(e1.getMessage());
    } catch (Exception e) {
      Errmsg.getErrorHandler().errmsg(e);
    }

    // default font
    String deffont = Prefs.getPref(PrefName.DEFFONT);
    if (!deffont.equals("")) {
      Font f = Font.decode(deffont);
      NwFontChooserS.setDefaultFont(f);
    }

    // set the look and feel
    String lnf = Prefs.getPref(PrefName.LNF);
    try {

      // set default jgoodies theme
      if (lnf.contains("jgoodies")) {
        String theme = System.getProperty("Plastic.defaultTheme");
        if (theme == null) {
          System.setProperty("Plastic.defaultTheme", Prefs.getPref(PrefName.GOODIESTHEME));
        }
      }

      UIManager.setLookAndFeel(lnf);
      UIManager.getLookAndFeelDefaults().put("ClassLoader", UIControl.class.getClassLoader());
    } catch (Exception e) {
      log.severe(e.toString());
    }

    // pop up the splash if the option is set
    if (Prefs.getBoolPref(PrefName.SPLASH)) {
      splashScreen = new SplashScreen();
      splashScreen.setText(Resource.getResourceString("Initializing"));
      splashScreen.setVisible(true);
      final String tn = trayname;

      /*
       * in order for the splash to be seen, we will complete
       * initialization later (in the swing thread).
       */
      Timer t =
          new Timer(
              3000,
              new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent arg0) {
                  completeUIInitialization(tn);
                }
              });
      t.setRepeats(false);
      t.start();
    } else completeUIInitialization(trayname);
  }
Пример #8
0
  /** shuts down the UI, including db backup */
  public static void shutDownUI() {

    // prompt for shutdown and backup options
    boolean do_backup = false;
    boolean backup_email = false;
    final String backupdir = Prefs.getPref(PrefName.BACKUPDIR);

    if (backupdir != null && !backupdir.equals("")) {

      String shutdown_action = Prefs.getPref(PrefName.SHUTDOWN_ACTION);
      if (shutdown_action.isEmpty() || SHUTDOWN_ACTION.PROMPT.toString().equals(shutdown_action)) {
        JRadioButton b1 =
            new JRadioButton(Resource.getResourceString("backup_notice") + " " + backupdir);
        JRadioButton b2 = new JRadioButton(Resource.getResourceString("exit_no_backup"));
        JRadioButton b3 = new JRadioButton(Resource.getResourceString("dont_exit"));
        JRadioButton b4 = new JRadioButton(Resource.getResourceString("backup_with_email"));

        b1.setSelected(true);

        ButtonGroup group = new ButtonGroup();
        group.add(b1);
        group.add(b2);
        group.add(b3);
        group.add(b4);

        Object[] array = {
          b1, b4, b2, b3,
        };

        int res =
            JOptionPane.showConfirmDialog(
                null,
                array,
                Resource.getResourceString("shutdown_options"),
                JOptionPane.OK_CANCEL_OPTION);

        if (res != JOptionPane.YES_OPTION) {
          return;
        }

        if (b3.isSelected()) return;
        if (b1.isSelected() || b4.isSelected()) do_backup = true;
        if (b4.isSelected()) backup_email = true;
      } else if (SHUTDOWN_ACTION.BACKUP.toString().equals(shutdown_action)) {
        do_backup = true;
      } else if (SHUTDOWN_ACTION.EMAIL.toString().equals(shutdown_action)) {
        do_backup = true;
        backup_email = true;
      }
    }

    // stop popup timer and destroy popups
    ReminderManager rm = ReminderManager.getReminderManager();
    if (rm != null) rm.remove();

    // show a splash screen for shutdown
    try {
      SplashScreen ban = new SplashScreen();
      ban.setText(Resource.getResourceString("shutdown"));
      ban.setVisible(true);

    } catch (Exception e) {
      e.printStackTrace();
    }

    // backup data
    if (do_backup == true) {
      try {
        ExportImport.exportToZip(backupdir, backup_email);
      } catch (Exception e) {
        Errmsg.getErrorHandler().errmsg(e);
        return;
      }
    }

    // non-UI shutdown
    if (shutdownListener != null) shutdownListener.update(null, null);
  }