Bug 187772 - "Save as..." doesn't work
Summary: "Save as..." doesn't work
Status: RESOLVED FIXED
Alias: None
Product: GMF-Tooling (ARCHIVED)
Classification: Modeling
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Alex Shatalin CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-18 05:58 EDT by Tatiana Fesenko CLA
Modified: 2010-07-19 22:19 EDT (History)
1 user (show)

See Also:
richard.gronback: pmc_approved+
Ed.Merks: pmc_approved+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tatiana Fesenko CLA 2007-05-18 05:58:39 EDT
Build ID: I20061214-1445

Steps To Reproduce:
1. Create simple Taipan Diagram
2. Invoke "Save as..." action.
3. There are two scenarios:
- let the original name of the file. Then confirmation diagram "The file xxx already exists. Do you want to replace existing one". After pressing "yes" error message appears: "Save could not be completed. Target file is already open in another editor." Save was not performed.

- enter a new file name. Then another error message appears: "Cannot open input element: Reason : Resource xxx does not exist". 


More information:
The problem is also relevant for all UML2Tools diagrams.
Comment 1 Antoine Toulmé CLA 2007-05-25 20:22:22 EDT
We fixed this in the STP BPMN modeler.

See here:
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.stp.bpmn/org.eclipse.stp.bpmn.diagram/src/org/eclipse/stp/bpmn/diagram/part/BpmnDocumentProvider.java?root=STP_Project&view=markup

However there are issues when renaming the diagram or any of its containers (project and folders).

Hope this helps.
Comment 2 Richard Gronback CLA 2007-06-04 08:09:17 EDT
Increasing priority, adding PMC approval.
Comment 3 Alex Shatalin CLA 2007-06-04 14:48:13 EDT
-
Comment 4 Antoine Toulmé CLA 2007-06-04 15:00:38 EDT
I am very interested in this bug. Could you please give a sample of the code that will be now generated for the save as ? As an alternative, could you point me to the commit revision log corresponding to the fix ?
I would like to integrate those changes in STP, and make sure there are no renaming issues.

Thanks !
Comment 5 Alex Shatalin CLA 2007-06-04 15:07:52 EDT
This fix was commited as a 1.16 revision of DocumentProvider.xpt

Do not hesitate to report any additional problems with current implementation.

In few words, following else {} statement was added (quotation from EcoreDocumentProvider):

protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException {
	ResourceSetInfo info = getResourceSetInfo(element);
	if (info != null) {
// Not changed
	} else {
// added:
		URI newResoruceURI;
		List affectedFiles = null;
		if (element instanceof FileEditorInput) {
			IFile newFile = ((FileEditorInput) element).getFile();
			affectedFiles = Collections.singletonList(newFile);
			newResoruceURI = URI.createPlatformResourceURI(newFile.getFullPath().toString(), true);
		} else if (element instanceof URIEditorInput) {
			newResoruceURI = ((URIEditorInput) element).getURI();
		} else {
			fireElementStateChangeFailed(element);
			throw new CoreException(new Status(IStatus.ERROR, EcoreDiagramEditorPlugin.ID, 0, NLS.bind(Messages.EcoreDocumentProvider_IncorrectInputError, new Object[] { element,
						"org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$ //$NON-NLS-2$ 
					null));
		}
		if (false == document instanceof IDiagramDocument) {
			fireElementStateChangeFailed(element);
			throw new CoreException(new Status(IStatus.ERROR, EcoreDiagramEditorPlugin.ID, 0,
					"Incorrect document used: " + document + " instead of org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument", null)); //$NON-NLS-1$ //$NON-NLS-2$
		}
		IDiagramDocument diagramDocument = (IDiagramDocument) document;
		final Resource newResource = diagramDocument.getEditingDomain().getResourceSet().createResource(newResoruceURI);
		final Diagram diagramCopy = (Diagram) EcoreUtil.copy(diagramDocument.getDiagram());
		try {
			new AbstractTransactionalCommand(diagramDocument.getEditingDomain(), NLS.bind(Messages.EcoreDocumentProvider_SaveAs, diagramCopy.getName()), affectedFiles) {

				protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
					newResource.getContents().add(diagramCopy);
					return CommandResult.newOKCommandResult();
				}
			}.execute(monitor, null);
			newResource.save(EcoreDiagramEditorUtil.getSaveOptions());
		} catch (ExecutionException e) {
			fireElementStateChangeFailed(element);
			throw new CoreException(new Status(IStatus.ERROR, EcoreDiagramEditorPlugin.ID, 0, e.getLocalizedMessage(), null));
		} catch (IOException e) {
			fireElementStateChangeFailed(element);
			throw new CoreException(new Status(IStatus.ERROR, EcoreDiagramEditorPlugin.ID, 0, e.getLocalizedMessage(), null));
		}
		newResource.unload();
	}
}
Comment 6 Antoine Toulmé CLA 2007-06-04 15:14:59 EDT
Thank you Alexander, this is much appreciated. I will try this out.
Comment 7 Antoine Toulmé CLA 2007-06-05 13:05:07 EDT
Sorry Alexander, we cannot test it now as apparently we are one step behind for the BPMN modeler. We still use a FileEditorInput, your document provider requires a URIEditorInput. 

We will test this feature when we regenerate our classes with GMF 2.0.

Comment 8 Eclipse Webmaster CLA 2010-07-19 22:19:27 EDT
[GMF Restructure] Bug 319140 : product GMF and component
Generation was the original product and component for this bug