|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2007 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 |
* Contributors: |
| 9 |
* Balan Subramanian (bsubram@us.ibm.com) |
| 10 |
* IBM Corporation - initial API and implementation |
| 11 |
*******************************************************************************/ |
| 12 |
|
| 13 |
package org.eclipse.tptp.wsdm.tooling.wizard.capability.internal; |
| 14 |
|
| 15 |
import javax.wsdl.Definition; |
| 16 |
import javax.wsdl.Operation; |
| 17 |
|
| 18 |
import org.eclipse.core.resources.IFile; |
| 19 |
import org.eclipse.core.resources.IWorkspaceRoot; |
| 20 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 21 |
import org.eclipse.core.runtime.Path; |
| 22 |
import org.eclipse.jface.dialogs.Dialog; |
| 23 |
import org.eclipse.jface.dialogs.MessageDialog; |
| 24 |
import org.eclipse.jface.viewers.ISelection; |
| 25 |
import org.eclipse.jface.window.Window; |
| 26 |
import org.eclipse.jface.wizard.IWizardPage; |
| 27 |
import org.eclipse.jface.wizard.WizardPage; |
| 28 |
import org.eclipse.swt.SWT; |
| 29 |
import org.eclipse.swt.events.ModifyEvent; |
| 30 |
import org.eclipse.swt.events.ModifyListener; |
| 31 |
import org.eclipse.swt.events.SelectionAdapter; |
| 32 |
import org.eclipse.swt.events.SelectionEvent; |
| 33 |
import org.eclipse.swt.layout.GridData; |
| 34 |
import org.eclipse.swt.layout.GridLayout; |
| 35 |
import org.eclipse.swt.widgets.Button; |
| 36 |
import org.eclipse.swt.widgets.Composite; |
| 37 |
import org.eclipse.swt.widgets.Text; |
| 38 |
import org.eclipse.tptp.wsdm.tooling.dialog.provisional.WSDLBrowseDialog; |
| 39 |
import org.eclipse.tptp.wsdm.tooling.dialog.provisional.XSDBrowseDialog; |
| 40 |
import org.eclipse.tptp.wsdm.tooling.editor.capability.imports.wsdl.OperationImportWizardPage; |
| 41 |
import org.eclipse.tptp.wsdm.tooling.editor.capability.imports.xsd.PropertyImportWizardPage; |
| 42 |
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition; |
| 43 |
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages; |
| 44 |
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils; |
| 45 |
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils; |
| 46 |
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils; |
| 47 |
import org.eclipse.xsd.XSDSchema; |
| 48 |
|
| 49 |
/** |
| 50 |
* Wizard page to import capability from XSD and WSDL files. |
| 51 |
*/ |
| 52 |
|
| 53 |
public class CapabilityModelImporterPage extends WizardPage |
| 54 |
{ |
| 55 |
private ISelection _selection; |
| 56 |
|
| 57 |
private NewCapabilityWizard _wizard; |
| 58 |
|
| 59 |
private Button _emptyCapability; |
| 60 |
|
| 61 |
private Button _fromXSD; |
| 62 |
|
| 63 |
private Text _xsdFilePathText; |
| 64 |
|
| 65 |
private Button _browseXSD; |
| 66 |
|
| 67 |
private Button _fromWSDL; |
| 68 |
|
| 69 |
private Text _wsdlFilePathText; |
| 70 |
|
| 71 |
private Button _browseWSDL; |
| 72 |
|
| 73 |
private Object[] _checkedItems; |
| 74 |
|
| 75 |
private Operation[] _importedOperations = new Operation[0]; |
| 76 |
|
| 77 |
private boolean _canFlipToNextPage = false; |
| 78 |
|
| 79 |
/** |
| 80 |
* Creates new object of this class. |
| 81 |
*/ |
| 82 |
protected CapabilityModelImporterPage(ISelection selection, |
| 83 |
NewCapabilityWizard wizard) |
| 84 |
{ |
| 85 |
super("wizardPage"); |
| 86 |
_selection = selection; |
| 87 |
_wizard = wizard; |
| 88 |
setTitle(Messages.SELECT_CAPABILITY_IMPORTER); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Creates wizard controls. |
| 93 |
*/ |
| 94 |
public void createControl(Composite parent) |
| 95 |
{ |
| 96 |
initializeDialogUnits(parent); |
| 97 |
Composite container = new Composite(parent, SWT.NULL); |
| 98 |
container.setFont(parent.getFont()); |
| 99 |
container.setLayout(new GridLayout()); |
| 100 |
container.setLayoutData(new GridData()); |
| 101 |
|
| 102 |
_emptyCapability = new Button(container, SWT.RADIO); |
| 103 |
_emptyCapability.setText(Messages.CREATE_EMPTY_CAPABILITY); |
| 104 |
_emptyCapability.addSelectionListener(new SelectionAdapter() |
| 105 |
{ |
| 106 |
public void widgetSelected(SelectionEvent e) |
| 107 |
{ |
| 108 |
handleEmptyCapabilityButtonSelection(); |
| 109 |
} |
| 110 |
}); |
| 111 |
|
| 112 |
createFromXSDControl(container); |
| 113 |
createFromWSDLControl(container); |
| 114 |
|
| 115 |
intialize(); |
| 116 |
|
| 117 |
setControl(container); |
| 118 |
Dialog.applyDialogFont(parent); |
| 119 |
} |
| 120 |
|
| 121 |
private void handleEmptyCapabilityButtonSelection() |
| 122 |
{ |
| 123 |
_fromXSD.setSelection(false); |
| 124 |
_browseXSD.setEnabled(false); |
| 125 |
_xsdFilePathText.setEnabled(false); |
| 126 |
_fromWSDL.setSelection(false); |
| 127 |
_browseWSDL.setEnabled(false); |
| 128 |
_wsdlFilePathText.setEnabled(false); |
| 129 |
setMessage(Messages.CREATE_EMPTY_CAPABILITY); |
| 130 |
_wizard.getOperationImportWizardPage().setPageComplete(true); |
| 131 |
_wizard.getPropertyImportWizardPage().setPageComplete(true); |
| 132 |
dialogChanged(); |
| 133 |
} |
| 134 |
|
| 135 |
private void createFromXSDControl(Composite parent) |
| 136 |
{ |
| 137 |
Composite fromXSDComposite = new Composite(parent, SWT.NULL); |
| 138 |
GridLayout layout = new GridLayout(2, false); |
| 139 |
layout.marginWidth = 0; |
| 140 |
fromXSDComposite.setLayout(layout); |
| 141 |
GridData gd = new GridData(SWT.FILL, SWT.NONE, true, false); |
| 142 |
fromXSDComposite.setLayoutData(gd); |
| 143 |
|
| 144 |
_fromXSD = new Button(fromXSDComposite, SWT.RADIO); |
| 145 |
_fromXSD |
| 146 |
.setText(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages.DEFINE_CAPABILITY_FROM_XSD); |
| 147 |
_fromXSD.addSelectionListener(new SelectionAdapter() |
| 148 |
{ |
| 149 |
public void widgetSelected(SelectionEvent e) |
| 150 |
{ |
| 151 |
handleFromXSDButtonSelection(); |
| 152 |
} |
| 153 |
}); |
| 154 |
gd = new GridData(); |
| 155 |
gd.horizontalSpan = 2; |
| 156 |
_fromXSD.setLayoutData(gd); |
| 157 |
|
| 158 |
_xsdFilePathText = new Text(fromXSDComposite, SWT.BORDER); |
| 159 |
gd = new GridData(SWT.FILL, SWT.NONE, true, false); |
| 160 |
gd.horizontalIndent = 15; |
| 161 |
_xsdFilePathText.setLayoutData(gd); |
| 162 |
_xsdFilePathText.addModifyListener(new ModifyListener() |
| 163 |
{ |
| 164 |
public void modifyText(ModifyEvent e) |
| 165 |
{ |
| 166 |
dialogChanged(); |
| 167 |
} |
| 168 |
}); |
| 169 |
|
| 170 |
_browseXSD = createBrowseWorkspaceButton(fromXSDComposite); |
| 171 |
_browseXSD.addSelectionListener(new SelectionAdapter() |
| 172 |
{ |
| 173 |
public void widgetSelected(SelectionEvent e) |
| 174 |
{ |
| 175 |
handleXSDBrowse(); |
| 176 |
} |
| 177 |
}); |
| 178 |
_browseXSD.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); |
| 179 |
} |
| 180 |
|
| 181 |
private void handleFromXSDButtonSelection() |
| 182 |
{ |
| 183 |
_emptyCapability.setSelection(false); |
| 184 |
_browseXSD.setEnabled(true); |
| 185 |
_xsdFilePathText.setEnabled(true); |
| 186 |
_fromWSDL.setSelection(false); |
| 187 |
_browseWSDL.setEnabled(false); |
| 188 |
_wsdlFilePathText.setEnabled(false); |
| 189 |
setMessage(Messages.IMPORT_PROPERTIES_FROM_XSD); |
| 190 |
dialogChanged(); |
| 191 |
} |
| 192 |
|
| 193 |
private void createFromWSDLControl(Composite parent) |
| 194 |
{ |
| 195 |
Composite fromWSDLComposite = new Composite(parent, SWT.NULL); |
| 196 |
GridLayout layout = new GridLayout(2, false); |
| 197 |
layout.marginWidth = 0; |
| 198 |
fromWSDLComposite.setLayout(layout); |
| 199 |
GridData gd = new GridData(SWT.FILL, SWT.NONE, true, false); |
| 200 |
fromWSDLComposite.setLayoutData(gd); |
| 201 |
|
| 202 |
_fromWSDL = new Button(fromWSDLComposite, SWT.RADIO); |
| 203 |
_fromWSDL |
| 204 |
.setText(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages.DEFINE_CAPABILITY_FROM_WSDL); |
| 205 |
_fromWSDL.addSelectionListener(new SelectionAdapter() |
| 206 |
{ |
| 207 |
public void widgetSelected(SelectionEvent e) |
| 208 |
{ |
| 209 |
handleFromWSDLButtonSelection(); |
| 210 |
} |
| 211 |
}); |
| 212 |
gd = new GridData(); |
| 213 |
gd.horizontalSpan = 2; |
| 214 |
_fromWSDL.setLayoutData(gd); |
| 215 |
|
| 216 |
_wsdlFilePathText = new Text(fromWSDLComposite, SWT.BORDER); |
| 217 |
gd = new GridData(SWT.FILL, SWT.NONE, true, false); |
| 218 |
gd.horizontalIndent = 15; |
| 219 |
_wsdlFilePathText.setLayoutData(gd); |
| 220 |
_wsdlFilePathText.addModifyListener(new ModifyListener() |
| 221 |
{ |
| 222 |
public void modifyText(ModifyEvent e) |
| 223 |
{ |
| 224 |
dialogChanged(); |
| 225 |
} |
| 226 |
}); |
| 227 |
|
| 228 |
_browseWSDL = createBrowseWorkspaceButton(fromWSDLComposite); |
| 229 |
_browseWSDL.addSelectionListener(new SelectionAdapter() |
| 230 |
{ |
| 231 |
public void widgetSelected(SelectionEvent e) |
| 232 |
{ |
| 233 |
handleWSDLBrowse(); |
| 234 |
} |
| 235 |
}); |
| 236 |
_browseWSDL.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); |
| 237 |
} |
| 238 |
|
| 239 |
private void handleFromWSDLButtonSelection() |
| 240 |
{ |
| 241 |
_emptyCapability.setSelection(false); |
| 242 |
_fromXSD.setSelection(false); |
| 243 |
_browseXSD.setEnabled(false); |
| 244 |
_xsdFilePathText.setEnabled(false); |
| 245 |
_browseWSDL.setEnabled(true); |
| 246 |
_wsdlFilePathText.setEnabled(true); |
| 247 |
setMessage(Messages.IMPORT_OPERATIONS_FROM_WSDL); |
| 248 |
dialogChanged(); |
| 249 |
} |
| 250 |
|
| 251 |
private void intialize() |
| 252 |
{ |
| 253 |
_emptyCapability.setSelection(true); |
| 254 |
_browseXSD.setEnabled(false); |
| 255 |
_xsdFilePathText.setEnabled(false); |
| 256 |
_browseWSDL.setEnabled(false); |
| 257 |
_wsdlFilePathText.setEnabled(false); |
| 258 |
setMessage(Messages.CREATE_EMPTY_CAPABILITY); |
| 259 |
} |
| 260 |
|
| 261 |
private Button createBrowseWorkspaceButton(Composite container) |
| 262 |
{ |
| 263 |
Button browseButton = new Button(container, SWT.PUSH); |
| 264 |
browseButton.setText(Messages.BROWSE_WORKSPACE); |
| 265 |
GridData gd = new GridData(GridData.END); |
| 266 |
gd.grabExcessHorizontalSpace = true; |
| 267 |
browseButton.setLayoutData(gd); |
| 268 |
return browseButton; |
| 269 |
} |
| 270 |
|
| 271 |
private void handleXSDBrowse() |
| 272 |
{ |
| 273 |
XSDBrowseDialog dialog = new XSDBrowseDialog(getShell()); |
| 274 |
if (dialog.open() == Window.OK) |
| 275 |
{ |
| 276 |
IFile browsedFile = (IFile) dialog.getFirstResult(); |
| 277 |
XSDSchema xsdSchema = XsdUtils.getSchema(browsedFile); |
| 278 |
_xsdFilePathText.setText(browsedFile.getFullPath().toString()); |
| 279 |
// TODO Check for valid file |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
private void handleWSDLBrowse() |
| 284 |
{ |
| 285 |
WSDLBrowseDialog dialog = new WSDLBrowseDialog(getShell()); |
| 286 |
if (dialog.open() == Window.OK) |
| 287 |
{ |
| 288 |
IFile browsedFile = (IFile) dialog.getFirstResult(); |
| 289 |
try |
| 290 |
{ |
| 291 |
WsdlUtils.getCapabilityDefinition(browsedFile); |
| 292 |
} |
| 293 |
catch (Exception e) |
| 294 |
{ |
| 295 |
MessageDialog |
| 296 |
.openError( |
| 297 |
getShell(), |
| 298 |
"Error", |
| 299 |
org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages.IMPROPER_WSDL_FILE); |
| 300 |
return; |
| 301 |
} |
| 302 |
_wsdlFilePathText.setText(browsedFile.getFullPath().toString()); |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
/** |
| 307 |
* Returns the imported XSD schemas specified. |
| 308 |
*/ |
| 309 |
/* |
| 310 |
* protected XSDSchema[] getSchemaToImport() { |
| 311 |
* if(_emptyCapability.getSelection() || _fromWSDL.getSelection()) return |
| 312 |
* new XSDSchema[0]; return new XSDSchema[0]; } |
| 313 |
*/ |
| 314 |
|
| 315 |
/** |
| 316 |
* Returns the imported Operations specified. |
| 317 |
*/ |
| 318 |
/* |
| 319 |
* protected Operation[] getOperationsToImport() { |
| 320 |
* if(_emptyCapability.getSelection() || _fromXSD.getSelection()) return new |
| 321 |
* Operation[0]; return _importedOperations; } |
| 322 |
*/ |
| 323 |
|
| 324 |
private void dialogChanged() |
| 325 |
{ |
| 326 |
if (_fromXSD.getSelection()) |
| 327 |
{ |
| 328 |
String xsdFilePath = getXSDFilePath(); |
| 329 |
if (!isValidWorkspaceFile(xsdFilePath)) |
| 330 |
{ |
| 331 |
updateStatus(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages.SPECIFY_EXISTING_XSD); |
| 332 |
return; |
| 333 |
} |
| 334 |
|
| 335 |
} |
| 336 |
if (_fromWSDL.getSelection()) |
| 337 |
{ |
| 338 |
String wsdlFilePath = getWSDLFilePath(); |
| 339 |
if (!isValidWorkspaceFile(wsdlFilePath)) |
| 340 |
{ |
| 341 |
updateStatus(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages.SPECIFY_EXISTING_WSDL); |
| 342 |
return; |
| 343 |
} |
| 344 |
} |
| 345 |
updateStatus(null); |
| 346 |
} |
| 347 |
|
| 348 |
private void updateStatus(String message) |
| 349 |
{ |
| 350 |
_canFlipToNextPage = true; |
| 351 |
if (message != null) |
| 352 |
_canFlipToNextPage = false; |
| 353 |
if (_emptyCapability.getSelection()) |
| 354 |
_canFlipToNextPage = false; |
| 355 |
setErrorMessage(message); |
| 356 |
setPageComplete(message == null && _emptyCapability.getSelection()); |
| 357 |
} |
| 358 |
|
| 359 |
private String getXSDFilePath() |
| 360 |
{ |
| 361 |
return _xsdFilePathText.getText(); |
| 362 |
} |
| 363 |
|
| 364 |
private String getWSDLFilePath() |
| 365 |
{ |
| 366 |
return _wsdlFilePathText.getText(); |
| 367 |
} |
| 368 |
|
| 369 |
private boolean isValidWorkspaceFile(String filePath) |
| 370 |
{ |
| 371 |
try |
| 372 |
{ |
| 373 |
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); |
| 374 |
IFile file = root.getFile(new Path(filePath)); |
| 375 |
if (file == null || (!file.exists())) |
| 376 |
return false; |
| 377 |
} |
| 378 |
catch (Exception e) |
| 379 |
{ |
| 380 |
return false; |
| 381 |
} |
| 382 |
return true; |
| 383 |
} |
| 384 |
|
| 385 |
public IWizardPage getNextPage() |
| 386 |
{ |
| 387 |
if (_emptyCapability.getSelection()) |
| 388 |
{ |
| 389 |
return null; |
| 390 |
} |
| 391 |
if (_fromWSDL.getSelection()) |
| 392 |
{ |
| 393 |
try |
| 394 |
{ |
| 395 |
_wizard.getPropertyImportWizardPage().setPageComplete(true); |
| 396 |
String wsdlFilePath = getWSDLFilePath(); |
| 397 |
IFile wsdlFile = EclipseUtils.getIFile(wsdlFilePath); |
| 398 |
CapabilityDefinition capabilityDefinition = WsdlUtils |
| 399 |
.getCapabilityDefinition(wsdlFile); |
| 400 |
Definition wsdlDefinition = capabilityDefinition |
| 401 |
.getDefinition(); |
| 402 |
OperationImportWizardPage page = _wizard |
| 403 |
.getOperationImportWizardPage(); |
| 404 |
page.setWSDLDefinition(wsdlDefinition); |
| 405 |
setPageComplete(true); |
| 406 |
return page; |
| 407 |
} |
| 408 |
catch (Exception e) |
| 409 |
{ |
| 410 |
e.printStackTrace(); |
| 411 |
} |
| 412 |
} |
| 413 |
if (_fromXSD.getSelection()) |
| 414 |
{ |
| 415 |
try |
| 416 |
{ |
| 417 |
_wizard.getOperationImportWizardPage().setPageComplete(true); |
| 418 |
String xsdFilePath = getXSDFilePath(); |
| 419 |
IFile xsdFile = EclipseUtils.getIFile(xsdFilePath); |
| 420 |
XSDSchema importSchema = XsdUtils.getSchema(xsdFile); |
| 421 |
PropertyImportWizardPage page = _wizard |
| 422 |
.getPropertyImportWizardPage(); |
| 423 |
page.setImportSchema(importSchema); |
| 424 |
setPageComplete(true); |
| 425 |
return page; |
| 426 |
} |
| 427 |
catch (Exception e) |
| 428 |
{ |
| 429 |
e.printStackTrace(); |
| 430 |
} |
| 431 |
} |
| 432 |
return super.getNextPage(); |
| 433 |
} |
| 434 |
|
| 435 |
public boolean canFlipToNextPage() |
| 436 |
{ |
| 437 |
return _canFlipToNextPage; |
| 438 |
} |
| 439 |
|
| 440 |
public boolean isEmptyCapabilityButtonSelected() |
| 441 |
{ |
| 442 |
return _emptyCapability.getSelection(); |
| 443 |
} |
| 444 |
|
| 445 |
public boolean isFromXSDButtonSelected() |
| 446 |
{ |
| 447 |
return _fromXSD.getSelection(); |
| 448 |
} |
| 449 |
|
| 450 |
public boolean isFromWSDLButtonSelected() |
| 451 |
{ |
| 452 |
return _fromWSDL.getSelection(); |
| 453 |
} |
| 454 |
} |