Lines 33-38
Link Here
|
33 |
import org.eclipse.emf.common.notify.Notification; |
33 |
import org.eclipse.emf.common.notify.Notification; |
34 |
import org.eclipse.emf.common.notify.Notifier; |
34 |
import org.eclipse.emf.common.notify.Notifier; |
35 |
import org.eclipse.emf.common.ui.URIEditorInput; |
35 |
import org.eclipse.emf.common.ui.URIEditorInput; |
|
|
36 |
import org.eclipse.emf.common.util.URI; |
36 |
import org.eclipse.emf.ecore.EObject; |
37 |
import org.eclipse.emf.ecore.EObject; |
37 |
import org.eclipse.emf.ecore.resource.Resource; |
38 |
import org.eclipse.emf.ecore.resource.Resource; |
38 |
import org.eclipse.emf.ecore.resource.ResourceSet; |
39 |
import org.eclipse.emf.ecore.resource.ResourceSet; |
Lines 52-57
Link Here
|
52 |
import org.eclipse.gmf.runtime.emf.core.resources.GMFResourceFactory; |
53 |
import org.eclipse.gmf.runtime.emf.core.resources.GMFResourceFactory; |
53 |
import org.eclipse.gmf.runtime.notation.Diagram; |
54 |
import org.eclipse.gmf.runtime.notation.Diagram; |
54 |
import org.eclipse.jface.operation.IRunnableContext; |
55 |
import org.eclipse.jface.operation.IRunnableContext; |
|
|
56 |
import org.eclipse.osgi.util.NLS; |
55 |
import org.eclipse.swt.widgets.Display; |
57 |
import org.eclipse.swt.widgets.Display; |
56 |
import org.eclipse.ui.IEditorInput; |
58 |
import org.eclipse.ui.IEditorInput; |
57 |
import org.eclipse.ui.part.FileEditorInput; |
59 |
import org.eclipse.ui.part.FileEditorInput; |
Lines 66-73
Link Here
|
66 |
*/ |
68 |
*/ |
67 |
protected ElementInfo createElementInfo(Object element) throws CoreException { |
69 |
protected ElementInfo createElementInfo(Object element) throws CoreException { |
68 |
if (false == element instanceof FileEditorInput && false == element instanceof URIEditorInput) { |
70 |
if (false == element instanceof FileEditorInput && false == element instanceof URIEditorInput) { |
69 |
throw new CoreException(new Status(IStatus.ERROR, GMFGraphDiagramEditorPlugin.ID, 0, |
71 |
throw new CoreException(new Status(IStatus.ERROR, GMFGraphDiagramEditorPlugin.ID, 0, NLS.bind(Messages.GMFGraphDocumentProvider_IncorrectInputError, new Object[] { element, |
70 |
"Incorrect element used: " + element + " instead of org.eclipse.ui.part.FileEditorInput or org.eclipse.emf.common.ui.URIEditorInput", null)); //$NON-NLS-1$ //$NON-NLS-2$ |
72 |
"org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), null)); |
71 |
} |
73 |
} |
72 |
IEditorInput editorInput = (IEditorInput) element; |
74 |
IEditorInput editorInput = (IEditorInput) element; |
73 |
IDiagramDocument document = (IDiagramDocument) createDocument(editorInput); |
75 |
IDiagramDocument document = (IDiagramDocument) createDocument(editorInput); |
Lines 83-90
Link Here
|
83 |
*/ |
85 |
*/ |
84 |
protected IDocument createDocument(Object element) throws CoreException { |
86 |
protected IDocument createDocument(Object element) throws CoreException { |
85 |
if (false == element instanceof FileEditorInput && false == element instanceof URIEditorInput) { |
87 |
if (false == element instanceof FileEditorInput && false == element instanceof URIEditorInput) { |
86 |
throw new CoreException(new Status(IStatus.ERROR, GMFGraphDiagramEditorPlugin.ID, 0, |
88 |
throw new CoreException(new Status(IStatus.ERROR, GMFGraphDiagramEditorPlugin.ID, 0, NLS.bind(Messages.GMFGraphDocumentProvider_IncorrectInputError, new Object[] { element, |
87 |
"Incorrect element used: " + element + " instead of org.eclipse.ui.part.FileEditorInput or org.eclipse.emf.common.ui.URIEditorInput", null)); //$NON-NLS-1$ //$NON-NLS-2$ |
89 |
"org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), null)); |
88 |
} |
90 |
} |
89 |
IDocument document = createEmptyDocument(); |
91 |
IDocument document = createEmptyDocument(); |
90 |
setDocumentContent(document, (IEditorInput) element); |
92 |
setDocumentContent(document, (IEditorInput) element); |
Lines 182-188
Link Here
|
182 |
Diagram diagram = DiagramIOUtil.load(domain, storage, true, getProgressMonitor()); |
184 |
Diagram diagram = DiagramIOUtil.load(domain, storage, true, getProgressMonitor()); |
183 |
document.setContent(diagram); |
185 |
document.setContent(diagram); |
184 |
} else if (element instanceof URIEditorInput) { |
186 |
} else if (element instanceof URIEditorInput) { |
185 |
org.eclipse.emf.common.util.URI uri = ((URIEditorInput) element).getURI(); |
187 |
URI uri = ((URIEditorInput) element).getURI(); |
186 |
Resource resource = null; |
188 |
Resource resource = null; |
187 |
try { |
189 |
try { |
188 |
resource = domain.getResourceSet().getResource(uri.trimFragment(), false); |
190 |
resource = domain.getResourceSet().getResource(uri.trimFragment(), false); |
Lines 201-207
Link Here
|
201 |
} |
203 |
} |
202 |
} |
204 |
} |
203 |
if (resource == null) { |
205 |
if (resource == null) { |
204 |
throw new RuntimeException("Unable to load diagram resource"); |
206 |
throw new RuntimeException(Messages.GMFGraphDocumentProvider_UnableToLoadResourceError); |
205 |
} |
207 |
} |
206 |
if (uri.fragment() != null) { |
208 |
if (uri.fragment() != null) { |
207 |
EObject rootElement = resource.getEObject(uri.fragment()); |
209 |
EObject rootElement = resource.getEObject(uri.fragment()); |
Lines 218-237
Link Here
|
218 |
} |
220 |
} |
219 |
} |
221 |
} |
220 |
} |
222 |
} |
221 |
throw new RuntimeException("Diagram is not present in resource"); |
223 |
throw new RuntimeException(Messages.GMFGraphDocumentProvider_NoDiagramInResourceError); |
222 |
} catch (Exception e) { |
224 |
} catch (Exception e) { |
223 |
CoreException thrownExcp = null; |
225 |
CoreException thrownExcp = null; |
224 |
if (e instanceof CoreException) { |
226 |
if (e instanceof CoreException) { |
225 |
thrownExcp = (CoreException) e; |
227 |
thrownExcp = (CoreException) e; |
226 |
} else { |
228 |
} else { |
227 |
String msg = e.getLocalizedMessage(); |
229 |
String msg = e.getLocalizedMessage(); |
228 |
thrownExcp = new CoreException(new Status(IStatus.ERROR, GMFGraphDiagramEditorPlugin.ID, 0, msg != null ? msg : "Error loading diagram", e)); //$NON-NLS-1$ |
230 |
thrownExcp = new CoreException(new Status(IStatus.ERROR, GMFGraphDiagramEditorPlugin.ID, 0, msg != null ? msg : Messages.GMFGraphDocumentProvider_DiagramLoadingError, e)); |
229 |
} |
231 |
} |
230 |
throw thrownExcp; |
232 |
throw thrownExcp; |
231 |
} |
233 |
} |
232 |
} else { |
234 |
} else { |
233 |
throw new CoreException(new Status(IStatus.ERROR, GMFGraphDiagramEditorPlugin.ID, 0, |
235 |
throw new CoreException(new Status(IStatus.ERROR, GMFGraphDiagramEditorPlugin.ID, 0, NLS.bind(Messages.GMFGraphDocumentProvider_IncorrectInputError, new Object[] { element, |
234 |
"Incorrect element used: " + element + " instead of org.eclipse.ui.part.FileEditorInput or org.eclipse.emf.common.ui.URIEditorInput", null)); //$NON-NLS-1$ //$NON-NLS-2$ |
236 |
"org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), null)); |
235 |
} |
237 |
} |
236 |
} |
238 |
} |
237 |
|
239 |
|
Lines 309-315
Link Here
|
309 |
try { |
311 |
try { |
310 |
updateCache(element); |
312 |
updateCache(element); |
311 |
} catch (CoreException ex) { |
313 |
} catch (CoreException ex) { |
312 |
GMFGraphDiagramEditorPlugin.getInstance().logError(Messages.DocumentProvider_isModifiable, ex); |
314 |
GMFGraphDiagramEditorPlugin.getInstance().logError(Messages.GMFGraphDocumentProvider_isModifiable, ex); |
|
|
315 |
// Error message to log was initially taken from org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.internal.l10n.EditorMessages.StorageDocumentProvider_isModifiable |
313 |
} |
316 |
} |
314 |
} |
317 |
} |
315 |
return info.isReadOnly(); |
318 |
return info.isReadOnly(); |
Lines 332-338
Link Here
|
332 |
try { |
335 |
try { |
333 |
updateCache(element); |
336 |
updateCache(element); |
334 |
} catch (CoreException ex) { |
337 |
} catch (CoreException ex) { |
335 |
GMFGraphDiagramEditorPlugin.getInstance().logError(Messages.DocumentProvider_isModifiable, ex); |
338 |
GMFGraphDiagramEditorPlugin.getInstance().logError(Messages.GMFGraphDocumentProvider_isModifiable, ex); |
|
|
339 |
// Error message to log was initially taken from org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.internal.l10n.EditorMessages.StorageDocumentProvider_isModifiable |
336 |
} |
340 |
} |
337 |
} |
341 |
} |
338 |
return info.isModifiable(); |
342 |
return info.isModifiable(); |
Lines 503-523
Link Here
|
503 |
ResourceSetInfo info = getResourceSetInfo(element); |
507 |
ResourceSetInfo info = getResourceSetInfo(element); |
504 |
if (info != null) { |
508 |
if (info != null) { |
505 |
if (!overwrite && !info.isSynchronized()) { |
509 |
if (!overwrite && !info.isSynchronized()) { |
506 |
throw new CoreException(new Status(IStatus.ERROR, GMFGraphDiagramEditorPlugin.ID, IStatus.OK, "The file has been changed on the file system", null)); //$NON-NLS-1$ |
510 |
throw new CoreException(new Status(IStatus.ERROR, GMFGraphDiagramEditorPlugin.ID, IStatus.OK, Messages.GMFGraphDocumentProvider_UnsynchronizedFileSaveError, null)); |
507 |
} |
511 |
} |
508 |
info.stopResourceListening(); |
512 |
info.stopResourceListening(); |
509 |
fireElementStateChanging(element); |
513 |
fireElementStateChanging(element); |
510 |
List resources = info.getResourceSet().getResources(); |
514 |
List resources = info.getResourceSet().getResources(); |
511 |
try { |
515 |
try { |
512 |
monitor.beginTask("Saving diagram", resources.size() + 1); |
516 |
monitor.beginTask(Messages.GMFGraphDocumentProvider_SaveDiagramTask, resources.size() + 1); //"Saving diagram" |
513 |
Map options = new HashMap(); |
|
|
514 |
options.put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE); |
515 |
for (Iterator it = resources.iterator(); it.hasNext();) { |
517 |
for (Iterator it = resources.iterator(); it.hasNext();) { |
516 |
Resource nextResource = (Resource) it.next(); |
518 |
Resource nextResource = (Resource) it.next(); |
517 |
monitor.setTaskName("Saving " + nextResource.getURI()); |
519 |
monitor.setTaskName(NLS.bind(Messages.GMFGraphDocumentProvider_SaveNextResourceTask, nextResource.getURI())); |
518 |
if (nextResource.isLoaded() && (!nextResource.isTrackingModification() || nextResource.isModified())) { |
520 |
if (nextResource.isLoaded()) { |
519 |
try { |
521 |
try { |
520 |
nextResource.save(options); |
522 |
nextResource.save(GMFGraphDiagramEditorUtil.getSaveOptions()); |
521 |
} catch (IOException e) { |
523 |
} catch (IOException e) { |
522 |
fireElementStateChangeFailed(element); |
524 |
fireElementStateChangeFailed(element); |
523 |
throw new CoreException(new Status(IStatus.ERROR, GMFGraphDiagramEditorPlugin.ID, EditorStatusCodes.RESOURCE_FAILURE, e.getLocalizedMessage(), null)); |
525 |
throw new CoreException(new Status(IStatus.ERROR, GMFGraphDiagramEditorPlugin.ID, EditorStatusCodes.RESOURCE_FAILURE, e.getLocalizedMessage(), null)); |
Lines 544-550
Link Here
|
544 |
try { |
546 |
try { |
545 |
file.refreshLocal(IResource.DEPTH_INFINITE, monitor); |
547 |
file.refreshLocal(IResource.DEPTH_INFINITE, monitor); |
546 |
} catch (CoreException ex) { |
548 |
} catch (CoreException ex) { |
547 |
GMFGraphDiagramEditorPlugin.getInstance().logError(Messages.DocumentProvider_handleElementContentChanged, ex); |
549 |
GMFGraphDiagramEditorPlugin.getInstance().logError(Messages.GMFGraphDocumentProvider_handleElementContentChanged, ex); |
|
|
550 |
// Error message to log was initially taken from org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.internal.l10n.EditorMessages.FileDocumentProvider_handleElementContentChanged |
548 |
} |
551 |
} |
549 |
} |
552 |
} |
550 |
changedResource.unload(); |
553 |
changedResource.unload(); |
Lines 567-575
Link Here
|
567 |
/** |
570 |
/** |
568 |
* @generated |
571 |
* @generated |
569 |
*/ |
572 |
*/ |
570 |
protected void handleElementMoved(IEditorInput input, org.eclipse.emf.common.util.URI uri) { |
573 |
protected void handleElementMoved(IEditorInput input, URI uri) { |
571 |
if (input instanceof FileEditorInput) { |
574 |
if (input instanceof FileEditorInput) { |
572 |
IFile newFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(org.eclipse.emf.common.util.URI.decode(uri.path())).removeFirstSegments(1)); |
575 |
IFile newFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(URI.decode(uri.path())).removeFirstSegments(1)); |
573 |
fireElementMoved(input, newFile == null ? null : new FileEditorInput(newFile)); |
576 |
fireElementMoved(input, newFile == null ? null : new FileEditorInput(newFile)); |
574 |
return; |
577 |
return; |
575 |
} |
578 |
} |
Lines 834-840
Link Here
|
834 |
/** |
837 |
/** |
835 |
* @generated |
838 |
* @generated |
836 |
*/ |
839 |
*/ |
837 |
public boolean handleResourceMoved(Resource resource, final org.eclipse.emf.common.util.URI newURI) { |
840 |
public boolean handleResourceMoved(Resource resource, final URI newURI) { |
838 |
synchronized (ResourceSetInfo.this) { |
841 |
synchronized (ResourceSetInfo.this) { |
839 |
if (ResourceSetInfo.this.fCanBeSaved) { |
842 |
if (ResourceSetInfo.this.fCanBeSaved) { |
840 |
ResourceSetInfo.this.setUnSynchronized(resource); |
843 |
ResourceSetInfo.this.setUnSynchronized(resource); |