Synchronizing Java outline view while typing in the Java editor [message #176324] |
Wed, 01 September 2004 21:00  |
Eclipse User |
|
|
|
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 #176465 is a reply to message #176324] |
Fri, 03 September 2004 06:21  |
Eclipse User |
|
|
|
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
>
>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.08843 seconds