Java Code Examples for org.eclipse.text.undo.IDocumentUndoManager#transferUndoHistory()

The following examples show how to use org.eclipse.text.undo.IDocumentUndoManager#transferUndoHistory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ERDiagramElementStateListener.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
@Override
public void elementMoved(final Object originalElement, final Object movedElement) {
    if (originalElement != null && originalElement.equals(editorPart.getEditorInput())) {
        final boolean doValidationAsync = Display.getCurrent() != null;
        final Runnable r = new Runnable() {
            @Override
            public void run() {
                if (movedElement == null || movedElement instanceof IEditorInput) {

                    final String previousContent;
                    IDocumentUndoManager previousUndoManager = null;
                    IDocument changed = null;
                    final boolean wasDirty = editorPart.isDirty();
                    changed = documentProvider.getDocument(editorPart.getEditorInput());
                    if (changed != null) {
                        if (wasDirty)
                            previousContent = changed.get();
                        else
                            previousContent = null;

                        previousUndoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(changed);
                        if (previousUndoManager != null)
                            previousUndoManager.connect(this);
                    } else
                        previousContent = null;

                    editorPart.setInputWithNotify((IEditorInput) movedElement);

                    if (previousUndoManager != null) {
                        final IDocument newDocument = documentProvider.getDocument(movedElement);
                        if (newDocument != null) {
                            final IDocumentUndoManager newUndoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(newDocument);
                            if (newUndoManager != null)
                                newUndoManager.transferUndoHistory(previousUndoManager);
                        }
                        previousUndoManager.disconnect(this);
                    }

                    if (wasDirty && changed != null) {
                        final Runnable r2 = new Runnable() {
                            @Override
                            public void run() {
                                documentProvider.getDocument(editorPart.getEditorInput()).set(previousContent);

                            }
                        };
                        execute(r2, doValidationAsync);
                    }

                }
            }
        };
        execute(r, false);
    }
}
 
Example 2
Source File: TestEditor.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
@Override
public void elementMoved(final Object originalElement, final Object movedElement) {
    if (originalElement != null && originalElement.equals(getEditorInput())) {
        final boolean doValidationAsync = Display.getCurrent() != null;
        final Runnable r = new Runnable() {
            @Override
            public void run() {
                enableSanityChecking(true);

                if (fSourceViewer == null)
                    return;

                if (movedElement == null || movedElement instanceof IEditorInput) {

                    final IDocumentProvider d = getDocumentProvider();
                    final String previousContent;
                    IDocumentUndoManager previousUndoManager = null;
                    IDocument changed = null;
                    final boolean wasDirty = isDirty();
                    changed = d.getDocument(getEditorInput());
                    if (changed != null) {
                        if (wasDirty)
                            previousContent = changed.get();
                        else
                            previousContent = null;

                        previousUndoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(changed);
                        if (previousUndoManager != null)
                            previousUndoManager.connect(this);
                    } else
                        previousContent = null;

                    setInput((IEditorInput) movedElement);

                    // The undo manager needs to be replaced with one
                    // for the new document.
                    // Transfer the undo history and then disconnect
                    // from the old undo manager.
                    if (previousUndoManager != null) {
                        final IDocument newDocument = getDocumentProvider().getDocument(movedElement);
                        if (newDocument != null) {
                            final IDocumentUndoManager newUndoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(newDocument);
                            if (newUndoManager != null)
                                newUndoManager.transferUndoHistory(previousUndoManager);
                        }
                        previousUndoManager.disconnect(this);
                    }

                    if (wasDirty && changed != null) {
                        final Runnable r2 = new Runnable() {
                            @Override
                            public void run() {
                                validateState(getEditorInput());
                                d.getDocument(getEditorInput()).set(previousContent);

                            }
                        };
                        execute(r2, doValidationAsync);
                    }

                }
            }
        };
        execute(r, false);
    }
}
 
