Skip to content

Commit

Permalink
Merge pull request #6772 from mbien/fix-project-group-window-race
Browse files Browse the repository at this point in the history
Fix Project Group window EDT race condition and update UX
  • Loading branch information
mbien authored Dec 19, 2023
2 parents 82b454b + 240e037 commit f874870
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@

import java.awt.Dialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
import org.netbeans.modules.project.ui.ProjectsRootNode;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
Expand All @@ -40,7 +39,6 @@
import org.openide.util.RequestProcessor;
import static org.netbeans.modules.project.ui.groups.Bundle.*;
import org.netbeans.modules.project.uiapi.BaseUtilities;
import org.netbeans.modules.project.uiapi.Utilities;
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
import org.openide.util.Lookup;
import org.openide.util.lookup.Lookups;
Expand Down Expand Up @@ -76,7 +74,7 @@ public void actionPerformed(ActionEvent e) {
@Messages({
"GroupsMenu.new_title=Create New Group",
"GroupsMenu.new_create=Create Group",
"GroupsMenu.new_cancel=Cancel"
"GroupsMenu.new_close=Close"
})
private static void newGroup() {
final NewGroupPanel panel = new NewGroupPanel();
Expand All @@ -88,16 +86,13 @@ private static void newGroup() {
final JButton create = new JButton(GroupsMenu_new_create());
create.setDefaultCapable(true);
create.setEnabled(panel.isReady());
panel.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (NewGroupPanel.PROP_READY.equals(evt.getPropertyName())) {
create.setEnabled(panel.isReady());
}
panel.addPropertyChangeListener((PropertyChangeEvent evt) -> {
if (NewGroupPanel.PROP_READY.equals(evt.getPropertyName())) {
create.setEnabled(panel.isReady());
}
});
JButton cancel = new JButton(GroupsMenu_new_cancel());
dd.setOptions(new Object[] {create, cancel});
JButton close = new JButton(GroupsMenu_new_close());
dd.setOptions(new Object[] {create, close});
Object result = DialogDisplayer.getDefault().notify(dd);
if (result.equals(create)) {
assert panel.isReady();
Expand All @@ -107,13 +102,13 @@ public void propertyChange(PropertyChangeEvent evt) {
final String name = panel.getNameField();
final String masterProject = panel.getMasterProjectField();
final String directory = panel.getDirectoryField();
RP.post(new Runnable() {
@Override
public void run() {
Group g = NewGroupPanel.create(type, name, autoSync, useOpen, masterProject, directory);
Group.setActiveGroup(g, true);
}
RP.post(() -> {
Group g = NewGroupPanel.create(type, name, autoSync, useOpen, masterProject, directory);
Group.setActiveGroup(g, true);
SwingUtilities.invokeLater(GroupsMenu::manageGroups);
});
} else {
SwingUtilities.invokeLater(GroupsMenu::manageGroups);
}
}

Expand All @@ -125,7 +120,7 @@ public void run() {
"GroupsMenu.manage_select_group=&Select Group",
"GroupsMenu.manage_new_group=&New Group...",
"GroupsMenu.manage_remove=&Remove",
"GroupsMenu.manage_cancel=&Cancel",
"GroupsMenu.manage_close=Close",
"GroupsMenu.manage_properties=&Properties",
})
private static void manageGroups() {
Expand All @@ -137,39 +132,23 @@ private static void manageGroups() {
final JButton select = new JButton();
Mnemonics.setLocalizedText(select, GroupsMenu_manage_select_group());
select.setDefaultCapable(true);
panel.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals("selection")) {
select.setEnabled(panel.isExactlyOneGroupSelected());
}
panel.addPropertyChangeListener((PropertyChangeEvent evt) -> {
if (evt.getPropertyName().equals("selection")) {
select.setEnabled(panel.isExactlyOneGroupSelected());
}
});
select.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
RP.post(new Runnable() {
@Override
public void run() {
Group.setActiveGroup(panel.getSelectedGroups()[0], false);
}
});
}
select.addActionListener((ActionEvent e) -> {
RP.post(() -> Group.setActiveGroup(panel.getSelectedGroups()[0], false));
});
final JButton newGroup = new JButton();
newGroup.setDefaultCapable(false);
Mnemonics.setLocalizedText(newGroup, GroupsMenu_manage_new_group());
newGroup.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
newGroup();
}
});
JButton cancel = new JButton(GroupsMenu_new_cancel());
cancel.setDefaultCapable(false);
dd.setOptions(new Object[] {select, newGroup, cancel});
// invokeLater ensures that the parent is disposed before the new dialog opens
// so that it can set a parent which doesn't disappear - fixes race condition
newGroup.addActionListener(e -> SwingUtilities.invokeLater(GroupsMenu::newGroup));
JButton close = new JButton(GroupsMenu_manage_close());
close.setDefaultCapable(false);
dd.setOptions(new Object[] {select, newGroup, close});
DialogDisplayer.getDefault().notify(dd);
}

