@Override
 public void done(SyncTask task) {
   if (task.task.equals(SyncTask.TASK_DOWN_DATA)) {
     Category c = null;
     c = book.root.search(task.local.id);
     if (c != null && c.getMessage() != null) {
       storage.save(c.getMessage());
       mainFrame.editor.reloadDocument(c.getMessage());
     }
   }
 }
 public void NewNote(BookAction event) {
   Category parent = selectedTreeNode();
   if (parent == null) {
     JOptionPane.showMessageDialog(
         mainFrame, "没有选择添加到哪一个目录.", "Error", JOptionPane.ERROR_MESSAGE);
   } else if (parent.isLeaf()) {
     JOptionPane.showMessageDialog(
         mainFrame, "不能在文件上面创建文件.", "Error", JOptionPane.ERROR_MESSAGE);
   } else {
     parent.addMessage("新建文件");
   }
 }
 public void Remove(BookAction event) {
   Category object = selectedTreeNode();
   if (object == null) {
     JOptionPane.showMessageDialog(mainFrame, "请选择需要删除的对象.", "Error", JOptionPane.ERROR_MESSAGE);
   } else {
     int i =
         JOptionPane.showConfirmDialog(
             mainFrame, "确定需要删除 '" + object.name + "'.", "确认", JOptionPane.OK_CANCEL_OPTION);
     if (i == 0) {
       object.remove();
     }
   }
 }
 public void Open(BookAction event) {
   final Category node = selectedTreeNode();
   if (node.isLeaf()) {
     actionThread.execute(
         new Runnable() {
           @Override
           public void run() {
             saveOpenedMessage();
             NoteMessage msg = node.getMessage(storage, true);
             mainFrame.editor.openDocument(msg);
             book.curNoteId = node.id;
           }
         });
     mainFrame.status("Opening " + node.name + "(" + node.id + ")");
   }
 }
 public void ReName(BookAction event) {
   Category object = selectedTreeNode();
   if (object == null) {
     JOptionPane.showMessageDialog(
         mainFrame, "请选择需要重命名的对象.", "Error", JOptionPane.ERROR_MESSAGE);
   } else {
     String s =
         (String)
             JOptionPane.showInputDialog(
                 mainFrame,
                 "输入新名字:\n",
                 "重命名",
                 JOptionPane.PLAIN_MESSAGE,
                 null,
                 null,
                 object.getName());
     if (s != null) {
       object.setName(s);
     }
   }
 }
 private void restoreLastStatus() {
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           Vector<TreePath> expaned = new Vector<TreePath>();
           if (book.expaned != null) {
             expaned.addAll(book.expaned);
             book.expaned.clear();
           } else {
             book.expaned = new Vector<TreePath>();
           }
           for (TreePath path : expaned) {
             mainFrame.tree.expandPath(path);
           }
         }
       });
   if (book.curNoteId != null && !book.curNoteId.equals("")) {
     Category node = book.root.search(book.curNoteId);
     if (node != null) {
       NoteMessage msg = node.getMessage(storage, true);
       mainFrame.editor.openDocument(msg);
     }
   }
 }
 public void OrderMoveDown(BookAction event) {
   Category object = selectedTreeNode();
   object.moveOrder(1);
 }
 public void OrderByName(BookAction event) {
   Category object = selectedTreeNode();
   object.orderBy("name");
 }
 public void OrderByUpdate(BookAction event) {
   Category object = selectedTreeNode();
   object.orderBy("update_date");
 }
 public void OrderByPosition(BookAction event) {
   Category object = selectedTreeNode();
   object.orderBy("position");
 }