Skip to content

Commit

Permalink
Merge pull request ome#5793 from jburel/open-with
Browse files Browse the repository at this point in the history
Open with
  • Loading branch information
sbesson authored Jul 3, 2018
2 parents 4f2fffc + 61a1a72 commit a1d9686
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,7 @@ public class LookupNames

/** Lookup name used to identify the status of the server*/
public static final String CAN_CREATE = "canCreate";

/** Lookup name used to identify the format to use to download the data when using open with*/
public static final String OPEN_WITH_DATA = "/services/OpenWith/Original";
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/*
* org.openmicroscopy.shoola.env.ui.OpenObjectActivity
*
*------------------------------------------------------------------------------
* Copyright (C) 2006-2015 University of Dundee. All rights reserved.
* Copyright (C) 2006-2018 University of Dundee. All rights reserved.
*
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -23,18 +21,13 @@
package org.openmicroscopy.shoola.env.ui;


//Java imports
import java.io.File;

//Third-party libraries


import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
//Application-internal dependencies
import org.openmicroscopy.shoola.env.LookupNames;

import org.openmicroscopy.shoola.env.config.Registry;
import org.openmicroscopy.shoola.env.data.model.ApplicationData;
import org.openmicroscopy.shoola.env.data.model.OpenActivityParam;
Expand Down Expand Up @@ -98,11 +91,16 @@ public OpenObjectActivity(UserNotifier viewer, Registry registry,
*/
protected UserNotifierLoader createLoader()
{
loader = new OpenObjectLoader(viewer, registry, ctx,
parameters.getObject(),
parameters.getFolderPath(), this);
return loader;
}
Boolean value = (Boolean) registry.lookup(LookupNames.OPEN_WITH_DATA);
boolean originalImage = false;
if (value != null) {
originalImage = value.booleanValue();
}
loader = new OpenObjectLoader(viewer, registry, ctx,
parameters.getObject(), parameters.getFolderPath(),
originalImage, this);
return loader;
}

/**
* Modifies the text of the component and opens the application.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*------------------------------------------------------------------------------
* Copyright (C) 2006-2015 University of Dundee. All rights reserved.
* Copyright (C) 2006-2018 University of Dundee. All rights reserved.
*
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -21,6 +21,10 @@
package org.openmicroscopy.shoola.env.ui;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.openmicroscopy.shoola.env.config.Registry;

Expand Down Expand Up @@ -57,7 +61,37 @@ public class OpenObjectLoader

/** The file where to export the object. */
private String folderPath;


private boolean originalImage;

/**
* Creates a new instance.
*
* @param viewer The viewer this data loader is for.
* Mustn't be <code>null</code>.
* @param registry Convenience reference for subclasses.
* @param ctx The security context.
* @param object The object to handle.
* @param folderPath The folder where to copy locally the object.
* @param originalImage Download the original image if <code>True</code>
* otherwise export as OME-TIFF.
* @param activity The activity associated to this loader.
*/
public OpenObjectLoader(UserNotifier viewer, Registry registry,
SecurityContext ctx, DataObject object, String folderPath,
boolean originalImage, ActivityComponent activity)
{
super(viewer, registry, ctx, activity);
if (object == null)
throw new IllegalArgumentException("Object not valid.");
if (!(object instanceof ImageData ||
object instanceof FileAnnotationData))
throw new IllegalArgumentException("Object not valid.");
this.object = object;
this.folderPath = folderPath;
this.originalImage = originalImage;
}

/**
* Creates a new instance.
*
Expand All @@ -73,14 +107,7 @@ public OpenObjectLoader(UserNotifier viewer, Registry registry,
SecurityContext ctx, DataObject object, String folderPath,
ActivityComponent activity)
{
super(viewer, registry, ctx, activity);
if (object == null)
throw new IllegalArgumentException("Object not valid.");
if (!(object instanceof ImageData ||
object instanceof FileAnnotationData))
throw new IllegalArgumentException("Object not valid.");
this.object = object;
this.folderPath = folderPath;
this(viewer, registry, ctx, object, folderPath, false, activity);
}

/**
Expand All @@ -93,14 +120,22 @@ public void load()
File f;
if (object instanceof ImageData) {
ImageData image = (ImageData) object;
String name = image.getName();
name += image.getName();
name += "_"+image.getId();
path += UIUtilities.replaceNonWordCharacters(name)+"."+OMETIFFFilter.OME_TIFF;
f = new File(path);
f.deleteOnExit();
handle = ivView.exportImageAsOMETiff(ctx, image.getId(), f, null,
this);
if (originalImage) {
List<DataObject> objects = new ArrayList<DataObject>();
objects.add(image);
f = new File(folderPath);
handle = mhView.loadArchivedImage(ctx, objects, f, false, false,
false, this);
} else {
String name = image.getName();
name += image.getName();
name += "_"+image.getId();
path += UIUtilities.replaceNonWordCharacters(name)+"."+OMETIFFFilter.OME_TIFF;
f = new File(path);
f.deleteOnExit();
handle = ivView.exportImageAsOMETiff(ctx, image.getId(), f, null,
this);
}
} else {
FileAnnotationData fa = (FileAnnotationData) object;
path += UIUtilities.replaceNonWordCharacters(fa.getFileName());
Expand Down Expand Up @@ -142,7 +177,23 @@ protected void onException(String message, Throwable ex) {
public void handleResult(Object result)
{
if (result == null) onException(MESSAGE_RESULT, null);
else activity.endActivity(result);
else {
if (originalImage) {
Map<Boolean, List<File>> r = (Map<Boolean, List<File>>) result;
List<File> files = r.get(true);
if (files.size() > 0) {
Iterator<File> i = files.iterator();
while (i.hasNext()) {
i.next().deleteOnExit();
}
activity.endActivity(files.get(0));
} else {
onException(MESSAGE_RESULT, null);
}
} else {
activity.endActivity(result);
}
}
}

}
5 changes: 5 additions & 0 deletions components/insight/config/container.xml
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@
* 1: indicate to display the user's data. Default value
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
<entry name="DataDisplay" type="integer">1</entry>
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Information indicating to load the original file instead of OME-TIFF
when using the Open With option
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
<entry name="/services/OpenWith/Original" type="boolean">false</entry>
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Information indicating the dependencies when the client is used as a plugin
* e.g. as an ImageJ plugin.
Expand Down

0 comments on commit a1d9686

Please sign in to comment.