Eclipseplugins
MultiCherryPickCredentialsPage.java
1 package com.proalpha.pds.gitutils.cherrypick;
2 
3 import org.eclipse.jface.dialogs.IMessageProvider;
4 import org.eclipse.jface.dialogs.TitleAreaDialog;
5 import org.eclipse.swt.SWT;
6 import org.eclipse.swt.layout.GridData;
7 import org.eclipse.swt.layout.GridLayout;
8 import org.eclipse.swt.widgets.Composite;
9 import org.eclipse.swt.widgets.Control;
10 import org.eclipse.swt.widgets.Label;
11 import org.eclipse.swt.widgets.Shell;
12 import org.eclipse.swt.widgets.Text;
13 
14 public class MultiCherryPickCredentialsPage extends TitleAreaDialog{
15  private Text txtUser;
16  private Text txtPassword;
17 
18  private String user;
19  private String password;
20 
21  public MultiCherryPickCredentialsPage(Shell parentShell) {
22  super(parentShell);
23  }
24 
25  @Override
26  public void create() {
27  super.create();
28  setTitle("Credentials for Bitbucket");
29  setMessage("Please Enter the bitbucket credentials", IMessageProvider.INFORMATION);
30  }
31 
32  @Override
33  protected Control createDialogArea(Composite parent) {
34  Composite area = (Composite) super.createDialogArea(parent);
35  Composite container = new Composite(area, SWT.NONE);
36  container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
37  GridLayout layout = new GridLayout(2, false);
38  container.setLayout(layout);
39 
40  createUser(container);
41  createPassword(container);
42 
43  return area;
44  }
45 
46  private void createUser(Composite container) {
47  Label lbtFirstName = new Label(container, SWT.NONE);
48  lbtFirstName.setText("Username:");
49 
50  GridData dataUser = new GridData();
51  dataUser.grabExcessHorizontalSpace = true;
52  dataUser.horizontalAlignment = GridData.FILL;
53 
54  txtUser = new Text(container, SWT.BORDER);
55  txtUser.setLayoutData(dataUser);
56  }
57 
58  private void createPassword(Composite container) {
59  Label lbtLastName = new Label(container, SWT.NONE);
60  lbtLastName.setText("Password");
61 
62  GridData dataPassword = new GridData();
63  dataPassword.grabExcessHorizontalSpace = true;
64  dataPassword.horizontalAlignment = GridData.FILL;
65 
66  txtPassword = new Text(container, SWT.BORDER | SWT.PASSWORD);
67  txtPassword.setLayoutData(dataPassword);
68  }
69 
70 
71 
72  @Override
73  protected boolean isResizable() {
74  return true;
75  }
76 
77  // save content of the Text fields because they get disposed
78  // as soon as the Dialog closes
79  private void saveInput() {
80  user = txtUser.getText();
81  password = txtPassword.getText();
82 
83  }
84 
85  @Override
86  protected void okPressed() {
87  saveInput();
88  super.okPressed();
89  }
90 
91  @Override
92  protected void cancelPressed() {
93  password = "";
94  user = "";
95  super.cancelPressed();
96  }
97 
98  public String getUser() {
99  return user;
100  }
101 
102  public String getPassword() {
103  return password;
104  }
105 }