Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #18 from bioclipse/bug3063
Browse files Browse the repository at this point in the history
Adds a 3d tab to the molecules table editor bug 3063
  • Loading branch information
goglepox committed Feb 8, 2013
2 parents 343446a + 42dbb10 commit fca0cc1
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 9 deletions.
3 changes: 2 additions & 1 deletion plugins/net.bioclipse.cdk.ui.sdfeditor/META-INF/MANIFEST.MF
Expand Up @@ -39,7 +39,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.expressions
Bundle-ActivationPolicy: lazy
Import-Package: net.bioclipse.inchi.business,
org.apache.log4j
org.apache.log4j,
org.slf4j
Export-Package: net.bioclipse.cdk.ui.sdfeditor,
net.bioclipse.cdk.ui.sdfeditor.business,
net.bioclipse.cdk.ui.sdfeditor.editor,
Expand Down
Expand Up @@ -151,6 +151,7 @@ else if(newInput instanceof IAdaptable){
properties.add(iter.next());
}
updateHeaders();
moleculeProperties.clear();

// NatTable table = this.viewer.table;
// if ( model instanceof ISortable ) {
Expand Down
Expand Up @@ -324,6 +324,21 @@ public MolTableElement(int index, IMoleculesEditorModel model) {
this.index = index;
}

@SuppressWarnings("unchecked")
public <T> T adaptTo(Class<T> adapter) {
if(adapter.isAssignableFrom( ICDKMolecule.class )) {
return (T) model.getMoleculeAt( index );
}
if(adapter.isAssignableFrom( IPropertySource.class )) {
ICDKMolecule mol = model.getMoleculeAt( index );
if(mol != null && pSource == null) {
pSource = new CDKMoleculePropertySource( mol );
}
return (T)pSource;
}
return (T) Platform.getAdapterManager().getAdapter(this, adapter);
}

