From 0a314ce9afeeac53b4d4653125cf56cb99be7976 Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Thu, 8 Dec 2016 11:06:36 +0200 Subject: [PATCH] Re-enabled CTRL+SHIFT+R resource search dialog in org.simantics.debug.ui This fixes the old problem where the index searches were not limited to e.g. a 1000 hits but to Integer.MAX_VALUE instead. If the user happened to write 'a' into the search field, this would return pretty much every indexed resource and kill the JVM eventually. This also fixes a problem from org.simantics.modeling.ui.diagramEditor.DiagramViewer which did not check diagram resource immutability before attempting to write a diagram page description to it because it was missing. This can happen if you use the resource search dialog to open e.g. diagram symbols from the ontologies. refs #6855 Change-Id: Id341871847e0ea8bdbc036e8023821ab0556a3cb --- .../META-INF/MANIFEST.MF | 5 +- bundles/org.simantics.debug.ui/plugin.xml | 12 +- .../debug/ui/SearchResourceDialog.java | 157 +++++++++--------- .../org/simantics/debug/ui/ShowInBrowser.java | 126 ++++++++++++++ .../ui/internal/SearchResourceHandler.java | 45 +++-- .../ui/diagramEditor/DiagramViewer.java | 14 +- 6 files changed, 241 insertions(+), 118 deletions(-) create mode 100644 bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/ShowInBrowser.java diff --git a/bundles/org.simantics.debug.ui/META-INF/MANIFEST.MF b/bundles/org.simantics.debug.ui/META-INF/MANIFEST.MF index e2e885975..f548261ca 100644 --- a/bundles/org.simantics.debug.ui/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.debug.ui/META-INF/MANIFEST.MF @@ -18,7 +18,10 @@ Require-Bundle: org.eclipse.core.runtime, org.simantics.wiki.ui;bundle-version="1.1.0", org.simantics.browsing.ui.swt;bundle-version="1.1.0", org.simantics.views.swt;bundle-version="1.0.0", - org.simantics.structural2;bundle-version="1.1.1" + org.simantics.structural2;bundle-version="1.1.1", + org.simantics.browsing.ui.model, + org.simantics.modeling.ontology, + org.slf4j.api Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: org.simantics.debug.ui diff --git a/bundles/org.simantics.debug.ui/plugin.xml b/bundles/org.simantics.debug.ui/plugin.xml index 94b8fe432..3bf794e3f 100644 --- a/bundles/org.simantics.debug.ui/plugin.xml +++ b/bundles/org.simantics.debug.ui/plugin.xml @@ -88,18 +88,18 @@ - diff --git a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/SearchResourceDialog.java b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/SearchResourceDialog.java index 8c88468e4..1ae23d719 100644 --- a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/SearchResourceDialog.java +++ b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/SearchResourceDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2013 Association for Decentralized Information Management + * Copyright (c) 2007, 2016 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 @@ -17,6 +17,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeSet; @@ -27,14 +28,14 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.LocalResourceManager; import org.eclipse.jface.resource.ResourceManager; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; +import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; @@ -46,11 +47,12 @@ import org.simantics.Simantics; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Session; -import org.simantics.db.common.primitiverequest.Adapter; +import org.simantics.db.common.primitiverequest.PossibleAdapter; import org.simantics.db.common.procedure.adapter.TransientCacheListener; import org.simantics.db.common.request.BinaryRead; import org.simantics.db.common.request.ObjectsWithType; import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.UniqueRead; import org.simantics.db.common.uri.UnescapedChildMapOfResource; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; @@ -64,24 +66,38 @@ import org.simantics.debug.ui.internal.DebugUtils; import org.simantics.layer0.Layer0; import org.simantics.operation.Layer0X; import org.simantics.scl.runtime.function.Function; -import org.simantics.ui.SimanticsUI; +import org.simantics.ui.selection.ResourceWorkbenchSelectionElement; import org.simantics.ui.workbench.dialogs.ResourceLabelProvider; import org.simantics.utils.Container; import org.simantics.utils.ui.BundleUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * TODO Add Debugger Composite as preview! */ public class SearchResourceDialog extends FilteredItemsSelectionDialog { + private static final Logger LOGGER = LoggerFactory.getLogger(SearchResourceDialog.class); + + /** + * The default maximum amount of Dependencies index hits to produce as results. + */ + private static final int DEFAULT_MAX_INDEX_HITS = 1000; + + private static final Pattern ID_PATTERN = Pattern.compile("\\$([0-9]+)"); + private static final String SEARCH_RESOURCE_DIALOG = "SearchResourceDialog"; //$NON-NLS-1$ - Session session; - IStructuredSelection selection; - ResourceManager resourceManager; + private static final int SHOW_IN_BROWSER_ID = IDialogConstants.CLIENT_ID + 1; + + private static final String SHOW_IN_BROWSER_LABEL = "Show In Browser"; - // Needed in a subclass - protected IResourceFilter resourceFilter = ResourceSearch.FILTER_ALL; + private Session session; + @SuppressWarnings("unused") + private IStructuredSelection selection; + private ResourceManager resourceManager; + private IResourceFilter resourceFilter = ResourceSearch.FILTER_ALL; LabelProvider detailsLabelProvider = new LabelProvider() { @Override @@ -143,69 +159,75 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { public SearchResourceDialog(Session s, boolean multi, Shell shell, String title, IStructuredSelection selection) { super(shell, multi); this.session = s; - resourceManager = new LocalResourceManager(JFaceResources.getResources()); + this.selection = selection; this.labelProvider = new ElementLabelProvider(shell.getDisplay()); - setMessage("Enter ID, URI or name"); + setMessage("Enter name, resource URI or ID"); setListLabelProvider(labelProvider); setDetailsLabelProvider(detailsLabelProvider); - setImage((Image) resourceManager.get(BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_blue.png"))); setTitle(title); //setInitialPattern("*", FilteredItemsSelectionDialog.FULL_SELECTION); setSelectionHistory(new ResourceSelectionHistory()); - this.selection = selection; setSeparatorLabel("Previously selected above, others below"); } @Override protected void configureShell(Shell shell) { + this.resourceManager = new LocalResourceManager(JFaceResources.getResources(), shell); + setImage((Image) resourceManager.get(BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_blue.png"))); super.configureShell(shell); - shell.addDisposeListener(new DisposeListener() { - @Override - public void widgetDisposed(DisposeEvent e) { - resourceManager.dispose(); - } - }); + } + + @Override + protected void createButtonsForButtonBar(Composite parent) { + createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, + true); + createButton(parent, SHOW_IN_BROWSER_ID, SHOW_IN_BROWSER_LABEL, + true); + createButton(parent, IDialogConstants.CANCEL_ID, + IDialogConstants.CANCEL_LABEL, false); + } + + @Override + protected void buttonPressed(int buttonId) { + if (buttonId == SHOW_IN_BROWSER_ID) { + okPressed(); + LabeledResource lr = (LabeledResource) getFirstResult(); + ShowInBrowser.defaultExecute(new StructuredSelection(new ResourceWorkbenchSelectionElement(lr.resource))); + return; + } + super.buttonPressed(buttonId); } class ResourceSelectionHistory extends FilteredItemsSelectionDialog.SelectionHistory { @Override protected Object restoreItemFromMemento(IMemento memento) { - String dada = memento.getTextData(); + String data = memento.getTextData(); try { - SerialisationSupport support = SimanticsUI.getSession().getService(SerialisationSupport.class); - final Resource r = support.getResource(Long.parseLong(dada)); - if (r == null) { + SerialisationSupport support = Simantics.getSession().getService(SerialisationSupport.class); + Resource r = support.getResource(Long.parseLong(data)); + if (r == null) return null; - } - String name = session.syncRequest(new Read() { + String name = session.syncRequest(new UniqueRead() { @Override public String perform(ReadGraph g) throws DatabaseException { - if (!resourceFilter.acceptResource(g, r)) { + if (!resourceFilter.acceptResource(g, r)) return null; - } - String name = null; try { try { - name = g.adapt(r, String.class); + return g.adapt(r, String.class); } catch (Exception ex) { System.out.println("Exception thrown from restoreItemFromMemento"); } - if (name != null) { - return name; - } } catch (Throwable t) {} return "" + r.getResourceId(); } }); if (name==null) return null; return new LabeledResource(name, r); - } catch (NumberFormatException e) { - e.printStackTrace(); - return null; - } catch (DatabaseException e) { - e.printStackTrace(); + } catch (NumberFormatException | DatabaseException e) { + LOGGER.info("Search memento restoration failed.", e); return null; } } @@ -215,7 +237,7 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { protected void storeItemToMemento(Object item, IMemento memento) { if(item instanceof Container) { try { - SerialisationSupport support = SimanticsUI.getSession().getService(SerialisationSupport.class); + SerialisationSupport support = Simantics.getSession().getService(SerialisationSupport.class); memento.putTextData(String.valueOf(support.getRandomAccessId(((Container)item).get()))); } catch (DatabaseException e) { e.printStackTrace(); @@ -268,7 +290,7 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { final long referencedResourceId = referencedResourceId(pattern); final boolean findIds = referencedResourceId != 0; - progressMonitor.beginTask("Searching", IProgressMonitor.UNKNOWN); + //progressMonitor.beginTask("Searching", IProgressMonitor.UNKNOWN); try { session.syncRequest(new ReadRequest() { @@ -308,13 +330,12 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { filter += "Name:" + pattern + "*"; Layer0 L0 = Layer0.getInstance(graph); - - HashSet indexRoots = new HashSet(); + + Set indexRoots = new HashSet<>(); indexRoots.addAll(graph.syncRequest(new ObjectsWithType(project, L0.ConsistsOf, L0.IndexRoot))); indexRoots.addAll(graph.syncRequest(new OntologiesFromLibrary(graph.getRootLibrary()))); for (Resource indexRoot : indexRoots) { - Collection hits = new ArrayList(find(graph, indexRoot, filter)); - hits.add(indexRoot); + Collection hits = find(graph, indexRoot, filter); for (Resource r : hits) { if (rf != null && !rf.acceptResource(graph, r)) continue; @@ -326,26 +347,10 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { } public Collection find(ReadGraph graph, Resource index, String filter) throws DatabaseException { + //TimeLogger.resetTimeAndLog("find(" + graph.getURI(index) + ", " + filter + ")"); Collection indexResult = graph.syncRequest(new QueryIndex(index, filter), TransientCacheListener.>instance()); - -// Layer0 L0 = Layer0.getInstance(graph); -// Collection linkedRoots = graph.syncRequest(new ObjectsWithType(index, L0.IsLinkedTo, L0.IndexRoot)); -// if (linkedRoots.isEmpty()) - return indexResult; - -// Collection result = indexResult; -// for (Resource dep : linkedRoots) { -// Collection linkedIndexResults = find(graph, dep, filter); -// if (linkedIndexResults.isEmpty()) -// continue; -// if (result == indexResult) { -// result = new ArrayList(indexResult.size() + linkedIndexResults.size()); -// result.addAll(indexResult); -// } else { -// } -// result.addAll(linkedIndexResults); -// } -// return result; + //TimeLogger.log("found " + indexResult.size()); + return indexResult; } }); @@ -372,28 +377,26 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { Layer0X L0X = Layer0X.getInstance(graph); @SuppressWarnings({ "unchecked", "rawtypes" }) - Function dependencies = graph.syncRequest(new Adapter(L0X.Dependencies, Function.class), TransientCacheListener.instance()); + Function dependencies = graph.syncRequest(new PossibleAdapter(L0X.DependencyResources, Function.class), TransientCacheListener.instance()); + if (dependencies == null) + return Collections.emptyList(); @SuppressWarnings("unchecked") - Collection> results = (Collection>)dependencies.apply(graph, parameter, parameter2); + List results = (List) dependencies.apply(graph, parameter, parameter2, DEFAULT_MAX_INDEX_HITS); if (results == null || results.isEmpty()) return Collections.emptyList(); - // TreeSet to keep the results in deterministic order. - Set resultSet = new TreeSet(); - for (Map entry : results) { - Resource res = (Resource)entry.get("Resource"); + // TreeSet to keep the results in deterministic order and to prevent duplicates. + Set resultSet = new TreeSet<>(); + for (Resource res : results) { if (res != null && !resultSet.contains(res)) resultSet.add(res); } - return new ArrayList(resultSet); } } - Pattern ID_PATTERN = Pattern.compile("\\$([0-9]+)"); - private long referencedResourceId(String pattern) { Matcher m = ID_PATTERN.matcher(pattern); if (m.matches()) { @@ -424,14 +427,10 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { //return item.toString(); } - @SuppressWarnings("rawtypes") @Override - protected Comparator getItemsComparator() { - return new Comparator() { - @Override - public int compare(Object arg0, Object arg1) { - return arg0.toString().compareTo(arg1.toString()); - } + protected Comparator getItemsComparator() { + return (arg0, arg1) -> { + return arg0.toString().compareTo(arg1.toString()); }; } diff --git a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/ShowInBrowser.java b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/ShowInBrowser.java new file mode 100644 index 000000000..54acdd604 --- /dev/null +++ b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/ShowInBrowser.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2016 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 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.debug.ui; + +import java.util.Collection; +import java.util.Collections; +import java.util.Deque; +import java.util.LinkedList; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.Simantics; +import org.simantics.browsing.ui.GraphExplorer; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.common.NodeContextBuilder; +import org.simantics.browsing.ui.model.browsecontexts.BrowseContext; +import org.simantics.browsing.ui.model.nodetypes.EntityNodeType; +import org.simantics.browsing.ui.model.nodetypes.NodeType; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.ui.selection.WorkbenchSelectionUtils; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + +/** + * @author Antti Villberg + * @author Tuukka Lehtonen + */ +public class ShowInBrowser extends AbstractHandler { + + private static final String DEFAULT_BROWSER_VIEW_ID = "org.simantics.modeling.ui.browser"; //$NON-NLS-1$ + + private static Read> getParentsRequest(BrowseContext bc, NodeContext context) { + return new UniqueRead>() { + @Override + public Collection perform(ReadGraph graph) throws DatabaseException { + return bc.getParents(graph, context); + } + }; + } + + private static Read getNodeTypeRequest(Resource element) { + return new UniqueRead() { + @Override + public NodeType perform(ReadGraph graph) throws DatabaseException { + return EntityNodeType.getNodeTypeFor(graph, element); + } + }; + } + + private static Collection tryGetParents(BrowseContext bc, NodeContext context) { + try { + return Simantics.getSession().syncRequest(getParentsRequest(bc, context)); + } catch (DatabaseException e) { + return Collections.emptyList(); + } + } + + private static boolean show(GraphExplorer explorer, BrowseContext browseContext, NodeContext context, Deque path) { + if (explorer.isVisible(context)) + return explorer.selectPath(path); + else { + for (NodeContext parent : tryGetParents(browseContext, context)) { + path.addFirst(parent); + if (show(explorer, browseContext, parent, path)) + return true; + path.removeFirst(); + } + } + return false; + } + + public static Object defaultExecute(ISelection selection, String browserViewId) { + IViewPart browser = (IViewPart) WorkbenchUtils.findView(browserViewId); + if (browser == null) + return null; + + GraphExplorer explorer = (GraphExplorer) browser.getAdapter(GraphExplorer.class); + BrowseContext browseContext = (BrowseContext) browser.getAdapter(BrowseContext.class); + if (explorer == null || browseContext == null) + return null; + + try { + final Resource element = WorkbenchSelectionUtils.getPossibleResource(selection); + WorkbenchUtils.showView(browserViewId, IWorkbenchPage.VIEW_VISIBLE); + NodeType nodeType = Simantics.getSession().syncRequest(getNodeTypeRequest(element));; + NodeContext context = NodeContextBuilder.buildWithData(NodeType.KEY_SEQUENCE, new Object[] { element, nodeType }); + Deque path = new LinkedList<>(); + path.add(context); + if (show(explorer, browseContext, context, path)) { + WorkbenchUtils.activateView(browserViewId); + } + } catch (DatabaseException e) { + } catch (PartInitException e) { + } + + return null; + } + + public static Object defaultExecute(ISelection selection) { + return defaultExecute(selection, DEFAULT_BROWSER_VIEW_ID); + } + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + return defaultExecute(HandlerUtil.getCurrentSelectionChecked(event)); + } + +} \ No newline at end of file diff --git a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/SearchResourceHandler.java b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/SearchResourceHandler.java index 38e60653c..3fb4013d8 100644 --- a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/SearchResourceHandler.java +++ b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/SearchResourceHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * Copyright (c) 2007, 2016 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 @@ -8,14 +8,16 @@ * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation + * Semantum Oy - refactoring (#6855) *******************************************************************************/ package org.simantics.debug.ui.internal; +import java.util.function.BiConsumer; + import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.action.IAction; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.handlers.HandlerUtil; import org.simantics.Simantics; @@ -29,6 +31,7 @@ import org.simantics.debug.ui.ResourceSearch; import org.simantics.debug.ui.SearchResourceDialog; import org.simantics.ui.workbench.action.ChooseActionRequest; import org.simantics.utils.Container; +import org.simantics.utils.ui.SWTUtils; import org.simantics.utils.ui.action.IPriorityAction; import org.simantics.utils.ui.workbench.WorkbenchUtils; @@ -39,7 +42,7 @@ public class SearchResourceHandler extends AbstractHandler { Shell shell = HandlerUtil.getActiveShellChecked(event); Session session = Simantics.getSession(); SearchResourceDialog rld = new SearchResourceDialog(session, false, shell, "Open Resource"); - rld.setResourceFilter(ResourceSearch.FILTER_RELATIONS); + rld.setResourceFilter(ResourceSearch.FILTER_ALL); rld.setBlockOnOpen(true); rld.open(); if (rld.getResult() == null) @@ -50,38 +53,32 @@ public class SearchResourceHandler extends AbstractHandler { for (Object o : rld.getResult()) { @SuppressWarnings("unchecked") Container rc = (Container) o; - openPreferredEditor(session, rc.get(), currentPerspectiveId); + openPreferredEditor(shell, session, rc.get(), currentPerspectiveId); } return null; } - void openPreferredEditor(Session s, final Resource r, final String defaultPerspective) { + private static void openPreferredEditor(Shell parent, Session s, Resource r, String defaultPerspective) { + findActions(s, r, defaultPerspective, (resourceName, actions) -> { + SWTUtils.asyncExec(parent, () -> { + IAction action = ChooseActionRequest.chooseAction(parent, actions, resourceName); + if (action != null) + action.run(); + }); + }); + } + private static void findActions(Session s, Resource r, String defaultPerspective, BiConsumer consumer) { s.asyncRequest(new ReadRequest() { - - String resourceName; - IPriorityAction[] actions; - @Override public void run(ReadGraph g) throws DatabaseException { - resourceName = NameUtils.getSafeName(g, r); - actions = ChooseActionRequest.findActions(g, r, defaultPerspective); - if (actions == null) - return; - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - IAction action = ChooseActionRequest.chooseAction(null, actions, resourceName); - if (action == null) - return; - action.run(); - } - }); + String resourceName = NameUtils.getSafeName(g, r); + IPriorityAction[] actions = ChooseActionRequest.findActions(g, r, defaultPerspective); + if (actions != null) + consumer.accept(resourceName, actions); } - }); - } } 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 8ac45cf02..07743860c 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 @@ -156,7 +156,6 @@ import org.simantics.ui.workbench.TitleUpdater; import org.simantics.ui.workbench.ToolTipRequest; import org.simantics.ui.workbench.editor.input.InputValidationCombinators; import org.simantics.utils.DataContainer; -import org.simantics.utils.datastructures.Callback; import org.simantics.utils.datastructures.hints.HintContext; import org.simantics.utils.datastructures.hints.HintListenerAdapter; import org.simantics.utils.datastructures.hints.IHintContext; @@ -797,15 +796,14 @@ public class DiagramViewer sessionContext.getSession().asyncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException { - CommonDBUtils.selectClusterSet(graph, diagramResource); + if (graph.isImmutable(diagramResource)) + return; + CommonDBUtils.selectClusterSet(graph, diagramResource); DiagramGraphUtil.setDiagramDesc(graph, diagramResource, desc); } - }, new Callback() { - @Override - public void run(DatabaseException parameter) { - if (parameter != null) - ErrorLogger.defaultLogError("Failed to write default diagram page description to database, see exception for details", parameter); - } + }, parameter -> { + if (parameter != null) + ErrorLogger.defaultLogError("Failed to write default diagram page description to database, see exception for details", parameter); }); } -- 2.43.2