| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
package org.homeunix.thecave.buddi.view.menu.items; |
| 5 | |
|
| 6 | |
import java.awt.event.ActionEvent; |
| 7 | |
import java.util.logging.Level; |
| 8 | |
import java.util.logging.Logger; |
| 9 | |
|
| 10 | |
import javax.swing.JOptionPane; |
| 11 | |
|
| 12 | |
import org.homeunix.thecave.buddi.i18n.BuddiKeys; |
| 13 | |
import org.homeunix.thecave.buddi.i18n.keys.ButtonKeys; |
| 14 | |
import org.homeunix.thecave.buddi.i18n.keys.MenuKeys; |
| 15 | |
import org.homeunix.thecave.buddi.model.Document; |
| 16 | |
import org.homeunix.thecave.buddi.model.impl.ModelFactory; |
| 17 | |
import org.homeunix.thecave.buddi.model.prefs.PrefsModel; |
| 18 | |
import org.homeunix.thecave.buddi.plugin.api.util.TextFormatter; |
| 19 | |
import org.homeunix.thecave.buddi.util.OperationCancelledException; |
| 20 | |
import org.homeunix.thecave.buddi.view.MainFrame; |
| 21 | |
|
| 22 | |
import ca.digitalcave.moss.application.document.exception.DocumentLoadException; |
| 23 | |
import ca.digitalcave.moss.swing.MossDocumentFrame; |
| 24 | |
import ca.digitalcave.moss.swing.MossFrame; |
| 25 | |
import ca.digitalcave.moss.swing.MossMenuItem; |
| 26 | |
import ca.digitalcave.moss.swing.exception.WindowOpenException; |
| 27 | |
|
| 28 | |
public class FileRevertToSaved extends MossMenuItem { |
| 29 | |
public static final long serialVersionUID = 0; |
| 30 | |
|
| 31 | |
public FileRevertToSaved(MossFrame frame) { |
| 32 | 5975 | super(frame, PrefsModel.getInstance().getTranslator().get(MenuKeys.MENU_FILE_REVERT_TO_SAVED)); |
| 33 | 5975 | } |
| 34 | |
|
| 35 | |
@Override |
| 36 | |
public void actionPerformed(ActionEvent e) { |
| 37 | 0 | String[] options = new String[2]; |
| 38 | 0 | options[0] = TextFormatter.getTranslation(ButtonKeys.BUTTON_YES); |
| 39 | 0 | options[1] = TextFormatter.getTranslation(ButtonKeys.BUTTON_NO); |
| 40 | |
|
| 41 | 0 | if (JOptionPane.showOptionDialog( |
| 42 | |
null, |
| 43 | |
TextFormatter.getTranslation(BuddiKeys.MESSAGE_REVERT_TO_SAVED), |
| 44 | |
TextFormatter.getTranslation(BuddiKeys.MESSAGE_REVERT_TO_SAVED_TITLE), |
| 45 | |
JOptionPane.YES_NO_OPTION, |
| 46 | |
JOptionPane.WARNING_MESSAGE, |
| 47 | |
null, |
| 48 | |
options, |
| 49 | |
options[0] |
| 50 | |
) == 0) { |
| 51 | |
try { |
| 52 | 0 | ModelFactory.getAutoSaveLocation(((MossDocumentFrame) getFrame()).getDocument().getFile()).delete(); |
| 53 | 0 | Document newDoc = ModelFactory.createDocument(((MossDocumentFrame) getFrame()).getDocument().getFile()); |
| 54 | |
|
| 55 | 0 | MainFrame mainWndow = new MainFrame(newDoc); |
| 56 | 0 | mainWndow.openWindow( |
| 57 | |
PrefsModel.getInstance().getWindowSize(((MainFrame) getFrame()).getDocument().getFile() + ""), |
| 58 | |
PrefsModel.getInstance().getWindowLocation(((MainFrame) getFrame()).getDocument().getFile() + ""), |
| 59 | |
true); |
| 60 | |
} |
| 61 | 0 | catch (OperationCancelledException oce){} |
| 62 | 0 | catch (WindowOpenException woe){} |
| 63 | 0 | catch (DocumentLoadException dle){ |
| 64 | 0 | Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "There was an error loading the file " + ((MossDocumentFrame) getFrame()).getDocument().getFile(), dle); |
| 65 | 0 | } |
| 66 | |
} |
| 67 | |
else { |
| 68 | 0 | Logger.getLogger(this.getClass().getName()).info("User cancelled file restore."); |
| 69 | |
} |
| 70 | 0 | } |
| 71 | |
|
| 72 | |
@Override |
| 73 | |
public void updateMenus() { |
| 74 | 42468 | super.updateMenus(); |
| 75 | |
|
| 76 | 42468 | this.setEnabled(getFrame() instanceof MossDocumentFrame |
| 77 | |
&& ((MossDocumentFrame) getFrame()).getDocument().getFile() != null && ((MossDocumentFrame) getFrame()).getDocument().isChanged()); |
| 78 | 42468 | } |
| 79 | |
} |