Skip to main content
summaryrefslogtreecommitdiffstats
blob: f2140f2014b7bd3b3a423fa3ad99cb50cccd5e3b (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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
/*******************************************************************************
 * Copyright (c) 2001, 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
 *******************************************************************************/
package org.eclipse.wst.wsdl.ui.internal;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.IPostSelectionProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.INavigationLocation;
import org.eclipse.ui.INavigationLocationProvider;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.TextSelectionNavigationLocation;
import org.eclipse.ui.views.properties.IPropertySheetPage;
import org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySheetPageContributor;
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
import org.eclipse.wst.wsdl.Binding;
import org.eclipse.wst.wsdl.Definition;
import org.eclipse.wst.wsdl.WSDLElement;
import org.eclipse.wst.wsdl.XSDSchemaExtensibilityElement;
import org.eclipse.wst.wsdl.internal.generator.BindingGenerator;
import org.eclipse.wst.wsdl.ui.internal.actions.WSDLMenuActionContributor;
import org.eclipse.wst.wsdl.ui.internal.dialogs.GenerateBindingOnSaveDialog;
import org.eclipse.wst.wsdl.ui.internal.extension.WSDLEditorExtension;
import org.eclipse.wst.wsdl.ui.internal.graph.WSDLGraphViewer;
import org.eclipse.wst.wsdl.ui.internal.graph.editparts.WSDLEditPartFactory;
import org.eclipse.wst.wsdl.ui.internal.model.WSDLGroupObject;
import org.eclipse.wst.wsdl.ui.internal.model.WSDLModelAdapterFactory;
import org.eclipse.wst.wsdl.ui.internal.outline.ModelAdapterContentProvider;
import org.eclipse.wst.wsdl.ui.internal.outline.ModelAdapterLabelProvider;
import org.eclipse.wst.wsdl.ui.internal.properties.section.WSDLTabbedPropertySheetPage;
import org.eclipse.wst.wsdl.ui.internal.text.WSDLModelAdapter;
import org.eclipse.wst.wsdl.ui.internal.util.ComponentReferenceUtil;
import org.eclipse.wst.wsdl.ui.internal.util.WSDLEditorUtil;
import org.eclipse.wst.wsdl.ui.internal.util.WSDLNodeAssociationProvider;
import org.eclipse.wst.wsdl.ui.internal.util.WSDLResourceUtil;
import org.eclipse.wst.wsdl.ui.internal.viewers.WSDLDetailsViewer;
import org.eclipse.wst.wsdl.ui.internal.viewers.WSDLDetailsViewerProvider;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

// public class WSDLEditor extends StructuredTextMultiPageEditorPart
// implements
// INavigationLocationProvider
public class WSDLEditor extends WSDLMultiPageEditorPart implements INavigationLocationProvider, ITabbedPropertySheetPageContributor {
	protected StructuredTextEditor textEditor;
	protected WSDLGraphViewer graphViewer;
	protected WSDLDetailsViewer detailsViewer;
	protected WSDLSelectionManager selectionManager;
	protected SashForm sashForm;
	int graphPageIndex;
	protected WSDLModelAdapter modelAdapter;
	protected WSDLEditorResourceChangeHandler resourceChangeHandler;
	// Used for Cut, Copy, Paste actions. This acts as a copy, cut, paste
	// clipboard
	protected WSDLElement clipboardElement;
	private IPropertySheetPage fPropertySheetPage;
	private SourceEditorSelectionListener fSourceEditorSelectionListener;
	private WSDLSelectionManagerSelectionListener fWSDLSelectionListener;

	/**
	 * Listener on SSE's source editor's selections that converts DOM
	 * selections into wsdl selections and notifies WSDL selection manager
	 */
	private class SourceEditorSelectionListener implements ISelectionChangedListener {
		/**
		 * Determines WSDL node based on object (DOM node)
		 * 
		 * @param object
		 * @return
		 */
		private Object getWSDLNode(Object object) {
			// get the element node
			Element element = null;
			if (object instanceof Node) {
				Node node = (Node) object;
				if (node != null) {
					if (node.getNodeType() == Node.ELEMENT_NODE) {
						element = (Element) node;
					}
					else if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
						element = ((Attr) node).getOwnerElement();
					}
				}
			}
			Object o = element;
			if (element != null) {
				Object modelObject = WSDLEditorUtil.getInstance().findModelObjectForElement(getDefinition(), element);
				if (modelObject != null) {
					o = modelObject;
				}
			}
			return o;
		}

		public void selectionChanged(SelectionChangedEvent event) {
			ISelection selection = event.getSelection();
			if (selection instanceof IStructuredSelection) {
				List wsdlSelections = new ArrayList();
				for (Iterator i = ((IStructuredSelection) selection).iterator(); i.hasNext();) {
					Object domNode = i.next();
					Object wsdlNode = getWSDLNode(domNode);
					if (wsdlNode != null) {
						wsdlSelections.add(wsdlNode);
					}
				}

				if (!wsdlSelections.isEmpty()) {
					StructuredSelection wsdlSelection = new StructuredSelection(wsdlSelections);
					getSelectionManager().setSelection(wsdlSelection, getTextEditor().getSelectionProvider());
				}
			}
		}
	}

	/**
	 * Listener on WSDL's selection manager's selections that converts WSDL
	 * selections into DOM selections and notifies SSE's selection provider
	 */
	private class WSDLSelectionManagerSelectionListener implements ISelectionChangedListener {
		/**
		 * Determines DOM node based on object (wsdl node)
		 * 
		 * @param object
		 * @return
		 */
		private Object getObjectForOtherModel(Object object) {
			Node node = null;

			if (object instanceof Node) {
				node = (Node) object;
			}
			else {
				node = WSDLEditorUtil.getInstance().getNodeForObject(object);
			}

			// the text editor can only accept sed nodes!
			//
			if (!(node instanceof IDOMNode)) {
				node = null;
			}
			return node;
		}

		public void selectionChanged(SelectionChangedEvent event) {
			// do not fire selection in source editor if selection event came
			// from source editor
			if (event.getSource() != getTextEditor().getSelectionProvider()) {
				ISelection selection = event.getSelection();
				if (selection instanceof IStructuredSelection) {
					List otherModelObjectList = new ArrayList();
					for (Iterator i = ((IStructuredSelection) selection).iterator(); i.hasNext();) {
						Object modelObject = i.next();
						Object otherModelObject = getObjectForOtherModel(modelObject);
						if (otherModelObject != null) {
							otherModelObjectList.add(otherModelObject);
						}
					}
					if (!otherModelObjectList.isEmpty()) {
						StructuredSelection nodeSelection = new StructuredSelection(otherModelObjectList);
						getTextEditor().getSelectionProvider().setSelection(nodeSelection);
					}
				}
			}
		}
	}

	public WSDLEditor() {
		selectionManager = new WSDLSelectionManager();
	}

	public void init(IEditorSite site, IEditorInput input) throws PartInitException {
		super.init(site, input);
		try {
			IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
			IWorkbenchPage page = window.getActivePage();
			if (page != null) {
				page.showView("org.eclipse.ui.views.PropertySheet");
			}
		}
		catch (PartInitException partInitException) {
		}
		catch (Exception exception) {
		}
	}

	public Object getAdapter(Class key) {
		Object result = null;
		if (key == ISelectionProvider.class) {
			result = selectionManager;
		}
		else if (IPropertySheetPage.class.equals(key)) {
			if (fPropertySheetPage == null || fPropertySheetPage.getControl() == null || fPropertySheetPage.getControl().isDisposed()) {
				fPropertySheetPage = new WSDLTabbedPropertySheetPage(this, this);
				((WSDLTabbedPropertySheetPage) fPropertySheetPage).setSelectionManager(getSelectionManager());

			}

			return fPropertySheetPage;
		}
		else {
			result = super.getAdapter(key);
		}
		return result;
	}

	public void dispose() {
		// call the extensibleOutlineProvider's inputChanged method a null
		// viewer
		// so that the outline's contentprovider/adapters don't attempt to
		// update
		// the viewer
		// after the editor closes
		// extensibleOutlineProvider.inputChanged(null, null, null);
		if (resourceChangeHandler != null) {
			resourceChangeHandler.dispose();
		}

		ISelectionProvider provider = getTextEditor().getSelectionProvider();
		if (provider instanceof IPostSelectionProvider) {
			((IPostSelectionProvider) provider).removePostSelectionChangedListener(fSourceEditorSelectionListener);
		}
		else {
			provider.removeSelectionChangedListener(fSourceEditorSelectionListener);
		}
		getSelectionManager().removeSelectionChangedListener(fWSDLSelectionListener);
		super.dispose();
	}

	public WSDLSelectionManager getSelectionManager() {
		return selectionManager;
	}

	public WSDLGraphViewer getGraphViewer() {
		return graphViewer;
	}

	public IStructuredModel getStructuredModel() {
		return textEditor.getModel();
		// IDocument doc =
		// textEditor.getDocumentProvider().getDocument(getEditorInput());
		// IModelManager modelManager = ModelManagerImpl.getInstance();
		// return modelManager.getModelForRead((IStructuredDocument) doc);
	}

	public Document getXMLDocument() {
		return ((IDOMModel) getStructuredModel()).getDocument();
	}

	public Definition getDefinition() {
		return modelAdapter != null ? modelAdapter.getDefinition() : null;
	}

	/**
	 * Creates the pages of this multi-page editor.
	 * <p>
	 * Subclasses of <code>MultiPageEditor</code> must implement this
	 * method.
	 * </p>
	 */
	protected void createPages() {
		try {
			if (resourceChangeHandler == null) {
				resourceChangeHandler = new WSDLEditorResourceChangeHandler(this);
				resourceChangeHandler.attach();
			}
			createSourcePage();
			addSourcePage();
			// create the wsdl model
			//
			lookupOrCreateWSDLModel();
			createAndAddGraphPage();

			// get the type of page and set the active page to show
			int pageIndexToShow = getDefaultPageIndex();
			setActivePage(pageIndexToShow);
			getSelectionManager().setSelection(new StructuredSelection(getDefinition()));

			// added selection listeners after setting selection to avoid
			// navigation exception
			ISelectionProvider provider = getTextEditor().getSelectionProvider();
			fSourceEditorSelectionListener = new SourceEditorSelectionListener();
			if (provider instanceof IPostSelectionProvider) {
				((IPostSelectionProvider) provider).addPostSelectionChangedListener(fSourceEditorSelectionListener);
			}
			else {
				provider.addSelectionChangedListener(fSourceEditorSelectionListener);
			}
			fWSDLSelectionListener = new WSDLSelectionManagerSelectionListener();
			getSelectionManager().addSelectionChangedListener(fWSDLSelectionListener);
		}
		catch (PartInitException e) {
			// log for now, unless we find reason not to
			Logger.log(Logger.INFO, e.getMessage());
		}
		// TODO: add a catch block here for any exception the design page
		// throws and
		// convert it into a more informative message.
	}

	protected void lookupOrCreateWSDLModel() {
		try {
			Document document = ((IDOMModel) getModel()).getDocument();
			if (document instanceof INodeNotifier) {
				INodeNotifier notifier = (INodeNotifier) document;
				modelAdapter = (WSDLModelAdapter) notifier.getAdapterFor(WSDLModelAdapter.class);
				if (modelAdapter == null) {
					modelAdapter = new WSDLModelAdapter();
					notifier.addAdapter(modelAdapter);
					modelAdapter.createDefinition(document.getDocumentElement());
				}
			}
		}
		catch (Exception e) {
		}
	}

	protected int getDefaultPageIndex() {
		if (WSDLEditorPlugin.getInstance().getDefaultPage().equals(WSDLEditorPlugin.GRAPH_PAGE)) {
			if (graphPageIndex != -1) {
				return graphPageIndex;
			}
		}
		return sourcePageIndex;
	}

	/**
	 * @see org.eclipse.wst.wsdl.ui.WSDLMultiPageEditorPart#createTextEditor()
	 */
	protected StructuredTextEditor createTextEditor() {
		textEditor = new StructuredTextEditor();
		return textEditor;
	}

	/**
	 * create our own
	 */
	protected void createSourcePage() throws PartInitException {
		super.createSourcePage();
		textEditor = getTextEditor();
	}

	int sourcePageIndex = -1;

	/**
	 * Adds the source page of the multi-page editor.
	 */
	protected void addSourcePage() throws PartInitException {
		sourcePageIndex = addPage(textEditor, getEditorInput());
		setPageText(sourcePageIndex, WSDLEditorPlugin.getWSDLString("_UI_TAB_SOURCE"));
		// the update's critical, to get viewer selection manager and
		// highlighting to
		// work
		textEditor.update();
	}

	int[] weights;

	public void setDesignWeights(int[] weights, boolean updateSourceDesign) {
		this.weights = weights;
		if (updateSourceDesign) {
			sashForm.setWeights(weights);
		}
	}

	protected void pageChange(int arg) {
		super.pageChange(arg);
		if (getPageText(arg).equals(WSDLEditorPlugin.getWSDLString("_UI_TAB_SOURCE"))) // TRANSLATE
		// !
		{
			// update the input
		}
		else if (getPageText(arg).equals(WSDLEditorPlugin.getWSDLString("_UI_TAB_GRAPH"))) // TRANSLATE
		// !
		{
			// update the input
		}
	}

	static private Color dividerColor;

	/**
	 * Creates the graph page and adds it to the multi-page editor.
	 */
	protected void createAndAddGraphPage() throws PartInitException {
		// create the graph page
		sashForm = new SashForm(getContainer(), SWT.BORDER);
		sashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
		sashForm.setOrientation(SWT.VERTICAL);
		graphPageIndex = addPage(sashForm);
		setPageText(graphPageIndex, WSDLEditorPlugin.getWSDLString("_UI_TAB_GRAPH"));
		// create the graph viewer
		graphViewer = new WSDLGraphViewer(this);
		graphViewer.createControl(sashForm);
		// detailsViewer = new WSDLDetailsViewer(this);
		// detailsViewer.createControl(sashForm);
		//
		// sashForm.setWeights(weights);
		if (dividerColor == null) {
			dividerColor = new Color(getContainer().getDisplay(), 143, 141, 138);
		}
		getContainer().addPaintListener(new PaintListener() {
			/**
			 * @see org.eclipse.swt.events.PaintListener#paintControl(PaintEvent)
			 */
			public void paintControl(PaintEvent e) {
				Object source = e.getSource();
				if (source instanceof Composite) {
					Composite comp = (Composite) source;
					Rectangle boundary = comp.getClientArea();
					e.gc.setForeground(dividerColor);
					e.gc.drawLine(boundary.x, boundary.y, boundary.x + boundary.width, boundary.y);
					setDesignWeights(sashForm.getWeights(), true);
				}
			}
		});
	}

	public void setFocus() {
		super.setFocus();
		int activePage = getActivePage();
		if (activePage == sourcePageIndex) {
			WSDLEditorPlugin.getInstance().setDefaultPage(WSDLEditorPlugin.SOURCE_PAGE);
		}
		else {
			WSDLEditorPlugin.getInstance().setDefaultPage(WSDLEditorPlugin.GRAPH_PAGE);
		}
	}

	//
	//
	public static class BuiltInWSDLEditorExtension implements WSDLEditorExtension {
		public boolean isExtensionTypeSupported(int type) {
			return type == OUTLINE_TREE_CONTENT_PROVIDER || type == OUTLINE_LABEL_PROVIDER || type == EDIT_PART_FACTORY || type == DETAILS_VIEWER_PROVIDER || type == MENU_ACTION_CONTRIBUTOR || type == NODE_RECONCILER || type == NODE_ASSOCIATION_PROVIDER;
		}

		public boolean isApplicable(Object object) {
			return (object instanceof WSDLElement && !(object instanceof XSDSchemaExtensibilityElement)) || (object instanceof WSDLGroupObject);
		}

		public Object createExtensionObject(int type, WSDLEditor wsdlEditor) {
			Object result = null;
			switch (type) {
				case OUTLINE_TREE_CONTENT_PROVIDER : {
					result = new ModelAdapterContentProvider(WSDLModelAdapterFactory.getWSDLModelAdapterFactory());
					break;
				}
				case OUTLINE_LABEL_PROVIDER : {
					result = new ModelAdapterLabelProvider(WSDLModelAdapterFactory.getWSDLModelAdapterFactory());
					break;
				}
				case DETAILS_VIEWER_PROVIDER : {
					result = new WSDLDetailsViewerProvider();
					break;
				}
				case MENU_ACTION_CONTRIBUTOR : {
					result = new WSDLMenuActionContributor(wsdlEditor);
					break;
				}
				case NODE_ASSOCIATION_PROVIDER : {
					result = new WSDLNodeAssociationProvider();
					break;
				}
				case EDIT_PART_FACTORY : {
					result = new WSDLEditPartFactory();
					break;
				}
			}
			return result;
		}
	}

	public void reloadDependencies() {
		try {
			getGraphViewer().getComponentViewer().setPreserveExpansionEnabled(true);
			Definition definition = getDefinition();
			if (definition != null) {
				WSDLResourceUtil.reloadDirectives(definition);
				ComponentReferenceUtil.updateBindingReferences(definition);
				ComponentReferenceUtil.updatePortTypeReferences(definition);
				ComponentReferenceUtil.updateMessageReferences(definition);
				ComponentReferenceUtil.updateSchemaReferences(definition);
				// the line below simply causes a notification in order to
				// update our
				// views
				//
				definition.setDocumentationElement(definition.getDocumentationElement());
			}
		}
		finally {
			getGraphViewer().getComponentViewer().setPreserveExpansionEnabled(false);
		}
	}

	public void openOnSelection(String specification) {
		EObject eObject = getDefinition().eResource().getEObject(specification);
		if (eObject != null) {
			getSelectionManager().setSelection(new StructuredSelection(eObject));
		}
	}

	public INavigationLocation createEmptyNavigationLocation() {
		return new InternalTextSelectionNavigationLocation(textEditor, false);
	}

	public INavigationLocation createNavigationLocation() {
		return new InternalTextSelectionNavigationLocation(textEditor, true);
	}

	static class InternalTextSelectionNavigationLocation extends TextSelectionNavigationLocation {
		public InternalTextSelectionNavigationLocation(ITextEditor part, boolean initialize) {
			super(part, initialize);
		}

		protected IEditorPart getEditorPart() {
			IEditorPart part = super.getEditorPart();
			if (part instanceof WSDLEditor) {
				part = ((WSDLEditor) part).getTextEditor();
			}
			return part;
		}

		public String getText() {
			// ISSUE: how to get title?
			// IEditorPart part = getEditorPart();
			// if (part instanceof WSDLTextEditor) {
			// return ((WSDLTextEditor) part).getWSDLEditor().getTitle();
			// }
			// else {
			// return super.getText();
			// }
			return super.getText();
		}
	}

	// Returns the element currently on the copy, cut, paste clipboard
	public WSDLElement getClipboardContents() {
		return clipboardElement;
	}

	public void setClipboardContents(WSDLElement element) {
		clipboardElement = element;
	}

	/**
	 * @see org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySheetPageContributor#getContributorId()
	 */
	public String getContributorId() {
		return "org.eclipse.wst.wsdl.ui.internal.WSDLTextEditor";
		// return getSite().getId();
	}

	/*
	 * We override this method so we can hook in our automatic Binding
	 * generation. We will generate the Binding after a save is executed (If
	 * this preference has been set to true).
	 */
	public void doSave(IProgressMonitor monitor) {
		try {
			// Display prompt message
			boolean continueRegeneration = false;
			if (WSDLEditorPlugin.getInstance().getPluginPreferences().getBoolean("Prompt Regenerate Binding on save")) {
				Shell shell = Display.getCurrent().getActiveShell();
				GenerateBindingOnSaveDialog dialog = new GenerateBindingOnSaveDialog(shell);

				int rValue = dialog.open();
				if (rValue == SWT.YES) {
					continueRegeneration = true;
				}
				else if (rValue == SWT.NO) {
					continueRegeneration = false;
				}
				else if (rValue == SWT.CANCEL) {
					return;
				}
				else {
					System.out.println("\nNothing: " + rValue);
				}
			}
			else {
				continueRegeneration = WSDLEditorPlugin.getInstance().getPluginPreferences().getBoolean(WSDLEditorPlugin.getWSDLString("_UI_PREF_PAGE_AUTO_REGENERATE_BINDING"));
			}

			if (continueRegeneration) {
				Iterator bindingsIt = getDefinition().getEBindings().iterator();
				while (bindingsIt.hasNext()) {
					Binding binding = (Binding) bindingsIt.next();
					BindingGenerator generator = new BindingGenerator(binding.getEnclosingDefinition(), binding);
					generator.setOverwrite(false);
					generator.generateBinding();
				}

				// Little hack to 'redraw' connecting lines in the graph
				// viewer
				getDefinition().setQName(getDefinition().getQName());
			}
		}
		catch (Exception e) {
			// e.printStackTrace();
		}
		super.doSave(monitor);
	}
}

Back to the top