001: /*
002: * Copyright (c) 2000, Jacob Smullyan.
003: *
004: * This is part of SkunkDAV, a WebDAV client. See http://skunkdav.sourceforge.net/
005: * for the latest version.
006: *
007: * SkunkDAV is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License as published
009: * by the Free Software Foundation; either version 2, or (at your option)
010: * any later version.
011: *
012: * SkunkDAV is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with SkunkDAV; see the file COPYING. If not, write to the Free
019: * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
020: * 02111-1307, USA.
021: */
022:
023: package org.skunk.dav.client.gui.action;
024:
025: import java.awt.event.ActionEvent;
026: import java.util.ArrayList;
027: import java.util.Iterator;
028: import javax.swing.AbstractAction;
029: import javax.swing.JOptionPane;
030: import org.skunk.dav.client.gui.AppContext;
031: import org.skunk.dav.client.gui.Buffer;
032: import org.skunk.dav.client.gui.Explorer;
033: import org.skunk.dav.client.gui.ExplorerApp;
034: import org.skunk.dav.client.gui.ResourceManager;
035: import org.skunk.dav.client.gui.View;
036: import org.skunk.dav.client.gui.editor.DAVEditor;
037:
038: public class ExitAction extends AbstractAction {
039: public void actionPerformed(ActionEvent ae) {
040: //if there are open, unsaved buffers, prompt user.
041: //if user does not cancel, close and unlock all buffers.
042: //I am not performing any saves here.
043: ArrayList cleanBuffers = new ArrayList();
044: ArrayList dirtyBuffers = new ArrayList();
045: int numViews = ExplorerApp.getAppContext().getViewCount();
046:
047: for (int i = 0; i < numViews; i++) {
048: View v = ExplorerApp.getAppContext().getView(i);
049: for (Iterator it = v.getDockedBuffers(); it.hasNext();) {
050: Buffer b = (Buffer) it.next();
051: if (b instanceof Explorer)
052: continue;
053: if (b instanceof DAVEditor && ((DAVEditor) b).isDirty()) {
054: dirtyBuffers.add(b);
055: } else
056: cleanBuffers.add(b);
057: }
058: }
059: if (dirtyBuffers.size() > 0) {
060: String title = ResourceManager
061: .getMessage(ResourceManager.DIRTY_BUFFER_ON_EXIT_TITLE);
062: String message = ResourceManager
063: .getMessage(ResourceManager.DIRTY_BUFFER_ON_EXIT_MESSAGE);
064: int option = JOptionPane.showConfirmDialog(ExplorerApp
065: .getAppContext().getCurrentView().getComponent(),
066: message, title, JOptionPane.OK_CANCEL_OPTION,
067: JOptionPane.WARNING_MESSAGE);
068: if (option == JOptionPane.CANCEL_OPTION)
069: return;
070: }
071: //CloseBufferAction does not require an ActionEvent.
072: for (Iterator it = dirtyBuffers.iterator(); it.hasNext();) {
073: new CloseBufferAction((Buffer) it.next(), true)
074: .actionPerformed(null);
075: }
076: for (Iterator it = cleanBuffers.iterator(); it.hasNext();) {
077: new CloseBufferAction((Buffer) it.next(), true)
078: .actionPerformed(null);
079: }
080: System.exit(0);
081: }
082: }
083:
084: /* $Log: ExitAction.java,v $
085: /* Revision 1.6 2001/01/02 20:43:03 smulloni
086: /* stopped trying to undock the Explorer component in ExitAction, which is a no-no.
087: /*
088: /* Revision 1.5 2000/12/19 22:36:05 smulloni
089: /* adjustments to preamble.
090: /*
091: /* Revision 1.4 2000/12/19 19:22:22 smulloni
092: /* some tweaks: ExitAction now cleans up the app's buffers. The app now does
093: /* not resize every time a buffer is added or removed.
094: /*
095: /* Revision 1.3 2000/12/03 23:53:26 smulloni
096: /* added license and copyright preamble to java files.
097: /*
098: /* Revision 1.2 2000/11/09 23:35:02 smullyan
099: /* log added to every Java file, with the help of python. Lock stealing
100: /* implemented, and treatment of locks made more robust.
101: /* */
|