Skip to content

Commit

Permalink
Clean-up of GEF Flow example
Browse files Browse the repository at this point in the history
  • Loading branch information
azoitl committed Apr 1, 2024
1 parent 121f906 commit 888f76b
Show file tree
Hide file tree
Showing 24 changed files with 172 additions and 182 deletions.
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.15.300.qualifier
Bundle-Version: 3.16.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
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2023 IBM Corporation and others.
* Copyright (c) 2003, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -111,4 +111,7 @@ public static PaletteRoot createPalette() {
return flowPalette;
}

private FlowEditorPaletteFactory() {
throw new UnsupportedOperationException("Utility class shell not be instantiated!"); //$NON-NLS-1$
}
}
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, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -22,15 +22,18 @@
*/
public class FlowImages {

public static final Image GEAR;
public static final Image GEAR = loadImage();

static {
InputStream stream = FlowPlugin.class.getResourceAsStream("images/gear.gif");
GEAR = new Image(null, stream);
try {
stream.close();
private static Image loadImage() {
try (InputStream stream = FlowPlugin.class.getResourceAsStream("images/gear.gif")) { //$NON-NLS-1$
return new Image(null, stream);
} catch (IOException ioe) {
ioe.printStackTrace();
}
return null;
}

private FlowImages() {
throw new UnsupportedOperationException("Utility class shell not be instantiated!"); //$NON-NLS-1$
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -19,13 +19,4 @@
*/
public class FlowPlugin extends AbstractUIPlugin {

/**
* Creates a new FlowPlugin with the given descriptor
*
* @param descriptor the descriptor
*/
public FlowPlugin() {
super();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -53,6 +53,7 @@ public void contributeToToolBar(IToolBarManager toolBarManager) {
*/
@Override
protected void declareGlobalActionKeys() {
// we don't want global action keys
}

}
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, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -25,10 +25,6 @@ public class ParallelActivityFigure extends SubgraphFigure {

boolean selected;

/**
* @param header
* @param footer
*/
public ParallelActivityFigure() {
super(new Label(""), new Label("")); //$NON-NLS-1$ //$NON-NLS-2$
setBorder(new MarginBorder(3, 5, 3, 0));
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, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -15,27 +15,15 @@
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;

/**
* @author hudsonr
*/
public class SequentialActivityFigure extends SubgraphFigure {

static final MarginBorder MARGIN_BORDER = new MarginBorder(0, 8, 0, 0);
private static final MarginBorder MARGIN_BORDER = new MarginBorder(0, 8, 0, 0);

static final PointList ARROW = new PointList(3);
{
ARROW.addPoint(0, 0);
ARROW.addPoint(10, 0);
ARROW.addPoint(5, 5);
}

/**
* @param header
* @param footer
*/
public SequentialActivityFigure() {
super(new StartTag(""), new EndTag("")); //$NON-NLS-1$ //$NON-NLS-2$
setBorder(MARGIN_BORDER);
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, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -31,10 +31,12 @@ public class SubgraphFigure extends Figure {

public SubgraphFigure(IFigure header, IFigure footer) {
contents = new Figure();
this.header = header;
this.footer = footer;
contents.setLayoutManager(new DummyLayout());
add(contents);
add(this.header = header);
add(this.footer = footer);
add(this.header);
add(this.footer);
}

public IFigure getContents() {
Expand Down Expand Up @@ -76,7 +78,7 @@ public void setBounds(Rectangle rect) {
header.setLocation(rect.getLocation());
}

public void setSelected(boolean value) {
public void setSelected(boolean selected) {
// in the default case we don't need to do anything
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -23,11 +23,11 @@

public abstract class FlowElement implements IPropertySource, Cloneable, Serializable {

public static final String CHILDREN = "Children", //$NON-NLS-1$
INPUTS = "inputs", //$NON-NLS-1$
OUTPUTS = "outputs"; //$NON-NLS-1$
public static final String CHILDREN = "Children"; //$NON-NLS-1$
public static final String INPUTS = "inputs"; //$NON-NLS-1$
public static final String OUTPUTS = "outputs"; //$NON-NLS-1$

transient protected PropertyChangeSupport listeners = new PropertyChangeSupport(this);
protected transient PropertyChangeSupport listeners = new PropertyChangeSupport(this);
static final long serialVersionUID = 1;

public void addPropertyChangeListener(PropertyChangeListener l) {
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, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -18,7 +18,8 @@
public class Transition extends FlowElement {

private static final long serialVersionUID = 4486688831285730788L;
public Activity source, target;
public Activity source;
public Activity target;

public Transition(Activity source, Activity target) {
this.source = source;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2023 IBM Corporation and others.
* Copyright (c) 2003, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -47,7 +47,7 @@ public StructuredActivity getParent() {
/**
* Sets the child to the passed Activity
*
* @param subpart the child
* @param newChild the child
*/
public void setChild(Activity newChild) {
child = newChild;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -24,7 +24,8 @@
public class RenameActivityCommand extends Command {

private Activity source;
private String name, oldName;
private String name;
private String oldName;

/**
* @see org.eclipse.gef.commands.Command#execute()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2023 IBM Corporation and others.
* Copyright (c) 2003, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -22,6 +22,7 @@
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.commands.CommandStackEventListener;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.gef.editpolicies.RootComponentEditPolicy;

import org.eclipse.gef.examples.flow.policies.ActivityContainerEditPolicy;
Expand All @@ -45,7 +46,8 @@ public class ActivityDiagramPart extends StructuredActivityPart {
};

@Override
protected void applyOwnResults(CompoundDirectedGraph graph, Map map) {
protected void applyOwnResults(CompoundDirectedGraph graph, Map<AbstractGraphicalEditPart, Object> map) {
// we don't want to do anything here.
}

/**
Expand Down Expand Up @@ -75,7 +77,8 @@ protected IFigure createFigure() {
Figure f = new Figure() {
@Override
public void setBounds(Rectangle rect) {
int x = bounds.x, y = bounds.y;
int x = bounds.x;
int y = bounds.y;

boolean resize = (rect.width != bounds.width) || (rect.height != bounds.height);
boolean translate = (rect.x != x) || (rect.y != y);
Expand Down Expand Up @@ -122,6 +125,7 @@ public boolean isSelectable() {
*/
@Override
protected void refreshVisuals() {
// we don't want to do anything here.
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2023 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -21,6 +21,8 @@
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Text;

import org.eclipse.jface.viewers.TextCellEditor;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.geometry.Dimension;
Expand All @@ -43,13 +45,11 @@ public class ActivityDirectEditManager extends DirectEditManager {
/**
* Creates a new ActivityDirectEditManager with the given attributes.
*
* @param source the source EditPart
* @param editorType type of editor
* @param locator the CellEditorLocator
* @param source the source EditPart
* @param locator the CellEditorLocator
*/
public ActivityDirectEditManager(GraphicalEditPart source, Class editorType, CellEditorLocator locator,
Label label) {
super(source, editorType, locator);
public ActivityDirectEditManager(GraphicalEditPart source, CellEditorLocator locator, Label label) {
super(source, TextCellEditor.class, locator);
activityLabel = label;
}

Expand All @@ -73,22 +73,7 @@ protected void bringDown() {
@Override
protected void initCellEditor() {
Text text = (Text) getCellEditor().getControl();
verifyListener = new VerifyListener() {
@Override
public void verifyText(VerifyEvent event) {
Text text = (Text) getCellEditor().getControl();
String oldText = text.getText();
String leftText = oldText.substring(0, event.start);
String rightText = oldText.substring(event.end, oldText.length());
GC gc = new GC(text);
Point size = gc.textExtent(leftText + event.text + rightText);
gc.dispose();
if (size.x != 0) {
size = text.computeSize(size.x, SWT.DEFAULT);
}
getCellEditor().getControl().setSize(size.x, size.y);
}
};
verifyListener = this::verifyText;
text.addVerifyListener(verifyListener);

String initialLabelText = activityLabel.getText();
Expand All @@ -115,4 +100,18 @@ protected void unhookListeners() {
verifyListener = null;
}

private void verifyText(VerifyEvent event) {
Text text = (Text) getCellEditor().getControl();
String oldText = text.getText();
String leftText = oldText.substring(0, event.start);
String rightText = oldText.substring(event.end, oldText.length());
GC gc = new GC(text);
Point size = gc.textExtent(leftText + event.text + rightText);
gc.dispose();
if (size.x != 0) {
size = text.computeSize(size.x, SWT.DEFAULT);
}
getCellEditor().getControl().setSize(size.x, size.y);
}

}
Loading

0 comments on commit 888f76b

Please sign in to comment.