View | Details | Raw Unified | Return to bug 149986
Collapse All | Expand All

(-)src/org/eclipse/gmf/runtime/diagram/ui/resources/editor/parts/DiagramDocumentEditor.java (-33 / +50 lines)
Lines 501-506 Link Here
501
		return pm != null ? pm : new NullProgressMonitor();
501
		return pm != null ? pm : new NullProgressMonitor();
502
	}
502
	}
503
503
504
    private boolean isHandlingElementDeletion = false;
504
	/**
505
	/**
505
	 * Handles an external change of the editor's input element. Subclasses may
506
	 * Handles an external change of the editor's input element. Subclasses may
506
	 * extend.
507
	 * extend.
Lines 520-555 Link Here
520
521
521
		final IEditorInput input= getEditorInput();
522
		final IEditorInput input= getEditorInput();
522
		if (provider.isDeleted(input)) {
523
		if (provider.isDeleted(input)) {
523
524
            try {
524
			if (isSaveAsAllowed()) {
525
                isHandlingElementDeletion = true;
525
526
    			if (isSaveAsAllowed()) {
526
				title= EditorMessages.Editor_error_activated_deleted_save_title;
527
    				title= EditorMessages.Editor_error_activated_deleted_save_title;
527
				msg= EditorMessages.Editor_error_activated_deleted_save_message;
528
    				msg= EditorMessages.Editor_error_activated_deleted_save_message;
528
529
    
529
				String[] buttons= {
530
    				String[] buttons= {
530
					EditorMessages.Editor_error_activated_deleted_save_button_save,
531
    					EditorMessages.Editor_error_activated_deleted_save_button_save,
531
					EditorMessages.Editor_error_activated_deleted_save_button_close,
532
    					EditorMessages.Editor_error_activated_deleted_save_button_close,
532
				};
533
    				};
533
534
    
534
				MessageDialog dialog= new MessageDialog(shell, title, null, msg, MessageDialog.QUESTION, buttons, 0);
535
    				MessageDialog dialog= new MessageDialog(shell, title, null, msg, MessageDialog.QUESTION, buttons, 0);
535
536
    
536
				if (dialog.open() == 0) {
537
    				if (dialog.open() == 0) {
537
					IProgressMonitor pm= getProgressMonitor();
538
    					IProgressMonitor pm= getProgressMonitor();
538
					performSaveAs(pm);
539
    					performSaveAs(pm);
539
					if (pm.isCanceled())
540
    					if (pm.isCanceled())
540
						handleEditorInputChanged();
541
    						handleEditorInputChanged();
541
				} else {
542
    				} else {
542
					close(false);
543
    					close(false);
543
				}
544
    				}
544
545
    			} else {
545
			} else {
546
    				title= EditorMessages.Editor_error_activated_deleted_close_title;
546
547
    				msg= EditorMessages.Editor_error_activated_deleted_close_message;
547
				title= EditorMessages.Editor_error_activated_deleted_close_title;
548
    				if (MessageDialog.openConfirm(shell, title, msg))
548
				msg= EditorMessages.Editor_error_activated_deleted_close_message;
549
    					close(false);
549
				if (MessageDialog.openConfirm(shell, title, msg))
550
    			}
550
					close(false);
551
            } finally {
551
			}
552
                isHandlingElementDeletion = false;
552
553
            }
553
		} else {
554
		} else {
554
555
555
			title= EditorMessages.Editor_error_activated_outofsync_title;
556
			title= EditorMessages.Editor_error_activated_outofsync_title;
Lines 1264-1270 Link Here
1264
		 * @see IElementStateListener#elementDeleted(Object)
1265
		 * @see IElementStateListener#elementDeleted(Object)
1265
		 */
1266
		 */
1266
		public void elementDeleted(Object deletedElement) {
1267
		public void elementDeleted(Object deletedElement) {
1267
			if (deletedElement != null && deletedElement.equals(getEditorInput())) {
1268
			if (deletedElement != null && deletedElement.equals(getEditorInput()) && !isHandlingElementDeletion) {
1268
				Runnable r= new Runnable() {
1269
				Runnable r= new Runnable() {
1269
					public void run() {
1270
					public void run() {
1270
						enableSanityChecking(true);
1271
						enableSanityChecking(true);
Lines 1298-1304 Link Here
1298
							final Object previousContent;
1299
							final Object previousContent;
1299
							IDocument changed= null;
1300
							IDocument changed= null;
1300
							IEditorInput oldInput= getEditorInput();
1301
							IEditorInput oldInput= getEditorInput();
1301
							if (isDirty()) {
1302
                            final boolean initialDirtyState = isDirty();
1303
							if (initialDirtyState || reuseDiagramOnMove()) {
1302
								changed= d.getDocument(oldInput);
1304
								changed= d.getDocument(oldInput);
1303
								if (changed != null) {
1305
								if (changed != null) {
1304
									if(changed instanceof IDiagramDocument)
1306
									if(changed instanceof IDiagramDocument)
Lines 1319-1329 Link Here
1319
								ErrorDialog.openError(shell, title, msg, e.getStatus());
1321
								ErrorDialog.openError(shell, title, msg, e.getStatus());
1320
							}
1322
							}
1321
1323
1322
							if (changed != null) {
1324
							if (changed != null && previousContent != null) {
1323
								Runnable r2= new Runnable() {
1325
								Runnable r2= new Runnable() {
1324
									public void run() {
1326
									public void run() {
1325
										validateState(getEditorInput());
1327
										validateState(getEditorInput());
1326
										getDocumentProvider().getDocument(getEditorInput()).setContent(previousContent);
1328
										getDocumentProvider().getDocument(getEditorInput()).setContent(previousContent);
1329
                                        
1330
                                        if(reuseDiagramOnMove() && !initialDirtyState) {
1331
                                            try {
1332
                                                getDocumentProvider().resetDocument(getEditorInput());
1333
                                            } catch (CoreException e) {
1334
                                                String title= EditorMessages.Editor_error_setinput_title;
1335
                                                String msg= EditorMessages.Editor_error_setinput_message;
1336
                                                Shell shell= getSite().getShell();
1337
                                                ErrorDialog.openError(shell, title, msg, e.getStatus());
1338
                                            }
1339
                                        }
1327
									}
1340
									}
1328
								};
1341
								};
1329
								execute(r2, doValidationAsync);
1342
								execute(r2, doValidationAsync);
Lines 1483-1486 Link Here
1483
    protected String getEditingDomainID() {
1496
    protected String getEditingDomainID() {
1484
        return null;
1497
        return null;
1485
    }
1498
    }
1499
    
1500
    protected boolean reuseDiagramOnMove() {
1501
        return false;
1502
    }
1486
}
1503
}

Return to bug 149986