Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Synchronizing Java outline view while typing in the Java editor
Synchronizing Java outline view while typing in the Java editor [message #176324] Wed, 01 September 2004 21:00 Go to next message
Eclipse UserFriend
Originally posted by: becker.kestrel.edu

Can somebody give me a pointer to how the synchronization between the Java
editor and the outline is implemented.
The outline changes while the code is being typed.
I am trying to implement similar functionality but I do not know when to
update my model. I am re-parsing the file when it gets saved by the user and
then modifying the model. JDT is smarter than that and I would like to
implement the same behavior.
I looked around in the JDT code but could not figure out how to do it.
Another question I have is what is the correct behavior for updating the
editor once the model is modified outside the editor. In my code, I can
modify the model from the outline view through a context menu.
The way I am doing it is having my Editor class (that extends
AbstractTextEditor) implement a property change listener. After the user
modifies the model using the outline view, the property change method (see
below) calls updateEditorContent where I write the new text description of
my model to its file and invalidate/validate the text presentation. Is there
an easier or more straight forward way to update the editor contents once
the model changes outside the Editor?

// Inside my Editor class
/* (non-Javadoc)
* @see
java.beans.PropertyChangeListener#propertyChange(java.beans. PropertyChangeEv
ent)
*/
public void propertyChange(PropertyChangeEvent evt) {
TraceUtil.traceMsg(" "+this.getClass().getName()+
".propertyChange(PlanwareEditor.java:"+(new
Throwable()).getStackTrace()[0].getLineNumber()+")\n");
TraceUtil.traceMsg("PlanwareEditor.propertyChange change "+evt);
getSourceViewer().invalidateTextPresentation();
SourceElement source =
((PlanwareEditorDocumentProvider)getDocumentProvider()).getS ourceElement();
TraceUtil.traceMsg("PlanwareEditor.propertyChange New Source \n"+source);
TraceUtil.traceMsg("
"+this.getClass().getName()+".propertyChange(PlanwareEditor.java: "+
(new Throwable()).getStackTrace()[0].getLineNumber());
updateEditorContent(source);
}


public void updateEditorContent (SourceElement source){
TraceUtil.traceMsg(" "+this.getClass().getName()+
".updateEditorContent(PlanwareEditor.java:"+(new
Throwable()).getStackTrace()[0].getLineNumber()+")\n");
TraceUtil.traceMsg("updateEditorContent source \n"+source);
TraceUtil.traceMsg(" "+this.getClass().getName()+
".updateEditorContent(PlanwareEditor.java:"+(new
Throwable()).getStackTrace()[0].getLineNumber()+")\n");
//getSourceViewer().invalidateTextPresentation();
StringBuffer sb = new StringBuffer(source.toString());
IFile file = ((IFileEditorInput)getEditorInput()).getFile();
try {
// Write the contents of the model to the file
file.setContents(new ByteArrayInputStream(sb.toString().getBytes()),
true, true, null);
} catch (CoreException ex){
System.err.println("PlanwareEditor.updateEditorContent Core Exception
"+ex);
TraceUtil.traceMsg(" "+this.getClass().getName()+
".updateEditorContent(PlanwareEditor.java:"+(new
Throwable()).getStackTrace()[0].getLineNumber()+")");
}
}



Marcel
Re: Synchronizing Java outline view while typing in the Java editor [message #176338 is a reply to message #176324] Wed, 01 September 2004 23:01 Go to previous messageGo to next message
Eclipse UserFriend
The editor I am familiar with the is the AntEditor.
It uses a notifying reconciler.
After ~500 microseconds after the typing has stopped it "pings" to let you
process the changes/update the model.
See the AntEditor and associated classes in org.eclipse.ant.ui

HTH
Darins

"Marcel Becker" <becker@kestrel.edu> wrote in message
news:ch5r46$h6e$1@eclipse.org...
> Can somebody give me a pointer to how the synchronization between the Java
> editor and the outline is implemented.
> The outline changes while the code is being typed.
> I am trying to implement similar functionality but I do not know when
to
> update my model. I am re-parsing the file when it gets saved by the user
and
> then modifying the model. JDT is smarter than that and I would like to
> implement the same behavior.
> I looked around in the JDT code but could not figure out how to do it.
> Another question I have is what is the correct behavior for updating
the
> editor once the model is modified outside the editor. In my code, I can
> modify the model from the outline view through a context menu.
> The way I am doing it is having my Editor class (that extends
> AbstractTextEditor) implement a property change listener. After the user
> modifies the model using the outline view, the property change method (see
> below) calls updateEditorContent where I write the new text description of
> my model to its file and invalidate/validate the text presentation. Is
there
> an easier or more straight forward way to update the editor contents once
> the model changes outside the Editor?
>
> // Inside my Editor class
> /* (non-Javadoc)
> * @see
>
java.beans.PropertyChangeListener#propertyChange(java.beans. PropertyChangeEv
> ent)
> */
> public void propertyChange(PropertyChangeEvent evt) {
> TraceUtil.traceMsg(" "+this.getClass().getName()+
> ".propertyChange(PlanwareEditor.java:"+(new
> Throwable()).getStackTrace()[0].getLineNumber()+")\n");
> TraceUtil.traceMsg("PlanwareEditor.propertyChange change "+evt);
> getSourceViewer().invalidateTextPresentation();
> SourceElement source =
>
((PlanwareEditorDocumentProvider)getDocumentProvider()).getS ourceElement();
> TraceUtil.traceMsg("PlanwareEditor.propertyChange New Source
\n"+source);
> TraceUtil.traceMsg("
> "+this.getClass().getName()+".propertyChange(PlanwareEditor.java: "+
> (new Throwable()).getStackTrace()[0].getLineNumber());
> updateEditorContent(source);
> }
>
>
> public void updateEditorContent (SourceElement source){
> TraceUtil.traceMsg(" "+this.getClass().getName()+
> ".updateEditorContent(PlanwareEditor.java:"+(new
> Throwable()).getStackTrace()[0].getLineNumber()+")\n");
> TraceUtil.traceMsg("updateEditorContent source \n"+source);
> TraceUtil.traceMsg(" "+this.getClass().getName()+
> ".updateEditorContent(PlanwareEditor.java:"+(new
> Throwable()).getStackTrace()[0].getLineNumber()+")\n");
> //getSourceViewer().invalidateTextPresentation();
> StringBuffer sb = new StringBuffer(source.toString());
> IFile file = ((IFileEditorInput)getEditorInput()).getFile();
> try {
> // Write the contents of the model to the file
> file.setContents(new ByteArrayInputStream(sb.toString().getBytes()),
> true, true, null);
> } catch (CoreException ex){
> System.err.println("PlanwareEditor.updateEditorContent Core Exception
> "+ex);
> TraceUtil.traceMsg(" "+this.getClass().getName()+
> ".updateEditorContent(PlanwareEditor.java:"+(new
> Throwable()).getStackTrace()[0].getLineNumber()+")");
> }
> }
>
>
>
> Marcel
>
>
Re: Synchronizing Java outline view while typing in the Java editor [message #176465 is a reply to message #176324] Fri, 03 September 2004 06:21 Go to previous message
Eclipse UserFriend
Originally posted by: daniel.megert.gmx.net

Marcel Becker wrote:

>Can somebody give me a pointer to how the synchronization between the Java
>editor and the outline is implemented.
>The outline changes while the code is being typed.
> I am trying to implement similar functionality but I do not know when to
>update my model. I am re-parsing the file when it gets saved by the user and
>then modifying the model. JDT is smarter than that and I would like to
>implement the same behavior.
> I looked around in the JDT code but could not figure out how to do it.
>
>
See JavaReconciler.

> Another question I have is what is the correct behavior for updating the
>editor once the model is modified outside the editor.
>
The Java model's compilation unit works on a buffer and the Java editor
adapts that buffer to a document. If a Java element changes the
underlying buffer is modified and the document adapter gets notified.

Dani

> In my code, I can
>modify the model from the outline view through a context menu.
> The way I am doing it is having my Editor class (that extends
>AbstractTextEditor) implement a property change listener. After the user
>modifies the model using the outline view, the property change method (see
>below) calls updateEditorContent where I write the new text description of
>my model to its file and invalidate/validate the text presentation. Is there
>an easier or more straight forward way to update the editor contents once
>the model changes outside the Editor?
>
>// Inside my Editor class
> /* (non-Javadoc)
> * @see
> java.beans.PropertyChangeListener#propertyChange(java.beans. PropertyChangeEv
>ent)
> */
> public void propertyChange(PropertyChangeEvent evt) {
> TraceUtil.traceMsg(" "+this.getClass().getName()+
> ".propertyChange(PlanwareEditor.java:"+(new
>Throwable()).getStackTrace()[0].getLineNumber()+")\n");
> TraceUtil.traceMsg("PlanwareEditor.propertyChange change "+evt);
> getSourceViewer().invalidateTextPresentation();
> SourceElement source =
> ((PlanwareEditorDocumentProvider)getDocumentProvider()).getS ourceElement();
> TraceUtil.traceMsg("PlanwareEditor.propertyChange New Source \n"+source);
> TraceUtil.traceMsg("
>"+this.getClass().getName()+".propertyChange(PlanwareEditor.java: "+
> (new Throwable()).getStackTrace()[0].getLineNumber());
> updateEditorContent(source);
> }
>
>
> public void updateEditorContent (SourceElement source){
> TraceUtil.traceMsg(" "+this.getClass().getName()+
> ".updateEditorContent(PlanwareEditor.java:"+(new
>Throwable()).getStackTrace()[0].getLineNumber()+")\n");
> TraceUtil.traceMsg("updateEditorContent source \n"+source);
> TraceUtil.traceMsg(" "+this.getClass().getName()+
> ".updateEditorContent(PlanwareEditor.java:"+(new
>Throwable()).getStackTrace()[0].getLineNumber()+")\n");
> //getSourceViewer().invalidateTextPresentation();
> StringBuffer sb = new StringBuffer(source.toString());
> IFile file = ((IFileEditorInput)getEditorInput()).getFile();
> try {
> // Write the contents of the model to the file
> file.setContents(new ByteArrayInputStream(sb.toString().getBytes()),
>true, true, null);
> } catch (CoreException ex){
> System.err.println("PlanwareEditor.updateEditorContent Core Exception
>"+ex);
> TraceUtil.traceMsg(" "+this.getClass().getName()+
> ".updateEditorContent(PlanwareEditor.java:"+(new
>Throwable()).getStackTrace()[0].getLineNumber()+")");
> }
> }
>
>
>
>Marcel
>
>
>
>
Previous Topic:Java Editor frustrations
Next Topic:Debug commands disabled when breakpoint hit
Goto Forum:
  


Current Time: Thu May 08 01:57:50 EDT 2025

Powered by FUDForum. Page generated in 0.08843 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top