Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0f1a1fd2a9297f6f70c513a94242bade61bd5749 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation.
 *     IBM Corporation - ongoing maintenance
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.ui;

import org.eclipse.jface.dialogs.*;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.window.Window;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.PlatformUI;

/**
 * A dialog for keyboad-interactive authentication for the ssh2 connection.
 */
public class KeyboardInteractiveDialog extends TrayDialog {
  // widgets
  private Text[] texts;

  protected String domain;
  protected String destination;
  protected String name;
  protected String instruction;
  protected String lang;
  protected String[] prompt;
  protected boolean[] echo;
  private String message;
  private String[] result;

  /**
   * Creates a nwe KeyboardInteractiveDialog.
   *
   * @param parentShell the parent shell
   * @param destication the location
   * @param name the name
   * @param instruction the instruction
   * @param prompt the titles for textfields
   * @param echo '*' should be used or not
   */
  public KeyboardInteractiveDialog(Shell parentShell,
				   String location,
				   String destination,
				   String name,
				   String instruction,
				   String[] prompt,
				   boolean[] echo){
    super(parentShell);
    this.domain=location;
    this.destination=destination;
    this.name=name;
    this.instruction=instruction;
    this.prompt=prompt;
    this.echo=echo;
    this.message=NLS.bind(CVSUIMessages.KeyboradInteractiveDialog_message, new String[] { destination+(name!=null && name.length()>0 ? ": "+name : "") }); //NON-NLS-1$ //$NON-NLS-1$ //$NON-NLS-2$ 
  }
  /**
   * @see Window#configureShell
   */
  protected void configureShell(Shell newShell) {
    super.configureShell(newShell);
    newShell.setText(message);
  }
  /**                                                                                           
   * @see Window#create                                                                         
   */
  public void create() {
    super.create();
    if(texts.length>0){
      texts[0].setFocus();
    }
  }
  /**                                                                                           
   * @see Dialog#createDialogArea                                                               
   */
  protected Control createDialogArea(Composite parent) {
    Composite main=new Composite(parent, SWT.NONE);
    GridLayout layout=new GridLayout();
    layout.numColumns=3;
    main.setLayout(layout);
    main.setLayoutData(new GridData(GridData.FILL_BOTH));
    
	// set F1 help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(main, IHelpContextIds.KEYBOARD_INTERACTIVE_DIALOG);
	
    if (message!=null) {
      Label messageLabel=new Label(main, SWT.WRAP);
      messageLabel.setText(message);
      GridData data=new GridData(GridData.FILL_HORIZONTAL);
      data.horizontalSpan=3;
      messageLabel.setLayoutData(data);
    }
    if(domain!=null){
      Label label = new Label(main, SWT.WRAP);
      label.setText(NLS.bind(CVSUIMessages.KeyboardInteractiveDialog_labelRepository, new String[] { domain })); 
      GridData data=new GridData(GridData.FILL_HORIZONTAL);
      data.horizontalSpan=3;
      label.setLayoutData(data);
    }
    if (instruction!=null && instruction.length()>0) {
      Label messageLabel=new Label(main, SWT.WRAP);
      messageLabel.setText(instruction);
      GridData data=new GridData(GridData.FILL_HORIZONTAL);
      data.horizontalSpan=3;
      messageLabel.setLayoutData(data);
    }
    createPasswordFields(main);
    return main;
  }
  /**                                                                                           
   * Creates the widgets that represent the entry area.                          
   *                                                                                            
   * @param parent  the parent of the widgets                                                   
   */
  protected void createPasswordFields(Composite parent) {
    texts=new Text[prompt.length];

    for(int i=0; i<prompt.length; i++){
      new Label(parent, SWT.NONE).setText(prompt[i]);
      texts[i]=new Text(parent, SWT.BORDER);
      GridData data=new GridData(GridData.FILL_HORIZONTAL);
      data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH);
      texts[i].setLayoutData(data);

      if(!echo[i]){
	texts[i].setEchoChar('*');
      }
      new Label(parent, SWT.NONE);
    }

  }
  /**                                                                                           
   * Returns the entered values, or null                                          
   * if the user canceled.                                                                      
   *                                                                                            
   * @return the entered values
   */
  public String[] getResult() {
    return result;
  }
  /**                                                                                           
   * Notifies that the ok button of this dialog has been pressed.                               
   * <p>                                                                                        
   * The default implementation of this framework method sets                                   
   * this dialog's return code to <code>Window.OK</code>                                        
   * and closes the dialog. Subclasses may override.                                            
   * </p>                                                                                       
   */
  protected void okPressed() {
    result=new String[prompt.length];
    for(int i=0; i<texts.length; i++){
      result[i]=texts[i].getText();
    }
    super.okPressed();
  }
  /**                                                                                           
   * Notifies that the cancel button of this dialog has been pressed.                               
   * <p>                                                                                        
   * The default implementation of this framework method sets                                   
   * this dialog's return code to <code>Window.CANCEL</code>                                        
   * and closes the dialog. Subclasses may override.                                            
   * </p>                                                                                       
   */
  protected void cancelPressed() {
    result=null;
    super.cancelPressed();
  }
}

Back to the top