Home » Modeling » GMF (Graphical Modeling Framework) » Problem with setVisible method
|
Re: Problem with setVisible method [message #487838 is a reply to message #487767] |
Thu, 24 September 2009 14:33 |
Artur Kronenberg Messages: 159 Registered: August 2009 |
Senior Member |
|
|
Jose,
I think this is a GMF bug.
Apparently, when the component is set visible the arrange all command does not get that unless you recreate the whole diagram with the hidden edit parts.
To solve this problem you could overwrite the
getRelevantConnections() method in your LayoutProvider. (Unfortunately due to some visibility problems you also have to overwrite handleConnectableListItems() , getFirstAnscestorinNodesMap() and getBorderItemEditParts() )
This is the solution that I found and that worked for me. Maybe there is a better one but so far this would work.
Your gerRelevantConnections will look like that:
@Override
protected List getRelevantConnections(Hashtable editPartToNodeDict) {
Enumeration enumeration = editPartToNodeDict.keys();
ArrayList connectionsToMove = new ArrayList();
while (enumeration.hasMoreElements()) {
Object e = enumeration.nextElement();
GraphicalEditPart shapeEP = (GraphicalEditPart) e;
Set sourceConnections = new HashSet(shapeEP.getSourceConnections());
if (shapeEP instanceof IBorderedShapeEditPart) {
List borderItems = getBorderItemEditParts(shapeEP,
editPartToNodeDict);
for (Iterator iter = borderItems.iterator(); iter.hasNext();) {
GraphicalEditPart element = (GraphicalEditPart) iter.next();
sourceConnections.addAll(element.getSourceConnections());
}
}
for (Iterator iter = sourceConnections.iterator(); iter.hasNext();) {
ConnectionEditPart connectionEP = (ConnectionEditPart) iter
.next();
EditPart target = connectionEP.getTarget();
// check to see if the toView is in the shapesDict, if yes,
// the associated connectionView should be included on graph
if (target instanceof IBorderItemEditPart)
target = target.getParent();
if (target != null) {
Object o = editPartToNodeDict.get(target);
[COLOR=red]if (o != null) {[/COLOR]
connectionsToMove.add(connectionEP);
}
}
}
if (shouldHandleConnectableListItems()) {
handleConnectableListItems(shapeEP, editPartToNodeDict,
connectionsToMove);
}
}
return connectionsToMove;
}
The red part is where you check if the component is actually still there. If you have hid it before this is where you will get the nullpointer exception in your code.
Best,
Artur
Jose Salazar wrote on Thu, 24 September 2009 07:36 | Hello,
I've a problem with the method org.eclipse.gmf.runtime.notation.Node. If I set the visibility to false and I try to arrange the diagram, appears the following error notification:
java.lang.NullPointerException
at java.util.Hashtable.get(Unknown Source)
at org.eclipse.gmf.runtime.diagram.ui.providers.internal.Defaul tProvider.getRelevantConnections(DefaultProvider.java:597)
at org.eclipse.gmf.runtime.diagram.ui.providers.internal.Defaul tProvider.build_graph(DefaultProvider.java:682)
at org.eclipse.gmf.runtime.diagram.ui.providers.internal.Defaul tProvider.layoutEditParts(DefaultProvider.java:147)
at org.eclipse.gmf.runtime.diagram.ui.services.layout.AbstractL ayoutEditPartProvider.layoutLayoutNodes(AbstractLayoutEditPa rtProvider.java:67)
at org.eclipse.gmf.runtime.diagram.ui.internal.services.layout. LayoutNodesOperation.execute(LayoutNodesOperation.java:74)
at org.eclipse.gmf.runtime.common.core.service.ExecutionStrateg y$1.execute(ExecutionStrategy.java:71)
at org.eclipse.gmf.runtime.common.core.service.Service.execute( Service.java:652)
at org.eclipse.gmf.runtime.diagram.ui.services.layout.LayoutSer vice.execute(LayoutService.java:65)
at org.eclipse.gmf.runtime.diagram.ui.services.layout.LayoutSer vice.layoutLayoutNodes(LayoutService.java:298)
at org.eclipse.gmf.runtime.diagram.ui.editpolicies.ContainerEdi tPolicy.layoutNodes(ContainerEditPolicy.java:374)
at org.eclipse.gmf.runtime.diagram.ui.editpolicies.ContainerEdi tPolicy.getArrangeCommand(ContainerEditPolicy.java:329)
at org.eclipse.gmf.runtime.diagram.ui.editpolicies.ContainerEdi tPolicy.getCommand(ContainerEditPolicy.java:513)
at org.eclipse.gef.editparts.AbstractEditPart.getCommand(Abstra ctEditPart.java:473)
If after setting the visibility of the node to true again,I can arrange all, but the node isn't in its right place, I mean, in the same position.
If after any action described above I close the editor and open it again, mistakes do not occur.
Do I have to call a method to make consistent the diagram? What is the problem?
Thanks, any comment could help me.
|
|
|
| |
Re: Problem with setVisible method [message #487889 is a reply to message #487876] |
Thu, 24 September 2009 17:25 |
Artur Kronenberg Messages: 159 Registered: August 2009 |
Senior Member |
|
|
Hi Jan,
the way you added your layout to the plugin xml seems to be fine.
What is not working there?
Here is the turorial for adding a custom layout:
http://wiki.eclipse.org/GMF_Tutorial_Part_3#Custom_Layout
So if you have only one layout you want to support, adding it to the plugin xml and implementing the layout provider should be fine. In addition you have to make the modifications I mentioned in my previous post to make it work for invisible components too.
If you have more then one layout it gets a little tricky. This is how I did it, but this is a custom solution that applied to my project:
In the preference page you can specify if you want to use the topdown or leftright layout. I have two more layouts there, but this should be enough. In the provides method I check which layout is used. I added my layouts to the plugin xml as two seperate extension points. The way GMF handles it, as far as I know, is, that GMF tries every provider until one returns true.
So in my providers I check, if they are the ones who are specified in the preference page. If yes, I return true, if no, I return false. If I return false, GMF goes into the next provider and tries it there and this goes until the right provider returns true and the layout can be arranged.
But like I said, to me the way you implemented yout layout seems to fine and should work. I suppose you implemented the provides method in your class and return true, if you want to use that layout.
Jose Salazar wrote on Thu, 24 September 2009 12:18 | Artur, thank you very much for your quick reply.
The fact is, how can I add my custom layout provider? I mean, I added one long time ago, but in the debug mode never get inside. This is the way in wich I added it in the plugin.xml of the XXX.diagram project:
<extension
id="topDownLayoutProvider"
name="TopDownLayoutProvider"
point="org.eclipse.gmf.runtime.diagram.ui.layoutProviders">
<layoutProvider
class="specializationModel.diagram.providers.SpecializationmodelDefaultLayoutProvider">
<Priority name="High"/>
</layoutProvider>
</extension>
Best,
Jose.
|
|
|
|
Goto Forum:
Current Time: Fri Apr 26 14:22:36 GMT 2024
Powered by FUDForum. Page generated in 0.03055 seconds
|