Skip to content

Commit ad9e3dc

Browse files
committed
Change constructor of OverviewOutlinePage
- It only needs the ScalableFreeformRootEditPart which AbstractDiagramEditor can supply and check it's not null - Also add some null checks
1 parent c0a8bad commit ad9e3dc

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

com.archimatetool.editor/src/com/archimatetool/editor/diagram/AbstractDiagramEditor.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -1004,10 +1004,11 @@ public <T> T getAdapter(Class<T> adapter) {
10041004
}
10051005

10061006
/*
1007-
* Return the singleton Outline Page
1007+
* Return the Outline Page
10081008
*/
1009-
if(adapter == IContentOutlinePage.class && getGraphicalViewer() != null) {
1010-
return adapter.cast(new OverviewOutlinePage(this));
1009+
if(adapter == IContentOutlinePage.class && getGraphicalViewer() != null
1010+
&& getGraphicalViewer().getRootEditPart() instanceof ScalableFreeformRootEditPart editPart) {
1011+
return adapter.cast(new OverviewOutlinePage(editPart));
10111012
}
10121013

10131014
/*
@@ -1034,7 +1035,7 @@ public <T> T getAdapter(Class<T> adapter) {
10341035

10351036
// Find/Replace Provider
10361037
if(adapter == IFindReplaceProvider.class) {
1037-
if(fFindReplaceProvider == null) {
1038+
if(fFindReplaceProvider == null && getGraphicalViewer() != null) {
10381039
fFindReplaceProvider = new DiagramEditorFindReplaceProvider(getGraphicalViewer());
10391040
}
10401041
return adapter.cast(fFindReplaceProvider);
@@ -1087,5 +1088,6 @@ public void dispose() {
10871088
fDiagramModel = null;
10881089

10891090
fContextActivation = null;
1091+
fFindReplaceProvider = null;
10901092
}
10911093
}

com.archimatetool.editor/src/com/archimatetool/editor/diagram/OverviewOutlinePage.java

+20-25
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.eclipse.draw2d.MarginBorder;
1010
import org.eclipse.draw2d.Viewport;
1111
import org.eclipse.draw2d.parts.ScrollableThumbnail;
12-
import org.eclipse.gef.EditPart;
1312
import org.eclipse.gef.LayerConstants;
1413
import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
1514
import org.eclipse.help.HelpSystem;
@@ -36,52 +35,48 @@
3635
*/
3736
public class OverviewOutlinePage extends Page implements IContentOutlinePage, IContextProvider {
3837

39-
private Canvas fCanvas;
40-
private ScrollableThumbnail fThumbnail;
41-
private ScalableFreeformRootEditPart fEditPart;
38+
private ScalableFreeformRootEditPart editPart;
39+
private Canvas canvas;
40+
private ScrollableThumbnail thumbnail;
4241

4342
public static String HELP_ID = "com.archimatetool.help.outlineViewHelp"; //$NON-NLS-1$
4443

4544
/**
46-
* Creates a new OverviewOutlinePage instance.
47-
* @param abstractDiagramEditor
45+
* Creates a new OverviewOutlinePage instance for editPart
4846
*/
49-
public OverviewOutlinePage(IDiagramModelEditor editor) {
50-
fEditPart = (ScalableFreeformRootEditPart)editor.getAdapter(EditPart.class);
47+
public OverviewOutlinePage(ScalableFreeformRootEditPart editPart) {
48+
this.editPart = editPart;
5149
}
5250

5351
@Override
5452
public void createControl(Composite parent) {
55-
if(fEditPart == null) {
56-
return;
57-
}
58-
59-
// create canvas and lws
60-
fCanvas = new Canvas(parent, SWT.NONE);
61-
LightweightSystem lws = new LightweightSystem(fCanvas);
53+
// Create Canvas and LWS
54+
canvas = new Canvas(parent, SWT.NONE);
55+
LightweightSystem lws = new LightweightSystem(canvas);
6256

63-
fThumbnail = new ScrollableThumbnail((Viewport)fEditPart.getFigure());
64-
fThumbnail.setUseScaledGraphics(false);
65-
fThumbnail.setSource(fEditPart.getLayer(LayerConstants.PRINTABLE_LAYERS));
66-
fThumbnail.setBorder(new MarginBorder(3));
67-
lws.setContents(fThumbnail);
57+
// Thumbnail is contents of LWS
58+
thumbnail = new ScrollableThumbnail((Viewport)editPart.getFigure());
59+
thumbnail.setUseScaledGraphics(false);
60+
thumbnail.setSource(editPart.getLayer(LayerConstants.PRINTABLE_LAYERS));
61+
thumbnail.setBorder(new MarginBorder(3));
62+
lws.setContents(thumbnail);
6863

6964
// Help
70-
PlatformUI.getWorkbench().getHelpSystem().setHelp(fCanvas, HELP_ID);
65+
PlatformUI.getWorkbench().getHelpSystem().setHelp(canvas, HELP_ID);
7166
}
7267

7368
@Override
7469
public void dispose() {
75-
if(fThumbnail != null) {
76-
fThumbnail.deactivate();
77-
fThumbnail = null;
70+
if(thumbnail != null) {
71+
thumbnail.deactivate();
72+
thumbnail = null;
7873
}
7974
super.dispose();
8075
}
8176

8277
@Override
8378
public Control getControl() {
84-
return fCanvas;
79+
return canvas;
8580
}
8681

8782
@Override

0 commit comments

Comments
 (0)