Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 102654 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/team/internal/ccvs/core/CVSProviderPlugin.java (-2 / +107 lines)
Lines 11-18 Link Here
11
package org.eclipse.team.internal.ccvs.core;
11
package org.eclipse.team.internal.ccvs.core;
12
 
12
 
13
import java.io.*;
13
import java.io.*;
14
import java.util.ArrayList;
14
import java.net.MalformedURLException;
15
import java.util.List;
15
import java.net.URL;
16
import java.util.*;
16
17
17
import org.eclipse.core.resources.*;
18
import org.eclipse.core.resources.*;
18
import org.eclipse.core.runtime.*;
19
import org.eclipse.core.runtime.*;
Lines 105-111 Link Here
105
	private boolean crash;
106
	private boolean crash;
106
107
107
    private boolean autoShareOnImport;
108
    private boolean autoShareOnImport;
109
    private boolean useProxy;
108
110
111
    public static final String PROXY_TYPE_HTTP = "HTTP"; //$NON-NLS-1$
112
    public static final String PROXY_TYPE_SOCKS5 = "SOCKS5"; //$NON-NLS-1$
113
    public static final String HTTP_DEFAULT_PORT = "80"; //$NON-NLS-1$
114
    public static final String SOCKS5_DEFAULT_PORT = "1080"; //$NON-NLS-1$
115
    
116
    private String proxyType;
117
    private String proxyHost;
118
    private String proxyPort;
119
    private boolean useProxyAuth;
120
121
    private static final String INFO_PROXY_USER = "org.eclipse.team.cvs.core.proxy.user"; //$NON-NLS-1$ 
122
    private static final String INFO_PROXY_PASS = "org.eclipse.team.cvs.core.proxy.pass"; //$NON-NLS-1$ 
123
124
    private static final URL FAKE_URL;
125
    static {
126
        URL temp = null;
127
        try {
128
            temp = new URL("http://org.eclipse.team.cvs.proxy.auth");//$NON-NLS-1$ 
129
        } catch (MalformedURLException e) {
130
            // Should never fail
131
        }
132
        FAKE_URL = temp;
133
    }
134
    
135
    
109
	public synchronized CVSWorkspaceSubscriber getCVSWorkspaceSubscriber() {
136
	public synchronized CVSWorkspaceSubscriber getCVSWorkspaceSubscriber() {
110
		if (cvsWorkspaceSubscriber == null) {
137
		if (cvsWorkspaceSubscriber == null) {
111
			cvsWorkspaceSubscriber = new CVSWorkspaceSubscriber(
138
			cvsWorkspaceSubscriber = new CVSWorkspaceSubscriber(
Lines 598-601 Link Here
598
	public boolean isWatchOnEdit() {
625
	public boolean isWatchOnEdit() {
599
		return getPluginPreferences().getBoolean(CVSProviderPlugin.ENABLE_WATCH_ON_EDIT);
626
		return getPluginPreferences().getBoolean(CVSProviderPlugin.ENABLE_WATCH_ON_EDIT);
600
	}
627
	}
628
    
629
    // proxy configuration
630
    
631
    public void setUseProxy(boolean useProxy) {
632
      this.useProxy = useProxy;
633
    }
634
635
    public boolean isUseProxy() {
636
        return this.useProxy;
637
    }
638
639
    public void setProxyType(String proxyType) {
640
        this.proxyType = proxyType;
641
    }
642
    
643
    public String getProxyType() {
644
        return this.proxyType;
645
    }
646
647
    public void setProxyHost(String proxyHost) {
648
        this.proxyHost = proxyHost;
649
    }
650
    
651
    public String getProxyHost() {
652
        return this.proxyHost;
653
    }
654
655
    public void setProxyPort(String proxyPort) {
656
        this.proxyPort = proxyPort;
657
    }
658
    
659
    public String getProxyPort() {
660
        return this.proxyPort;
661
    }
662
663
    public void setUseProxyAuth(boolean useProxyAuth) {
664
        this.useProxyAuth = useProxyAuth;
665
    }
666
667
    public boolean isUseProxyAuth() {
668
        return this.useProxyAuth;
669
    }
670
    
671
    public String getProxyUser() {
672
        Object user = getAuthInfo().get(INFO_PROXY_USER);
673
        return user==null ? "" : (String) user; //$NON-NLS-1$
674
    }
675
    
676
    public String getProxyPassword() {
677
        Object pass = getAuthInfo().get(INFO_PROXY_PASS);
678
        return pass==null ? "" : (String) pass; //$NON-NLS-1$
679
    }
680
    
681
    private Map getAuthInfo() {
682
      // Retrieve username and password from keyring.
683
      Map authInfo = Platform.getAuthorizationInfo(FAKE_URL, "proxy", ""); //$NON-NLS-1$ //$NON-NLS-2$
684
      return authInfo!=null ? authInfo : Collections.EMPTY_MAP;
685
    }
686
687
    public void setProxyAuth(String proxyUser, String proxyPass) {
688
        Map authInfo = getAuthInfo();
689
        if (authInfo.size()==0) {
690
            authInfo = new java.util.HashMap(4);
691
        }
692
        if (proxyUser != null) {
693
            authInfo.put(INFO_PROXY_USER, proxyUser);
694
        }
695
        if (proxyPass != null) {
696
            authInfo.put(INFO_PROXY_PASS, proxyPass);
697
        }
698
        try {
699
            Platform.addAuthorizationInfo(FAKE_URL, "proxy", "", authInfo);  //$NON-NLS-1$ //$NON-NLS-2$
700
        } catch (CoreException e) {
701
            // We should probably wrap the CoreException here!
702
            CVSProviderPlugin.log(e);
703
        }
704
    }
705
    
601
}
706
}
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 19-23 Link Here
19
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.1.0,4.0.0)",
19
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.1.0,4.0.0)",
20
 org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
20
 org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
21
 org.eclipse.team.core;bundle-version="[3.2.0,4.0.0)",
21
 org.eclipse.team.core;bundle-version="[3.2.0,4.0.0)",
22
 org.eclipse.core.filesystem;bundle-version="[1.0.0,2.0.0)"
22
 org.eclipse.core.filesystem;bundle-version="[1.0.0,2.0.0)",
23
 com.jcraft.jsch;bundle-version="[0.1.25,2.0.0)"
23
Eclipse-LazyStart: true
24
Eclipse-LazyStart: true
(-)src/org/eclipse/team/internal/ccvs/core/connection/PServerConnection.java (-14 / +118 lines)
Lines 9-25 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.team.internal.ccvs.core.connection;
11
package org.eclipse.team.internal.ccvs.core.connection;
12
13
 
12
 
14
import java.io.*;
13
import java.io.*;
15
import java.net.Socket;
14
import java.net.*;
16
15
17
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.*;
18
import org.eclipse.osgi.util.NLS;
17
import org.eclipse.osgi.util.NLS;
19
import org.eclipse.team.internal.ccvs.core.*;
18
import org.eclipse.team.internal.ccvs.core.*;
19
import org.eclipse.team.internal.ccvs.core.connection.CVSAuthenticationException;
20
import org.eclipse.team.internal.ccvs.core.connection.Connection;
20
import org.eclipse.team.internal.ccvs.core.util.Util;
21
import org.eclipse.team.internal.ccvs.core.util.Util;
21
import org.eclipse.team.internal.core.streams.*;
22
import org.eclipse.team.internal.core.streams.*;
22
23
24
import com.jcraft.jsch.*;
25
import com.jcraft.jsch.Proxy;
26
23
/**
27
/**
24
 * A connection used to talk to an cvs pserver.
28
 * A connection used to talk to an cvs pserver.
25
 */
29
 */
Lines 97-109 Link Here
97
		monitor.subTask(CVSMessages.PServerConnection_authenticating);
101
		monitor.subTask(CVSMessages.PServerConnection_authenticating);
98
		monitor.worked(1);
102
		monitor.worked(1);
99
		
103
		
100
		fSocket = createSocket(monitor);
104
		InputStream is = null;
105
		OutputStream os = null;
106
        
107
        Proxy proxy = getProxy();
108
        if (proxy!=null) {
109
          String host = cvsroot.getHost();
110
          int port = cvsroot.getPort();
111
          if (port == ICVSRepositoryLocation.USE_DEFAULT_PORT) {
112
            port = DEFAULT_PORT;
113
          }
114
          try {
115
            int timeout = CVSProviderPlugin.getPlugin().getTimeout() * 1000;
116
            proxy.connect(new ResponsiveSocketFacory(monitor), host, port, timeout);
117
          } catch( Exception ex) {
118
            ex.printStackTrace();
119
            throw new IOException(ex.getMessage());
120
          }
121
          is = proxy.getInputStream();
122
          os = proxy.getOutputStream();
123
          
124
        } else {
125
          fSocket = createSocket(monitor);
126
          is = fSocket.getInputStream();
127
          os = fSocket.getOutputStream();
128
        }
129
        
101
		boolean connected = false;
130
		boolean connected = false;
102
		try {
131
		try {
103
			this.inputStream = new BufferedInputStream(new PollingInputStream(fSocket.getInputStream(),
132
			this.inputStream = new BufferedInputStream(new PollingInputStream(is,
104
				cvsroot.getTimeout(), monitor));
133
				cvsroot.getTimeout(), monitor));
105
			this.outputStream = new PollingOutputStream(new TimeoutOutputStream(
134
			this.outputStream = new PollingOutputStream(new TimeoutOutputStream(
106
				fSocket.getOutputStream(), 8192 /*bufferSize*/, 1000 /*writeTimeout*/, 1000 /*closeTimeout*/),
135
				os, 8192 /*bufferSize*/, 1000 /*writeTimeout*/, 1000 /*closeTimeout*/),
107
				cvsroot.getTimeout(), monitor);
136
				cvsroot.getTimeout(), monitor);
108
			authenticate();
137
			authenticate();
109
			connected = true;
138
			connected = true;
Lines 112-118 Link Here
112
		}
141
		}
113
	}
142
	}
114
143
115
	/**
144
	private Proxy getProxy() {
145
        CVSProviderPlugin plugin = CVSProviderPlugin.getPlugin();
146
        boolean useProxy = plugin.isUseProxy();
147
        Proxy proxy = null;
148
        if (useProxy) {
149
            String type = plugin.getProxyType();
150
            String host = plugin.getProxyHost();
151
            String port = plugin.getProxyPort();
152
153
            boolean useAuth = plugin.isUseProxyAuth();
154
155
            String proxyhost = host + ":" + port; //$NON-NLS-1$
156
            if (type.equals(CVSProviderPlugin.PROXY_TYPE_HTTP)) {
157
                proxy = new ProxyHTTP(proxyhost);
158
                if (useAuth) {
159
                    ((ProxyHTTP) proxy).setUserPasswd(plugin.getProxyUser(), plugin.getProxyPassword());
160
                }
161
            } else if (type.equals(CVSProviderPlugin.PROXY_TYPE_SOCKS5)) {
162
                proxy = new ProxySOCKS5(proxyhost);
163
                if (useAuth) {
164
                    ((ProxySOCKS5) proxy).setUserPasswd(plugin.getProxyUser(), plugin.getProxyPassword());
165
                }
166
            }
167
        }
168
        return proxy;
169
    }
170
171
    /**
116
	 * @see Connection#getInputStream()
172
	 * @see Connection#getInputStream()
117
	 */
173
	 */
118
	public InputStream getInputStream() {
174
	public InputStream getInputStream() {
Lines 169-181 Link Here
169
		// Accumulate a message from the error (E) stream
225
		// Accumulate a message from the error (E) stream
170
		String message = "";//$NON-NLS-1$
226
		String message = "";//$NON-NLS-1$
171
		String separator = ""; //$NON-NLS-1$
227
		String separator = ""; //$NON-NLS-1$
172
		while (line.length() > 0 && line.charAt(0) == ERROR_CHAR) {
228
173
		    if (line.length() > 2) {
229
        if(!CVSProviderPlugin.getPlugin().isUseProxy()) {
174
		        message += separator + line.substring(2);
230
          while (line.length() > 0 && line.charAt(0) == ERROR_CHAR) {
175
			    separator = " "; //$NON-NLS-1$
231
  		    if (line.length() > 2) {
176
		    }
232
  		        message += separator + line.substring(2);
177
		    line = Connection.readLine(cvsroot, getInputStream());
233
  			    separator = " "; //$NON-NLS-1$
178
		}
234
  		    }
235
  		    line = Connection.readLine(cvsroot, getInputStream());
236
          }
237
        } else {
238
            while (line.length() > 0) {
239
                message += separator + line;
240
                separator = "\n"; //$NON-NLS-1$
241
                line = Connection.readLine(cvsroot, getInputStream());
242
            }
243
        }
179
		
244
		
180
		// If the last line is the login failed (I HATE YOU) message, return authentication failure
245
		// If the last line is the login failed (I HATE YOU) message, return authentication failure
181
		if (LOGIN_FAILED.equals(line)) {
246
		if (LOGIN_FAILED.equals(line)) {
Lines 255-258 Link Here
255
	private void throwInValidCharacter() throws CVSAuthenticationException {
320
	private void throwInValidCharacter() throws CVSAuthenticationException {
256
		throw new CVSAuthenticationException(CVSMessages.PServerConnection_invalidChars, CVSAuthenticationException.RETRY);
321
		throw new CVSAuthenticationException(CVSMessages.PServerConnection_invalidChars, CVSAuthenticationException.RETRY);
257
	}
322
	}
323
    
324
    
325
    public static class SimpleSocketFactory implements SocketFactory {
326
        InputStream in = null;
327
        OutputStream out = null;
328
        public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
329
            Socket socket = null;
330
            socket = new Socket(host, port);
331
            return socket;
332
        }
333
        public InputStream getInputStream(Socket socket) throws IOException {
334
            if (in == null)
335
                in = socket.getInputStream();
336
            return in;
337
        }
338
        public OutputStream getOutputStream(Socket socket) throws IOException {
339
            if (out == null)
340
                out = socket.getOutputStream();
341
            return out;
342
        }
343
    }
344
    
345
    public static class ResponsiveSocketFacory extends SimpleSocketFactory {
346
        private IProgressMonitor monitor;
347
        public ResponsiveSocketFacory(IProgressMonitor monitor) {
348
            this.monitor = monitor;
349
        }
350
        public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
351
            Socket socket = null;
352
            socket = Util.createSocket(host, port, monitor);
353
            // Null out the monitor so we don't hold onto anything
354
            // (i.e. the SSH2 session will keep a handle to the socket factory around
355
            monitor = new NullProgressMonitor();
356
            // Set the socket timeout
357
            socket.setSoTimeout(CVSProviderPlugin.getPlugin().getTimeout() * 1000);
358
            return socket;
359
        }
360
    }
361
    
258
}
362
}
(-)src/org/eclipse/team/internal/ccvs/ui/IHelpContextIds.java (+2 lines)
Lines 105-110 Link Here
105
	public static final String WATCH_EDIT_PREFERENCE_PAGE = PREFIX + "watch_edit_preference_page_context"; //$NON-NLS-1$
105
	public static final String WATCH_EDIT_PREFERENCE_PAGE = PREFIX + "watch_edit_preference_page_context"; //$NON-NLS-1$
106
	public static final String PASSWORD_MANAGEMENT_PAGE = PREFIX + "password_management_preference_page_context"; //$NON-NLS-1$
106
	public static final String PASSWORD_MANAGEMENT_PAGE = PREFIX + "password_management_preference_page_context"; //$NON-NLS-1$
107
	public static final String COMPARE_PREFERENCE_PAGE = PREFIX + "cvs_compare_preference_page_context"; //$NON-NLS-1$
107
	public static final String COMPARE_PREFERENCE_PAGE = PREFIX + "cvs_compare_preference_page_context"; //$NON-NLS-1$
108
    public static final String PROXY_PREFERENCE_PAGE = PREFIX + "proxy_preference_page_context"; //$NON-NLS-1$
108
109
109
	// Views
110
	// Views
110
	public static final String CONSOLE_VIEW = PREFIX + "console_view_context"; //$NON-NLS-1$
111
	public static final String CONSOLE_VIEW = PREFIX + "console_view_context"; //$NON-NLS-1$
Lines 156-159 Link Here
156
	public static final String PROJECT_PROPERTY_PAGE = PREFIX + "project_property_page_context"; //$NON-NLS-1$
157
	public static final String PROJECT_PROPERTY_PAGE = PREFIX + "project_property_page_context"; //$NON-NLS-1$
157
	public static final String FOLDER_PROPERTY_PAGE = PREFIX + "folder_property_page_context"; //$NON-NLS-1$
158
	public static final String FOLDER_PROPERTY_PAGE = PREFIX + "folder_property_page_context"; //$NON-NLS-1$
158
	public static final String FILE_PROPERTY_PAGE = PREFIX + "file_property_page_context"; //$NON-NLS-1$
159
	public static final String FILE_PROPERTY_PAGE = PREFIX + "file_property_page_context"; //$NON-NLS-1$
160
159
}
161
}
(-)src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java (+9 lines)
Lines 1074-1078 Link Here
1074
	public static String CVSHistoryPage_Previous;
1074
	public static String CVSHistoryPage_Previous;
1075
	public static String CVSHistoryPage_NoRevisionsForMode;
1075
	public static String CVSHistoryPage_NoRevisionsForMode;
1076
	public static String CVSHistoryPage_NoFilter;
1076
	public static String CVSHistoryPage_NoFilter;
1077
  
1078
    public static String CVSProxyPreferencePage_enableProxy;
1079
    public static String CVSProxyPreferencePage_proxyTpe;
1080
    public static String CVSProxyPreferencePage_proxyHost;
1081
    public static String CVSProxyPreferencePage_proxyPort;
1082
    public static String CVSProxyPreferencePage_enableProxyAuth;
1083
    public static String CVSProxyPreferencePage_proxyUser;
1084
    public static String CVSProxyPreferencePage_proxyPass;
1085
    public static String CVSProxyPreferencePage_proxyPortError;
1077
1086
1078
}
1087
}
(-)src/org/eclipse/team/internal/ccvs/ui/ICVSUIConstants.java (+6 lines)
Lines 170-175 Link Here
170
	
170
	
171
	public final String PREF_ENABLE_MODEL_SYNC = "enableModelSync"; //$NON-NLS-1$
171
	public final String PREF_ENABLE_MODEL_SYNC = "enableModelSync"; //$NON-NLS-1$
172
	
172
	
173
    public final String PREF_USE_PROXY = "proxyEnabled"; //$NON-NLS-1$
174
    public final String PREF_PROXY_TYPE = "proxyType"; //$NON-NLS-1$
175
    public final String PREF_PROXY_HOST = "proxyHost"; //$NON-NLS-1$
176
    public final String PREF_PROXY_PORT = "proxyPort"; //$NON-NLS-1$
177
    public final String PREF_PROXY_AUTH = "proxyAuth"; //$NON-NLS-1$
178
    
173
	// Wizard banners
179
	// Wizard banners
174
	public final String IMG_WIZBAN_SHARE = "wizban/newconnect_wizban.png";	 //$NON-NLS-1$
180
	public final String IMG_WIZBAN_SHARE = "wizban/newconnect_wizban.png";	 //$NON-NLS-1$
175
	public final String IMG_WIZBAN_MERGE = "wizban/mergestream_wizban.png";	 //$NON-NLS-1$
181
	public final String IMG_WIZBAN_MERGE = "wizban/mergestream_wizban.png";	 //$NON-NLS-1$
(-)src/org/eclipse/team/internal/ccvs/ui/messages.properties (+8 lines)
Lines 226-231 Link Here
226
CVSPreferencesPage_45=Use .project &project name instead of module name on check out
226
CVSPreferencesPage_45=Use .project &project name instead of module name on check out
227
CVSPropertiesPage_virtualModule=<no corresponding remote folder>
227
CVSPropertiesPage_virtualModule=<no corresponding remote folder>
228
228
229
CVSProxyPreferencePage_enableProxy=&Enable proxy connection
230
CVSProxyPreferencePage_proxyTpe=Proxy &type:
231
CVSProxyPreferencePage_proxyHost=Proxy host add&ress:
232
CVSProxyPreferencePage_proxyPort=Proxy host p&ort:
233
CVSProxyPreferencePage_enableProxyAuth=E&nable proxy authentication
234
CVSProxyPreferencePage_proxyUser=Proxy &user name:
235
CVSProxyPreferencePage_proxyPass=Proxy pa&ssword:
236
CVSProxyPreferencePage_proxyPortError=Port must be a number between 0 and 65535.
229
237
230
CVSRemoteFilePropertySource_name=Name
238
CVSRemoteFilePropertySource_name=Name
231
CVSRemoteFilePropertySource_revision=Revision
239
CVSRemoteFilePropertySource_revision=Revision
(-)src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java (+13 lines)
Lines 600-605 Link Here
600
		CVSProviderPlugin.getPlugin().setDetermineVersionEnabled(store.getBoolean(ICVSUIConstants.PREF_DETERMINE_SERVER_VERSION));
600
		CVSProviderPlugin.getPlugin().setDetermineVersionEnabled(store.getBoolean(ICVSUIConstants.PREF_DETERMINE_SERVER_VERSION));
601
		CVSProviderPlugin.getPlugin().setDebugProtocol(CVSProviderPlugin.getPlugin().isDebugProtocol() || store.getBoolean(ICVSUIConstants.PREF_DEBUG_PROTOCOL));
601
		CVSProviderPlugin.getPlugin().setDebugProtocol(CVSProviderPlugin.getPlugin().isDebugProtocol() || store.getBoolean(ICVSUIConstants.PREF_DEBUG_PROTOCOL));
602
        CVSProviderPlugin.getPlugin().setAutoshareOnImport(store.getBoolean(ICVSUIConstants.PREF_AUTO_SHARE_ON_IMPORT));
602
        CVSProviderPlugin.getPlugin().setAutoshareOnImport(store.getBoolean(ICVSUIConstants.PREF_AUTO_SHARE_ON_IMPORT));
603
        
604
        // proxy configuration
605
        store.setDefault(ICVSUIConstants.PREF_USE_PROXY, false);
606
        store.setDefault(ICVSUIConstants.PREF_PROXY_TYPE, CVSProviderPlugin.PROXY_TYPE_HTTP);
607
        store.setDefault(ICVSUIConstants.PREF_PROXY_HOST, ""); //$NON-NLS-1$
608
        store.setDefault(ICVSUIConstants.PREF_PROXY_PORT, CVSProviderPlugin.HTTP_DEFAULT_PORT);
609
        store.setDefault(ICVSUIConstants.PREF_PROXY_AUTH, false);
610
611
        CVSProviderPlugin.getPlugin().setUseProxy(store.getBoolean(ICVSUIConstants.PREF_USE_PROXY));
612
        CVSProviderPlugin.getPlugin().setProxyType(store.getString(ICVSUIConstants.PREF_PROXY_TYPE));
613
        CVSProviderPlugin.getPlugin().setProxyHost(store.getString(ICVSUIConstants.PREF_PROXY_HOST));
614
        CVSProviderPlugin.getPlugin().setProxyPort(store.getString(ICVSUIConstants.PREF_PROXY_PORT));
615
        CVSProviderPlugin.getPlugin().setUseProxyAuth(store.getBoolean(ICVSUIConstants.PREF_PROXY_AUTH));
603
	}
616
	}
604
	
617
	
605
	/**
618
	/**
(-)plugin.xml (+13 lines)
Lines 895-900 Link Here
895
         <keywordReference id="org.eclipse.team.cvs.ui.cvs"/>
895
         <keywordReference id="org.eclipse.team.cvs.ui.cvs"/>
896
      </page>
896
      </page>
897
   </extension>
897
   </extension>
898
   
899
   <extension
900
         point="org.eclipse.ui.preferencePages">
901
      <page
902
            name="%ProxyPreferencePage.name"
903
            category="org.eclipse.team.cvs.ui.CVSPreferences"
904
            class="org.eclipse.team.internal.ccvs.ui.ProxyPreferencePage"
905
            id="org.eclipse.team.cvs.ui.ProxyPreferencesPreferences">
906
            <keywordReference id="org.eclipse.team.cvs.ui.cvs.proxy"/>
907
      </page>
908
   </extension>
909
   
910
   
898
<!-- **************** Decorator ******************* -->
911
<!-- **************** Decorator ******************* -->
899
   <extension
912
   <extension
900
         point="org.eclipse.ui.decorators">
913
         point="org.eclipse.ui.decorators">
(-)plugin.properties (+1 lines)
Lines 34-39 Link Here
34
ConsolePreferencePage.name=Console
34
ConsolePreferencePage.name=Console
35
DecoratorPreferencePage.name=Label Decorations
35
DecoratorPreferencePage.name=Label Decorations
36
ExtMethodPreferencePage.name=Ext Connection Method
36
ExtMethodPreferencePage.name=Ext Connection Method
37
ProxyPreferencePage.name=Proxy Settings
37
WatchEditPreferencePage.name=Watch/Edit
38
WatchEditPreferencePage.name=Watch/Edit
38
ComparePreferencePage.name=Synchronize/Compare
39
ComparePreferencePage.name=Synchronize/Compare
39
UpdateMergePreferencePage.name=Update/Merge
40
UpdateMergePreferencePage.name=Update/Merge
(-)src/org/eclipse/team/internal/ccvs/ui/ProxyPreferencePage.java (+279 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.team.internal.ccvs.ui;
12
13
import org.eclipse.jface.dialogs.Dialog;
14
import org.eclipse.jface.preference.IPreferenceStore;
15
import org.eclipse.jface.preference.PreferencePage;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.*;
18
import org.eclipse.swt.layout.GridData;
19
import org.eclipse.swt.layout.GridLayout;
20
import org.eclipse.swt.widgets.*;
21
import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
22
import org.eclipse.ui.*;
23
24
public class ProxyPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
25
26
    private Label proxyTypeLabel;
27
    private Label proxyHostLabel;
28
    private Label proxyPortLabel;
29
    private Label proxyUserLabel;
30
    private Label proxyPassLabel;
31
32
    private Button enableProxy;
33
    private Combo proxyTypeCombo;
34
    private Text proxyHostText;
35
    private Text proxyPortText;
36
    private Button enableAuth;
37
    private Text proxyUserText;
38
    private Text proxyPassText;
39
40
  /*
41
   * @see PreferencePage#createContents(Composite)
42
   */
43
  protected Control createContents(Composite parent) {
44
      Composite composite = new Composite(parent, SWT.NULL);
45
      GridLayout layout = new GridLayout();
46
      layout.marginWidth = 0;
47
      layout.marginHeight = 0;
48
      layout.numColumns = 2;
49
      composite.setLayout(layout);
50
      composite.setLayoutData(new GridData());
51
    
52
      GridData data = new GridData();
53
      data.horizontalAlignment = GridData.FILL;
54
      composite.setLayoutData(data);
55
      
56
      createProxyPage(composite);
57
       
58
      initializeDefaults();
59
      PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IHelpContextIds.PROXY_PREFERENCE_PAGE);
60
      Dialog.applyDialogFont(parent);
61
      return composite;
62
    }
63
  
64
  
65
    private void initializeDefaults() {
66
        IPreferenceStore store = getPreferenceStore();
67
68
        enableProxy.setSelection(store.getBoolean(ICVSUIConstants.PREF_USE_PROXY));
69
70
        proxyTypeCombo.select(store.getString(ICVSUIConstants.PREF_PROXY_TYPE).equals(CVSProviderPlugin.PROXY_TYPE_HTTP)? 0:1); 
71
        proxyHostText.setText(store.getString(ICVSUIConstants.PREF_PROXY_HOST));
72
        proxyPortText.setText(store.getString(ICVSUIConstants.PREF_PROXY_PORT));
73
        
74
        enableAuth.setSelection(store.getBoolean(ICVSUIConstants.PREF_PROXY_AUTH));        
75
        proxyUserText.setText(CVSProviderPlugin.getPlugin().getProxyUser());
76
        proxyPassText.setText(CVSProviderPlugin.getPlugin().getProxyPassword());
77
78
        // FIXME
79
        updateControls();
80
    }
81
  
82
    /*
83
     * @see IWorkbenchPreferencePage#init(IWorkbench)
84
     */
85
    public void init(IWorkbench workbench) {
86
    }
87
  
88
    /*
89
     * @see IPreferencePage#performOk()
90
     */
91
    public boolean performOk() {
92
        IPreferenceStore store = getPreferenceStore();
93
        
94
        store.setValue(ICVSUIConstants.PREF_USE_PROXY, enableProxy.getSelection());
95
        
96
        store.setValue(ICVSUIConstants.PREF_PROXY_TYPE, proxyTypeCombo.getText());
97
        store.setValue(ICVSUIConstants.PREF_PROXY_HOST, proxyHostText.getText());
98
        store.setValue(ICVSUIConstants.PREF_PROXY_PORT, proxyPortText.getText());
99
100
        store.setValue(ICVSUIConstants.PREF_PROXY_AUTH, enableAuth.getSelection());
101
        
102
        CVSProviderPlugin plugin = CVSProviderPlugin.getPlugin();
103
        
104
        plugin.setUseProxy(enableProxy.getSelection());
105
106
        plugin.setProxyType(proxyTypeCombo.getText());
107
        plugin.setProxyHost(proxyHostText.getText());
108
        plugin.setProxyPort(proxyPortText.getText());
109
110
        plugin.setUseProxyAuth(enableAuth.getSelection());
111
        plugin.setProxyAuth(proxyUserText.getText(), proxyPassText.getText());
112
                
113
        CVSUIPlugin.getPlugin().savePluginPreferences();
114
        return super.performOk();
115
    }
116
    
117
    /* 
118
     * @see PreferencePage#performDefaults()
119
     */
120
    protected void performDefaults() {
121
    	super.performDefaults();
122
        IPreferenceStore store = getPreferenceStore();
123
        store.setToDefault(ICVSUIConstants.PREF_USE_PROXY);
124
        store.setToDefault(ICVSUIConstants.PREF_PROXY_TYPE);
125
        store.setToDefault(ICVSUIConstants.PREF_PROXY_HOST);
126
        store.setToDefault(ICVSUIConstants.PREF_PROXY_PORT);
127
        store.setToDefault(ICVSUIConstants.PREF_PROXY_AUTH);
128
        CVSProviderPlugin.getPlugin().setProxyAuth("",""); //$NON-NLS-1$ //$NON-NLS-2$
129
        
130
        initializeDefaults();
131
    }
132
    
133
134
    /*
135
     * @see PreferencePage#doGetPreferenceStore()
136
     */
137
    protected IPreferenceStore doGetPreferenceStore() {
138
      return CVSUIPlugin.getPlugin().getPreferenceStore();
139
    }
140
  
