Home » Modeling » GMF (Graphical Modeling Framework) » problem with notifications
problem with notifications [message #172027] |
Mon, 11 February 2008 03:10  |
Eclipse User |
|
|
|
Originally posted by: Sid.v.v
Hello,
i have a problem with notifications. in one of my node-parts i do some
graphical changes in the method notifyChanged().
if i get a notification from the node-parts ecore-implementation (for
example i change a value of the node) the graphical changes are not
correct, they arent just done. i have to move the node afterwards, so it
will get a bounds-notification and then the graphical changes will work.
could someone give me a hint how to solve this?
Greetings Sid
|
|
| |
Re: problem with notifications [message #172049 is a reply to message #172035] |
Mon, 11 February 2008 08:18   |
Eclipse User |
|
|
|
Originally posted by: Sid.v.v
Hi Tobias!
thanks for your answer. ive already tried this. But refreshVisuals seems
not to be working. I spend a lot of time debugging this ... the behaviour
is like this:
if i changed a node property then nodeimpl-notification is called ->no
refresh
if i move the node after i changed a node property then
BoundImpl-Notification is called AND immediately afterwards
nodeimpl-notification is called ->refresh
my source code:
public void notifyChanged(Notification notification) {
super.notifyChanged(notification);
int feature = notification.getFeatureID(PetriPackage.class);
switch (feature) {
case PetriPackage.STELLE__MARKEN:
getPrimaryShape().updateGraphics(getCastedModel().getMarken( ));
refreshVisuals();
break;
}
}
public void updateGraphics(int tokens) {
Point p = this.getLocation();
this.fFigureDOT1.setLocation(new Point(p.x + 9,
p.y + 7));
this.fFigureDOT1.setSize(5, 5);
this.fFigureDOT2.setLocation(new Point(p.x + 15,
p.y + 7));
this.fFigureDOT2.setSize(5, 5);
this.fFigureDOT3.setLocation(new Point(p.x + 21,
p.y + 7));
this.fFigureDOT3.setSize(5, 5);
this.fFigureDOT4.setLocation(new Point(p.x + 6,
p.y + 15));
this.fFigureDOT4.setSize(5, 5);
this.fFigureDOT5.setLocation(new Point(p.x + 12,
p.y + 15));
this.fFigureDOT5.setSize(5, 5);
this.fFigureDOT6.setLocation(new Point(p.x + 18,
p.y + 15));
this.fFigureDOT6.setSize(5, 5);
this.fFigureDOT7.setLocation(new Point(p.x + 24,
p.y + 15));
this.fFigureDOT7.setSize(5, 5);
this.fFigureDOT8.setLocation(new Point(p.x + 9,
p.y + 24));
this.fFigureDOT8.setSize(5, 5);
this.fFigureDOT9.setLocation(new Point(p.x + 15,
p.y + 24));
this.fFigureDOT9.setSize(5, 5);
this.fFigureDOT10.setLocation(new Point(p.x + 21,
p.y + 24));
this.fFigureDOT10.setSize(5, 5);
boolean b[] = new boolean[10];
for(int i=0;i<b.length;i++)b[i]=false;
if(tokens>0&tokens<11)
{
b[0]=true;
if(tokens>1)b[1]=true;
if(tokens>2)b[2]=true;
if(tokens>3)b[3]=true;
if(tokens>4)b[4]=true;
if(tokens>5)b[5]=true;
if(tokens>6)b[6]=true;
if(tokens>7)b[7]=true;
if(tokens>8)b[8]=true;
if(tokens>9)b[9]=true;
}
this.fFigureDOT1.setVisible(b[0]);
this.fFigureDOT2.setVisible(b[1]);
this.fFigureDOT3.setVisible(b[2]);
this.fFigureDOT4.setVisible(b[3]);
this.fFigureDOT5.setVisible(b[4]);
this.fFigureDOT6.setVisible(b[5]);
this.fFigureDOT7.setVisible(b[6]);
this.fFigureDOT8.setVisible(b[7]);
this.fFigureDOT9.setVisible(b[8]);
this.fFigureDOT10.setVisible(b[9]);
}
Tobias wrote:
> A simple refreshVisuals() should do, like this:
> public void notifyChanged(Notification notification) {
> super.notifyChanged(notification);
> int feature = notification.getFeatureID(VsdtPackage.class);
> switch (feature) {
> case VsdtPackage.ACTIVITY__LOOP_TYPE:
> getPrimaryShape().setLoopType(getCastedModel().getLoopType() );;
> refreshVisuals();
> break;
> ...more cases
> Tobias
|
|
|
Re: problem with notifications [message #172276 is a reply to message #172049] |
Tue, 12 February 2008 05:53   |
Eclipse User |
|
|
|
Originally posted by: jan.herriger.gmx.de
AFAIK, always the parent editparts have to refresh their children, if
children visuals changed. A convenient method is to call
#handleMajorSemanticChange, which will invote the parent editpart's
refresh mechanism.
Sid schrieb:
> Hi Tobias!
>
> thanks for your answer. ive already tried this. But refreshVisuals seems
> not to be working. I spend a lot of time debugging this ... the
> behaviour is like this:
> if i changed a node property then nodeimpl-notification is called ->no
> refresh
>
> if i move the node after i changed a node property then
> BoundImpl-Notification is called AND immediately afterwards
> nodeimpl-notification is called ->refresh
>
> my source code:
>
> public void notifyChanged(Notification notification) {
> super.notifyChanged(notification);
>
> int feature = notification.getFeatureID(PetriPackage.class);
> switch (feature) {
> case PetriPackage.STELLE__MARKEN:
>
>
> getPrimaryShape().updateGraphics(getCastedModel().getMarken( ));
> refreshVisuals();
> break;
>
> }
>
> }
>
> public void updateGraphics(int tokens) {
>
>
> Point p = this.getLocation();
>
> this.fFigureDOT1.setLocation(new Point(p.x + 9,
> p.y + 7));
> this.fFigureDOT1.setSize(5, 5);
> this.fFigureDOT2.setLocation(new Point(p.x + 15,
> p.y + 7));
> this.fFigureDOT2.setSize(5, 5);
> this.fFigureDOT3.setLocation(new Point(p.x + 21,
> p.y + 7));
> this.fFigureDOT3.setSize(5, 5);
> this.fFigureDOT4.setLocation(new Point(p.x + 6,
> p.y + 15));
> this.fFigureDOT4.setSize(5, 5);
> this.fFigureDOT5.setLocation(new Point(p.x + 12,
> p.y + 15));
> this.fFigureDOT5.setSize(5, 5);
> this.fFigureDOT6.setLocation(new Point(p.x + 18,
> p.y + 15));
> this.fFigureDOT6.setSize(5, 5);
> this.fFigureDOT7.setLocation(new Point(p.x + 24,
> p.y + 15));
> this.fFigureDOT7.setSize(5, 5);
> this.fFigureDOT8.setLocation(new Point(p.x + 9,
> p.y + 24));
> this.fFigureDOT8.setSize(5, 5);
> this.fFigureDOT9.setLocation(new Point(p.x + 15,
> p.y + 24));
> this.fFigureDOT9.setSize(5, 5);
> this.fFigureDOT10.setLocation(new Point(p.x + 21,
> p.y + 24));
> this.fFigureDOT10.setSize(5, 5);
> boolean b[] = new boolean[10];
> for(int i=0;i<b.length;i++)b[i]=false;
>
>
>
> if(tokens>0&tokens<11)
> {
> b[0]=true;
> if(tokens>1)b[1]=true;
> if(tokens>2)b[2]=true;
> if(tokens>3)b[3]=true;
> if(tokens>4)b[4]=true;
> if(tokens>5)b[5]=true;
> if(tokens>6)b[6]=true;
> if(tokens>7)b[7]=true;
> if(tokens>8)b[8]=true;
> if(tokens>9)b[9]=true;
> }
>
> this.fFigureDOT1.setVisible(b[0]);
> this.fFigureDOT2.setVisible(b[1]);
> this.fFigureDOT3.setVisible(b[2]);
> this.fFigureDOT4.setVisible(b[3]);
> this.fFigureDOT5.setVisible(b[4]);
> this.fFigureDOT6.setVisible(b[5]);
> this.fFigureDOT7.setVisible(b[6]);
> this.fFigureDOT8.setVisible(b[7]);
> this.fFigureDOT9.setVisible(b[8]);
> this.fFigureDOT10.setVisible(b[9]);
>
>
> }
>
>
> Tobias wrote:
>
>> A simple refreshVisuals() should do, like this:
>
>> public void notifyChanged(Notification notification) {
>> super.notifyChanged(notification);
>> int feature = notification.getFeatureID(VsdtPackage.class);
>> switch (feature) {
>> case VsdtPackage.ACTIVITY__LOOP_TYPE:
>> getPrimaryShape().setLoopType(getCastedModel().getLoopType() );;
>> refreshVisuals();
>> break;
>> ...more cases
>
>> Tobias
>
>
|
|
| | | |
Re: problem with notifications [message #172535 is a reply to message #172470] |
Thu, 14 February 2008 06:43   |
Eclipse User |
|
|
|
Originally posted by: jan.herriger.gmx.de
This is a multi-part message in MIME format.
--------------080009070709010304040700
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
> Thanks for that link. I've tried that too, but it failed also. I think i
> will give it a second try, just to prove it.
> By the way: whats the difference between notifyChanged() and
> handleNotificationEvent()?
handleNotificationEvent() is called by notifyChanged() inside
GraphicalEditPart iff the edit part is active.
> i dont know if setting the visibility of edit-parts is the best
> solution. so any suggestion are welcome.
You mean setting visibility of figures, don't you? I don't know if this
is the best solution. But I had a similar problem and it's working fine
for me (a diamond, which displays either an 'and' or an 'or' symbol).
I attached my edit part. May be, you'll find something helpful in it.
> and more question about notifications: how can a editpart notify all
> other editparts?
IMHO notifications should only be send from models (notation
model/semantic model) to controllers (edit parts).
You can enable an edit part to listen to more notifiers, by overriding
GraphicalEditPart#addNotationalListeners()/addSemanticListen ers(). But
this should not be necessary in this case.
--------------080009070709010304040700
Content-Type: text/java;
name="SynchronizerEditPart.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="SynchronizerEditPart.java"
package org.memo.orgml.process.controlflow.diagram.edit.parts;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Polygon;
import org.eclipse.draw2d.Polyline;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.StackLayout;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
import org.eclipse.gef.editpolicies.ResizableEditPolicy;
import org.eclipse.gef.requests.CreateRequest;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPa rt;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRo les;
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure ;
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
import org.eclipse.gmf.runtime.notation.View;
import org.memo.orgml.process.ProcessPackage;
import org.memo.orgml.process.Synchronizer;
import org.memo.orgml.process.controlflow.diagram.edit.policies.Syn chronizerItemSemanticEditPolicy;
/**
* @generated
*/
public class SynchronizerEditPart extends ShapeNodeEditPart {
/**
* @generated
*/
public static final int VISUAL_ID = 2107;
/**
* @generated
*/
protected IFigure contentPane;
/**
* @generated
*/
protected IFigure primaryShape;
/**
* @generated
*/
public SynchronizerEditPart(View view) {
super(view);
}
/**
* @generated NOT
*/
@Override
public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart arg0) {
FixedConnectionAnchor fixedAnchor = new FixedConnectionAnchor(
getFigure(), FixedConnectionAnchor.Side.EAST);
return fixedAnchor;
}
/**
* @generated NOT
*/
@Override
public ConnectionAnchor getSourceConnectionAnchor(Request request) {
FixedConnectionAnchor fixedAnchor = new FixedConnectionAnchor(
getFigure(), FixedConnectionAnchor.Side.EAST);
return fixedAnchor;
}
/**
* @generated NOT
*/
@Override
public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart arg0) {
return new FixedCenteredConnectionAnchor(getFigure());
}
/**
* @generated NOT
*/
@Override
public ConnectionAnchor getTargetConnectionAnchor(Request request) {
return new FixedCenteredConnectionAnchor(getFigure());
}
/**
* @generated
*/
protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
new SynchronizerItemSemanticEditPolicy());
installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
// XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies
// removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpoli cies.EditPolicyRoles.CONNECTION_HANDLES_ROLE);
}
/**
* @generated
*/
protected LayoutEditPolicy createLayoutEditPolicy() {
LayoutEditPolicy lep = new LayoutEditPolicy() {
protected EditPolicy createChildEditPolicy(EditPart child) {
EditPolicy result = child
.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
if (result == null) {
result = new NonResizableEditPolicy();
}
return result;
}
protected Command getMoveChildrenCommand(Request request) {
return null;
}
protected Command getCreateCommand(CreateRequest request) {
return null;
}
};
return lep;
}
/**
* @generated
*/
protected IFigure createNodeShape() {
SynchronizerFigure figure = new SynchronizerFigure();
return primaryShape = figure;
}
/**
* @generated
*/
public SynchronizerFigure getPrimaryShape() {
return (SynchronizerFigure) primaryShape;
}
/**
* @generated
*/
protected NodeFigure createNodePlate() {
DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode()
.DPtoLP(40), getMapMode().DPtoLP(40));
return result;
}
/**
* @generated
*/
public EditPolicy getPrimaryDragEditPolicy() {
EditPolicy result = super.getPrimaryDragEditPolicy();
if (result instanceof ResizableEditPolicy) {
ResizableEditPolicy ep = (ResizableEditPolicy) result;
ep.setResizeDirections(PositionConstants.NONE);
}
return result;
}
/**
* Creates figure for this edit part.
*
* Body of this method does not depend on settings in generation model
* so you may safely remove <i>generated</i> tag and modify it.
*
* @generated
*/
protected NodeFigure createNodeFigure() {
NodeFigure figure = createNodePlate();
figure.setLayoutManager(new StackLayout());
IFigure shape = createNodeShape();
figure.add(shape);
contentPane = setupContentPane(shape);
return figure;
}
/**
* Default implementation treats passed figure as content pane.
* Respects layout one may have set for generated figure.
* @param nodeShape instance of generated figure class
* @generated
*/
protected IFigure setupContentPane(IFigure nodeShape) {
return nodeShape; // use nodeShape itself as contentPane
}
/**
* @generated
*/
public IFigure getContentPane() {
if (contentPane != null) {
return contentPane;
}
return super.getContentPane();
}
/**
* @generated NOT
*/
protected void handleNotificationEvent(Notification event) {
//generated statement
if (event.getNotifier() == getModel()
&& EcorePackage.eINSTANCE.getEModelElement_EAnnotations()
.equals(event.getFeature())) {
handleMajorSemanticChange();
}
//Synchronizer type changed
if (ProcessPackage.eINSTANCE.getSynchronizer_Conjunctive()
.equals(event.getFeature())) {
getPrimaryShape().switchType();
}
super.handleNotificationEvent(event);
}
/**
* @generated
*/
public class SynchronizerFigure extends RectangleFigure {
/**
* @generated
*/
private Polyline fFigureOrFigure;
/**
* @generated
*/
private Polyline fFigureAndFigure;
/**
* @generated
*/
public SynchronizerFigure() {
this.setOutline(false);
createContents();
switchType();
}
/**
* Switch between 'conjunctive' figure and 'disjunctive' figure
* depending on underlying element
*/
private void switchType()
{
Synchronizer element = (Synchronizer)resolveSemanticElement();
if (element!=null)
{
if (element.isConjunctive())
{
this.getFigureOrFigure().setVisible(true);
this.getFigureAndFigure().setVisible(false);
}
else
{
this.getFigureOrFigure().setVisible(false);
this.getFigureAndFigure().setVisible(true);
}
}
}
/**
* @generated
*/
private void createContents() {
Polygon synchronizerFigure0 = new Polygon();
synchronizerFigure0.addPoint(new Point(getMapMode().DPtoLP(20),
getMapMode().DPtoLP(0)));
synchronizerFigure0.addPoint(new Point(getMapMode().DPtoLP(40),
getMapMode().DPtoLP(20)));
synchronizerFigure0.addPoint(new Point(getMapMode().DPtoLP(20),
getMapMode().DPtoLP(40)));
synchronizerFigure0.addPoint(new Point(getMapMode().DPtoLP(0),
getMapMode().DPtoLP(20)));
synchronizerFigure0.addPoint(new Point(getMapMode().DPtoLP(20),
getMapMode().DPtoLP(0)));
this.add(synchronizerFigure0);
synchronizerFigure0.setLayoutManager(new FlowLayout());
fFigureAndFigure = new Polyline();
fFigureAndFigure.addPoint(new Point(getMapMode().DPtoLP(10),
getMapMode().DPtoLP(25)));
fFigureAndFigure.addPoint(new Point(getMapMode().DPtoLP(20),
getMapMode().DPtoLP(10)));
fFigureAndFigure.addPoint(new Point(getMapMode().DPtoLP(30),
getMapMode().DPtoLP(25)));
synchronizerFigure0.add(fFigureAndFigure);
fFigureOrFigure = new Polyline();
fFigureOrFigure.addPoint(new Point(getMapMode().DPtoLP(10),
getMapMode().DPtoLP(15)));
fFigureOrFigure.addPoint(new Point(getMapMode().DPtoLP(20),
getMapMode().DPtoLP(30)));
fFigureOrFigure.addPoint(new Point(getMapMode().DPtoLP(30),
getMapMode().DPtoLP(15)));
synchronizerFigure0.add(fFigureOrFigure);
Polygon synchronizerPolygonFigure1 = new Polygon();
synchronizerFigure0.add(synchronizerPolygonFigure1);
}
/**
* @generated
*/
private boolean myUseLocalCoordinates = true;
/**
* @generated
*/
protected boolean useLocalCoordinates() {
return myUseLocalCoordinates;
}
/**
* @generated
*/
protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
myUseLocalCoordinates = useLocalCoordinates;
}
/**
* @generated
*/
public Polyline getFigureOrFigure() {
return fFigureOrFigure;
}
/**
* @generated
*/
public Polyline getFigureAndFigure() {
return fFigureAndFigure;
}
}
}
--------------080009070709010304040700--
|
|
| | | |
Re: problem with notifications [message #172729 is a reply to message #172721] |
Sun, 17 February 2008 12:40  |
Eclipse User |
|
|
|
Originally posted by: Sid.v.v
UPDATE: it works now .. finally :D
ive cleaned up the gmfgraph/gmfmap and created a new generation model ..
works just fine now.
i will now try out the addListenerFilter() method, to keep the nodes
updating
thanks a lot for your help!
best regards
Sid
|
|
|
Goto Forum:
Current Time: Wed Jul 23 17:42:07 EDT 2025
Powered by FUDForum. Page generated in 0.06206 seconds
|