fix: Corrects dialog message for deleting games in current view. Adds progress dialog when deleting
This commit is contained in:
parent
ffcb509d9e
commit
f91a7179ed
|
@ -0,0 +1,71 @@
|
|||
package se.lantz.gui;
|
||||
|
||||
import java.awt.Frame;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.WindowConstants;
|
||||
|
||||
import java.awt.GridBagConstraints;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.Insets;
|
||||
|
||||
public class DeleteProgressDialog extends JDialog
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JProgressBar progressBar;
|
||||
private JLabel textLabel;
|
||||
|
||||
public DeleteProgressDialog(Frame frame)
|
||||
{
|
||||
super(frame, "Deleting", true);
|
||||
setAlwaysOnTop(true);
|
||||
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||
setResizable(false);
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
getContentPane().setLayout(gridBagLayout);
|
||||
GridBagConstraints gbc_progressBar = new GridBagConstraints();
|
||||
gbc_progressBar.weightx = 1.0;
|
||||
gbc_progressBar.anchor = GridBagConstraints.NORTH;
|
||||
gbc_progressBar.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_progressBar.insets = new Insets(5, 5, 5, 5);
|
||||
gbc_progressBar.gridx = 0;
|
||||
gbc_progressBar.gridy = 0;
|
||||
getContentPane().add(getProgressBar(), gbc_progressBar);
|
||||
GridBagConstraints gbc_textLabel = new GridBagConstraints();
|
||||
gbc_textLabel.insets = new Insets(5, 5, 5, 5);
|
||||
gbc_textLabel.anchor = GridBagConstraints.NORTH;
|
||||
gbc_textLabel.weightx = 1.0;
|
||||
gbc_textLabel.weighty = 1.0;
|
||||
gbc_textLabel.gridx = 0;
|
||||
gbc_textLabel.gridy = 1;
|
||||
getContentPane().add(getTextLabel(), gbc_textLabel);
|
||||
}
|
||||
|
||||
public void finish()
|
||||
{
|
||||
progressBar.setIndeterminate(false);
|
||||
getProgressBar().setValue(getProgressBar().getMaximum());
|
||||
dispose();
|
||||
}
|
||||
|
||||
private JProgressBar getProgressBar()
|
||||
{
|
||||
if (progressBar == null)
|
||||
{
|
||||
progressBar = new JProgressBar();
|
||||
progressBar.setIndeterminate(true);
|
||||
}
|
||||
return progressBar;
|
||||
}
|
||||
|
||||
private JLabel getTextLabel()
|
||||
{
|
||||
if (textLabel == null)
|
||||
{
|
||||
textLabel = new JLabel("Deleting games, screens and cover files...");
|
||||
}
|
||||
return textLabel;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package se.lantz.gui;
|
||||
|
||||
import javax.swing.SwingWorker;
|
||||
|
||||
import se.lantz.model.MainViewModel;
|
||||
import se.lantz.util.ExceptionHandler;
|
||||
import se.lantz.util.FileManager;
|
||||
|
||||
public class DeleteWorker extends SwingWorker<Void, String>
|
||||
{
|
||||
private DeleteProgressDialog dialog;
|
||||
private boolean deleteAll;
|
||||
private MainViewModel model;
|
||||
|
||||
public DeleteWorker(DeleteProgressDialog dialog, boolean deleteAll, MainViewModel model)
|
||||
{
|
||||
this.deleteAll = deleteAll;
|
||||
this.dialog = dialog;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground() throws Exception
|
||||
{
|
||||
if (deleteAll)
|
||||
{
|
||||
model.deleteAllGames();
|
||||
FileManager.deleteAllFolderContent();
|
||||
}
|
||||
else
|
||||
{
|
||||
model.deleteAllGamesInCurrentView();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done()
|
||||
{
|
||||
try
|
||||
{
|
||||
get();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExceptionHandler.handleException(e, "Error when deleting");
|
||||
}
|
||||
dialog.finish();
|
||||
if (deleteAll)
|
||||
{
|
||||
//Trigger a reload of game views
|
||||
model.reloadGameViews();
|
||||
MainWindow.getInstance().selectViewAfterRestore();
|
||||
}
|
||||
MainWindow.getInstance().getMainPanel().repaintAfterModifications();
|
||||
}
|
||||
}
|
|
@ -483,12 +483,7 @@ public class MenuManager
|
|||
{
|
||||
backupDb();
|
||||
}
|
||||
MainWindow.getInstance().getMainPanel().clearGameListSelection();
|
||||
uiModel.deleteAllGames();
|
||||
FileManager.deleteAllFolderContent();
|
||||
//Trigger a reload of game views
|
||||
uiModel.reloadGameViews();
|
||||
MainWindow.getInstance().selectViewAfterRestore();
|
||||
startDeleteProgress(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -500,7 +495,7 @@ public class MenuManager
|
|||
}
|
||||
else
|
||||
{
|
||||
DeleteDialog dialog = new DeleteDialog(true);
|
||||
DeleteDialog dialog = new DeleteDialog(false);
|
||||
dialog.pack();
|
||||
dialog.setLocationRelativeTo(MainWindow.getInstance());
|
||||
if (dialog.showDialog())
|
||||
|
@ -509,12 +504,21 @@ public class MenuManager
|
|||
{
|
||||
backupDb();
|
||||
}
|
||||
MainWindow.getInstance().getMainPanel().clearGameListSelection();
|
||||
uiModel.deleteAllGamesInCurrentView();
|
||||
MainWindow.getInstance().getMainPanel().repaintAfterModifications();
|
||||
startDeleteProgress(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void startDeleteProgress(boolean deleteAll)
|
||||
{
|
||||
MainWindow.getInstance().getMainPanel().clearGameListSelection();
|
||||
DeleteProgressDialog delDialog = new DeleteProgressDialog(MainWindow.getInstance());
|
||||
delDialog.pack();
|
||||
delDialog.setLocationRelativeTo(MainWindow.getInstance());
|
||||
DeleteWorker worker = new DeleteWorker(delDialog, deleteAll, uiModel);
|
||||
worker.execute();
|
||||
delDialog.setVisible(true);
|
||||
}
|
||||
|
||||
private void convertScreens()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue