?? cvsssh2preferencepage.java
字號(hào):
/* -*-mode:java; c-basic-offset:2; -*- *//**********************************************************************Copyright (c) 2003, Atsuhiko Yamanaka, JCraft,Inc. and others.All rights reserved. This program and the accompanying materialsare made available under the terms of the Common Public License v1.0which accompanies this distribution, and is available athttp://www.eclipse.org/legal/cpl-v10.htmlContributors: Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation.**********************************************************************/package org.eclipse.team.ccvs.ssh2;import org.eclipse.core.runtime.*;import org.eclipse.jface.dialogs.*;import org.eclipse.jface.dialogs.Dialog;import org.eclipse.jface.preference.*;import org.eclipse.jface.viewers.ColumnWeightData;import org.eclipse.jface.viewers.IStructuredContentProvider;import org.eclipse.jface.viewers.IStructuredSelection;import org.eclipse.jface.viewers.ITableLabelProvider;import org.eclipse.jface.viewers.LabelProvider;import org.eclipse.jface.viewers.TableLayout;import org.eclipse.jface.viewers.TableViewer;import org.eclipse.jface.viewers.Viewer;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.MessageBox;import org.eclipse.swt.SWT;import org.eclipse.swt.events.*;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.*;import org.eclipse.swt.custom.*;import org.eclipse.ui.IWorkbench;import org.eclipse.ui.IWorkbenchPreferencePage;import org.eclipse.swt.graphics.Image;import java.util.Iterator;import java.io.ByteArrayOutputStream;import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.File;import com.jcraft.jsch.*;import org.eclipse.team.ccvs.ssh2.Policy;public class CVSSSH2PreferencePage extends PreferencePage implements IWorkbenchPreferencePage { public static String KEY_PROXY="CVSSSH2PreferencePage.PROXY"; //$NON-NLS-1$ public static String KEY_PROXY_TYPE="CVSSSH2PreferencePage.PROXY_TYPE"; //$NON-NLS-1$ public static String KEY_PROXY_HOST="CVSSSH2PreferencePage.PROXY_HOST"; //$NON-NLS-1$ public static String KEY_PROXY_PORT="CVSSSH2PreferencePage.PROXY_PORT"; //$NON-NLS-1$ public static String KEY_PROXY_AUTH="CVSSSH2PreferencePage.PROXY_AUTH"; //$NON-NLS-1$ public static String KEY_PROXY_USER="CVSSSH2PreferencePage.PROXY_USER"; //$NON-NLS-1$ public static String KEY_PROXY_PASS="CVSSSH2PreferencePage.PROXY_PASS"; //$NON-NLS-1$ public static String KEY_SSH2HOME="CVSSSH2PreferencePage.SSH2HOME"; //$NON-NLS-1$ public static String KEY_KEYFILE="CVSSSH2PreferencePage.KEYFILE"; //$NON-NLS-1$ public static String KEY_PRIVATEKEY="CVSSSH2PreferencePage.PRIVATEKEY"; //$NON-NLS-1$ static String SOCKS5="SOCKS5"; //$NON-NLS-1$ static String HTTP="HTTP"; //$NON-NLS-1$ private static String HTTP_DEFAULT_PORT="80"; //$NON-NLS-1$ private static String SOCKS5_DEFAULT_PORT="1080"; //$NON-NLS-1$ private static String privatekeys="id_dsa,id_rsa"; //$NON-NLS-1$ static String DSA="DSA"; //$NON-NLS-1$ static String RSA="RSA"; //$NON-NLS-1$// private DirectoryFieldEditor ssh2homeEditor; private Label ssh2HomeLabel; private Label proxyTypeLabel; private Label proxyHostLabel; private Label proxyPortLabel; private Label proxyUserLabel; private Label proxyPassLabel; private Label privateKeyLabel; private Combo proxyTypeCombo; private Text ssh2HomeText; private Text proxyHostText; private Text proxyPortText; private Text proxyUserText; private Text proxyPassText; private Text privateKeyText; private Button enableProxy; private Button enableAuth; private Button privateKeyAdd; private boolean useProxy; private boolean useAuth; private Label keyTypeLabel; private Combo keyTypeCombo; private Button ssh2HomeBrowse; private Button keyGenerateDSA; private Button keyGenerateRSA; private Button keyLoad; private Button keyExport; private Button saveKeyPair; private Label keyCommentLabel; private Text keyCommentText; private Label keyFingerPrintLabel; private Text keyFingerPrintText; private Label keyPassphrase1Label; private Text keyPassphrase1Text; private Label keyPassphrase2Label; private Text keyPassphrase2Text; private Label publicKeylabel; private Text publicKeyText; private KeyPair kpair=null; private String kpairComment; public CVSSSH2PreferencePage() {// super(GRID); IPreferenceStore store=CVSSSH2Plugin.getDefault().getPreferenceStore(); setPreferenceStore(store); setDescription(Policy.bind("CVSSSH2PreferencePage.18")); //$NON-NLS-1$ } protected Control createContents(Composite parent) { Composite container = new Composite(parent, SWT.NULL); GridLayout layout = new GridLayout(); container.setLayout(layout); TabFolder tabFolder = new TabFolder(container, SWT.NONE); tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH)); TabItem tabItem = new TabItem(tabFolder, SWT.NONE); tabItem.setText(Policy.bind("CVSSSH2PreferencePage.19")); //$NON-NLS-1$ tabItem.setControl(createGeneralPage(tabFolder)); tabItem = new TabItem(tabFolder, SWT.NONE); tabItem.setText(Policy.bind("CVSSSH2PreferencePage.20")); //$NON-NLS-1$ tabItem.setControl(createProxyPage(tabFolder)); tabItem = new TabItem(tabFolder, SWT.NONE); tabItem.setText(Policy.bind("CVSSSH2PreferencePage.21")); //$NON-NLS-1$ tabItem.setControl(createKeyManagementPage(tabFolder)); tabItem = new TabItem(tabFolder, SWT.NONE); tabItem.setText(Policy.bind("CVSSSH2PreferencePage.133")); //$NON-NLS-1$ tabItem.setControl(createHostKeyManagementPage(tabFolder)); IPreferenceStore store=CVSSSH2Plugin.getDefault().getPreferenceStore(); initDefaults(store); initControls(); Dialog.applyDialogFont(parent); return container; } private Control createGeneralPage(Composite parent) { Composite group=new Composite(parent, SWT.NULL); GridLayout layout=new GridLayout(); layout.numColumns=3; group.setLayout(layout); GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; group.setLayoutData(data); ssh2HomeLabel=new Label(group, SWT.NONE); ssh2HomeLabel.setText(Policy.bind("CVSSSH2PreferencePage.23")); //$NON-NLS-1$ ssh2HomeText=new Text(group, SWT.SINGLE | SWT.BORDER); ssh2HomeText.setFont(group.getFont()); GridData gd=new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan=1; ssh2HomeText.setLayoutData(gd); ssh2HomeBrowse=new Button(group, SWT.NULL); ssh2HomeBrowse.setText(Policy.bind("CVSSSH2PreferencePage.24")); //$NON-NLS-1$ gd=new GridData(GridData.HORIZONTAL_ALIGN_FILL); gd.horizontalSpan=1; ssh2HomeBrowse.setLayoutData(gd); createSpacer(group, 3); privateKeyLabel=new Label(group, SWT.NONE); privateKeyLabel.setText(Policy.bind("CVSSSH2PreferencePage.25")); //$NON-NLS-1$ privateKeyText=new Text(group, SWT.SINGLE | SWT.BORDER); privateKeyText.setFont(group.getFont()); gd=new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan=1; privateKeyText.setLayoutData(gd); privateKeyAdd=new Button(group, SWT.NULL); privateKeyAdd.setText(Policy.bind("CVSSSH2PreferencePage.26")); //$NON-NLS-1$ gd=new GridData(GridData.HORIZONTAL_ALIGN_FILL); gd.horizontalSpan=1; privateKeyAdd.setLayoutData(gd); ssh2HomeBrowse.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e){ String home=ssh2HomeText.getText(); if(!new File(home).exists()){ while(true){ int foo=home.lastIndexOf(java.io.File.separator, home.length()); if(foo==-1)break; home=home.substring(0, foo); if(new File(home).exists())break; } } DirectoryDialog dd=new DirectoryDialog(getShell()); dd.setFilterPath(home); dd.setMessage(Policy.bind("CVSSSH2PreferencePage.27")); //$NON-NLS-1$ String dir=dd.open(); if(dir==null){ // cancel return; } ssh2HomeText.setText(dir); } }); privateKeyAdd.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e){ String home=ssh2HomeText.getText(); FileDialog fd=new FileDialog(getShell(), SWT.OPEN|SWT.MULTI); fd.setFilterPath(home); Object o=fd.open(); if(o==null){ // cancel return; } String[] files=fd.getFileNames(); String keys=privateKeyText.getText(); String dir=fd.getFilterPath(); if(dir.equals(home)){dir="";} //$NON-NLS-1$ else{dir+=java.io.File.separator;} for(int i=0; i<files.length; i++){ String foo=files[i]; if(keys.length()!=0)keys=keys+","; keys=keys+dir+foo; } privateKeyText.setText(keys); } }); return group; } private Control createProxyPage(Composite parent) { Composite group=new Composite(parent, SWT.NULL); GridLayout layout=new GridLayout(); layout.numColumns=3; group.setLayout(layout); GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; group.setLayoutData(data); enableProxy=new Button(group, SWT.CHECK); enableProxy.setText(Policy.bind("CVSSSH2PreferencePage.30")); //$NON-NLS-1$ GridData gd=new GridData(); gd.horizontalSpan=3; enableProxy.setLayoutData(gd); proxyTypeLabel=new Label(group, SWT.NONE); proxyTypeLabel.setText(Policy.bind("CVSSSH2PreferencePage.31")); //$NON-NLS-1$ proxyTypeCombo=new Combo(group, SWT.READ_ONLY); proxyTypeCombo.setFont(group.getFont()); gd=new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan=2; proxyTypeCombo.setLayoutData(gd); proxyTypeCombo.addModifyListener(new ModifyListener () { public void modifyText(ModifyEvent e){ if(proxyPortText==null) return; Combo combo=(Combo)(e.getSource()); String foo=combo.getText(); if(foo.equals(HTTP)){ proxyPortText.setText(HTTP_DEFAULT_PORT); } else if(foo.equals(SOCKS5)){ proxyPortText.setText(SOCKS5_DEFAULT_PORT); } } }); proxyTypeCombo.add(HTTP); proxyTypeCombo.add(SOCKS5); proxyTypeCombo.select(0); proxyHostLabel=new Label(group, SWT.NONE); proxyHostLabel.setText(Policy.bind("CVSSSH2PreferencePage.32")); //$NON-NLS-1$ proxyHostText=new Text(group, SWT.SINGLE | SWT.BORDER); proxyHostText.setFont(group.getFont()); gd=new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan=2; proxyHostText.setLayoutData(gd); proxyPortLabel=new Label(group, SWT.NONE); proxyPortLabel.setText(Policy.bind("CVSSSH2PreferencePage.33")); //$NON-NLS-1$ proxyPortText=new Text(group, SWT.SINGLE | SWT.BORDER); proxyPortText.setFont(group.getFont()); gd=new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan=2; proxyPortText.setLayoutData(gd); proxyPortText.addModifyListener(new ModifyListener(){ public void modifyText(ModifyEvent e){ if(isValidPort(proxyPortText.getText())){ setErrorMessage(null); } } }); createSpacer(group, 3); enableAuth=new Button(group, SWT.CHECK); enableAuth.setText(Policy.bind("CVSSSH2PreferencePage.34")); //$NON-NLS-1$ gd=new GridData(); gd.horizontalSpan=3; enableAuth.setLayoutData(gd); proxyUserLabel=new Label(group, SWT.NONE); proxyUserLabel.setText(Policy.bind("CVSSSH2PreferencePage.35")); //$NON-NLS-1$ proxyUserText=new Text(group, SWT.SINGLE | SWT.BORDER); proxyUserText.setFont(group.getFont()); gd=new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan=2; proxyUserText.setLayoutData(gd); proxyPassLabel=new Label(group, SWT.NONE); proxyPassLabel.setText(Policy.bind("CVSSSH2PreferencePage.36")); //$NON-NLS-1$ proxyPassText=new Text(group, SWT.SINGLE | SWT.BORDER); proxyPassText.setFont(group.getFont()); gd=new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan=2; proxyPassText.setLayoutData(gd); // performDefaults(); enableProxy.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { updateControls(); } public void widgetDefaultSelected(SelectionEvent e) { } }); enableAuth.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { updateControls(); } public void widgetDefaultSelected(SelectionEvent e) { } }); return group; } private Control createKeyManagementPage(Composite parent) { int columnSpan=3; Composite group=new Composite(parent, SWT.NULL); GridLayout layout=new GridLayout(); layout.numColumns=3; group.setLayout(layout); GridData gd = new GridData(); gd.horizontalAlignment = GridData.FILL; group.setLayoutData(gd); keyGenerateDSA=new Button(group, SWT.NULL); keyGenerateDSA.setText(Policy.bind("CVSSSH2PreferencePage.131")); //$NON-NLS-1$ gd=new GridData(); gd.horizontalSpan=1; keyGenerateDSA.setLayoutData(gd); keyGenerateRSA=new Button(group, SWT.NULL); keyGenerateRSA.setText(Policy.bind("CVSSSH2PreferencePage.132")); //$NON-NLS-1$ gd=new GridData(); gd.horizontalSpan=1; keyGenerateRSA.setLayoutData(gd); keyLoad=new Button(group, SWT.NULL); keyLoad.setText(Policy.bind("CVSSSH2PreferencePage.128")); //$NON-NLS-1$ gd=new GridData(); gd.horizontalSpan=1; keyLoad.setLayoutData(gd);// keyTypeLabel=new Label(group, SWT.NONE);// keyTypeLabel.setText(Policy.bind("CVSSSH2PreferencePage.37")); //$NON-NLS-1$// keyTypeCombo=new Combo(group, SWT.READ_ONLY);// keyTypeCombo.setFont(group.getFont());// GridData gd=new GridData(GridData.FILL_HORIZONTAL);// gd.horizontalSpan=2;// keyTypeCombo.setLayoutData(gd);// keyGenerate=new Button(group, SWT.NULL);// keyGenerate.setText(Policy.bind("CVSSSH2PreferencePage.38")); //$NON-NLS-1$// gd=new GridData(GridData.HORIZONTAL_ALIGN_END);// gd.horizontalSpan=columnSpan;// keyGenerate.setLayoutData(gd);/* keyLoad=new Button(group, SWT.NULL); keyLoad.setText("Load(not implemented)"); gd=new GridData(GridData.HORIZONTAL_ALIGN_END); gd.horizontalSpan=columnSpan; keyLoad.setLayoutData(gd);*/ publicKeylabel=new Label(group, SWT.NONE); publicKeylabel.setText(Policy.bind("CVSSSH2PreferencePage.39")); //$NON-NLS-1$ gd=new GridData(); gd.horizontalSpan=columnSpan; publicKeylabel.setLayoutData(gd); publicKeyText=new Text(group,SWT.MULTI|SWT.BORDER|SWT.V_SCROLL|SWT.WRAP); publicKeyText.setText(""); //$NON-NLS-1$ publicKeyText.setEditable(false); gd=new GridData(); gd.horizontalSpan=columnSpan; gd.horizontalAlignment = GridData.FILL; gd.verticalAlignment = GridData.FILL; gd.grabExcessHorizontalSpace = true; gd.grabExcessVerticalSpace = true; publicKeyText.setLayoutData(gd); keyExport=new Button(group, SWT.NULL); keyExport.setText(Policy.bind("CVSSSH2PreferencePage.105")); //$NON-NLS-1$ gd=new GridData(GridData.HORIZONTAL_ALIGN_END); gd.horizontalSpan=columnSpan; keyExport.setLayoutData(gd); keyFingerPrintLabel=new Label(group, SWT.NONE); keyFingerPrintLabel.setText(Policy.bind("CVSSSH2PreferencePage.41")); //$NON-NLS-1$ keyFingerPrintText=new Text(group, SWT.SINGLE | SWT.BORDER); keyFingerPrintText.setFont(group.getFont()); keyFingerPrintText.setEditable(false); gd=new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan=2; keyFingerPrintText.setLayoutData(gd); keyCommentLabel=new Label(group, SWT.NONE); keyCommentLabel.setText(Policy.bind("CVSSSH2PreferencePage.42")); //$NON-NLS-1$ keyCommentText=new Text(group, SWT.SINGLE | SWT.BORDER); keyCommentText.setFont(group.getFont()); gd=new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan=2; keyCommentText.setLayoutData(gd); keyCommentText.addModifyListener(new ModifyListener(){ public void modifyText(ModifyEvent e){ if(kpair==null)return;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -