You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/01/25 21:24:45 UTC

[GitHub] sdedic closed pull request #386: NETBEANS-328: TemplateWizard shows current folder's contents, does no?

sdedic closed pull request #386: NETBEANS-328: TemplateWizard shows current folder's contents, does no?
URL: https://github.com/apache/incubator-netbeans/pull/386
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/o.n.core/src/org/netbeans/beaninfo/editors/FileEditor.java b/o.n.core/src/org/netbeans/beaninfo/editors/FileEditor.java
index de36211e8..933c2b1ab 100644
--- a/o.n.core/src/org/netbeans/beaninfo/editors/FileEditor.java
+++ b/o.n.core/src/org/netbeans/beaninfo/editors/FileEditor.java
@@ -222,6 +222,9 @@ public Component getCustomEditor() {
             if (originalFile != null && ! originalFile.isAbsolute() && baseDirectory != null) {
                 originalFile = new File(baseDirectory, originalFile.getPath());
             }
+            // must precede setting of the selected file, in order to properly set 
+            // the name textfield in case of directory selection.
+            chooser.setFileSelectionMode(mode);
             if (currentDirectory != null) {
                 chooser.setCurrentDirectory (currentDirectory);
             } else if (originalFile != null && originalFile.getParentFile() != null) {
@@ -230,7 +233,6 @@ public Component getCustomEditor() {
             } else if (lastCurrentDir != null) {
                 chooser.setCurrentDirectory(lastCurrentDir);
             }
-            chooser.setFileSelectionMode(mode);
             if (fileFilter != null) {
                 chooser.setFileFilter(fileFilter);
             }
diff --git a/openide.dialogs/src/org/openide/WizardDescriptor.java b/openide.dialogs/src/org/openide/WizardDescriptor.java
index c70fd0a9c..e7d82b2d2 100644
--- a/openide.dialogs/src/org/openide/WizardDescriptor.java
+++ b/openide.dialogs/src/org/openide/WizardDescriptor.java
@@ -813,8 +813,9 @@ private static void checkComponent(Panel<?> pnl) {
     }
 
     private <A> void updateStateOpen(SettingsAndIterator<A> data) {
-        if( !initialized.get() ) //#220286
+        if (!initialized.get()) { //#220286 
             return;
+        }
         
         Panel<A> p = data.getIterator(this).current();
         checkComponent(p);
diff --git a/openide.loaders/src/org/openide/loaders/TemplateWizard2.java b/openide.loaders/src/org/openide/loaders/TemplateWizard2.java
index 2aef2467a..1c000e754 100644
--- a/openide.loaders/src/org/openide/loaders/TemplateWizard2.java
+++ b/openide.loaders/src/org/openide/loaders/TemplateWizard2.java
@@ -20,6 +20,8 @@
 package org.openide.loaders;
 
 import java.awt.event.KeyEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.beans.PropertyDescriptor;
 import java.io.File;
 import java.io.IOException;
@@ -151,6 +153,17 @@ void addChangeListener(ChangeListener l) {
         listener = l;
     }    
     
+    /**
+     * Tracks whether setValue was called on the wizard to switch / close panels.
+     * Should be reset when this panel becomes visible.
+     */
+    private boolean setValueCalled;
+    
+    /**
+     * Reference to the current wizard
+     */
+    private TemplateWizard theWizard;
+    
     public void addNotify () {
         super.addNotify();
         //Fix for issue 31086, initial focus on Back button 
@@ -158,8 +171,25 @@ public void addNotify () {
         getAccessibleContext().setAccessibleDescription(
             NbBundle.getBundle(TemplateWizard2.class).getString ("ACSD_TemplateWizard2") // NOI18N
         );
+        setValueCalled = false;
     }
     
+    @Override
+    public void removeNotify() {
+        if (!setValueCalled) {
+            // record wizard close if the panel was just removed;
+            // this is the case of ESC pressed in file chooser.
+            theWizard.setValue(WizardDescriptor.CLOSED_OPTION);
+        }
+        super.removeNotify();
+    }
+
+    /**
+     * Prevents Wizard listener from GC. TemplateWizard do not hard-reference
+     * this Panel through property change listener.
+     */
+    private PropertyChangeListener valueChangedL;
+    
     /** Helper implementation of WizardDescription.Panel for TemplateWizard.Panel2.
      * Provides the wizard panel with the current data--either
      * the default data or already-modified settings, if the user used the previous and/or next buttons.
@@ -181,12 +211,30 @@ void implReadSettings(Object settings) {
         }
         
         setNewObjectName (wizard.getTargetName ());
-
+        
         try {
             setLocationDataFolder(wizard.getTargetFolder());
         } catch (IOException ioe) {
             setLocationFolder (null);
         }
+        assert this.theWizard == null || this.theWizard == wizard;
+        this.theWizard = wizard;
+        if (valueChangedL == null) {
+            // listener records that setValue() was called on the WizardDescriptor
+            // before the panel goes away. If the panel is just removed,
+            // it is assumed that the Wizard got closed.
+            valueChangedL = new PropertyChangeListener() {
+                @Override
+                public void propertyChange(PropertyChangeEvent evt) {
+                    if (WizardDescriptor.PROP_VALUE.equals(evt.getPropertyName()) 
+                        && isDisplayable()) {
+                        setValueCalled = true;
+                    }
+                }
+            };
+            wizard.addPropertyChangeListener(WeakListeners.propertyChange(valueChangedL, 
+                    WizardDescriptor.PROP_VALUE, wizard));
+        }
     }
     
     /** Remove a listener to changes of the panel's validity.
@@ -239,11 +287,12 @@ String implIsValid () {
         // target filesystem should be writable
         if (!lF.getPrimaryFile().canWrite())
             return NbBundle.getMessage(TemplateWizard2.class, "MSG_fs_is_readonly"); // NOI18N
-        
-        if (locationFolder.exists()) {
+
+        FileObject target = lF.getPrimaryFile().getFileObject(newObjectName.getText(), extension);
+        if (target != null) {
             return NbBundle.getMessage(TemplateWizard2.class, "MSG_file_already_exist", locationFolder.getAbsolutePath()); // NOI18N
         }
-
+        
         if ((Utilities.isWindows () || (Utilities.getOperatingSystem () == Utilities.OS_OS2))) {
             if (TemplateWizard.checkCaseInsensitiveName(lF.getPrimaryFile(), newObjectName.getText(), extension)) {
                 return NbBundle.getMessage(TemplateWizard2.class, "MSG_file_already_exist", newObjectName.getText ()); // NOI18N
@@ -350,6 +399,9 @@ public void setLocationFolder(File fd) {
             return ;
         File oldLocation = locationFolder;
         locationFolder = fd;
+        if (locationFolderModel != null) {
+            locationFolderModel.getFeatureDescriptor().setValue("currentDir", fd); // NOI18N
+        }
         firePropertyChange (PROP_LOCATION_FOLDER, oldLocation, locationFolder);
         fireStateChanged ();
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists