From 4aaf90be00254a2aae41b8a2911e6fbfd59725bc Mon Sep 17 00:00:00 2001 From: Arvid Berg Date: Thu, 24 Jun 2010 10:43:13 +0200 Subject: [PATCH] Cleaned up code related to selections and structure changed events. This was done while researching bug 2016 --- .../widgets/JChemPaintEditorWidget.java | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/plugins/net.bioclipse.cdk.jchempaint/src/net/bioclipse/cdk/jchempaint/widgets/JChemPaintEditorWidget.java b/plugins/net.bioclipse.cdk.jchempaint/src/net/bioclipse/cdk/jchempaint/widgets/JChemPaintEditorWidget.java index 62b6a59d9..1be8a2a36 100644 --- a/plugins/net.bioclipse.cdk.jchempaint/src/net/bioclipse/cdk/jchempaint/widgets/JChemPaintEditorWidget.java +++ b/plugins/net.bioclipse.cdk.jchempaint/src/net/bioclipse/cdk/jchempaint/widgets/JChemPaintEditorWidget.java @@ -368,11 +368,7 @@ public void selectionChanged() { } public void structureChanged() { - Display.getDefault().syncExec( new Runnable() { - public void run() { JChemPaintEditorWidget.this.structureChanged(); - } - }); setDirty(true); } @@ -655,11 +651,10 @@ public void addSelectionChangedListener( ISelectionChangedListener listener ) { public ISelection getSelection() { RendererModel rendererModel = getRenderer2DModel(); + ICDKMolecule sourceMol = getMolecule(); if (rendererModel == null) - if(source != null) - return new StructuredSelection(source); - else - return StructuredSelection.EMPTY; + return sourceMol != null? new StructuredSelection(sourceMol) + : StructuredSelection.EMPTY; List> selection = new LinkedList>(); @@ -678,8 +673,8 @@ public ISelection getSelection() { } } - if (selection.isEmpty() && source != null) { - return new StructuredSelection(source); + if (selection.isEmpty() && sourceMol != null) { + return new StructuredSelection(sourceMol); } return new StructuredSelection(selection); @@ -714,8 +709,14 @@ protected void structureChanged() { IChemModel model = hub.getIChemModel(); removeDanglingHydrogens( model ); updateAtomTypesAndHCounts( model ); - if(!this.isDisposed()) - resizeControl(); + if(!this.isDisposed()){ + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + resizeControl(); + } + }); + } } /** @@ -915,4 +916,18 @@ public void addDropSupport(int operations, Transfer[] transferTypes, dropTarget.setTransfer(transferTypes); dropTarget.addDropListener(listener); } + + @Override + public ICDKMolecule getMolecule() { + ICDKMolecule model = super.getMolecule(); + if(model == null) return null; + IAtomContainer modelContainer = model.getAtomContainer(); + modelContainer.removeAllElements(); + IChemModel chemModel = getControllerHub().getIChemModel(); + for(IAtomContainer aContainer:ChemModelManipulator + .getAllAtomContainers( chemModel )) { + modelContainer.add( aContainer ); + } + return model; + } }