4
4
package org.vcs.bazaar.eclipse.ui.dialogs;
7
import java.util.ArrayList;
8
import java.util.Collection;
7
9
import java.util.Collections;
8
10
import java.util.List;
10
12
import org.eclipse.jface.dialogs.IInputValidator;
11
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.events.FocusEvent;
15
import org.eclipse.swt.events.FocusListener;
12
16
import org.eclipse.swt.events.ModifyEvent;
13
17
import org.eclipse.swt.events.ModifyListener;
18
import org.eclipse.swt.events.MouseEvent;
19
import org.eclipse.swt.events.MouseListener;
20
import org.eclipse.swt.events.SelectionEvent;
21
import org.eclipse.swt.events.SelectionListener;
14
22
import org.eclipse.swt.layout.GridData;
15
23
import org.eclipse.swt.widgets.Button;
16
24
import org.eclipse.swt.widgets.Combo;
17
25
import org.eclipse.swt.widgets.Composite;
18
26
import org.eclipse.swt.widgets.Control;
27
import org.eclipse.swt.widgets.Display;
19
28
import org.eclipse.swt.widgets.Shell;
20
import org.vcs.bazaar.client.commandline.commands.options.Option;
29
import org.vcs.bazaar.client.core.BranchLocation;
21
30
import org.vcs.bazaar.eclipse.core.model.IBzrBranch;
31
import org.vcs.bazaar.eclipse.internal.core.model.RemoteBranch;
22
32
import org.vcs.bazaar.eclipse.ui.UITexts;
30
40
private Combo uriCombo;
31
41
private Button remember;
32
42
private Button force;
33
private List<IBzrBranch> locations;
43
private Collection<IBzrBranch> locations;
34
44
private LocationDialogInfo info;
35
45
private Boolean[] options;
46
private Button useExistingDir;
37
48
private static final int REMEMBER = 0;
38
49
private static final int FORCE = 1;
50
private static final int USE_EXISTING_DIR = 2;
40
52
protected static class BaseURIValidator implements IInputValidator {
41
53
public String isValid(String newText) {
61
public static LocationInputDialog remoteBindLocationDialog(Shell parentShell, List<IBzrBranch> locations, LocationDialogInfo info) {
73
public static LocationInputDialog remoteBindLocationDialog(Shell parentShell, Collection<IBzrBranch> locations, LocationDialogInfo info) {
62
74
return remoteLocationDialog(parentShell, locations, info, "Please enter the URI to bind: ", false);
65
public static LocationInputDialog remotePushLocationDialog(Shell parentShell, List<IBzrBranch> locations, LocationDialogInfo info) {
66
return remoteLocationDialog(parentShell, locations, info, "Please enter the URI to push to: ", true);
77
public static LocationInputDialog remotePushLocationDialog(Shell parentShell, Collection<IBzrBranch> locations, LocationDialogInfo info) {
78
return new LocationInputDialog(parentShell, "Remote location Dialog", "Please enter the URI to push to: ", "", new BaseURIValidator(), locations, info, true, false, true);
69
public static LocationInputDialog remotePullLocationDialog(Shell parentShell, List<IBzrBranch> locations, LocationDialogInfo info) {
81
public static LocationInputDialog remotePullLocationDialog(Shell parentShell, Collection<IBzrBranch> locations, LocationDialogInfo info) {
70
82
return remoteLocationDialog(parentShell, locations, info, "Please enter the URI to pull from: ", true);
73
public static LocationInputDialog missingLocationDialog(Shell parentShell, final List<IBzrBranch> locations, LocationDialogInfo info) {
85
public static LocationInputDialog missingLocationDialog(Shell parentShell, final Collection<IBzrBranch> locations, LocationDialogInfo info) {
74
86
return new LocationInputDialog(parentShell, "Remote location Dialog", "Please enter the URI to look for missing revisions: ", "", new BaseURIValidator(), locations, info, false);
77
public static LocationInputDialog remoteMergeLocationDialog(Shell parentShell, List<IBzrBranch> locations, LocationDialogInfo info) {
89
public static LocationInputDialog remoteMergeLocationDialog(Shell parentShell, Collection<IBzrBranch> locations, LocationDialogInfo info) {
78
90
return remoteLocationDialog(parentShell, locations, info, "Please enter the URI of the branch to merge with: ", true);
89
101
* LocationInputDialog
91
public static LocationInputDialog remoteLocationDialog(Shell parentShell, List<IBzrBranch> locations, LocationDialogInfo info, String dialogMessage, boolean rememberOption) {
103
public static LocationInputDialog remoteLocationDialog(Shell parentShell, Collection<IBzrBranch> locations, LocationDialogInfo info, String dialogMessage, boolean rememberOption) {
92
104
return new LocationInputDialog(parentShell, "Remote location Dialog", dialogMessage, "", new BaseURIValidator(), locations, info, rememberOption);
95
public static LocationInputDialog switchLocationDialog(Shell parentShell, List<IBzrBranch> locations, LocationDialogInfo dialogInfo) {
107
public static LocationInputDialog switchLocationDialog(Shell parentShell, Collection<IBzrBranch> locations, LocationDialogInfo dialogInfo) {
96
108
return new LocationInputDialog(parentShell, "Switch location", "Please enter the URI to switch: ", "", new BaseURIValidator(), locations, dialogInfo, false, true);
99
public LocationInputDialog(Shell parentShell, String dialogTitle, String dialogMessage, String initialValue, IInputValidator validator, List<IBzrBranch> locations, LocationDialogInfo info, Boolean...options) {
111
public LocationInputDialog(Shell parentShell, String dialogTitle, String dialogMessage, String initialValue, IInputValidator validator, Collection<IBzrBranch> locations, LocationDialogInfo info, Boolean...options) {
100
112
super(parentShell, dialogTitle, dialogMessage, initialValue, validator);
101
113
this.locations = locations;
102
114
this.info = info;
106
118
protected LocationInputDialog(Shell shell, String dialogTitle, String dialogMessage, String initialValue, BaseURIValidator validator) {
107
119
super(shell, dialogTitle, dialogMessage, initialValue, validator);
108
this.locations = Collections.EMPTY_LIST;
120
this.locations = Collections.emptyList();
109
121
this.info = new LocationDialogInfo();
110
122
this.options = new Boolean[0];
121
133
uriCombo.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
122
134
uriCombo.addModifyListener(new ModifyListener() {
123
135
public void modifyText(ModifyEvent e) {
139
uriCombo.addSelectionListener(new SelectionListener() {
140
public void widgetSelected(SelectionEvent e) {
143
public void widgetDefaultSelected(SelectionEvent e) {
147
uriCombo.addMouseListener(new MouseListener() {
148
public void mouseUp(MouseEvent e) {
151
public void mouseDown(MouseEvent e) {
154
public void mouseDoubleClick(MouseEvent e) {
158
uriCombo.addFocusListener(new FocusListener() {
159
public void focusLost(FocusEvent e) {
162
public void focusGained(FocusEvent e) {
127
166
loadBranchesInCombo();
137
176
protected void createOptionsArea(Composite composite) {
138
177
if(options.length >= 1 && options[REMEMBER]) {
139
178
remember = new Button(composite, SWT.CHECK);
140
remember.setText("remember");
179
remember.setText("Remember");
141
180
remember.setSelection(false); // Start unselected.
143
182
if(options.length >= 2 && options[FORCE]) {
146
185
force.setToolTipText(UITexts.SwitchAction_force_tooltip);
147
186
force.setSelection(false); // Start unselected.
188
if(options.length >= 3 && options[USE_EXISTING_DIR]) {
189
useExistingDir = new Button(composite, SWT.CHECK);
190
useExistingDir.setText("Use existing directory");
191
useExistingDir.setToolTipText("Use existing directory");
192
useExistingDir.setSelection(false); // Start unselected.
206
255
public void setForce(boolean force) {
207
256
this.force = force;
258
public boolean isUseExistingDir() {
259
return useExistingDir;
261
public void setUseExistingDir(boolean useExistingDir) {
262
this.useExistingDir = useExistingDir;
266
// this main is for test the dialog during development
267
public static void main(String[] args) {
268
Display display = new Display();
269
Shell shell = new Shell(display);
270
shell.setMinimumSize(280, 400);
271
LocationDialogInfo info = new LocationDialogInfo();
272
List<IBzrBranch> locations = new ArrayList<IBzrBranch>();
273
IBzrBranch b = new RemoteBranch(new BranchLocation("lp:bzr-eclipse"));
275
LocationInputDialog dialog =
276
LocationInputDialog.remotePullLocationDialog(shell, locations, info);
277
dialog.setBlockOnOpen(true);