You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by sd...@apache.org on 2018/01/25 21:24:44 UTC
[incubator-netbeans] branch master updated: NETBEANS-328: TemplateWizard shows current folder's contents, does no… (#386)
This is an automated email from the ASF dual-hosted git repository.
sdedic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 775de6e NETBEANS-328: TemplateWizard shows current folder's contents, does no… (#386)
775de6e is described below
commit 775de6ef581c5ccec3548db723373d58f99d3db6
Author: Svatopluk Dedic <sv...@oracle.com>
AuthorDate: Thu Jan 25 22:24:41 2018 +0100
NETBEANS-328: TemplateWizard shows current folder's contents, does no… (#386)
NETBEANS-328: TemplateWizard shows current folder's contents, does not freeze on ESC
---
.../org/netbeans/beaninfo/editors/FileEditor.java | 4 +-
.../src/org/openide/WizardDescriptor.java | 3 +-
.../src/org/openide/loaders/TemplateWizard2.java | 60 ++++++++++++++++++++--
3 files changed, 61 insertions(+), 6 deletions(-)
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 de36211..933c2b1 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 class FileEditor extends PropertyEditorSupport implements ExPropertyEdito
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 class FileEditor extends PropertyEditorSupport implements ExPropertyEdito
} 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 c70fd0a..e7d82b2 100644
--- a/openide.dialogs/src/org/openide/WizardDescriptor.java
+++ b/openide.dialogs/src/org/openide/WizardDescriptor.java
@@ -813,8 +813,9 @@ public class WizardDescriptor extends DialogDescriptor {
}
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 2aef246..1c000e7 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 @@ final class TemplateWizard2 extends javax.swing.JPanel implements DocumentListen
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 @@ final class TemplateWizard2 extends javax.swing.JPanel implements DocumentListen
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 @@ final class TemplateWizard2 extends javax.swing.JPanel implements DocumentListen
}
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 @@ final class TemplateWizard2 extends javax.swing.JPanel implements DocumentListen
// 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 @@ final class TemplateWizard2 extends javax.swing.JPanel implements DocumentListen
return ;
File oldLocation = locationFolder;
locationFolder = fd;
+ if (locationFolderModel != null) {
+ locationFolderModel.getFeatureDescriptor().setValue("currentDir", fd); // NOI18N
+ }
firePropertyChange (PROP_LOCATION_FOLDER, oldLocation, locationFolder);
fireStateChanged ();
}
--
To stop receiving notification emails like this one, please contact
sdedic@apache.org.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists