From aee46ed41287c6f4ec88ce362e5420506580eedf Mon Sep 17 00:00:00 2001 From: lempinen Date: Tue, 5 Jul 2011 13:07:31 +0000 Subject: [PATCH] Fixed thread access errors for accessing graph explorer selection inside graph query thread git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@21411 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/properties/ArrayIndexesTab.java | 146 ++++++++++-------- .../SharedFunctionLibrariesTab.java | 46 ++++-- 2 files changed, 114 insertions(+), 78 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayIndexesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayIndexesTab.java index 0f275677..a6e4b241 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayIndexesTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayIndexesTab.java @@ -72,22 +72,23 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg add.addSelectionListener(new SelectionListenerImpl(context) { + List enumerationResources; + + @Override + public void beforeApply() { + enumerationResources = getSelectedResources(availableEnumerationsExplorer); + } + @Override public void apply(WriteGraph graph, Resource input) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(graph); Resource arrayIndexes = graph.getPossibleObject(input, sr.HasArrayIndexes); - - List enumerationResources = getSelectedResources(availableEnumerationsExplorer); - if(arrayIndexes == null) { - arrayIndexes = OrderedSetUtils.create(graph, sr.ArrayIndexes, enumerationResources); + arrayIndexes = OrderedSetUtils.create(graph, sr.ArrayIndexes); graph.claim(input, sr.HasArrayIndexes, arrayIndexes); - } else { - OrderedSetUtils.addAll(graph, arrayIndexes, enumerationResources); } - - + OrderedSetUtils.addAll(graph, arrayIndexes, enumerationResources); } }); @@ -121,71 +122,92 @@ public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widg Button up = new Button(buttons, support, SWT.NONE); up.setText("Up"); up.addSelectionListener(new SelectionListenerImpl(context) { - @Override - public void apply(WriteGraph graph, Resource input) - throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - Resource arrayIndexes = graph.getPossibleObject(input, sr.HasArrayIndexes); - if(arrayIndexes == null) - return; - - List enumerationResources = getSelectedResources(usedEnumerationsExplorer); - if(enumerationResources.size() != 1) - return; - Resource enumeration = enumerationResources.get(0); - Resource prev = OrderedSetUtils.prev(graph, arrayIndexes, enumeration); - if(prev.equals(arrayIndexes)) - return; - - OrderedSetUtils.remove(graph, arrayIndexes, enumeration); - OrderedSetUtils.addBefore(graph, arrayIndexes, prev, enumeration); - } + + List enumerationResources; + + @Override + public void beforeApply() { + enumerationResources = getSelectedResources(usedEnumerationsExplorer); + } + + @Override + public void apply(WriteGraph graph, Resource input) + throws DatabaseException { + if(enumerationResources != null && enumerationResources.size() == 1) { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource arrayIndexes = graph.getPossibleObject(input, sr.HasArrayIndexes); + if(arrayIndexes == null) + return; + + Resource enumeration = enumerationResources.get(0); + Resource prev = OrderedSetUtils.prev(graph, arrayIndexes, enumeration); + if(prev.equals(arrayIndexes)) + return; + + OrderedSetUtils.remove(graph, arrayIndexes, enumeration); + OrderedSetUtils.addBefore(graph, arrayIndexes, prev, enumeration); + } + } }); - + Button down = new Button(buttons, support, SWT.NONE); down.setText("Down"); down.addSelectionListener(new SelectionListenerImpl(context) { - @Override - public void apply(WriteGraph graph, Resource input) - throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - Resource arrayIndexes = graph.getPossibleObject(input, sr.HasArrayIndexes); - if(arrayIndexes == null) - return; - - List enumerationResources = getSelectedResources(usedEnumerationsExplorer); - if(enumerationResources.size() != 1) - return; - Resource enumeration = enumerationResources.get(0); - Resource next = OrderedSetUtils.next(graph, arrayIndexes, enumeration); - if(next.equals(arrayIndexes)) - return; - OrderedSetUtils.remove(graph, arrayIndexes, enumeration); - OrderedSetUtils.addAfter(graph, arrayIndexes, next, enumeration); - } + + List enumerationResources; + + @Override + public void beforeApply() { + enumerationResources = getSelectedResources(usedEnumerationsExplorer); + } + + + @Override + public void apply(WriteGraph graph, Resource input) + throws DatabaseException { + if(enumerationResources != null && enumerationResources.size() == 1) { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource arrayIndexes = graph.getPossibleObject(input, sr.HasArrayIndexes); + if(arrayIndexes == null) + return; + Resource enumeration = enumerationResources.get(0); + Resource next = OrderedSetUtils.next(graph, arrayIndexes, enumeration); + if(next.equals(arrayIndexes)) + return; + OrderedSetUtils.remove(graph, arrayIndexes, enumeration); + OrderedSetUtils.addAfter(graph, arrayIndexes, next, enumeration); + } + } }); - + Button remove = new Button(buttons, support, SWT.NONE); remove.setText("Remove"); remove.addSelectionListener(new SelectionListenerImpl(context) { - @Override - public void apply(WriteGraph graph, Resource input) - throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - Resource arrayIndexes = graph.getPossibleObject(input, sr.HasArrayIndexes); - if(arrayIndexes == null) - return; - - List enumerationResources = getSelectedResources(usedEnumerationsExplorer); - if(enumerationResources.size() != 1) - return; - Resource enumeration = enumerationResources.get(0); - OrderedSetUtils.remove(graph, arrayIndexes, enumeration); - } + + List enumerationResources; + + @Override + public void beforeApply() { + enumerationResources = getSelectedResources(usedEnumerationsExplorer); + } + + @Override + public void apply(WriteGraph graph, Resource input) + throws DatabaseException { + if(enumerationResources != null && enumerationResources.size() == 1) { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource arrayIndexes = graph.getPossibleObject(input, sr.HasArrayIndexes); + if(arrayIndexes == null) + return; + + Resource enumeration = enumerationResources.get(0); + OrderedSetUtils.remove(graph, arrayIndexes, enumeration); + } + } }); } - + private List getSelectedResources(GraphExplorerComposite explorer) { List result = new ArrayList(); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SharedFunctionLibrariesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SharedFunctionLibrariesTab.java index d3d855a3..248bceeb 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SharedFunctionLibrariesTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SharedFunctionLibrariesTab.java @@ -113,30 +113,44 @@ public class SharedFunctionLibrariesTab extends LabelPropertyTabContributor impl add.addSelectionListener(new SelectionListenerImpl(context) { - @Override - public void apply(WriteGraph graph, Resource input) - throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - List selectedLibraries = getSelectedResources(availableSharedFunctionLibraries); - for(Resource library : selectedLibraries) { - graph.claim(input, l0.IsLinkedTo, library); - } - } + List selectedLibraries; + + public void beforeApply() { + selectedLibraries = getSelectedResources(availableSharedFunctionLibraries); + } + + @Override + public void apply(WriteGraph graph, Resource input) + throws DatabaseException { + if(selectedLibraries != null) { + Layer0 l0 = Layer0.getInstance(graph); + for(Resource library : selectedLibraries) { + graph.claim(input, l0.IsLinkedTo, library); + } + } + } }); - + Button remove = new Button(middleButtons, support, SWT.NONE); remove.setText(" <- "); remove.addSelectionListener(new SelectionListenerImpl(context) { + + List selectedLibraries; + + public void beforeApply() { + selectedLibraries = getSelectedResources(usedSharedFunctionLibraries); + } @Override public void apply(WriteGraph graph, Resource input) - throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - List selectedLibraries = getSelectedResources(usedSharedFunctionLibraries); - for(Resource library : selectedLibraries) { - graph.deny(input, l0.IsLinkedTo, library); - } + throws DatabaseException { + if(selectedLibraries != null) { + Layer0 l0 = Layer0.getInstance(graph); + for(Resource library : selectedLibraries) { + graph.deny(input, l0.IsLinkedTo, library); + } + } } }); -- 2.47.1