From 052c827e209230bd428e74180caed3620280a31f Mon Sep 17 00:00:00 2001 From: Jussi Koskela Date: Wed, 24 Jun 2020 15:33:13 +0300 Subject: [PATCH] Bringing layers back to life Change-Id: I72ff3880f41994c4760d3cccfd9368883f85e6af --- bundles/org.simantics.diagram/plugin.xml | 6 +- .../diagram/adapter/ConnectionRequest.java | 13 +- .../diagram/adapter/ConnectionRequest2.java | 11 +- .../adapter/DefinedElementFactory.java | 3 +- .../diagram/adapter/ElementFactoryUtil.java | 4 +- .../diagram/adapter/FlagClassFactory.java | 9 + .../adapter/GraphToDiagramSynchronizer.java | 13 +- .../RouteGraphConnectionClassFactory.java | 9 + .../diagram/content/ConnectionUtil.java | 2 + .../simantics/diagram/layer/LayersView.java | 9 + .../diagram/layer/messages.properties | 2 +- .../graph/layer/GraphLayer.java | 51 +++- .../graph/layer/GraphLayerManager.java | 126 +++++---- .../graph/layer/GraphLayerUtil.java | 19 +- .../graph/layer/LayersSpec.java | 41 +++ .../diagram/participant/ElementPainter.java | 90 +++---- .../g2d/diagram/participant/Selection.java | 26 +- .../g2d/element/handler/ElementLayers.java | 2 + .../handler/impl/SimpleElementLayers.java | 32 ++- .../simantics/g2d/elementclass/FlagClass.java | 3 +- .../RouteGraphConnectionClass.java | 3 +- .../src/org/simantics/g2d/layers/ILayers.java | 6 + .../simantics/g2d/layers/ILayersEditor.java | 6 +- .../simantics/g2d/layers/SimpleLayers.java | 72 ++++- .../diagram/SetFocusabilityContribution.java | 3 +- .../diagram/monitor/MonitorClassFactory2.java | 10 + .../ui/diagramEditor/DiagramLayersPage.java | 245 ++++++++++-------- .../ui/diagramEditor/DiagramViewer.java | 2 +- .../modeling/ui/diagramEditor/Messages.java | 4 - .../ui/diagramEditor/PlainDiagramViewer.java | 8 + .../ui/diagramEditor/SheetViewer.java | 2 +- .../ui/diagramEditor/WikiDiagramViewer.java | 2 +- .../ui/diagramEditor/e4/DiagramViewer.java | 3 +- .../ui/diagramEditor/messages.properties | 20 +- .../ui/symbolEditor/SymbolViewer.java | 9 +- .../simantics-desktop.product | 20 +- 36 files changed, 587 insertions(+), 299 deletions(-) create mode 100644 bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/LayersSpec.java diff --git a/bundles/org.simantics.diagram/plugin.xml b/bundles/org.simantics.diagram/plugin.xml index b6a591201..fca5d19c1 100644 --- a/bundles/org.simantics.diagram/plugin.xml +++ b/bundles/org.simantics.diagram/plugin.xml @@ -45,18 +45,18 @@ --> - + { } @Override - public void execute(AsyncReadGraph graph, final ElementClass ec) { - + public void execute(AsyncReadGraph graph, ElementClass mutableClazz) { + + List substitutes = diagram.getDiagramClass().getItemsByClass(SubstituteElementClass.class); + for (SubstituteElementClass subs : substitutes) { + mutableClazz = subs.substitute(diagram, mutableClazz); + } + final ElementClass ec = mutableClazz; + graph.asyncRequest(new SpawnRequest(canvas, ec, data), new TransientCacheAsyncListener() { @Override diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ConnectionRequest2.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ConnectionRequest2.java index 36a01b54c..a19bc3dad 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ConnectionRequest2.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ConnectionRequest2.java @@ -11,6 +11,8 @@ *******************************************************************************/ package org.simantics.diagram.adapter; +import java.util.List; + import org.simantics.db.AsyncReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.primitiverequest.Adapter; @@ -19,6 +21,7 @@ import org.simantics.db.procedure.AsyncProcedure; import org.simantics.diagram.synchronization.ErrorHandler; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.diagram.handler.SubstituteElementClass; import org.simantics.g2d.element.ElementClass; import org.simantics.g2d.element.IElement; import org.simantics.scl.runtime.tuple.Tuple3; @@ -75,7 +78,13 @@ public class ConnectionRequest2 extends BaseRequest2 { } @Override - public void execute(AsyncReadGraph graph, final ElementClass ec) { + public void execute(AsyncReadGraph graph, ElementClass mutableClazz) { + + List substitutes = diagram.getDiagramClass().getItemsByClass(SubstituteElementClass.class); + for (SubstituteElementClass subs : substitutes) { + mutableClazz = subs.substitute(diagram, mutableClazz); + } + final ElementClass ec = mutableClazz; graph.asyncRequest(new SpawnRequest(canvas, ec, data), new TransientCacheAsyncListener() { diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DefinedElementFactory.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DefinedElementFactory.java index 10855496b..d58f383e2 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DefinedElementFactory.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DefinedElementFactory.java @@ -270,7 +270,8 @@ public class DefinedElementFactory extends ElementFactoryAdapter { ElementFactoryUtil.readParameters(graph, element, e); - GuardedAsyncProcedureWrapper guard = new GuardedAsyncProcedureWrapper(procedure, 1); + GuardedAsyncProcedureWrapper guard = new GuardedAsyncProcedureWrapper(procedure, 2); + ElementFactoryUtil.loadLayersForElement(graph, diagram, e, element, guard); ElementFactoryUtil.readTransform(graph, element, e, guard); // graph.asyncRequest(new SafeName(resource), new ProcedureAdapter() { diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ElementFactoryUtil.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ElementFactoryUtil.java index f05667cb6..e8163cd9c 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ElementFactoryUtil.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ElementFactoryUtil.java @@ -32,7 +32,7 @@ import org.simantics.g2d.diagram.DiagramHints; import org.simantics.g2d.diagram.IDiagram; import org.simantics.g2d.element.ElementUtils; import org.simantics.g2d.element.IElement; -import org.simantics.g2d.layers.ILayersEditor; +import org.simantics.g2d.layers.ILayers; import org.simantics.utils.datastructures.hints.IHintContext.Key; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -118,7 +118,7 @@ public class ElementFactoryUtil { public static void loadLayersForElement(AsyncReadGraph graph, GraphLayerManager layerManager, IDiagram diagram, IElement e, Resource element, AsyncProcedure callback) { - final ILayersEditor layers = diagram.getHint(DiagramHints.KEY_LAYERS_EDITOR); + final ILayers layers = diagram.getHint(DiagramHints.KEY_LAYERS); if (layers != null) layerManager.loadLayersForElement(graph, layers, e, element, callback); else diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/FlagClassFactory.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/FlagClassFactory.java index 56c2ceef4..94acc5116 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/FlagClassFactory.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/FlagClassFactory.java @@ -33,6 +33,7 @@ import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.WriteGraph; import org.simantics.db.common.procedure.adapter.TransientCacheListener; +import org.simantics.db.common.procedure.guarded.GuardedAsyncProcedureWrapper; import org.simantics.db.common.request.ResourceRead; import org.simantics.db.common.request.TernaryRead; import org.simantics.db.common.request.WriteRequest; @@ -103,6 +104,14 @@ public class FlagClassFactory extends SyncElementFactory { procedure.execute(graph, createFlagClass(DIA.Flag, DIA.Flag_Terminal)); } + @Override + public void load(AsyncReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, + final Resource elementResource, final IElement element, final AsyncProcedure procedure) { + GuardedAsyncProcedureWrapper guard = new GuardedAsyncProcedureWrapper(procedure, 2); + super.load(graph, canvas, diagram, elementResource, element, guard); + ElementFactoryUtil.loadLayersForElement(graph, diagram, element, elementResource, guard); + } + @Override public void load(ReadGraph g, ICanvasContext canvas, IDiagram diagram, Resource flag, IElement e) throws DatabaseException { Layer0 l0 = g.getService(Layer0.class); diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GraphToDiagramSynchronizer.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GraphToDiagramSynchronizer.java index 37471eb3a..14b9f148a 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GraphToDiagramSynchronizer.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GraphToDiagramSynchronizer.java @@ -129,6 +129,7 @@ import org.simantics.g2d.element.IElementClassProvider; import org.simantics.g2d.element.handler.EdgeVisuals.EdgeEnd; import org.simantics.g2d.element.handler.ElementHandler; import org.simantics.g2d.element.handler.ElementLayerListener; +import org.simantics.g2d.element.handler.ElementLayers; import org.simantics.g2d.element.handler.TerminalTopology; import org.simantics.g2d.element.impl.Element; import org.simantics.g2d.layers.ILayer; @@ -768,16 +769,14 @@ public class GraphToDiagramSynchronizer extends AbstractDisposable implements ID // If the element class is our own, there's no point in creating // a copy of it. - if (ec.contains(elementLayerListener)) - return ec; + /*if (ec.contains(elementLayerListener)) + return ec;*/ List all = ec.getAll(); - List result = new ArrayList(all.size()); + List result = new ArrayList(all); for (ElementHandler eh : all) { - if (eh instanceof ElementLayerListenerImpl) + if (eh instanceof ElementLayers) result.add(elementLayerListener); - else - result.add(eh); } return ElementClass.compile(result, false).setId(ec.getId()); } @@ -1173,7 +1172,7 @@ public class GraphToDiagramSynchronizer extends AbstractDisposable implements ID * A common handler for all elements that is used to listen to changes in * element visibility and focusability on diagram layers. */ - class ElementLayerListenerImpl implements ElementLayerListener { + public class ElementLayerListenerImpl implements ElementLayerListener { private static final long serialVersionUID = -3410052116598828129L; @Override diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/RouteGraphConnectionClassFactory.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/RouteGraphConnectionClassFactory.java index 4e15608a6..82d249380 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/RouteGraphConnectionClassFactory.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/RouteGraphConnectionClassFactory.java @@ -21,6 +21,7 @@ import org.simantics.db.AsyncReadGraph; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Session; +import org.simantics.db.common.procedure.guarded.GuardedAsyncProcedureWrapper; import org.simantics.db.exception.DatabaseException; import org.simantics.db.procedure.AsyncProcedure; import org.simantics.diagram.adapter.RouteGraphUtils.BackendConnection; @@ -89,6 +90,14 @@ public class RouteGraphConnectionClassFactory extends SyncElementFactory { return DIA.Connection; } + @Override + public void load(AsyncReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, + final Resource elementResource, final IElement element, final AsyncProcedure procedure) { + GuardedAsyncProcedureWrapper guard = new GuardedAsyncProcedureWrapper(procedure, 2); + super.load(graph, canvas, diagram, elementResource, element, guard); + ElementFactoryUtil.loadLayersForElement(graph, diagram, element, elementResource, guard); + } + @Override public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, final Resource connection, IElement element) throws DatabaseException { diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/content/ConnectionUtil.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/content/ConnectionUtil.java index 3bcb26de7..c96b8fb94 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/content/ConnectionUtil.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/content/ConnectionUtil.java @@ -42,6 +42,7 @@ import org.simantics.diagram.connection.ConnectionSegmentEnd; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.diagram.synchronization.graph.BasicResources; import org.simantics.diagram.synchronization.graph.DiagramGraphUtil; +import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil; import org.simantics.g2d.connection.handler.ConnectionHandler; import org.simantics.g2d.diagram.handler.PickRequest.PickFilter; import org.simantics.g2d.diagram.handler.Topology.Terminal; @@ -117,6 +118,7 @@ public final class ConnectionUtil { // often it is visually the expected result. OrderedSetUtils.addFirst(g, composite, connection); g.claim(composite, br.L0.ConsistsOf, br.L0.PartOf, connection); + GraphLayerUtil.addToVisibleLayers(g, connection, composite); return connection; } diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/layer/LayersView.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/layer/LayersView.java index f7a9ccb1f..32a8d0f72 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/layer/LayersView.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/layer/LayersView.java @@ -169,6 +169,15 @@ public class LayersView extends PageBookView implements ISelectionProvider, ISel public void partBroughtToTop(IWorkbenchPart part) { partActivated(part); } + + // Dirty hack to ensure that a new Page will be created if the previous one has been disposed due to disposal of AWTChassis + protected PageRec getPageRec(IWorkbenchPart part) { + PageRec rec = super.getPageRec(part); + if (rec == null || rec.page == null || rec.page.getControl() == null || rec.page.getControl().isDisposed()) + return null; + else + return rec; + } /* (non-Javadoc) * Method declared on ISelectionProvider. diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/layer/messages.properties b/bundles/org.simantics.diagram/src/org/simantics/diagram/layer/messages.properties index 32d02a717..f2600a973 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/layer/messages.properties +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/layer/messages.properties @@ -9,7 +9,7 @@ # Contributors: # VTT Technical Research Centre of Finland - initial API and implementation ############################################################################### -LayersView_noLayers=No roles available. +LayersView_noLayers=No layers available. LayersView_noProfiles=No profiles available. GroupsView_noGroups=No groups available. StylesView_noStyles=No styles available. diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayer.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayer.java index 33df689be..2f25b84a9 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayer.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayer.java @@ -32,16 +32,19 @@ public class GraphLayer { private final Resource layer; + private boolean active; + private final Map tags; - public GraphLayer(String name, Resource layer, Map tags) { + public GraphLayer(String name, Resource layer, Map tags, boolean active) { this.name = name; this.layer = layer; this.tags = tags; + this.active = active; } public GraphLayer withName(String name) { - return new GraphLayer(name, layer, tags); + return new GraphLayer(name, layer, tags, active); } public String getName() { @@ -59,6 +62,10 @@ public class GraphLayer { public Resource getFocusable() { return tags.get(PROP_FOCUSABLE); } + + public boolean isActive() { + return active; + } public ILayer getILayer() { return new SimpleLayer(name); @@ -73,4 +80,44 @@ public class GraphLayer { consumer.accept(r); } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (active ? 1231 : 1237); + result = prime * result + ((layer == null) ? 0 : layer.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((tags == null) ? 0 : tags.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + GraphLayer other = (GraphLayer) obj; + if (active != other.active) + return false; + if (layer == null) { + if (other.layer != null) + return false; + } else if (!layer.equals(other.layer)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (tags == null) { + if (other.tags != null) + return false; + } else if (!tags.equals(other.tags)) + return false; + return true; + } + } \ No newline at end of file diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerManager.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerManager.java index e92ce1b41..79e79a217 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerManager.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerManager.java @@ -25,10 +25,12 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.procedure.adapter.AsyncProcedureAdapter; +import org.simantics.db.common.request.ResourceRead; import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.ServiceException; import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.procedure.Listener; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.diagram.synchronization.IModificationQueue; import org.simantics.diagram.synchronization.ModificationAdapter; @@ -131,6 +133,8 @@ public class GraphLayerManager { */ LayerListener layerListener = new LayerListener(); + boolean disposed = false; + public GraphLayerManager(ReadGraph graph, IModificationQueue modificationQueue, Resource diagram) { this.modificationQueue = modificationQueue; this.diagram = diagram; @@ -145,6 +149,7 @@ public class GraphLayerManager { } } layers.clear(); + disposed = true; } Resource getDiagramResource() { @@ -295,69 +300,96 @@ public class GraphLayerManager { public ILayersEditor loadLayers(IDiagram diagram, ReadGraph g, Resource diagramResource) throws DatabaseException { - SimpleLayers result = new SimpleLayers(); - ConcurrentMap newLayers = new ConcurrentHashMap(); - + layerEditor = new SimpleLayers(); + layerEditor.addLayerEditorListener(layerListener); + String[] fixed = diagram.getHint(DiagramHints.KEY_FIXED_LAYERS); - if (fixed != null) { -// for (String name : fixed) { -// SimpleLayer l = new SimpleLayer(name); -// result.addLayer(l); -// result.activate(l); -// } + g.syncRequest(new ResourceRead(diagramResource) { - // We need to put GraphLayer to newLayers so... - for (Resource layer : g.getObjects(diagramResource, dia.HasLayer)) { - IGraphLayerUtil layerUtil = g.adapt(g.getSingleObject(layer, Layer0.getInstance(g).InstanceOf), IGraphLayerUtil.class); - - GraphLayer gl = layerUtil.loadLayer(g, layer); - for (String name : fixed) { - if (name.equals(gl.getName())) { - ILayer l = gl.getILayer(); - newLayers.put(gl.getName(), gl); - result.addLayer(l); - result.activate(l); - } + @Override + public LayersSpec perform(ReadGraph g) throws DatabaseException { + Collection gls = new ArrayList<>(); + for (Resource layer : g.getObjects(resource, dia.HasLayer)) { + IGraphLayerUtil layerUtil = g.adapt(g.getSingleObject(layer, Layer0.getInstance(g).InstanceOf), IGraphLayerUtil.class); + GraphLayer gl = layerUtil.loadLayer(g, layer); + gls.add(gl); } + return new LayersSpec(gls); } + + }, new Listener() { - } else { + @Override + public void execute(LayersSpec layersSpec) { + ConcurrentMap newLayers = new ConcurrentHashMap(); + Set visibleLayers = new HashSet<>(); + Set allLayers = new HashSet<>(); + + if (fixed != null) { + for (GraphLayer gl : layersSpec.getGraphLayers()) { + for (String name : fixed) { + if (name.equals(gl.getName())) { + ILayer l = gl.getILayer(); + newLayers.put(gl.getName(), gl); + allLayers.add(l); + visibleLayers.add(l); + } + } + } + + } else { - if (DEBUG_LAYERS) - System.out.println("Loading layers"); + if (DEBUG_LAYERS) + System.out.println("Loading layers"); + + for (GraphLayer gl : layersSpec.getGraphLayers()) { + ILayer l = gl.getILayer(); - for (Resource layer : g.getObjects(diagramResource, dia.HasLayer)) { - IGraphLayerUtil layerUtil = g.adapt(g.getSingleObject(layer, Layer0.getInstance(g).InstanceOf), IGraphLayerUtil.class); - GraphLayer gl = layerUtil.loadLayer(g, layer); - ILayer l = gl.getILayer(); + newLayers.put(gl.getName(), gl); + + if (DEBUG_LAYERS) + System.out.println(" Loaded " + (gl.isActive() ? "active" : "inactive") + " layer '" + gl.getName() + "'"); - newLayers.put(gl.getName(), gl); - result.addLayer(l); + if (l instanceof IEditableLayer) + ((IEditableLayer) l).addLayerListener(layerListener); - Boolean active = g.getPossibleRelatedValue(layer, dia.IsActive); - if (active == null) - active = Boolean.FALSE; + allLayers.add(l); + if (gl.isActive()) + visibleLayers.add(l); + + } + } + // Show all and focus all by default if there are no layers + + + if (newLayers.isEmpty()) { + layerEditor.setIgnoreVisibilitySettings(true); + layerEditor.setIgnoreFocusSettings(true); + } if (DEBUG_LAYERS) - System.out.println(" Loaded " + (active ? "active" : "inactive") + " layer '" + gl.getName() + "'"); + System.out.println("Loaded " + newLayers.size() + " layers"); - if (l instanceof IEditableLayer) - ((IEditableLayer) l).addLayerListener(layerListener); - if (active) - result.activate(l); + layerEditor.update(allLayers, visibleLayers); + + layers = newLayers; } - if (DEBUG_LAYERS) - System.out.println("Loaded " + newLayers.size() + " layers"); + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } - } + @Override + public boolean isDisposed() { + return disposed; + } + + }); - this.layers = newLayers; - this.layerEditor = result; - this.layerEditor.addListener(layerListener); - return result; + return layerEditor; } public void loadLayersForElement(ReadGraph graph, ILayersEditor layersEditor, IElement e, Resource element) @@ -406,7 +438,7 @@ public class GraphLayerManager { * many times depending on how many errors occur during layer loading * @throws DatabaseException */ - public void loadLayersForElement(AsyncReadGraph graph, ILayersEditor layersEditor, final IElement e, + public void loadLayersForElement(AsyncReadGraph graph, ILayers layers2, final IElement e, Resource element, final AsyncProcedure callback) { if (DEBUG_LAYERS) System.out.println("Loading layers for element " + element + " - " + e); @@ -417,7 +449,7 @@ public class GraphLayerManager { // NOTE: must not set layer hints into element until the layer sets have // been properly loaded. - Set allLayers = layersEditor.getLayers(); + Set allLayers = layers2.getLayers(); if (allLayers.isEmpty()) { e.setHint(ElementHints.KEY_VISIBLE_LAYERS, visible); e.setHint(ElementHints.KEY_FOCUS_LAYERS, focusable); diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerUtil.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerUtil.java index 370345f4f..43b7fe117 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerUtil.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerUtil.java @@ -59,7 +59,7 @@ public final class GraphLayerUtil implements IGraphLayerUtil { properties.put(GraphLayer.PROP_FOCUSABLE, focusableTag); properties.put(GraphLayer.PROP_VISIBLE, visibleTag); - return new GraphLayer(layerName, layer, properties); + return new GraphLayer(layerName, layer, properties, active); } public static Resource newTag(WriteGraph graph, Layer0 L0, Resource baseTag) throws DatabaseException { @@ -80,12 +80,25 @@ public final class GraphLayerUtil implements IGraphLayerUtil { String name = graph.getRelatedValue(layer, L0.HasName); Resource visible = graph.getSingleObject(layer, DIA.HasVisibleTag); Resource focusable = graph.getSingleObject(layer, DIA.HasFocusableTag); - + boolean active = graph.getRelatedValue(layer, DIA.IsActive); Map properties = new HashMap<>(); properties.put(GraphLayer.PROP_FOCUSABLE, focusable); properties.put(GraphLayer.PROP_VISIBLE, visible); - return new GraphLayer(name, layer, properties); + return new GraphLayer(name, layer, properties, active); + } + + public static void addToVisibleLayers(WriteGraph graph, Resource element, Resource diagram) throws DatabaseException { + DiagramResource DIA = DiagramResource.getInstance(graph); + for (Resource layer : graph.getObjects(diagram, DIA.HasLayer)) { + boolean active = graph.getRelatedValue(layer, DIA.IsActive); + if (active) { + Resource visibleTag = graph.getSingleObject(layer, DIA.HasVisibleTag); + Resource focusableTag = graph.getSingleObject(layer, DIA.HasFocusableTag); + graph.claim(element, visibleTag, element); + graph.claim(element, focusableTag, element); + } + } } } diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/LayersSpec.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/LayersSpec.java new file mode 100644 index 000000000..42bd7cca6 --- /dev/null +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/LayersSpec.java @@ -0,0 +1,41 @@ +package org.simantics.diagram.synchronization.graph.layer; + +import java.util.Collection; + +public class LayersSpec { + private Collection graphLayers; + + public LayersSpec(Collection gls) { + this.graphLayers = gls; + } + + public Collection getGraphLayers() { + return graphLayers; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((graphLayers == null) ? 0 : graphLayers.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + LayersSpec other = (LayersSpec) obj; + if (graphLayers == null) { + if (other.graphLayers != null) + return false; + } else if (!graphLayers.equals(other.graphLayers)) + return false; + return true; + } + +} diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementPainter.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementPainter.java index 9134c1729..a8fee9582 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementPainter.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementPainter.java @@ -61,6 +61,7 @@ import org.simantics.g2d.element.handler.BendsHandler; import org.simantics.g2d.element.handler.Children; import org.simantics.g2d.element.handler.Children.ChildEvent; import org.simantics.g2d.element.handler.Children.ChildListener; +import org.simantics.g2d.element.handler.ElementLayers; import org.simantics.g2d.element.handler.FillColor; import org.simantics.g2d.element.handler.Outline; import org.simantics.g2d.element.handler.OutlineColorSpec; @@ -71,9 +72,9 @@ import org.simantics.g2d.element.handler.SelectionSpecification; import org.simantics.g2d.element.handler.StrokeSpec; import org.simantics.g2d.element.handler.TerminalTopology; import org.simantics.g2d.element.handler.Transform; -import org.simantics.g2d.layers.ILayer; +import org.simantics.g2d.layers.ILayers; +import org.simantics.g2d.layers.ILayers.ILayersListener; import org.simantics.g2d.layers.ILayersEditor; -import org.simantics.g2d.layers.ILayersEditor.ILayersEditorListener; import org.simantics.g2d.participant.TransformUtil; import org.simantics.g2d.scenegraph.SceneGraphConstants; import org.simantics.g2d.utils.ElementNodeBridge; @@ -213,9 +214,9 @@ public class ElementPainter extends AbstractDiagramParticipant implements Compos oldValue.removeKeyHintListener(Hints.KEY_DIRTY, diagramHintListener); oldValue.removeKeyHintListener(Hints.KEY_DISABLE_PAINTING, diagramHintListener); - ILayersEditor layers = oldValue.getHint(DiagramHints.KEY_LAYERS_EDITOR); + ILayers layers = oldValue.getHint(DiagramHints.KEY_LAYERS); if (layers != null) { - layers.removeListener(layersListener); + layers.removeLayersListener(layersListener); } for (TransactionContext tc : oldValue.getDiagramClass().getItemsByClass(TransactionContext.class)) { @@ -237,9 +238,9 @@ public class ElementPainter extends AbstractDiagramParticipant implements Compos newValue.addKeyHintListener(Hints.KEY_DISABLE_PAINTING, diagramHintListener); newValue.addKeyHintListener(Hints.KEY_DIRTY, diagramHintListener); - ILayersEditor layers = newValue.getHint(DiagramHints.KEY_LAYERS_EDITOR); + ILayers layers = newValue.getHint(DiagramHints.KEY_LAYERS); if (layers != null) { - layers.addListener(layersListener); + layers.addLayersListener(layersListener); } for (TransactionContext tc : newValue.getDiagramClass().getItemsByClass(TransactionContext.class)) { @@ -302,41 +303,21 @@ public class ElementPainter extends AbstractDiagramParticipant implements Compos // Layer configuration change listening and reaction logic // ------------------------------------------------------------------------ - ILayersEditorListener layersListener = new ILayersEditorListener() { - private void layersChanged() { + ILayersListener layersListener = new ILayersListener() { + @Override + public void changed() { Object task = BEGIN("EP.layersChanged"); - // Update visibility/focusability for each node only, do not reinitialize the graphics. + ICanvasContext ctx = getContext(); + if(ctx != null) { + G2DSceneGraph sg = ctx.getSceneGraph(); + if(sg != null) { + ILayersEditor layers = diagram.getHint(DiagramHints.KEY_LAYERS); + sg.setGlobalProperty(G2DSceneGraph.IGNORE_FOCUS, layers.getIgnoreFocusSettings()); + } + } updateAllVisibility(); END(task); } - @Override - public void layerRemoved(ILayer layer) { - layersChanged(); - } - @Override - public void layerDeactivated(ILayer layer) { - layersChanged(); - } - @Override - public void layerAdded(ILayer layer) { - layersChanged(); - } - @Override - public void layerActivated(ILayer layer) { - layersChanged(); - } - @Override - public void ignoreFocusChanged(boolean value) { - ICanvasContext ctx = getContext(); - if(ctx == null) return; - G2DSceneGraph sg = ctx.getSceneGraph(); - if(sg == null) return; - sg.setGlobalProperty(G2DSceneGraph.IGNORE_FOCUS, value); - } - @Override - public void ignoreVisibilityChanged(boolean value) { - layersChanged(); - } }; protected void updateAllVisibility() { @@ -405,11 +386,17 @@ public class ElementPainter extends AbstractDiagramParticipant implements Compos } } else if (key == ElementHints.KEY_FOCUS_LAYERS || key == ElementHints.KEY_VISIBLE_LAYERS) { if (sender instanceof IElement) { - assert getContext().getThreadAccess().currentThreadAccess(); - IElement e = (IElement) sender; - Object task = BEGIN("layers changed: " + e); - update(e); - END(task); + getContext().getThreadAccess().asyncExec(new Runnable() { + + @Override + public void run() { + assert getContext().getThreadAccess().currentThreadAccess(); + IElement e = (IElement) sender; + Object task = BEGIN("layers changed: " + e); + update(e); + END(task); + } + }); } } } @@ -775,14 +762,6 @@ public class ElementPainter extends AbstractDiagramParticipant implements Compos if (ElementUtils.isHidden(e)) return null; -// ElementClass ec = e.getElementClass(); -// ILayers layers = diagram.getHint(DiagramHints.KEY_LAYERS); -// if (layers != null && !layers.getIgnoreVisibilitySettings()) { -// ElementLayers el = ec.getAtMostOneItemOfClass(ElementLayers.class); -// if (el != null && !el.isVisible(e, layers)) { -// return null; -// } -// } // Update the node scene graph through SceneGraph handlers. List nodeHandlers = e.getElementClass().getItemsByClass(SceneGraph.class); @@ -797,7 +776,16 @@ public class ElementPainter extends AbstractDiagramParticipant implements Compos e.setHint(elementSgNodeKey, holder); } holder.setComposite(composite); - holder.setVisible(true); + boolean visible = true; + ElementClass ec = e.getElementClass(); + ILayers layers = diagram.getHint(DiagramHints.KEY_LAYERS); + if (layers != null && !layers.getIgnoreVisibilitySettings()) { + ElementLayers el = ec.getAtMostOneItemOfClass(ElementLayers.class); + if (el != null && !el.isVisible(e, layers)) { + visible = false; + } + } + holder.setVisible(visible); for (SceneGraph n : nodeHandlers) { n.init(e, holder); diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/Selection.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/Selection.java index c7aa7872d..ebdbdfa74 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/Selection.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/Selection.java @@ -16,14 +16,18 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant; import org.simantics.g2d.diagram.DiagramHints; import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.element.ElementClass; import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.ElementLayers; +import org.simantics.g2d.layers.ILayers; import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler; import org.simantics.scenegraph.g2d.events.command.CommandEvent; import org.simantics.scenegraph.g2d.events.command.Commands; @@ -62,7 +66,7 @@ public class Selection extends AbstractCanvasParticipant { if (e.command.equals( Commands.SELECT_ALL )) { IDiagram d = getHint( DiagramHints.KEY_DIAGRAM ); if (d==null) return true; - addAll(0, d.getElements()); + addAll(0, filterSelectionByLayers(d, d.getElements())); return true; } if (e.command.equals( Commands.INVERT_SELECTION )) { @@ -71,12 +75,28 @@ public class Selection extends AbstractCanvasParticipant { Set current = getSelection(0); Set inverted = new HashSet(d.getElements()); inverted.removeAll(current); - setSelection(0, inverted); + setSelection(0, filterSelectionByLayers(d, inverted)); return true; } return false; } + private static Collection filterSelectionByLayers(IDiagram diagram, Collection elements) { + ILayers layers = diagram.getHint(DiagramHints.KEY_LAYERS); + if (layers != null && !layers.getIgnoreFocusSettings()) { + List filteredElements = new ArrayList(); + for (IElement element : elements) { + ElementClass ec = element.getElementClass(); + ElementLayers el = ec.getAtMostOneItemOfClass(ElementLayers.class); + if (el == null || el.isFocusable(element, layers)) { + filteredElements.add(element); + } + } + return filteredElements; + } else { + return elements; + } + } /** * Get selection diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/ElementLayers.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/ElementLayers.java index 650bc556f..9edf28d41 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/ElementLayers.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/ElementLayers.java @@ -11,6 +11,8 @@ *******************************************************************************/ package org.simantics.g2d.element.handler; +import java.util.Collection; + import org.simantics.g2d.element.IElement; import org.simantics.g2d.layers.ILayer; import org.simantics.g2d.layers.ILayers; diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/SimpleElementLayers.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/SimpleElementLayers.java index e7d3dd4c4..d62e85b80 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/SimpleElementLayers.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/SimpleElementLayers.java @@ -33,10 +33,10 @@ public class SimpleElementLayers implements ElementLayers { @Override public boolean isVisible(IElement e, ILayers layers) { - assert(e != null); - assert(layers != null); + assert (e != null); + assert (layers != null); - Set elementLayers = (Set)e.getHint(ElementHints.KEY_VISIBLE_LAYERS); + Set elementLayers = (Set) e.getHint(ElementHints.KEY_VISIBLE_LAYERS); if (elementLayers == null) return true; @@ -47,7 +47,7 @@ public class SimpleElementLayers implements ElementLayers { @Override public boolean isVisible(IElement e, ILayer layer) { - Set elementLayers = (Set)e.getHint(ElementHints.KEY_VISIBLE_LAYERS); + Set elementLayers = (Set) e.getHint(ElementHints.KEY_VISIBLE_LAYERS); if (elementLayers == null) return true; @@ -62,10 +62,10 @@ public class SimpleElementLayers implements ElementLayers { @Override public boolean isFocusable(IElement e, ILayers layers) { - assert(e != null); - assert(layers != null); + assert (e != null); + assert (layers != null); - Set elementLayers = (Set)e.getHint(ElementHints.KEY_FOCUS_LAYERS); + Set elementLayers = (Set) e.getHint(ElementHints.KEY_FOCUS_LAYERS); if (elementLayers == null) return true; @@ -76,7 +76,7 @@ public class SimpleElementLayers implements ElementLayers { @Override public boolean isFocusable(IElement e, ILayer layer) { - Set elementLayers = (Set)e.getHint(ElementHints.KEY_FOCUS_LAYERS); + Set elementLayers = (Set) e.getHint(ElementHints.KEY_FOCUS_LAYERS); if (elementLayers == null) return true; @@ -87,12 +87,14 @@ public class SimpleElementLayers implements ElementLayers { @Override public boolean setVisibility(IElement e, ILayer layer, boolean value) { - Set elementLayers = (Set)e.getHint(ElementHints.KEY_VISIBLE_LAYERS); + Set elementLayers = (Set) e.getHint(ElementHints.KEY_VISIBLE_LAYERS); if (elementLayers == null) return false; boolean result; - if (value) result = elementLayers.add(layer); - else result = elementLayers.remove(layer); + if (value) + result = elementLayers.add(layer); + else + result = elementLayers.remove(layer); if (result) { for (ElementLayerListener ell : e.getElementClass().getItemsByClass(ElementLayerListener.class)) { @@ -106,12 +108,14 @@ public class SimpleElementLayers implements ElementLayers { @Override public boolean setFocusability(IElement e, ILayer layer, boolean value) { - Set elementLayers = (Set)e.getHint(ElementHints.KEY_FOCUS_LAYERS); + Set elementLayers = (Set) e.getHint(ElementHints.KEY_FOCUS_LAYERS); if (elementLayers == null) return false; boolean result; - if(value) result = elementLayers.add(layer); - else result = elementLayers.remove(layer); + if (value) + result = elementLayers.add(layer); + else + result = elementLayers.remove(layer); if (result) { for (ElementLayerListener ell : e.getElementClass().getItemsByClass(ElementLayerListener.class)) { diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/FlagClass.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/FlagClass.java index 7c60894bc..10dd267d6 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/FlagClass.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/FlagClass.java @@ -311,7 +311,8 @@ public class FlagClass { TextImpl.INSTANCE, FlagTerminalTopology.DEFAULT, FlagSceneGraph.INSTANCE, - DEFAULT_STATIC_SYMBOL + DEFAULT_STATIC_SYMBOL, + SimpleElementLayers.INSTANCE ).setId(FlagClass.class.getSimpleName()); public static ElementClass create(Terminal terminal) { diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/RouteGraphConnectionClass.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/RouteGraphConnectionClass.java index 5aa435920..8da74b64c 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/RouteGraphConnectionClass.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/RouteGraphConnectionClass.java @@ -35,6 +35,7 @@ import org.simantics.g2d.element.handler.SelectionOutline; import org.simantics.g2d.element.handler.impl.ConfigurableEdgeVisuals; import org.simantics.g2d.element.handler.impl.ConnectionSelectionOutline; import org.simantics.g2d.element.handler.impl.FillColorImpl; +import org.simantics.g2d.element.handler.impl.SimpleElementLayers; import org.simantics.g2d.element.handler.impl.TextImpl; import org.simantics.g2d.elementclass.connection.EdgeClass.FixedTransform; import org.simantics.scenegraph.g2d.G2DParentNode; @@ -70,7 +71,7 @@ public class RouteGraphConnectionClass { ConnectionSelectionOutline.INSTANCE, ConnectionHandlerImpl.INSTANCE, ConnectionSceneGraph.INSTANCE, - //SimpleElementLayers.INSTANCE, + SimpleElementLayers.INSTANCE, // Exists only loading connection visuals through ConnectionVisualsLoader ConfigurableEdgeVisuals.DEFAULT, diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/layers/ILayers.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/layers/ILayers.java index 618f15538..72f25e7cb 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/layers/ILayers.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/layers/ILayers.java @@ -25,4 +25,10 @@ public interface ILayers { boolean getIgnoreFocusSettings(); boolean getIgnoreVisibilitySettings(); + void addLayersListener(ILayersListener listener); + void removeLayersListener(ILayersListener listener); + + public interface ILayersListener { + void changed(); + } } diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/layers/ILayersEditor.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/layers/ILayersEditor.java index a5c892b5b..5113ac777 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/layers/ILayersEditor.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/layers/ILayersEditor.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.simantics.g2d.layers; +import java.util.Set; /** * @author Antti Villberg @@ -33,8 +34,8 @@ public interface ILayersEditor extends ILayers { void setIgnoreFocusSettings(boolean value); void setIgnoreVisibilitySettings(boolean value); - void addListener(ILayersEditorListener listener); - void removeListener(ILayersEditorListener listener); + void addLayerEditorListener(ILayersEditorListener listener); + void removeLayerEditorListener(ILayersEditorListener listener); void addLayer(ILayer layer); void removeLayer(ILayer layer); @@ -42,4 +43,5 @@ public interface ILayersEditor extends ILayers { void activate(ILayer layer); void deactivate(ILayer layer); + void update(Set allLayers, Set visibleLayers); } diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/layers/SimpleLayers.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/layers/SimpleLayers.java index f250449a4..43c52099c 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/layers/SimpleLayers.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/layers/SimpleLayers.java @@ -17,6 +17,8 @@ import java.util.Set; import java.util.TreeSet; import java.util.concurrent.CopyOnWriteArrayList; +import org.simantics.utils.strings.AlphanumComparator; + /** * @author Antti Villberg */ @@ -25,7 +27,7 @@ public class SimpleLayers implements ILayersEditor { private static final Comparator LAYER_COMPARATOR = new Comparator() { @Override public int compare(ILayer o1, ILayer o2) { - return o1.getName().compareTo(o2.getName()); + return AlphanumComparator.COMPARATOR.compare(o1.getName(), o2.getName()); } }; @@ -35,7 +37,8 @@ public class SimpleLayers implements ILayersEditor { private Set visible = new TreeSet(LAYER_COMPARATOR); private volatile Set visibleSnapshot; - private CopyOnWriteArrayList listeners = new CopyOnWriteArrayList(); + private CopyOnWriteArrayList layerEditorListeners = new CopyOnWriteArrayList(); + private CopyOnWriteArrayList layersListeners = new CopyOnWriteArrayList(); private boolean ignoreFocusSettings = false; @@ -50,8 +53,21 @@ public class SimpleLayers implements ILayersEditor { all.add(layer); visible.add(layer); } - allSnapshot = null; - visibleSnapshot = null; + } + + @Override + public void update(Set allLayers, Set visibleLayers) { + synchronized (this) { + all.clear(); + all.addAll(allLayers); + visible.clear(); + visible.addAll(visibleLayers); + allSnapshot = null; + visibleSnapshot = null; + } + for (ILayersListener listener : layersListeners) { + listener.changed(); + } } @Override @@ -105,7 +121,10 @@ public class SimpleLayers implements ILayersEditor { synchronized (this) { visibleSnapshot = null; } - for (ILayersEditorListener listener : listeners) { + for (ILayersListener listener : layersListeners) { + listener.changed(); + } + for (ILayersEditorListener listener : layerEditorListeners) { listener.layerDeactivated(layer); } } @@ -121,7 +140,10 @@ public class SimpleLayers implements ILayersEditor { synchronized (this) { visibleSnapshot = null; } - for (ILayersEditorListener listener : listeners) { + for (ILayersListener listener : layersListeners) { + listener.changed(); + } + for (ILayersEditorListener listener : layerEditorListeners) { listener.layerActivated(layer); } } @@ -137,7 +159,10 @@ public class SimpleLayers implements ILayersEditor { synchronized (this) { allSnapshot = null; } - for (ILayersEditorListener listener : listeners) { + for (ILayersListener listener : layersListeners) { + listener.changed(); + } + for (ILayersEditorListener listener : layerEditorListeners) { listener.layerAdded(layer); } } @@ -155,20 +180,33 @@ public class SimpleLayers implements ILayersEditor { allSnapshot = null; visibleSnapshot = null; } - for (ILayersEditorListener listener : listeners) { + for (ILayersListener listener : layersListeners) { + listener.changed(); + } + for (ILayersEditorListener listener : layerEditorListeners) { listener.layerRemoved(layer); } } } @Override - public void addListener(ILayersEditorListener listener) { - listeners.add(listener); + public void addLayerEditorListener(ILayersEditorListener listener) { + layerEditorListeners.add(listener); } @Override - public void removeListener(ILayersEditorListener listener) { - listeners.remove(listener); + public void removeLayerEditorListener(ILayersEditorListener listener) { + layerEditorListeners.remove(listener); + } + + @Override + public void addLayersListener(ILayersListener listener) { + layersListeners.add(listener); + } + + @Override + public void removeLayersListener(ILayersListener listener) { + layersListeners.remove(listener); } @Override @@ -181,7 +219,10 @@ public class SimpleLayers implements ILayersEditor { boolean changed = ignoreFocusSettings != value; ignoreFocusSettings = value; if (changed) { - for (ILayersEditorListener listener : listeners) { + for (ILayersListener listener : layersListeners) { + listener.changed(); + } + for (ILayersEditorListener listener : layerEditorListeners) { listener.ignoreFocusChanged(value); } } @@ -197,7 +238,10 @@ public class SimpleLayers implements ILayersEditor { boolean changed = ignoreVisibilitySettings != value; ignoreVisibilitySettings = value; if (changed) { - for (ILayersEditorListener listener : listeners) { + for (ILayersListener listener : layersListeners) { + listener.changed(); + } + for (ILayersEditorListener listener : layerEditorListeners) { listener.ignoreVisibilityChanged(value); } } diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/SetFocusabilityContribution.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/SetFocusabilityContribution.java index 6441cdd4c..306f98890 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/SetFocusabilityContribution.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/SetFocusabilityContribution.java @@ -14,6 +14,7 @@ import org.simantics.db.ReadGraph; import org.simantics.db.exception.DatabaseException; import org.simantics.g2d.diagram.DiagramHints; import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.layers.ILayers; import org.simantics.g2d.layers.ILayersEditor; import org.simantics.modeling.ui.Activator; import org.simantics.modeling.ui.diagramEditor.DiagramEditor; @@ -54,7 +55,7 @@ public class SetFocusabilityContribution extends DynamicMenuContribution impleme IDiagram diagram = (IDiagram) editor.getAdapter(IDiagram.class); if (diagram == null) return NO_OBJECTS; - ILayersEditor le = diagram.getHint(DiagramHints.KEY_LAYERS_EDITOR); + ILayers le = diagram.getHint(DiagramHints.KEY_LAYERS); if (le == null) return NO_OBJECTS; return new Object[] { le, le.getIgnoreFocusSettings() }; diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/monitor/MonitorClassFactory2.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/monitor/MonitorClassFactory2.java index 75d3050b9..ab9eb2f94 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/monitor/MonitorClassFactory2.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/monitor/MonitorClassFactory2.java @@ -24,12 +24,14 @@ import org.simantics.db.AsyncReadGraph; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Session; +import org.simantics.db.common.procedure.guarded.GuardedAsyncProcedureWrapper; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.util.EvaluatingListener; import org.simantics.db.layer0.util.EvaluatingListener.Evaluation; import org.simantics.db.layer0.variable.RVI; import org.simantics.db.layer0.variable.Variables; import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.diagram.adapter.ElementFactoryUtil; import org.simantics.diagram.adapter.SyncElementFactory; import org.simantics.diagram.content.ConnectionUtil; import org.simantics.diagram.elements.MonitorClass; @@ -94,6 +96,14 @@ public class MonitorClassFactory2 extends SyncElementFactory { procedure.execute(graph, createMonitorClass(elementType)); } + @Override + public void load(AsyncReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, + final Resource elementResource, final IElement element, final AsyncProcedure procedure) { + GuardedAsyncProcedureWrapper guard = new GuardedAsyncProcedureWrapper(procedure, 2); + super.load(graph, canvas, diagram, elementResource, element, guard); + ElementFactoryUtil.loadLayersForElement(graph, diagram, element, elementResource, guard); + } + @Override public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException { if (!graph.hasStatement(element)) diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramLayersPage.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramLayersPage.java index 895c4bfa2..87e18ed8e 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramLayersPage.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramLayersPage.java @@ -61,36 +61,36 @@ import org.simantics.g2d.element.handler.ElementLayers; import org.simantics.g2d.layers.IEditableLayer; import org.simantics.g2d.layers.ILayer; import org.simantics.g2d.layers.ILayers; +import org.simantics.g2d.layers.ILayers.ILayersListener; import org.simantics.g2d.layers.ILayersEditor; import org.simantics.g2d.layers.SimpleLayer; -import org.simantics.g2d.layers.ILayersEditor.ILayersEditorListener; import org.simantics.utils.datastructures.Arrays; +import org.simantics.utils.datastructures.disposable.IDisposable; +import org.simantics.utils.datastructures.disposable.IDisposeListener; import org.simantics.utils.datastructures.hints.HintListenerAdapter; +import org.simantics.utils.datastructures.hints.IHintContext.Key; import org.simantics.utils.datastructures.hints.IHintListener; import org.simantics.utils.datastructures.hints.IHintObservable; -import org.simantics.utils.datastructures.hints.IHintContext.Key; import org.simantics.utils.ui.ISelectionUtils; public class DiagramLayersPage extends Page implements ILayersViewPage { - private static final String TEXT_APPLY_FOCUS_SETTINGS = Messages.DiagramLayersPage_FocusActive; - private static final String TOOLTIP_APPLY_FOCUS_SETTINGS = Messages.DiagramLayersPage_FocusActiveTT; private static final String TEXT_IGNORE_FOCUS_SETTINGS = Messages.DiagramLayersPage_FocusAll; private static final String TOOLTIP_IGNORE_FOCUS_SETTINGS = Messages.DiagramLayersPage_FocusAllTT; - private static final String TEXT_APPLY_VISIBILITY_SETTINGS = Messages.DiagramLayersPage_ShowActive; - private static final String TOOLTIP_APPLY_VISIBILITY_SETTINGS = Messages.DiagramLayersPage_ShowActiveTT; private static final String TEXT_IGNORE_VISIBILITY_SETTINGS = Messages.DiagramLayersPage_ShowAll; private static final String TOOLTIP_IGNORE_VISIBILITY_SETTINGS = Messages.DiagramLayersPage_ShowAllTT; final private ICanvasContext context; - final private IDiagram diagram; private CheckboxTreeViewer viewer; + private Button ignoreVisibilityButton; + private Button ignoreFocusButton; private Composite composite; private TreeEditor editor; private Collection elements = Collections.emptySet(); - + private ILayersEditor layers; + enum Attribute { Visible, Focusable @@ -227,82 +227,128 @@ public class DiagramLayersPage extends Page implements ILayersViewPage { } private void redraw() { - viewer.getControl().getDisplay().asyncExec(new Runnable() { + if (viewer != null) { + viewer.getControl().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + if (viewer.getControl().isDisposed()) + return; + viewer.getControl().redraw(); + } + }); + } + } + }; + + final private IDisposeListener contextDisposeListener = new IDisposeListener() { + + @Override + public void onDisposed(IDisposable sender) { + if (getControl() != null) getControl().getDisplay().asyncExec(new Runnable() { @Override public void run() { - if (viewer.getControl().isDisposed()) - return; - viewer.getControl().redraw(); + dispose(); } }); } }; - public DiagramLayersPage(IDiagram diagram, ICanvasContext context) { - - assert(diagram != null); - - this.diagram = diagram; + public DiagramLayersPage(ICanvasContext context) { this.context = context; context.getDefaultHintContext().addKeyHintListener(Selection.SELECTION0, selectionListener); + context.addDisposeListener(contextDisposeListener); } @Override public void dispose() { context.getDefaultHintContext().removeKeyHintListener(Selection.SELECTION0, selectionListener); - + context.removeDisposeListener(contextDisposeListener); + if (layers != null && layersListener != null) { + layers.removeLayersListener(layersListener); + layersListener = null; + } super.dispose(); } @Override public void createControl(Composite parent) { - - final ILayersEditor layers = diagram.getHint(DiagramHints.KEY_LAYERS_EDITOR); - layers.addListener(new ILayersEditorListener() { - + composite = new Composite(parent, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(4).applyTo(composite); + + IDiagram diagram = context.getDefaultHintContext().getHint(DiagramHints.KEY_DIAGRAM); + if (diagram != null) onDiagramSet(diagram); + context.getDefaultHintContext().addKeyHintListener(DiagramHints.KEY_DIAGRAM, new IHintListener() { @Override - public void layerRemoved(ILayer layer) { - scheduleRefresh(); + public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) { + IDiagram diagram = (IDiagram)newValue; + onDiagramSet(diagram); } @Override - public void layerAdded(ILayer layer) { - scheduleRefresh(); + public void hintRemoved(IHintObservable sender, Key key, Object oldValue) { } - @Override - public void layerActivated(ILayer layer) { - scheduleRefresh(); - } + }); + } + + private void onDiagramSet(IDiagram diagram) { + if (diagram != null) { + layers = diagram.getHint(DiagramHints.KEY_LAYERS_EDITOR); + if (layers != null) initialize(layers, diagram); + diagram.addKeyHintListener(DiagramHints.KEY_LAYERS_EDITOR, new IHintListener() { + + + @Override + public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) { + if (newValue != null) { + initialize(layers, diagram); + } + } + @Override + public void hintRemoved(IHintObservable sender, Key key, Object oldValue) { + // TODO Auto-generated method stub + System.out.println("REM"); + } - @Override - public void layerDeactivated(ILayer layer) { - scheduleRefresh(); - } + }); + } + } - @Override - public void ignoreFocusChanged(boolean value) { - } + private void initialize(ILayersEditor layers, IDiagram diagram) { + composite.getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + initialize2(layers, diagram); + } + }); + } - @Override - public void ignoreVisibilityChanged(boolean value) { - } + private ILayersListener layersListener = new ILayersListener() { - void scheduleRefresh() { - viewer.getControl().getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - viewer.refresh(); - } - }); - } - }); + @Override + public void changed() { + scheduleRefresh(); + } - composite = new Composite(parent, SWT.NONE); - GridLayoutFactory.fillDefaults().numColumns(4).applyTo(composite); + void scheduleRefresh() { + viewer.getControl().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + viewer.refresh(); + ignoreVisibilityButton.setSelection(layers.getIgnoreVisibilitySettings()); + ignoreFocusButton.setSelection(layers.getIgnoreFocusSettings()); + if (!context.isDisposed()) + context.getContentContext().setDirty(); + } + }); + } + }; + + private void initialize2(ILayersEditor layers, IDiagram diagram) { + layers.addLayersListener(layersListener); Button addButton = new Button(composite, SWT.NONE); addButton.setText(Messages.DiagramLayersPage_New); @@ -372,6 +418,15 @@ public class DiagramLayersPage extends Page implements ILayersViewPage { if (selectIndex >= 0) { viewer.getTree().select(all[selectIndex]); } + context.getThreadAccess().asyncExec(new Runnable() { + + @Override + public void run() { + if(context.isDisposed()) return; + context.getContentContext().setDirty(); + } + + }); } @Override @@ -380,34 +435,15 @@ public class DiagramLayersPage extends Page implements ILayersViewPage { } }); - String ignoreVisibilityText = TEXT_IGNORE_VISIBILITY_SETTINGS; - String ignoreVisibilityTooltip = TOOLTIP_IGNORE_VISIBILITY_SETTINGS; - boolean ignoreVisibility = layers.getIgnoreVisibilitySettings(); - if (ignoreVisibility) { - ignoreVisibilityText = TEXT_APPLY_VISIBILITY_SETTINGS; - ignoreVisibilityTooltip = TOOLTIP_APPLY_VISIBILITY_SETTINGS; - } - - final Button ignoreVisibilityButton = new Button(composite, SWT.NONE); - ignoreVisibilityButton.setText(ignoreVisibilityText); - ignoreVisibilityButton.setToolTipText(ignoreVisibilityTooltip); + ignoreVisibilityButton = new Button(composite, SWT.CHECK); + ignoreVisibilityButton.setText(TEXT_IGNORE_VISIBILITY_SETTINGS); + ignoreVisibilityButton.setToolTipText(TOOLTIP_IGNORE_VISIBILITY_SETTINGS); + ignoreVisibilityButton.setSelection(layers.getIgnoreVisibilitySettings()); ignoreVisibilityButton.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { - String ignoreText = TEXT_IGNORE_VISIBILITY_SETTINGS; - String ignoreTooltip= TOOLTIP_IGNORE_VISIBILITY_SETTINGS; - boolean ignore = layers.getIgnoreVisibilitySettings(); - if(!ignore) { - ignoreText = TEXT_APPLY_VISIBILITY_SETTINGS; - ignoreTooltip = TOOLTIP_APPLY_VISIBILITY_SETTINGS; - layers.setIgnoreVisibilitySettings(true); - } else { - layers.setIgnoreVisibilitySettings(false); - } - ignoreVisibilityButton.setText(ignoreText); - ignoreVisibilityButton.setToolTipText(ignoreTooltip); - composite.layout(); + layers.setIgnoreVisibilitySettings(!layers.getIgnoreVisibilitySettings()); context.getThreadAccess().asyncExec(new Runnable() { @Override @@ -426,34 +462,15 @@ public class DiagramLayersPage extends Page implements ILayersViewPage { }); - String ignoreFocusText = TEXT_IGNORE_FOCUS_SETTINGS; - String ignoreFocusTooltip = TOOLTIP_IGNORE_FOCUS_SETTINGS; - boolean ignoreFocus = layers.getIgnoreFocusSettings(); - if(ignoreFocus) { - ignoreFocusText = TEXT_APPLY_FOCUS_SETTINGS; - ignoreFocusTooltip = TOOLTIP_APPLY_FOCUS_SETTINGS; - } - - final Button ignoreFocusButton = new Button(composite, SWT.NONE); - ignoreFocusButton.setText(ignoreFocusText); - ignoreFocusButton.setToolTipText(ignoreFocusTooltip); + ignoreFocusButton = new Button(composite, SWT.CHECK); + ignoreFocusButton.setText(TEXT_IGNORE_FOCUS_SETTINGS); + ignoreFocusButton.setToolTipText(TOOLTIP_IGNORE_FOCUS_SETTINGS); + ignoreFocusButton.setSelection(layers.getIgnoreFocusSettings()); ignoreFocusButton.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { - String ignoreText = TEXT_IGNORE_FOCUS_SETTINGS; - String ignoreTooltip = TOOLTIP_IGNORE_FOCUS_SETTINGS; - boolean ignore = layers.getIgnoreFocusSettings(); - if(!ignore) { - ignoreText = TEXT_APPLY_FOCUS_SETTINGS; - ignoreTooltip = TOOLTIP_APPLY_FOCUS_SETTINGS; - layers.setIgnoreFocusSettings(true); - } else { - layers.setIgnoreFocusSettings(false); - } - ignoreFocusButton.setText(ignoreText); - ignoreFocusButton.setToolTipText(ignoreTooltip); - composite.layout(); + layers.setIgnoreFocusSettings(!layers.getIgnoreFocusSettings()); context.getThreadAccess().asyncExec(new Runnable() { @Override @@ -519,16 +536,20 @@ public class DiagramLayersPage extends Page implements ILayersViewPage { Tristate state = getJointAttribute(elements, lz[index], attribute); Color color = null; - switch (state) { - case False: - color = viewer.getTree().getDisplay().getSystemColor(SWT.COLOR_RED); - break; - case True: - color = viewer.getTree().getDisplay().getSystemColor(SWT.COLOR_GREEN); - break; - case Both: - color = viewer.getTree().getDisplay().getSystemColor(SWT.COLOR_GRAY); - break; + if (state == null) { + color = viewer.getTree().getDisplay().getSystemColor(SWT.COLOR_GRAY); + } else { + switch (state) { + case False: + color = viewer.getTree().getDisplay().getSystemColor(SWT.COLOR_RED); + break; + case True: + color = viewer.getTree().getDisplay().getSystemColor(SWT.COLOR_GREEN); + break; + case Both: + color = viewer.getTree().getDisplay().getSystemColor(SWT.COLOR_GRAY); + break; + } } GC gc = event.gc; @@ -707,6 +728,8 @@ public class DiagramLayersPage extends Page implements ILayersViewPage { for(ILayer layer : layers.getVisibleLayers()) { viewer.setSubtreeChecked(layer, true); } + + composite.layout(); } @Override @@ -762,7 +785,7 @@ public class DiagramLayersPage extends Page implements ILayersViewPage { IEditableLayer l = (IEditableLayer)layer; l.setName(text.getText()); System.out.println("renamed layer to " + text.getText()); //$NON-NLS-1$ - viewer.refresh(); + //viewer.refresh(); } // // Item may be disposed if the tree gets reset after a previous editing. @@ -810,7 +833,7 @@ public class DiagramLayersPage extends Page implements ILayersViewPage { IEditableLayer l = (IEditableLayer)layer; l.setName(text.getText()); //System.out.println("renamed layer to " + text.getText()); - viewer.refresh(); + //viewer.refresh(); } // error = modifier.isValid(text.getText()); // if (error == null) { diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewer.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewer.java index 88d85cfbf..fb5399ea0 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewer.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewer.java @@ -1043,7 +1043,7 @@ public class DiagramViewer return (T) new DiagramOutlinePage(sessionContextProvider, getResourceInput2()); // Role view support if (adapter == ILayersViewPage.class) - return (T) new DiagramLayersPage(sourceDiagram, canvasContext); + return (T) new DiagramLayersPage(canvasContext); // Support external steering of the diagram canvas, zooming etc. if (adapter == ICanvasContext.class) return (T) canvasContext; diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/Messages.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/Messages.java index 970fbc650..f80372ce0 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/Messages.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/Messages.java @@ -5,8 +5,6 @@ import org.eclipse.osgi.util.NLS; public class Messages extends NLS { private static final String BUNDLE_NAME = "org.simantics.modeling.ui.diagramEditor.messages"; //$NON-NLS-1$ public static String DiagramEditor_InvalidParameter; - public static String DiagramLayersPage_FocusActive; - public static String DiagramLayersPage_FocusActiveTT; public static String DiagramLayersPage_Focus; public static String DiagramLayersPage_FocusAll; public static String DiagramLayersPage_FocusAllTT; @@ -17,8 +15,6 @@ public class Messages extends NLS { public static String DiagramLayersPage_RemoveTT; public static String DiagramLayersPage_Role; public static String DiagramLayersPage_SelectTT; - public static String DiagramLayersPage_ShowActive; - public static String DiagramLayersPage_ShowActiveTT; public static String DiagramLayersPage_Show; public static String DiagramLayersPage_ShowAll; public static String DiagramLayersPage_ShowAllTT; diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/PlainDiagramViewer.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/PlainDiagramViewer.java index 3c5d4af63..a5c95eac4 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/PlainDiagramViewer.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/PlainDiagramViewer.java @@ -99,6 +99,14 @@ public class PlainDiagramViewer extends org.simantics.modeling.ui.diagramEditor. return true; } + @Override + public void addLayersListener(ILayersListener listener) { + } + + @Override + public void removeLayersListener(ILayersListener listener) { + } + }); // Disable roles (layers) by default in symbol editor to show everything. diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/SheetViewer.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/SheetViewer.java index 22a1b59e4..02a317ce0 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/SheetViewer.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/SheetViewer.java @@ -658,7 +658,7 @@ public class SheetViewer extends EditorPart implements IResourceEditorPart2 { if (adapter == IContentOutlinePage.class) return (T) new DiagramOutlinePage(sessionContextProvider, getResourceInput2()); if (adapter == ILayersViewPage.class) - return (T) new DiagramLayersPage(sourceDiagram, canvasContext); + return (T) new DiagramLayersPage(canvasContext); if (adapter == ICanvasContext.class) return (T) canvasContext; if (adapter == INode.class) { diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/WikiDiagramViewer.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/WikiDiagramViewer.java index 47913a7e0..70436d134 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/WikiDiagramViewer.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/WikiDiagramViewer.java @@ -396,7 +396,7 @@ public class WikiDiagramViewer extends EditorPart implements IResourceEditorPart if (adapter == IContentOutlinePage.class) return new DiagramOutlinePage(sessionContextProvider, getResourceInput2()); if (adapter == ILayersViewPage.class) - return new DiagramLayersPage(sourceDiagram, canvasContext); + return new DiagramLayersPage(canvasContext); if (adapter == ICanvasContext.class) return canvasContext; if (adapter == IDiagram.class) diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/e4/DiagramViewer.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/e4/DiagramViewer.java index d0bf18b83..2cbf33447 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/e4/DiagramViewer.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/e4/DiagramViewer.java @@ -148,7 +148,6 @@ import org.simantics.scenegraph.g2d.snap.GridSnapAdvisor; import org.simantics.scenegraph.utils.NodeUtil; import org.simantics.structural.stubs.StructuralResource2; import org.simantics.structural2.modelingRules.IModelingRules; -import org.simantics.ui.SimanticsUI; import org.simantics.ui.jobs.SessionGarbageCollectorJob; import org.simantics.ui.workbench.IPropertyPage; import org.simantics.ui.workbench.IResourceEditorInput; @@ -998,7 +997,7 @@ public class DiagramViewer return new DiagramOutlinePage(sessionContextProvider, getResourceEditorInput()); // Role view support if (adapter == ILayersViewPage.class) - return new DiagramLayersPage(sourceDiagram, canvasContext); + return new DiagramLayersPage(canvasContext); // Support external steering of the diagram canvas, zooming etc. if (adapter == ICanvasContext.class) return canvasContext; diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/messages.properties b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/messages.properties index 19052dac1..f4f9f0671 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/messages.properties +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/messages.properties @@ -1,21 +1,17 @@ DiagramEditor_InvalidParameter=Invalid parameter ''{0}''. Complete view argument: {1} DiagramLayersPage_Focus=Focus -DiagramLayersPage_FocusActive=Focus Active -DiagramLayersPage_FocusActiveTT=Only Focus Diagram Elements For Active Roles DiagramLayersPage_FocusAll=Focus All -DiagramLayersPage_FocusAllTT=Focus All Diagram Elements Regardless Of Active Roles -DiagramLayersPage_New=New -DiagramLayersPage_NewRole=New Role -DiagramLayersPage_NewTT=Create New Diagram Role -DiagramLayersPage_Remove=Remove -DiagramLayersPage_RemoveTT=Remove Selected Diagram Role -DiagramLayersPage_Role=Role +DiagramLayersPage_FocusAllTT=Focus All Diagram Elements Regardless Of Active Layers +DiagramLayersPage_New=New Layer +DiagramLayersPage_NewRole=New Layer +DiagramLayersPage_NewTT=Create New Layer +DiagramLayersPage_Remove=Remove Layer +DiagramLayersPage_RemoveTT=Remove Selected Layer +DiagramLayersPage_Role=Active Layers DiagramLayersPage_SelectTT=Selects the diagram to include in the exported document. DiagramLayersPage_Show=Show -DiagramLayersPage_ShowActive=Show Active -DiagramLayersPage_ShowActiveTT=Only Show Diagram Elements For Active Roles DiagramLayersPage_ShowAll=Show All -DiagramLayersPage_ShowAllTT=Show All Diagram Elements Regardless Of Active Roles +DiagramLayersPage_ShowAllTT=Show All Diagram Elements Regardless Of Active Layers DiagramViewer_FailedtoLoadModeled=Failed to load modeled browse contexts for property page, see exception for details. DiagramViewer_MonitorActivateMapping=Activate Mapping DiagramViewerActionContributor_ConnectMode=Connect Mode diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/symbolEditor/SymbolViewer.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/symbolEditor/SymbolViewer.java index 150ccfe52..d27f91b93 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/symbolEditor/SymbolViewer.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/symbolEditor/SymbolViewer.java @@ -17,7 +17,6 @@ import java.util.Set; import org.simantics.db.common.request.ParametrizedRead; import org.simantics.db.layer0.request.combinations.Combinators; import org.simantics.diagram.handler.CopyPasteStrategy; -import org.simantics.diagram.handler.DefaultCopyPasteStrategy; import org.simantics.diagram.participant.PointerInteractor2; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.diagram.DiagramHints; @@ -109,6 +108,14 @@ public class SymbolViewer extends org.simantics.modeling.ui.diagramEditor.Diagra return true; } + @Override + public void addLayersListener(ILayersListener listener) { + } + + @Override + public void removeLayersListener(ILayersListener listener) { + } + }); // Disable roles (layers) by default in symbol editor to show everything. diff --git a/releng/org.simantics.desktop.rcp.product/simantics-desktop.product b/releng/org.simantics.desktop.rcp.product/simantics-desktop.product index 55b537f94..1a4088c3b 100644 --- a/releng/org.simantics.desktop.rcp.product/simantics-desktop.product +++ b/releng/org.simantics.desktop.rcp.product/simantics-desktop.product @@ -14,18 +14,18 @@ - -fixerrors --data -@noDefault --cssTheme + -fixerrors +-data +@noDefault +-cssTheme org.eclipse.e4.ui.css.theme.e4_classic - -ea --Xmx500M --Xshare:off --Dorg.simantics.workbench.application.showFastViewBars=false --Dorg.simantics.workbench.application.showPerspectiveBar=false --Dorg.simantics.workbench.application.excludePerspectiveFromTitle=true + -ea +-Xmx500M +-Xshare:off +-Dorg.simantics.workbench.application.showFastViewBars=false +-Dorg.simantics.workbench.application.showPerspectiveBar=false +-Dorg.simantics.workbench.application.excludePerspectiveFromTitle=true -Declipse.workaround.bug467000=true -Dorg.osgi.framework.os.name=win32 -- 2.47.1