Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Refresh RootEditPart
Refresh RootEditPart [message #663821] Wed, 06 April 2011 14:30 Go to next message
Ugo Sangiorgi is currently offline Ugo SangiorgiFriend
Messages: 59
Registered: January 2010
Member
I have a custom layer on my
org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart ,
I tried everything to refresh and show its figure, but it only refreshes
when i add or move something, and also when I resize the editor area, of
course.

Any hints?


my createFigure() and getContentPane():

@Override
/**
* Replaces default figure with layered pane. Lower layer for
decorations, upper is original figure.
*/
protected IFigure createFigure() {
FreeformLayeredPane pane = new FreeformLayeredPane();
FreeformLayer roseLayer = new FreeformLayer() {

public Rectangle getFreeformExtent() {
// Do not count children; they are decorations that
should not interfere with diagram contents.
Insets insets = getInsets();
return new Rectangle(0, 0, insets.getWidth(),
insets.getHeight());
}
};
roseLayer.setLayoutManager(new StackLayout());
pane.add(roseLayer);
roseLayer.add(new Figure() {
@Override
public void paint(Graphics g) {
g.setLineWidth(1);
g.setForegroundColor(new Color(null, 100, 100, 100));

DiagramImpl d = (DiagramImpl) getModel();

Sketch s = ((Diagram) d.getElement()).getRootSketch();

if (s != null) {

for (int i = 1; i < s.getPointlist().size(); i++) {
Point p = (Point) s.getPointlist().get(i);
Point lastp = p;
lastp = (Point) s.getPointlist().get(i - 1);

if (lastp.x == -1) {
//if the last point is a pen lift, then
consider just the current one
g.drawLine(p.x, p.y, p.x, p.y);

} else if (p.x > 0) {
//if is a normal point, then traces a line
from the last point to the current
g.drawLine(lastp.x, lastp.y, p.x, p.y);
}

}
}

}
});

pane.add(contentPane = super.createFigure());
return pane;
}

@Override
public IFigure getContentPane() {
return contentPane;
}
Re: Refresh RootEditPart [message #664674 is a reply to message #663821] Mon, 11 April 2011 14:49 Go to previous messageGo to next message
Ugo Sangiorgi is currently offline Ugo SangiorgiFriend
Messages: 59
Registered: January 2010
Member
Nobody?
=(
Le 06/04/11 16:30, Ugo Sangiorgi a écrit :
> I have a custom layer on my
> org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart ,
> I tried everything to refresh and show its figure, but it only
> refreshes when i add or move something, and also when I resize the
> editor area, of course.
>
> Any hints?
>
>
> my createFigure() and getContentPane():
>
> @Override
> /**
> * Replaces default figure with layered pane. Lower layer for
> decorations, upper is original figure.
> */
> protected IFigure createFigure() {
> FreeformLayeredPane pane = new FreeformLayeredPane();
> FreeformLayer roseLayer = new FreeformLayer() {
>
> public Rectangle getFreeformExtent() {
> // Do not count children; they are decorations that
> should not interfere with diagram contents.
> Insets insets = getInsets();
> return new Rectangle(0, 0, insets.getWidth(),
> insets.getHeight());
> }
> };
> roseLayer.setLayoutManager(new StackLayout());
> pane.add(roseLayer);
> roseLayer.add(new Figure() {
> @Override
> public void paint(Graphics g) {
> g.setLineWidth(1);
> g.setForegroundColor(new Color(null, 100, 100, 100));
>
> DiagramImpl d = (DiagramImpl) getModel();
>
> Sketch s = ((Diagram) d.getElement()).getRootSketch();
>
> if (s != null) {
>
> for (int i = 1; i < s.getPointlist().size(); i++) {
> Point p = (Point) s.getPointlist().get(i);
> Point lastp = p;
> lastp = (Point) s.getPointlist().get(i - 1);
>
> if (lastp.x == -1) {
> //if the last point is a pen lift, then
> consider just the current one
> g.drawLine(p.x, p.y, p.x, p.y);
>
> } else if (p.x > 0) {
> //if is a normal point, then traces a line
> from the last point to the current
> g.drawLine(lastp.x, lastp.y, p.x, p.y);
> }
>
> }
> }
>
> }
> });
>
> pane.add(contentPane = super.createFigure());
> return pane;
> }
>
> @Override
> public IFigure getContentPane() {
> return contentPane;
> }
>
Re: Refresh RootEditPart [message #664679 is a reply to message #664674] Mon, 11 April 2011 15:06 Go to previous messageGo to next message
Elhamlaoui Mahmoud is currently offline Elhamlaoui MahmoudFriend
Messages: 263
Registered: March 2010
Senior Member
HI,

may be sthis link could help you :
http://www.eclipse.org/forums/index.php?t=msg&goto=17663 1&S=d407a8cee29e2c8d83a8478067722c4c#msg_176631
Re: Refresh RootEditPart [message #666062 is a reply to message #663821] Mon, 18 April 2011 20:06 Go to previous messageGo to next message
Robin  randst is currently offline Robin randstFriend
Messages: 7
Registered: April 2011
Junior Member
Hi, did you refresh the diagram (as DiagramEditPart.refresh()) at the
end of after your code, if it doesnt work maybe try to refresh all children

for(Object o : yourDiagramEditPart.getChildren()){
if(o instanceof EditPart){//or ur costumized EditPart
EditPart editPart = (EditPart)o;
editPart.refresh();
}
}
maybe u have to go deeper in the childrentree.
I had a problem like this before, that some labels didnt refresh, so i
had to refresh the LabelEditParts children of the Figures in the diagram.


Am 06.04.2011 16:30, schrieb Ugo Sangiorgi:
> I have a custom layer on my
> org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart ,
> I tried everything to refresh and show its figure, but it only refreshes
> when i add or move something, and also when I resize the editor area, of
> course.
>
> Any hints?
>
>
> my createFigure() and getContentPane():
>
> @Override
> /**
> * Replaces default figure with layered pane. Lower layer for
> decorations, upper is original figure.
> */
> protected IFigure createFigure() {
> FreeformLayeredPane pane = new FreeformLayeredPane();
> FreeformLayer roseLayer = new FreeformLayer() {
>
> public Rectangle getFreeformExtent() {
> // Do not count children; they are decorations that should not interfere
> with diagram contents.
> Insets insets = getInsets();
> return new Rectangle(0, 0, insets.getWidth(),
> insets.getHeight());
> }
> };
> roseLayer.setLayoutManager(new StackLayout());
> pane.add(roseLayer);
> roseLayer.add(new Figure() {
> @Override
> public void paint(Graphics g) {
> g.setLineWidth(1);
> g.setForegroundColor(new Color(null, 100, 100, 100));
>
> DiagramImpl d = (DiagramImpl) getModel();
>
> Sketch s = ((Diagram) d.getElement()).getRootSketch();
>
> if (s != null) {
>
> for (int i = 1; i < s.getPointlist().size(); i++) {
> Point p = (Point) s.getPointlist().get(i);
> Point lastp = p;
> lastp = (Point) s.getPointlist().get(i - 1);
>
> if (lastp.x == -1) {
> //if the last point is a pen lift, then consider just the current one
> g.drawLine(p.x, p.y, p.x, p.y);
>
> } else if (p.x > 0) {
> //if is a normal point, then traces a line from the last point to the
> current
> g.drawLine(lastp.x, lastp.y, p.x, p.y);
> }
>
> }
> }
>
> }
> });
>
> pane.add(contentPane = super.createFigure());
> return pane;
> }
>
> @Override
> public IFigure getContentPane() {
> return contentPane;
> }
>
Re: Refresh RootEditPart [message #666113 is a reply to message #666062] Tue, 19 April 2011 07:54 Go to previous messageGo to next message
Sophia is currently offline SophiaFriend
Messages: 4
Registered: March 2011
Junior Member
check this link
https://bugs.eclipse.org/bugs/show_bug.cgi?id=281014
Re: Refresh RootEditPart [message #666600 is a reply to message #666062] Thu, 21 April 2011 09:21 Go to previous messageGo to next message
Ugo Sangiorgi is currently offline Ugo SangiorgiFriend
Messages: 59
Registered: January 2010
Member
Hello Robin,

thank you, but actually my editor starts with no editparts at all. I
write some freehand drawn pixels at the RootEditPart and want it to be
displayed.

If I resize the editor, the RootEditPart is refreshed and shows the
drawing.

I just want to activate that =(

Le 18/04/11 22:06, Robin Brandstädter a écrit :
> Hi, did you refresh the diagram (as DiagramEditPart.refresh()) at the
> end of after your code, if it doesnt work maybe try to refresh all
> children
>
> for(Object o : yourDiagramEditPart.getChildren()){
> if(o instanceof EditPart){//or ur costumized EditPart
> EditPart editPart = (EditPart)o;
> editPart.refresh();
> }
> }
> maybe u have to go deeper in the childrentree.
> I had a problem like this before, that some labels didnt refresh, so i
> had to refresh the LabelEditParts children of the Figures in the diagram.
>
>
> Am 06.04.2011 16:30, schrieb Ugo Sangiorgi:
>> I have a custom layer on my
>> org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart ,
>> I tried everything to refresh and show its figure, but it only refreshes
>> when i add or move something, and also when I resize the editor area, of
>> course.
>>
>> Any hints?
>>
>>
>> my createFigure() and getContentPane():
>>
>> @Override
>> /**
>> * Replaces default figure with layered pane. Lower layer for
>> decorations, upper is original figure.
>> */
>> protected IFigure createFigure() {
>> FreeformLayeredPane pane = new FreeformLayeredPane();
>> FreeformLayer roseLayer = new FreeformLayer() {
>>
>> public Rectangle getFreeformExtent() {
>> // Do not count children; they are decorations that should not interfere
>> with diagram contents.
>> Insets insets = getInsets();
>> return new Rectangle(0, 0, insets.getWidth(),
>> insets.getHeight());
>> }
>> };
>> roseLayer.setLayoutManager(new StackLayout());
>> pane.add(roseLayer);
>> roseLayer.add(new Figure() {
>> @Override
>> public void paint(Graphics g) {
>> g.setLineWidth(1);
>> g.setForegroundColor(new Color(null, 100, 100, 100));
>>
>> DiagramImpl d = (DiagramImpl) getModel();
>>
>> Sketch s = ((Diagram) d.getElement()).getRootSketch();
>>
>> if (s != null) {
>>
>> for (int i = 1; i < s.getPointlist().size(); i++) {
>> Point p = (Point) s.getPointlist().get(i);
>> Point lastp = p;
>> lastp = (Point) s.getPointlist().get(i - 1);
>>
>> if (lastp.x == -1) {
>> //if the last point is a pen lift, then consider just the current one
>> g.drawLine(p.x, p.y, p.x, p.y);
>>
>> } else if (p.x > 0) {
>> //if is a normal point, then traces a line from the last point to the
>> current
>> g.drawLine(lastp.x, lastp.y, p.x, p.y);
>> }
>>
>> }
>> }
>>
>> }
>> });
>>
>> pane.add(contentPane = super.createFigure());
>> return pane;
>> }
>>
>> @Override
>> public IFigure getContentPane() {
>> return contentPane;
>> }
>>
>
Re: Refresh RootEditPart [message #666603 is a reply to message #666113] Thu, 21 April 2011 09:36 Go to previous messageGo to next message
Ugo Sangiorgi is currently offline Ugo SangiorgiFriend
Messages: 59
Registered: January 2010
Member
Le 19/04/11 09:54, Sophia a écrit :
> check this link
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=281014
Thank you Sophia,
I've tried to remove the semanticHints, apparently it did nothing.

Also, i tried to refresh the editpolicies, see:

EObject modelElement = ((View)
(editor.getDiagramEditPart().getModel())).getElement();
List editPolicies =
CanonicalEditPolicy.getRegisteredEditPolicies(modelElement);
for (Iterator it = editPolicies.iterator(); it.hasNext();) {
DiagramCanonicalEditPolicy nextEditPolicy =
(DiagramCanonicalEditPolicy) it
.next();
nextEditPolicy.activate();
nextEditPolicy.getViewer().getControl().redraw();
nextEditPolicy.refresh();
}

but nothing
=(
Re: Refresh RootEditPart [message #666783 is a reply to message #663821] Fri, 22 April 2011 14:28 Go to previous messageGo to next message
Ugo Sangiorgi is currently offline Ugo SangiorgiFriend
Messages: 59
Registered: January 2010
Member
What is even more weird is that:
When I open the diagram it doesnt show anything, only if I resize the
editor area.
Then the next drawings shows up normally, the editor is refreshed and all.

What could be hapening? How can I tell that the editor needs to be
repainted upfront?

Le 06/04/11 16:30, Ugo Sangiorgi a écrit :
> I have a custom layer on my
> org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart ,
> I tried everything to refresh and show its figure, but it only
> refreshes when i add or move something, and also when I resize the
> editor area, of course.
>
> Any hints?
>
>
> my createFigure() and getContentPane():
>
> @Override
> /**
> * Replaces default figure with layered pane. Lower layer for
> decorations, upper is original figure.
> */
> protected IFigure createFigure() {
> FreeformLayeredPane pane = new FreeformLayeredPane();
> FreeformLayer roseLayer = new FreeformLayer() {
>
> public Rectangle getFreeformExtent() {
> // Do not count children; they are decorations that
> should not interfere with diagram contents.
> Insets insets = getInsets();
> return new Rectangle(0, 0, insets.getWidth(),
> insets.getHeight());
> }
> };
> roseLayer.setLayoutManager(new StackLayout());
> pane.add(roseLayer);
> roseLayer.add(new Figure() {
> @Override
> public void paint(Graphics g) {
> g.setLineWidth(1);
> g.setForegroundColor(new Color(null, 100, 100, 100));
>
> DiagramImpl d = (DiagramImpl) getModel();
>
> Sketch s = ((Diagram) d.getElement()).getRootSketch();
>
> if (s != null) {
>
> for (int i = 1; i < s.getPointlist().size(); i++) {
> Point p = (Point) s.getPointlist().get(i);
> Point lastp = p;
> lastp = (Point) s.getPointlist().get(i - 1);
>
> if (lastp.x == -1) {
> //if the last point is a pen lift, then
> consider just the current one
> g.drawLine(p.x, p.y, p.x, p.y);
>
> } else if (p.x > 0) {
> //if is a normal point, then traces a line
> from the last point to the current
> g.drawLine(lastp.x, lastp.y, p.x, p.y);
> }
>
> }
> }
>
> }
> });
>
> pane.add(contentPane = super.createFigure());
> return pane;
> }
>
> @Override
> public IFigure getContentPane() {
> return contentPane;
> }
>
Re: Refresh RootEditPart [SOLVED] [message #667045 is a reply to message #666783] Tue, 26 April 2011 07:57 Go to previous message
Ugo Sangiorgi is currently offline Ugo SangiorgiFriend
Messages: 59
Registered: January 2010
Member
I did solved.

My DiagramEditPart reads the model (which has some x,y points) and draws
them accordingly:

private IFigure contentPane;

@Override
/**
* Replaces default figure with layered pane. Lower layer for
decorations, upper is original figure.
*/
protected IFigure createFigure() {
FreeformLayeredPane pane = new FreeformLayeredPane();
FreeformLayer sketchLayer = new FreeformLayer() {

public Rectangle getFreeformExtent() {
// Do not count children; they are decorations that
should not interfere with diagram contents.
Insets insets = getInsets();
return new Rectangle(0, 0, insets.getWidth(),
insets.getHeight());
}
};
sketchLayer.setLayoutManager(new StackLayout());
pane.add(sketchLayer);
sketchLayer.add(new Figure() {
@Override
public void paint(Graphics g) {


[here i draw whatever i want]

}
});

pane.add(contentPane = super.createFigure());
return pane;
}

I just neeeded to refresh through a request, with this the editpart is
refreshed upon creation:
...
@Override
public IFigure getContentPane() {
performRequest(new Request(RequestConstants.REQ_REFRESH));
return contentPane;
}
....

Outside the DiagramEditPart I just performed the refresh request:
editor.getDiagramEditPart().performRequest(new
Request(RequestConstants.REQ_REFRESH));



Thats it =)

Le 22/04/11 16:28, Ugo Sangiorgi a écrit :
> What is even more weird is that:
> When I open the diagram it doesnt show anything, only if I resize the
> editor area.
> Then the next drawings shows up normally, the editor is refreshed and
> all.
>
> What could be hapening? How can I tell that the editor needs to be
> repainted upfront?
>
> Le 06/04/11 16:30, Ugo Sangiorgi a écrit :
>> I have a custom layer on my
>> org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart ,
>> I tried everything to refresh and show its figure, but it only
>> refreshes when i add or move something, and also when I resize the
>> editor area, of course.
>>
>> Any hints?
>>
>>
>> my createFigure() and getContentPane():
>>
>> @Override
>> /**
>> * Replaces default figure with layered pane. Lower layer for
>> decorations, upper is original figure.
>> */
>> protected IFigure createFigure() {
>> FreeformLayeredPane pane = new FreeformLayeredPane();
>> FreeformLayer roseLayer = new FreeformLayer() {
>>
>> public Rectangle getFreeformExtent() {
>> // Do not count children; they are decorations that
>> should not interfere with diagram contents.
>> Insets insets = getInsets();
>> return new Rectangle(0, 0, insets.getWidth(),
>> insets.getHeight());
>> }
>> };
>> roseLayer.setLayoutManager(new StackLayout());
>> pane.add(roseLayer);
>> roseLayer.add(new Figure() {
>> @Override
>> public void paint(Graphics g) {
>> g.setLineWidth(1);
>> g.setForegroundColor(new Color(null, 100, 100, 100));
>>
>> DiagramImpl d = (DiagramImpl) getModel();
>>
>> Sketch s = ((Diagram) d.getElement()).getRootSketch();
>>
>> if (s != null) {
>>
>> for (int i = 1; i < s.getPointlist().size(); i++) {
>> Point p = (Point) s.getPointlist().get(i);
>> Point lastp = p;
>> lastp = (Point) s.getPointlist().get(i - 1);
>>
>> if (lastp.x == -1) {
>> //if the last point is a pen lift, then
>> consider just the current one
>> g.drawLine(p.x, p.y, p.x, p.y);
>>
>> } else if (p.x > 0) {
>> //if is a normal point, then traces a
>> line from the last point to the current
>> g.drawLine(lastp.x, lastp.y, p.x, p.y);
>> }
>>
>> }
>> }
>>
>> }
>> });
>>
>> pane.add(contentPane = super.createFigure());
>> return pane;
>> }
>>
>> @Override
>> public IFigure getContentPane() {
>> return contentPane;
>> }
>>
>
Previous Topic:Drag and Drop Java files
Next Topic:[SOLVED] How to programmatically set the location of a label?
Goto Forum:
  


Current Time: Wed Nov 26 23:27:47 GMT 2014

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

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