if (unlock)
ctx.setLocked(false);
}
+
+ public static class DiagramDescListener implements Listener<DiagramDesc> {
+ ICanvasContext ctx;
+ public DiagramDescListener(ICanvasContext ctx) {
+ this.ctx = ctx;
+ }
+ @Override
+ public void execute(DiagramDesc result) {
+ if (result != null && ctx != null) {
+ ThreadUtils.asyncExec(ctx.getThreadAccess(), () -> {
+ if (ctx != null) {
+ setDiagramDesc(ctx, result);
+ }
+ });
+ }
+ }
+
+ @Override
+ public void exception(Throwable t) {
+ ErrorLogger.defaultLogError(t);
+ }
+
+ @Override
+ public boolean isDisposed() {
+ return ctx == null;
+ }
+
+ protected void setDiagramDesc(ICanvasContext ctx, DiagramDesc diagramDesc) {
+ IHintContext hints = ctx.getDefaultHintContext();
+ hints.setHint(Hints.KEY_PAGE_DESC, diagramDesc.getPageDesc());
+ hints.setHint(Hints.KEY_DISPLAY_PAGE, diagramDesc.isPageBordersVisible());
+ hints.setHint(Hints.KEY_DISPLAY_MARGINS, diagramDesc.isMarginsVisible());
+ }
+
+ public void dispose() {
+ ctx = null;
+ }
+ }
+ DiagramDescListener diagramDescListener;
+
protected void loadPageSettings(ICanvasContext ctx, Resource diagramResource) {
try {
DiagramDesc diagramDesc = Simantics.getSession().syncRequest(DiagramRequests.getDiagramDesc(diagramResource));
if (diagramDesc != null)
setDiagramDesc(ctx, diagramDesc);
+ diagramDescListener = new DiagramDescListener(ctx);
// Create a listener to react to page setting changes.
- Simantics.getSession().asyncRequest(DiagramRequests.getDiagramDesc(diagramResource), new Listener<DiagramDesc>() {
- @Override
- public void execute(DiagramDesc result) {
- if (result != null && ctx != null) {
- ThreadUtils.asyncExec(ctx.getThreadAccess(), () -> {
- if (ctx != null) {
- setDiagramDesc(ctx, result);
- }
- });
- }
- }
-
- @Override
- public void exception(Throwable t) {
- ErrorLogger.defaultLogError(t);
- }
-
- @Override
- public boolean isDisposed() {
- return DiagramSceneGraphProvider.this.ctx == null;
- }
- });
+ Simantics.getSession().asyncRequest(DiagramRequests.getDiagramDesc(diagramResource), diagramDescListener);
} catch (DatabaseException e) {
ErrorLogger.defaultLogError(e);
}
*/
private G2DSceneGraph initializeSceneGraph(G2DSceneGraph sg, String modelURI, String RVI, String view) {
IThreadWorkQueue thread = AWTThread.getThreadAccess();
- ctx = new CanvasContext(thread, sg); // By giving the scene graph instance as parameter, we can use external serializer
+ ICanvasContext ctx = new CanvasContext(thread, sg); // By giving the scene graph instance as parameter, we can use external serializer
return initializeSceneGraph(ctx, sg, modelURI, RVI, view);
}
* @return
*/
private G2DSceneGraph initializeSceneGraph(ICanvasContext context, G2DSceneGraph sg, String modelURI, String RVI, String view) {
- this.ctx = (CanvasContext) context;
+ if (this.ctx != null)
+ throw new RuntimeException("Cannot initialize scenegraph twice");
+ this.ctx = (CanvasContext) context;
this.view = view;
if(view != null) {
//System.out.println("using layer '"+view+"'");
@Override
public void dispose() {
+ if (diagramDescListener != null) {
+ diagramDescListener.dispose();
+ diagramDescListener = null;
+ }
if(ctx != null) {
if (ownsContext)
ctx.dispose();