1 /*******************************************************************************
2 * Copyright (c) 2007, 2013 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 * Semantum Oy - issue #4384
12 *******************************************************************************/
13 package org.simantics.modeling.ui.diagramEditor;
15 import java.awt.Color;
16 import java.lang.reflect.InvocationTargetException;
17 import java.util.function.Supplier;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.SubMonitor;
21 import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
22 import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
23 import org.eclipse.jface.action.IStatusLineManager;
24 import org.eclipse.jface.operation.IRunnableWithProgress;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.ui.IEditorInput;
27 import org.eclipse.ui.IEditorSite;
28 import org.eclipse.ui.PartInitException;
29 import org.eclipse.ui.PlatformUI;
30 import org.eclipse.ui.contexts.IContextService;
31 import org.eclipse.ui.part.EditorPart;
32 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
33 import org.simantics.db.ReadGraph;
34 import org.simantics.db.Resource;
35 import org.simantics.db.Session;
36 import org.simantics.db.common.ResourceArray;
37 import org.simantics.db.exception.DatabaseException;
38 import org.simantics.db.management.ISessionContext;
39 import org.simantics.db.management.ISessionContextProvider;
40 import org.simantics.db.request.Read;
41 import org.simantics.diagram.adapter.DefaultConnectionClassFactory;
42 import org.simantics.diagram.adapter.FlagClassFactory;
43 import org.simantics.diagram.adapter.GraphToDiagramSynchronizer;
44 import org.simantics.diagram.handler.ConnectionCommandHandler;
45 import org.simantics.diagram.handler.CopyPasteHandler;
46 import org.simantics.diagram.handler.DeleteHandler;
47 import org.simantics.diagram.handler.ExpandSelectionHandler;
48 import org.simantics.diagram.handler.SimpleElementTransformHandler;
49 import org.simantics.diagram.layer.ILayersViewPage;
50 import org.simantics.diagram.participant.ContextUtil;
51 import org.simantics.diagram.participant.SGFocusParticipant;
52 import org.simantics.diagram.query.DiagramRequests;
53 import org.simantics.diagram.stubs.DiagramResource;
54 import org.simantics.diagram.synchronization.IModifiableSynchronizationContext;
55 import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;
56 import org.simantics.diagram.ui.SWTPopupMenuParticipant;
57 import org.simantics.g2d.canvas.Hints;
58 import org.simantics.g2d.canvas.ICanvasContext;
59 import org.simantics.g2d.canvas.impl.CanvasContext;
60 import org.simantics.g2d.chassis.SWTChassis;
61 import org.simantics.g2d.diagram.DiagramClass;
62 import org.simantics.g2d.diagram.DiagramHints;
63 import org.simantics.g2d.diagram.IDiagram;
64 import org.simantics.g2d.diagram.impl.Diagram;
65 import org.simantics.g2d.diagram.participant.DiagramParticipant;
66 import org.simantics.g2d.diagram.participant.ElementInteractor;
67 import org.simantics.g2d.diagram.participant.ElementPainter;
68 import org.simantics.g2d.diagram.participant.Selection;
69 import org.simantics.g2d.diagram.participant.TerminalPainter;
70 import org.simantics.g2d.diagram.participant.ZOrderHandler;
71 import org.simantics.g2d.diagram.participant.pointertool.PointerInteractor;
72 import org.simantics.g2d.element.ElementClassProviders;
73 import org.simantics.g2d.element.ElementClasses;
74 import org.simantics.g2d.element.IElementClassProvider;
75 import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;
76 import org.simantics.g2d.participant.CanvasBoundsParticipant;
77 import org.simantics.g2d.participant.CanvasGrab;
78 import org.simantics.g2d.participant.KeyUtil;
79 import org.simantics.g2d.participant.MouseUtil;
80 import org.simantics.g2d.participant.MultitouchPanZoomRotateInteractor;
81 import org.simantics.g2d.participant.Notifications;
82 import org.simantics.g2d.participant.PageBorderParticipant;
83 import org.simantics.g2d.participant.PanZoomRotateHandler;
84 import org.simantics.g2d.participant.PointerPainter;
85 import org.simantics.g2d.participant.RulerPainter;
86 import org.simantics.g2d.participant.SymbolUtil;
87 import org.simantics.g2d.participant.TimeParticipant;
88 import org.simantics.g2d.participant.TransformUtil;
89 import org.simantics.g2d.participant.ZoomToAreaHandler;
90 import org.simantics.layer0.utils.triggers.IActivation;
91 import org.simantics.layer0.utils.triggers.IActivationManager;
92 import org.simantics.modeling.ModelingResources;
93 import org.simantics.modeling.mapping.ModelingSynchronizationHints;
94 import org.simantics.modeling.ui.diagramEditor.handlers.WorkbenchStructuralSelectionProvider;
95 import org.simantics.modeling.ui.preferences.DiagramPreferenceUtil;
96 import org.simantics.modeling.ui.preferences.DiagramPreferences;
97 import org.simantics.scenegraph.INode;
98 import org.simantics.scenegraph.g2d.snap.GridSnapAdvisor;
99 import org.simantics.scenegraph.utils.NodeUtil;
100 import org.simantics.selectionview.StandardPropertyPage;
101 import org.simantics.ui.SimanticsUI;
102 import org.simantics.ui.workbench.IPropertyPage;
103 import org.simantics.ui.workbench.IResourceEditorInput;
104 import org.simantics.ui.workbench.IResourceEditorInput2;
105 import org.simantics.ui.workbench.IResourceEditorPart2;
106 import org.simantics.ui.workbench.ResourceEditorSupport;
107 import org.simantics.ui.workbench.TitleRequest;
108 import org.simantics.ui.workbench.TitleUpdater;
109 import org.simantics.ui.workbench.ToolTipRequest;
110 import org.simantics.utils.DataContainer;
111 import org.simantics.utils.datastructures.hints.IHintContext;
112 import org.simantics.utils.page.PageDesc;
113 import org.simantics.utils.threads.AWTThread;
114 import org.simantics.utils.threads.IThreadWorkQueue;
115 import org.simantics.utils.threads.SWTThread;
116 import org.simantics.utils.threads.ThreadUtils;
117 import org.simantics.utils.ui.ErrorLogger;
120 * @author Toni Kalajainen
121 * @author Tuukka Lehtonen
123 public class SheetViewer extends EditorPart implements IResourceEditorPart2 {
125 private static final boolean PROFILE = false;
127 protected boolean disposed = false;
128 protected IThreadWorkQueue swt;
129 protected IStatusLineManager statusLineManager;
130 protected SWTChassis c;
131 protected IDiagram sourceDiagram;
132 protected ICanvasContext canvasContext;
133 protected ResourceEditorSupport support;
134 protected ISessionContextProvider sessionContextProvider;
135 protected ISessionContext sessionContext;
136 protected Resource diagramResource;
137 protected GraphToDiagramSynchronizer synchronizer;
138 protected IActivation activation;
139 protected ContextUtil contextUtil;
141 protected DiagramPreferences diagramPreferences;
142 protected GridSnapAdvisor snapAdvisor;
144 public ResourceArray structuralPath;
146 IPreferenceChangeListener preferenceListener = new IPreferenceChangeListener() {
148 public void preferenceChange(PreferenceChangeEvent event) {
149 String value = (String) event.getNewValue();
150 if (DiagramPreferences.P_SNAP_GRID_SIZE.equals(event.getKey())) {
151 double grid = DiagramPreferences.DEFAULT_SNAP_GRID_SIZE;
153 grid = Double.parseDouble(value);
154 snapAdvisor.setResolution(grid);
155 } else if (DiagramPreferences.P_DEFAULT_PAGE_SIZE.equals(event.getKey())) {
156 PageDesc pageDesc = PageDesc.deserialize(value, DiagramPreferences.DEFAULT_PAGE_SIZE);
157 //System.out.println("new page desc: " + pageDesc);
158 canvasContext.getDefaultHintContext().setHint(Hints.KEY_PAGE_DESC, pageDesc);
159 } else if (DiagramPreferences.P_DISPLAY_PAGE_SIZE.equals(event.getKey())) {
160 Boolean display = value != null ? Boolean.parseBoolean(value) : DiagramPreferences.DEFAULT_DISPLAY_PAGE_SIZE;
161 canvasContext.getDefaultHintContext().setHint(Hints.KEY_DISPLAY_PAGE, display);
162 } else if (DiagramPreferences.P_DISPLAY_MARGINS.equals(event.getKey())) {
163 Boolean display = value != null ? Boolean.parseBoolean(value) : DiagramPreferences.DEFAULT_DISPLAY_MARGINS;
164 canvasContext.getDefaultHintContext().setHint(Hints.KEY_DISPLAY_MARGINS, display);
169 protected void addDropParticipants(ICanvasContext ctx) {
170 // FIXME This is a workaround so that this participant can be disabled
172 ctx.add(new PopulateElementDropParticipant(synchronizer));
173 ctx.add(new PopulateElementMonitorDropParticipant(synchronizer, 0.5, 0.5));
176 protected void addKeyBindingParticipants(CanvasContext ctx) {
177 //ctx.add( new KeyToCommand( CommandKeyBinding.DEFAULT_BINDINGS ) );
178 ctx.add(new DeleteHandler(statusLineManager));
179 ctx.add(new CopyPasteHandler(statusLineManager));
180 ctx.add(new ConnectionCommandHandler());
183 protected void addPopupmenu(ICanvasContext ctx) {
184 ctx.add(new SWTPopupMenuParticipant(getSite(), c, getPopupId()));
187 protected void addStructureParticipants(ICanvasContext ctx) {
188 structuralPath = getResourceInput().getResourceArray().removeFromBeginning(1);
190 ctx.add(new WorkbenchStructuralSelectionProvider(swt, getSite(), structuralPath));
191 // Add visual browsing capabilities for structural models
192 // ctx.add(new StructuralBrowsingHandler(getSite(), sessionContext, structuralPath));
193 // ctx.add(new LinkBrowsingHandler(getSite(), this, sessionContext));
196 protected String getPopupId() {
197 return "#ModelingDiagramPopup";
200 protected void getPreferences() {
201 this.diagramPreferences = DiagramPreferenceUtil.getPreferences();
204 protected void initSession() {
205 sessionContextProvider = SimanticsUI.getSessionContextProvider();
206 sessionContext = sessionContextProvider.getSessionContext();
209 protected void readNames() {
210 String name = getEditorInput().getName();
212 setTitleToolTip(name);
215 protected void createChassis(Composite parent) {
216 c = new SWTChassis(parent, 0);
220 protected void setCanvasContext(ICanvasContext context) {
221 c.setCanvasContext(canvasContext);
225 public void createPartControl(Composite parent) {
226 swt = SWTThread.getThreadAccess(parent.getDisplay());
227 statusLineManager = getEditorSite().getActionBars().getStatusLineManager();
229 Object task = BEGIN("DV.initSession");
233 diagramResource = getInputResource();
237 task = BEGIN("DV.createChassis");
238 createChassis(parent);
243 // Start tracking changes in diagram preferences.
244 diagramPreferences.preferences.addPreferenceChangeListener(preferenceListener);
247 protected void initializeCanvas() {
248 Object canvasInit = BEGIN("DV.canvasInitialization");
250 Object task = BEGIN("DV.createViewerCanvas");
251 // ThreadUtils.syncExec(AWTThread.getThreadAccess(), new Runnable() {
253 // public void run() {
254 canvasContext = createViewerCanvas();
259 //FullscreenUtils.addFullScreenHandler(canvasContext, s, canvasProvider);
261 task = BEGIN("DV.setCanvasContext");
262 setCanvasContext(canvasContext);
266 task = BEGIN("DV.loadDiagram");
267 sourceDiagram = loadDiagram(diagramResource);
271 task = BEGIN("DV.scheduleZoomToFit");
273 // canvasContext.getDefaultHintContext().setHint(Hints.KEY_CANVAS_TRANSFORM, new AffineTransform());
274 // canvasContext.getContentContext().setDirty();
279 // Start an activation for the input resource.
280 // This will activate mapping if necessary.
281 task = BEGIN("DV.performActivation");
285 task = BEGIN("DV.activate context");
286 contextUtil.activate(DiagramViewer.DIAGRAMMING_CONTEXT);
289 task = BEGIN("DV.onCreated");
293 } catch (DatabaseException e) {
294 ErrorLogger.defaultLogError(e);
296 // Without this all diagram participants will crash like there's no tomorrow.
297 // Just trying to keep the behavior a bit more sane in case of
298 // errors instead of flooding the console with exceptions.
299 canvasContext.getDefaultHintContext().setHint(DiagramHints.KEY_DIAGRAM, Diagram.spawnNew(DiagramClass.DEFAULT));
304 protected void performActivation() {
306 IActivationManager activationManager = sessionContext.getSession().peekService(IActivationManager.class);
307 if (activationManager != null) {
308 activation = activationManager.activate(diagramResource);
313 protected void scheduleZoomToFit() {
314 if (sourceDiagram == null)
315 throw new IllegalStateException("source diagram is null");
317 sourceDiagram.setHint(Hints.KEY_DISABLE_PAINTING, Boolean.TRUE);
318 sourceDiagram.setHint(DiagramHints.KEY_INITIAL_ZOOM_TO_FIT, Boolean.TRUE);
319 ThreadUtils.asyncExec(swt, new Runnable() {
325 // System.out.println("size: " + c.getSize());
326 ThreadUtils.asyncExec(canvasContext.getThreadAccess(), new Runnable() {
331 // System.out.println("fit diagram to view");
332 sourceDiagram.removeHint(Hints.KEY_DISABLE_PAINTING);
333 /*Boolean zoomToFit =*/ sourceDiagram.removeHint(DiagramHints.KEY_INITIAL_ZOOM_TO_FIT);
334 canvasContext.getDefaultHintContext().removeHint(Hints.KEY_DISABLE_PAINTING);
336 // if (Boolean.TRUE.equals(zoomToFit))
337 // CanvasUtils.sendCommand(canvasContext, Commands.ZOOM_TO_FIT);
339 canvasContext.getContentContext().setDirty();
348 protected IDiagram loadDiagram(final Resource r) throws DatabaseException {
349 final DataContainer<IDiagram> dc = new DataContainer<IDiagram>();
350 //dc.set( loadDiagram(new NullProgressMonitor(), r) );
352 PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
354 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
355 SubMonitor mon = SubMonitor.convert(monitor, "Loading Diagram", 100);
357 dc.set( loadDiagram(mon.newChild(100), r) );
358 } catch (DatabaseException e) {
359 throw new InvocationTargetException(e);
365 } catch (InvocationTargetException e) {
366 Throwable t = e.getTargetException();
367 if (t instanceof DatabaseException)
368 throw (DatabaseException) t;
369 throw new DatabaseException(t);
370 } catch (InterruptedException e) {
371 throw new DatabaseException(e);
376 protected IDiagram loadDiagram(IProgressMonitor monitor, Resource r) throws DatabaseException {
377 SubMonitor mon = SubMonitor.convert(monitor, "Loading Diagram", 100);
379 Object task = BEGIN("DV.DiagramLoadQuery");
380 IDiagram d = sessionContext.getSession().syncRequest(DiagramRequests.loadDiagram(mon.newChild(100), getResourceInput2().getModel(null), r, null, structuralPath, synchronizer, null));
383 task = BEGIN("DV.setDiagramHint");
384 canvasContext.getDefaultHintContext().setHint(DiagramHints.KEY_DIAGRAM, d);
387 task = BEGIN("DV.set other hints");
388 // Setup a copy advisor for the synchronizer
389 //d.setHint(SynchronizationHints.COPY_ADVISOR, new MappedElementCopyAdvisor(new ComponentCopyAdvisor()));
390 d.setHint(DiagramHints.KEY_USE_CONNECTION_FLAGS, Boolean.FALSE);
391 d.setHint(DiagramHints.KEY_ALLOW_CONNECTION_BRANCHING, Boolean.FALSE);
392 d.setHint(DiagramHints.KEY_ALLOW_ROUTE_POINTS, Boolean.FALSE);
398 protected GraphToDiagramSynchronizer createSynchronizer(final ICanvasContext ctx, final ISessionContext sessionContext) {
400 return sessionContext.getSession().syncRequest(new Read<GraphToDiagramSynchronizer>() {
402 public GraphToDiagramSynchronizer perform(ReadGraph graph) throws DatabaseException {
403 GraphToDiagramSynchronizer sync = new GraphToDiagramSynchronizer(graph, ctx, createElementClassProvider(graph));
404 initializeSynchronizationContext(graph, sync);
408 } catch (DatabaseException e) {
409 throw new UnsupportedOperationException("Failed to initialize data model synchronizer", e);
413 protected void initializeSynchronizationContext(ReadGraph graph, IModifiableSynchronizationContext context) {
414 context.set(ModelingSynchronizationHints.MODELING_RESOURCE, ModelingResources.getInstance(graph));
417 protected IElementClassProvider createElementClassProvider(ReadGraph graph) {
418 DiagramResource dr = DiagramResource.getInstance(graph);
419 return ElementClassProviders.mappedProvider(
420 ElementClasses.CONNECTION, DefaultConnectionClassFactory.CLASS.newClassWith(new StaticObjectAdapter(dr.Connection)),
421 ElementClasses.FLAG, FlagClassFactory.createFlagClass(dr.Flag, dr.Flag_Terminal)
425 public ICanvasContext createViewerCanvas() {
426 IThreadWorkQueue thread = AWTThread.getThreadAccess();
427 CanvasContext ctx = new CanvasContext(thread);
428 IHintContext h = ctx.getDefaultHintContext();
430 Object task = BEGIN("createSynchronizer");
431 this.synchronizer = createSynchronizer(ctx, sessionContext);
434 IContextService contextService = (IContextService) getSite().getService(IContextService.class);
435 contextUtil = new ContextUtil(contextService, swt);
437 ctx.add(new PanZoomRotateHandler()); // Must be before TransformUtil
439 // Support & Util Participants
440 ctx.add(new TransformUtil());
441 ctx.add(new MouseUtil());
442 ctx.add(new KeyUtil());
443 ctx.add(contextUtil);
444 ctx.add(new CanvasGrab());
445 ctx.add(new SymbolUtil());
446 ctx.add(new TimeParticipant());
447 ctx.add(new CanvasBoundsParticipant());
448 ctx.add(new Notifications());
450 ctx.add( new SGFocusParticipant(c, DiagramViewer.DIAGRAMMING_CONTEXT) );
452 // Debug participant(s)
453 // ctx.add( new PointerPainter() );
454 // ctx.add( new HandPainter() );
455 h.setHint(PointerPainter.KEY_PAINT_POINTER, true);
457 // Pan & Zoom & Rotate
458 ctx.add(new MultitouchPanZoomRotateInteractor());
459 // ctx.add( new OrientationRestorer() );
460 ctx.add(new ZoomToAreaHandler());
461 ctx.add(new SimpleElementTransformHandler(true, true, true));
462 ctx.add(new ExpandSelectionHandler(getEditorSite().getActionBars().getStatusLineManager()));
465 addKeyBindingParticipants(ctx);
467 // Grid & Ruler & Background
468 // ctx.add(new GridPainter());
469 // ctx.add(new RulerPainter());
470 // ctx.add(new BackgroundPainter());
473 h.setHint(PanZoomRotateHandler.KEY_ADAPT_VIEWPORT_TO_RESIZED_CONTROL, Boolean.FALSE);
474 h.setHint(Hints.KEY_DISPLAY_PAGE, diagramPreferences.get(DiagramPreferences.P_DISPLAY_PAGE_SIZE));
475 h.setHint(Hints.KEY_DISPLAY_MARGINS, diagramPreferences.get(DiagramPreferences.P_DISPLAY_MARGINS));
476 ctx.add(new PageBorderParticipant());
478 // h.setHint(Hints.KEY_GRID_COLOR, new Color(0.9f, 0.9f, 0.9f));
479 // h.setHint(Hints.KEY_BACKGROUND_COLOR, Color.LIGHT_GRAY);
480 h.setHint(Hints.KEY_GRID_COLOR, new Color(0.95f, 0.95f, 0.95f));
481 h.setHint(Hints.KEY_BACKGROUND_COLOR, Color.WHITE);
482 h.setHint(RulerPainter.KEY_RULER_BACKGROUND_COLOR, new Color(0.9f, 0.9f, 0.9f, 0.75f));
483 h.setHint(RulerPainter.KEY_RULER_TEXT_COLOR, Color.BLACK);
485 ////// Diagram Participants //////
486 ctx.add(new ZOrderHandler());
487 ctx.add(new PointerInteractor(true, true, true, false, true, false, synchronizer.getElementClassProvider(), null));
488 ctx.add(new ElementInteractor());
489 ctx.add(new Selection());
490 ctx.add(new DiagramParticipant());
491 ctx.add(new ElementPainter());
492 ctx.add(new TerminalPainter(true, true, false, true));
493 //ctx.add(new ElementHeartbeater());
494 // ctx.add(new ZoomTransitionParticipant(TransitionFunction.SIGMOID));
496 /////// D'n'D ///////
497 addDropParticipants(ctx);
499 h.setHint(ElementPainter.KEY_SELECTION_FRAME_COLOR, Color.MAGENTA);
500 h.setHint(Hints.KEY_TOOL, Hints.POINTERTOOL);
502 h.setHint(PanZoomRotateHandler.KEY_ZOOM_IN_LIMIT, 100000.0);
503 h.setHint(PanZoomRotateHandler.KEY_ZOOM_OUT_LIMIT, 10.0);
505 Double snapResolution = diagramPreferences.get(DiagramPreferences.P_SNAP_GRID_SIZE);
506 this.snapAdvisor = new GridSnapAdvisor(snapResolution);
507 h.setHint(DiagramHints.SNAP_ADVISOR, this.snapAdvisor);
509 // Workbench selection provider
510 addStructureParticipants(ctx);
515 // Load page frame description settings
516 loadPageSettings(ctx);
518 // The canvas context should not be painted until it is ready to avoid
519 // unnecessary visual glitches.
520 h.setHint(Hints.KEY_DISABLE_PAINTING, Boolean.TRUE);
522 ctx.assertParticipantDependencies();
527 protected void loadPageSettings(ICanvasContext ctx) {
528 PageDesc pageDesc = null;
530 if (diagramResource != null) {
532 pageDesc = sessionContext.getSession().syncRequest(new Read<PageDesc>() {
534 public PageDesc perform(ReadGraph graph) throws DatabaseException {
535 return DiagramGraphUtil.getPageDesc(graph, diagramResource, null);
538 } catch (DatabaseException e) {
539 ErrorLogger.defaultLogError(e);
543 if (pageDesc == null) {
544 // Take page description from the preferences if nothing else is available.
545 PageDesc pd = diagramPreferences.getCompletePageDesc();
548 ctx.getDefaultHintContext().setHint(Hints.KEY_PAGE_DESC, pageDesc);
551 private boolean firstFocus = true;
554 public void setFocus() {
558 // This is a workaround for using the symbol viewer in multi-page
559 // editors which causes the first zoom-to-fit scheduling to happen
560 // already before the controls have been laid out properly.
566 protected void firstTimeSetFocus() {
567 //scheduleZoomToFit();
571 public void dispose() {
572 // Remember to remove the added preference change listener
573 diagramPreferences.preferences.removePreferenceChangeListener(preferenceListener);
575 // Deactivate all contexts here because after this the context service
576 // in question will not be available.
577 contextUtil.deactivateAll();
580 if (activation != null) {
581 activation.deactivate();
584 synchronizer.dispose();
585 ThreadUtils.asyncExec(c.getCanvasContext().getThreadAccess(), new Runnable() {
588 c.getCanvasContext().dispose();
591 sourceDiagram.dispose();
596 protected Resource getInputResource() {
597 return getResourceInput().getResource();
601 public IResourceEditorInput2 getResourceInput2() {
602 return (IResourceEditorInput2) getEditorInput();
606 public IResourceEditorInput getResourceInput() {
607 return (IResourceEditorInput) getEditorInput();
611 public void doSave(IProgressMonitor monitor) {
615 public void doSaveAs() {
619 public void init(IEditorSite site, IEditorInput input) throws PartInitException {
620 if (!(input instanceof IResourceEditorInput))
621 throw new PartInitException("Invalid input: must be IResourceEditorInput");
624 support = new ResourceEditorSupport(this);
626 // Set initial part name according to the name given by IEditorInput
627 setPartName(getEditorInput().getName());
629 Session session = SimanticsUI.peekSession();
630 if (session != null) {
631 Supplier<Boolean> disposedCallback = () -> disposed;
632 session.asyncRequest(
633 new TitleRequest(site.getId(), getResourceInput2()),
634 new TitleUpdater(site.getShell().getDisplay(), this::setPartName, disposedCallback));
635 session.asyncRequest(
636 new ToolTipRequest(site.getId(), getResourceInput2()),
637 new TitleUpdater(site.getShell().getDisplay(), this::setTitleToolTip, disposedCallback));
643 public boolean isDirty() {
648 public boolean isSaveAsAllowed() {
652 @SuppressWarnings("unchecked")
654 public <T> T getAdapter(Class<T> adapter) {
655 if (adapter == IPropertyPage.class)
656 return (T) new StandardPropertyPage(getSite());
657 if (adapter == IContentOutlinePage.class)
658 return (T) new DiagramOutlinePage(sessionContextProvider, getResourceInput2());
659 if (adapter == ILayersViewPage.class)
660 return (T) new DiagramLayersPage(sourceDiagram, canvasContext);
661 if (adapter == ICanvasContext.class)
662 return (T) canvasContext;
663 if (adapter == INode.class) {
664 if (canvasContext != null) {
665 INode node = canvasContext.getCanvasNode();
667 return (T) NodeUtil.getRootNode(node);
671 if (adapter == IDiagram.class)
672 return (T) sourceDiagram;
673 if (adapter == Session.class)
674 return (T) sessionContext.getSession();
675 return super.getAdapter(adapter);
678 protected void onCreated() {
682 private static Object BEGIN(String name) {
684 //return ThreadLog.BEGIN(name);
689 private static void END(Object task) {
691 //((Task) task).end();