Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean editpart children #212

Merged
merged 10 commits into from
Jul 3, 2023
2 changes: 1 addition & 1 deletion org.eclipse.gef.examples.flow/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.gef.examples.flow; singleton:=true
Bundle-Version: 3.13.100.qualifier
Bundle-Version: 3.14.0.qualifier
Bundle-Activator: org.eclipse.gef.examples.flow.FlowPlugin
Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,24 @@
*/
public class ActivityDiagramPart extends StructuredActivityPart {

CommandStackEventListener stackListener = new CommandStackEventListener() {

public void stackChanged(org.eclipse.gef.commands.CommandStackEvent event) {
if ((event.getDetail() & CommandStack.POST_MASK) != 0) {
if (!GraphAnimation.captureLayout(getFigure()))
return;
while (GraphAnimation.step())
getFigure().getUpdateManager().performUpdate();
GraphAnimation.end();
}
};
CommandStackEventListener stackListener = event -> {
if ((event.getDetail() & CommandStack.POST_MASK) != 0) {
if (!GraphAnimation.captureLayout(getFigure()))
return;
while (GraphAnimation.step())
getFigure().getUpdateManager().performUpdate();
GraphAnimation.end();
}
};

@Override
protected void applyOwnResults(CompoundDirectedGraph graph, Map map) {
}

/**
* @see org.eclipse.gef.examples.flow.parts.ActivityPart#activate()
*/
@Override
public void activate() {
super.activate();
getViewer().getEditDomain().getCommandStack().addCommandStackEventListener(stackListener);
Expand All @@ -55,6 +54,7 @@ public void activate() {
/**
* @see org.eclipse.gef.examples.flow.parts.ActivityPart#createEditPolicies()
*/
@Override
protected void createEditPolicies() {
installEditPolicy(EditPolicy.NODE_ROLE, null);
installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, null);
Expand All @@ -64,8 +64,10 @@ protected void createEditPolicies() {
installEditPolicy(EditPolicy.CONTAINER_ROLE, new ActivityContainerEditPolicy());
}

@Override
protected IFigure createFigure() {
Figure f = new Figure() {
@Override
public void setBounds(Rectangle rect) {
int x = bounds.x, y = bounds.y;

Expand Down Expand Up @@ -94,6 +96,7 @@ public void setBounds(Rectangle rect) {
/**
* @see org.eclipse.gef.examples.flow.parts.ActivityPart#deactivate()
*/
@Override
public void deactivate() {
getViewer().getEditDomain().getCommandStack().removeCommandStackEventListener(stackListener);
super.deactivate();
Expand All @@ -102,13 +105,15 @@ public void deactivate() {
/**
* @see org.eclipse.gef.editparts.AbstractEditPart#isSelectable()
*/
@Override
public boolean isSelectable() {
return false;
}

/**
* @see org.eclipse.gef.examples.flow.parts.StructuredActivityPart#refreshVisuals()
*/
@Override
protected void refreshVisuals() {
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2010 IBM Corporation and others.
* Copyright (c) 2003, 2023 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -46,9 +46,10 @@ public abstract class ActivityPart extends AbstractGraphicalEditPart implements
/**
* @see org.eclipse.gef.EditPart#activate()
*/
@Override
public void activate() {
super.activate();
getActivity().addPropertyChangeListener(this);
getModel().addPropertyChangeListener(this);
}

protected void applyGraphResults(CompoundDirectedGraph graph, Map map) {
Expand All @@ -67,17 +68,15 @@ public void contributeEdgesToGraph(CompoundDirectedGraph graph, Map map) {
TransitionPart part = (TransitionPart) getSourceConnections().get(i);
part.contributeToGraph(graph, map);
}
for (int i = 0; i < getChildren().size(); i++) {
ActivityPart child = (ActivityPart) children.get(i);
child.contributeEdgesToGraph(graph, map);
}
getChildren().forEach(child -> child.contributeEdgesToGraph(graph, map));
}

public abstract void contributeNodesToGraph(CompoundDirectedGraph graph, Subgraph s, Map map);

/**
* @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
*/
@Override
protected void createEditPolicies() {
installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new ActivityNodeEditPolicy());
installEditPolicy(EditPolicy.CONTAINER_ROLE, new ActivitySourceEditPolicy());
Expand All @@ -88,60 +87,74 @@ protected void createEditPolicies() {
/**
* @see org.eclipse.gef.EditPart#deactivate()
*/
@Override
public void deactivate() {
super.deactivate();
getActivity().removePropertyChangeListener(this);
getModel().removePropertyChangeListener(this);
}

/**
* Returns the Activity model associated with this EditPart
*
* @return the Activity model
*/
protected Activity getActivity() {
return (Activity) getModel();
@Override
public Activity getModel() {
return (Activity) super.getModel();
}

@SuppressWarnings("unchecked") // children of an ActivityPart are ActivityParts
@Override
public List<? extends ActivityPart> getChildren() {
return (List<? extends ActivityPart>) super.getChildren();
}

/**
* @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#getModelSourceConnections()
*/
@Override
protected List getModelSourceConnections() {
return getActivity().getOutgoingTransitions();
return getModel().getOutgoingTransitions();
}

/**
* @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#getModelTargetConnections()
*/
@Override
protected List getModelTargetConnections() {
return getActivity().getIncomingTransitions();
return getModel().getIncomingTransitions();
}

abstract int getAnchorOffset();

/**
* @see NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef.ConnectionEditPart)
*/
@Override
public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart connection) {
return new BottomAnchor(getFigure(), getAnchorOffset());
}

/**
* @see org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef.Request)
*/
@Override
public ConnectionAnchor getSourceConnectionAnchor(Request request) {
return new BottomAnchor(getFigure(), getAnchorOffset());
}

/**
* @see NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.ConnectionEditPart)
*/
@Override
public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart connection) {
return new TopAnchor(getFigure(), getAnchorOffset());
}

/**
* @see org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.Request)
*/
@Override
public ConnectionAnchor getTargetConnectionAnchor(Request request) {
return new TopAnchor(getFigure(), getAnchorOffset());
}
Expand All @@ -152,6 +165,7 @@ protected void performDirectEdit() {
/**
* @see org.eclipse.gef.EditPart#performRequest(org.eclipse.gef.Request)
*/
@Override
public void performRequest(Request request) {
if (request.getType() == RequestConstants.REQ_DIRECT_EDIT)
performDirectEdit();
Expand All @@ -160,6 +174,7 @@ public void performRequest(Request request) {
/**
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
*/
@Override
public void propertyChange(PropertyChangeEvent evt) {
String prop = evt.getPropertyName();
if (FlowElement.CHILDREN.equals(prop))
Expand All @@ -178,6 +193,7 @@ else if (Activity.NAME.equals(prop))
/**
* @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#setFigure(org.eclipse.draw2d.IFigure)
*/
@Override
protected void setFigure(IFigure figure) {
figure.getBounds().setSize(0, 0);
super.setFigure(figure);
Expand All @@ -186,6 +202,7 @@ protected void setFigure(IFigure figure) {
/**
* @see org.eclipse.gef.editparts.AbstractEditPart#toString()
*/
@Override
public String toString() {
return getModel().toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
*/
public class ParallelActivityPart extends StructuredActivityPart {

@Override
protected IFigure createFigure() {
return new ParallelActivityFigure();
}

/**
* @see org.eclipse.gef.EditPart#setSelected(int)
*/
@Override
public void setSelected(int value) {
super.setSelected(value);
SubgraphFigure sf = (SubgraphFigure) getFigure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
*******************************************************************************/
package org.eclipse.gef.examples.flow.parts;

import java.util.List;
import java.util.Map;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.graph.CompoundDirectedGraph;
import org.eclipse.draw2d.graph.Edge;
import org.eclipse.draw2d.graph.Node;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.examples.flow.figures.SequentialActivityFigure;

/**
Expand All @@ -28,6 +26,7 @@ public class SequentialActivityPart extends StructuredActivityPart {
/**
* @see org.eclipse.gef.examples.flow.parts.StructuredActivityPart#createFigure()
*/
@Override
protected IFigure createFigure() {
return new SequentialActivityFigure();
}
Expand All @@ -36,26 +35,26 @@ protected IFigure createFigure() {
* @see ActivityPart#contributeEdgesToGraph(org.eclipse.graph.CompoundDirectedGraph,
* java.util.Map)
*/
@Override
public void contributeEdgesToGraph(CompoundDirectedGraph graph, Map map) {
super.contributeEdgesToGraph(graph, map);
Node node, prev = null;
EditPart a;
List members = getChildren();
for (int n = 0; n < members.size(); n++) {
a = (EditPart) members.get(n);
node = (Node) map.get(a);
Node prev = null;
for (ActivityPart a : getChildren()) {
Node node = (Node) map.get(a);
if (prev != null) {
Edge e = new Edge(prev, node);
e.weight = 50;
graph.edges.add(e);
}
prev = node;
}
;
}

/**
* @see org.eclipse.gef.examples.flow.parts.StructuredActivityPart#getAnchorOffset()
*/
@Override
int getAnchorOffset() {
return 15;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2010 IBM Corporation and others.
* Copyright (c) 2003, 2023 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -28,6 +28,7 @@
*/
public class SimpleActivityPart extends ActivityPart {

@Override
public void contributeNodesToGraph(CompoundDirectedGraph graph, Subgraph s, Map map) {
Node n = new Node(this, s);
n.outgoingOffset = getAnchorOffset();
Expand All @@ -42,20 +43,28 @@ public void contributeNodesToGraph(CompoundDirectedGraph graph, Subgraph s, Map
/**
* @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
*/
@Override
protected IFigure createFigure() {
Label l = new SimpleActivityLabel();
l.setLabelAlignment(PositionConstants.LEFT);
l.setIcon(FlowImages.GEAR);
return l;
}

@Override
int getAnchorOffset() {
return 9;
}

@Override
public Label getFigure() {
return (Label) super.getFigure();
}

@Override
protected void performDirectEdit() {
if (manager == null) {
Label l = (Label) getFigure();
Label l = getFigure();
manager = new ActivityDirectEditManager(this, TextCellEditor.class, new ActivityCellEditorLocator(l), l);
}
manager.show();
Expand All @@ -64,8 +73,9 @@ protected void performDirectEdit() {
/**
* @see org.eclipse.gef.editparts.AbstractEditPart#refreshVisuals()
*/
@Override
protected void refreshVisuals() {
((Label) getFigure()).setText(getActivity().getName());
getFigure().setText(getModel().getName());
}

}
Loading