141
    private void createProxyPage(Composite group) {
142
    
143
        enableProxy = new Button(group, SWT.CHECK);
144
        enableProxy.setText(CVSUIMessages.CVSProxyPreferencePage_enableProxy);
145
        GridData gd = new GridData();
146
        gd.horizontalSpan = 2;
147
        enableProxy.setLayoutData(gd);
148
        enableProxy.addSelectionListener(new SelectionAdapter() {
149
          public void widgetSelected(SelectionEvent e) {
150
            updateControls();
151
          }
152
        });
153
    
154
        proxyTypeLabel = new Label(group, SWT.NONE);
155
        proxyTypeLabel.setText(CVSUIMessages.CVSProxyPreferencePage_proxyTpe);
156
        
157
        proxyTypeCombo = new Combo(group, SWT.READ_ONLY);
158
        proxyTypeCombo.setFont(group.getFont());
159
        gd = new GridData(GridData.FILL_HORIZONTAL);
160
        gd.horizontalSpan = 1;
161
        proxyTypeCombo.setLayoutData(gd);
162
        proxyTypeCombo.add(CVSProviderPlugin.PROXY_TYPE_HTTP);
163
        proxyTypeCombo.add(CVSProviderPlugin.PROXY_TYPE_SOCKS5);
164
        proxyTypeCombo.select(0);
165
        proxyTypeCombo.addModifyListener(new ModifyListener() {
166
          public void modifyText(ModifyEvent e) {
167
            if(proxyPortText == null)
168
              return;
169
            Combo combo = (Combo) (e.getSource());
170
            String foo = combo.getText();
171
            if(foo.equals(CVSProviderPlugin.PROXY_TYPE_HTTP)) {
172
              proxyPortText.setText(CVSProviderPlugin.HTTP_DEFAULT_PORT);
173
            } else if(foo.equals(CVSProviderPlugin.PROXY_TYPE_SOCKS5)) {
174
              proxyPortText.setText(CVSProviderPlugin.SOCKS5_DEFAULT_PORT);
175
            }
176
          }
177
        });
178
    
179
        proxyHostLabel = new Label(group, SWT.NONE);
180
        proxyHostLabel.setText(CVSUIMessages.CVSProxyPreferencePage_proxyHost);
181
    
182
        proxyHostText = new Text(group, SWT.SINGLE | SWT.BORDER);
183
        proxyHostText.setFont(group.getFont());
184
        gd = new GridData(GridData.FILL_HORIZONTAL);
185
        gd.horizontalSpan = 1;
186
        proxyHostText.setLayoutData(gd);
187
    
188
        proxyPortLabel = new Label(group, SWT.NONE);
189
        proxyPortLabel.setText(CVSUIMessages.CVSProxyPreferencePage_proxyPort);
190
    
191
        proxyPortText = new Text(group, SWT.SINGLE | SWT.BORDER);
192
        proxyPortText.setFont(group.getFont());
193
        gd = new GridData(GridData.FILL_HORIZONTAL);
194
        gd.horizontalSpan = 1;
195
        proxyPortText.setLayoutData(gd);
196
    
197
        proxyPortText.addModifyListener(new ModifyListener() {
198
          public void modifyText(ModifyEvent e) {
199
            if(isValidPort(proxyPortText.getText())) {
200
              setErrorMessage(null);
201
            }
202
          }
203
        });
204
    
205
        createSpacer(group, 2);
206
    
207
        enableAuth = new Button(group, SWT.CHECK);
208
        enableAuth.setText(CVSUIMessages.CVSProxyPreferencePage_enableProxyAuth);
209
        gd = new GridData();
210
        gd.horizontalSpan = 2;
211
        enableAuth.setLayoutData(gd);
212
        enableAuth.addSelectionListener(new SelectionAdapter() {
213
          public void widgetSelected(SelectionEvent e) {
214
            updateControls();
215
          }
216
        });
217
    
218
        proxyUserLabel = new Label(group, SWT.NONE);
219
        proxyUserLabel.setText(CVSUIMessages.CVSProxyPreferencePage_proxyUser);
220
    
221
        proxyUserText = new Text(group, SWT.SINGLE | SWT.BORDER);
222
        proxyUserText.setFont(group.getFont());
223
        gd = new GridData(GridData.FILL_HORIZONTAL);
224
        gd.horizontalSpan = 1;
225
        proxyUserText.setLayoutData(gd);
226
    
227
        proxyPassLabel = new Label(group, SWT.NONE);
228
        proxyPassLabel.setText(CVSUIMessages.CVSProxyPreferencePage_proxyPass);
229
    
230
        proxyPassText = new Text(group, SWT.SINGLE | SWT.BORDER);
231
        proxyPassText.setEchoChar('*');
232
        proxyPassText.setFont(group.getFont());
233
        gd = new GridData(GridData.FILL_HORIZONTAL);
234
        gd.horizontalSpan = 1;
235
        proxyPassText.setLayoutData(gd);
236
    
237
        //  performDefaults();
238
    }
239
240
    private boolean isValidPort(String port){
241
        int i = -1;
242
        try {   
243
            i = Integer.parseInt(port);
244
        } catch (NumberFormatException ee) {
245
//          setErrorMessage(Policy.bind("CVSSSH2PreferencePage.103")); //$NON-NLS-1$
246
//          return false;
247
        }
248
        if(i < 0 || i > 65535){
249
            setErrorMessage(CVSUIMessages.CVSProxyPreferencePage_proxyPortError); 
250
            return false;
251
        }
252
        return true;
253
    }
254
    
255
    protected void createSpacer(Composite composite, int columnSpan) {
256
      Label label = new Label(composite, SWT.NONE);
257
      GridData gd = new GridData();
258
      gd.horizontalSpan = columnSpan;
259
      label.setLayoutData(gd);
260
    }
261
    
262
    private void updateControls() {
263
      boolean enable = enableProxy.getSelection();
264
      proxyTypeLabel.setEnabled(enable);
265
      proxyTypeCombo.setEnabled(enable);
266
      proxyPortLabel.setEnabled(enable);
267
      proxyPortText.setEnabled(enable);
268
      proxyHostLabel.setEnabled(enable);
269
      proxyHostText.setEnabled(enable);
270
271
      enableAuth.setEnabled(enable);
272
      enable&=enableAuth.getSelection();
273
      proxyUserLabel.setEnabled(enable);
274
      proxyUserText.setEnabled(enable);
275
      proxyPassLabel.setEnabled(enable);
276
      proxyPassText.setEnabled(enable);
277
    }
278
    
279
}

Return to bug 102654