Skip to main content
summaryrefslogtreecommitdiffstats
blob: 193731f85e64e654c515b18140acd6cb1fd93516 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*******************************************************************************
 * Copyright (c) 2006, 2008 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 * IBM Corporation - initial API and implementation
 * yyyymmdd bug      Email and other contact information
 * -------- -------- -----------------------------------------------------------
 * yyyymmdd   bug     Email and other contact information
 * 20060329   127016 andyzhai@ca.ibm.com - Andy Zhai    
 * 20080428   224726 pmoogk@ca.ibm.com - Peter Moogk
 *******************************************************************************/
package org.eclipse.jst.ws.internal.axis.consumption.ui.preferences;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jst.ws.internal.axis.consumption.core.context.AxisEmitterContext;
import org.eclipse.jst.ws.internal.axis.consumption.core.context.AxisEmitterDefaults;
import org.eclipse.jst.ws.internal.axis.consumption.core.plugin.WebServiceAxisConsumptionCorePlugin;
import org.eclipse.jst.ws.internal.axis.consumption.ui.AxisConsumptionUIMessages;
import org.eclipse.jst.ws.internal.axis.consumption.ui.plugin.WebServiceAxisConsumptionUIPlugin;
import org.eclipse.jst.ws.internal.ui.common.UIUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.help.IWorkbenchHelpSystem;



public class AxisEmitterPreferencePage extends PreferencePage implements IWorkbenchPreferencePage
{
  /*CONTEXT_ID PPAE0001 for the Axis Emitter Preference Page*/
  private String INFOPOP_PPAE_PAGE = WebServiceAxisConsumptionUIPlugin.ID + ".PPAE0001";
  //
  private Button allWanted;
  /*CONTEXT_ID PPAE0002 for the all wanted check box on the Axis Emitter Preference Page*/
  private String INFOPOP_PPAE_CHECKBOX_ALL_WANTED = "PPAE0002";
  //
  private Button helperWanted;
  /*CONTEXT_ID PPAE0003 for helper wanted check box on the Axis Emitter Preference Page*/
  private String INFOPOP_PPAE_CHECKBOX_HELPER_WANTED = "PPAE0003";
  //
  private Button wrapArrays;
  /*CONTEXT_ID PPAE0004 for the wrap arrays check box on the Axis Emitter Preference Page*/
  private String INFOPOP_PPAE_CHECKBOX_WRAP_ARRAYS = "PPAE0004";

  private Combo deployScopeTypes;
  //*CONTEXT_ID PPAE0005 for the deploy scope type combo box on the Axis Emitter page*/
  private String INFOPOP_PPAE_COMBO_DEPLOY_SCOPE = "PPAE0005";
  
  private StackLayout timeOutSubCompositeStackLayout;
  
  private Text timeOutField;
  int timeOut;
  String wsdl2JavaTimeoutProperty = System.getProperty("AxisWsdl2JavaTimeout");
  
  private Text timeOutMsgText;
  /*CONTEXT_ID PPAE0006 for the time out field on the Axis Emitter Preference page*/
  private String INFOPOP_PPAE_FIELD_TIME_OUT = "PPAE0006";

  private Button useInheritedMethods;
  /*CONTEXT_ID PPAE0007 for the use inherited methods check box on the Axis Emitter Preference page*/
  private String INFOPOP_PPAE_CHECKBOX_USE_INHERITED_METHODS = "PPAE0007";

  private Button validateAgainstJAXRPC;
  /*CONTEXT_ID PPAE0010 for the "validate against JAXRPC..." check box on the Axis Emitter Preference page*/
  private String INFOPOP_PPAE_CHECKBOX_VALIDATE_AGAINST_JAXRPC = "PPAE0010";
  
  /*CONTEXT_ID PPAE0008 for the wsdl2java group on the Axis Emitter Preference page*/
  private String INFOPOP_PPAE_GROUP_WSDL2JAVA = "PPAE0008";
  /*CONTEXT_ID PPAE0009 for the java2wsdl group on the Axis Emitter Preference page*/
  private String INFOPOP_PPAE_GROUP_JAVA2WSDL = "PPAE0009";
/**
   * Creates preference page controls on demand.
   *   @param parent  the parent for the preference page
   */
  protected Control createContents(Composite superparent)
  {
	UIUtils utils = new UIUtils( WebServiceAxisConsumptionUIPlugin.ID );
  	IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem();
  	
    Composite   parent = new Composite( superparent, SWT.NONE );	
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    parent.setLayout( layout );
    parent.setToolTipText(AxisConsumptionUIMessages.TOOLTIP_PPAE_PAGE);
    helpSystem.setHelp(parent, INFOPOP_PPAE_PAGE);
    Group wsdl2JavaGroup = utils.createGroup(parent, AxisConsumptionUIMessages.GROUP_WSDL2JAVA_NAME, AxisConsumptionUIMessages.TOOLTIP_PPAE_GROUP_WSDL2JAVA, INFOPOP_PPAE_GROUP_WSDL2JAVA, 2, 10,10);
    allWanted = createCheckBox(wsdl2JavaGroup, AxisConsumptionUIMessages.BUTTON_ALL_WANTED,AxisConsumptionUIMessages.TOOLTIP_PPAE_CHECKBOX_ALL_WANTED,INFOPOP_PPAE_CHECKBOX_ALL_WANTED);

    helperWanted  = createCheckBox(wsdl2JavaGroup, AxisConsumptionUIMessages.BUTTON_HELPER_WANTED,AxisConsumptionUIMessages.TOOLTIP_PPAE_CHECKBOX_HELPER_WANTED,INFOPOP_PPAE_CHECKBOX_HELPER_WANTED);

    wrapArrays = createCheckBox(wsdl2JavaGroup, AxisConsumptionUIMessages.BUTTON_WRAP_ARRAYS,AxisConsumptionUIMessages.TOOLTIP_PPAE_CHECKBOX_WRAP_ARRAYS,INFOPOP_PPAE_CHECKBOX_WRAP_ARRAYS);    
    
    deployScopeTypes = utils.createCombo(wsdl2JavaGroup, AxisConsumptionUIMessages.LABEL_DEPLOY_SCOPE, AxisConsumptionUIMessages.TOOLTIP_PPAE_COMBO_DEPLOY_SCOPE, INFOPOP_PPAE_COMBO_DEPLOY_SCOPE, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
    /* 
     * Ensure the order is the same as it in the fields for class
     * org.eclipse.jst.ws.internal.axis.consumption.core.context.AxisEmitterContext
     */
    deployScopeTypes.setItems(new String []{AxisConsumptionUIMessages.DEPLOY_SCOPE_APPLICATION, AxisConsumptionUIMessages.DEPLOY_SCOPE_REQUEST,AxisConsumptionUIMessages.DEPLOY_SCOPE_SESSION});
    
    Label timeoutLabel = new Label(wsdl2JavaGroup, SWT.WRAP);
    timeoutLabel.setText(AxisConsumptionUIMessages.LABEL_TIME_OUT);
    timeoutLabel.setToolTipText(AxisConsumptionUIMessages.TOOLTIP_PPAE_FIELD_TIME_OUT);
    
    Composite timeOutSubComposite = utils.createComposite(wsdl2JavaGroup, 1);
    timeOutSubCompositeStackLayout = new StackLayout();
    timeOutSubComposite.setLayout(timeOutSubCompositeStackLayout);
    
    // only one of this is displayed at one time, they share infopop and tooltip text
    timeOutField = createTextField(timeOutSubComposite, null ,AxisConsumptionUIMessages.TOOLTIP_PPAE_FIELD_TIME_OUT,INFOPOP_PPAE_FIELD_TIME_OUT);
    timeOutMsgText = createTextField(timeOutSubComposite, null ,AxisConsumptionUIMessages.TOOLTIP_PPAE_FIELD_TIME_OUT,INFOPOP_PPAE_FIELD_TIME_OUT);
    
    timeOutMsgText.setEditable(false);
    
    Group java2WsdlGroup = utils.createGroup(parent, AxisConsumptionUIMessages.GROUP_JAVA2WSDL_NAME, AxisConsumptionUIMessages.TOOLTIP_PPAE_GROUP_JAVA2WSDL, INFOPOP_PPAE_GROUP_JAVA2WSDL, 2, 10,10);
    useInheritedMethods = createCheckBox(java2WsdlGroup, AxisConsumptionUIMessages.BUTTON_USE_INHERITED_METHODS,AxisConsumptionUIMessages.TOOLTIP_PPAE_CHECKBOX_USE_INHERITED_METHODS,INFOPOP_PPAE_CHECKBOX_USE_INHERITED_METHODS);
    validateAgainstJAXRPC = createCheckBox(java2WsdlGroup, AxisConsumptionUIMessages.BUTTON_VALIDATE_AGAINST_JAXRPC,AxisConsumptionUIMessages.TOOLTIP_PPAE_CHECKBOX_VALIDATE_AGAINST_JAXRPC,INFOPOP_PPAE_CHECKBOX_VALIDATE_AGAINST_JAXRPC);

    initializeValues();
    org.eclipse.jface.dialogs.Dialog.applyDialogFont(superparent);    

    return parent;
  }
  
  /**
   * Creates checkbox with horizontalSpan = 2 in its grid data in order to
   * match the grid layout for combo 
   */
  private Button createCheckBox( Composite parent, String labelName, String tooltip, String infopop )
  {
    Button button = new Button( parent, SWT.CHECK );
    button.setText(labelName);
    button.setToolTipText( tooltip );
    if( infopop != null ) PlatformUI.getWorkbench().getHelpSystem().setHelp( button, WebServiceAxisConsumptionUIPlugin.ID + "." + infopop );
	GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
	gd.horizontalSpan= 2;
	button.setLayoutData(gd);	
    return button;
  }
     
  private Text createTextField(Composite parent,String labelName, String tooltip, String infopop) 
  { tooltip = tooltip == null ? labelName : tooltip;
	if( labelName != null )
    {
      Label label = new Label( parent, SWT.WRAP);
      label.setText( labelName );
      label.setToolTipText( tooltip );
    }
     Text text = new Text(parent, SWT.SINGLE | SWT.BORDER);
     GridData data = new GridData();
     data.verticalAlignment = GridData.FILL;
     data.horizontalAlignment = GridData.FILL;
     data.grabExcessHorizontalSpace = true;
     text.setLayoutData(data);
     text.setToolTipText(tooltip);
     if( infopop != null ) PlatformUI.getWorkbench().getHelpSystem().setHelp( text, WebServiceAxisConsumptionUIPlugin.ID + "." + infopop );
     
     text.addModifyListener( new ModifyListener() {
		public void modifyText(ModifyEvent e) {
			numberFieldChanged((Text) e.widget);
		}
	 }
     );
     return text;
  }

  /**
   * Does anything necessary because the default button has been pressed.
   */
  protected void performDefaults()
  {
    super.performDefaults();
    initializeDefaults();
  }

  /**
   * Do anything necessary because the OK button has been pressed.
   *  @return whether it is okay to close the preference page
   */
  public boolean performOk()
  {
    if(validateNumber(timeOutField.getText()).isOK())
    	storeValues();
    return true;
  }

  protected void performApply()
  {
    performOk();
  }

  /**
   * @see IWorkbenchPreferencePage
   */
  public void init(IWorkbench workbench)  { }

  /**
   * Initializes states of the controls using default values
   * in the preference store.
   */
  private void initializeDefaults()
  {
    allWanted.setSelection( AxisEmitterDefaults.getAllWantedDefault());
    helperWanted.setSelection( AxisEmitterDefaults.getHelperWantedDefault());
    wrapArrays.setSelection( AxisEmitterDefaults.getWrapArraysDefault());
    deployScopeTypes.select(AxisEmitterDefaults.getDeployScopeDefault());
    if (wsdl2JavaTimeoutProperty != null) timeOutField.setText(""+ getTimeOutValueWithProperty());
    else timeOutField.setText("" + AxisEmitterDefaults.getTimeOutDefault());	
    useInheritedMethods.setSelection(AxisEmitterDefaults.getUseInheritedMethodsDefault());
    validateAgainstJAXRPC.setSelection(AxisEmitterDefaults.getValidateAgainstJAXRPC());
  }

  /**
   * Initializes states of the controls from the preference store.
   */
  private void initializeValues()
  {
    // get the persistent context from the plugin
    AxisEmitterContext context = WebServiceAxisConsumptionCorePlugin.getInstance().getAxisEmitterContext();
    allWanted.setSelection( context.isAllWantedEnabled());
    helperWanted.setSelection( context.isHelperWantedEnabled());
    wrapArrays.setSelection( context.isWrapArraysEnabled());
    deployScopeTypes.select(context.getDeployScopeType());
    useInheritedMethods.setSelection( context.isUseInheritedMethodsEnabled());
    validateAgainstJAXRPC.setSelection( context.isValidateAgainstJAXRPCEnabled() );
    if (wsdl2JavaTimeoutProperty != null) 
    {	timeOut=getTimeOutValueWithProperty();
    	//timeOutField.setEnabled(false);
    	timeOutSubCompositeStackLayout.topControl = timeOutMsgText;
        timeOutMsgText.setText(AxisConsumptionUIMessages.MSG_USE_JVM_ARGUMENT_FOR_TIME_OUT);		
    }
	else
	{
	    timeOut = context.getTimeOut();
	    timeOutSubCompositeStackLayout.topControl = timeOutField;
	}
    timeOutField.setText(""+ timeOut);
   }

  /**
   * Stores the values of the controls back to the preference store.
   */
  private void storeValues()
  {
    // get the persistent context from the plugin
    AxisEmitterContext context = WebServiceAxisConsumptionCorePlugin.getInstance().getAxisEmitterContext();
    context.setAllWantedEnabled( allWanted.getSelection() );
    context.setHelperWantedEnabled( helperWanted.getSelection() );
    context.setWrapArraysEnabled( wrapArrays.getSelection() );
    context.selectDeployScopeType(deployScopeTypes.getSelectionIndex());
    timeOut = Integer.parseInt(timeOutField.getText().trim());
    context.setTimeOut(timeOut);
    context.setUseInheritedMethodsEnabled( useInheritedMethods.getSelection() );
    context.setValidateAgainstJAXRPCEnabled( validateAgainstJAXRPC.getSelection() );
  }
  
  private void numberFieldChanged(Text textControl) {
		IStatus status = validateNumber(textControl.getText());
		setValid(!status.matches(IStatus.ERROR));
		applyToStatusLine(this,status);	
 }
  
  private int getTimeOutValueWithProperty() 
  {
	  if (wsdl2JavaTimeoutProperty != null)
	  {	try {
		  long timeOutProperty = Long.parseLong(wsdl2JavaTimeoutProperty);
		  if (timeOutProperty < 0) return -1; // timeout = -1 equals never time out; treating all negative number as -1
		  else return (int)Math.ceil(timeOutProperty/1000.0);
	    } catch (NumberFormatException e){
	      System.err.print("AxisWSDL2JavaTimeout is not a valid number");
	      return AxisEmitterDefaults.getTimeOutDefault();
	    }
	  }
	  else return AxisEmitterDefaults.getTimeOutDefault();
  }
  
  private IStatus validateNumber(String numberString)
  {
	    IStatus status;
		try 
		{
			int number = Integer.parseInt(numberString);
			if (number <= 0 && number != -1)
			{
				status = new Status(IStatus.ERROR, WebServiceAxisConsumptionUIPlugin.ID, IStatus.ERROR,
						AxisConsumptionUIMessages.MSG_ERROR_INVALID_TIME_OUT, null);
			}
			else
			{	timeOut = number;
				status = Status.OK_STATUS;
				//we set param:message="" here, Later in 
				//applyToStatusLine(), we do page.setMessage(null,type) 
				status = new Status(IStatus.OK, WebServiceAxisConsumptionUIPlugin.ID, IStatus.OK, "",null);
			}
		} 
		catch 
		(NumberFormatException e) 
		{
			status = new Status(IStatus.ERROR, WebServiceAxisConsumptionUIPlugin.ID, IStatus.ERROR,
					AxisConsumptionUIMessages.MSG_ERROR_INVALID_TIME_OUT, null);
		}
		return status; 
  	}
  
	private void applyToStatusLine(DialogPage page, IStatus status) {
		String message= status.getMessage();
		switch (status.getSeverity()) {
			case IStatus.OK:
				page.setMessage(null, IMessageProvider.NONE);
				page.setErrorMessage(null);
				break;
			case IStatus.WARNING:
				page.setMessage(message, IMessageProvider.WARNING);
				page.setErrorMessage(null);
				break;				
			case IStatus.INFO:
				page.setMessage(message, IMessageProvider.INFORMATION);
				page.setErrorMessage(null);
				break;			
			default:
				if (message.length() == 0) {
					message= null;
				}
				page.setMessage(null);
				page.setErrorMessage(message);
				break;		
		}
	}
}

Back to the top