Skip to main content
summaryrefslogtreecommitdiffstats
blob: cf008154606bb36ddffb08d333a3f3d3953add79 (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
/*******************************************************************************
 * Copyright (c) 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
/*
 * Created on May 12, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.eclipse.jst.ws.internal.consumption.ui.widgets;

import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jdt.core.IType;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jst.ws.internal.consumption.ui.plugin.WebServiceConsumptionUIPlugin;
import org.eclipse.jst.ws.internal.ui.common.UIUtils;
import org.eclipse.jst.ws.internal.ui.dialog.DialogUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wst.command.internal.provisional.env.core.common.MessageUtils;



public class AddHandlerDialog extends Dialog implements Listener {

  private String pluginId_ = "org.eclipse.jst.ws.consumption.ui";
  private MessageUtils msgUtils_;
  private boolean validateOn_;
  private boolean isClient_;
  private String className;
  private String name;
  private String selectedPortName;
  
  private Text classNameText;
  private Text nameText;
  private Combo portNameCombo;
  
  // ----TOOLTIPS Section----
  /* CONTEXT_ID AHDL0001 for the Handler Config Page */
  private final String INFOPOP_TEXT_HANDLER_NAME  = "AHDL0001"; //$NON-NLS-1$
  private final String TOOLTIP_TEXT_HANDLER_NAME = "TOOLTIP_TEXT_HANDLER_NAME";
  
  /* CONTEXT_ID AHDL0002 for the Handler Config Page */
  private final String INFOPOP_TEXT_HANDLER_CLASS  = "AHDL0002"; //$NON-NLS-1$
  private final String TOOLTIP_TEXT_HANDLER_CLASS = "TOOLTIP_TEXT_HANDLER_CLASS";
  
  /* CONTEXT_ID AHDL0001 for the Handler Config Page */
  private final String INFOPOP_TEXT_HANDLER_PORT  = "AHDL0003"; //$NON-NLS-1$
  private final String TOOLTIP_TEXT_HANDLER_PORT = "TOOLTIP_TEXT_HANDLER_PORT";
    
  private Button beanClassBrowseButton_;
  /*CONTEXT_ID PBCL0003 for the Bean Class Browse button of the Bean Selection Page*/
  private String INFOPOP_PBCL_BUTTON_BEAN_CLASS_BROWSE = "PBCL0003";
  
  public AddHandlerDialog( Shell shell, boolean isClientHandler)
  {
    super(shell);
    isClient_ = isClientHandler;
  }

  protected Control createContents(Composite parent) {
    Composite comp = (Composite) super.createContents(parent);
    parent.getShell().pack();
    return comp;
  }

  protected Control createDialogArea(Composite parent) {
    validateOn_ = false;
    msgUtils_ = new MessageUtils(WebServiceConsumptionUIPlugin.ID + ".plugin", this);
    UIUtils uiUtils = new UIUtils(msgUtils_, pluginId_);
    
    Shell thisShell = parent.getShell();
    if (thisShell == null) {
      thisShell = createShell();
    }
    thisShell.setText(msgUtils_.getMessage("DIALOG_TITLE_WS_ADD_HANDLER"));
    
    Composite composite = (Composite) super.createDialogArea(parent);    
    
    Composite sourceLocationComp = uiUtils.createComposite(composite, 3);
    
    classNameText = uiUtils.createText(sourceLocationComp, "LABEL_TEXT_HANDLER_CLASS", TOOLTIP_TEXT_HANDLER_CLASS, INFOPOP_TEXT_HANDLER_CLASS, SWT.SINGLE | SWT.BORDER);
    classNameText.addListener(SWT.Modify,this);
    
    beanClassBrowseButton_ = uiUtils.createPushButton( sourceLocationComp, "BUTTON_BROWSE_CLASSES",
                                                       "TOOLTIP_PBCL_BUTTON_BEAN_CLASS_BROWSE",
                                                       INFOPOP_PBCL_BUTTON_BEAN_CLASS_BROWSE );
    beanClassBrowseButton_.addSelectionListener( new SelectionAdapter()
        {
          public void widgetSelected( SelectionEvent evt )
          {
            handleBrowseClasses();  
          }
        } );
    
    nameText = uiUtils.createText(sourceLocationComp, "LABEL_TEXT_HANDLER_NAME", TOOLTIP_TEXT_HANDLER_NAME, INFOPOP_TEXT_HANDLER_NAME, SWT.SINGLE | SWT.BORDER );
    nameText.addListener(SWT.Modify, this);
    
    // dummy label for column 3.
    new Label( sourceLocationComp, SWT.NONE );
    
    if (!isClient_){
      portNameCombo = uiUtils.createCombo(sourceLocationComp, "LABEL_TEXT_HANDLER_PORT", TOOLTIP_TEXT_HANDLER_PORT, INFOPOP_TEXT_HANDLER_PORT, SWT.SINGLE | SWT.BORDER );
      portNameCombo.addListener(SWT.Modify, this);
      
      // dummy label for column 3.
      new Label( sourceLocationComp, SWT.NONE );
    }
    validateOn_ = true;
   return composite;
  }
  
  private void handleBrowseClasses()
  {
    Shell shell = getShell();
    IType itype = DialogUtils.browseClassesAsIType(shell, ResourcesPlugin.getWorkspace().getRoot().getProjects(), new ProgressMonitorDialog(shell));
    
    if( itype != null )
    {
      classNameText.setText(itype.getFullyQualifiedName());      
    }
  }
  
  /* (non-Javadoc)
   * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
   */
  public void handleEvent(Event event) {
    if (!validateOn_)
      return;
    if (classNameText == event.widget) {
      handleClassNameTextEvent();
      validateTextFieldEntries();
      return;
    }
    if (nameText == event.widget) {
      handleNameTextEvent();
      validateTextFieldEntries();      
      return;
    }
    if (portNameCombo == event.widget) {
      handlePortNameTextEvent();
      validateTextFieldEntries();      
      return;
    }    
  }

  private void handleClassNameTextEvent(){
    className = classNameText.getText();
    if (className.lastIndexOf(".java") != -1){
      nameText.setText(className.substring(0, className.lastIndexOf(".java")));
    }
    else {
      nameText.setText(className);
    }
    
    if (className.lastIndexOf(".") != -1){
      nameText.setText(className.substring(className.lastIndexOf(".")+1, className.length()));
    }
    name = nameText.getText();
  }
  
  private void handleNameTextEvent() {
   name = nameText.getText(); 

  }
  
  private void handlePortNameTextEvent(){
    selectedPortName = portNameCombo.getText();
  }
  
  private void disableOKButton() {
    if (getButton(0) != null)
      getButton(0).setEnabled(false);
  }

  private void enableOKButton() {
    if (getButton(0) != null)
      getButton(0).setEnabled(true);
  }
  
  private void validateTextFieldEntries(){
  	if (classNameText.getText().equals("")){
  		disableOKButton();
  		return;
  	}
  	if (nameText.getText().equals("")){
  		disableOKButton();
  		return;
  	}
  	if (!isClient_){
  		if (portNameCombo.getText()!=null && portNameCombo.getText().equals("")){
  			disableOKButton();
  			return;
  		}
  		else if (portNameCombo.getText()==null) {
  			disableOKButton();
  			return;
  		}
  	}
  	
  	enableOKButton();
  	
	
  }
  
  /**
   * @return Returns the className.
   */
  public String getClassName() {
    if (className.lastIndexOf(".java") != -1){
      return className.substring(0, className.lastIndexOf(".java"));
    }
    else {
      return className;
    }
  }
  /**
   * @param className The className to set.
   */
  public void setClassName(String className) {
    this.className = className;
  }
  /**
   * @return Returns the name.
   */
  public String getName() {
    return name;
  }
  /**
   * @param name The name to set.
   */
  public void setName(String name) {
    this.name = name;
  }
  /**
   * @return Returns the portName.
   */
  public String getPortName() {
    return selectedPortName;
  }
  /**
   * @param portName The portName to set.
   */
  public void setPortNames(String[] portNames) {
    portNameCombo.setItems(portNames);
    portNameCombo.select(0);
  }
}

Back to the top