@SuppressWarnings("unchecked")
public Object getAdapter( Class adapter ) {

Expand Down
Expand Up @@ -651,6 +651,7 @@ public void setUseExtensionGenerators( boolean useGenerators ) {

public void refresh() {

getMolTableViewer().setInput( getModel() );
molTableViewer.refresh();
}

Expand Down
Expand Up @@ -17,18 +17,19 @@
import java.util.HashMap;
import java.util.Map;

import net.bioclipse.cdk.business.ICDKManager;
import net.bioclipse.cdk.domain.ICDKMolecule;
import net.bioclipse.cdk.domain.MoleculesIndexEditorInput;
import net.bioclipse.cdk.domain.SDFElement;
import net.bioclipse.cdk.jchempaint.editor.JChemPaintEditor;
import net.bioclipse.cdk.ui.sdfeditor.Activator;
import net.bioclipse.cdk.ui.sdfeditor.business.IPropertyCalculator;
import net.bioclipse.cdk.ui.sdfeditor.business.MappingEditorModel;
import net.bioclipse.cdk.ui.sdfeditor.business.SDFIndexEditorModel;
import net.bioclipse.cdk.ui.sdfeditor.editor.MoleculeTableViewer.MolTableElement;
import net.bioclipse.cdk.ui.sdfeditor.handlers.CalculatePropertyHandler;
import net.bioclipse.cdk.ui.views.IFileMoleculesEditorModel;
import net.bioclipse.cdk.ui.views.IMoleculesEditorModel;
import net.bioclipse.core.business.BioclipseException;
import net.bioclipse.core.domain.CMLMolecule;
import net.bioclipse.core.util.LogUtils;
import net.bioclipse.jmol.editors.JmolEditor;
import net.bioclipse.jobs.BioclipseUIJob;
Expand Down Expand Up @@ -63,8 +64,8 @@
import org.eclipse.ui.dialogs.SaveAsDialog;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.part.MultiPageEditorPart;
import org.openscience.cdk.Mapping;
import org.openscience.cdk.renderer.IRenderer;
import org.eclipse.ui.part.Page;
import org.slf4j.LoggerFactory;

public class MultiPageMoleculesEditorPart extends MultiPageEditorPart implements
ISelectionListener,
Expand Down Expand Up @@ -109,6 +110,7 @@ protected void createPages() {
int i;
for(Pages page:new Pages[]{ Pages.Molecules,
Pages.JCP,
// Pages.Jmol,
Pages.Headers,
}) {
switch(page) {
Expand Down Expand Up @@ -171,6 +173,32 @@ public Object getAdapter( Class adapter ) {
pageOrder.put( i, page );
setPageText( i, "Single Molecule" );
break;
case Jmol:
i = addPage( jmolPage = new JmolEditor(),
new IEditorInput() {

public boolean exists() {
return false;
}
public ImageDescriptor getImageDescriptor() {
return null;
}
public String getName() {
return null;
}
public IPersistableElement getPersistable() {
return null;
}
public String getToolTipText() {
return null;
}
@SuppressWarnings("unchecked")
public Object getAdapter( Class adapter ) {
return null;
}
});
pageOrder.put( i, page );
setPageText(i,"3D View");
}
}

Expand Down Expand Up @@ -342,6 +370,9 @@ protected void pageChange( int newPageIndex ) {
updateJCPPage();
jcpActivation = contextService.activateContext( JCP_CONTEXT );
break;
case Jmol:
updateJmolPage();
break;
}

lastPage = pageOrder.get(newPageIndex);
Expand Down Expand Up @@ -389,9 +420,11 @@ private void updateJmolPage() {
ISelection selection = moleculesPage.getSelection();
if(selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection)selection).getFirstElement();
if(element instanceof SDFElement) {
jmolPage.setDataInput( (IEditorInput) ((SDFElement) element)
.getAdapter( MoleculesIndexEditorInput.class ) );
if(element instanceof MolTableElement) {
final ICDKMolecule mol = ((MolTableElement)element).adaptTo( ICDKMolecule.class );
IEditorInput input;
input = new CDKMoleculeEditorInput( mol );
jmolPage.setDataInput(input);
}
}
}
Expand All @@ -404,6 +437,43 @@ public void selectionChanged( IWorkbenchPart part, ISelection selection ) {
// updateJmolPage();
// if(pageOrder.get(getActivePage() ) == Pages.JCP)
// updateJCPPage();
} else if(part == this && selection instanceof IStructuredSelection){
Object elem = ((IStructuredSelection) selection).getFirstElement();
if(elem instanceof MolTableElement) {
final ICDKMolecule mol = ((MolTableElement)elem).adaptTo( ICDKMolecule.class );
ICDKManager cdk = net.bioclipse.cdk.business.Activator.getDefault().getJavaCDKManager();
try {
if(cdk.has3d( mol )) {
// show page
if(!pageOrder.values().contains( Pages.Jmol )){
int i = addPage( jmolPage = new JmolEditor(),
new CDKMoleculeEditorInput(mol){
@Override
public Object getAdapter( Class adapter ) {
return super.getAdapter( adapter );
}
});
pageOrder.put( i, Pages.Jmol );
setPageText( i, "3D" );
}
} else {
//hide page
if(pageOrder.values().contains( Pages.Jmol )) {
for(Integer i : pageOrder.keySet()) {
if(pageOrder.get( i ).equals( Pages.Jmol )) {
removePage( i );
pageOrder.remove( i );
break;
}
}
}
}
} catch ( BioclipseException e) {
// This space is intentionally left blank
} catch ( PartInitException e ) {
logger.error( "Could not create 3d page",e );
}
}
}
}

Expand Down Expand Up @@ -504,3 +574,57 @@ public boolean isJCPVisible() {
}

}

class CDKMoleculeEditorInput implements IEditorInput {
org.slf4j.Logger logger = LoggerFactory.getLogger( CDKMoleculeEditorInput.class );
ICDKMolecule molecule;


public CDKMoleculeEditorInput(ICDKMolecule mol) {
molecule = mol;
}

@SuppressWarnings("unchecked")
@Override
public Object getAdapter( Class adapter ) {
if(adapter.isAssignableFrom( CMLMolecule.class )) {
try {
return new CMLMolecule(molecule.toCML());
} catch ( BioclipseException e ) {
logger.warn( "Could not convert molecule to CML" );
}
}
return null;
}

@Override
public boolean exists() {
return false;
}

@Override
public ImageDescriptor getImageDescriptor() {
return ImageDescriptor.getMissingImageDescriptor();
}

@Override
public String getName() {
String name = molecule.getName();
if(name==null || name.isEmpty()) {
ICDKManager cdk = net.bioclipse.cdk.business.Activator.getDefault().getJavaCDKManager();
name = cdk.molecularFormula( molecule );
}
return name==null?"":name;
}

@Override
public IPersistableElement getPersistable() {
return null;
}

@Override
public String getToolTipText() {
return "";
}

}
Expand Up @@ -900,7 +900,16 @@ public IEditorPart getPart(){
}

public void setDataInput(IEditorInput input){
String data = (String) input.getAdapter( String.class );
String data;
data = (String) input.getAdapter( String.class );
if(data == null) {
try {
data = ((net.bioclipse.core.domain.CMLMolecule)
input.getAdapter(net.bioclipse.core.domain.CMLMolecule.class)).toCML();
} catch ( BioclipseException e ) {
logger.warn( "Could not adapt input to CML" );
}
}
if(jmolPanel != null && data != null) {
jmolPanel.getViewer().openStringInline( data );
}
Expand Down

0 comments on commit fca0cc1

Please sign in to comment.