changeset 86:2a93d2a65b0f

TabCalendarBoard: Saving and loading of calendar board card Also started on column saving.
author Fox
date Mon, 06 Feb 2023 23:58:57 +0100
parents 9eb88ddd4e94
children caae98448674
files src/junotu/Card.java src/junotu/Database.java src/junotu/TabCalendarBoard.java
diffstat 3 files changed, 73 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/junotu/Card.java	Mon Jan 30 05:53:41 2023 +0100
+++ b/src/junotu/Card.java	Mon Feb 06 23:58:57 2023 +0100
@@ -24,6 +24,8 @@
     public static final String TAG_BOARD_COLUMN_CARD  = TAG_CORE_PREFIX+"board_column_card";
 
     public static final String TAG_CALENDAR_BOARD                    = TAG_CORE_PREFIX+"calendar_board";
+    public static final String TAG_CALENDAR_BOARD_COLUMN             = TAG_CORE_PREFIX+"calendar_board_column";
+    public static final String TAG_CALENDAR_BOARD_COLUMN_CARDS       = TAG_CORE_PREFIX+"calendar_board_column_cards";
     public static final String TAG_CALENDAR_BOARD_OPTION_ONLY_FILLED = TAG_CORE_PREFIX+"calendar_board_hide_empty_days";
 
     public static final String VALUE_BOARD_COLUMN_CARD_ONLY = "only";
--- a/src/junotu/Database.java	Mon Jan 30 05:53:41 2023 +0100
+++ b/src/junotu/Database.java	Mon Feb 06 23:58:57 2023 +0100
@@ -437,4 +437,37 @@
 	
     }
 
+    public Card[] searchCustom( Query query, int limit, boolean useIgnores )
+    {
+
+	if( useIgnores ) {
+	    BooleanQuery withIgnores = new BooleanQuery();
+
+	    withIgnores.add( query, BooleanClause.Occur.SHOULD );
+	    for( int i = 0; i < hideQueries.length; i++ ) {
+		withIgnores.add( hideQueries[i], BooleanClause.Occur.MUST_NOT );
+	    }
+
+	    query = withIgnores;
+	    
+	}
+	
+	try {
+	    
+	    TopDocs hits = luceneSearcher.search( query, limit );
+	    Card[] cards = new Card[hits.scoreDocs.length];
+	    
+	    for( int i = 0; i < hits.scoreDocs.length; i++ ) {
+		Document document = luceneSearcher.doc( hits.scoreDocs[i].doc );
+		cards[i] = cardFromDocument( document );
+	    }
+	    
+	    return cards;
+	    
+	} catch( IOException e ) {
+	    throw new RuntimeException(e);
+	}
+	
+    }
+
 }
--- a/src/junotu/TabCalendarBoard.java	Mon Jan 30 05:53:41 2023 +0100
+++ b/src/junotu/TabCalendarBoard.java	Mon Feb 06 23:58:57 2023 +0100
@@ -7,6 +7,10 @@
 import java.util.Calendar;
 import java.text.DateFormat;
 
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.WildcardQuery;
+import org.apache.lucene.index.Term;
+
 import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.GridBagConstraints;
@@ -52,9 +56,10 @@
 
 import junotu.Main;
 import junotu.Window.Tab;
+import junotu.Window.TabInterface;
 import junotu.Card;
 
-public class TabCalendarBoard extends JPanel implements ActionListener, MouseListener, ChangeListener {
+public class TabCalendarBoard extends JPanel implements TabInterface, ActionListener, MouseListener, ChangeListener {
 
     final static int COLUMN_CONTENT_WIDTH = 256;
     final static int COLUMN_WIDTH = COLUMN_CONTENT_WIDTH+16;
@@ -304,8 +309,8 @@
 	    }
 
 	    card.titleSet( titleGet() );
-	    card.tagValueSetOnly( Card.TAG_BOARD_COLUMN_CARDS, cardIdentifiers );
-	    card.tagValueSetOnly( Card.TAG_BOARD_COLUMN, null );
+	    card.tagValueSetOnly( Card.TAG_CALENDAR_BOARD_COLUMN, null );
+	    card.tagValueSetOnly( Card.TAG_CALENDAR_BOARD_COLUMN_CARDS, cardIdentifiers );
 
 	    try {
 		if( newCard ) {
@@ -481,7 +486,7 @@
 	
     }
 
-    static long identifier = -1;
+    long identifier = -1;
     Box columns;
     JScrollPane scroll;
 
@@ -526,10 +531,27 @@
 
     public void boardEdit()
     {
-	// TODO: Find or create calendar board card.
-	if( identifier == -1 ) {
-	    
+	if( identifier != -1 ) {
+	    return;
 	}
+	
+	Card card;
+	
+	Query query = new WildcardQuery( new Term(Card.TAG_CALENDAR_BOARD, "*") );
+	Card cards[] = Main.database.searchCustom( query, 1, false );
+
+        if( cards.length == 0 ) {
+	    card = new Card();
+	    identifier = Main.database.cardAdd(card);
+	    boardSave();
+	} else if( cards.length == 1 ) {
+	    card = cards[0];	    
+	} else {
+	    throw new RuntimeException();
+	}
+	
+	optionOnlyFilledColumns = card.tagHas( Card.TAG_CALENDAR_BOARD_OPTION_ONLY_FILLED );
+	
     }
 
     public Card boardSave()
@@ -539,7 +561,7 @@
 	card = Main.database.cardGetByIdentifier(identifier);
 	
 	if( card == null ) {
-	    throw new RuntimeException();
+	    throw new RuntimeException(""+identifier);
 	}
 
 	card.titleSet( "JUnotu calendar board" );
@@ -552,6 +574,8 @@
 	    card.tagRemove( Card.TAG_CALENDAR_BOARD_OPTION_ONLY_FILLED );
 	}
 
+	// TODO: Save columns here.
+
 	Main.database.cardUpdate(card);
 	Main.refreshSearches();
 	
@@ -649,6 +673,11 @@
 	window.tabSwitch( Tab.SEARCH );
     }
 
+    public void onSwitchedTo()
+    {
+	boardEdit();
+    }
+
     public void actionPerformed( ActionEvent e )
     {
 	if( e.getSource() == back ) {
@@ -697,6 +726,7 @@
     {
 	Object source = e.getSource();
 	if( source == dateRangeBegin || source == dateRangeEnd ) {
+	    boardSave();
 	    populateColumns();
 	}
     }