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 javax.swing.AbstractAction;
027:import javax.swing.JOptionPane;
028:import org.skunk.assert.Assertion;
029:import org.skunk.dav.client.gui.Explorer;
030:import org.skunk.dav.client.gui.ExplorerMenuBar;
031:import org.skunk.dav.client.gui.ResourceManager;
032:import org.skunk.dav.client.gui.ServerData;
033:import org.skunk.dav.client.gui.StateMonitor;
034:import org.skunk.dav.client.gui.StateProperties;
035:import org.skunk.trace.Debug;
036:
037:public class DisconnectionAction extends AbstractAction
038:{
039: Explorer ex;
040: ServerData sd;
041:
042: public DisconnectionAction(Explorer ex, ServerData sd)
043: {
044: this .ex=ex;
045: this .sd=sd;
046: }
047:
048: public DisconnectionAction(Explorer ex)
049: {
050: this (ex, null);
051: }
052:
053: public void actionPerformed(ActionEvent ae)
054: {
055: if (sd!=null)
056: disconnect(sd);
057: else if (ex.getConnectedServerCount()==1)
058: {
059: Debug.trace(this , Debug.DP3,
060: "only one connected server, will disconnect");
061: ServerData[] allServers=ex.getConnectedServers();
062: Assertion.assert((allServers.length==1),
063: "length of array of connected servers is 1");
064: disconnect(allServers[0]);
065: }
066: else
067: {
068: Debug.trace(this , Debug.DP3, "finding selected connection");
069: ServerData selectedServer=ex.getSelectedConnection();
070: if (selectedServer!=null)
071: disconnect(selectedServer);
072: else
073: {
074: //it would be preferable to show a choice dialog here rather than an error message.
075: String message=ResourceManager.getMessage(ResourceManager.DISCONNECTION_ERROR_MESSAGE);
076: String title=ResourceManager.getMessage(ResourceManager.DISCONNECTION_ERROR_TITLE);
077: JOptionPane.showMessageDialog(ex, message, title, JOptionPane.ERROR_MESSAGE);
078: }
079: }
080: }
081:
082: private void disconnect(ServerData sd)
083: {
084: ex.removeConnectionNode(sd);
085: if (ex.getConnectedServerCount()==0)
086: {
087: //ExplorerMenuBar.getMenuBar(ex).setConnected(false);
088: StateMonitor.setProperty(StateProperties.CONNECTED,
089: new Boolean(false),
090: ex);
091: }
092: }
093:}
094:
095:/* $Log: DisconnectionAction.java,v $
096:/* Revision 1.8 2000/12/19 22:36:05 smulloni
097:/* adjustments to preamble.
098:/*
099:/* Revision 1.7 2000/12/03 23:53:26 smulloni
100:/* added license and copyright preamble to java files.
101:/*
102:/* Revision 1.6 2000/11/18 04:36:05 smullyan
103:/* work on StateMonitor and related functionality.
104:/*
105:/* Revision 1.5 2000/11/10 22:40:09 smullyan
106:/* added icon to table for resource type; fixes to copy and move; disabling of
107:/* menu items that are inappropriate.
108:/*
109:/* Revision 1.4 2000/11/09 23:35:02 smullyan
110:/* log added to every Java file, with the help of python. Lock stealing
111:/* implemented, and treatment of locks made more robust.
112:/* */
|