Skip to content

Commit

Permalink
Cleaned up code related to selections and structure changed events.
Browse files Browse the repository at this point in the history
This was done while researching bug 2016
  • Loading branch information
Arvid Berg authored and egonw committed Jun 24, 2010
1 parent d7bc081 commit 4aaf90b
Showing 1 changed file with 27 additions and 12 deletions.
Expand Up @@ -368,11 +368,7 @@ public void selectionChanged() {
}

public void structureChanged() {
Display.getDefault().syncExec( new Runnable() {
public void run() {
JChemPaintEditorWidget.this.structureChanged();
}
});
setDirty(true);
}

Expand Down Expand Up @@ -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<?>>();

Expand All @@ -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);
Expand Down Expand Up @@ -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();
}
});
}
}

/**
Expand Down Expand Up @@ -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.