Example 3
Source File: ERDiagramElementStateListener.java    From erflute with Apache License 2.0 4 votes vote down vote up
@Override
public void elementMoved(final Object originalElement, final Object movedElement) {
    if (originalElement != null && originalElement.equals(editorPart.getEditorInput())) {
        final boolean doValidationAsync = Display.getCurrent() != null;
        final Runnable r = new Runnable() {

            @Override
            public void run() {
                if (movedElement == null || movedElement instanceof IEditorInput) {
                    final String previousContent;
                    IDocumentUndoManager previousUndoManager = null;
                    IDocument changed = null;
                    final boolean wasDirty = editorPart.isDirty();
                    changed = documentProvider.getDocument(editorPart.getEditorInput());
                    if (changed != null) {
                        if (wasDirty) {
                            previousContent = changed.get();
                        } else {
                            previousContent = null;
                        }
                        previousUndoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(changed);
                        if (previousUndoManager != null) {
                            previousUndoManager.connect(this);
                        }
                    } else {
                        previousContent = null;
                    }
                    editorPart.setInputWithNotify((IEditorInput) movedElement);

                    if (previousUndoManager != null) {
                        final IDocument newDocument = documentProvider.getDocument(movedElement);
                        if (newDocument != null) {
                            final IDocumentUndoManager newUndoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(newDocument);
                            if (newUndoManager != null)
                                newUndoManager.transferUndoHistory(previousUndoManager);
                        }
                        previousUndoManager.disconnect(this);
                    }

                    if (wasDirty && changed != null) {
                        final Runnable r2 = new Runnable() {

                            @Override
                            public void run() {
                                documentProvider.getDocument(editorPart.getEditorInput()).set(previousContent);
                            }
                        };
                        execute(r2, doValidationAsync);
                    }
                }
            }
        };
        execute(r, false);
    }
}
 
Example 4
Source File: ERDiagramElementStateListener.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
public void elementMoved(final Object originalElement,
		final Object movedElement) {
	if (originalElement != null
			&& originalElement.equals(editorPart.getEditorInput())) {
		final boolean doValidationAsync = Display.getCurrent() != null;
		Runnable r = new Runnable() {
			public void run() {
				if (movedElement == null
						|| movedElement instanceof IEditorInput) {

					final String previousContent;
					IDocumentUndoManager previousUndoManager = null;
					IDocument changed = null;
					boolean wasDirty = editorPart.isDirty();
					changed = documentProvider.getDocument(editorPart
							.getEditorInput());
					if (changed != null) {
						if (wasDirty)
							previousContent = changed.get();
						else
							previousContent = null;

						previousUndoManager = DocumentUndoManagerRegistry
								.getDocumentUndoManager(changed);
						if (previousUndoManager != null)
							previousUndoManager.connect(this);
					} else
						previousContent = null;

					editorPart
							.setInputWithNotify((IEditorInput) movedElement);

					if (previousUndoManager != null) {
						IDocument newDocument = documentProvider
								.getDocument(movedElement);
						if (newDocument != null) {
							IDocumentUndoManager newUndoManager = DocumentUndoManagerRegistry
									.getDocumentUndoManager(newDocument);
							if (newUndoManager != null)
								newUndoManager
										.transferUndoHistory(previousUndoManager);
						}
						previousUndoManager.disconnect(this);
					}

					if (wasDirty && changed != null) {
						Runnable r2 = new Runnable() {
							public void run() {
								documentProvider.getDocument(
										editorPart.getEditorInput()).set(
										previousContent);

							}
						};
						execute(r2, doValidationAsync);
					}

				}
			}
		};
		execute(r, false);
	}
}
 
Example 5
Source File: TestEditor.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
public void elementMoved(final Object originalElement,
		final Object movedElement) {
	if (originalElement != null
			&& originalElement.equals(getEditorInput())) {
		final boolean doValidationAsync = Display.getCurrent() != null;
		Runnable r = new Runnable() {
			public void run() {
				enableSanityChecking(true);

				if (fSourceViewer == null)
					return;

				if (movedElement == null
						|| movedElement instanceof IEditorInput) {

					final IDocumentProvider d = getDocumentProvider();
					final String previousContent;
					IDocumentUndoManager previousUndoManager = null;
					IDocument changed = null;
					boolean wasDirty = isDirty();
					changed = d.getDocument(getEditorInput());
					if (changed != null) {
						if (wasDirty)
							previousContent = changed.get();
						else
							previousContent = null;

						previousUndoManager = DocumentUndoManagerRegistry
								.getDocumentUndoManager(changed);
						if (previousUndoManager != null)
							previousUndoManager.connect(this);
					} else
						previousContent = null;

					setInput((IEditorInput) movedElement);

					// The undo manager needs to be replaced with one
					// for the new document.
					// Transfer the undo history and then disconnect
					// from the old undo manager.
					if (previousUndoManager != null) {
						IDocument newDocument = getDocumentProvider()
								.getDocument(movedElement);
						if (newDocument != null) {
							IDocumentUndoManager newUndoManager = DocumentUndoManagerRegistry
									.getDocumentUndoManager(newDocument);
							if (newUndoManager != null)
								newUndoManager
										.transferUndoHistory(previousUndoManager);
						}
						previousUndoManager.disconnect(this);
					}

					if (wasDirty && changed != null) {
						Runnable r2 = new Runnable() {
							public void run() {
								validateState(getEditorInput());
								d.getDocument(getEditorInput()).set(
										previousContent);

							}
						};
						execute(r2, doValidationAsync);
					}

				}
			}
		};
		execute(r, false);
	}
}