Permalink
Browse files

Added a wizard for adding molecules to QSAR project.

* Page 1: Select molecular files
* Page 2: Optionally select a property that should be imported as response value
+ Added PropertyEntry as model object for properties.
  • Loading branch information...
olas committed Jul 20, 2009
1 parent 45ae223 commit 5b1ba637c522d2ad3c591176ef59594350a1f379
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,97 @@
+package net.bioclipse.qsar.ui.wizards;
+
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.Wizard;
+
+/**
+ * A wizard to select molecules and optionally a property that is used
+ * as reponse value.
+ *
+ * @author ola
+ *
+ */
+public class AddMoleculeFilesWizard extends Wizard{
+
+ private SelectMoleculesPage selectMolPage;
+ private SelectPropertyAsResponsePage selectResponsePage;
+
+ private List<IFile> selectedFiles;
+ private Map<IFile, PropertyEntry> selectedProperties;
+ private List<IResource> blacklist;
+
+ public List<IResource> getBlacklist() {
+ return blacklist;
+ }
+
+ public AddMoleculeFilesWizard(List<IResource> blacklistFilter) {
+ this.blacklist=blacklistFilter;
+ }
+
+ public void setSelectedProperties( Map<IFile, PropertyEntry> selectedProperties ) {
+ this.selectedProperties = selectedProperties;
+ }
+
+ public Map<IFile, PropertyEntry> getSelectedProperties() {
+ return selectedProperties;
+ }
+
+ public void setSelectedFiles( List<IFile> selectedFiles ) {
+ this.selectedFiles = selectedFiles;
+ }
+
+ public List<IFile> getSelectedFiles() {
+ return selectedFiles;
+ }
+
+
+ @Override
+ public void addPages() {
+
+ //Page 1: Select molecular files
+ selectMolPage=new SelectMoleculesPage("Select molecule files to add");
+ addPage(selectMolPage);
+
+ //Page 2: Select properties to use as response values for the molecules
+ selectResponsePage=new SelectPropertyAsResponsePage("Select property as response");
+ addPage( selectResponsePage );
+ }
+
+ /**
+ * When moving from first to second page, we need to send selected resources
+ */
+ @Override
+ public IWizardPage getNextPage( IWizardPage page ) {
+
+ if (page==selectMolPage)
+ selectResponsePage.setInput( selectedFiles );
+
+ return super.getNextPage( page );
+ }
+
+ @Override
+ public boolean canFinish() {
+ //We require a valid molecules selection, and that's it
+ if (selectedFiles==null || selectedFiles.size()<=0)
+ return false;
+
+ return true;
+ }
+
+ @Override
+ public boolean performFinish() {
+
+ //If no properties selected, add file with null propertyentry
+ for (IFile file : selectedFiles){
+ if (!(selectedProperties.keySet().contains( file )))
+ selectedProperties.put( file, null );
+ }
+
+ return true;
+ }
+
+}
@@ -0,0 +1,96 @@
+package net.bioclipse.qsar.ui.wizards;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import net.bioclipse.cdk.business.Activator;
+import net.bioclipse.cdk.business.ICDKManager;
+import net.bioclipse.cdk.domain.ICDKMolecule;
+import net.bioclipse.chemoinformatics.util.ChemoinformaticUtils;
+import net.bioclipse.core.business.BioclipseException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ *
+ * @author ola
+ *
+ */
+public class MoleculePropertyContentProvider implements ITreeContentProvider{
+
+ private static final Object[] EMPTY_CHILDREN = new Object[0];
+
+ public Object[] getChildren( Object parentElement ) {
+
+ if (!( parentElement instanceof IFile ))
+ return EMPTY_CHILDREN;
+
+ IFile molfile=(IFile)parentElement;
+
+ ICDKManager cdk = Activator.getDefault().getJavaCDKManager();
+ ICDKMolecule cdkmol=null;
+
+ try {
+ //Handle multiple mols separately since might take a long time parse
+ if (ChemoinformaticUtils.isMultipleMolecule( molfile)){
+ Iterator<ICDKMolecule> it;
+ it = cdk.createMoleculeIterator( molfile );
+ cdkmol=it.next();
+ }else{
+ //Single mol, just parse
+ cdkmol = cdk.loadMolecule( molfile );
+ }
+ } catch ( CoreException e ) {
+ e.printStackTrace();
+ return EMPTY_CHILDREN;
+ } catch ( IOException e ) {
+ e.printStackTrace();
+ return EMPTY_CHILDREN;
+ } catch ( BioclipseException e ) {
+ e.printStackTrace();
+ return EMPTY_CHILDREN;
+ }
+
+ List<PropertyEntry> props = new ArrayList<PropertyEntry>();
+
+ if (cdkmol.getAtomContainer().getProperties()!=null){
+ for (Object obj : cdkmol.getAtomContainer().getProperties().keySet()){
+ PropertyEntry prop=new PropertyEntry(molfile, obj);
+ props.add( prop );
+ }
+ }
+
+ return props.toArray();
+
+ }
+
+ public Object getParent( Object element ) {
+ if ( element instanceof PropertyEntry ) {
+ PropertyEntry prop = (PropertyEntry) element;
+ return prop.getParent();
+ }
+ return null;
+ }
+
+ public boolean hasChildren( Object element ) {
+ return getChildren( element ).length >0 ? true : false;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object[] getElements( Object inputElement ) {
+ List<IFile> reslist = (List<IFile>) inputElement;
+ return reslist.toArray();
+ }
+
+ public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) {
+ }
+
+ public void dispose() {
+ }
+
+}
@@ -0,0 +1,93 @@
+package net.bioclipse.qsar.ui.wizards;
+
+import java.io.IOException;
+import java.util.Map;
+
+import net.bioclipse.chemoinformatics.util.ChemoinformaticUtils;
+import net.bioclipse.qsar.ui.Activator;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ *
+ * @author ola
+ *
+ */
+public class MoleculePropertyLabelProvider implements ILabelProvider {
+
+ private Image singleIcon;
+ private Image multiIcon;
+ private Image propIcon;
+ private Map<IFile, PropertyEntry> selectedProperties;
+
+ public MoleculePropertyLabelProvider(Map<IFile, PropertyEntry> selectedProperties) {
+
+ //Init the images
+ singleIcon=Activator
+ .getImageDescriptor( "icons/benzene.gif" ).createImage();
+ multiIcon=Activator
+ .getImageDescriptor( "icons/moltable.png" ).createImage();
+ propIcon=Activator
+ .getImageDescriptor( "icons/property.gif" ).createImage();
+
+ //We need to cache this to be able to look up the selected elements
+ this.selectedProperties=selectedProperties;
+ }
+
+ public Image getImage( Object element ) {
+ if ( element instanceof IFile ) {
+ IFile file = (IFile) element;
+ try {
+ if (ChemoinformaticUtils.isMolecule( file ))
+ return singleIcon;
+ if (ChemoinformaticUtils.isMultipleMolecule( file ))
+ return multiIcon;
+ } catch ( CoreException e ) {
+ } catch ( IOException e ) {
+ }
+ }
+
+ if ( element instanceof PropertyEntry ) {
+ return propIcon;
+ }
+
+ return null;
+ }
+
+ public String getText( Object element ) {
+
+ if ( element instanceof IFile ) {
+ return ((IFile) element).getName();
+ }
+ if ( element instanceof PropertyEntry ) {
+ PropertyEntry prop = (PropertyEntry) element;
+ String ret = prop.getPropObject().toString();
+ if (selectedProperties.get( prop.getParent() ) != null){
+ if (selectedProperties.get( prop.getParent() ).equals( prop )){
+ ret = ret + " [SELECTED]";
+ }
+ }
+ return ret;
+ }
+
+ return "???";
+ }
+
+ public void addListener( ILabelProviderListener listener ) {
+ }
+
+ public void dispose() {
+ }
+
+ public boolean isLabelProperty( Object element, String property ) {
+ return false;
+ }
+
+ public void removeListener( ILabelProviderListener listener ) {
+ }
+
+}
@@ -0,0 +1,37 @@
+package net.bioclipse.qsar.ui.wizards;
+
+import org.eclipse.core.resources.IFile;
+
+
+public class PropertyEntry {
+
+ IFile parent;
+ Object propObject;
+
+ public IFile getParent() {
+ return parent;
+ }
+ public Object getPropObject() {
+ return propObject;
+ }
+
+ public PropertyEntry(IFile molfile, Object obj) {
+ parent=molfile;
+ propObject=obj;
+ }
+
+ @Override
+ public boolean equals( Object obj ) {
+
+ if ( obj instanceof PropertyEntry ) {
+ PropertyEntry pe = (PropertyEntry) obj;
+ if ((pe.getParent().equals( parent ))
+ &&
+ pe.getPropObject().toString().equals( propObject.toString()))
+ return true;
+ }
+
+ return false;
+ }
+
+}
Oops, something went wrong.

0 comments on commit 5b1ba63

Please sign in to comment.