private MultiselectJlist buildActivePluginsPanel(DOFileImportTemplate template) { // initialize the active plugins list view final MultiselectJlist newList = new MultiselectJlist(FileImportHelper.getAvailableEngineNames(fileType)); newList.setCellRenderer(new ActiveEnginesListCellRenderer()); newList.setBorder( new TitledBorder(Messages.getString("ML.FileImportPropertiesPanel.title.ActivePlugins"))); newList.setBackground(getBackground()); List<String> activeEngines = template.getEnabledEngines().get(fileType); if (activeEngines != null) { // collect the indexes to select in a List<Integer> List<Integer> engineIndexesToSelect = new ArrayList<Integer>(); ListModel model = newList.getModel(); for (String engineName : activeEngines) { for (int i = 0; i < model.getSize(); i++) { String currentEngine = model.getElementAt(i).toString(); if (currentEngine.equals(engineName)) { engineIndexesToSelect.add(i); break; } } } // convert the List<Integer to int[] int[] indexesToSelect = new int[engineIndexesToSelect.size()]; for (int i = 0; i < engineIndexesToSelect.size(); i++) { indexesToSelect[i] = engineIndexesToSelect.get(i); } newList.setSelectedIndices(indexesToSelect); } newList.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { synchronized (this) { if (isHandlingPluginSelectionChange) return; isHandlingPluginSelectionChange = true; } try { ListModel model = newList.getModel(); for (ActionListener l : activePluginsChangedListeners) { for (int i = e.getFirstIndex(); i < e.getLastIndex(); i++) { l.actionPerformed( new ActionEvent( this, newList.isSelectedIndex(i) ? 0 : 1, model.getElementAt(i).toString())); } } } finally { isHandlingPluginSelectionChange = false; } } }); return newList; }
private Map<String, MultiselectJlist> getTagsPerEngine(DOFileImportTemplate fileImportTemplate) { Map<String, MultiselectJlist> res = new HashMap<String, MultiselectJlist>(); Map<String, List<String>> availableTags = FileImportHelper.getTagNamesPerEngine(fileType, fileImportTemplate); Map<String, List<String>> enabledTagsForEngines = fileImportTemplate.getEnabledTags().get(fileType); for (String engineName : availableTags.keySet()) { List<String> currentTags = availableTags.get(engineName); Collections.sort(currentTags); MultiselectJlist newList = new MultiselectJlist(currentTags); newList.setBackground(getBackground()); newList.setCellRenderer(new ActiveEnginesListCellRenderer()); List<String> enabledTags = enabledTagsForEngines.get(engineName); if (enabledTags != null && enabledTags.size() > 0) { ListModel model = newList.getModel(); List<Integer> tagIndexesToSelect = new ArrayList<Integer>(); for (int i = 0; i < model.getSize(); i++) { Object element = model.getElementAt(i); if (enabledTags.contains(element)) { tagIndexesToSelect.add(i); } } // convert the List<Integer> to int[] int[] indexesToSelect = new int[tagIndexesToSelect.size()]; for (int i = 0; i < tagIndexesToSelect.size(); i++) { indexesToSelect[i] = tagIndexesToSelect.get(i); } newList.setSelectedIndices(indexesToSelect); } res.put(engineName, newList); } return res; }