4444import com .jme3 .gde .core .util .datatransfer .CopyMeshDataFromOriginal ;
4545import com .jme3 .gde .core .util .datatransfer .CopyTransformDataFromOriginal ;
4646import com .jme3 .scene .Spatial ;
47+ import java .awt .BorderLayout ;
4748import java .io .IOException ;
4849
4950import java .util .concurrent .Callable ;
5051import java .util .concurrent .atomic .AtomicBoolean ;
5152import java .util .logging .Level ;
5253import java .util .logging .Logger ;
54+ import javax .swing .JCheckBox ;
55+ import javax .swing .JLabel ;
56+ import javax .swing .JPanel ;
57+ import javax .swing .SwingUtilities ;
5358
5459import org .netbeans .api .progress .ProgressHandle ;
5560import org .openide .DialogDisplayer ;
@@ -80,6 +85,15 @@ public class ExternalChangeScanner implements AssetDataPropertyChangeListener,
8085 private final AssetDataObject assetDataObject ;
8186 private final AssetData assetData ;
8287 private FileObject originalObject ;
88+
89+ final String noOption = "No" ;
90+ final String allOption = "All" ;
91+ final String meshOption = "Only mesh data" ;
92+ final String animOption = "Only animation data" ;
93+ // closing window without selection
94+ final int cancel = -1 ;
95+
96+ private Object savedOption ;
8397
8498 public ExternalChangeScanner (AssetDataObject assetDataObject ) {
8599 this .assetDataObject = assetDataObject ;
@@ -115,24 +129,34 @@ public void fileDeleted(FileEvent fe) {
115129 }
116130
117131 private void notifyUser () {
118- if (!userNotified .getAndSet (true )) {
132+ if (savedOption == null && !userNotified .getAndSet (true )) {
119133 //TODO: execute on separate thread?
120134 java .awt .EventQueue .invokeLater (() -> {
121- final String noOption = "No" ;
122- final String allOption = "All" ;
123- final String meshOption = "Only mesh data" ;
124- final String animOption = "Only animation data" ;
135+ JPanel panel = new JPanel ();
136+ panel .setLayout (new BorderLayout ());
137+ panel .add (new JLabel ("Original file for "
138+ + assetDataObject .getName () + " changed\n Try "
139+ + "and reapply data to j3o file?" ), BorderLayout .NORTH );
140+ JCheckBox rememberSelectionBox = new JCheckBox ("Remember selection" );
141+ rememberSelectionBox .setSelected (savedOption != null );
142+ panel .add (rememberSelectionBox , BorderLayout .SOUTH );
143+
125144 final NotifyDescriptor .Confirmation message =
126- new NotifyDescriptor .Confirmation ("Original file for "
127- + assetDataObject .getName () + " changed\n Try "
128- + "and reapply data to j3o file?" ,
145+ new NotifyDescriptor .Confirmation (panel ,
129146 "Original file changed" ,
130147 NotifyDescriptor .YES_NO_CANCEL_OPTION ,
131148 NotifyDescriptor .QUESTION_MESSAGE );
132149 message .setOptions (new Object []{allOption , meshOption , animOption ,
133150 noOption });
151+
134152 DialogDisplayer .getDefault ().notify (message );
135- if (message .getValue ().equals (noOption )) {
153+
154+ if (rememberSelectionBox .isSelected () && !message .getValue ().equals (cancel )) {
155+ savedOption = message .getValue ();
156+ LOGGER .log (Level .INFO , "Saving selection "
157+ + "{0}" , savedOption );
158+ }
159+ if (message .getValue ().equals (cancel ) || message .getValue ().equals (noOption )) {
136160 userNotified .set (false );
137161 return ;
138162 }
@@ -143,6 +167,17 @@ private void notifyUser() {
143167 });
144168 userNotified .set (false );
145169 });
170+ } else if (savedOption != null ) {
171+ LOGGER .log (Level .INFO , "Using saved option "
172+ + "{0}" , savedOption );
173+ if (savedOption .equals (noOption )) {
174+ return ;
175+ }
176+ SceneApplication .getApplication ().enqueue ((Callable <Void >) () -> {
177+ applyExternalData (savedOption .equals (meshOption ),
178+ savedOption .equals (animOption ));
179+ return null ;
180+ });
146181 } else {
147182 LOGGER .log (Level .INFO , "User already notified about change in "
148183 + "{0}" , assetDataObject .getName ());
@@ -173,12 +208,16 @@ private void applyExternalData(final boolean onlyMeshData,
173208 new CopyMaterialDataFromOriginal (finder ).update (spat , original );
174209 }
175210 // Do a complicated recurse refresh since AbstractSceneExplorerNode:refresh() isn't working
176- SceneApplication . getApplication (). enqueue (( Runnable ) () -> {
211+ SwingUtilities . invokeLater ( () -> {
177212 Node rootNode = SceneExplorerTopComponent .findInstance ().getExplorerManager ().getRootContext ();
178213 if (rootNode instanceof JmeNode ) {
214+ SceneApplication .getApplication ().enqueue ((Runnable ) () -> {
179215 refreshNamedSpatial ((JmeNode ) rootNode , spat .getName ());
216+ });
180217 }
181218 });
219+
220+
182221 closeOriginalSpatial ();
183222 assetDataObject .saveAsset ();
184223 } catch (IOException e ) {
0 commit comments