Skip to content

ExternalChangeScanner bug fixes and improvement #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 49 additions & 10 deletions jme3-core/src/com/jme3/gde/core/assets/ExternalChangeScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,17 @@
import com.jme3.gde.core.util.datatransfer.CopyMeshDataFromOriginal;
import com.jme3.gde.core.util.datatransfer.CopyTransformDataFromOriginal;
import com.jme3.scene.Spatial;
import java.awt.BorderLayout;
import java.io.IOException;

import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import org.netbeans.api.progress.ProgressHandle;
import org.openide.DialogDisplayer;
Expand Down Expand Up @@ -80,6 +85,15 @@ public class ExternalChangeScanner implements AssetDataPropertyChangeListener,
private final AssetDataObject assetDataObject;
private final AssetData assetData;
private FileObject originalObject;

final String noOption = "No";
final String allOption = "All";
final String meshOption = "Only mesh data";
final String animOption = "Only animation data";
// closing window without selection
final int cancel = -1;

private Object savedOption;

public ExternalChangeScanner(AssetDataObject assetDataObject) {
this.assetDataObject = assetDataObject;
Expand Down Expand Up @@ -115,24 +129,34 @@ public void fileDeleted(FileEvent fe) {
}

private void notifyUser() {
if (!userNotified.getAndSet(true)) {
if (savedOption == null && !userNotified.getAndSet(true)) {
//TODO: execute on separate thread?
java.awt.EventQueue.invokeLater(() -> {
final String noOption = "No";
final String allOption = "All";
final String meshOption = "Only mesh data";
final String animOption = "Only animation data";
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(new JLabel("Original file for "
+ assetDataObject.getName() + " changed\n Try "
+ "and reapply data to j3o file?"), BorderLayout.NORTH);
JCheckBox rememberSelectionBox = new JCheckBox("Remember selection");
rememberSelectionBox.setSelected(savedOption != null);
panel.add(rememberSelectionBox, BorderLayout.SOUTH);

final NotifyDescriptor.Confirmation message =
new NotifyDescriptor.Confirmation("Original file for "
+ assetDataObject.getName() + " changed\nTry "
+ "and reapply data to j3o file?",
new NotifyDescriptor.Confirmation(panel ,
"Original file changed",
NotifyDescriptor.YES_NO_CANCEL_OPTION,
NotifyDescriptor.QUESTION_MESSAGE);
message.setOptions(new Object[]{allOption, meshOption, animOption,
noOption});

DialogDisplayer.getDefault().notify(message);
if (message.getValue().equals(noOption)) {

if(rememberSelectionBox.isSelected() && !message.getValue().equals(cancel)) {
savedOption = message.getValue();
LOGGER.log(Level.INFO, "Saving selection "
+ "{0}", savedOption);
}
if (message.getValue().equals(cancel) || message.getValue().equals(noOption)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously didn't handle pressing the "x" to close the window.

userNotified.set(false);
return;
}
Expand All @@ -143,6 +167,17 @@ private void notifyUser() {
});
userNotified.set(false);
});
} else if(savedOption != null) {
LOGGER.log(Level.INFO, "Using saved option "
+ "{0}", savedOption);
if(savedOption.equals(noOption)) {
return;
}
SceneApplication.getApplication().enqueue((Callable<Void>) () -> {
applyExternalData(savedOption.equals(meshOption),
savedOption.equals(animOption));
return null;
});
} else {
LOGGER.log(Level.INFO, "User already notified about change in "
+ "{0}", assetDataObject.getName());
Expand Down Expand Up @@ -173,12 +208,16 @@ private void applyExternalData(final boolean onlyMeshData,
new CopyMaterialDataFromOriginal(finder).update(spat, original);
}
// Do a complicated recurse refresh since AbstractSceneExplorerNode:refresh() isn't working
SceneApplication.getApplication().enqueue((Runnable) () -> {
SwingUtilities.invokeLater(() -> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solves an exception I don't remember seeing before

Node rootNode = SceneExplorerTopComponent.findInstance().getExplorerManager().getRootContext();
if (rootNode instanceof JmeNode) {
SceneApplication.getApplication().enqueue((Runnable) () -> {
refreshNamedSpatial((JmeNode) rootNode, spat.getName());
});
}
});


closeOriginalSpatial();
assetDataObject.saveAsset();
} catch (IOException e) {
Expand Down