--- /dev/null
+/*\r
+ * This file is part of NeverNote \r
+ * Copyright 2009 Randy Baumgarte\r
+ * \r
+ * This file may be licensed under the terms of of the\r
+ * GNU General Public License Version 2 (the ``GPL'').\r
+ *\r
+ * Software distributed under the License is distributed\r
+ * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
+ * express or implied. See the GPL for the specific language\r
+ * governing rights and limitations.\r
+ *\r
+ * You should have received a copy of the GPL along with this\r
+ * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
+ * or write to the Free Software Foundation, Inc.,\r
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
+ *\r
+*/\r
+\r
+package cx.fbn.nevernote.filters;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import com.evernote.edam.type.Note;\r
+import com.evernote.edam.type.Notebook;\r
+\r
+import cx.fbn.nevernote.sql.DatabaseConnection;\r
+import cx.fbn.nevernote.utilities.ApplicationLogger;\r
+\r
+public class FilterEditorNotebooks {\r
+ DatabaseConnection conn;\r
+ ApplicationLogger logger;\r
+ \r
+ public FilterEditorNotebooks(DatabaseConnection conn, ApplicationLogger logger) {\r
+ this.logger = logger;\r
+ this.conn = conn;\r
+ }\r
+ \r
+ \r
+ public List<Notebook> getValidNotebooks(Note note, List<Notebook> notebooks) {\r
+ \r
+ List<Notebook> books = new ArrayList<Notebook>();\r
+ for (int i=0; i<notebooks.size(); i++) \r
+ books.add(notebooks.get(i));\r
+ \r
+ // If this is a new note, it isn't tied to any particular notebook.h\r
+ if (note == null || note.getUpdateSequenceNum() == 0) {\r
+ for (int i=books.size()-1; i>=0; i--) {\r
+ if (conn.getNotebookTable().isReadOnly(books.get(i).getGuid()))\r
+ books.remove(i);\r
+ }\r
+ return books;\r
+ }\r
+ \r
+ boolean linked = conn.getNotebookTable().isLinked(note.getNotebookGuid());\r
+ \r
+ // If the notebook is linked, then we really only need to return the one notebookd\r
+ if (linked) {\r
+ List<Notebook> newList = new ArrayList<Notebook>();\r
+ for (int i=0; i<books.size(); i++) {\r
+ if (books.get(i).getGuid().equals(note.getNotebookGuid())) {\r
+ newList.add(books.get(i));\r
+ return newList;\r
+ }\r
+ }\r
+ } \r
+ // If the note's notebook isn't linked, then we need to return any non-linked notebook\r
+ List<Notebook> newList = new ArrayList<Notebook>();\r
+ for (int i=0; i<books.size(); i++) {\r
+ if (!conn.getNotebookTable().isLinked(books.get(i).getGuid())) {\r
+ newList.add(books.get(i));\r
+ }\r
+ }\r
+ return newList;\r
+ }\r
+\r
+}\r