void newResB_actionPerformed(ActionEvent e) {
    AddResourceDialog dlg = new AddResourceDialog(App.getFrame(), Local.getString("New resource"));
    Dimension frmSize = App.getFrame().getSize();
    Point loc = App.getFrame().getLocation();
    dlg.setLocation(
        (frmSize.width - dlg.getSize().width) / 2 + loc.x,
        (frmSize.height - dlg.getSize().height) / 2 + loc.y);
    dlg.setVisible(true);
    if (dlg.CANCELLED) return;
    if (dlg.localFileRB.isSelected()) {
      String fpath = dlg.pathField.getText();
      MimeType mt = MimeTypesList.getMimeTypeForFile(fpath);
      if (mt.getMimeTypeId().equals("__UNKNOWN")) {
        mt = addResourceType(fpath);
        if (mt == null) return;
      }
      if (!checkApp(mt)) return;
      // if file if projectFile, than copy the file and change url.
      if (dlg.projectFileCB.isSelected()) {
        fpath = copyFileToProjectDir(fpath);
        CurrentProject.getResourcesList().addResource(fpath, false, true);
      } else CurrentProject.getResourcesList().addResource(fpath);

      resourcesTable.tableChanged();
    } else {
      if (!Util.checkBrowser()) return;
      CurrentProject.getResourcesList().addResource(dlg.urlField.getText(), true, false);
      resourcesTable.tableChanged();
    }
  }
 /** @see javax.swing.tree.TreeModel#getChildCount(java.lang.Object) */
 public int getChildCount(Object parent) {
   if (parent instanceof IProject) {
     if (activeOnly()) {
       return CurrentProject.getTaskList().getActiveSubTasks(null, CurrentDate.get()).size();
     } else return CurrentProject.getTaskList().getTopLevelTasks().size();
   }
   ITask t = (ITask) parent;
   if (activeOnly())
     return CurrentProject.getTaskList().getActiveSubTasks(t.getID(), CurrentDate.get()).size();
   else return t.getSubTasks().size();
 }
 /** @see javax.swing.tree.TreeModel#getChild(java.lang.Object, int) */
 public Object getChild(Object parent, int index) {
   if (parent instanceof IProject)
     if (activeOnly())
       return CurrentProject.getTaskList()
           .getActiveSubTasks(null, CurrentDate.get())
           .toArray()[index];
     else return CurrentProject.getTaskList().getTopLevelTasks().toArray()[index];
   ITask t = (ITask) parent;
   if (activeOnly())
     return CurrentProject.getTaskList()
         .getActiveSubTasks(t.getID(), CurrentDate.get())
         .toArray()[index];
   else return t.getSubTasks().toArray()[index];
 }
  // Sort
  void sortTasks(ArrayList<String> ids) {
    String[] array = new String[ids.size()];

    for (int i = 0; i < array.length; i++) {
      array[i] = ids.get(i);
    }

    CurrentProject.getProcessList().getProcess(processId).setTaskOrder(array);
    CurrentStorage.get().storeProcessList(CurrentProject.getProcessList(), CurrentProject.get());

    this.getContentPane().remove(taskPanel);
    drawTaskPanel();
    pack();
  }
 void removeResB_actionPerformed(ActionEvent e) {
   int[] toRemove = resourcesTable.getSelectedRows();
   String msg = "";
   if (toRemove.length == 1)
     msg =
         Local.getString("Remove the shortcut to resource")
             + "\n'"
             + resourcesTable.getModel().getValueAt(toRemove[0], 0)
             + "'";
   else
     msg = Local.getString("Remove") + " " + toRemove.length + " " + Local.getString("shortcuts");
   msg += "\n" + Local.getString("Are you sure?");
   int n =
       JOptionPane.showConfirmDialog(
           App.getFrame(), msg, Local.getString("Remove resource"), JOptionPane.YES_NO_OPTION);
   if (n != JOptionPane.YES_OPTION) return;
   for (int i = 0; i < toRemove.length; i++) {
     CurrentProject.getResourcesList()
         .removeResource(
             ((Resource)
                     resourcesTable.getModel().getValueAt(toRemove[i], ResourcesTable._RESOURCE))
                 .getPath());
   }
   resourcesTable.tableChanged();
 }
  public Object getChild(Object parent, int index) {
    Collection c = null;

    if (parent instanceof IProject) {
      if (activeOnly()) c = CurrentProject.getTaskList().getActiveSubTasks(null, CurrentDate.get());
      else c = CurrentProject.getTaskList().getTopLevelTasks();
    } else {
      ITask t = (ITask) parent;
      if (activeOnly())
        c = CurrentProject.getTaskList().getActiveSubTasks(t.getID(), CurrentDate.get());
      else c = t.getSubTasks();
    }

    Object array[] = c.toArray();
    Arrays.sort(array, comparator);
    if (opposite) {
      return array[array.length - index - 1];
    }
    return array[index];
  }
  /**
   * Copy a file to the directory of the current project
   *
   * @param srcStr The path of the source file.
   * @param destStr The destination path.
   * @return The new path of the file.
   */
  String copyFileToProjectDir(String srcStr) {

    String JN_DOCPATH = Util.getEnvDir();

    String baseName;
    int i = srcStr.lastIndexOf(File.separator);
    if (i != -1) {
      baseName = srcStr.substring(i + 1);
    } else baseName = srcStr;

    String destStr =
        JN_DOCPATH
            + CurrentProject.get().getID()
            + File.separator
            + "_projectFiles"
            + File.separator
            + baseName;

    File f = new File(JN_DOCPATH + CurrentProject.get().getID() + File.separator + "_projectFiles");
    if (!f.exists()) {
      f.mkdirs();
    }
    System.out.println("[DEBUG] Copy file from: " + srcStr + " to: " + destStr);

    try {
      FileInputStream in = new FileInputStream(srcStr);
      FileOutputStream out = new FileOutputStream(destStr);
      byte[] buf = new byte[4096];
      int len;
      while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
      }
      out.close();
      in.close();
    } catch (IOException e) {
      System.err.println(e.toString());
    }

    return destStr;
  }
 /**
  * JAVADOC: Constructor of <code>TaskTableModel</code>
  *
  * @param root
  */
 public TaskTableModel() {
   super(CurrentProject.get());
 }
  // Tasks UI
  void drawTaskPanel() {
    if (processId != null) {
      Collection<Task> tasks = CurrentProject.getProcessList().getProcess(processId).getTasks();
      taskIds = new ArrayList<>();
      List<Task> taskList = new ArrayList<>(tasks);
      DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
      GridBagConstraints gc = new GridBagConstraints();
      gc.ipadx = 3;
      gc.ipady = 3;
      gc.gridy = 0;
      gc.weightx = 1;
      gc.weighty = 1;
      gc.anchor = GridBagConstraints.WEST;

      taskInnerPanel = new JPanel(new GridBagLayout());

      {
        JLabel title = new JLabel(Local.getString("Task"));
        JLabel status = new JLabel(Local.getString("Status"));
        JLabel priority = new JLabel(Local.getString("Priority"));

        gc.gridx = 1;
        taskInnerPanel.add(title, gc);
        gc.gridx = 2;
        taskInnerPanel.add(status, gc);
        gc.gridx = 3;
        taskInnerPanel.add(priority, gc);
      }

      for (Task task : taskList) {
        Util.debug("Adding task: " + task.getText());

        BasicArrowButton up = new BasicArrowButton(BasicArrowButton.NORTH);
        BasicArrowButton dn = new BasicArrowButton(BasicArrowButton.SOUTH);
        JLabel title = new JLabel(task.getText());
        JLabel status = new JLabel(task.getStatusString());
        JLabel priority = new JLabel(task.getPriorityString());

        gc.gridy = gc.gridy + 1;
        gc.gridx = 0;
        gc.gridx = 1;
        gc.anchor = GridBagConstraints.WEST;
        taskInnerPanel.add(title, gc);
        gc.gridx = 2;
        taskInnerPanel.add(status, gc);
        gc.gridx = 3;
        taskInnerPanel.add(priority, gc);
        gc.gridx = 4;
        gc.anchor = GridBagConstraints.CENTER;
        taskInnerPanel.add(up, gc);
        gc.gridx = 5;
        gc.anchor = GridBagConstraints.CENTER;
        taskInnerPanel.add(dn, gc);

        up.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent action) {
                int index = taskList.indexOf(task);

                if (index > 0) {
                  Collections.swap(taskList, index, index - 1);
                  Collections.swap(taskIds, index, index - 1);

                  sortTasks(taskIds);
                }
              }
            });

        dn.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent action) {
                int index = taskList.indexOf(task);

                if (index < taskList.size() - 1) {
                  Collections.swap(taskList, index, index + 1);
                  Collections.swap(taskIds, index, index + 1);

                  sortTasks(taskIds);
                }
              }
            });

        taskIds.add(task.getID());
      }

      taskScrollPane = new JScrollPane(taskInnerPanel);

      taskPanel = new JPanel(new BorderLayout());
      taskPanel.setPreferredSize(new Dimension(400, 300));
      taskPanel.setBorder(defaultBorder);
      taskPanel.add(taskScrollPane, BorderLayout.CENTER);
      this.getContentPane().add(taskPanel, BorderLayout.CENTER);
    }
  }