All Downloads are FREE. Search and download functionalities are using the official Maven repository.

bibliothek.notes.view.actions.Delete Maven / Gradle / Ivy

package bibliothek.notes.view.actions;

import javax.swing.JOptionPane;

import bibliothek.extension.gui.dock.theme.eclipse.EclipseTabDockAction;
import bibliothek.gui.Dockable;
import bibliothek.gui.dock.action.actions.SimpleButtonAction;
import bibliothek.notes.model.Note;
import bibliothek.notes.model.NoteModel;

/**
 * An action that contains methods to remove a {@link Note} from
 * the {@link NoteModel}.
 * @author Benjamin Sigg
 *
 */
@EclipseTabDockAction
public abstract class Delete extends SimpleButtonAction{
    /** the model from which a Note might be removed */
	private NoteModel model;
	
	/**
	 * Creates a new action.
	 * @param model the model from which Notes will be
	 * removed.
	 */
	public Delete( NoteModel model ){
		this.model = model;
		
		setText( "Delete" );
	}
	
	/**
	 * Removes note from {@link #model}, but only after the
	 * user confirmed the action. This method will show a question-dialog
	 * above dockable.
	 * @param note the Note to delete
	 * @param dockable the owner of the dialog which will be shown
	 */
	public void delete( Note note, Dockable dockable ){
		int option = JOptionPane.showConfirmDialog( dockable.getComponent(), 
				"Delete \"" + note.getTitle()  + "\"?", "Delete", 
				JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE );
		
		if( option == JOptionPane.YES_OPTION )
			model.removeNote( note );
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy