]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/e4/DiagramViewer.java
Use Consumer interface instead of deprecated Callback interface
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / diagramEditor / e4 / DiagramViewer.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2013 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *     Semantum Oy - issue #4384
12  *******************************************************************************/
13 package org.simantics.modeling.ui.diagramEditor.e4;
14
15 import java.awt.Color;
16 import java.awt.dnd.DnDConstants;
17 import java.util.Collections;
18 import java.util.Set;
19 import java.util.concurrent.TimeUnit;
20 import java.util.function.Supplier;
21
22 import org.eclipse.core.runtime.Assert;
23 import org.eclipse.core.runtime.IAdaptable;
24 import org.eclipse.core.runtime.IProgressMonitor;
25 import org.eclipse.core.runtime.SubMonitor;
26 import org.eclipse.core.runtime.jobs.Job;
27 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
28 import org.eclipse.e4.ui.services.EContextService;
29 import org.eclipse.jface.action.IStatusLineManager;
30 import org.eclipse.jface.resource.JFaceResources;
31 import org.eclipse.jface.resource.LocalResourceManager;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Display;
34 import org.eclipse.swt.widgets.Shell;
35 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
36 import org.simantics.Simantics;
37 import org.simantics.browsing.ui.model.browsecontexts.BrowseContext;
38 import org.simantics.db.ReadGraph;
39 import org.simantics.db.Resource;
40 import org.simantics.db.Session;
41 import org.simantics.db.WriteGraph;
42 import org.simantics.db.common.primitiverequest.PossibleAdapter;
43 import org.simantics.db.common.procedure.adapter.ListenerDelegate;
44 import org.simantics.db.common.procedure.adapter.ListenerSupport;
45 import org.simantics.db.common.request.ParametrizedRead;
46 import org.simantics.db.common.request.WriteRequest;
47 import org.simantics.db.common.utils.CommonDBUtils;
48 import org.simantics.db.common.utils.TagUtil;
49 import org.simantics.db.exception.DatabaseException;
50 import org.simantics.db.layer0.request.combinations.Combinators;
51 import org.simantics.db.management.ISessionContext;
52 import org.simantics.db.management.ISessionContextProvider;
53 import org.simantics.db.request.Read;
54 import org.simantics.diagram.DiagramTypeUtils;
55 import org.simantics.diagram.adapter.FlagClassFactory;
56 import org.simantics.diagram.adapter.GraphToDiagramSynchronizer;
57 import org.simantics.diagram.adapter.IDiagramLoader;
58 import org.simantics.diagram.connection.ModelledConnectionAdvisor;
59 import org.simantics.diagram.handler.ConnectionCommandHandler;
60 import org.simantics.diagram.handler.CopyPasteStrategy;
61 import org.simantics.diagram.handler.DefaultCopyPasteStrategy;
62 import org.simantics.diagram.handler.DeleteHandler;
63 import org.simantics.diagram.handler.ExpandSelectionHandler;
64 import org.simantics.diagram.handler.SimpleElementTransformHandler;
65 import org.simantics.diagram.handler.e4.CopyPasteHandler;
66 import org.simantics.diagram.layer.ILayersViewPage;
67 import org.simantics.diagram.participant.PointerInteractor2;
68 import org.simantics.diagram.participant.SGFocusParticipant;
69 import org.simantics.diagram.participant.e4.ContextUtil;
70 import org.simantics.diagram.query.DiagramRequests;
71 import org.simantics.diagram.runtime.RuntimeDiagramManager;
72 import org.simantics.diagram.stubs.DiagramResource;
73 import org.simantics.diagram.symbolcontribution.SymbolProviderFactory;
74 import org.simantics.diagram.synchronization.CopyAdvisor;
75 import org.simantics.diagram.synchronization.IModifiableSynchronizationContext;
76 import org.simantics.diagram.synchronization.SynchronizationHints;
77 import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;
78 import org.simantics.diagram.ui.DiagramModelHints;
79 import org.simantics.diagram.ui.SWTPopupMenuParticipant;
80 import org.simantics.diagram.ui.WorkbenchSelectionProvider;
81 import org.simantics.g2d.canvas.Hints;
82 import org.simantics.g2d.canvas.ICanvasContext;
83 import org.simantics.g2d.canvas.ICanvasParticipant;
84 import org.simantics.g2d.canvas.impl.CanvasContext;
85 import org.simantics.g2d.chassis.AWTChassis;
86 import org.simantics.g2d.chassis.ICanvasChassis;
87 import org.simantics.g2d.chassis.IChassisListener;
88 import org.simantics.g2d.chassis.SWTChassis;
89 import org.simantics.g2d.connection.IConnectionAdvisor;
90 import org.simantics.g2d.diagram.DiagramClass;
91 import org.simantics.g2d.diagram.DiagramHints;
92 import org.simantics.g2d.diagram.IDiagram;
93 import org.simantics.g2d.diagram.handler.PickRequest.PickFilter;
94 import org.simantics.g2d.diagram.impl.Diagram;
95 import org.simantics.g2d.diagram.participant.DelayedBatchElementPainter;
96 import org.simantics.g2d.diagram.participant.DiagramParticipant;
97 import org.simantics.g2d.diagram.participant.ElementInteractor;
98 import org.simantics.g2d.diagram.participant.ElementPainter;
99 import org.simantics.g2d.diagram.participant.Selection;
100 import org.simantics.g2d.diagram.participant.TerminalPainter;
101 import org.simantics.g2d.diagram.participant.ZOrderHandler;
102 import org.simantics.g2d.diagram.participant.pointertool.PointerInteractor;
103 import org.simantics.g2d.element.ElementClassProviders;
104 import org.simantics.g2d.element.ElementClasses;
105 import org.simantics.g2d.element.IElement;
106 import org.simantics.g2d.element.IElementClassProvider;
107 import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;
108 import org.simantics.g2d.elementclass.connection.ConnectionClass;
109 import org.simantics.g2d.page.DiagramDesc;
110 import org.simantics.g2d.participant.BackgroundPainter;
111 import org.simantics.g2d.participant.CanvasBoundsParticipant;
112 import org.simantics.g2d.participant.CanvasGrab;
113 import org.simantics.g2d.participant.GridPainter;
114 import org.simantics.g2d.participant.KeyUtil;
115 import org.simantics.g2d.participant.MouseUtil;
116 import org.simantics.g2d.participant.Notifications;
117 import org.simantics.g2d.participant.PageBorderParticipant;
118 import org.simantics.g2d.participant.PanZoomRotateHandler;
119 import org.simantics.g2d.participant.PointerPainter;
120 import org.simantics.g2d.participant.RenderingQualityInteractor;
121 import org.simantics.g2d.participant.RulerPainter;
122 import org.simantics.g2d.participant.SymbolUtil;
123 import org.simantics.g2d.participant.TimeParticipant;
124 import org.simantics.g2d.participant.TransformUtil;
125 import org.simantics.g2d.participant.WorkbenchStatusLine;
126 import org.simantics.g2d.participant.ZoomToAreaHandler;
127 import org.simantics.g2d.tooltip.TerminalTooltipParticipant;
128 import org.simantics.g2d.utils.CanvasUtils;
129 import org.simantics.layer0.utils.triggers.IActivation;
130 import org.simantics.layer0.utils.triggers.IActivationManager;
131 import org.simantics.modeling.ModelingResources;
132 import org.simantics.modeling.mapping.ComponentCopyAdvisor;
133 import org.simantics.modeling.mapping.ElementCopyAdvisor;
134 import org.simantics.modeling.mapping.MappedElementCopyAdvisor;
135 import org.simantics.modeling.mapping.ModelingSynchronizationHints;
136 import org.simantics.modeling.ui.diagramEditor.DiagramEditorStates;
137 import org.simantics.modeling.ui.diagramEditor.DiagramLayersPage;
138 import org.simantics.modeling.ui.diagramEditor.DiagramOutlinePage;
139 import org.simantics.modeling.ui.diagramEditor.EditorState;
140 import org.simantics.modeling.ui.diagramEditor.PopulateElementMonitorDropParticipant;
141 import org.simantics.modeling.ui.diagramEditor.handlers.e4.LinkBrowsingHandler;
142 import org.simantics.modeling.ui.diagramEditor.handlers.e4.StructuralBrowsingHandler;
143 import org.simantics.modeling.ui.preferences.DiagramPreferenceUtil;
144 import org.simantics.modeling.ui.preferences.DiagramPreferences;
145 import org.simantics.project.ontology.ProjectResource;
146 import org.simantics.scenegraph.INode;
147 import org.simantics.scenegraph.g2d.snap.GridSnapAdvisor;
148 import org.simantics.scenegraph.utils.NodeUtil;
149 import org.simantics.structural.stubs.StructuralResource2;
150 import org.simantics.structural2.modelingRules.IModelingRules;
151 import org.simantics.ui.SimanticsUI;
152 import org.simantics.ui.jobs.SessionGarbageCollectorJob;
153 import org.simantics.ui.workbench.IPropertyPage;
154 import org.simantics.ui.workbench.IResourceEditorInput;
155 import org.simantics.ui.workbench.IResourceEditorInput2;
156 import org.simantics.ui.workbench.TitleRequest;
157 import org.simantics.ui.workbench.TitleUpdater;
158 import org.simantics.ui.workbench.ToolTipRequest;
159 import org.simantics.ui.workbench.editor.input.InputValidationCombinators;
160 import org.simantics.utils.DataContainer;
161 import org.simantics.utils.datastructures.hints.HintContext;
162 import org.simantics.utils.datastructures.hints.HintListenerAdapter;
163 import org.simantics.utils.datastructures.hints.IHintContext;
164 import org.simantics.utils.datastructures.hints.IHintContext.Key;
165 import org.simantics.utils.datastructures.hints.IHintListener;
166 import org.simantics.utils.datastructures.hints.IHintObservable;
167 import org.simantics.utils.threads.AWTThread;
168 import org.simantics.utils.threads.IThreadWorkQueue;
169 import org.simantics.utils.threads.SWTThread;
170 import org.simantics.utils.threads.ThreadUtils;
171 import org.simantics.utils.ui.ErrorLogger;
172 import org.simantics.utils.ui.ExceptionUtils;
173 import org.simantics.utils.ui.workbench.WorkbenchUtils;
174
175 import com.kitfox.svg.SVGCache;
176
177 /**
178  * @author Toni Kalajainen
179  * @author Tuukka Lehtonen
180  */
181 public class DiagramViewer 
182   //extends EditorPart implements IResourceEditorPart2, 
183     implements ListenerSupport, IAdaptable {
184
185     public interface DiagramViewerHost {
186         void doSetPartName(String name);
187         void doSetTitleToolTip(String name);
188     }
189
190     public static final String                     DIAGRAMMING_CONTEXT      = "org.simantics.modeling.ui.diagramming";
191     private static final String                     PREFERENCE_VIRTUAL_GRAPH = "preferences";
192
193     private static final boolean                    PROFILE                  = false;
194
195     ParametrizedRead<IResourceEditorInput, Boolean> INPUT_VALIDATOR =
196         Combinators.compose(
197                 InputValidationCombinators.or(
198                         // Normal configuration diagrams of a model
199                         Combinators.compose(
200                                 InputValidationCombinators.hasURI(),
201                                 InputValidationCombinators.partialFunction(ModelingResources.URIs.DiagramToComposite)
202                         ),
203                         // Configuration diagrams of a component type
204                         Combinators.compose(
205                                 InputValidationCombinators.hasURI(),
206                                 Combinators.compose(
207                                         InputValidationCombinators.partialFunction(StructuralResource2.URIs.Defines),
208                                         InputValidationCombinators.partialFunction(ModelingResources.URIs.DiagramToComposite)
209                                 )
210                         )
211                 ),
212                 InputValidationCombinators.extractInputResource()
213         );
214
215     protected EditorState                editorState;
216
217     protected boolean                    disposed           = false;
218     protected IThreadWorkQueue           swt;
219     protected IStatusLineManager         statusLineManager;
220     protected Display                    display;
221     protected LocalResourceManager       resourceManager;
222     protected SWTChassis                 c;
223     protected IDiagram                   sourceDiagram;
224     protected DataContainer<IDiagram>    sourceDiagramContainer = new DataContainer<IDiagram>();
225     protected CanvasContext              canvasContext;
226     protected ISessionContextProvider    sessionContextProvider;
227     protected ISessionContext            sessionContext;
228     protected Resource                   diagramResource;
229     protected GraphToDiagramSynchronizer synchronizer;
230     protected IActivation                activation;
231     protected ContextUtil                contextUtil;
232     protected SWTPopupMenuParticipant    popupMenuParticipant;
233     
234     protected DiagramPreferences         diagramPreferences;
235     protected DiagramDesc                diagramDesc;
236     protected GridSnapAdvisor            snapAdvisor;
237
238     private RuntimeDiagramManager        runtimeDiagramManager;
239
240     protected WorkbenchSelectionProvider selectionProvider;
241
242     public Resource getRuntime() {
243         RuntimeDiagramManager rtdm = runtimeDiagramManager;
244         return (rtdm == null) ? null : rtdm.getRuntimeDiagram();
245     }
246
247     public ParametrizedRead<IResourceEditorInput, Boolean> getInputValidator() {
248         return INPUT_VALIDATOR;
249     }
250
251     protected void addDropParticipants(ICanvasContext ctx) {
252         ctx.getDefaultHintContext().setHint(Hints.KEY_ALLOWED_DRAG_ACTIONS, DnDConstants.ACTION_COPY);
253
254         ctx.add(new PopulateElementDropParticipant(synchronizer, getPart()));
255         ctx.add(new PopulateElementMonitorDropParticipant(synchronizer, 0.5, 0.5));
256     }
257
258     protected CopyPasteStrategy getCopyPasteStrategy() {
259                 try {
260                         CopyPasteStrategy cpStrategy = Simantics.getSession().syncRequest(new PossibleAdapter<CopyPasteStrategy>(getResourceEditorInput().getResource(), CopyPasteStrategy.class));
261                         if(cpStrategy != null) return cpStrategy;
262                 } catch (DatabaseException e) {
263                 }
264                 return new DefaultCopyPasteStrategy();
265     }
266
267     protected CopyAdvisor getCopyAdvisor() {
268                 try {
269                         CopyAdvisor advisor = Simantics.getSession().syncRequest(new PossibleAdapter<CopyAdvisor>(getResourceEditorInput().getResource(), CopyAdvisor.class));
270                         if(advisor != null) return advisor;
271                 } catch (DatabaseException e) {
272                 }
273                 return new MappedElementCopyAdvisor(new ElementCopyAdvisor(), new ComponentCopyAdvisor());
274     }
275     
276     /**
277      * @param ctx
278      * TODO: change argument from CanvasContext to ICanvasContext
279      */
280     protected void addKeyBindingParticipants(CanvasContext ctx) {
281         //ctx.add( new KeyToCommand( CommandKeyBinding.DEFAULT_BINDINGS ) );
282         ctx.add(new DeleteHandler(statusLineManager));
283         ctx.add(new CopyPasteHandler(getCopyPasteStrategy(), statusLineManager).setWorkbenchSite(getPart()));
284         ctx.add(new ConnectionCommandHandler());
285     }
286
287     protected void addPopupmenu(ICanvasContext ctx) {
288         ctx.add(popupMenuParticipant);
289     }
290
291     protected void addWorkbenchSelectionProvider(ICanvasContext ctx) {
292         ctx.add(selectionProvider);
293     }
294
295     protected void addViewManipulationParticipants(CanvasContext ctx) {
296         ctx.add(new PanZoomRotateHandler());
297         //ctx.add(new MousePanZoomInteractor());
298         //ctx.add(new MultitouchPanZoomRotateInteractor());
299         // ctx.add( new OrientationRestorer() );
300         ctx.add(new ZoomToAreaHandler());
301     }
302
303     protected void addDiagramParticipants(ICanvasContext ctx) {
304         ctx.add(new ZOrderHandler());
305         ctx.add(getPointerInteractor());
306         ctx.add(new ElementInteractor());
307         ctx.add(new Selection());
308         ctx.add(new DiagramParticipant());
309         ctx.add(new ElementPainter());
310         //ctx.add(new ElementHeartbeater());
311         //ctx.add(new ZoomTransitionParticipant(TransitionFunction.SIGMOID));
312         //ctx.add(new TooltipParticipant());
313         ctx.add(new TerminalTooltipParticipant());
314     }
315
316     protected void addPainterParticipants(ICanvasContext ctx) {
317         ctx.add(new RenderingQualityInteractor());
318         ctx.add(new TerminalPainter(true, true, false, true));
319         ctx.add(new DelayedBatchElementPainter(PickFilter.FILTER_MONITORS, 500, TimeUnit.MILLISECONDS));
320     }
321
322     protected void addStructureParticipants(ICanvasContext ctx) {
323         addWorkbenchSelectionProvider(ctx);
324         // Add visual browsing capabilities for structural models
325         ctx.add(new StructuralBrowsingHandler(sessionContext, getPart(), getResourceEditorInput()));
326         ctx.add(new LinkBrowsingHandler(this, sessionContext));
327     }
328
329     /**
330      * Override to add any diagram/canvas participants to the canvas context
331      * initialized for the editor.
332      * 
333      * @param ctx
334      */
335     protected void addOtherParticipants(CanvasContext ctx) {
336     }
337
338     public static Set<String> defaultPropertyBrowseContexts = Collections.singleton(ProjectResource.URIs.ProjectBrowseContext);
339
340     protected Set<String> getPropertyPageContexts() {
341         try {
342             return BrowseContext.getBrowseContextClosure(SimanticsUI.getSession(), defaultPropertyBrowseContexts);
343         } catch (DatabaseException e) {
344             ExceptionUtils.logAndShowError("Failed to load modeled browse contexts for property page, see exception for details.", e);
345             return defaultPropertyBrowseContexts;
346         }
347     }
348
349     protected IPropertyPage createPropertyPage(MPart part, Set<String> contexts) {
350 //        #TODO Finish this when we are going to use full E4 workbench
351 //        return new StandardPropertyPage(part, contexts);
352         return null;
353     }
354
355     protected String getPopupId() {
356         return "#ModelingDiagramPopup";
357     }
358
359     protected void getPreferences() {
360         this.diagramPreferences = DiagramPreferenceUtil.getPreferences();
361     }
362
363     protected void initSession() {
364         sessionContextProvider = SimanticsUI.getSessionContextProvider();
365         sessionContext = sessionContextProvider.getSessionContext();
366     }
367
368     protected void readNames() {
369         String name = getResourceEditorInput().getName();
370         host.doSetPartName(name);
371         host.doSetTitleToolTip(name);
372     }
373
374     class ChassisListener implements IChassisListener {
375         @Override
376         public void chassisClosed(ICanvasChassis sender) {
377             // Prevent deadlock while disposing which using syncExec would result in.
378             final ICanvasContext ctx = canvasContext;
379             ThreadUtils.asyncExec(ctx.getThreadAccess(), new Runnable() {
380                 @Override
381                 public void run() {
382                     if (ctx != null) {
383                         saveEditorState(ctx);
384                         ctx.getHintStack().removeKeyHintListener(GridPainter.KEY_GRID_ENABLED, canvasHintListener);
385                         ctx.getHintStack().removeKeyHintListener(RulerPainter.KEY_RULER_ENABLED, canvasHintListener);
386                         final AWTChassis awtChassis = c.getAWTComponent();
387                         if (awtChassis != null)
388                             awtChassis.setCanvasContext(null);
389                         ctx.dispose();
390                     }
391
392                     sourceDiagramContainer.set(null);
393                     sourceDiagramContainer = null;
394
395                     if (sourceDiagram != null)
396                         sourceDiagram.dispose();
397
398                     if(synchronizer != null) {
399                         synchronizer.dispose();
400                         // Let GC work.
401                         synchronizer = null;
402                     }
403
404                     if (runtimeDiagramManager != null) {
405                         runtimeDiagramManager.dispose();
406                         runtimeDiagramManager = null;
407                     }
408                 }
409             });
410             c.removeChassisListener(ChassisListener.this);
411         }
412     }
413
414     protected void createChassis(Composite parent) {
415         resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent);
416         c = new SWTChassis(parent, 0);
417
418         Object task = BEGIN("DV.precreateParticipants");
419         createCustomParticipants();
420         END(task);
421
422         c.populate(component -> {
423             if (!disposed) {
424                 c.addChassisListener(new ChassisListener());
425                 initializeCanvas();
426             }
427         });
428     }
429
430     protected void beforeSetCanvasContext(ICanvasContext canvasContext2) {
431     }
432
433     /**
434      * Invoke this only from the AWT thread.
435      * @param context
436      */
437     protected void setCanvasContext(ICanvasContext context) {
438         // Cannot directly invoke SWTChassis.setCanvasContext only because it
439         // needs to be invoked in the SWT thread and AWTChassis.setCanvasContext in the
440         // AWT thread, but directly invoking SWTChassis.setCanvasContext would call both
441         // in the SWT thread which would cause synchronous scheduling of AWT
442         // runnables which is always a potential source of deadlocks.
443         c.getAWTComponent().setCanvasContext(canvasContext);
444         swt.asyncExec(new Runnable() {
445             @Override
446             public void run() {
447                 if (!c.isDisposed())
448                     // For AWT, this is a no-operation.
449                     c.setCanvasContext(canvasContext);
450             }
451         });
452     }
453
454     public void createPartControl(Composite parent) {
455         //ProfileObserver.begin = System.nanoTime();
456         display = parent.getDisplay(); 
457         swt = SWTThread.getThreadAccess(display);
458         statusLineManager = WorkbenchUtils.getStatusLine(WorkbenchUtils.getActiveWorkbenchPart());
459
460         Object task = BEGIN("DV.initSession");
461         initSession();
462         END(task);
463
464         diagramResource = getResourceEditorInput().getResource();
465         readNames();
466         getPreferences();
467
468         // DiagramViewerSelectionProvider MUST be created and attached to the
469         // workbench site:
470         //   1. in SWT thread!
471         //   2. here before returning from createPartControl
472         selectionProvider = createSelectionProvider();
473
474         try {
475             this.runtimeDiagramManager = RuntimeDiagramManager.track(sessionContext.getSession(), diagramResource, getResourceEditorInput(), this);
476
477             // Create the canvas context here before finishing createPartControl
478             // to give DiagramViewerActionContributor a chance to work.
479             // The context can be created in SWT thread without scheduling
480             // to the context thread and having potential deadlocks.
481             IThreadWorkQueue thread = AWTThread.getThreadAccess();
482             this.canvasContext = new CanvasContext(thread);
483             this.canvasContext.setLocked(true);
484
485             task = BEGIN("DV.createChassis");
486             createChassis(parent);
487             END(task);
488         } catch (DatabaseException e) {
489             ErrorLogger.defaultLogError(e);
490         }
491     }
492
493     /**
494      * @return
495      */
496     protected WorkbenchSelectionProvider createSelectionProvider() {
497 //        #TODO Finish this when we are going to use full E4 workbench        
498 //        return new DiagramViewerSelectionProvider(swt, getPart(), sourceDiagramContainer);
499         return null;
500     }
501
502         /**
503      * A method invoked before chassis construction for creating such
504      * {@link ICanvasParticipant}s that need to be constructed in the SWT
505      * thread.
506      * 
507      * Use it for creating any such canvas participants during the viewer 
508      * construction and add them to the {@link ICanvasContext} later on from
509      * the AWT thread.
510      */
511     protected void createCustomParticipants() {
512 //        #TODO Finish this when we are going to use full E4 workbench
513 //        popupMenuParticipant = new SWTPopupMenuParticipant(getPart(), c, display, getPopupId());
514     }
515
516     /**
517      * Invoke this only from the AWT thread.
518      */
519     protected void initializeCanvas() {
520         Object canvasInit = BEGIN("DV.canvasInitialization");
521
522         Object task = BEGIN("DV.createViewerCanvas");
523         initializeCanvasContext(canvasContext);
524         END(task);
525
526         beforeSetCanvasContext(canvasContext);
527         //FullscreenUtils.addFullScreenHandler(canvasContext, s, canvasProvider);
528
529         // Without this all diagram participants will crash like there's no tomorrow.
530         // Just trying to keep the behavior a bit more sane in case of
531         // errors instead of flooding the console with exceptions.
532         canvasContext.getDefaultHintContext().setHint(DiagramHints.KEY_DIAGRAM, Diagram.spawnNew(DiagramClass.DEFAULT));
533
534         // Changes in ruler/grid activity shall be written as
535         // workspace-persistent diagram-specific preferences.
536         canvasContext.getHintStack().addKeyHintListener(GridPainter.KEY_GRID_ENABLED, canvasHintListener);
537         canvasContext.getHintStack().addKeyHintListener(RulerPainter.KEY_RULER_ENABLED, canvasHintListener);
538
539         task = BEGIN("DV.setCanvasContext");
540         setCanvasContext(canvasContext);
541         END(task);
542
543         // Finish loading in a worker thread because it may be a time consuming
544         // process to load a large diagram and we don't want unnecessary AWT
545         // thread contention.
546         Job loadJob = new DiagramViewerLoadJob(this);
547         loadJob.schedule();
548
549         END(canvasInit);
550     }
551
552     protected void activateUiContexts(ContextUtil util) {
553         util.activate(DIAGRAMMING_CONTEXT);
554     }
555
556     /**
557      * @param monitor the progress monitor to use for reporting progress to the
558      *        user. It is the caller's responsibility to call done() on the
559      *        given monitor. Accepts <code>null</code>, indicating that no
560      *        progress should be reported and that the operation cannot be
561      *        cancelled.
562      */
563     protected void performActivation(IProgressMonitor monitor) {
564         SubMonitor progress = SubMonitor.convert(monitor, "Activate Mapping", 100);
565         IActivationManager activationManager = sessionContext.getSession().peekService(IActivationManager.class);
566         if (activationManager != null) {
567             activation = activationManager.activate(diagramResource);
568         }
569         progress.worked(100);
570     }
571
572     protected void onCreated() {
573     }
574
575     /**
576      * @param diagram
577      */
578     protected void scheduleZoomToFit(IDiagram diagram) {
579         if (diagram == null)
580             throw new IllegalStateException("diagram is null");
581
582         CanvasUtils.scheduleZoomToFit(swt, () -> disposed, canvasContext, diagram);
583     }
584
585     /**
586      * Subclasses may override but should always invoke super.
587      * 
588      * @param diagram
589      * @param initialHints
590      * @throws DatabaseException
591      */
592     protected void fillInitialDiagramHints(Resource diagram, IHintContext initialHints) throws DatabaseException {
593         IModelingRules modelingRules = sessionContext.getSession().syncRequest(
594                 DiagramRequests.getModelingRules(diagram, null));
595         if (modelingRules != null) {
596             initialHints.setHint(DiagramModelHints.KEY_MODELING_RULES, modelingRules);
597             initialHints.setHint(DiagramHints.CONNECTION_ADVISOR,
598                     getConnectionAdvisor(modelingRules, sessionContext.getSession()));
599         }
600
601         initialHints.setHint(SynchronizationHints.COPY_ADVISOR, getCopyAdvisor());
602         initialHints.setHint(DiagramHints.KEY_USE_CONNECTION_FLAGS, Boolean.TRUE);
603         initialHints.setHint(DiagramHints.KEY_ALLOW_CONNECTION_BRANCHING, Boolean.TRUE);
604         initialHints.setHint(DiagramHints.KEY_ALLOW_ROUTE_POINTS, Boolean.TRUE);
605     }
606
607     /**
608      * @param monitor the progress monitor to use for reporting progress to the
609      *        user. It is the caller's responsibility to call done() on the
610      *        given monitor. Accepts <code>null</code>, indicating that no
611      *        progress should be reported and that the operation cannot be
612      *        cancelled.
613      * @param r
614      * @return
615      * @throws DatabaseException
616      */
617     protected IDiagram loadDiagram(IProgressMonitor monitor, final Resource r) throws DatabaseException {
618         // Pre-load modeling rules and possibly other hints too since they are
619         // needed already while loading the diagram contents.
620         IHintContext initialHints = new HintContext();
621         fillInitialDiagramHints(r, initialHints);
622         IDiagram d = loadDiagram(monitor, r, initialHints);
623         return d;
624     }
625
626     /**
627      * @param monitor the progress monitor to use for reporting progress to the
628      *        user. It is the caller's responsibility to call done() on the
629      *        given monitor. Accepts <code>null</code>, indicating that no
630      *        progress should be reported and that the operation cannot be
631      *        cancelled.
632      * @param diagram
633      * @param initialHints
634      * @return
635      * @throws DatabaseException
636      */
637     protected IDiagram loadDiagram(IProgressMonitor monitor, Resource diagram, IHintContext initialHints) throws DatabaseException {
638         RuntimeDiagramManager rtdm = runtimeDiagramManager;
639         Resource runtimeDiagram = rtdm != null ? rtdm.getRuntimeDiagram() : null;
640         IDiagramLoader loader = synchronizer;
641         if (rtdm == null || runtimeDiagram == null || loader == null)
642                 return null;
643         IDiagram d = sessionContext.getSession().syncRequest(
644                 DiagramRequests.loadDiagram(monitor, getResourceEditorInput().getModel(null), diagram,
645                         runtimeDiagram, null, loader, initialHints));
646         return d;
647     }
648
649     protected void beforeSetDiagram(IDiagram diagram) {
650     }
651
652     protected PointerInteractor getPointerInteractor() {
653         return new PointerInteractor2(true, true, true, false, true, false, synchronizer.getElementClassProvider());
654     }
655
656     protected IConnectionAdvisor getConnectionAdvisor(IModelingRules modelingRules, Session session) {
657         return new ModelledConnectionAdvisor(modelingRules, sessionContext.getSession());
658     }
659
660     protected GraphToDiagramSynchronizer createSynchronizer(final ICanvasContext ctx, final ISessionContext sessionContext) {
661         try {
662             return sessionContext.getSession().syncRequest(new Read<GraphToDiagramSynchronizer>() {
663                 @Override
664                 public GraphToDiagramSynchronizer perform(ReadGraph graph) throws DatabaseException {
665                     GraphToDiagramSynchronizer sync = new GraphToDiagramSynchronizer(graph, ctx, createElementClassProvider(graph));
666                     initializeSynchronizationContext(graph, sync);
667                     return sync;
668                 }
669             });
670         } catch (DatabaseException e) {
671             throw new UnsupportedOperationException("Failed to initialize data model synchronizer", e);
672         }
673     }
674
675     protected void initializeSynchronizationContext(ReadGraph graph, IModifiableSynchronizationContext context) {
676         context.set(ModelingSynchronizationHints.MODELING_RESOURCE, ModelingResources.getInstance(graph));
677     }
678
679     protected IElementClassProvider createElementClassProvider(ReadGraph graph) {
680         DiagramResource dr = DiagramResource.getInstance(graph);
681         return ElementClassProviders.mappedProvider(
682                 ElementClasses.CONNECTION, ConnectionClass.CLASS.newClassWith(new StaticObjectAdapter(dr.RouteGraphConnection)),
683                 ElementClasses.FLAG, FlagClassFactory.createFlagClass(dr.Flag, dr.Flag_Terminal)
684         );
685     }
686     
687     protected SimpleElementTransformHandler getTransformHandler() {
688         return new SimpleElementTransformHandler(true, true, true);
689     }
690
691     public void initializeCanvasContext(CanvasContext ctx) {
692         IHintContext h = ctx.getDefaultHintContext();
693
694         // The canvas context should not be painted until it is ready to avoid
695         // unnecessary visual glitches.
696         h.setHint(Hints.KEY_DISABLE_PAINTING, Boolean.TRUE);
697
698         Object task = BEGIN("createSynchronizer");
699         this.synchronizer = createSynchronizer(ctx, sessionContext);
700         END(task);
701
702         EContextService contextService = getPart().getContext().get(EContextService.class);
703         contextUtil = new ContextUtil(contextService, swt);
704
705         // Support & Util Participants
706         ctx.add(new TransformUtil());
707         ctx.add(new MouseUtil());
708         ctx.add(new KeyUtil());
709         ctx.add(contextUtil);
710         ctx.add(new WorkbenchStatusLine(statusLineManager));
711         ctx.add(new CanvasGrab());
712         ctx.add(new SymbolUtil());
713         ctx.add(new TimeParticipant());
714         ctx.add(new CanvasBoundsParticipant());
715         ctx.add(new Notifications());
716
717         ctx.add(new SGFocusParticipant(c, DIAGRAMMING_CONTEXT));
718
719         // Debug participant(s)
720         // ctx.add( new PointerPainter() );
721         // ctx.add( new HandPainter() );
722         h.setHint(PointerPainter.KEY_PAINT_POINTER, true);
723
724         // Pan & Zoom & Rotate
725         addViewManipulationParticipants(ctx);
726
727         ctx.add(getTransformHandler());
728         ctx.add(new ExpandSelectionHandler(statusLineManager));
729
730         // Key bindings
731         addKeyBindingParticipants(ctx);
732
733         // Grid & Ruler & Background
734         ctx.add(new GridPainter());
735         ctx.add(new RulerPainter());
736         ctx.add(new BackgroundPainter());
737
738         h.setHint(Hints.KEY_DISPLAY_PAGE, diagramPreferences.get(DiagramPreferences.P_DISPLAY_PAGE_SIZE));
739         h.setHint(Hints.KEY_DISPLAY_MARGINS, diagramPreferences.get(DiagramPreferences.P_DISPLAY_MARGINS));
740         ctx.add(new PageBorderParticipant());
741
742         // h.setHint(Hints.KEY_GRID_COLOR, new Color(0.9f, 0.9f, 0.9f));
743         // h.setHint(Hints.KEY_BACKGROUND_COLOR, Color.LIGHT_GRAY);
744         h.setHint(Hints.KEY_GRID_COLOR, new Color(0.9f, 0.9f, 0.9f));
745         h.setHint(Hints.KEY_BACKGROUND_COLOR, Color.WHITE);
746         h.setHint(RulerPainter.KEY_RULER_BACKGROUND_COLOR, new Color(0.9f, 0.9f, 0.9f, 0.75f));
747         h.setHint(RulerPainter.KEY_RULER_TEXT_COLOR, Color.BLACK);
748
749         ////// Diagram Participants //////
750         addDiagramParticipants(ctx);
751         addPainterParticipants(ctx);
752
753         /////// D'n'D ///////
754         addDropParticipants(ctx);
755
756         h.setHint(ElementPainter.KEY_SELECTION_FRAME_COLOR, Color.MAGENTA);
757         h.setHint(Hints.KEY_TOOL, Hints.POINTERTOOL);
758
759         h.setHint(PanZoomRotateHandler.KEY_ZOOM_IN_LIMIT, 100000.0);
760         h.setHint(PanZoomRotateHandler.KEY_ZOOM_OUT_LIMIT, 10.0);
761
762         Double snapResolution = diagramPreferences.get(DiagramPreferences.P_SNAP_GRID_SIZE);
763         this.snapAdvisor = new GridSnapAdvisor(snapResolution);
764         h.setHint(DiagramHints.SNAP_ADVISOR, this.snapAdvisor);
765         h.setHint(GridPainter.KEY_GRID_SIZE, snapResolution);
766         h.setHint(GridPainter.KEY_GRID_ENABLED, Boolean.FALSE);
767
768         // Workbench selection provider
769         addStructureParticipants(ctx);
770
771         // Pop-up menu
772         addPopupmenu(ctx);
773
774         // Load page frame description settings
775         loadPageSettings(ctx);
776
777         addOtherParticipants(ctx);
778
779         ctx.assertParticipantDependencies();
780         ctx.setLocked(false);
781     }
782
783     protected void loadPageSettings(ICanvasContext ctx) {
784         DiagramDesc diagramDesc = null;
785
786         // load diagram page configuration
787         if (diagramResource != null) {
788             try {
789                 diagramDesc = sessionContext.getSession().syncRequest(DiagramRequests.getDiagramDesc(diagramResource));
790             } catch (DatabaseException e) {
791                 ErrorLogger.defaultLogError(e);
792             }
793         }
794
795         if (diagramDesc == null) {
796             // Take page description from the preferences if nothing else is available.
797             final DiagramDesc desc = diagramDesc = diagramPreferences.getDiagramDesc();
798
799             // Write page configuration to graph
800             sessionContext.getSession().asyncRequest(new WriteRequest() {
801                 @Override
802                 public void perform(WriteGraph graph) throws DatabaseException {
803                         CommonDBUtils.selectClusterSet(graph, diagramResource);
804                     DiagramGraphUtil.setDiagramDesc(graph, diagramResource, desc);
805                 }
806             }, e -> {
807                 if (e != null)
808                     ErrorLogger.defaultLogError("Failed to write default diagram page description to database, see exception for details", e);
809             });
810         }
811
812         setDiagramDesc(ctx, diagramDesc);
813
814         // Create a listener to react to page setting changes.
815         sessionContext.getSession().asyncRequest(DiagramRequests.getDiagramDesc(diagramResource),
816                 new ListenerDelegate<DiagramDesc>(this) {
817             @Override
818             public void execute(final DiagramDesc result) {
819                 if (result != null && canvasContext != null) {
820                     ThreadUtils.asyncExec(canvasContext.getThreadAccess(), new Runnable() {
821                         @Override
822                         public void run() {
823                             if (!disposed)
824                                 setDiagramDesc(canvasContext, result);
825                         }
826                     });
827                 }
828             }
829         });
830     }
831
832     protected void setDiagramDesc(ICanvasContext ctx, DiagramDesc diagramDesc) {
833         if (diagramDesc == null)
834             throw new NullPointerException("null diagram desc");
835
836         if (diagramDesc.equals(this.diagramDesc))
837             return;
838
839         this.diagramDesc = diagramDesc;
840         IHintContext hints = ctx.getDefaultHintContext();
841         hints.setHint(Hints.KEY_PAGE_DESC, diagramDesc.getPageDesc());
842         hints.setHint(Hints.KEY_DISPLAY_PAGE, diagramDesc.isPageBordersVisible());
843         hints.setHint(Hints.KEY_DISPLAY_MARGINS, diagramDesc.isMarginsVisible());
844         hints.setHint(GridPainter.KEY_GRID_ENABLED, diagramDesc.isGridVisible());
845         hints.setHint(RulerPainter.KEY_RULER_ENABLED, diagramDesc.isRulerVisible());
846         snapAdvisor.setResolution(diagramDesc.getGridSize());
847         hints.setHint(GridPainter.KEY_GRID_SIZE, diagramDesc.getGridSize());
848     }
849
850     /**
851      * Must be invoked from the AWT thread only.
852      * 
853      * @param state
854      * @param ctx
855      */
856     protected void applyEditorState(final EditorState state, final ICanvasContext ctx) {
857         final IDiagram diagram = ctx.getHintStack().getHint(DiagramHints.KEY_DIAGRAM);
858
859         if (state.viewTransform != null && state.viewTransform.getDeterminant() != 0) {
860             for (PanZoomRotateHandler h : ctx.getItemsByClass(PanZoomRotateHandler.class)) {
861                 h.setTransform(state.viewTransform);
862             }
863         }
864
865         if (diagram != null) {
866             if (state.viewTransform != null)
867                 diagram.removeHint(DiagramHints.KEY_INITIAL_ZOOM_TO_FIT);
868
869             if (state.toolMode != null)
870                 ctx.getDefaultHintContext().setHint(Hints.KEY_TOOL, state.toToolMode());
871             else
872                 ctx.getDefaultHintContext().setHint(Hints.KEY_TOOL, Hints.POINTERTOOL);
873
874             final Set<IElement> selected = DiagramEditorStates.toElements(state.selection, diagram);
875             if (!selected.isEmpty()) {
876                 for (Selection s : ctx.getItemsByClass(Selection.class)) {
877                     s.setSelection(0, selected);
878                 }
879             }
880         }
881     }
882
883     protected EditorState getSavedEditorState(ICanvasContext ctx) {
884         return DiagramEditorStates.toEditorState(ctx, true, true, true);
885     }
886
887     protected void saveEditorState(ICanvasContext ctx) {
888         DiagramEditorStates.saveEditorState(PREFERENCE_VIRTUAL_GRAPH, diagramResource, getSavedEditorState(ctx) , DiagramViewer.this);
889     }
890
891     private boolean firstFocus = true;
892
893     public void setFocus() {
894         
895         if(c != null) {
896                 c.setFocus();
897
898                 if (firstFocus) {
899                     // This is a workaround for using the symbol viewer in multi-page
900                     // editors which causes the first zoom-to-fit scheduling to happen
901                     // already before the controls have been laid out properly.
902                     firstFocus = false;
903                     firstTimeSetFocus();
904                 }
905                 
906         }
907         
908     }
909
910     protected void firstTimeSetFocus() {
911         // [Tuukka@2010-02-11]
912         // Removed since this is actually a workaround for multi-page editors.
913         //scheduleZoomToFit();
914     }
915
916     public void dispose() {
917         // Deactivate all contexts here because after this the context service
918         // in question will not be available.
919         if (contextUtil != null) {
920             contextUtil.deactivateAll();
921         }
922
923         disposed = true;
924         if (activation != null) {
925             activation.deactivate();
926             activation = null;
927         }
928
929         if (resourceManager != null) {
930                 resourceManager.dispose();
931                 resourceManager = null;
932         }
933         //super.dispose();
934     }
935
936 //    protected Resource getInputResource() {
937 //        return getResourceInput().getResource();
938 //    }
939 //
940 //    public IResourceEditorInput getResourceInput() {
941 //        return (IResourceEditorInput) getEditorInput();
942 //    }
943 //
944 //    public IResourceEditorInput2 getResourceInput2() {
945 //        return (IResourceEditorInput2) getEditorInput();
946 //    }
947
948     public void init(DiagramViewerHost _host, MPart part, IResourceEditorInput2 input) {
949
950         if (!(input instanceof IResourceEditorInput))
951             throw new RuntimeException("Invalid input: must be IResourceEditorInput");
952
953         setHost(_host);
954         setPart(part);
955         setResourceEditorInput(input);
956
957         // Set initial part name according to the name given by IEditorInput
958         host.doSetPartName(getResourceEditorInput().getName());
959
960         Session session = SimanticsUI.peekSession();
961         if (session != null) {
962             Supplier<Boolean> disposedCallback = () -> disposed;
963             Display display = part.getContext().get(Shell.class).getDisplay();
964             session.asyncRequest(
965                     new TitleRequest(part.getElementId(), getResourceEditorInput()),
966                     new TitleUpdater(display, host::doSetPartName, disposedCallback));
967             session.asyncRequest(
968                     new ToolTipRequest(part.getElementId(), getResourceEditorInput()),
969                     new TitleUpdater(display, host::doSetTitleToolTip, disposedCallback));
970         }
971
972         try {
973             // Read previous editor state from the database
974             editorState = DiagramEditorStates.readEditorState(getResourceEditorInput().getResource());
975         } catch (DatabaseException e) {
976             exception(e);
977         }
978     }
979
980     @SuppressWarnings("rawtypes")
981     @Override
982     public Object getAdapter(Class adapter) {
983 //        System.out.println("diagramViewer getAdapter " + adapter);
984         // Property view support
985         if (adapter == IPropertyPage.class)
986             return createPropertyPage(getPart(), getPropertyPageContexts());
987         // Provide symbols for the editor
988         if (adapter == SymbolProviderFactory.class) {
989             try {
990                 return DiagramTypeUtils.readSymbolProviderFactory(sessionContext.getSession(), diagramResource);
991             } catch (DatabaseException e) {
992                 ErrorLogger.defaultLogError(getClass() + " failed to adapt to SymbolProviderFactory, see exception for details.", e);
993                 return null;
994             }
995         }
996         // Outline view support
997         if (adapter == IContentOutlinePage.class)
998             return new DiagramOutlinePage(sessionContextProvider, getResourceEditorInput());
999         // Role view support
1000         if (adapter == ILayersViewPage.class)
1001             return new DiagramLayersPage(sourceDiagram, canvasContext);
1002         // Support external steering of the diagram canvas, zooming etc.
1003         if (adapter == ICanvasContext.class)
1004             return canvasContext;
1005         // Support scene graph debugger view
1006         if (adapter == INode.class) {
1007             if (canvasContext != null) {
1008                 INode node = canvasContext.getCanvasNode();
1009                 if (node != null)
1010                     return NodeUtil.getRootNode(node);
1011             }
1012             return null;
1013         }
1014         // Support retrieval of the current diagram.
1015         if (adapter == IDiagram.class)
1016             return sourceDiagram;
1017         // Why is this here ??
1018         if (adapter == Session.class)
1019             return sessionContext.getSession();
1020         if(adapter == RuntimeDiagramManager.class)
1021             return runtimeDiagramManager;
1022         if (adapter == Resource.class)
1023             return getRuntime();
1024         if (adapter == ICanvasChassis.class)
1025                 return c;
1026
1027         return null;
1028     }
1029
1030     //-------------------------------------------------------------------------
1031     // Profiling aid
1032
1033     protected static Object BEGIN(String name) {
1034         if (PROFILE) {
1035             //return ThreadLog.BEGIN(name);
1036         }
1037         return null;
1038     }
1039
1040     protected static void END(Object task) {
1041         if (PROFILE) {
1042             //((Task) task).end();
1043         }
1044     }
1045
1046     //-------------------------------------------------------------------------
1047     // implement ListenerSupport
1048
1049     @Override
1050     public void exception(Throwable t) {
1051         ErrorLogger.defaultLogError(t);
1052     }
1053
1054     @Override
1055     public boolean isDisposed() {
1056         return disposed;
1057     }
1058
1059     protected void collectGarbage() {
1060         SessionGarbageCollectorJob.getInstance().schedule(0);
1061         AWTThread.getThreadAccess().asyncExec(new Runnable() {
1062             @Override
1063             public void run() {
1064                 //System.out.println("BEFORE CLEAR: " + SVGCache.getSVGUniverse().report());
1065                 SVGCache.getSVGUniverse().clearUnreferenced();
1066                 //System.out.println("AFTER CLEAR: " + SVGCache.getSVGUniverse().report());
1067             }
1068         });
1069     }
1070
1071     //-------------------------------------------------------------------------
1072     // Listener for certain canvas context hint changes
1073
1074     IHintListener canvasHintListener = new HintListenerAdapter() {
1075         @Override
1076         public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {
1077             if (key == GridPainter.KEY_GRID_ENABLED) {
1078                 boolean v = Boolean.TRUE.equals(newValue);
1079                 if (diagramDesc.isGridVisible() != v)
1080                     setGlobalPreference(DiagramResource.URIs.DisplayGrid, v);
1081             } else if (key == RulerPainter.KEY_RULER_ENABLED) {
1082                 boolean v = Boolean.TRUE.equals(newValue);
1083                 if (diagramDesc.isRulerVisible() != v)
1084                     setGlobalPreference(DiagramResource.URIs.DisplayRuler, v);
1085             }
1086         }
1087     };
1088
1089     private <T> void setGlobalPreference(final String preferenceURI, boolean value) {
1090         TagUtil.execute(Simantics.getSession(), PREFERENCE_VIRTUAL_GRAPH, preferenceURI, value, Simantics.getProjectResource());
1091     }
1092
1093     /*
1094      * --------------------------------------------------------------------
1095      * Changes related to removal of EditorPart extension from here on down
1096      * --------------------------------------------------------------------
1097      */
1098
1099     private MPart part;
1100     private DiagramViewerHost host;
1101     private IResourceEditorInput2 resourceEditorInput = null;
1102
1103     public MPart getPart() {
1104         return part;
1105     }
1106
1107 //    public IEditorSite getEditorSite() {
1108 //        return (IEditorSite) getSite();
1109 //    }
1110
1111 //    public IEditorInput getEditorInput() {
1112 //        return editorInput;
1113 //    }
1114
1115 //    protected void setPartName(String partName) {
1116 ////        if (compatibilityTitleListener != null) {
1117 ////            removePropertyListener(compatibilityTitleListener);
1118 ////            compatibilityTitleListener = null;
1119 ////        }
1120 ////
1121 ////        super.setPartName(partName);
1122 //    }
1123  
1124 //    protected void setTitleToolTip(String toolTip) {
1125 ////        toolTip = Util.safeString(toolTip);
1126 ////        //Do not send changes if they are the same
1127 ////        if (Util.equals(this.toolTip, toolTip)) {
1128 ////                    return;
1129 ////            }
1130 ////        this.toolTip = toolTip;
1131 ////        firePropertyChange(IWorkbenchPart.PROP_TITLE);
1132 //    }
1133
1134     protected void setHost(DiagramViewerHost host) {
1135         this.host = host;
1136     }
1137
1138     protected void setPart(MPart part) {
1139         this.part = part;
1140     }
1141
1142     protected void setResourceEditorInput(IResourceEditorInput2 input) {
1143         Assert.isLegal(input != null);
1144         resourceEditorInput = input;
1145     }
1146     
1147     public IResourceEditorInput2 getResourceEditorInput() {
1148         return resourceEditorInput;
1149     }
1150
1151     public Composite getComposite() {
1152         return c;
1153     }
1154
1155 }