- Timestamp:
- 2004-05-05T10:50:29+12:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/PlugInManager.java
r7252 r7270 57 57 /** The library 'reserve' of base plugins. */ 58 58 private ArrayList library = null; 59 /** When asking how many rows are in the model, and if this variables value is true, then this modifier alters the number returned. This funtionality is used to hide the first two andlast three rows of the list in low detail modes. */59 /** When asking how many rows are in the model, and if this variables value is true, then this modifier alters the number returned. This funtionality is used to hide the last three rows of the list in low detail modes. */ 60 60 private boolean modify_row_count = false; 61 61 /** The controls for editing the contents of this manager. */ … … 63 63 private DOMProxyListModel model; 64 64 private JPanel separator; 65 private PlugIn top_separator_plugin; 66 private PlugIn bottom_separator_plugin; 65 private PlugIn separator_plugin; 67 66 /** Constructor. 68 67 */ … … 92 91 public void assignPlugIn(PlugIn plugin) { 93 92 if(plugin.getName().equals(StaticStrings.RECPLUG_STR) || plugin.getName().equals(StaticStrings.ARCPLUG_STR)) { 94 addAfter(plugin, bottom_separator_plugin); // Adds after separator 95 } else if (plugin.getName().equals(StaticStrings.GAPLUG_STR)) { 96 addBefore(plugin, top_separator_plugin); 93 addAfter(plugin, separator_plugin); // Adds after separator 97 94 } else { 98 addBefore(plugin, bottom_separator_plugin);95 addBefore(plugin, separator_plugin); 99 96 } 100 97 Gatherer.c_man.configurationChanged(); 101 }102 103 /** override this because we want to use the real getElementAt */104 public synchronized ArrayList children() {105 ArrayList child_list = new ArrayList();106 int child_count = super.getSize();107 for(int i = 0; i < child_count; i++) {108 child_list.add(super.getElementAt(i));109 }110 return child_list;111 98 } 112 99 … … 156 143 return null; 157 144 } 158 /** override this to hide the first two entries in some cases */ 159 public synchronized Object getElementAt(int index) { 160 if (modify_row_count) { 161 index = index+2; 162 } 163 return super.getElementAt(index); 164 } 145 165 146 /** Overrides getSize in DOMProxyListModel to take into account the row count modifier used to hide the last three rows in lower detail modes 166 147 * @return an int indicating the number of rows in the model, or more correctly the desired number of rows to display … … 169 150 int result = super.getSize(); 170 151 if(modify_row_count) { 171 result = result - 5;152 result = result-3; 172 153 } 173 154 return result; … … 190 171 // why are all the error notices there when the buttons are disabled is you cant move??? 191 172 public void movePlugIn(PlugIn plugin, boolean direction, boolean all) { 192 // Can't ever move RecPlug or ArcPlug or GAPlug193 if(super.getSize() < 7) {173 // Can't ever move RecPlug or ArcPlug 174 if(super.getSize() < 4) { 194 175 //Gatherer.println("Not enough plugins to allow moving."); 195 176 return; 196 177 } 197 if(plugin.getName().equals(StaticStrings.ARCPLUG_STR) || plugin.getName().equals(StaticStrings.RECPLUG_STR) || plugin.getName().equals(StaticStrings.GAPLUG_STR)) {178 if(plugin.getName().equals(StaticStrings.ARCPLUG_STR) || plugin.getName().equals(StaticStrings.RECPLUG_STR)) { 198 179 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.Move.Fixed"), Dictionary.get("CDM.Move.Title"), JOptionPane.ERROR_MESSAGE); 199 180 return; … … 204 185 // Remove the moving plugin 205 186 remove(plugin); 206 addAfter(plugin, top_separator_plugin); //************ 187 // Retrieve the first plugin 188 PlugIn first_plugin = (PlugIn) getElementAt(0); 189 // Add the moving plugin before the first plugin 190 addBefore(plugin, first_plugin); 191 first_plugin = null; 207 192 Gatherer.c_man.configurationChanged(); 208 193 } … … 211 196 remove(plugin); 212 197 // Add the moving plugin before the separator 213 addBefore(plugin, bottom_separator_plugin);198 addBefore(plugin, separator_plugin); 214 199 Gatherer.c_man.configurationChanged(); 215 200 } … … 228 213 return; 229 214 } 230 PlugIn next_plugin = (PlugIn) super.getElementAt(index); 215 remove(plugin); 216 add(index, plugin); 217 Gatherer.c_man.configurationChanged(); 218 } 219 else { 220 index++; 221 PlugIn next_plugin = (PlugIn) getElementAt(index); 231 222 if(next_plugin.isSeparator()) { 232 223 String args[] = new String[1]; … … 240 231 Gatherer.c_man.configurationChanged(); 241 232 } 242 else {243 index++;244 PlugIn next_plugin = (PlugIn) super.getElementAt(index);245 if(next_plugin.isSeparator()) {246 String args[] = new String[1];247 args[0] = plugin.getName();248 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.Move.Cannot", args), Dictionary.get("CDM.Move.Title"), JOptionPane.ERROR_MESSAGE);249 // Still not going to move RecPlug or ArcPlug.250 return;251 }252 remove(plugin);253 add(index, plugin);254 Gatherer.c_man.configurationChanged();255 }256 233 } 257 234 } … … 259 236 /** We attempt to place the separator between the unfixed and the fixed plugins. Since we only know of two fixed plugins, we search for either of them, and place the separator before them. 260 237 */ 261 public void placeSeparator s() {238 public void placeSeparator() { 262 239 ///ystem.err.println("Placing separator."); 263 240 int separator_index = super.getSize(); 264 int top_separator_index = 0;265 241 if(separator_index > 0) { 266 // see if GAPlug is there267 PlugIn plugin = (PlugIn) super.getElementAt(0);268 if (plugin.getName().equals(StaticStrings.GAPLUG_STR)) {269 top_separator_index = 1;270 }271 242 boolean found_fixed = false; 272 243 int index = separator_index - 1; 273 244 while(index > 0) { 274 plugin = (PlugIn) super.getElementAt(index);245 PlugIn plugin = (PlugIn) getElementAt(index); 275 246 String name = plugin.getName(); 276 247 if(name.equals(StaticStrings.RECPLUG_STR) || name.equals(StaticStrings.ARCPLUG_STR)) { … … 294 265 element.setAttribute(CollectionConfiguration.TYPE_ATTRIBUTE, CollectionConfiguration.SEPARATOR_ATTRIBUTE); 295 266 element.setAttribute(CollectionConfiguration.SEPARATOR_ATTRIBUTE, CollectionConfiguration.TRUE_STR); 296 bottom_separator_plugin = new PlugIn(element, null); 297 top_separator_plugin = new PlugIn((Element)element.cloneNode(true), null); 267 separator_plugin = new PlugIn(element, null); 298 268 ///atherer.println("Adding plugin separator at: " + separator_index); 299 add(separator_index, bottom_separator_plugin); 300 add(top_separator_index, top_separator_plugin); 269 add(separator_index, separator_plugin); 301 270 } 302 271 … … 331 300 if(modify_row_count) { 332 301 fireIntervalRemoved(this, original_size - 4, original_size - 1); 333 fireIntervalRemoved(this, 0,1);334 302 } 335 303 else { 336 fireIntervalAdded(this, 0, 1);337 304 fireIntervalAdded(this, original_size - 4, original_size - 1); 338 305 } 339 306 } 340 307 341 /** Determine the first separat */342 308 /** Determine the current separator index. */ 343 309 private int findSeparatorIndex() { 344 310 int separator_index = super.getSize() - 1; 345 311 while(separator_index >= 0) { 346 PlugIn search = (PlugIn) super.getElementAt(separator_index);312 PlugIn search = (PlugIn) getElementAt(separator_index); 347 313 if(search.isSeparator()) { 348 314 return separator_index; … … 350 316 separator_index--; 351 317 } 352 System.err.println("separator index is "+separator_index);353 318 return separator_index; 354 319 } … … 977 942 configure.setEnabled(true); 978 943 String plugin_name = selected_plugin.getName(); 979 // Some buttons are only available for plugins other than ArcPlug and RecPlug and GAPlug980 if(plugin_name.equals(StaticStrings.ARCPLUG_STR) || plugin_name.equals(StaticStrings.RECPLUG_STR) || plugin_name.equals(StaticStrings.GAPLUG_STR)) {944 // Some buttons are only available for plugins other than ArcPlug and RecPlug 945 if(plugin_name.equals(StaticStrings.ARCPLUG_STR) || plugin_name.equals(StaticStrings.RECPLUG_STR) ) { 981 946 //move_top_button.setEnabled(false); 982 947 move_up_button.setEnabled(false); … … 986 951 } 987 952 else { 988 // Move ups are only enabled if the selected plugin isn't already at the top (allowing for GAPlug) 989 int top_index = (modify_row_count ? 0: 2); 990 PlugIn first_plugin = (PlugIn) getElementAt(top_index); 953 // don't let people remove GAPlug 954 if (plugin_name.equals(StaticStrings.GAPLUG_STR)) { 955 remove.setEnabled(false); 956 } else { 957 remove.setEnabled(true); 958 } 959 960 // Move ups are only enabled if the selected plugin isn't already at the top 961 PlugIn first_plugin = (PlugIn) getElementAt(0); 991 962 if(!first_plugin.equals(selected_plugin)) { 992 963 //move_top_button.setEnabled(true); … … 998 969 } 999 970 // And move downs are only allowed when the selected plugin isn't at an index one less than the separator line. 1000 int bottom_index = (modify_row_count ? model.getSize(): findSeparatorIndex());971 int separator_index = findSeparatorIndex(); 1001 972 int selected_index = plugin_list.getSelectedIndex(); 1002 if(selected_index < bottom_index - 1) {973 if(selected_index < separator_index - 1) { 1003 974 move_down_button.setEnabled(true); 1004 975 //move_bottom_button.setEnabled(true); … … 1008 979 //move_bottom_button.setEnabled(false); 1009 980 } 1010 remove.setEnabled(true);1011 981 } 1012 982 selected_plugin = null;
Note:
See TracChangeset
for help on using the changeset viewer.