/*******************************************************************************
- * Copyright (c) 2007, 2013 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2019 Association for Decentralized Information Management
* in Industry THTH ry.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
*
* Contributors:
* VTT Technical Research Centre of Finland - initial API and implementation
- * Semantum Oy - issue #4384
+ * Semantum Oy - issue #4384, gitlab #399
*******************************************************************************/
package org.simantics.modeling.ui.diagramEditor;
import org.simantics.db.Session;
import org.simantics.db.WriteGraph;
import org.simantics.db.common.primitiverequest.PossibleAdapter;
+import org.simantics.db.common.primitiverequest.PossibleObject;
import org.simantics.db.common.procedure.adapter.ListenerDelegate;
import org.simantics.db.common.procedure.adapter.ListenerSupport;
import org.simantics.db.common.request.ParametrizedRead;
+import org.simantics.db.common.request.TypeURIs;
import org.simantics.db.common.request.WriteRequest;
import org.simantics.db.common.utils.CommonDBUtils;
import org.simantics.db.common.utils.TagUtil;
import org.simantics.g2d.diagram.participant.pointertool.PointerInteractor;
import org.simantics.g2d.element.ElementClassProviders;
import org.simantics.g2d.element.ElementClasses;
+import org.simantics.g2d.element.ElementUtils;
import org.simantics.g2d.element.IElement;
import org.simantics.g2d.element.IElementClassProvider;
import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;
void doSetTitleToolTip(String name);
}
- public static final String DIAGRAMMING_CONTEXT = "org.simantics.modeling.ui.diagramming";
- private static final String PREFERENCE_VIRTUAL_GRAPH = "preferences";
+ public static final String DIAGRAMMING_CONTEXT = "org.simantics.modeling.ui.diagramming"; //$NON-NLS-1$
+ private static final String PREFERENCE_VIRTUAL_GRAPH = "preferences"; //$NON-NLS-1$
private static final boolean PROFILE = false;
protected GridSnapAdvisor snapAdvisor;
private RuntimeDiagramManager runtimeDiagramManager;
+ private Resource runtimeDiagramResourceCache;
+ private HasDiagramSourceListener hasDiagramSourceListener;
/**
* Set externally in
*/
protected WorkbenchSelectionProvider selectionProvider;
- public Resource getRuntime() {
+ protected Resource getRuntimeFromManager() {
RuntimeDiagramManager rtdm = runtimeDiagramManager;
return (rtdm == null) ? null : rtdm.getRuntimeDiagram();
}
+ public Resource getRuntime() {
+ if (runtimeDiagramResourceCache != null)
+ return runtimeDiagramResourceCache;
+ runtimeDiagramResourceCache = getRuntimeFromManager();
+ return runtimeDiagramResourceCache;
+ }
+
public ParametrizedRead<IResourceEditorInput, Boolean> getInputValidator() {
return INPUT_VALIDATOR;
}
protected Set<String> getPropertyPageContexts() {
try {
- return BrowseContext.getBrowseContextClosure(SimanticsUI.getSession(), defaultPropertyBrowseContexts);
+ return BrowseContext.getBrowseContextClosure(Simantics.getSession(), defaultPropertyBrowseContexts);
} catch (DatabaseException e) {
- ExceptionUtils.logAndShowError("Failed to load modeled browse contexts for property page, see exception for details.", e);
+ ExceptionUtils.logAndShowError(Messages.DiagramViewer_FailedtoLoadModeled, e);
return defaultPropertyBrowseContexts;
}
}
}
protected String getPopupId() {
- return "#ModelingDiagramPopup";
+ return "#ModelingDiagramPopup"; //$NON-NLS-1$
}
protected void getPreferences() {
}
protected void initSession() {
- sessionContextProvider = SimanticsUI.getSessionContextProvider();
+ sessionContextProvider = Simantics.getSessionContextProvider();
sessionContext = sessionContextProvider.getSessionContext();
}
resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent);
c = new SWTChassis(parent, 0);
- Object task = BEGIN("DV.precreateParticipants");
+ Object task = BEGIN("DV.precreateParticipants"); //$NON-NLS-1$
createCustomParticipants();
END(task);
swt = SWTThread.getThreadAccess(display);
statusLineManager = getEditorSite().getActionBars().getStatusLineManager();
- Object task = BEGIN("DV.initSession");
+ Object task = BEGIN("DV.initSession"); //$NON-NLS-1$
initSession();
END(task);
this.canvasContext = new CanvasContext(thread);
this.canvasContext.setLocked(true);
- task = BEGIN("DV.createChassis");
+ task = BEGIN("DV.createChassis"); //$NON-NLS-1$
createChassis(parent);
END(task);
} catch (DatabaseException e) {
* Invoke this only from the AWT thread.
*/
protected void initializeCanvas() {
- Object canvasInit = BEGIN("DV.canvasInitialization");
+ Object canvasInit = BEGIN("DV.canvasInitialization"); //$NON-NLS-1$
- Object task = BEGIN("DV.createViewerCanvas");
+ Object task = BEGIN("DV.createViewerCanvas"); //$NON-NLS-1$
initializeCanvasContext(canvasContext);
END(task);
canvasContext.getHintStack().addKeyHintListener(GridPainter.KEY_GRID_ENABLED, canvasHintListener);
canvasContext.getHintStack().addKeyHintListener(RulerPainter.KEY_RULER_ENABLED, canvasHintListener);
- task = BEGIN("DV.setCanvasContext");
+ task = BEGIN("DV.setCanvasContext"); //$NON-NLS-1$
setCanvasContext(canvasContext);
END(task);
* cancelled.
*/
protected void performActivation(IProgressMonitor monitor) {
- SubMonitor progress = SubMonitor.convert(monitor, "Activate Mapping", 100);
+ SubMonitor progress = SubMonitor.convert(monitor, Messages.DiagramViewer_MonitorActivateMapping, 100);
IActivationManager activationManager = sessionContext.getSession().peekService(IActivationManager.class);
if (activationManager != null) {
activation = activationManager.activate(diagramResource);
*/
protected void scheduleZoomToFit(IDiagram diagram) {
if (diagram == null)
- throw new IllegalStateException("diagram is null");
+ throw new IllegalStateException("diagram is null"); //$NON-NLS-1$
CanvasUtils.scheduleZoomToFit(swt, () -> disposed, canvasContext, diagram);
}
* @throws DatabaseException
*/
protected IDiagram loadDiagram(IProgressMonitor monitor, Resource diagram, IHintContext initialHints) throws DatabaseException {
- RuntimeDiagramManager rtdm = runtimeDiagramManager;
- Resource runtimeDiagram = rtdm != null ? rtdm.getRuntimeDiagram() : null;
- IDiagramLoader loader = synchronizer;
- if (rtdm == null || runtimeDiagram == null || loader == null)
- return null;
- IDiagram d = sessionContext.getSession().syncRequest(
- DiagramRequests.loadDiagram(monitor, getResourceInput2().getModel(null), diagram,
- runtimeDiagram, null, loader, initialHints));
+ RuntimeDiagramManager rtdm = runtimeDiagramManager;
+ Resource runtimeDiagram = rtdm != null ? rtdm.getRuntimeDiagram() : null;
+ IDiagramLoader loader = synchronizer;
+ if (rtdm == null || runtimeDiagram == null || loader == null)
+ return null;
+ IDiagram d = sessionContext.getSession().syncRequest((Read<IDiagram>) graph -> {
+ IDiagram result = DiagramRequests.loadDiagram(monitor, getResourceInput2().getModel(null), diagram,
+ runtimeDiagram, null, loader, initialHints).perform(graph);
+
+ // #399: Enable certain PropertyTester implementation without database transactions
+ ModelingResources MOD = ModelingResources.getInstance(graph);
+ Resource composite = graph.getPossibleObject(diagram, MOD.DiagramToComposite);
+ result.setHint(
+ DiagramModelHints.KEY_DIAGRAM_RESOURCE_TYPE_URIS,
+ graph.syncRequest(new TypeURIs(diagram)));
+ result.setHint(
+ DiagramModelHints.KEY_MAPPED_COMPOSITE_RESOURCE_TYPE_URIS,
+ composite != null ? graph.syncRequest(new TypeURIs(composite)) : Collections.emptySet());
+
+ Resource diagramSource = graph.syncRequest(
+ new PossibleObject(diagram, MOD.HasDiagramSource),
+ hasDiagramSourceListener = new HasDiagramSourceListener(sourceDiagramContainer));
+ ElementUtils.setOrRemoveHint(
+ result,
+ DiagramModelHints.KEY_HAS_DIAGRAM_SOURCE,
+ diagramSource);
+
+ return result;
+ });
return d;
}
}
});
} catch (DatabaseException e) {
- throw new UnsupportedOperationException("Failed to initialize data model synchronizer", e);
+ throw new UnsupportedOperationException("Failed to initialize data model synchronizer", e); //$NON-NLS-1$
}
}
// unnecessary visual glitches.
h.setHint(Hints.KEY_DISABLE_PAINTING, Boolean.TRUE);
- Object task = BEGIN("createSynchronizer");
+ Object task = BEGIN("createSynchronizer"); //$NON-NLS-1$
this.synchronizer = createSynchronizer(ctx, sessionContext);
END(task);
}
}, parameter -> {
if (parameter != null)
- ErrorLogger.defaultLogError("Failed to write default diagram page description to database, see exception for details", parameter);
+ ErrorLogger.defaultLogError("Failed to write default diagram page description to database, see exception for details", parameter); //$NON-NLS-1$
});
}
protected void setDiagramDesc(ICanvasContext ctx, DiagramDesc diagramDesc) {
if (diagramDesc == null)
- throw new NullPointerException("null diagram desc");
+ throw new NullPointerException("null diagram desc"); //$NON-NLS-1$
if (diagramDesc.equals(this.diagramDesc))
return;
}
disposed = true;
+
+ if (hasDiagramSourceListener != null) {
+ hasDiagramSourceListener.dispose();
+ hasDiagramSourceListener = null;
+ }
+
if (activation != null) {
activation.deactivate();
activation = null;
public void init(DiagramViewerHost _host, IEditorSite site, IEditorInput input, DataContainer<IDiagram> diagramContainer, WorkbenchSelectionProvider selectionProvider) {
if (!(input instanceof IResourceEditorInput))
- throw new RuntimeException("Invalid input: must be IResourceEditorInput");
+ throw new RuntimeException("Invalid input: must be IResourceEditorInput"); //$NON-NLS-1$
setHost(_host);
setSite(site);
// Set initial part name according to the name given by IEditorInput
host.doSetPartName(getEditorInput().getName());
- Session session = SimanticsUI.peekSession();
+ Session session = Simantics.peekSession();
if (session != null) {
Supplier<Boolean> disposedCallback = () -> disposed;
session.asyncRequest(
try {
return (T) DiagramTypeUtils.readSymbolProviderFactory(sessionContext.getSession(), diagramResource);
} catch (DatabaseException e) {
- ErrorLogger.defaultLogError(getClass() + " failed to adapt to SymbolProviderFactory, see exception for details.", e);
+ ErrorLogger.defaultLogError(getClass() + " failed to adapt to SymbolProviderFactory, see exception for details.", e); //$NON-NLS-1$
return null;
}
}