Removed
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2002, 2008 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Initial Contributors: |
9 |
* The following IBM employees contributed to the Remote System Explorer |
10 |
* component that contains this file: David McKnight, Kushal Munir, |
11 |
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, |
12 |
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. |
13 |
* |
14 |
* Contributors: |
15 |
* David Dykstal (IBM) - [160403] filters should be connection private by default |
16 |
* David McKnight (IBM) - [225506] [api][breaking] RSE UI leaks non-API types |
17 |
*******************************************************************************/ |
18 |
|
19 |
package org.eclipse.rse.internal.ui.filters.dialogs; |
20 |
import org.eclipse.rse.core.filters.ISystemFilterPool; |
21 |
import org.eclipse.rse.core.filters.ISystemFilterPoolSelectionValidator; |
22 |
import org.eclipse.rse.core.filters.ISystemFilterPoolWrapper; |
23 |
import org.eclipse.rse.core.filters.ISystemFilterPoolWrapperInformation; |
24 |
import org.eclipse.rse.services.clientserver.messages.SystemMessage; |
25 |
import org.eclipse.rse.ui.SystemWidgetHelpers; |
26 |
import org.eclipse.rse.ui.filters.dialogs.ISystemNewFilterWizardConfigurator; |
27 |
import org.eclipse.rse.ui.filters.dialogs.SystemNewFilterWizard; |
28 |
import org.eclipse.rse.ui.validators.ISystemValidator; |
29 |
import org.eclipse.rse.ui.wizards.AbstractSystemWizardPage; |
30 |
import org.eclipse.swt.events.ModifyEvent; |
31 |
import org.eclipse.swt.events.ModifyListener; |
32 |
import org.eclipse.swt.events.SelectionEvent; |
33 |
import org.eclipse.swt.events.SelectionListener; |
34 |
import org.eclipse.swt.widgets.Button; |
35 |
import org.eclipse.swt.widgets.Combo; |
36 |
import org.eclipse.swt.widgets.Composite; |
37 |
import org.eclipse.swt.widgets.Control; |
38 |
import org.eclipse.swt.widgets.Label; |
39 |
import org.eclipse.swt.widgets.Text; |
40 |
|
41 |
|
42 |
|
43 |
|
44 |
/** |
45 |
* Second page of the New Filter wizard that prompts for the name of the filter. |
46 |
*/ |
47 |
public class SystemNewFilterWizardNamePage |
48 |
extends AbstractSystemWizardPage |
49 |
implements SelectionListener |
50 |
{ |
51 |
|
52 |
protected Text nameText; |
53 |
protected Button uniqueCB; |
54 |
protected Label poolVerbiage; |
55 |
protected Label poolComboLabel; |
56 |
protected Combo poolWrapperCombo; |
57 |
protected Combo poolCombo; |
58 |
protected SystemMessage errorMessage; |
59 |
protected String inputFilterName; |
60 |
protected boolean contentsCreated; |
61 |
protected boolean userEditedName; |
62 |
protected boolean ignoreChanges; |
63 |
protected ISystemValidator nameValidator; |
64 |
protected ISystemValidator[] nameValidators; |
65 |
protected ISystemFilterPoolSelectionValidator filterPoolSelectionValidator; |
66 |
protected ISystemFilterPool[] poolsToSelectFrom = null; |
67 |
protected ISystemFilterPoolWrapper[] poolWrappers = null; |
68 |
protected ISystemFilterPoolWrapperInformation poolWrapperInformation; |
69 |
protected ISystemFilterPool parentPool = null; |
70 |
private ISystemNewFilterWizardConfigurator configurator; |
71 |
|
72 |
/** |
73 |
* Constructor. |
74 |
*/ |
75 |
public SystemNewFilterWizardNamePage(SystemNewFilterWizard wizard, ISystemFilterPool parentPool, ISystemNewFilterWizardConfigurator data) |
76 |
{ |
77 |
super(wizard, "SetNewFilterName", data.getPage2Title(), data.getPage2Description()); //$NON-NLS-1$ |
78 |
this.parentPool = parentPool; |
79 |
this.configurator = data; |
80 |
setHelp(data.getPage2HelpID()); |
81 |
} |
82 |
|
83 |
// --------------------------------- |
84 |
// INPUT METHODS... |
85 |
// --------------------------------- |
86 |
/** |
87 |
* Set the filter name to default the entry field to |
88 |
*/ |
89 |
public void setFilterName(String filterName) |
90 |
{ |
91 |
this.inputFilterName = filterName; |
92 |
if (nameText != null) |
93 |
nameText.setText(inputFilterName); |
94 |
} |
95 |
/** |
96 |
* Set the validator to use to verify the filter name is correct |
97 |
*/ |
98 |
public void setFilterNameValidator(ISystemValidator nameValidator) |
99 |
{ |
100 |
this.nameValidator = nameValidator; |
101 |
} |
102 |
/** |
103 |
* Call if you want to allow the user to select the filter pool to create this filter in. |
104 |
*/ |
105 |
public void setAllowFilterPoolSelection(ISystemFilterPool[] poolsToSelectFrom, |
106 |
ISystemValidator[] nameValidators) |
107 |
{ |
108 |
this.poolsToSelectFrom = poolsToSelectFrom; |
109 |
this.nameValidators = nameValidators; |
110 |
if ((poolsToSelectFrom != null) && (poolsToSelectFrom.length>0)) |
111 |
{ |
112 |
if (parentPool == null) |
113 |
parentPool = poolsToSelectFrom[0]; |
114 |
} |
115 |
} |
116 |
/** |
117 |
* This is an alternative to {@link #setAllowFilterPoolSelection(ISystemFilterPool[], ISystemValidator[])} |
118 |
* <p> |
119 |
* If you want to prompt the user for the parent filter pool to create this filter in, |
120 |
* but want to not use the term "pool" say, you can use an array of euphamisms. That is, |
121 |
* you can pass an array of objects that map to filter pools, but have a different |
122 |
* display name that is shown in the dropdown. |
123 |
* <p> |
124 |
* Of course, if you want to do this, then you will likely want to offer a different |
125 |
* label and tooltip for the prompt, and different verbiage above the prompt. The |
126 |
* object this method accepts as a parameter encapsulates all that information, and |
127 |
* there is a default class you can use for this. |
128 |
*/ |
129 |
public void setAllowFilterPoolSelection(ISystemFilterPoolWrapperInformation poolWrappersToSelectFrom, |
130 |
ISystemValidator[] nameValidators) |
131 |
{ |
132 |
this.poolWrapperInformation = poolWrappersToSelectFrom; |
133 |
this.nameValidators = nameValidators; |
134 |
if (parentPool == null) |
135 |
parentPool = poolWrappersToSelectFrom.getPreSelectWrapper().getSystemFilterPool(); |
136 |
} |
137 |
/** |
138 |
* Set the validator to call when the user selects a filter pool. Optional. |
139 |
*/ |
140 |
public void setFilterPoolSelectionValidator(ISystemFilterPoolSelectionValidator validator) |
141 |
{ |
142 |
filterPoolSelectionValidator = validator; |
143 |
//System.out.println("Inside setFilterPoolSelectionValidator. Non null? " + (validator != null)); |
144 |
} |
145 |
|
146 |
// --------------------------------- |
147 |
// LIFECYCLE METHODS... |
148 |
// --------------------------------- |
149 |
|
150 |
/** |
151 |
* Populate the dialog area with our widgets. Return the composite they are in. |
152 |
*/ |
153 |
public Control createContents(Composite parent) |
154 |
{ |
155 |
|
156 |
int nbrColumns = 2; |
157 |
Composite composite_prompts = SystemWidgetHelpers.createComposite(parent, nbrColumns); |
158 |
|
159 |
SystemWidgetHelpers.createVerbiage(composite_prompts, configurator.getPage2NameVerbiage(), nbrColumns, false, 200); |
160 |
nameText = SystemWidgetHelpers.createLabeledTextField(composite_prompts, null, configurator.getPage2NamePromptLabel(), configurator.getPage2NamePromptTooltip()); |
161 |
|
162 |
addSeparatorLine(composite_prompts, nbrColumns); |
163 |
addFillerLine(composite_prompts, nbrColumns); |
164 |
|
165 |
// allow the user to create this filter uniquely for this connection, which means putting it in a |
166 |
// special filter pool we will create, just for this connection. This option is not shown if we are |
167 |
// already told which filter pool to create the filter in, such as in Show Filter Pools mode, when |
168 |
// the user selects New Filter to create a filter in the selected pool. We assume in this case the |
169 |
// will go in whatever filter is selected. |
170 |
if ((poolsToSelectFrom!=null) || (poolWrapperInformation!=null)) |
171 |
{ |
172 |
uniqueCB = SystemWidgetHelpers.createCheckBox(composite_prompts, nbrColumns, configurator.getPage2UniqueToConnectionLabel(), null); |
173 |
uniqueCB.setToolTipText(configurator.getPage2UniqueToConnectionToolTip()); |
174 |
uniqueCB.addSelectionListener(this); |
175 |
uniqueCB.setSelection(true); // [160403] filters should be connection private by default |
176 |
} |
177 |
|
178 |
addFillerLine(composite_prompts, nbrColumns); |
179 |
|
180 |
if (poolsToSelectFrom != null) |
181 |
{ |
182 |
poolVerbiage = SystemWidgetHelpers.createVerbiage(composite_prompts, configurator.getPage2PoolVerbiage(), nbrColumns, false, 200); |
183 |
poolVerbiage.setToolTipText(configurator.getPage2PoolVerbiageTip()); |
184 |
poolCombo = SystemWidgetHelpers.createLabeledReadonlyCombo(composite_prompts, null, configurator.getPage2PoolPromptLabel(), configurator.getPage2PoolPromptTooltip()); |
185 |
poolComboLabel = SystemWidgetHelpers.getLastLabel(); |
186 |
String[] poolNames = new String[poolsToSelectFrom.length]; |
187 |
int filterPoolSelectionIndex = 0; |
188 |
for (int idx=0; idx<poolNames.length; idx++) |
189 |
{ |
190 |
ISystemFilterPool pool = poolsToSelectFrom[idx]; |
191 |
if (pool == parentPool) |
192 |
filterPoolSelectionIndex = idx; |
193 |
poolNames[idx] = pool.getSystemFilterPoolManager().getName()+"."+pool.getName(); //$NON-NLS-1$ |
194 |
} |
195 |
if ((nameValidator == null) && (nameValidators!=null)) |
196 |
nameValidator = nameValidators[filterPoolSelectionIndex]; |
197 |
poolCombo.setItems(poolNames); |
198 |
poolCombo.select(filterPoolSelectionIndex); |
199 |
poolCombo.addSelectionListener(this); |
200 |
if ((uniqueCB!=null) && uniqueCB.getSelection()) |
201 |
{ |
202 |
poolVerbiage.setEnabled(false); |
203 |
poolComboLabel.setEnabled(false); |
204 |
poolCombo.setEnabled(false); |
205 |
} |
206 |
} |
207 |
else if (poolWrapperInformation != null) |
208 |
{ |
209 |
poolVerbiage = SystemWidgetHelpers.createVerbiage(composite_prompts, poolWrapperInformation.getVerbiageLabel(), nbrColumns, false, 200); |
210 |
//poolWrapperCombo = SystemWidgetHelpers.createLabeledCombo(composite_prompts, null, poolWrapperInformation.getResourceBundle(), poolWrapperInformation.getPromptRBKey()); // d47323 |
211 |
poolWrapperCombo = SystemWidgetHelpers.createLabeledReadonlyCombo(composite_prompts, null, poolWrapperInformation.getPromptLabel(), poolWrapperInformation.getPromptTooltip()); |
212 |
poolComboLabel = SystemWidgetHelpers.getLastLabel(); |
213 |
poolWrappers = poolWrapperInformation.getWrappers(); |
214 |
String[] poolNames = new String[poolWrappers.length]; |
215 |
int filterPoolSelectionIndex = 0; |
216 |
for (int idx=0; idx<poolNames.length; idx++) |
217 |
{ |
218 |
if (poolWrapperInformation.getPreSelectWrapper() == poolWrappers[idx]) |
219 |
filterPoolSelectionIndex = idx; |
220 |
poolNames[idx] = poolWrappers[idx].getDisplayName(); |
221 |
} |
222 |
if ((nameValidator == null) && (nameValidators!=null)) |
223 |
nameValidator = nameValidators[filterPoolSelectionIndex]; |
224 |
poolWrapperCombo.setItems(poolNames); |
225 |
poolWrapperCombo.select(filterPoolSelectionIndex); |
226 |
poolWrapperCombo.addSelectionListener(this); |
227 |
if ((uniqueCB!=null) && uniqueCB.getSelection()) |
228 |
{ |
229 |
poolVerbiage.setEnabled(false); |
230 |
poolComboLabel.setEnabled(false); |
231 |
poolWrapperCombo.setEnabled(false); |
232 |
} |
233 |
} |
234 |
|
235 |
// initialize inputs |
236 |
if (nameValidator != null) |
237 |
{ |
238 |
int maxNameLength = nameValidator.getMaximumNameLength(); |
239 |
if (maxNameLength >= 0) |
240 |
nameText.setTextLimit(maxNameLength); |
241 |
} |
242 |
if (inputFilterName != null) |
243 |
nameText.setText(inputFilterName); |
244 |
|
245 |
// add keystroke listeners... |
246 |
nameText.addModifyListener( |
247 |
new ModifyListener() { |
248 |
public void modifyText(ModifyEvent e) { |
249 |
if (ignoreChanges) |
250 |
return; |
251 |
userEditedName = true; |
252 |
validateNameInput(); |
253 |
} |
254 |
} |
255 |
); |
256 |
|
257 |
setPageComplete(); |
258 |
contentsCreated = true; |
259 |
return composite_prompts; |
260 |
} |
261 |
/** |
262 |
* Return the Control to be given initial focus. |
263 |
* Override from parent. Return control to be given initial focus. |
264 |
*/ |
265 |
protected Control getInitialFocusControl() |
266 |
{ |
267 |
return nameText; |
268 |
} |
269 |
|
270 |
/** |
271 |
* Completes processing of the wizard. If this |
272 |
* method returns true, the wizard will close; |
273 |
* otherwise, it will stay active. |
274 |
* This method is an override from the parent Wizard class. |
275 |
* |
276 |
* @return whether the wizard finished successfully |
277 |
*/ |
278 |
public boolean performFinish() |
279 |
{ |
280 |
if (!contentsCreated) |
281 |
return true; |
282 |
return (verify() == null); |
283 |
} |
284 |
|
285 |
/** |
286 |
* Return true if the page is complete, so to enable Finish. |
287 |
* Called by wizard framework. |
288 |
*/ |
289 |
public boolean isPageComplete() |
290 |
{ |
291 |
boolean pageComplete = (errorMessage == null) && (nameText!=null); |
292 |
if (pageComplete) |
293 |
pageComplete = (nameText.getText().trim().length() > 0); |
294 |
return pageComplete; |
295 |
} |
296 |
|
297 |
/** |
298 |
* Inform caller of page-complete status of this page |
299 |
*/ |
300 |
public void setPageComplete() |
301 |
{ |
302 |
setPageComplete(isPageComplete()); |
303 |
} |
304 |
/** |
305 |
* User has selected something |
306 |
*/ |
307 |
public void widgetSelected(SelectionEvent e) |
308 |
{ |
309 |
Object src = e.getSource(); |
310 |
if (src == poolCombo) |
311 |
{ |
312 |
int selection = poolCombo.getSelectionIndex(); |
313 |
if ((selection >= 0) && (nameValidators!=null)) |
314 |
nameValidator = nameValidators[selection]; |
315 |
} |
316 |
else if (src == poolWrapperCombo) |
317 |
{ |
318 |
int selection = poolWrapperCombo.getSelectionIndex(); |
319 |
if ((selection >= 0) && (nameValidators!=null)) |
320 |
nameValidator = nameValidators[selection]; |
321 |
} |
322 |
else if (src == uniqueCB) |
323 |
{ |
324 |
boolean selected = uniqueCB.getSelection(); |
325 |
if (poolVerbiage != null) |
326 |
poolVerbiage.setEnabled(!selected); |
327 |
if (poolCombo != null) |
328 |
poolCombo.setEnabled(!selected); |
329 |
if (poolWrapperCombo != null) |
330 |
poolWrapperCombo.setEnabled(!selected); |
331 |
if (poolComboLabel != null) |
332 |
poolComboLabel.setEnabled(!selected); |
333 |
} |
334 |
verify(); |
335 |
setPageComplete(); |
336 |
} |
337 |
/** |
338 |
* User has selected something and pressed Enter |
339 |
*/ |
340 |
public void widgetDefaultSelected(SelectionEvent e) |
341 |
{ |
342 |
} |
343 |
// --------------------------------- |
344 |
// VERIFICATION METHODS... |
345 |
// --------------------------------- |
346 |
/** |
347 |
* Verify all contents |
348 |
*/ |
349 |
public SystemMessage verify() |
350 |
{ |
351 |
errorMessage = null; |
352 |
Control controlInError = null; |
353 |
|
354 |
if ((errorMessage == null) && (filterPoolSelectionValidator != null)) |
355 |
{ |
356 |
errorMessage = filterPoolSelectionValidator.validate(getParentSystemFilterPool()); |
357 |
if (poolCombo != null) |
358 |
controlInError = poolCombo; |
359 |
else if (poolWrapperCombo != null) |
360 |
controlInError = poolCombo; |
361 |
} |
362 |
if ((errorMessage == null) && (nameValidator != null)) |
363 |
{ |
364 |
errorMessage = nameValidator.validate(nameText.getText().trim()); |
365 |
controlInError = nameText; |
366 |
} |
367 |
|
368 |
if (errorMessage != null) |
369 |
{ |
370 |
if (controlInError != null) |
371 |
controlInError.setFocus(); |
372 |
setErrorMessage(errorMessage); |
373 |
} |
374 |
else |
375 |
clearErrorMessage(); |
376 |
return errorMessage; |
377 |
} |
378 |
/** |
379 |
* This hook method is called whenever the text changes in the filter name input field. |
380 |
*/ |
381 |
protected SystemMessage validateNameInput() |
382 |
{ |
383 |
errorMessage= null; |
384 |
if (nameValidator != null) |
385 |
errorMessage = nameValidator.validate(nameText.getText().trim()); |
386 |
if ((errorMessage == null) && (filterPoolSelectionValidator != null)) |
387 |
errorMessage = filterPoolSelectionValidator.validate(getParentSystemFilterPool()); |
388 |
setPageComplete(); |
389 |
if (errorMessage != null) |
390 |
setErrorMessage(errorMessage); |
391 |
else |
392 |
clearErrorMessage(); |
393 |
return errorMessage; |
394 |
} |
395 |
|
396 |
|
397 |
// --------------------------------- |
398 |
// METHODS FOR EXTRACTING USER DATA |
399 |
// --------------------------------- |
400 |
/** |
401 |
* Return name of filter |
402 |
* Call this after finish ends successfully. |
403 |
*/ |
404 |
public String getFilterName() |
405 |
{ |
406 |
if (nameText != null) |
407 |
return nameText.getText().trim(); |
408 |
else |
409 |
return inputFilterName; |
410 |
} |
411 |
/** |
412 |
* Return the filter pool that was explicitly chosen by the user, |
413 |
* or implicitly set by the caller. |
414 |
*/ |
415 |
public ISystemFilterPool getParentSystemFilterPool() |
416 |
{ |
417 |
ISystemFilterPool pool = null; |
418 |
// do we prompt with a list of filter pools? Yes, just return selected... |
419 |
if (poolCombo != null) |
420 |
{ |
421 |
int selection = poolCombo.getSelectionIndex(); |
422 |
if (selection < 0) |
423 |
selection = 0; |
424 |
pool = poolsToSelectFrom[selection]; |
425 |
} |
426 |
// do we prompt using a wrapper of some kind, such a profile or a command set, |
427 |
// from which we deduce the pool? If so, deduce pool from selected wrapper.... |
428 |
else if (poolWrapperCombo != null) |
429 |
{ |
430 |
int selection = poolWrapperCombo.getSelectionIndex(); |
431 |
if (selection < 0) |
432 |
selection = 0; |
433 |
pool = poolWrappers[selection].getSystemFilterPool(); |
434 |
} |
435 |
// else no prompt so we must have been given the explicit filter pool in which |
436 |
// to create this filter. Eg, in Show Filter Pools mode and the user selects a |
437 |
// filter pool and choose New Filter from it. |
438 |
else |
439 |
pool = parentPool; |
440 |
//System.out.println("Inside getParentSystemFilterPool. returning " + pool.getName()); |
441 |
return pool; |
442 |
} |
443 |
|
444 |
/** |
445 |
* Return the user's decision whether to create this filter uniquely |
446 |
* for this connection, or for all applicable connections. |
447 |
*/ |
448 |
public boolean getUniqueToThisConnection() |
449 |
{ |
450 |
if (uniqueCB != null) |
451 |
return uniqueCB.getSelection(); |
452 |
else |
453 |
return false; |
454 |
} |
455 |
|
456 |
// ------------------------------- |
457 |
// INTERCEPT OF WIZARDPAGE METHODS |
458 |
// ------------------------------- |
459 |
/** |
460 |
* This is called when a page is given focus or loses focus |
461 |
*/ |
462 |
public void setVisible(boolean visible) |
463 |
{ |
464 |
super.setVisible(visible); |
465 |
if (visible) |
466 |
{ |
467 |
if (!userEditedName && (nameText!=null)) |
468 |
{ |
469 |
String defaultName = ((SystemNewFilterWizard)getWizard()).getDefaultFilterName(); |
470 |
if (defaultName != null) |
471 |
{ |
472 |
ignoreChanges = true; |
473 |
nameText.setText(defaultName); |
474 |
ignoreChanges = false; |
475 |
} |
476 |
} |
477 |
verify(); |
478 |
//System.out.println("Wizard size = " + ((SystemNewFilterWizard)getWizard()).getShell().getSize()); |
479 |
} |
480 |
} |
481 |
|
482 |
// -------------------------------------------------------------- |
483 |
// ALL THE MRI ON THIS PAGE IS CONFIGURABLE. CALL HERE TO SET IT. |
484 |
// -------------------------------------------------------------- |
485 |
|
486 |
} |