Skip to content
Snippets Groups Projects
Commit 0fd2ac0d authored by Raphael GIRARDOT's avatar Raphael GIRARDOT
Browse files

URI update bug correction (JAVAAPI-561)

parent 9f55edcc
No related branches found
No related tags found
No related merge requests found
......@@ -166,7 +166,11 @@ public class CDMAUriReader extends AbstractCDMAReader implements IUriTarget, ITe
URI oldURi = this.uri;
this.uri = uri;
uriToString = (uri == null ? null : uri.toString());
// Update "uriDidChange" only if it was false.
// Otherwise, it could provoke a data update bug (JAVAAPI-561)
if (!uriDidChange) {
uriDidChange = (!ObjectUtils.sameObject(oldURi, uri));
}
if (!applyChangeOnNameChange) {
updateReader();
}
......
......@@ -56,9 +56,11 @@ import fr.soleil.lib.project.swing.ITextTransferable;
*/
public abstract class DoubleClickUriTree extends Tree implements ITreeNodeListener, ITextTransferable {
private static final long serialVersionUID = 4691187757299538154L;
private static final long serialVersionUID = 5247579750450411705L;
protected static final String DEFAULT_URI_SELECTION_ERROR_MESSAGE = "URI selection error";
protected static final String FILE = "file";
protected static final String SLASH = "/";
protected final AbstractDataSource<URI> uriSource;
protected final AbstractDataSource<CometeImage> imageSource;
......@@ -215,22 +217,26 @@ public abstract class DoubleClickUriTree extends Tree implements ITreeNodeListen
prepareKey(key);
if (key != null) {
SwingWorker<Boolean, Void> updateWorker = new SwingWorker<Boolean, Void>() {
private ITreeNode refNode = null;
@Override
protected Boolean doInBackground() throws Exception {
boolean isExperiment;
if (!nodes[0].isTreeNodeListenerRegistered(DoubleClickUriTree.this)) {
nodes[0].addTreeNodeListener(DoubleClickUriTree.this);
ITreeNode node = nodes[0];
if (!node.isTreeNodeListenerRegistered(DoubleClickUriTree.this)) {
node.addTreeNodeListener(DoubleClickUriTree.this);
}
// search for children only when not an experiment
URI uri = (URI) nodes[0].getData();
URI uri = (URI) node.getData();
try {
isExperiment = CDMABoxUtils.isExperiment(uri);
} catch (Exception e) {
isExperiment = false;
}
refNode = node;
if (!isExperiment) {
treeNodeMatrixBox.setSynchronTransmission(nodes[0], true);
treeNodeMatrixBox.connectWidget(nodes[0], key, true, true, true);
treeNodeMatrixBox.setSynchronTransmission(node, true);
treeNodeMatrixBox.connectWidget(node, key, true, true, true);
updateRefreshingStrategy(key);
}
return isExperiment;
......@@ -243,7 +249,7 @@ public abstract class DoubleClickUriTree extends Tree implements ITreeNodeListen
TreePath path = getSelectionPath();
expandPath(path);
if (isExperiment.booleanValue()) {
updateURI();
sendURI(refNode);
}
} catch (Exception e) {
if (!(e instanceof InterruptedException)) {
......@@ -253,6 +259,8 @@ public abstract class DoubleClickUriTree extends Tree implements ITreeNodeListen
}
LoggerFactory.getLogger(applicationId).error(getUriSelectionErrorMesage(), error);
}
} finally {
refNode = null;
}
}
};
......@@ -314,19 +322,13 @@ public abstract class DoubleClickUriTree extends Tree implements ITreeNodeListen
}
/**
* Updates associated {@link URI} {@link AbstractDataSource} with selected node's content, if it contains an
* {@link URI}
* Sends an {@link ITreeNode}'s URI and name to associated sources.
*
* @param treeNode The {@link ITreeNode}.
*/
protected void updateURI() {
if (uriSource != null) {
TreePath path = getSelectionPath();
if (path != null) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
if ((node != null) && (node.isLeaf())) {
ITreeNode treeNode = getModel().getTreeNode(node);
URI uri = null;
if ((treeNode != null) && (treeNode.getData() instanceof URI)) {
uri = (URI) treeNode.getData();
protected void sendURI(final ITreeNode treeNode) {
if ((uriSource != null) && (imageSource != null) && (treeNode != null) && (treeNode.getData() instanceof URI)) {
URI uri = (URI) treeNode.getData();
if (updateUriAndName(uri, treeNode.getName(), false)) {
try {
imageSource.setData(treeNode.getImage());
......@@ -336,9 +338,6 @@ public abstract class DoubleClickUriTree extends Tree implements ITreeNodeListen
}
}
}
}
}
}
/**
* Connect the given {@link URI} {@link AbstractDataSource} if it's an experiment.
......@@ -353,13 +352,13 @@ public abstract class DoubleClickUriTree extends Tree implements ITreeNodeListen
// XXX ugly name recovery. Should have a common CDMA method
if (testForFragment) {
if (uri.getFragment() != null) {
name = uri.getFragment().replaceFirst("/", ObjectUtils.EMPTY_STRING);
name = uri.getFragment().replaceFirst(SLASH, ObjectUtils.EMPTY_STRING);
}
} else {
if (uri.getFragment() == null) {
name = uri.toString();
if (name.startsWith("file")) {
if (name.endsWith("/")) {
if (name.startsWith(FILE)) {
if (name.endsWith(SLASH)) {
name = name.substring(0, name.length() - 1);
}
int index = name.lastIndexOf('/');
......@@ -368,7 +367,7 @@ public abstract class DoubleClickUriTree extends Tree implements ITreeNodeListen
}
}
} else {
name = uri.getFragment().replaceFirst("/", ObjectUtils.EMPTY_STRING);
name = uri.getFragment().replaceFirst(SLASH, ObjectUtils.EMPTY_STRING);
}
}
updateUriAndName(uri, name, true);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment