Skip to content

Commit

Permalink
Changed save to allow for use of IMoleculesEditorModel.save()
Browse files Browse the repository at this point in the history
Save will use above method while saveAs will open
save file dialog.

Signed-off-by: Egon Willighagen <egon.willighagen@gmail.com>
  • Loading branch information
Arvid Berg authored and egonw committed Aug 13, 2009
1 parent 0efbbd7 commit 6a45928
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 31 deletions.
Expand Up @@ -15,8 +15,6 @@
import net.bioclipse.cdk.domain.ICDKMolecule;
import net.bioclipse.cdk.ui.sdfeditor.editor.SDFIndexEditorModel;
import net.bioclipse.cdk.ui.views.IMoleculesEditorModel;
import net.bioclipse.core.PublishedClass;
import net.bioclipse.core.PublishedMethod;
import net.bioclipse.core.Recorded;
import net.bioclipse.core.business.BioclipseException;
import net.bioclipse.jobs.BioclipseJob;
Expand Down Expand Up @@ -61,7 +59,7 @@ public void calculateProperties( ICDKMolecule molecule,
public void saveSDF(IMoleculesEditorModel model, IFile file)
throws BioclipseException;
public void saveSDF( IMoleculesEditorModel model, IFile file,
BioclipseUIJob<SDFIndexEditorModel> uiJob)
BioclipseUIJob<IMoleculesEditorModel> uiJob)
throws BioclipseException;

@Recorded
Expand Down
Expand Up @@ -21,7 +21,6 @@
import java.nio.channels.ReadableByteChannel;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
Expand Down Expand Up @@ -267,10 +266,8 @@ public void saveSDF( IMoleculesEditorModel model, IFile file,
IReturner<IMoleculesEditorModel> returner,
IProgressMonitor monitor)
throws BioclipseException {
SDFIndexEditorModel index = saveSDF( model, file, monitor );
returner.completeReturn( index);
// return index.getResource().getFullPath().toPortableString();

SDFIndexEditorModel index = saveSDF( model, file, monitor );
returner.completeReturn( index);
}

private SDFIndexEditorModel saveSDF(IMoleculesEditorModel model, IFile file,
Expand All @@ -292,8 +289,9 @@ private SDFIndexEditorModel saveSDF(IMoleculesEditorModel model, IFile file,

IFile target = null;
Collection<Object> availableProperties = null;
if(model instanceof SDFIndexEditorModel)
if(model instanceof SDFIndexEditorModel) // FIXME save properties to sDB
availableProperties = ((SDFIndexEditorModel) model).getPropertyKeys();

SubMonitor loopProgress = subMonitor.newChild( 1000 );
loopProgress.setWorkRemaining( 1000*model.getNumberOfMolecules() );
loopProgress.subTask( "Writing to file" );
Expand Down
Expand Up @@ -59,9 +59,7 @@
import org.eclipse.ui.contexts.IContextService;
import org.eclipse.ui.dialogs.SaveAsDialog;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.part.MultiPageEditorPart;
import org.eclipse.ui.part.Page;

public class MultiPageMoleculesEditorPart extends MultiPageEditorPart implements
ISelectionListener,
Expand Down Expand Up @@ -198,15 +196,15 @@ protected void setActivePage( int pageIndex ) {
@Override
public void doSave( IProgressMonitor monitor ) {
IMoleculesEditorModel model = moleculesPage.getModel();
IResource original = null;
if(model instanceof SDFIndexEditorModel) {
original = ((SDFIndexEditorModel)model).getResource();
}
if(original instanceof IFile) {

syncJCP();
save((IFile)original,model);
}else
doSaveAs();
if(model instanceof SDFIndexEditorModel)
save(model,((SDFIndexEditorModel)model).getSaveFile());
else {
model.save();
jcpPage.getWidget().setDirty( false );
setDirty( false );
}
}

@Override
Expand All @@ -228,24 +226,32 @@ public void doSaveAs() {
moleculesPage.getMolTableViewer().setInput( null );
IPath path = saveAsDialog.getResult();
IFile file= ResourcesPlugin.getWorkspace().getRoot().getFile( path );
save(file,model);
if(model instanceof SDFIndexEditorModel) {
((SDFIndexEditorModel)model).setSaveFile(file);
}
save(model,file);
}

private void save(IFile file,IMoleculesEditorModel model) {
private void save(IMoleculesEditorModel model, IFile file) {
try {
Activator.getDefault().getMoleculeTableManager()
.saveSDF( model, file ,new BioclipseUIJob<SDFIndexEditorModel>() {
.saveSDF( model,file,new BioclipseUIJob<IMoleculesEditorModel>() {

@Override
public void runInUI() {
SDFIndexEditorModel model =getReturnValue();
IMoleculesEditorModel model =getReturnValue();
moleculesPage.getMolTableViewer().setInput( model );
moleculesPage.getMolTableViewer().refresh();
IFile file = (IFile)model.getResource();
setInput( new FileEditorInput(file) );
setPartName( file.getName() );
firePropertyChange( IWorkbenchPartConstants.PROP_PART_NAME);
firePropertyChange( IWorkbenchPartConstants.PROP_INPUT);

// IFile file = (IFile)model.getResource();
// setInput( new FileEditorInput(file) );
if(model instanceof SDFIndexEditorModel) {
IResource origin = ((SDFIndexEditorModel)model).getResource();
if(origin !=null)
setPartName(origin.getName() );
firePropertyChange( IWorkbenchPartConstants.PROP_PART_NAME);
firePropertyChange( IWorkbenchPartConstants.PROP_INPUT);
}
jcpPage.getWidget().setDirty( false );
setDirty( false );
}
Expand Down Expand Up @@ -476,5 +482,5 @@ public boolean isJCPVisible() {
return true;
return false;
}

}
Expand Up @@ -24,7 +24,6 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

import net.bioclipse.cdk.domain.CDKMolecule;
import net.bioclipse.cdk.domain.CDKMoleculeUtils;
Expand All @@ -37,6 +36,7 @@
import net.bioclipse.core.util.LogUtils;

import org.apache.log4j.Logger;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
Expand Down Expand Up @@ -71,6 +71,8 @@ public class SDFIndexEditorModel implements IMoleculesEditorModel,
protected ISimpleChemObjectReader chemReader;
protected IChemObjectBuilder builder;

private IFile saveAs;

int lastIndex = -1;
ICDKMolecule lastRead = null;

Expand All @@ -87,7 +89,7 @@ public class SDFIndexEditorModel implements IMoleculesEditorModel,

private boolean dirty = false;

public SDFIndexEditorModel() {
private SDFIndexEditorModel() {
molProps = new HashMap<Integer, Map<String,Object>>();
propertyList = new HashMap<String, Class<?>>();
chemReader = new MDLV2000Reader();
Expand All @@ -102,6 +104,7 @@ public SDFIndexEditorModel() {
public SDFIndexEditorModel(SDFileIndex input) {
this();
this.input = input;
this.saveAs = input.file();
}

public IResource getResource() {
Expand All @@ -115,6 +118,10 @@ public boolean isDirt() {
public void setDirty(boolean dirty) {
this.dirty = dirty;
}

public IFile getSaveFile() { return saveAs;}
public void setSaveFile(IFile file) { saveAs = file;}

/* (non-Javadoc)
* @see net.bioclipse.cdk.ui.views.IMoleculesEditorModel#getMoleculeAt(int)
*/
Expand Down

0 comments on commit 6a45928

Please sign in to comment.