Index: projects/src/org/netbeans/modules/ruby/rubyproject/gems/GemPanel.java =================================================================== RCS file: /cvs/ruby/projects/src/org/netbeans/modules/ruby/rubyproject/gems/Attic/GemPanel.java,v --- projects/src/org/netbeans/modules/ruby/rubyproject/gems/GemPanel.java 30 Oct 2007 21:16:51 -0000 1.11 +++ projects/src/org/netbeans/modules/ruby/rubyproject/gems/GemPanel.java 30 Nov 2007 18:59:37 -0000 @@ -55,6 +55,7 @@ import javax.swing.JTextField; import javax.swing.JTextPane; import javax.swing.ListSelectionModel; +import javax.swing.SwingUtilities; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import org.netbeans.api.options.OptionsDisplayer; @@ -134,10 +135,16 @@ public void run() { // This will also update the New and Installed lists because Update depends on these - refreshUpdated(); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + refreshUpdated(); + } + }); } private void updateGemDescription(JTextPane pane, Gem gem) { + assert SwingUtilities.isEventDispatchThread(); + if (gem == null) { pane.setText(""); return; @@ -196,6 +203,8 @@ * @return True iff we're done with the updates */ private synchronized boolean updateGems() { + assert SwingUtilities.isEventDispatchThread(); + if (!(fetchingRemote || fetchingLocal)) { updatedProgress.setVisible(false); updatedProgressLabel.setVisible(false); @@ -250,6 +259,8 @@ } private void updateList(int tab, boolean showCount) { + assert SwingUtilities.isEventDispatchThread(); + Pattern pattern = null; String filter = getGemFilter(tab); String lcFilter = null; @@ -351,6 +362,8 @@ } private synchronized void refreshInstalled(boolean fetch) { + assert SwingUtilities.isEventDispatchThread(); + if (installedList.getSelectedIndex() != -1) { updateGemDescription(installedDesc, null); } @@ -364,6 +377,8 @@ } private synchronized void refreshNew(boolean fetch) { + assert SwingUtilities.isEventDispatchThread(); + if (newList.getSelectedIndex() != -1) { updateGemDescription(newDesc, null); } @@ -376,6 +391,8 @@ } private void refreshUpdated() { + assert SwingUtilities.isEventDispatchThread(); + if (updatedList.getSelectedIndex() != -1) { updateGemDescription(updatedDesc, null); } @@ -790,6 +807,8 @@ }//GEN-LAST:event_reloadReposButtonActionPerformed private void installButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_installButtonActionPerformed + assert SwingUtilities.isEventDispatchThread(); + int[] indices = newList.getSelectedIndices(); List gems = new ArrayList(); for (int index : indices) { @@ -836,6 +855,8 @@ }//GEN-LAST:event_updateAllButtonActionPerformed private void updateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateButtonActionPerformed + assert SwingUtilities.isEventDispatchThread(); + int[] indices = updatedList.getSelectedIndices(); List gems = new ArrayList(); if (indices != null) { @@ -856,6 +877,8 @@ }//GEN-LAST:event_updateButtonActionPerformed private void uninstallButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uninstallButtonActionPerformed + assert SwingUtilities.isEventDispatchThread(); + int[] indices = installedList.getSelectedIndices(); List gems = new ArrayList(); if (indices != null) { @@ -884,6 +907,7 @@ Runnable runner = new Runnable() { public void run() { synchronized(this) { + assert !SwingUtilities.isEventDispatchThread(); List lines = new ArrayList(500); if (tab == INSTALLED_TAB_INDEX) { installedGems = gemManager.reloadInstalledGems(lines); @@ -897,15 +921,19 @@ fetchingRemote = false; } - // Recompute lists - boolean done = updateGems(); - - if (!done) { - // Just filter - updateList(tab, false); - } else if (tab == INSTALLED_TAB_INDEX) { - updateList(tab, true); - } + // Update UI + SwingUtilities.invokeLater(new Runnable() { + public void run() { + boolean done = updateGems(); + + if (!done) { + // Just filter + updateList(tab, false); + } else if (tab == INSTALLED_TAB_INDEX) { + updateList(tab, true); + } + } + }); } } }; @@ -917,6 +945,8 @@ Runnable runner = new Runnable() { public void run() { synchronized(this) { + assert !SwingUtilities.isEventDispatchThread(); + List lines = Collections.emptyList(); remoteFailure = null; if (!useCached) { @@ -932,14 +962,18 @@ remoteFailure = lines; } - // Recompute lists - updateGems(); - updateList(INSTALLED_TAB_INDEX, true); - - if (remoteFailure != null && !fetchingLocal) { - // Update the local list which shouldn't have any errors - refreshInstalled(true); - } + // Update UI + SwingUtilities.invokeLater(new Runnable() { + public void run() { + updateGems(); + updateList(INSTALLED_TAB_INDEX, true); + + if (remoteFailure != null && !fetchingLocal) { + // Update the local list which shouldn't have any errors + refreshInstalled(true); + } + } + }); } } }; @@ -948,6 +982,8 @@ } private String getGemFilter(int tab) { + assert SwingUtilities.isEventDispatchThread(); + String filter = null; JTextField tf; if (tab == INSTALLED_TAB_INDEX) { Index: railsprojects/src/org/netbeans/modules/ruby/railsprojects/plugins/PluginPanel.java =================================================================== RCS file: /cvs/ruby/railsprojects/src/org/netbeans/modules/ruby/railsprojects/plugins/PluginPanel.java,v --- railsprojects/src/org/netbeans/modules/ruby/railsprojects/plugins/PluginPanel.java 22 Oct 2007 21:41:03 -0000 1.10 +++ railsprojects/src/org/netbeans/modules/ruby/railsprojects/plugins/PluginPanel.java 30 Nov 2007 18:59:37 -0000 @@ -52,6 +52,7 @@ import javax.swing.JList; import javax.swing.JTextField; import javax.swing.ListSelectionModel; +import javax.swing.SwingUtilities; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import org.netbeans.api.options.OptionsDisplayer; @@ -474,6 +475,8 @@ }//GEN-LAST:event_reloadNewButtonActionPerformed private void addUrlButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addUrlButtonActionPerformed + assert SwingUtilities.isEventDispatchThread(); + NewUrlPanel panel = new NewUrlPanel(); DialogDescriptor descriptor = new DialogDescriptor(panel, NbBundle.getMessage(PluginPanel.class, @@ -503,6 +506,8 @@ }//GEN-LAST:event_proxyButtonActionPerformed private void discoverButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_discoverButtonActionPerformed + assert SwingUtilities.isEventDispatchThread(); + // Bring up a selection list String wait = getWaitMsg(); RepositorySelectionPanel panel = new RepositorySelectionPanel(); @@ -557,6 +562,8 @@ }//GEN-LAST:event_reloadReposButtonActionPerformed private void unregisterButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_unregisterButtonActionPerformed + assert SwingUtilities.isEventDispatchThread(); + int[] indices = repositoryList.getSelectedIndices(); List repositories = new ArrayList(); if (indices != null) { @@ -580,6 +587,8 @@ }//GEN-LAST:event_unregisterButtonActionPerformed private void repositoryPanelComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_repositoryPanelComponentShown + assert SwingUtilities.isEventDispatchThread(); + // Make sure the list is shown if (!repositoriesInitialized) { repositoriesInitialized = true; @@ -603,6 +612,8 @@ }//GEN-LAST:event_repositoryPanelComponentShown private void newPanelComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_newPanelComponentShown + assert SwingUtilities.isEventDispatchThread(); + // Make sure the list is shown if (!newInitialized) { newInitialized = true; @@ -617,6 +628,8 @@ }//GEN-LAST:event_newPanelComponentShown private void installButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_installButtonActionPerformed + assert SwingUtilities.isEventDispatchThread(); + int[] indices = newList.getSelectedIndices(); List plugins = new ArrayList(); for (int index : indices) { @@ -639,7 +652,7 @@ if (result.equals(NotifyDescriptor.OK_OPTION)) { Plugin plugin = new Plugin(panel.getPluginName(), null); // XXX Do I really need to refresh it right way? - PluginListRefresher completionTask = new PluginListRefresher(newList, true); + PluginListRefresher completionTask = new PluginListRefresher(newList, false); boolean changed = pluginManager.install(new Plugin[] { plugin }, this, null, panel.isSvnExternals(), panel.isSvnCheckout(), panel.getRevision(), true, completionTask); installedModified = installedModified || changed; @@ -660,6 +673,8 @@ }//GEN-LAST:event_updateAllButtonActionPerformed private void updateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateButtonActionPerformed + assert SwingUtilities.isEventDispatchThread(); + int[] indices = installedList.getSelectedIndices(); List plugins = new ArrayList(); if (indices != null) { @@ -680,6 +695,8 @@ }//GEN-LAST:event_updateButtonActionPerformed private void uninstallButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uninstallButtonActionPerformed + assert SwingUtilities.isEventDispatchThread(); + int[] indices = installedList.getSelectedIndices(); List plugins = new ArrayList(); if (indices != null) { @@ -704,6 +721,8 @@ }//GEN-LAST:event_reloadInstalledButtonActionPerformed private void installedPanelComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_installedPanelComponentShown + assert SwingUtilities.isEventDispatchThread(); + // Make sure the list is shown if (!installedInitialized) { installedInitialized = true; @@ -724,6 +743,8 @@ /** Refresh the list of displayed plugins. If refresh is true, refresh the list from the plugin manager, otherwise just refilter list */ private void refreshPluginList(final String filter, final boolean refresh, final JList list, final boolean local) { + assert SwingUtilities.isEventDispatchThread(); + boolean showRefreshMessage = true; // if (!pluginManager.hasUptodateAvailableList()) { // // No need to ask for cached version if the full version will be displayed shortly @@ -744,7 +765,7 @@ Runnable runner = new Runnable() { public void run() { synchronized(this) { - DefaultListModel model = new DefaultListModel(); + final DefaultListModel model = new DefaultListModel(); List lines = new ArrayList(500); List plugins; if (local) { @@ -800,25 +821,32 @@ model.addElement("" + line + ""); // NOI18N } } - list.clearSelection(); - list.setModel(model); - list.invalidate(); - list.repaint(); - if (plugins.size() > 0) { - list.setSelectedIndex(0); - } + + final int pluginsCount = plugins.size(); - int tabIndex = local ? 0 : 1; - String tabTitle = pluginsTab.getTitleAt(tabIndex); - String originalTabTitle = tabTitle; - int index = tabTitle.lastIndexOf('('); - if (index != -1) { - tabTitle = tabTitle.substring(0, index); - } - tabTitle = tabTitle + "(" + plugins.size() + ")"; - if (!tabTitle.equals(originalTabTitle)) { - pluginsTab.setTitleAt(tabIndex, tabTitle); - } + SwingUtilities.invokeLater(new Runnable() { + public void run() { + list.clearSelection(); + list.setModel(model); + list.invalidate(); + list.repaint(); + if (pluginsCount > 0) { + list.setSelectedIndex(0); + } + + int tabIndex = local ? 0 : 1; + String tabTitle = pluginsTab.getTitleAt(tabIndex); + String originalTabTitle = tabTitle; + int index = tabTitle.lastIndexOf('('); + if (index != -1) { + tabTitle = tabTitle.substring(0, index); + } + tabTitle = tabTitle + "(" + pluginsCount + ")"; + if (!tabTitle.equals(originalTabTitle)) { + pluginsTab.setTitleAt(tabIndex, tabTitle); + } + } + }); } } }; @@ -838,10 +866,12 @@ /** Refresh the list of displayed plugins. If refresh is true, refresh the list from the plugin manager, otherwise just refilter list */ private void refreshRepositoryList(final String filter, final boolean refresh, final JList list, final boolean local) { + assert SwingUtilities.isEventDispatchThread(); + Runnable runner = new Runnable() { public void run() { synchronized(this) { - DefaultListModel model = new DefaultListModel(); + final DefaultListModel model = new DefaultListModel(); List lines = new ArrayList(500); List repositories; if (local) { @@ -888,13 +918,19 @@ model.addElement("" + line + ""); // NOI18N } } - list.clearSelection(); - list.setModel(model); - list.invalidate(); - list.repaint(); - if (repositories.size() > 0) { - list.setSelectedIndex(0); - } + final int repositoryCount = repositories.size(); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + list.clearSelection(); + list.setModel(model); + list.invalidate(); + list.repaint(); + if (repositoryCount > 0) { + list.setSelectedIndex(0); + } + } + }); } } }; @@ -910,8 +946,9 @@ } } - private String getRepositoryFilter(boolean local) { + assert SwingUtilities.isEventDispatchThread(); + String filter = null; if (local) { filter = searchReposText.getText().trim(); @@ -924,6 +961,8 @@ } private String getPluginFilter(boolean local) { + assert SwingUtilities.isEventDispatchThread(); + String filter = null; JTextField tf = local ? instSearchText : searchNewText; filter = tf.getText().trim(); @@ -944,6 +983,10 @@ } public void run() { + if (!SwingUtilities.isEventDispatchThread()) { + SwingUtilities.invokeLater(this); + return; + } refreshPluginList(getPluginFilter(local), true, list, local); if (list == newList) { newModified = false; @@ -964,6 +1007,10 @@ } public void run() { + if (!SwingUtilities.isEventDispatchThread()) { + SwingUtilities.invokeLater(this); + return; + } refreshRepositoryList(getRepositoryFilter(local), true, list, local); if (list == repositoryList) { repositoriesModified = false;