~piastucki/bzr-eclipse/embed-rewrite

« back to all changes in this revision

Viewing changes to org.vcs.bazaar.eclipse.ui/src/org/vcs/bazaar/eclipse/ui/dialogs/LocationInputDialog.java

  • Committer: Guillermo Gonzalez
  • Date: 2010-02-02 06:40:31 UTC
  • mfrom: (219 trunk)
  • mto: This revision was merged to the branch mainline in revision 223.
  • Revision ID: guillo.gonzo@gmail.com-20100202064031-r0hch2h8bq67y1sx
merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
package org.vcs.bazaar.eclipse.ui.dialogs;
5
5
 
6
6
import java.net.URI;
 
7
import java.util.ArrayList;
 
8
import java.util.Collection;
7
9
import java.util.Collections;
8
10
import java.util.List;
9
11
 
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;
23
33
 
24
34
/**
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;
36
47
        
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;
39
51
        
40
52
        protected static class BaseURIValidator implements IInputValidator {
41
53
                public String isValid(String newText) {
58
70
                }
59
71
        };
60
72
 
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);
63
75
        }
64
76
        
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);
67
79
        }
68
80
        
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);
71
83
        }
72
84
        
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);
75
87
        }
76
88
        
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);
79
91
        }
80
92
        
88
100
         * @return 
89
101
         * LocationInputDialog
90
102
         */
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);
93
105
        }
94
106
        
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);
97
109
        }
98
110
 
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;
105
117
        
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];
111
123
        }
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) {
124
 
                                validateInput();
 
136
                validateInput();
125
137
                        }
126
138
                });
 
139
        uriCombo.addSelectionListener(new SelectionListener() {
 
140
            public void widgetSelected(SelectionEvent e) {
 
141
                validateInput();
 
142
            }
 
143
            public void widgetDefaultSelected(SelectionEvent e) {
 
144
                // ignore it
 
145
            }
 
146
        });
 
147
        uriCombo.addMouseListener(new MouseListener() {
 
148
            public void mouseUp(MouseEvent e) {
 
149
                validateInput();
 
150
            }
 
151
            public void mouseDown(MouseEvent e) {
 
152
                validateInput();
 
153
            }
 
154
            public void mouseDoubleClick(MouseEvent e) {
 
155
                // ignore the event
 
156
            }
 
157
        });
 
158
        uriCombo.addFocusListener(new FocusListener() {
 
159
            public void focusLost(FocusEvent e) {
 
160
                validateInput();
 
161
            }
 
162
            public void focusGained(FocusEvent e) {
 
163
                validateInput();
 
164
            }
 
165
        });
127
166
                loadBranchesInCombo();
128
167
        }
129
168
        
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.
142
181
                }
143
182
                if(options.length >= 2 && options[FORCE]) {
146
185
                        force.setToolTipText(UITexts.SwitchAction_force_tooltip);
147
186
                        force.setSelection(false); // Start unselected.
148
187
                }
 
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.
 
193
                }
149
194
        }
150
195
 
151
196
        @Override
179
224
                if(options.length >= 2 && options[FORCE]) {
180
225
                        info.setForce(force.getSelection());
181
226
                }
 
227
                if(options.length >= 3 && options[USE_EXISTING_DIR]) {
 
228
                        info.setUseExistingDir(useExistingDir.getSelection());
 
229
                }
182
230
                info.setLocation(getValue());
183
231
                super.okPressed();
184
232
        }
186
234
        public static class LocationDialogInfo {
187
235
                boolean remember;
188
236
                boolean force;
 
237
                boolean useExistingDir;
189
238
                String location;
190
239
                
191
240
                public boolean isRemember() {
206
255
                public void setForce(boolean force) {
207
256
                        this.force = force;
208
257
                }
 
258
                public boolean isUseExistingDir() {
 
259
                        return useExistingDir;
 
260
                }
 
261
                public void setUseExistingDir(boolean useExistingDir) {
 
262
                        this.useExistingDir = useExistingDir;
 
263
                }
209
264
        }
210
265
 
 
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"));
 
274
        locations.add(b);
 
275
        LocationInputDialog dialog =
 
276
            LocationInputDialog.remotePullLocationDialog(shell, locations, info);
 
277
        dialog.setBlockOnOpen(true);
 
278
        dialog.open();
 
279
    }
211
280
}