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