Skip to main content



      Home
Home » Eclipse Projects » GEF » Question about EditPart.setModel() & EditPartViewer.setContents()
Question about EditPart.setModel() & EditPartViewer.setContents() [message #10117] Fri, 14 June 2002 22:29 Go to next message
Eclipse UserFriend
Originally posted by: eric_to_jeff.hotmail.com

Hi,

If I change the model of any EditPart use setModel method, I think it
should reinitialize the editpart, but it never happend because
shouldInitialize always return false.

And a question about EditPartViewer.setContents(EditPart), if I has
codes like following:

outlineViewer = new TreeViewer();
treeContents = new AnyTreeEditPart(model);
outlineViewer.setContents(treeContents);

Then when outlineViewer.dispose is called, is treeContents disposed?
Should I dispose treeContents myself?

And should I dispose any editpart myself If I use
EditPartViewer.setContents(Object) &
EditPartViewer.setEditPartFactory(EditPartFactory)?

Regards,

Eric
Re: Question about EditPart.setModel() & EditPartViewer.setContents() [message #11468 is a reply to message #10117] Fri, 28 June 2002 11:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.ibm.com

> If I change the model of any EditPart use setModel method, I think it
> should reinitialize the editpart, but it never happend because
> shouldInitialize always return false.

By definition, initialize will only happen once.
If you want to update the figure, calling refresh should work. Typically if
the model is completely new, you should probably throw out the EditPart and
get a new one. This is what happens anyway. Why are you calling setModel
on your EditPart? I should only be set during creation, like
createChild(Object model).

> And a question about EditPartViewer.setContents(EditPart), if I has
> codes like following:
>
> outlineViewer = new TreeViewer();
> treeContents = new AnyTreeEditPart(model);
> outlineViewer.setContents(treeContents);
>
> Then when outlineViewer.dispose is called, is treeContents disposed?
> Should I dispose treeContents myself?

> And should I dispose any editpart myself If I use
> EditPartViewer.setContents(Object) &
> EditPartViewer.setEditPartFactory(EditPartFactory)?

Someone asked a similar question. Basically, the intent of dispose was to
remove any links between the EditPart and its viewer (i.e., the various
registration stuff). If you are throwing out the viewer, there is no reason
to clean up the registries.

deactivate() is guaranteed to be called when the viewer is disposed.

Think of it like this:
register= register with viewer (called as soon as possible, as soon as the
EditPart knows its parent)
activate = connect with model world
deactive = desconnect from model world
dispose = removing from viewer (should really be unregister)

> Regards,
>
> Eric
>
>
Re: Question about EditPart.setModel() & EditPartViewer.setContents() [message #11541 is a reply to message #11468] Fri, 28 June 2002 23:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eric_to_jeff.hotmail.com

> Why are you calling setModel on your EditPart?

I write a program that allow user switch between design view
and source view. If user change the source code, the model was
recreated. In my earlier code, I throw out the old EditPart and
create a new one.

Following is my older code:

public void setJasperDesign(JasperDesign jasperDesign) {
if (this.jasperDesign != jasperDesign) {
this.jasperDesign = jasperDesign;
EditPart oldReport = getGraphicalViewer().getContents();
EditPart oldTreeContents = getOutlineViewer().getContents();
if (oldReport != null) oldReport.dispose();
if (oldTreeContents != null) oldTreeContents.dispose();
ReportPS rs = new ReportPS(jasperDesign);
EditPart report = new ReportEditPart();
report.setModel(rs);
getGraphicalViewer().setContents(report);
EditPart treeContents = new ReportTreeEditPart(rs);
getOutlineViewer().setContents(treeContents);
}
}

And these are my current code:

public void setJasperDesign(JasperDesign jasperDesign) {
if (this.jasperDesign != jasperDesign) {
this.jasperDesign = jasperDesign;
getCommandStack().flush();
EditPart report = getGraphicalViewer().getContents();
EditPart treeContents = getOutlineViewer().getContents();
ReportPS rs = new ReportPS(jasperDesign);
if (report == null) {
report = new ReportEditPart();
report.setModel(rs);
getGraphicalViewer().setContents(report);
} else {
//report.deactivate();
report.setModel(rs);
}
if (treeContents == null) {
treeContents = new ReportTreeEditPart(rs);
getOutlineViewer().setContents(treeContents);
} else {
//treeContents.deactivate();
treeContents.setModel(rs);
}
}
}

And I override setModel method for ReportEditPart and ReportTreeEditPar.

public void setModel(Object model) {
setFlag(FLAG_INITIALIZED, false);
super.setModel(model);
}

Which one is correct?

Thanks,

Eric
Re: Question about EditPart.setModel() & EditPartViewer.setContents() [message #11614 is a reply to message #11541] Sun, 30 June 2002 17:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.ibm.com

The real question is what are you trying to gain. do you do this
recursively through all of the EditPart, or just for the Contents EditPart?
If just at the contents, I don't see the motivation.

> public void setJasperDesign(JasperDesign jasperDesign) {
> if (this.jasperDesign != jasperDesign) {
> this.jasperDesign = jasperDesign;
> EditPart oldReport = getGraphicalViewer().getContents();
> EditPart oldTreeContents = getOutlineViewer().getContents();
> if (oldReport != null) oldReport.dispose();
> if (oldTreeContents != null) oldTreeContents.dispose();

There should be no reason to get the old contents and dispose. Per other
postings, dispose is not guaranteed to call. But, The RootEditPart should
already dispose the old contents (and deactivate()) when setting the new
contents. It would be nice someone to verify this :-), though

> ReportPS rs = new ReportPS(jasperDesign);

If PS == propertysheet, you can wrap it later only for the propertysheet,
and use it's regular API from the EdirPart.

> EditPart report = new ReportEditPart();

You can put a factory on the EditPartViewers that will do this, and then ...

> report.setModel(rs);
> getGraphicalViewer().setContents(report);

.... call setContents(Object) instead, where the factory will then create the
proper contents EP.

> EditPart treeContents = new ReportTreeEditPart(rs);
> getOutlineViewer().setContents(treeContents);
> }
> }
>

> And I override setModel method for ReportEditPart and ReportTreeEditPar.
>
> public void setModel(Object model) {
> setFlag(FLAG_INITIALIZED, false);
> super.setModel(model);
> }

If you do do this, I would try calling refresh() instead of resetting the
INIT flag. GEF assumes that doInitialize won't occur more than once, even
though I don't think anything bad will happen with the current code in GEF.
Re: Question about EditPart.setModel() & EditPartViewer.setContents() [message #11650 is a reply to message #11614] Sun, 30 June 2002 22:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eric_to_jeff.hotmail.com

> The real question is what are you trying to gain. do you do this
> recursively through all of the EditPart, or just for the Contents
EditPart?
> If just at the contents, I don't see the motivation.

It just for the Contents EditPart. ReportEditPart is the top EditPart
someting
like the LogicDiagramEditPart in logic examples.

> > public void setJasperDesign(JasperDesign jasperDesign) {
> > if (this.jasperDesign != jasperDesign) {
> > this.jasperDesign = jasperDesign;
> > EditPart oldReport = getGraphicalViewer().getContents();
> > EditPart oldTreeContents = getOutlineViewer().getContents();
> > if (oldReport != null) oldReport.dispose();
> > if (oldTreeContents != null) oldTreeContents.dispose();
>
> There should be no reason to get the old contents and dispose. Per other
> postings, dispose is not guaranteed to call. But, The RootEditPart should
> already dispose the old contents (and deactivate()) when setting the new
> contents. It would be nice someone to verify this :-), though
>

I don't think so, if I does not to get the old contents and dispose it,
seems
dispose never happended(I add a print statement in dispose method, but no
message
print to console unless I dispose the Contents EditPart).

> > ReportPS rs = new ReportPS(jasperDesign);
>
> If PS == propertysheet, you can wrap it later only for the propertysheet,
> and use it's regular API from the EdirPart.
>

PS is the model which implement IPropertySource interface. Just like the
class
LogicDiagram in logic examples.

> > EditPart report = new ReportEditPart();
>
> You can put a factory on the EditPartViewers that will do this, and then
....
>

Yes, the factory is the new design pattern since GEF Build 20020604, and I
will
change my code to that pattern later. :-)

Thanks for your help!

Eric
Re: Question about EditPart.setModel() & EditPartViewer.setContents() [message #11756 is a reply to message #11650] Mon, 01 July 2002 10:52 Go to previous message
Eclipse UserFriend
Originally posted by: none.ibm.com

> > > public void setJasperDesign(JasperDesign jasperDesign) {
> > > if (this.jasperDesign != jasperDesign) {
> > > this.jasperDesign = jasperDesign;
> > > EditPart oldReport = getGraphicalViewer().getContents();
> > > EditPart oldTreeContents = getOutlineViewer().getContents();
> > > if (oldReport != null) oldReport.dispose();
> > > if (oldTreeContents != null) oldTreeContents.dispose();
> >
> > There should be no reason to get the old contents and dispose. Per
other
> > postings, dispose is not guaranteed to call. But, The RootEditPart
should
> > already dispose the old contents (and deactivate()) when setting the new
> > contents. It would be nice someone to verify this :-), though
> >
>
> I don't think so, if I does not to get the old contents and dispose it,
> seems
> dispose never happended(I add a print statement in dispose method, but no
> message
> print to console unless I dispose the Contents EditPart).

Then this is a bug. Please open a bugzilla. This is supposed to work.
And, once working I think you should be swapping EditPArts, not the model
for the EditPart.
However note that dispose() on EditParts is not called when you close the
Viewer.


> > > ReportPS rs = new ReportPS(jasperDesign);
> >
> > If PS == propertysheet, you can wrap it later only for the
propertysheet,
> > and use it's regular API from the EdirPart.
> >
>
> PS is the model which implement IPropertySource interface. Just like the
> class
> LogicDiagram in logic examples.

We mixed IPropertySource into our model. It looks like you are wrapping our
Model. Both are the same. But, my point was that if your *model*
(jasperDesign) implemented IAdaptable, it could return the wrapper only when
the PropertySheet needed it. Or, if you don't want to modify your model at
all, then your EditPart can override getAdapter(Class adapterType), and wrap
the jasperDesign at that point.

Otherwise, it seems like you will have to promote API from jasperDesign to
the ReportPS.

> Yes, the factory is the new design pattern since GEF Build 20020604, and I
> will
> change my code to that pattern later. :-)

Good eye! It is new, and hopefully easier to use :-)
Previous Topic:Disposing
Next Topic:GUI Builder - best approach
Goto Forum:
  


Current Time: Thu May 08 11:30:46 EDT 2025

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

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

Back to the top