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.Component;
026: import java.awt.event.ActionEvent;
027: import java.util.Vector;
028: import javax.swing.AbstractAction;
029: import org.skunk.dav.client.gui.ConnectionDialog;
030: import org.skunk.dav.client.gui.Explorer;
031: import org.skunk.dav.client.gui.ExplorerMenuBar;
032: import org.skunk.dav.client.gui.ResourceManager;
033: import org.skunk.dav.client.gui.ServerData;
034: import org.skunk.dav.client.gui.StateMonitor;
035: import org.skunk.dav.client.gui.StateProperties;
036:
037: public class ConnectionAction extends AbstractAction {
038: public static final String CONNECTION_MESSAGE = ResourceManager
039: .getMessage(ResourceManager.CONNECTION_PROMPT, 50);
040: public static final String CONNECTION_TITLE = ResourceManager
041: .getMessage(ResourceManager.CONNECT_KEY);
042: public static final String NEW_CONNECTION_OPTION = ResourceManager
043: .getMessage(ResourceManager.ADD_NEW_CONNECTION_LABEL);
044: public static final String REMOVE_CONNECTION_OPTION = ResourceManager
045: .getMessage(ResourceManager.REMOVE_CONNECTION_LABEL);
046: public static final String CHOOSE_COMMAND = "choose";
047: public static final String CONNECT_COMMAND = "connect";
048: private Explorer ex = null;
049: private ServerData sd = null;
050:
051: public ConnectionAction() {
052: super ();
053: }
054:
055: public ConnectionAction(Explorer ex) {
056: super ();
057: this .ex = ex;
058: }
059:
060: public ConnectionAction(Explorer ex, ServerData sd) {
061: super ();
062: this .ex = ex;
063: this .sd = sd;
064: }
065:
066: protected static Object[] getServerArray() {
067: Vector v = (Vector) ServerData.getServers().clone();
068: v.addElement(NEW_CONNECTION_OPTION);
069: v.addElement(REMOVE_CONNECTION_OPTION);
070: return v.toArray();
071: }
072:
073: public void actionPerformed(ActionEvent ae) {
074: String actionCommand = (ae == null) ? CONNECT_COMMAND : ae
075: .getActionCommand();
076:
077: if (CHOOSE_COMMAND.equals(actionCommand)) {
078: Explorer localExplorer = (ex == null) ? Explorer
079: .guessActiveExplorer() : ex;
080: ConnectionDialog conDialog = new ConnectionDialog(
081: localExplorer);
082: if (conDialog.show()) {
083: ServerData localServerData = conDialog.getServerData();
084: if (localServerData != null)
085: localExplorer.addConnectionNode(localServerData,
086: new ConnectionRunner(localExplorer));
087: }
088: } else if (CONNECT_COMMAND.equals(actionCommand)) {
089: if (ex != null && sd != null) {
090: ex.addConnectionNode(sd, new ConnectionRunner(ex));
091: }
092: }
093: }
094:
095: private static class ConnectionRunner implements Runnable {
096: private Explorer ex;
097:
098: ConnectionRunner(Explorer ex) {
099: this .ex = ex;
100: }
101:
102: public void run() {
103: StateMonitor.setProperty(StateProperties.CONNECTED,
104: new Boolean(true), this .ex);
105: }
106: }
107: }
108:
109: /* $Log: ConnectionAction.java,v $
110: /* Revision 1.13 2001/06/05 01:09:53 smulloni
111: /* fixed bug wtih failed connection attempts, which used to set the
112: /* connection flag as if the connection had succeeded.
113: /*
114: /* Revision 1.12 2001/05/30 03:49:35 smulloni
115: /* Some bug fixes and improvements to authentication handling. Users are now
116: /* prompted for a password the first time they connect to a given server
117: /* in a session; if the password is rejected, they are asked again.
118: /* Users also now have the option of whether a given password will be remembered
119: /* or not.
120: /*
121: /* Revision 1.11 2001/01/05 08:01:12 smulloni
122: /* changes to the connection gui for the Explorer; added depth configurability to
123: /* propfind in the jpython test script; added an experimental "allprop" system
124: /* property which affects the propfind query type
125: /*
126: /* Revision 1.10 2000/12/19 22:36:05 smulloni
127: /* adjustments to preamble.
128: /*
129: /* Revision 1.9 2000/12/04 23:51:16 smulloni
130: /* added ImageViewer; fixed word in SimpleTextEditor
131: /*
132: /* Revision 1.8 2000/12/03 23:53:26 smulloni
133: /* added license and copyright preamble to java files.
134: /*
135: /* Revision 1.7 2000/11/18 04:36:05 smullyan
136: /* work on StateMonitor and related functionality.
137: /*
138: /* Revision 1.6 2000/11/10 22:40:09 smullyan
139: /* added icon to table for resource type; fixes to copy and move; disabling of
140: /* menu items that are inappropriate.
141: /*
142: /* Revision 1.5 2000/11/09 23:35:01 smullyan
143: /* log added to every Java file, with the help of python. Lock stealing
144: /* implemented, and treatment of locks made more robust.
145: /* */
|