Changeset 14234 for gli


Ignore:
Timestamp:
2007-07-09T12:04:04+12:00 (17 years ago)
Author:
xiao
Message:

modify RemoveListener so that the remove button is disabled after the plugin above MetadataXMLPlug was deleted and the focus automatically falls on the MetadataXMLPlug.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gli/trunk/src/org/greenstone/gatherer/cdm/PluginManager.java

    r13734 r14234  
    366366    private void removePlugin(Plugin plugin) {
    367367    remove(plugin);
     368 
    368369    }
    369370
     
    673674    }
    674675
    675     /** listens for changes in the list selection and enables the configure and remove buttons if there is a selection, disables them if there is no selection */
    676     private class ListListener
    677         implements ListSelectionListener {
    678 
    679         public void valueChanged(ListSelectionEvent e) {
    680         if (!e.getValueIsAdjusting()) { // we get two events for one change in list selection - use the false one (the second one)
    681             if (plugin_list.isSelectionEmpty()) {
    682             move_up_button.setEnabled(false);
    683             move_down_button.setEnabled(false);
    684             configure.setEnabled(false);
    685             remove.setEnabled(false);
    686             }
    687             else {
    688             Plugin selected_plugin = (Plugin) plugin_list.getSelectedValue();
    689             if(selected_plugin.isSeparator()) {
    690                 move_up_button.setEnabled(false);
    691                 move_down_button.setEnabled(false);
    692                 configure.setEnabled(false);
    693                 remove.setEnabled(false);
    694             }
    695             else {
    696                 configure.setEnabled(true);
    697                 String plugin_name = selected_plugin.getName();
    698                 // Some buttons are only available for plugins other than ArcPlug and RecPlug
    699                 if(plugin_name.equals(StaticStrings.ARCPLUG_STR) || plugin_name.equals(StaticStrings.RECPLUG_STR) ) {
    700                 move_up_button.setEnabled(false);
    701                 move_down_button.setEnabled(false);
    702                 remove.setEnabled(false);
    703                 }
    704                 else if (plugin_name.equals(StaticStrings.METADATAXMLPLUG_STR)) {
    705                 remove.setEnabled(false);
    706                 }
    707                
    708                 else {
    709                 // don't let people remove special plugins such GAPlug an METSPlug,
    710                 // unless they are in systems mode or above
    711                 int mode = Configuration.getMode();
    712                 for (int i=0; i<StaticStrings.KEEP_PLUG.length; i++) {
    713                     if ((plugin_name.equals(StaticStrings.KEEP_PLUG[i])) &&
    714                     (mode < Configuration.SYSTEMS_MODE)) {
    715                     remove.setEnabled(false);
    716                     break;
    717                     } else {
    718                     remove.setEnabled(true);
    719                     }
    720                 }
    721                    
    722                 // Move ups are only enabled if the selected plugin isn't already at the top
    723                 Plugin first_plugin = (Plugin) getElementAt(0);
    724                 if(!first_plugin.equals(selected_plugin)) {
    725                     move_up_button.setEnabled(true);
    726                 }
    727                 else {
    728                     move_up_button.setEnabled(false);
    729                 }
    730                 // And move downs are only allowed when the selected plugin isn't at an index one less than the separator line.
    731                 int separator_index = findSeparatorIndex();
    732                 int selected_index = plugin_list.getSelectedIndex();
    733                 if(selected_index < separator_index - 1) {
    734                     move_down_button.setEnabled(true);
    735                 }
    736                 else {
    737                     move_down_button.setEnabled(false);
    738                 }
    739                 }
    740                 selected_plugin = null;
    741                 plugin_name = null;
    742             }
    743             }
    744         }
    745         }
    746     }
     676  /** listens for changes in the list selection and enables the configure and remove buttons if there is a selection, disables them if there is no selection */
     677  private class ListListener
     678    implements ListSelectionListener {
     679   
     680    public void valueChanged(ListSelectionEvent e) {
     681      if (!e.getValueIsAdjusting()) { // we get two events for one change in list selection - use the false one (the second one)
     682        if (plugin_list.isSelectionEmpty()) {
     683          move_up_button.setEnabled(false);
     684          move_down_button.setEnabled(false);
     685          configure.setEnabled(false);
     686          remove.setEnabled(false);
     687        } else {
     688          Plugin selected_plugin = (Plugin) plugin_list.getSelectedValue();
     689          if(selected_plugin.isSeparator()) {
     690            move_up_button.setEnabled(false);
     691            move_down_button.setEnabled(false);
     692            configure.setEnabled(false);
     693            remove.setEnabled(false);
     694          } else {
     695            configure.setEnabled(true);
     696            String plugin_name = selected_plugin.getName();
     697            // Some buttons are only available for plugins other than ArcPlug and RecPlug
     698            if(plugin_name.equals(StaticStrings.ARCPLUG_STR) || plugin_name.equals(StaticStrings.RECPLUG_STR) ) {
     699              move_up_button.setEnabled(false);
     700              move_down_button.setEnabled(false);
     701              remove.setEnabled(false);
     702            } else if (plugin_name.equals(StaticStrings.METADATAXMLPLUG_STR)) {
     703              remove.setEnabled(false);
     704            }
     705           
     706            else {
     707              // don't let people remove special plugins such GAPlug an METSPlug,
     708              // unless they are in systems mode or above
     709              int mode = Configuration.getMode();
     710              for (int i=0; i<StaticStrings.KEEP_PLUG.length; i++) {
     711                if ((plugin_name.equals(StaticStrings.KEEP_PLUG[i])) &&
     712                  (mode < Configuration.SYSTEMS_MODE)) {
     713                  remove.setEnabled(false);
     714                  break;
     715                } else {
     716                  remove.setEnabled(true);
     717                }
     718              }
     719             
     720              // Move ups are only enabled if the selected plugin isn't already at the top
     721              Plugin first_plugin = (Plugin) getElementAt(0);
     722              if(!first_plugin.equals(selected_plugin)) {
     723                move_up_button.setEnabled(true);
     724              } else {
     725                move_up_button.setEnabled(false);
     726              }
     727              // And move downs are only allowed when the selected plugin isn't at an index one less than the separator line.
     728              int separator_index = findSeparatorIndex();
     729              int selected_index = plugin_list.getSelectedIndex();
     730              if(selected_index < separator_index - 1) {
     731                move_down_button.setEnabled(true);
     732              } else {
     733                move_down_button.setEnabled(false);
     734              }
     735            }
     736            selected_plugin = null;
     737            plugin_name = null;
     738          }
     739        }
     740      }
     741    }
     742  }
    747743
    748744    /** A special list renderer which is able to render separating lines as well. */
     
    818814    }
    819815   
    820     /** This class listens for actions upon the remove button in the controls, and if detected calls the <i>removePlugin()</i> method.
    821      */
    822     private class RemoveListener
    823         implements ActionListener {
    824         /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed when an action has occured on one of our target controls.
    825          * @param event An <strong>ActionEvent</strong> containing information garnered from the control action.
    826          */
    827         public void actionPerformed(ActionEvent event) {
    828         int selected_index = plugin_list.getSelectedIndex();
    829         if(selected_index != -1) {
    830             Plugin selected_plugin = (Plugin) plugin_list.getSelectedValue();
    831             removePlugin(selected_plugin);
    832             selected_plugin = null;
    833             // Select the next plugin if available
    834             if(selected_index < plugin_list.getModel().getSize()) {
    835             // If the new selection is above the separator we can remove it
    836             if(selected_index < findSeparatorIndex()) {
    837                 plugin_list.setSelectedIndex(selected_index);
    838                
    839                 // don't let people remove special plugins such GAPlug an METSPlug,
    840                 // unless they are in systems mode or above
    841                 int mode = Configuration.getMode();
    842                 for (int i=0; i<StaticStrings.KEEP_PLUG.length; i++) {
    843                 String selected_plugin_name
    844                     = ((Plugin)plugin_list.getSelectedValue()).getName();
    845                 if ((selected_plugin_name.equals(StaticStrings.KEEP_PLUG[i])) &&
    846                     (mode < Configuration.SYSTEMS_MODE)) {
    847                     remove.setEnabled(false);
    848                     break;
    849                 } else {
    850                     remove.setEnabled(true);
    851                 }
    852                 }                   
    853             }
    854             // Otherwise select the first non-removable plugin
    855             else {
    856                 plugin_list.setSelectedIndex(selected_index + 1);
    857                 remove.setEnabled(false);
    858             }
    859             }
    860             else {
    861             remove.setEnabled(false);
    862             }
    863             // Refresh the available plugins
    864             plugin_combobox.setModel(new DefaultComboBoxModel(getAvailablePlugins()));
    865         }
    866         else {
    867             remove.setEnabled(false);
    868         }
    869         }
    870     }
     816  /** This class listens for actions upon the remove button in the controls, and if detected calls the <i>removePlugin()</i> method.
     817   */
     818  private class RemoveListener
     819    implements ActionListener {
     820    /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed when an action has occured on one of our target controls.
     821     * @param event An <strong>ActionEvent</strong> containing information garnered from the control action.
     822     */
     823    public void actionPerformed(ActionEvent event) {
     824      int selected_index = plugin_list.getSelectedIndex();
     825      if(selected_index != -1) {
     826        Plugin selected_plugin = (Plugin) plugin_list.getSelectedValue();
     827        removePlugin(selected_plugin);
     828        selected_plugin = null;
     829        // Refresh the available plugins
     830        plugin_combobox.setModel(new DefaultComboBoxModel(getAvailablePlugins()));
     831
     832        // Select the next plugin if available
     833        if(selected_index < plugin_list.getModel().getSize()) {
     834          // If the new selection is above the separator we can remove it
     835          if(selected_index < findSeparatorIndex()) {
     836            plugin_list.setSelectedIndex(selected_index);
     837           
     838            // don't let people remove special plugins such GAPlug an METSPlug,
     839            // unless they are in systems mode or above
     840            int mode = Configuration.getMode();
     841            for (int i=0; i<StaticStrings.KEEP_PLUG.length; i++) {
     842              String selected_plugin_name
     843                = ((Plugin)plugin_list.getSelectedValue()).getName();
     844             
     845              if (selected_plugin_name.equals(StaticStrings.METADATAXMLPLUG_STR)) {
     846                //this plug cannot be removed under any conditions.
     847                remove.setEnabled(false);
     848              }else if ((selected_plugin_name.equals(StaticStrings.KEEP_PLUG[i])) &&
     849                (mode < Configuration.SYSTEMS_MODE)) {
     850                remove.setEnabled(false);
     851                break;
     852              } else {
     853                remove.setEnabled(true);
     854              }
     855            }
     856          }
     857          // Otherwise select the first non-removable plugin
     858          else {
     859            plugin_list.setSelectedIndex(selected_index + 1);
     860            remove.setEnabled(false);
     861          }
     862        } else {
     863          remove.setEnabled(false);
     864        }
     865      } else {
     866        remove.setEnabled(false);
     867      }
     868    }
     869  }
    871870    }
    872871   
Note: See TracChangeset for help on using the changeset viewer.