|
Lines 12-17
Link Here
|
| 12 |
|
12 |
|
| 13 |
import java.util.ArrayList; |
13 |
import java.util.ArrayList; |
| 14 |
import java.util.EventObject; |
14 |
import java.util.EventObject; |
|
|
15 |
import java.util.Iterator; |
| 16 |
import java.util.List; |
| 15 |
|
17 |
|
| 16 |
import org.eclipse.core.resources.IFile; |
18 |
import org.eclipse.core.resources.IFile; |
| 17 |
import org.eclipse.core.runtime.IPath; |
19 |
import org.eclipse.core.runtime.IPath; |
|
Lines 21-28
Link Here
|
| 21 |
import org.eclipse.jface.text.IDocument; |
23 |
import org.eclipse.jface.text.IDocument; |
| 22 |
import org.eclipse.jface.util.IPropertyChangeListener; |
24 |
import org.eclipse.jface.util.IPropertyChangeListener; |
| 23 |
import org.eclipse.jface.util.PropertyChangeEvent; |
25 |
import org.eclipse.jface.util.PropertyChangeEvent; |
|
|
26 |
import org.eclipse.jface.viewers.DoubleClickEvent; |
| 27 |
import org.eclipse.jface.viewers.IDoubleClickListener; |
| 28 |
import org.eclipse.jface.viewers.IPostSelectionProvider; |
| 24 |
import org.eclipse.jface.viewers.ISelection; |
29 |
import org.eclipse.jface.viewers.ISelection; |
|
|
30 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
| 25 |
import org.eclipse.jface.viewers.ISelectionProvider; |
31 |
import org.eclipse.jface.viewers.ISelectionProvider; |
|
|
32 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 26 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
33 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
| 27 |
import org.eclipse.jface.viewers.StructuredSelection; |
34 |
import org.eclipse.jface.viewers.StructuredSelection; |
| 28 |
import org.eclipse.swt.widgets.Control; |
35 |
import org.eclipse.swt.widgets.Control; |
|
Lines 37-622
Link Here
|
| 37 |
import org.eclipse.ui.PartInitException; |
44 |
import org.eclipse.ui.PartInitException; |
| 38 |
import org.eclipse.ui.PlatformUI; |
45 |
import org.eclipse.ui.PlatformUI; |
| 39 |
import org.eclipse.ui.editors.text.ILocationProvider; |
46 |
import org.eclipse.ui.editors.text.ILocationProvider; |
|
|
47 |
import org.eclipse.ui.views.contentoutline.IContentOutlinePage; |
| 48 |
import org.eclipse.ui.views.properties.IPropertySheetPage; |
| 40 |
import org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySheetPageContributor; |
49 |
import org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySheetPageContributor; |
| 41 |
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; |
50 |
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; |
| 42 |
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; |
51 |
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; |
|
|
52 |
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; |
| 43 |
import org.eclipse.wst.sse.core.internal.provisional.events.IStructuredDocumentListener; |
53 |
import org.eclipse.wst.sse.core.internal.provisional.events.IStructuredDocumentListener; |
| 44 |
import org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager; |
54 |
import org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager; |
| 45 |
import org.eclipse.wst.sse.ui.StructuredTextEditor; |
55 |
import org.eclipse.wst.sse.ui.StructuredTextEditor; |
|
|
56 |
import org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage; |
| 46 |
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; |
57 |
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; |
|
|
58 |
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; |
| 47 |
import org.eclipse.wst.xsd.ui.internal.graph.XSDGraphViewer; |
59 |
import org.eclipse.wst.xsd.ui.internal.graph.XSDGraphViewer; |
|
|
60 |
import org.eclipse.wst.xsd.ui.internal.properties.section.XSDTabbedPropertySheetPage; |
| 61 |
import org.eclipse.wst.xsd.ui.internal.provider.CategoryAdapter; |
| 62 |
import org.eclipse.wst.xsd.ui.internal.provider.XSDAdapterFactoryLabelProvider; |
| 63 |
import org.eclipse.wst.xsd.ui.internal.provider.XSDModelAdapterFactoryImpl; |
| 48 |
import org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter; |
64 |
import org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter; |
| 49 |
import org.eclipse.wst.xsd.ui.internal.util.OpenOnSelectionHelper; |
65 |
import org.eclipse.wst.xsd.ui.internal.util.OpenOnSelectionHelper; |
|
|
66 |
import org.eclipse.xsd.XSDComponent; |
| 50 |
import org.eclipse.xsd.XSDConcreteComponent; |
67 |
import org.eclipse.xsd.XSDConcreteComponent; |
| 51 |
import org.eclipse.xsd.XSDSchema; |
68 |
import org.eclipse.xsd.XSDSchema; |
| 52 |
import org.eclipse.xsd.util.XSDConstants; |
69 |
import org.eclipse.xsd.util.XSDConstants; |
|
|
70 |
import org.w3c.dom.Attr; |
| 53 |
import org.w3c.dom.Document; |
71 |
import org.w3c.dom.Document; |
| 54 |
import org.w3c.dom.Element; |
72 |
import org.w3c.dom.Element; |
|
|
73 |
import org.w3c.dom.Node; |
| 55 |
import org.w3c.dom.ProcessingInstruction; |
74 |
import org.w3c.dom.ProcessingInstruction; |
| 56 |
|
75 |
|
| 57 |
// public class XSDEditor extends StructuredTextMultiPageEditorPart |
76 |
// public class XSDEditor extends StructuredTextMultiPageEditorPart |
| 58 |
public class XSDEditor extends XSDMultiPageEditorPart implements ITabbedPropertySheetPageContributor |
77 |
public class XSDEditor extends XSDMultiPageEditorPart implements ITabbedPropertySheetPageContributor { |
| 59 |
{ |
78 |
protected StructuredTextEditor textEditor; |
| 60 |
protected XSDTextEditor textEditor; |
79 |
IFile resourceFile; |
| 61 |
IFile resourceFile; |
80 |
XSDSelectionManager xsdSelectionManager; |
| 62 |
XSDSelectionManager xsdSelectionManager; |
81 |
XSDModelAdapter schemalNodeAdapter; |
| 63 |
XSDModelAdapter schemalNodeAdapter; |
82 |
|
| 64 |
|
83 |
private IStructuredModel result; |
| 65 |
private IStructuredModel result; |
84 |
|
| 66 |
|
85 |
/** |
| 67 |
public XSDEditor() |
86 |
* Listener on SSE's outline page's selections that converts DOM |
| 68 |
{ |
87 |
* selections into wsdl selections and notifies WSDL selection manager |
| 69 |
super(); |
88 |
*/ |
| 70 |
xsdSelectionManager = new XSDSelectionManager(); |
89 |
class OutlineTreeSelectionChangeListener implements ISelectionChangedListener, IDoubleClickListener { |
| 71 |
} |
90 |
public OutlineTreeSelectionChangeListener() { |
| 72 |
|
91 |
} |
| 73 |
InternalPartListener partListener = new InternalPartListener(this); |
92 |
|
| 74 |
|
93 |
private ISelection getXSDSelection(ISelection selection) { |
| 75 |
// show outline view - defect 266116 |
94 |
ISelection sel = null; |
| 76 |
public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException |
95 |
if (selection instanceof IStructuredSelection) { |
| 77 |
{ |
96 |
IStructuredSelection structuredSelection = (IStructuredSelection) selection; |
| 78 |
super.init(site, editorInput); |
97 |
Object o = structuredSelection.getFirstElement(); |
| 79 |
IWorkbenchWindow dw=PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
98 |
if (o != null) |
| 80 |
IWorkbenchPage page=dw.getActivePage(); |
99 |
sel = new StructuredSelection(o); |
| 81 |
getSite().getPage().addPartListener(partListener); |
100 |
} |
| 82 |
try |
101 |
return sel; |
| 83 |
{ |
102 |
} |
| 84 |
if (page != null) |
103 |
|
| 85 |
{ |
104 |
/** |
| 86 |
// page.showView("org.eclipse.ui.views.ContentOutline"); |
105 |
* Determines DOM node based on object (xsd node) |
| 87 |
page.showView("org.eclipse.ui.views.PropertySheet"); |
106 |
* |
| 88 |
} |
107 |
* @param object |
| 89 |
} catch (PartInitException e) |
108 |
* @return |
| 90 |
{ |
109 |
*/ |
| 91 |
// e.printStackTrace(); |
110 |
private Object getObjectForOtherModel(Object object) { |
| 92 |
} |
111 |
Node node = null; |
| 93 |
} |
112 |
|
| 94 |
|
113 |
if (object instanceof Node) { |
| 95 |
// For team support |
114 |
node = (Node) object; |
| 96 |
// protected PropertyDirtyChangeListener propertyChangeListener; |
115 |
} |
| 97 |
|
116 |
else if (object instanceof XSDComponent) { |
| 98 |
/** |
117 |
node = ((XSDComponent) object).getElement(); |
| 99 |
* Creates the pages of this multi-page editor. |
118 |
} |
| 100 |
* <p> |
119 |
else if (object instanceof CategoryAdapter) { |
| 101 |
* Subclasses of <code>MultiPageEditor</code> must implement this method. |
120 |
node = ((CategoryAdapter) object).getXSDSchema().getElement(); |
| 102 |
* </p> |
121 |
} |
| 103 |
*/ |
122 |
|
| 104 |
protected void createPages() |
123 |
// the text editor can only accept sed nodes! |
| 105 |
{ |
124 |
// |
| 106 |
try |
125 |
if (!(node instanceof IDOMNode)) { |
| 107 |
{ |
126 |
node = null; |
| 108 |
if (!loadFile()) |
127 |
} |
| 109 |
return; |
128 |
return node; |
| 110 |
|
129 |
} |
| 111 |
// source page MUST be created before design page, now |
130 |
|
| 112 |
createSourcePage(); |
131 |
public void doubleClick(DoubleClickEvent event) { |
| 113 |
|
132 |
/* |
| 114 |
addSourcePage(); |
133 |
* Selection in outline tree changed so set outline tree's |
| 115 |
buildXSDModel(); |
134 |
* selection into editor's selection and say it came from outline |
| 116 |
|
135 |
* tree |
| 117 |
// comment this line out to hide the graph page |
136 |
*/ |
| 118 |
// |
137 |
if (getSelectionManager() != null && getSelectionManager().enableNotify) { |
| 119 |
createAndAddGraphPage(); |
138 |
ISelection selection = getXSDSelection(event.getSelection()); |
| 120 |
|
139 |
if (selection != null) { |
| 121 |
int pageIndexToShow = getDefaultPageTypeIndex(); |
140 |
getSelectionManager().setSelection(selection, fOutlinePage); |
| 122 |
setActivePage(pageIndexToShow); |
141 |
} |
| 123 |
|
142 |
|
| 124 |
addCommandStackListener(); |
143 |
if (getTextEditor() != null && selection instanceof IStructuredSelection) { |
| 125 |
|
144 |
int start = -1; |
| 126 |
XSDEditorPlugin.getPlugin().getPreferenceStore().addPropertyChangeListener(preferenceStoreListener); |
145 |
int length = 0; |
| 127 |
} |
146 |
Object o = ((IStructuredSelection) selection).getFirstElement(); |
| 128 |
catch (PartInitException e) |
147 |
if (o != null) |
| 129 |
{ |
148 |
o = getObjectForOtherModel(o); |
| 130 |
// log for now, unless we find reason not to |
149 |
if (o instanceof IndexedRegion) { |
| 131 |
Logger.log(Logger.INFO, e.getMessage()); |
150 |
start = ((IndexedRegion) o).getStartOffset(); |
| 132 |
} |
151 |
length = ((IndexedRegion) o).getEndOffset() - start; |
| 133 |
} |
152 |
} |
| 134 |
|
153 |
if (start > -1) { |
| 135 |
|
154 |
getTextEditor().selectAndReveal(start, length); |
| 136 |
public void buildXSDModel() |
155 |
} |
| 137 |
{ |
156 |
} |
| 138 |
try |
157 |
} |
| 139 |
{ |
158 |
} |
| 140 |
Document document = ((IDOMModel)getModel()).getDocument(); |
159 |
|
| 141 |
|
160 |
public void selectionChanged(SelectionChangedEvent event) { |
| 142 |
boolean schemaNodeExists = document.getElementsByTagNameNS(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "schema").getLength() == 1; |
161 |
/* |
| 143 |
|
162 |
* Selection in outline tree changed so set outline tree's |
| 144 |
if (document.getChildNodes().getLength() == 0 || !schemaNodeExists) |
163 |
* selection into editor's selection and say it came from outline |
| 145 |
{ |
164 |
* tree |
| 146 |
createDefaultSchemaNode(document); |
165 |
*/ |
| 147 |
} |
166 |
if (getSelectionManager() != null && getSelectionManager().enableNotify) { |
| 148 |
|
167 |
ISelection selection = getXSDSelection(event.getSelection()); |
| 149 |
if (document instanceof INodeNotifier) |
168 |
if (selection != null) { |
| 150 |
{ |
169 |
getSelectionManager().setSelection(selection, fOutlinePage); |
| 151 |
INodeNotifier notifier = (INodeNotifier)document; |
170 |
} |
| 152 |
schemalNodeAdapter = (XSDModelAdapter)notifier.getAdapterFor(XSDModelAdapter.class); |
171 |
} |
| 153 |
if (schemalNodeAdapter == null) |
172 |
} |
| 154 |
{ |
173 |
} |
| 155 |
schemalNodeAdapter = new XSDModelAdapter(); |
174 |
|
| 156 |
notifier.addAdapter(schemalNodeAdapter); |
175 |
/** |
| 157 |
schemalNodeAdapter.createSchema(document.getDocumentElement()); |
176 |
* Listener on SSE's source editor's selections that converts DOM |
| 158 |
} |
177 |
* selections into xsd selections and notifies XSD selection manager |
| 159 |
} |
178 |
*/ |
| 160 |
} |
179 |
private class SourceEditorSelectionListener implements ISelectionChangedListener { |
| 161 |
catch (Exception e) |
180 |
/** |
| 162 |
{ |
181 |
* Determines XSD node based on object (DOM node) |
| 163 |
// XSDEditorPlugin.getPlugin().getMsgLogger().write("Failed to create Model"); |
182 |
* |
| 164 |
// XSDEditorPlugin.getPlugin().getMsgLogger().write(e); |
183 |
* @param object |
| 165 |
// e.printStackTrace(); |
184 |
* @return |
| 166 |
} |
185 |
*/ |
| 167 |
|
186 |
private Object getXSDNode(Object object) { |
| 168 |
|
187 |
// get the element node |
| 169 |
|
188 |
Element element = null; |
| 170 |
// XSDResourceFactoryImpl.validate(xsdSchema, input.getFile().getContents(true)); |
189 |
if (object instanceof Node) { |
| 171 |
} |
190 |
Node node = (Node) object; |
| 172 |
|
191 |
if (node != null) { |
| 173 |
public String[] getPropertyCategories() |
192 |
if (node.getNodeType() == Node.ELEMENT_NODE) { |
| 174 |
{ |
193 |
element = (Element) node; |
| 175 |
return new String[] { "general", "namespace", "other", "attributes", "documentation", "facets" }; //$NON-NLS-1$ |
194 |
} |
| 176 |
} |
195 |
else if (node.getNodeType() == Node.ATTRIBUTE_NODE) { |
|
|
196 |
element = ((Attr) node).getOwnerElement(); |
| 197 |
} |
| 198 |
} |
| 199 |
} |
| 200 |
Object o = element; |
| 201 |
if (element != null) { |
| 202 |
Object modelObject = getXSDSchema().getCorrespondingComponent(element); |
| 203 |
if (modelObject != null) { |
| 204 |
o = modelObject; |
| 205 |
} |
| 206 |
} |
| 207 |
return o; |
| 208 |
} |
| 209 |
|
| 210 |
public void selectionChanged(SelectionChangedEvent event) { |
| 211 |
ISelection selection = event.getSelection(); |
| 212 |
if (selection instanceof IStructuredSelection) { |
| 213 |
List xsdSelections = new ArrayList(); |
| 214 |
for (Iterator i = ((IStructuredSelection) selection).iterator(); i.hasNext();) { |
| 215 |
Object domNode = i.next(); |
| 216 |
Object xsdNode = getXSDNode(domNode); |
| 217 |
if (xsdNode != null) { |
| 218 |
xsdSelections.add(xsdNode); |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
if (!xsdSelections.isEmpty()) { |
| 223 |
StructuredSelection xsdSelection = new StructuredSelection(xsdSelections); |
| 224 |
getSelectionManager().setSelection(xsdSelection, getTextEditor().getSelectionProvider()); |
| 225 |
} |
| 226 |
} |
| 227 |
} |
| 228 |
} |
| 229 |
|
| 230 |
/** |
| 231 |
* Listener on XSD's selection manager's selections that converts XSD |
| 232 |
* selections into DOM selections and notifies SSE's selection provider |
| 233 |
*/ |
| 234 |
private class XSDSelectionManagerSelectionListener implements ISelectionChangedListener { |
| 235 |
/** |
| 236 |
* Determines DOM node based on object (xsd node) |
| 237 |
* |
| 238 |
* @param object |
| 239 |
* @return |
| 240 |
*/ |
| 241 |
private Object getObjectForOtherModel(Object object) { |
| 242 |
Node node = null; |
| 243 |
|
| 244 |
if (object instanceof Node) { |
| 245 |
node = (Node) object; |
| 246 |
} |
| 247 |
else if (object instanceof XSDComponent) { |
| 248 |
node = ((XSDComponent) object).getElement(); |
| 249 |
} |
| 250 |
else if (object instanceof CategoryAdapter) { |
| 251 |
node = ((CategoryAdapter) object).getXSDSchema().getElement(); |
| 252 |
} |
| 253 |
|
| 254 |
// the text editor can only accept sed nodes! |
| 255 |
// |
| 256 |
if (!(node instanceof IDOMNode)) { |
| 257 |
node = null; |
| 258 |
} |
| 259 |
return node; |
| 260 |
} |
| 261 |
|
| 262 |
public void selectionChanged(SelectionChangedEvent event) { |
| 263 |
// do not fire selection in source editor if selection event came |
| 264 |
// from source editor |
| 265 |
if (event.getSource() != getTextEditor().getSelectionProvider()) { |
| 266 |
ISelection selection = event.getSelection(); |
| 267 |
if (selection instanceof IStructuredSelection) { |
| 268 |
List otherModelObjectList = new ArrayList(); |
| 269 |
for (Iterator i = ((IStructuredSelection) selection).iterator(); i.hasNext();) { |
| 270 |
Object modelObject = i.next(); |
| 271 |
Object otherModelObject = getObjectForOtherModel(modelObject); |
| 272 |
if (otherModelObject != null) { |
| 273 |
otherModelObjectList.add(otherModelObject); |
| 274 |
} |
| 275 |
} |
| 276 |
if (!otherModelObjectList.isEmpty()) { |
| 277 |
StructuredSelection nodeSelection = new StructuredSelection(otherModelObjectList); |
| 278 |
getTextEditor().getSelectionProvider().setSelection(nodeSelection); |
| 279 |
} |
| 280 |
} |
| 281 |
} |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
public XSDEditor() { |
| 286 |
super(); |
| 287 |
xsdSelectionManager = new XSDSelectionManager(); |
| 288 |
} |
| 289 |
|
| 290 |
InternalPartListener partListener = new InternalPartListener(this); |
| 291 |
|
| 292 |
// show outline view - defect 266116 |
| 293 |
public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException { |
| 294 |
super.init(site, editorInput); |
| 295 |
IWorkbenchWindow dw = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
| 296 |
IWorkbenchPage page = dw.getActivePage(); |
| 297 |
getSite().getPage().addPartListener(partListener); |
| 298 |
try { |
| 299 |
if (page != null) { |
| 300 |
// page.showView("org.eclipse.ui.views.ContentOutline"); |
| 301 |
page.showView("org.eclipse.ui.views.PropertySheet"); |
| 302 |
} |
| 303 |
} |
| 304 |
catch (PartInitException e) { |
| 305 |
// e.printStackTrace(); |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
// For team support |
| 310 |
// protected PropertyDirtyChangeListener propertyChangeListener; |
| 311 |
|
| 312 |
/** |
| 313 |
* Creates the pages of this multi-page editor. |
| 314 |
* <p> |
| 315 |
* Subclasses of <code>MultiPageEditor</code> must implement this |
| 316 |
* method. |
| 317 |
* </p> |
| 318 |
*/ |
| 319 |
protected void createPages() { |
| 320 |
try { |
| 321 |
if (!loadFile()) |
| 322 |
return; |
| 323 |
|
| 324 |
xsdModelAdapterFactory = XSDModelAdapterFactoryImpl.getInstance(); |
| 325 |
adapterFactoryLabelProvider = new XSDAdapterFactoryLabelProvider(xsdModelAdapterFactory); |
| 326 |
|
| 327 |
// source page MUST be created before design page, now |
| 328 |
createSourcePage(); |
| 329 |
|
| 330 |
addSourcePage(); |
| 331 |
buildXSDModel(); |
| 332 |
|
| 333 |
// comment this line out to hide the graph page |
| 334 |
// |
| 335 |
createAndAddGraphPage(); |
| 336 |
|
| 337 |
int pageIndexToShow = getDefaultPageTypeIndex(); |
| 338 |
setActivePage(pageIndexToShow); |
| 339 |
|
| 340 |
openOnSelectionHelper = new OpenOnSelectionHelper(textEditor, getXSDSchema()); |
| 341 |
// added selection listeners after setting selection to avoid |
| 342 |
// navigation exception |
| 343 |
ISelectionProvider provider = getTextEditor().getSelectionProvider(); |
| 344 |
fSourceEditorSelectionListener = new SourceEditorSelectionListener(); |
| 345 |
if (provider instanceof IPostSelectionProvider) { |
| 346 |
((IPostSelectionProvider) provider).addPostSelectionChangedListener(fSourceEditorSelectionListener); |
| 347 |
} |
| 348 |
else { |
| 349 |
provider.addSelectionChangedListener(fSourceEditorSelectionListener); |
| 350 |
} |
| 351 |
fXSDSelectionListener = new XSDSelectionManagerSelectionListener(); |
| 352 |
getSelectionManager().addSelectionChangedListener(fXSDSelectionListener); |
| 353 |
|
| 354 |
addCommandStackListener(); |
| 355 |
|
| 356 |
XSDEditorPlugin.getPlugin().getPreferenceStore().addPropertyChangeListener(preferenceStoreListener); |
| 357 |
} |
| 358 |
catch (PartInitException e) { |
| 359 |
// log for now, unless we find reason not to |
| 360 |
Logger.log(Logger.INFO, e.getMessage()); |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
public void buildXSDModel() { |
| 366 |
try { |
| 367 |
Document document = ((IDOMModel) getModel()).getDocument(); |
| 368 |
|
| 369 |
boolean schemaNodeExists = document.getElementsByTagNameNS(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "schema").getLength() == 1; |
| 370 |
|
| 371 |
if (document.getChildNodes().getLength() == 0 || !schemaNodeExists) { |
| 372 |
createDefaultSchemaNode(document); |
| 373 |
} |
| 374 |
|
| 375 |
if (document instanceof INodeNotifier) { |
| 376 |
INodeNotifier notifier = (INodeNotifier) document; |
| 377 |
schemalNodeAdapter = (XSDModelAdapter) notifier.getAdapterFor(XSDModelAdapter.class); |
| 378 |
if (schemalNodeAdapter == null) { |
| 379 |
schemalNodeAdapter = new XSDModelAdapter(); |
| 380 |
notifier.addAdapter(schemalNodeAdapter); |
| 381 |
schemalNodeAdapter.createSchema(document.getDocumentElement()); |
| 382 |
} |
| 383 |
} |
| 384 |
} |
| 385 |
catch (Exception e) { |
| 386 |
// XSDEditorPlugin.getPlugin().getMsgLogger().write("Failed to |
| 387 |
// create Model"); |
| 388 |
// XSDEditorPlugin.getPlugin().getMsgLogger().write(e); |
| 389 |
// e.printStackTrace(); |
| 390 |
} |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
// XSDResourceFactoryImpl.validate(xsdSchema, |
| 395 |
// input.getFile().getContents(true)); |
| 396 |
} |
| 397 |
|
| 398 |
public String[] getPropertyCategories() { |
| 399 |
return new String[]{"general", "namespace", "other", "attributes", "documentation", "facets"}; //$NON-NLS-1$ |
| 400 |
} |
| 177 |
|
401 |
|
| 178 |
/** |
402 |
/** |
| 179 |
* @see org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySheetPageContributor#getContributorId() |
403 |
* @see org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySheetPageContributor#getContributorId() |
| 180 |
*/ |
404 |
*/ |
| 181 |
public String getContributorId() |
405 |
public String getContributorId() { |
| 182 |
{ |
406 |
return "org.eclipse.wst.xsd.ui.internal.XSDEditor"; |
| 183 |
return "org.eclipse.wst.xsd.ui.internal.XSDEditor"; |
407 |
// return getSite().getId(); |
| 184 |
//return getSite().getId(); |
408 |
} |
| 185 |
} |
409 |
|
| 186 |
|
410 |
protected CommandStackListener commandStackListener; |
| 187 |
protected CommandStackListener commandStackListener; |
411 |
|
| 188 |
protected void addCommandStackListener() |
412 |
protected void addCommandStackListener() { |
| 189 |
{ |
413 |
if (commandStackListener == null) { |
| 190 |
if (commandStackListener == null) |
414 |
IStructuredTextUndoManager undoManager = getModel().getUndoManager(); |
| 191 |
{ |
415 |
commandStackListener = new CommandStackListener() { |
| 192 |
IStructuredTextUndoManager undoManager = getModel().getUndoManager(); |
416 |
/** |
| 193 |
commandStackListener = new CommandStackListener() |
417 |
* @see org.eclipse.emf.common.command.CommandStackListener#commandStackChanged(EventObject) |
| 194 |
{ |
418 |
*/ |
| 195 |
/** |
419 |
public void commandStackChanged(EventObject event) { |
| 196 |
* @see org.eclipse.emf.common.command.CommandStackListener#commandStackChanged(EventObject) |
420 |
Object obj = event.getSource(); |
| 197 |
*/ |
421 |
if (obj instanceof BasicCommandStack) { |
| 198 |
public void commandStackChanged(EventObject event) |
422 |
BasicCommandStack stack = (BasicCommandStack) obj; |
| 199 |
{ |
423 |
Command recentCommand = stack.getMostRecentCommand(); |
| 200 |
Object obj = event.getSource(); |
424 |
Command redoCommand = stack.getRedoCommand(); |
| 201 |
if (obj instanceof BasicCommandStack) |
425 |
Command undoCommand = stack.getUndoCommand(); |
| 202 |
{ |
426 |
if (recentCommand == redoCommand) { |
| 203 |
BasicCommandStack stack = (BasicCommandStack) obj; |
427 |
// there must have been an undo reset info tasks |
| 204 |
Command recentCommand = stack.getMostRecentCommand(); |
428 |
resetInformationTasks(); |
| 205 |
Command redoCommand = stack.getRedoCommand(); |
429 |
} |
| 206 |
Command undoCommand = stack.getUndoCommand(); |
430 |
} |
| 207 |
if (recentCommand == redoCommand) |
431 |
} |
| 208 |
{ |
432 |
}; |
| 209 |
// there must have been an undo reset info tasks |
433 |
|
| 210 |
resetInformationTasks(); |
434 |
// TODO WTP Port |
| 211 |
} |
435 |
// undoManager.getCommandStack().addCommandStackListener(commandStackListener); |
| 212 |
} |
436 |
|
| 213 |
} |
437 |
} |
| 214 |
}; |
438 |
} |
| 215 |
|
439 |
|
| 216 |
//TODO WTP Port undoManager.getCommandStack().addCommandStackListener(commandStackListener); |
440 |
protected void pageChange(int arg) { |
| 217 |
|
441 |
super.pageChange(arg); |
| 218 |
} |
442 |
} |
| 219 |
} |
443 |
|
| 220 |
|
444 |
protected void removeCommandStackListener() { |
| 221 |
protected void pageChange(int arg) |
445 |
if (commandStackListener != null) { |
| 222 |
{ |
446 |
IStructuredTextUndoManager undoManager = getModel().getUndoManager(); |
| 223 |
super.pageChange(arg); |
447 |
// TODO WTP Port |
| 224 |
} |
448 |
// undoManager.getCommandStack().removeCommandStackListener(commandStackListener); |
| 225 |
|
449 |
} |
| 226 |
protected void removeCommandStackListener() |
450 |
} |
| 227 |
{ |
451 |
|
| 228 |
if (commandStackListener != null) |
452 |
// This is from the IValidateEditEditor interface |
| 229 |
{ |
453 |
/* |
| 230 |
IStructuredTextUndoManager undoManager = getModel().getUndoManager(); |
454 |
* public void undoChange() { StructuredTextUndoManager undoManager = |
| 231 |
//TODO WTP Port undoManager.getCommandStack().removeCommandStackListener(commandStackListener); |
455 |
* textEditor.getModel().getUndoManager(); undoManager.undo(); // Make the |
| 232 |
} |
456 |
* editor clean textEditor.getModel().setDirtyState(false); } |
| 233 |
} |
457 |
*/ |
| 234 |
|
458 |
|
| 235 |
// This is from the IValidateEditEditor interface |
459 |
private class PreferenceStoreListener implements IPropertyChangeListener { |
| 236 |
/* public void undoChange() |
460 |
/** |
| 237 |
{ |
461 |
* @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(PropertyChangeEvent) |
| 238 |
StructuredTextUndoManager undoManager = textEditor.getModel().getUndoManager(); |
462 |
*/ |
| 239 |
undoManager.undo(); |
463 |
public void propertyChange(PropertyChangeEvent event) { |
| 240 |
// Make the editor clean |
464 |
} |
| 241 |
textEditor.getModel().setDirtyState(false); |
465 |
} |
| 242 |
} */ |
466 |
|
| 243 |
|
467 |
protected IPropertyChangeListener preferenceStoreListener = new PreferenceStoreListener(); |
| 244 |
private class PreferenceStoreListener implements IPropertyChangeListener |
468 |
|
| 245 |
{ |
469 |
protected int getDefaultPageTypeIndex() { |
| 246 |
/** |
470 |
int pageIndex = sourcePageIndex; |
| 247 |
* @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(PropertyChangeEvent) |
471 |
|
| 248 |
*/ |
472 |
if (XSDEditorPlugin.getPlugin().getDefaultPage().equals(XSDEditorPlugin.GRAPH_PAGE)) { |
| 249 |
public void propertyChange(PropertyChangeEvent event) |
473 |
if (graphPageIndex != -1) |
| 250 |
{ |
474 |
pageIndex = graphPageIndex; |
| 251 |
} |
475 |
} |
| 252 |
} |
476 |
|
| 253 |
|
477 |
return pageIndex; |
| 254 |
protected IPropertyChangeListener preferenceStoreListener = new PreferenceStoreListener(); |
478 |
} |
| 255 |
|
479 |
|
| 256 |
protected int getDefaultPageTypeIndex() |
480 |
int currentPage = -1; |
| 257 |
{ |
481 |
|
| 258 |
int pageIndex = sourcePageIndex; |
482 |
public String getCurrentPageType() { |
| 259 |
|
|
|
| 260 |
if (XSDEditorPlugin.getPlugin().getDefaultPage().equals(XSDEditorPlugin.GRAPH_PAGE)) |
| 261 |
{ |
| 262 |
if (graphPageIndex != -1) |
| 263 |
pageIndex = graphPageIndex; |
| 264 |
} |
| 265 |
|
| 266 |
return pageIndex; |
| 267 |
} |
| 268 |
|
| 269 |
int currentPage = -1; |
| 270 |
public String getCurrentPageType() |
| 271 |
{ |
| 272 |
// should update pref. for valid pages |
483 |
// should update pref. for valid pages |
| 273 |
if (getActivePage() != -1) |
484 |
if (getActivePage() != -1) { |
| 274 |
{ |
|
|
| 275 |
currentPage = getActivePage(); |
485 |
currentPage = getActivePage(); |
| 276 |
} |
486 |
} |
| 277 |
if (currentPage == graphPageIndex) |
487 |
if (currentPage == graphPageIndex) { |
| 278 |
{ |
|
|
| 279 |
return XSDEditorPlugin.GRAPH_PAGE; |
488 |
return XSDEditorPlugin.GRAPH_PAGE; |
| 280 |
} |
489 |
} |
| 281 |
else |
490 |
else { |
| 282 |
{ |
|
|
| 283 |
return XSDEditorPlugin.SOURCE_PAGE; |
491 |
return XSDEditorPlugin.SOURCE_PAGE; |
| 284 |
} |
492 |
} |
|
|
493 |
} |
| 494 |
|
| 495 |
public Object getActivePart() { |
| 496 |
return getSite().getWorkbenchWindow().getActivePage().getActivePart(); |
| 497 |
} |
| 498 |
|
| 499 |
public void dispose() { |
| 500 |
// some things in the configuration need to clean |
| 501 |
// up after themselves |
| 502 |
if (fOutlinePage != null) { |
| 503 |
if (fOutlinePage instanceof ConfigurableContentOutlinePage && fOutlineListener != null) { |
| 504 |
((ConfigurableContentOutlinePage) fOutlinePage).removeDoubleClickListener(fOutlineListener); |
| 505 |
} |
| 506 |
if (fOutlineListener != null) { |
| 507 |
fOutlinePage.removeSelectionChangedListener(fOutlineListener); |
| 508 |
} |
| 509 |
} |
| 510 |
ISelectionProvider provider = getTextEditor().getSelectionProvider(); |
| 511 |
if (provider instanceof IPostSelectionProvider) { |
| 512 |
((IPostSelectionProvider) provider).removePostSelectionChangedListener(fSourceEditorSelectionListener); |
| 513 |
} |
| 514 |
else { |
| 515 |
provider.removeSelectionChangedListener(fSourceEditorSelectionListener); |
| 516 |
} |
| 517 |
getSelectionManager().removeSelectionChangedListener(fXSDSelectionListener); |
| 518 |
|
| 519 |
// propertyChangeListener.dispose(); |
| 520 |
removeCommandStackListener(); |
| 521 |
|
| 522 |
XSDEditorPlugin.getPlugin().setDefaultPage(getCurrentPageType()); |
| 523 |
XSDEditorPlugin.getPlugin().getPreferenceStore().removePropertyChangeListener(preferenceStoreListener); |
| 524 |
|
| 525 |
getSite().getPage().removePartListener(partListener); |
| 526 |
|
| 527 |
// KB: Temporary solution for bug 99468 |
| 528 |
IStructuredModel myModel = textEditor.getModel(); |
| 529 |
if (myModel != null && myModel instanceof IStructuredDocumentListener) |
| 530 |
myModel.getStructuredDocument().removeDocumentChangingListener((IStructuredDocumentListener) myModel); |
| 531 |
|
| 532 |
textEditor = null; |
| 533 |
resourceFile = null; |
| 534 |
xsdSelectionManager = null; |
| 535 |
schemalNodeAdapter = null; |
| 536 |
result = null; |
| 537 |
partListener = null; |
| 538 |
commandStackListener = null; |
| 539 |
preferenceStoreListener = null; |
| 540 |
openOnSelectionHelper = null; |
| 541 |
graphViewer = null; |
| 542 |
|
| 543 |
super.dispose(); |
| 544 |
|
| 545 |
// release the schema model |
| 546 |
// |
| 547 |
if (schemalNodeAdapter != null) { |
| 548 |
schemalNodeAdapter.clear(); |
| 549 |
schemalNodeAdapter = null; |
| 550 |
} |
| 551 |
} |
| 552 |
|
| 553 |
protected boolean loadFile() { |
| 554 |
Object input = getEditorInput(); |
| 555 |
|
| 556 |
if (input instanceof IFileEditorInput) { |
| 557 |
resourceFile = ((IFileEditorInput) input).getFile(); |
| 558 |
} |
| 559 |
else if (input instanceof ILocationProvider) { |
| 560 |
IPath path = ((ILocationProvider) input).getPath(input); |
| 561 |
String ext = path.getFileExtension(); |
| 562 |
if (ext != null && ext.equals("xsd")) { |
| 563 |
return true; |
| 564 |
} |
| 565 |
return false; |
| 566 |
} |
| 567 |
else { |
| 568 |
return false; |
| 569 |
} |
| 570 |
return true; |
| 571 |
} |
| 572 |
|
| 573 |
/** |
| 574 |
* Method openOnGlobalReference. The comp argument is a resolved xsd |
| 575 |
* schema object from another file. This is created and called from |
| 576 |
* another schema model to allow F3 navigation to open a new editor and |
| 577 |
* choose the referenced object within that editor context |
| 578 |
* |
| 579 |
* @param comp |
| 580 |
*/ |
| 581 |
public void openOnGlobalReference(XSDConcreteComponent comp) { |
| 582 |
openOnSelectionHelper.openOnGlobalReference(comp); |
| 583 |
} |
| 584 |
|
| 585 |
protected OpenOnSelectionHelper openOnSelectionHelper; |
| 586 |
|
| 587 |
public OpenOnSelectionHelper getOpenOnSelectionHelper() { |
| 588 |
return openOnSelectionHelper; |
| 589 |
} |
| 590 |
|
| 591 |
/** |
| 592 |
* @see org.eclipse.wst.xsd.ui.internal.XSDMultiPageEditorPart#createTextEditor() |
| 593 |
*/ |
| 594 |
protected StructuredTextEditor createTextEditor() { |
| 595 |
textEditor = new StructuredTextEditor(); |
| 596 |
return textEditor; |
| 597 |
} |
| 598 |
|
| 599 |
/* |
| 600 |
* @see StructuredTextMultiPageEditorPart#createSourcePage() |
| 601 |
*/ |
| 602 |
protected void createSourcePage() throws PartInitException { |
| 603 |
super.createSourcePage(); |
| 604 |
} |
| 605 |
|
| 606 |
int sourcePageIndex = -1; |
| 607 |
|
| 608 |
/** |
| 609 |
* Adds the source page of the multi-page editor. |
| 610 |
*/ |
| 611 |
protected void addSourcePage() throws PartInitException { |
| 612 |
|
| 613 |
sourcePageIndex = addPage(textEditor, getEditorInput()); |
| 614 |
setPageText(sourcePageIndex, XSDEditorPlugin.getXSDString("_UI_TAB_SOURCE")); |
| 615 |
|
| 616 |
// the update's critical, to get viewer selection manager and |
| 617 |
// highlighting to work |
| 618 |
textEditor.update(); |
| 619 |
firePropertyChange(PROP_TITLE); |
| 620 |
} |
| 621 |
|
| 622 |
int graphPageIndex = -1; |
| 623 |
XSDGraphViewer graphViewer; |
| 624 |
|
| 625 |
/** |
| 626 |
* Creates the graph page and adds it to the multi-page editor. |
| 627 |
*/ |
| 628 |
protected void createAndAddGraphPage() throws PartInitException { |
| 629 |
graphViewer = new XSDGraphViewer(this); |
| 630 |
graphViewer.setSchema(getXSDSchema()); |
| 631 |
Control graphControl = graphViewer.createControl(getContainer()); |
| 632 |
graphPageIndex = addPage(graphControl); |
| 633 |
setPageText(graphPageIndex, XSDEditorPlugin.getXSDString("_UI_TAB_GRAPH")); |
| 634 |
|
| 635 |
// graphViewer.setViewerSelectionManager(textEditor.getViewerSelectionManager()); |
| 636 |
graphViewer.setSelectionManager(getSelectionManager()); |
| 637 |
|
| 638 |
// this forces the editor to initially select the top level schema |
| 639 |
// object |
| 640 |
// |
| 641 |
if (getXSDSchema() != null) { |
| 642 |
getSelectionManager().setSelection(new StructuredSelection(getXSDSchema())); |
| 643 |
} |
| 644 |
} |
| 645 |
|
| 646 |
protected XSDModelAdapterFactoryImpl xsdModelAdapterFactory; |
| 647 |
protected XSDAdapterFactoryLabelProvider adapterFactoryLabelProvider; |
| 648 |
private IPropertySheetPage fPropertySheetPage; |
| 649 |
private IContentOutlinePage fOutlinePage; |
| 650 |
private OutlineTreeSelectionChangeListener fOutlineListener; |
| 651 |
private SourceEditorSelectionListener fSourceEditorSelectionListener; |
| 652 |
private XSDSelectionManagerSelectionListener fXSDSelectionListener; |
| 653 |
|
| 654 |
/* |
| 655 |
* @see IAdaptable#getAdapter(Class) |
| 656 |
*/ |
| 657 |
public Object getAdapter(Class key) { |
| 658 |
Object result = null; |
| 659 |
if (key == ISelectionProvider.class) { |
| 660 |
result = xsdSelectionManager; |
| 661 |
} |
| 662 |
if (IPropertySheetPage.class.equals(key)) { |
| 663 |
fPropertySheetPage = new XSDTabbedPropertySheetPage(this); |
| 664 |
|
| 665 |
((XSDTabbedPropertySheetPage) fPropertySheetPage).setXSDModelAdapterFactory(xsdModelAdapterFactory); |
| 666 |
((XSDTabbedPropertySheetPage) fPropertySheetPage).setSelectionManager(getSelectionManager()); |
| 667 |
((XSDTabbedPropertySheetPage) fPropertySheetPage).setXSDSchema(getXSDSchema()); |
| 668 |
|
| 669 |
return fPropertySheetPage; |
| 670 |
} |
| 671 |
else if (IContentOutlinePage.class.equals(key)) { |
| 672 |
if (fOutlinePage == null || fOutlinePage.getControl() == null || fOutlinePage.getControl().isDisposed()) { |
| 673 |
IContentOutlinePage page = (IContentOutlinePage) super.getAdapter(key); |
| 674 |
if (page != null) { |
| 675 |
fOutlineListener = new OutlineTreeSelectionChangeListener(); |
| 676 |
page.addSelectionChangedListener(fOutlineListener); |
| 677 |
if (page instanceof ConfigurableContentOutlinePage) { |
| 678 |
((ConfigurableContentOutlinePage) page).addDoubleClickListener(fOutlineListener); |
| 679 |
} |
| 680 |
} |
| 681 |
fOutlinePage = page; |
| 682 |
// XSDContentOutlinePage outlinePage = new |
| 683 |
// XSDContentOutlinePage(this); |
| 684 |
// XSDContentProvider xsdContentProvider = new |
| 685 |
// XSDContentProvider(xsdModelAdapterFactory); |
| 686 |
// xsdContentProvider.setXSDSchema(getXSDSchema()); |
| 687 |
// outlinePage.setContentProvider(xsdContentProvider); |
| 688 |
// outlinePage.setLabelProvider(adapterFactoryLabelProvider); |
| 689 |
// outlinePage.setModel(getXSDSchema().getDocument()); |
| 690 |
// |
| 691 |
// fOutlinePage = outlinePage; |
| 692 |
} |
| 693 |
return fOutlinePage; |
| 694 |
} |
| 695 |
else { |
| 696 |
result = super.getAdapter(key); |
| 697 |
} |
| 698 |
return result; |
| 699 |
} |
| 700 |
|
| 701 |
|
| 702 |
public XSDModelAdapterFactoryImpl getXSDModelAdapterFactory() { |
| 703 |
return xsdModelAdapterFactory; |
| 704 |
} |
| 705 |
|
| 706 |
public XSDAdapterFactoryLabelProvider getLabelProvider() { |
| 707 |
return adapterFactoryLabelProvider; |
| 708 |
} |
| 709 |
|
| 710 |
|
| 711 |
public XSDSelectionManager getSelectionManager() { |
| 712 |
return xsdSelectionManager; |
| 713 |
} |
| 714 |
|
| 715 |
/** |
| 716 |
* @see org.eclipse.wst.xsd.ui.internal.XSDMultiPageEditorPart#doSaveAs() |
| 717 |
*/ |
| 718 |
public void doSaveAs() { |
| 719 |
super.doSaveAs(); |
| 720 |
} |
| 721 |
|
| 722 |
public void doSave(org.eclipse.core.runtime.IProgressMonitor monitor) { |
| 723 |
super.doSave(monitor); |
| 724 |
} |
| 725 |
|
| 726 |
public void reparseSchema() { |
| 727 |
// TODO cs : Are there no better ways to make the model |
| 728 |
// reload it's dependencies? This seems rather extreme. |
| 729 |
// |
| 730 |
Document document = ((IDOMModel) getModel()).getDocument(); |
| 731 |
if (schemalNodeAdapter != null) { |
| 732 |
schemalNodeAdapter.createSchema(document.getDocumentElement()); |
| 733 |
} |
| 734 |
} |
| 735 |
|
| 736 |
/** |
| 737 |
* Returns the xsdSchema. |
| 738 |
* |
| 739 |
* @return XSDSchema |
| 740 |
*/ |
| 741 |
public XSDSchema getXSDSchema() { |
| 742 |
return schemalNodeAdapter != null ? schemalNodeAdapter.getSchema() : null; |
| 743 |
} |
| 744 |
|
| 745 |
|
| 746 |
/** |
| 747 |
* Returns the resourceFile. |
| 748 |
* |
| 749 |
* @return IFile |
| 750 |
*/ |
| 751 |
public IFile getFileResource() { |
| 752 |
return resourceFile; |
| 753 |
} |
| 754 |
|
| 755 |
/** |
| 756 |
* Get the IDocument from the text viewer |
| 757 |
*/ |
| 758 |
public IDocument getEditorIDocument() { |
| 759 |
IDocument document = textEditor.getTextViewer().getDocument(); |
| 760 |
return document; |
| 761 |
} |
| 762 |
|
| 763 |
/** |
| 764 |
* Create ref integrity tasks in task list |
| 765 |
*/ |
| 766 |
public void createTasksInTaskList(ArrayList messages) { |
| 767 |
// DisplayErrorInTaskList tasks = new |
| 768 |
// DisplayErrorInTaskList(getEditorIDocument(), getFileResource(), |
| 769 |
// messages); |
| 770 |
// tasks.run(); |
| 771 |
} |
| 772 |
|
| 773 |
public void resetInformationTasks() { |
| 774 |
// DisplayErrorInTaskList.removeInfoMarkers(getFileResource()); |
| 775 |
} |
| 776 |
|
| 777 |
public XSDGraphViewer getGraphViewer() { |
| 778 |
return graphViewer; |
| 779 |
} |
| 780 |
|
| 781 |
public IEditorPart getActiveEditorPage() { |
| 782 |
return getActiveEditor(); |
| 783 |
} |
| 784 |
|
| 785 |
public StructuredTextEditor getTextEditor() { |
| 786 |
return textEditor; |
| 787 |
} |
| 788 |
|
| 789 |
class InternalPartListener implements IPartListener { |
| 790 |
XSDEditor editor; |
| 791 |
|
| 792 |
public InternalPartListener(XSDEditor editor) { |
| 793 |
this.editor = editor; |
| 794 |
} |
| 795 |
|
| 796 |
public void partActivated(IWorkbenchPart part) { |
| 797 |
if (part == editor) { |
| 798 |
ISelection selection = getSelectionManager().getSelection(); |
| 799 |
if (selection != null) { |
| 800 |
if (getCurrentPageType().equals(XSDEditorPlugin.GRAPH_PAGE)) { |
| 801 |
getSelectionManager().selectionChanged(new SelectionChangedEvent(editor.getGraphViewer().getComponentViewer(), selection)); |
| 802 |
} |
| 803 |
else if (getCurrentPageType().equals(XSDEditorPlugin.SOURCE_PAGE)) { |
| 804 |
getSelectionManager().setSelection(selection); |
| 805 |
} |
| 806 |
} |
| 807 |
} |
| 808 |
} |
| 809 |
|
| 810 |
public void partBroughtToTop(IWorkbenchPart part) { |
| 811 |
} |
| 812 |
|
| 813 |
public void partClosed(IWorkbenchPart part) { |
| 814 |
} |
| 815 |
|
| 816 |
public void partDeactivated(IWorkbenchPart part) { |
| 817 |
} |
| 818 |
|
| 819 |
public void partOpened(IWorkbenchPart part) { |
| 820 |
} |
| 821 |
} |
| 822 |
|
| 823 |
|
| 824 |
/** |
| 825 |
* Method createDefaultSchemaNode. Should only be called to insert a |
| 826 |
* schema node into an empty document |
| 827 |
*/ |
| 828 |
public void createDefaultSchemaNode(Document document) { |
| 829 |
if (document.getChildNodes().getLength() == 0) { |
| 830 |
// if it is a completely empty file, then add the encoding and |
| 831 |
// version processing instruction |
| 832 |
// TODO String encoding = EncodingHelper.getDefaultEncodingTag(); |
| 833 |
String encoding = "UTF-8"; |
| 834 |
ProcessingInstruction instr = document.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"" + encoding + "\""); |
| 835 |
document.appendChild(instr); |
| 836 |
} |
| 837 |
|
| 838 |
// Create a default schema tag now |
| 839 |
|
| 840 |
// String defaultPrefixForTargetNamespace = |
| 841 |
// getFileResource().getProjectRelativePath().removeFileExtension().lastSegment(); |
| 842 |
String defaultPrefixForTargetNamespace = "tns"; |
| 843 |
String prefixForSchemaNamespace = ""; |
| 844 |
String schemaNamespaceAttribute = "xmlns"; |
| 845 |
if (XSDEditorPlugin.getPlugin().isQualifyXMLSchemaLanguage()) { |
| 846 |
// Added this if check before disallowing blank prefixes in the |
| 847 |
// preferences... |
| 848 |
// Can take this out. See also NewXSDWizard |
| 849 |
if (XSDEditorPlugin.getPlugin().getXMLSchemaPrefix().trim().length() > 0) { |
| 850 |
prefixForSchemaNamespace = XSDEditorPlugin.getPlugin().getXMLSchemaPrefix() + ":"; |
| 851 |
schemaNamespaceAttribute += ":" + XSDEditorPlugin.getPlugin().getXMLSchemaPrefix(); |
| 852 |
} |
| 853 |
} |
| 854 |
|
| 855 |
document.appendChild(document.createTextNode("\n")); |
| 856 |
Element element = document.createElement(prefixForSchemaNamespace + XSDConstants.SCHEMA_ELEMENT_TAG); |
| 857 |
|
| 858 |
element.setAttribute(schemaNamespaceAttribute, "http://www.w3.org/2001/XMLSchema"); |
| 859 |
|
| 860 |
String defaultTargetURI = XSDEditorPlugin.getPlugin().getXMLSchemaTargetNamespace(); |
| 861 |
element.setAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE, defaultTargetURI); |
| 862 |
element.setAttribute("xmlns:" + defaultPrefixForTargetNamespace, defaultTargetURI); |
| 863 |
|
| 864 |
document.appendChild(element); |
| 285 |
} |
865 |
} |
| 286 |
|
|
|
| 287 |
public Object getActivePart() |
| 288 |
{ |
| 289 |
return getSite().getWorkbenchWindow().getActivePage().getActivePart(); |
| 290 |
} |
| 291 |
|
| 292 |
public void dispose() |
| 293 |
{ |
| 294 |
// propertyChangeListener.dispose(); |
| 295 |
removeCommandStackListener(); |
| 296 |
|
| 297 |
XSDEditorPlugin.getPlugin().setDefaultPage(getCurrentPageType()); |
| 298 |
XSDEditorPlugin.getPlugin().getPreferenceStore().removePropertyChangeListener(preferenceStoreListener); |
| 299 |
|
| 300 |
getSite().getPage().removePartListener(partListener); |
| 301 |
|
| 302 |
// KB: Temporary solution for bug 99468 |
| 303 |
IStructuredModel myModel = textEditor.getModel(); |
| 304 |
if (myModel != null && myModel instanceof IStructuredDocumentListener) |
| 305 |
myModel.getStructuredDocument().removeDocumentChangingListener((IStructuredDocumentListener)myModel); |
| 306 |
|
| 307 |
textEditor = null; |
| 308 |
resourceFile = null; |
| 309 |
xsdSelectionManager = null; |
| 310 |
schemalNodeAdapter = null; |
| 311 |
result = null; |
| 312 |
partListener = null; |
| 313 |
commandStackListener = null; |
| 314 |
preferenceStoreListener = null; |
| 315 |
openOnSelectionHelper = null; |
| 316 |
graphViewer = null; |
| 317 |
|
| 318 |
super.dispose(); |
| 319 |
|
| 320 |
// release the schema model |
| 321 |
// |
| 322 |
if (schemalNodeAdapter != null) |
| 323 |
{ |
| 324 |
schemalNodeAdapter.clear(); |
| 325 |
schemalNodeAdapter = null; |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
protected boolean loadFile() |
| 330 |
{ |
| 331 |
Object input = getEditorInput(); |
| 332 |
|
| 333 |
if (input instanceof IFileEditorInput) |
| 334 |
{ |
| 335 |
resourceFile = ((IFileEditorInput) input).getFile(); |
| 336 |
} |
| 337 |
else if (input instanceof ILocationProvider) |
| 338 |
{ |
| 339 |
IPath path = ((ILocationProvider)input).getPath(input); |
| 340 |
String ext = path.getFileExtension(); |
| 341 |
if (ext != null && ext.equals("xsd")) |
| 342 |
{ |
| 343 |
return true; |
| 344 |
} |
| 345 |
return false; |
| 346 |
} |
| 347 |
else |
| 348 |
{ |
| 349 |
return false; |
| 350 |
} |
| 351 |
return true; |
| 352 |
} |
| 353 |
|
| 354 |
/** |
| 355 |
* Method openOnGlobalReference. |
| 356 |
* The comp argument is a resolved xsd schema object from another file. This is created and called from another |
| 357 |
* schema model to allow F3 navigation to open a new editor and choose the referenced object within that editor context |
| 358 |
* @param comp |
| 359 |
*/ |
| 360 |
public void openOnGlobalReference(XSDConcreteComponent comp) |
| 361 |
{ |
| 362 |
openOnSelectionHelper.openOnGlobalReference(comp); |
| 363 |
} |
| 364 |
|
| 365 |
protected OpenOnSelectionHelper openOnSelectionHelper; |
| 366 |
|
| 367 |
public OpenOnSelectionHelper getOpenOnSelectionHelper() |
| 368 |
{ |
| 369 |
return openOnSelectionHelper; |
| 370 |
} |
| 371 |
|
| 372 |
/** |
| 373 |
* @see org.eclipse.wst.xsd.ui.internal.XSDMultiPageEditorPart#createTextEditor() |
| 374 |
*/ |
| 375 |
protected StructuredTextEditor createTextEditor() |
| 376 |
{ |
| 377 |
return new XSDTextEditor(this); |
| 378 |
} |
| 379 |
|
| 380 |
/* |
| 381 |
* @see StructuredTextMultiPageEditorPart#createSourcePage() |
| 382 |
*/ |
| 383 |
protected void createSourcePage() throws PartInitException |
| 384 |
{ |
| 385 |
super.createSourcePage(); |
| 386 |
|
| 387 |
textEditor = (XSDTextEditor) getTextEditor(); |
| 388 |
|
| 389 |
openOnSelectionHelper = new OpenOnSelectionHelper(textEditor); |
| 390 |
} |
| 391 |
|
| 392 |
int sourcePageIndex = -1; |
| 393 |
/** |
| 394 |
* Adds the source page of the multi-page editor. |
| 395 |
*/ |
| 396 |
protected void addSourcePage() throws PartInitException { |
| 397 |
|
| 398 |
sourcePageIndex = addPage(textEditor, getEditorInput()); |
| 399 |
setPageText(sourcePageIndex, XSDEditorPlugin.getXSDString("_UI_TAB_SOURCE")); |
| 400 |
|
| 401 |
// the update's critical, to get viewer selection manager and highlighting to work |
| 402 |
textEditor.update(); |
| 403 |
firePropertyChange(PROP_TITLE); |
| 404 |
} |
| 405 |
|
| 406 |
int graphPageIndex = -1; |
| 407 |
XSDGraphViewer graphViewer; |
| 408 |
|
| 409 |
/** |
| 410 |
* Creates the graph page and adds it to the multi-page editor. |
| 411 |
*/ |
| 412 |
protected void createAndAddGraphPage() throws PartInitException |
| 413 |
{ |
| 414 |
graphViewer = new XSDGraphViewer(this); |
| 415 |
graphViewer.setSchema(getXSDSchema()); |
| 416 |
Control graphControl = graphViewer.createControl(getContainer()); |
| 417 |
graphPageIndex = addPage(graphControl); |
| 418 |
setPageText(graphPageIndex, XSDEditorPlugin.getXSDString("_UI_TAB_GRAPH")); |
| 419 |
|
| 420 |
// graphViewer.setViewerSelectionManager(textEditor.getViewerSelectionManager()); |
| 421 |
graphViewer.setSelectionManager(getSelectionManager()); |
| 422 |
|
| 423 |
// this forces the editor to initially select the top level schema object |
| 424 |
// |
| 425 |
if (textEditor.getXSDSchema() != null) |
| 426 |
{ |
| 427 |
getSelectionManager().setSelection(new StructuredSelection(textEditor.getXSDSchema())); |
| 428 |
} |
| 429 |
} |
| 430 |
|
| 431 |
/* |
| 432 |
* @see IAdaptable#getAdapter(Class) |
| 433 |
*/ |
| 434 |
public Object getAdapter(Class key) |
| 435 |
{ |
| 436 |
Object result = null; |
| 437 |
if (key == ISelectionProvider.class) |
| 438 |
{ |
| 439 |
result = xsdSelectionManager; |
| 440 |
} |
| 441 |
else |
| 442 |
{ |
| 443 |
result = textEditor.getAdapter(key); |
| 444 |
} |
| 445 |
return result; |
| 446 |
} |
| 447 |
|
| 448 |
public XSDSelectionManager getSelectionManager() |
| 449 |
{ |
| 450 |
return xsdSelectionManager; |
| 451 |
} |
| 452 |
|
| 453 |
/** |
| 454 |
* @see org.eclipse.wst.xsd.ui.internal.XSDMultiPageEditorPart#doSaveAs() |
| 455 |
*/ |
| 456 |
public void doSaveAs() |
| 457 |
{ |
| 458 |
super.doSaveAs(); |
| 459 |
} |
| 460 |
|
| 461 |
public void doSave(org.eclipse.core.runtime.IProgressMonitor monitor) |
| 462 |
{ |
| 463 |
super.doSave(monitor); |
| 464 |
} |
| 465 |
|
| 466 |
public void reparseSchema() |
| 467 |
{ |
| 468 |
// TODO cs : Are there no better ways to make the model |
| 469 |
// reload it's dependencies? This seems rather extreme. |
| 470 |
// |
| 471 |
Document document = ((IDOMModel)getModel()).getDocument(); |
| 472 |
if (schemalNodeAdapter != null) |
| 473 |
{ |
| 474 |
schemalNodeAdapter.createSchema(document.getDocumentElement()); |
| 475 |
} |
| 476 |
} |
| 477 |
|
| 478 |
/** |
| 479 |
* Returns the xsdSchema. |
| 480 |
* @return XSDSchema |
| 481 |
*/ |
| 482 |
public XSDSchema getXSDSchema() |
| 483 |
{ |
| 484 |
return schemalNodeAdapter != null ? schemalNodeAdapter.getSchema() : null; |
| 485 |
} |
| 486 |
|
| 487 |
|
| 488 |
/** |
| 489 |
* Returns the resourceFile. |
| 490 |
* @return IFile |
| 491 |
*/ |
| 492 |
public IFile getFileResource() |
| 493 |
{ |
| 494 |
return resourceFile; |
| 495 |
} |
| 496 |
|
| 497 |
/** |
| 498 |
* Get the IDocument from the text viewer |
| 499 |
*/ |
| 500 |
public IDocument getEditorIDocument() |
| 501 |
{ |
| 502 |
IDocument document = textEditor.getTextViewer().getDocument(); |
| 503 |
return document; |
| 504 |
} |
| 505 |
|
| 506 |
/** |
| 507 |
* Create ref integrity tasks in task list |
| 508 |
*/ |
| 509 |
public void createTasksInTaskList(ArrayList messages) |
| 510 |
{ |
| 511 |
// DisplayErrorInTaskList tasks = new DisplayErrorInTaskList(getEditorIDocument(), getFileResource(), messages); |
| 512 |
// tasks.run(); |
| 513 |
} |
| 514 |
|
| 515 |
public void resetInformationTasks() |
| 516 |
{ |
| 517 |
// DisplayErrorInTaskList.removeInfoMarkers(getFileResource()); |
| 518 |
} |
| 519 |
|
| 520 |
public XSDGraphViewer getGraphViewer() |
| 521 |
{ |
| 522 |
return graphViewer; |
| 523 |
} |
| 524 |
|
| 525 |
public IEditorPart getActiveEditorPage() |
| 526 |
{ |
| 527 |
return getActiveEditor(); |
| 528 |
} |
| 529 |
|
| 530 |
public XSDTextEditor getXSDTextEditor() |
| 531 |
{ |
| 532 |
return textEditor; |
| 533 |
} |
| 534 |
|
| 535 |
class InternalPartListener implements IPartListener |
| 536 |
{ |
| 537 |
XSDEditor editor; |
| 538 |
public InternalPartListener(XSDEditor editor) |
| 539 |
{ |
| 540 |
this.editor = editor; |
| 541 |
} |
| 542 |
|
| 543 |
public void partActivated(IWorkbenchPart part) |
| 544 |
{ |
| 545 |
if (part == editor) |
| 546 |
{ |
| 547 |
ISelection selection = getSelectionManager().getSelection(); |
| 548 |
if (selection != null) |
| 549 |
{ |
| 550 |
if (getCurrentPageType().equals(XSDEditorPlugin.GRAPH_PAGE)) |
| 551 |
{ |
| 552 |
getSelectionManager().selectionChanged(new SelectionChangedEvent(editor.getGraphViewer().getComponentViewer(), selection)); |
| 553 |
} |
| 554 |
else if (getCurrentPageType().equals(XSDEditorPlugin.SOURCE_PAGE)) |
| 555 |
{ |
| 556 |
getSelectionManager().setSelection(selection); |
| 557 |
} |
| 558 |
} |
| 559 |
} |
| 560 |
} |
| 561 |
|
| 562 |
public void partBroughtToTop(IWorkbenchPart part) |
| 563 |
{ |
| 564 |
} |
| 565 |
|
| 566 |
public void partClosed(IWorkbenchPart part) |
| 567 |
{ |
| 568 |
} |
| 569 |
|
| 570 |
public void partDeactivated(IWorkbenchPart part) |
| 571 |
{ |
| 572 |
} |
| 573 |
|
| 574 |
public void partOpened(IWorkbenchPart part) |
| 575 |
{ |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
/** |
| 581 |
* Method createDefaultSchemaNode. Should only be called to insert a schema node into an empty document |
| 582 |
*/ |
| 583 |
public void createDefaultSchemaNode(Document document) |
| 584 |
{ |
| 585 |
if (document.getChildNodes().getLength() == 0) |
| 586 |
{ |
| 587 |
// if it is a completely empty file, then add the encoding and version processing instruction |
| 588 |
//TODO String encoding = EncodingHelper.getDefaultEncodingTag(); |
| 589 |
String encoding = "UTF-8"; |
| 590 |
ProcessingInstruction instr = document.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"" + encoding + "\""); |
| 591 |
document.appendChild(instr); |
| 592 |
} |
| 593 |
|
| 594 |
// Create a default schema tag now |
| 595 |
|
| 596 |
// String defaultPrefixForTargetNamespace = getFileResource().getProjectRelativePath().removeFileExtension().lastSegment(); |
| 597 |
String defaultPrefixForTargetNamespace = "tns"; |
| 598 |
String prefixForSchemaNamespace = ""; |
| 599 |
String schemaNamespaceAttribute = "xmlns"; |
| 600 |
if (XSDEditorPlugin.getPlugin().isQualifyXMLSchemaLanguage()) |
| 601 |
{ |
| 602 |
// Added this if check before disallowing blank prefixes in the preferences... |
| 603 |
// Can take this out. See also NewXSDWizard |
| 604 |
if (XSDEditorPlugin.getPlugin().getXMLSchemaPrefix().trim().length() > 0) |
| 605 |
{ |
| 606 |
prefixForSchemaNamespace = XSDEditorPlugin.getPlugin().getXMLSchemaPrefix() + ":"; |
| 607 |
schemaNamespaceAttribute += ":" + XSDEditorPlugin.getPlugin().getXMLSchemaPrefix(); |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
document.appendChild(document.createTextNode("\n")); |
| 612 |
Element element = document.createElement(prefixForSchemaNamespace + XSDConstants.SCHEMA_ELEMENT_TAG); |
| 613 |
|
| 614 |
element.setAttribute(schemaNamespaceAttribute,"http://www.w3.org/2001/XMLSchema"); |
| 615 |
|
| 616 |
String defaultTargetURI = XSDEditorPlugin.getPlugin().getXMLSchemaTargetNamespace(); |
| 617 |
element.setAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE, defaultTargetURI); |
| 618 |
element.setAttribute("xmlns:" + defaultPrefixForTargetNamespace, defaultTargetURI); |
| 619 |
|
| 620 |
document.appendChild(element); |
| 621 |
} |
| 622 |
} |
866 |
} |