-
Notifications
You must be signed in to change notification settings - Fork 103
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
neph1
merged 2 commits into
jMonkeyEngine:master
from
neph1:ExternalScanner_remember_option
Dec 28, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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)) { | ||
userNotified.set(false); | ||
return; | ||
} | ||
|
@@ -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()); | ||
|
@@ -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(() -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.