Skip to content

Commit

Permalink
[NONE] Fix emulated layout was broken for DotGraphView.
Browse files Browse the repository at this point in the history
- Added LayoutBehavior bindings for DOT.UI, which are required for
emulated layout.
- Fix NPE within GraphLayoutBehavior if no hiding model is present (as
for DOT.UI).
  • Loading branch information
nyssen committed Mar 16, 2017
1 parent 042aa88 commit 0a7da34
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.eclipse.gef.common.adapt.AdapterKey;
import org.eclipse.gef.common.adapt.inject.AdaptableScopes;
import org.eclipse.gef.common.adapt.inject.AdapterMaps;
import org.eclipse.gef.layout.LayoutContext;
import org.eclipse.gef.mvc.fx.MvcFxModule;
import org.eclipse.gef.mvc.fx.behaviors.ConnectionClickableAreaBehavior;
import org.eclipse.gef.mvc.fx.behaviors.HoverBehavior;
Expand All @@ -29,8 +30,12 @@
import org.eclipse.gef.mvc.fx.providers.GeometricOutlineProvider;
import org.eclipse.gef.mvc.fx.providers.ShapeBoundsProvider;
import org.eclipse.gef.mvc.fx.viewer.IViewer;
import org.eclipse.gef.zest.fx.behaviors.EdgeLayoutBehavior;
import org.eclipse.gef.zest.fx.behaviors.GraphLayoutBehavior;
import org.eclipse.gef.zest.fx.behaviors.NodeLayoutBehavior;
import org.eclipse.gef.zest.fx.parts.EdgeLabelPart;
import org.eclipse.gef.zest.fx.parts.EdgePart;
import org.eclipse.gef.zest.fx.parts.GraphPart;
import org.eclipse.gef.zest.fx.parts.NodeLabelPart;
import org.eclipse.gef.zest.fx.parts.NodePart;
import org.eclipse.gef.zest.fx.parts.ZestFxContentPartFactory;
Expand Down Expand Up @@ -105,6 +110,10 @@ protected void bindEdgeLabelPartAdapters(
*/
protected void bindEdgePartAdapters(
MapBinder<AdapterKey<?>, Object> adapterMapBinder) {
// layout behavior
adapterMapBinder.addBinding(AdapterKey.defaultRole())
.to(EdgeLayoutBehavior.class);

// selection link feedback provider
adapterMapBinder
.addBinding(AdapterKey
Expand Down Expand Up @@ -203,6 +212,27 @@ protected void bindNodeLabelPartAdapters(
.to(HoverOnHoverHandler.class);
}

/**
* Adds (default) adapter map bindings for {@link GraphPart} and all
* sub-classes. May be overwritten by sub-classes to change the default
* bindings.
*
* @param adapterMapBinder
* The {@link MapBinder} to be used for the binding registration.
* In this case, will be obtained from
* {@link AdapterMaps#getAdapterMapBinder(Binder, Class)} using
* {@link GraphPart} as a key.
*
* @see AdapterMaps#getAdapterMapBinder(Binder, Class)
*/
protected void bindGraphPartAdapters(
MapBinder<AdapterKey<?>, Object> adapterMapBinder) {
adapterMapBinder.addBinding(AdapterKey.defaultRole())
.to(LayoutContext.class);
adapterMapBinder.addBinding(AdapterKey.defaultRole())
.to(GraphLayoutBehavior.class);
}

/**
* Adds (default) adapter map bindings for {@link NodePart} and all
* sub-classes. May be overwritten by sub-classes to change the default
Expand All @@ -218,6 +248,10 @@ protected void bindNodeLabelPartAdapters(
*/
protected void bindNodePartAdapters(
MapBinder<AdapterKey<?>, Object> adapterMapBinder) {
// layout
adapterMapBinder.addBinding(AdapterKey.defaultRole())
.to(NodeLayoutBehavior.class);

// anchor provider
adapterMapBinder.addBinding(AdapterKey.defaultRole())
.to(DotAnchorProvider.class);
Expand Down Expand Up @@ -281,6 +315,8 @@ protected void configure() {

bindIContentPartFactory();

bindGraphPartAdapters(
AdapterMaps.getAdapterMapBinder(binder(), GraphPart.class));
bindNodePartAdapters(
AdapterMaps.getAdapterMapBinder(binder(), NodePart.class));
bindEdgePartAdapters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ public boolean isLayoutIrrelevant(org.eclipse.gef.graph.Node node) {
return Boolean.TRUE.equals(ZestProperties.getLayoutIrrelevant(node)) || hidingModel.isHidden(node);
}
});
hidingModel.hiddenProperty().addListener(hidingModelObserver);
}
hidingModel.hiddenProperty().addListener(hidingModelObserver);

// initially apply layout if no viewport state is saved for this graph,
// or we are nested inside a node, or the saved viewport is outdated
Expand All @@ -262,7 +262,9 @@ protected void doDeactivate() {
getHost().getChildrenUnmodifiable().removeListener(childrenObserver);

final HidingModel hidingModel = getHost().getRoot().getViewer().getAdapter(HidingModel.class);
hidingModel.hiddenProperty().removeListener(hidingModelObserver);
if (hidingModel != null) {
hidingModel.hiddenProperty().removeListener(hidingModelObserver);
}

LayoutContext layoutContext = getLayoutContext();
layoutContext.unschedulePreLayoutPass(preLayout);
Expand Down

0 comments on commit 0a7da34

Please sign in to comment.