Expand All @@ -178,25 +157,16 @@ public void actionPerformed(ActionEvent e) {
*/
@Messages("GroupsMenu.properties_title=Project Group Properties")
static void openProperties(Group g) {
Lookup context = Lookups.fixed(new Object[] { g, BaseUtilities.ACCESSOR.createGroup(g.getName(), g.prefs()) });
Dialog dialog = ProjectCustomizer.createCustomizerDialog("Projects/Groups/Customizer", //NOI18N
context,
(String)null,
new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
//noop
}
},
new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
//noop
}
}, new HelpCtx(HELPCTX));
dialog.setTitle( GroupsMenu_properties_title() );
dialog.setModal(true);
dialog.setVisible(true);
Lookup context = Lookups.fixed(new Object[] { g, BaseUtilities.ACCESSOR.createGroup(g.getName(), g.prefs()) });
Dialog dialog = ProjectCustomizer.createCustomizerDialog("Projects/Groups/Customizer", //NOI18N
context,
(String)null,
(ActionEvent ae) -> {},
(ActionEvent ae) -> {},
new HelpCtx(HELPCTX));
dialog.setTitle( GroupsMenu_properties_title() );
dialog.setModal(true);
dialog.setVisible(true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@
-->

<Form version="1.4" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<Properties>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[600, 250]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[600, 250]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
Expand All @@ -49,10 +41,10 @@
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jScrollPane1" pref="472" max="32767" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="352" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" max="-2" attributes="0">
<Component id="removeAllButton" pref="0" max="32767" attributes="0"/>
<Component id="removeAllButton" pref="106" max="32767" attributes="0"/>
<Component id="propertiesButton" alignment="1" max="32767" attributes="0"/>
<Component id="removeButton" alignment="1" max="32767" attributes="0"/>
</Group>
Expand All @@ -64,7 +56,7 @@
<Component id="jSeparator1" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
Expand Down Expand Up @@ -105,11 +97,6 @@
</Properties>
</Component>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<Properties>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[300, 130]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
Expand All @@ -125,12 +112,6 @@
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/netbeans/modules/project/ui/groups/Bundle.properties" key="ManageGroupsPanel.propertiesButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[105, 29]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[105, 29]"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="propertiesButtonActionPerformed"/>
Expand All @@ -141,12 +122,6 @@
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/netbeans/modules/project/ui/groups/Bundle.properties" key="ManageGroupsPanel.removeButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[87, 29]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[87, 29]"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="removeButtonActionPerformed"/>
Expand All @@ -157,12 +132,6 @@
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/netbeans/modules/project/ui/groups/Bundle.properties" key="ManageGroupsPanel.removeAllButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[87, 29]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[87, 29]"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="removeAllButtonActionPerformed"/>
Expand Down
Loading

0 comments on commit f874870

Please sign in to comment.