changeset 62:e28cb683c561

TabBoard: Improved card removal Now cards' card representations are removed when cards are individually removed from columns.
author Fox
date Fri, 23 Dec 2022 18:15:24 +0100
parents 07a05c60abef
children 1304d3d5b4a4
files src/junotu/TabBoard.java
diffstat 1 files changed, 31 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
diff -r 07a05c60abef -r e28cb683c561 src/junotu/TabBoard.java
--- a/src/junotu/TabBoard.java	Fri Dec 23 17:57:33 2022 +0100
+++ b/src/junotu/TabBoard.java	Fri Dec 23 18:15:24 2022 +0100
@@ -364,30 +364,7 @@
 	    Component[] cardList = cards.getComponents();
 	    for( int i = 0; i < cardList.length; i++ ) {
 		ColumnCardWidget cardWidget = (ColumnCardWidget)cardList[i];
-	        if( cardWidget.newCard ) {
-		    continue;
-		}
-
-		Card card;
-		
-		try {
-		    card = Main.database.cardGetByIdentifier(cardWidget.identifier);
-		} catch( Exception e ) {
-		    throw new RuntimeException(e);
-		}
-
-		if( card == null ) {
-		    throw new RuntimeException();
-		}
-
-		if( card.<String>tagGetAsOr( Card.TAG_BOARD_COLUMN_CARD, "" ).equals(Card.VALUE_BOARD_COLUMN_CARD_ONLY) ) {
-		    System.out.print("Deleting card with identifier "+Long.toString(card.identifierGet())+" because it was only present in column identifier "+Long.toString(identifier)+" ('"+titleGet()+"') which is being deleted.\n");
-		    try {
-			Main.database.cardDelete(card.identifierGet());
-		    } catch( Exception e ) {
-			throw new RuntimeException(e);
-		    }
-		}
+		cardWidget.delete();
 	    }
 	    if( !newCard ) {
 		try {
@@ -446,7 +423,9 @@
 		}
 	    } else if( source instanceof ColumnCardWidget ) {
 		if( e.getButton() == MouseEvent.BUTTON2 ) {
-		    cards.remove( (ColumnCardWidget)e.getSource() );
+		    ColumnCardWidget cardWidget = (ColumnCardWidget)e.getSource();
+		    cardWidget.delete();
+		    cards.remove(cardWidget);
 		    cards.revalidate();
 		}
 	    }
@@ -534,6 +513,33 @@
 	    }
 	}
 
+	public void delete()
+	{
+	    if( newCard ) {
+		return;
+	    }
+
+	    Card card;
+	    
+	    try {
+		card = Main.database.cardGetByIdentifier(identifier);
+	    } catch( Exception e ) {
+		throw new RuntimeException(e);
+	    }
+	    
+	    if( card == null ) {
+		throw new RuntimeException();
+	    }
+
+	    if( card.<String>tagGetAsOr( Card.TAG_BOARD_COLUMN_CARD, "" ).equals(Card.VALUE_BOARD_COLUMN_CARD_ONLY) ) {
+		try {
+		    Main.database.cardDelete(card.identifierGet());
+		} catch( Exception e ) {
+		    throw new RuntimeException(e);
+		}
+	    }
+	}
+
 	public boolean isSelected()
 	{
 	    return title.isFocusOwner();