View | Details | Raw Unified | Return to bug 226948
Collapse All | Expand All

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

Return to bug 226948