Permalink
Browse files

Cleaned up code related to selections and structure changed events.

This was done while researching bug 2016
  • Loading branch information...
1 parent d7bc081 commit 4aaf90be00254a2aae41b8a2911e6fbfd59725bc Arvid Berg committed with Jun 24, 2010
View
39 ...lipse.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<CDKChemObject<?>> selection = new LinkedList<CDKChemObject<?>>();
@@ -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;
+ }
}

0 comments on commit 4aaf90b

Please sign in to comment.