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

The following examples show how to use org.eclipse.text.undo.IDocumentUndoManager#addDocumentUndoListener() . 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: DocumentManager.java    From ContentAssist with MIT License 6 votes vote down vote up
/**
 * Registers a document manager with an editor.
 * @param doc the document to be managed
 * @param st the styled text of the editor
 * @param dm the document manager
 */
public static void register(IDocument doc, StyledText st, DocumentManager dm) {
    if (doc != null) {
        doc.addDocumentListener(dm);
        
        DocumentUndoManagerRegistry.connect(doc);
        IDocumentUndoManager undoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
        if (undoManager != null) {
            undoManager.addDocumentUndoListener(dm);
        }
    }
    
    if (st != null) {
        st.addListener(SWT.KeyDown, dm);
        st.addListener(SWT.MouseDown, dm);
        st.addListener(SWT.MouseDoubleClick, dm);
    }
}
 
Example 2
Source File: JSEditor.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void createPartControl( Composite parent )
{
	Composite child = this.initEditorLayout( parent );

	// Script combo
	cmbExprListViewer = new ComboViewer( cmbExpList );
	JSExpListProvider provider = new JSExpListProvider( );
	cmbExprListViewer.setContentProvider( provider );
	cmbExprListViewer.setLabelProvider( provider );
	cmbExprListViewer.setData( VIEWER_CATEGORY_KEY, VIEWER_CATEGORY_CONTEXT );

	// SubFunctions combo
	JSSubFunctionListProvider subProvider = new JSSubFunctionListProvider( this );

	// also add subProvider as listener of expr viewer.
	cmbExprListViewer.addSelectionChangedListener( subProvider );

	cmbSubFunctions.addListener( CustomChooserComposite.DROPDOWN_EVENT,
			new Listener( ) {

				public void handleEvent( Event event )
				{
					cmbSubFunctions.deselectAll( );

					ScriptParser parser = new ScriptParser( getEditorText( ) );

					Collection<IScriptMethodInfo> coll = parser.getAllMethodInfo( );

					for ( Iterator<IScriptMethodInfo> itr = coll.iterator( ); itr.hasNext( ); )
					{
						IScriptMethodInfo mtd = itr.next( );

						cmbSubFunctions.markSelection( METHOD_DISPLAY_INDENT
								+ mtd.getName( ) );
					}
				}

			} );

	cmbSubFunctionsViewer = new TextComboViewer( cmbSubFunctions );
	cmbSubFunctionsViewer.setContentProvider( subProvider );
	cmbSubFunctionsViewer.setLabelProvider( subProvider );
	cmbSubFunctionsViewer.addSelectionChangedListener( subProvider );
	cmbSubFunctionsViewer.addSelectionChangedListener( propertyDefnChangeListener );

	// Initialize the model for the document.
	Object model = getModel( );
	if ( model != null )
	{
		cmbExpList.setVisible( true );
		cmbSubFunctions.setVisible( true );
		setComboViewerInput( model );
	}
	else
	{
		setComboViewerInput( Messages.getString( "JSEditor.Input.trial" ) ); //$NON-NLS-1$
	}
	cmbExprListViewer.addSelectionChangedListener( palettePage.getSupport( ) );
	cmbExprListViewer.addSelectionChangedListener( propertyDefnChangeListener );

	scriptEditor.createPartControl( child );
	scriptValidator = new ScriptValidator( getViewer( ) );

	disableEditor( );

	SourceViewer viewer = getViewer( );
	IDocument document = viewer == null ? null : viewer.getDocument( );

	if ( document != null )
	{
		IDocumentUndoManager undoManager = DocumentUndoManagerRegistry.getDocumentUndoManager( document );

		if ( undoManager != null )
		{
			undoManager.addDocumentUndoListener( undoListener );
		}
		document.addDocumentListener( documentListener );
	}
}