Skip to content

Commit

Permalink
Merge pull request #20 from bioclipse/bug3447
Browse files Browse the repository at this point in the history
Cleans up unused classes and implements isDirty for MoleculesTable
  • Loading branch information
goglepox committed Feb 8, 2013
2 parents fca0cc1 + b3b7b1d commit fa0e891
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 832 deletions.
Expand Up @@ -661,12 +661,6 @@ && has2DCoordinatesNew( atomContainer )<2) {
if(GenerateLabelPrefChangedLisener.showGeneratedLabel())
add( Message.GENERATED );
}else {
IAtomContainer oldAC = atomContainer;
atomContainer = atomContainer.getBuilder()
.newInstance(IAtomContainer.class, atomContainer );
atomContainer.setProperties( new HashMap<Object, Object>(
oldAC.getProperties()) );
setDirty( oldAC.getFlag( 7 ) );
}
setAtomContainer(atomContainer);
}
Expand Down
Expand Up @@ -75,6 +75,11 @@ public void move( int indexFrom, int indexTo ) {
public void markDirty( int index, ICDKMolecule moleculeToSave ) {
model.markDirty( mappingIndex.get( index ), moleculeToSave );
}

@Override
public boolean isDirty( int index ) {
return model.isDirty( mappingIndex.get( index ));
}

public void save() {
throw new UnsupportedOperationException( "Use MolTable manager to save "+
Expand Down
Expand Up @@ -209,7 +209,6 @@ public int getNumberOfMolecules() {
*/
public void markDirty( int index, ICDKMolecule moleculeToSave ) {
assert(moleculeToSave!=null);
moleculeToSave.getAtomContainer().setFlag( 7, true );
edited.put( index, moleculeToSave );
Collection<IPropertyCalculator<?>> propCalcs = retriveCalculatorContributions();

Expand All @@ -220,6 +219,11 @@ public void markDirty( int index, ICDKMolecule moleculeToSave ) {
setPropertyFor( index, key, o );
}
}

@Override
public boolean isDirty( int index ) {
return edited.containsKey( index );
}

public void save() {

Expand Down
Expand Up @@ -31,30 +31,65 @@

public class ListMoleculesEditorModel implements IMoleculesEditorModel,
ISortable {

List<ICDKMolecule> molecules;
List<ICDKMolecule> source;

static class ListElement implements Comparable<ListElement>{
static ListElement newElement(int index,ICDKMolecule mol) {
return new ListElement(index,mol,false);
}
static ListElement changeElement(ListElement element,ICDKMolecule mol) {
return new ListElement(element.index,mol,true);
}

int index;
ICDKMolecule mol;
boolean dirty;

private ListElement(int index,ICDKMolecule mol,boolean dirty) {
this.index = index;
this.mol = mol;
this.dirty = dirty;
}

public boolean isDirty() { return dirty;}
public ICDKMolecule getMolecule() {
return mol;
}

@Override
public int compareTo( ListElement arg0 ) {
return arg0.index - index;
}
}

final List<ListElement> molecules;

Comparator<ICDKMolecule> comparator= null;
boolean dirty = false;

public ListMoleculesEditorModel(List<ICDKMolecule> molecuels) {
this.source = molecuels;
this.molecules = source;
this.molecules = new ArrayList<ListElement>(molecuels.size());
int index = 0;
for(ICDKMolecule mol: molecuels) {
this.molecules.add( ListElement.newElement(index,mol) );

}
}

public ICDKMolecule getMoleculeAt( int index ) {
if(index < molecules.size())
return molecules.get( index );
if(index < molecules.size() || index >= 0)
return molecules.get( index ).getMolecule();
else
return null;
return null;// index out of bounds
}

public int getNumberOfMolecules() { return molecules.size(); }

public void markDirty( int index, ICDKMolecule moleculeToSave ) {
molecules.set( index, moleculeToSave );
dirty= true;
molecules.set( index, ListElement.changeElement( molecules.get( index ), moleculeToSave ) );
dirty=true;
}

public boolean isDirty(int index) {
return molecules.get( index ).isDirty();
}

public void save() {
Expand All @@ -64,7 +99,7 @@ public void save() {

public void setSortingProperties(final List<SortProperty<?>> properties ) {
if(properties.isEmpty()) {
molecules = source;
Collections.sort( molecules);
comparator = null;
return;
}
Expand Down Expand Up @@ -98,38 +133,58 @@ public int compare( ICDKMolecule o1, ICDKMolecule o2 ) {

private void sort() {
if(comparator!=null) {
molecules = new ArrayList<ICDKMolecule>(source);
Collections.sort( molecules, comparator );
Collections.sort( molecules, wrapComparator( comparator ) );
}
}

static private <T extends Comparator<? super ICDKMolecule>> ListElementComparator<T> wrapComparator(T comparator) {
return new ListElementComparator<T>( comparator );
}
static class ListElementComparator<T extends Comparator<? super ICDKMolecule>> implements Comparator<ListElement> {

final T comparator;

public ListElementComparator(T comparator) {
this.comparator = comparator;
}

@Override
public int compare( ListElement o1, ListElement o2 ) {
return comparator.compare( o1.getMolecule(), o2.getMolecule() );
}

}

public Collection<Object> getAvailableProperties() {
Set<Object> props = new HashSet<Object>();
if(!molecules.isEmpty()) {
if(molecules.size() < 100) {
for(ICDKMolecule mol:molecules) {
props.addAll(mol.getAtomContainer().getProperties().keySet());
}
} else
props.addAll(molecules.get(0).getAtomContainer().getProperties().keySet());
List<ListElement> mols = molecules.subList( 0, Math.max(molecules.size(),100) );
for(ListElement m:mols) {
ICDKMolecule mol = m.getMolecule();
props.addAll(mol.getAtomContainer().getProperties().keySet());
}
return props;
}
return Collections.emptyList();
}

public <T> void setPropertyFor( int moleculeIndex, String property, T value ) {

molecules.get( moleculeIndex ).setProperty( property, value );
molecules.get( moleculeIndex ).getMolecule().setProperty( property, value );

}

public void instert( ICDKMolecule... molecules ) {
source.addAll( Arrays.asList( molecules ));
List<ListElement> elements = new ArrayList<ListElement>(molecules.length);
int molCount = this.molecules.size();
for(int i = 0;i < molecules.length;i++) {
elements.add( ListElement.newElement( molCount + i, molecules[i] ) );
}
this.molecules.addAll( elements);
sort();
}

public void delete( int index ) {
ICDKMolecule mol = molecules.remove( index );
source.remove( mol );
ListElement mol = molecules.remove( index );
}
}
Expand Up @@ -70,6 +70,11 @@ public void markDirty( int index,
throw new UnsupportedOperationException();

}

@Override
public boolean isDirty( int index ) {
throw new UnsupportedOperationException();
}

public void save() {
throw new UnsupportedOperationException();
Expand Down
Expand Up @@ -485,8 +485,10 @@ private void updateJCPPage() {
int index = moleculesPage.getMolTableViewer().getFirstSelected();
if(index < 0 ) index = 0;
IMoleculesEditorModel model = moleculesPage.getModel();
if(model != null)
if(model != null) {
jcpPage.setInput( model.getMoleculeAt( index ));
jcpPage.getWidget().setDirty( model.isDirty( index ) );
}
else
jcpPage.setInput( null );
// ISelection selection = moleculesPage.getSelection();
Expand Down
Expand Up @@ -17,7 +17,6 @@
import java.util.HashMap;
import java.util.Map;

import net.bioclipse.cdk.ui.views.MoleculeContentProvider;
import net.bioclipse.core.domain.IMolecule;

import org.eclipse.core.resources.IFile;
Expand All @@ -32,63 +31,6 @@

public class MoleculeContentProviderTest {


@Test
public void testGetChildren() throws CoreException, IOException {

//Create WS with data
Map<String, IFile> files =createWorkspaceWithData();

//Create ContentProvider to test
MoleculeContentProvider provider=new MoleculeContentProvider();

//New file to test, contains one molecule
//================
IFile gbkFile=files.get("sar.sdf");
assertNotNull(gbkFile);

Object[] obj=provider.getChildren(gbkFile);
assertNotNull(obj);
assertEquals(1, obj.length);
assertTrue(obj[0] instanceof IMolecule);

//New file to test
//================
gbkFile=files.get("iterconftest.sdf");
assertNotNull(gbkFile);

obj=provider.getChildren(gbkFile);
assertNotNull(obj);
assertEquals(39, obj.length);
assertTrue(obj[0] instanceof IMolecule);
assertTrue(obj[1] instanceof IMolecule);
assertTrue(obj[2] instanceof IMolecule);
assertTrue(obj[3] instanceof IMolecule);
//...

//New file to test
//================
IFile fastaFile=files.get("0037.cml");
assertNotNull(fastaFile);

obj=provider.getChildren(fastaFile);
assertNotNull(obj);
assertEquals(1, obj.length);
assertTrue(obj[0] instanceof IMolecule);

//New file to test
//================
IFile malFile=files.get("mal.sdf");
assertNotNull(malFile);

obj=provider.getChildren(malFile);
assertNotNull(obj);
assertEquals(3, obj.length);

}



/**
* Supporting method, not a Test
* @return
Expand Down
42 changes: 0 additions & 42 deletions plugins/net.bioclipse.cdk.ui/plugin.xml
Expand Up @@ -17,38 +17,6 @@
</extension>


<extension
point="org.eclipse.ui.navigator.navigatorContent">
<navigatorContent
contentProvider="net.bioclipse.cdk.ui.views.MoleculeContentProvider"
id="net.bioclipse.cdk.ui.views.MoleculeContent"
labelProvider="net.bioclipse.cdk.ui.views.MoleculeLabelProvider"
name="Molecule Content">
<commonSorter
class="net.bioclipse.cdk.ui.SDFElementSorter">
</commonSorter>
<triggerPoints>
<or>
<and>
<instanceof value="org.eclipse.core.resources.IResource"/>
<or>
<test
forcePluginActivation="true"
property="org.eclipse.core.resources.extension"
value="sdf"/>
<test
forcePluginActivation="true"
property="org.eclipse.core.resources.extension"
value="smi">
</test>
</or>
</and>
<instanceof value="net.bioclipse.cdk.ui.model.IMoleculesFromFile" />
<instanceof value="net.bioclipse.cdk.domain.SDFElement" />
</or>
</triggerPoints>
</navigatorContent>
</extension>

<!-- Add MoleculeContent to expand molecules with CDK -->
<!-- Commented untill all bugs blocking bug 766 have been solved
Expand Down Expand Up @@ -505,16 +473,6 @@
primary="true"/>
</extension>

<extension
point="org.eclipse.core.runtime.adapters">
<factory
adaptableType="org.eclipse.ui.IEditorInput"
class="net.bioclipse.cdk.ui.MoleculesEditorModelAdapterFactory">
<adapter
type="net.bioclipse.cdk.ui.views.IMoleculesEditorModel">
</adapter>
</factory>
</extension>

<extension point="org.eclipse.ui.newWizards">
<wizard
Expand Down

This file was deleted.

0 comments on commit fa0e891

Please sign in to comment.