/* * Copyright (C) 2013 Serdar * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.fub.maps.project.detector.ui; import de.fub.maps.project.detector.model.Detector; import de.fub.maps.project.detector.model.pipeline.preprocessors.FilterProcess; import de.fub.maps.project.detector.model.process.AbstractDetectorProcess; import de.fub.maps.project.detector.model.process.DetectorProcess; import de.fub.maps.project.detector.model.xmls.ProcessDescriptor; import de.fub.utilsmodule.Collections.ObservableList; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.openide.util.Lookup; /** * * @author Serdar */ public class PreprocessorComponent extends javax.swing.JPanel implements ChangeListener { private static final long serialVersionUID = 1L; private Detector detector; /** * Creates new form PreprocessorComponent */ public PreprocessorComponent() { initComponents(); selectionComponent1.getAllItemListTitle().setText("Registered Preprocessors"); //NO18N selectionComponent1.getSelectedItemListTitle().setText("Selected Preprocessors"); //NO18N ArrayList<FilterProcess> arrayList = new ArrayList<FilterProcess>(Lookup.getDefault().lookupResult(FilterProcess.class).allInstances()); Collections.sort(arrayList); selectionComponent1.getAllItems().addAll(arrayList); } public PreprocessorComponent(Lookup lookup) { this(); detector = lookup.lookup(Detector.class); assert detector != null; Collection<FilterProcess> processes = detector.getPreProcessorPipeline().getProcesses(); selectionComponent1.getSelectedItems().addAll(processes); ObservableList<DetectorProcess> allItems = selectionComponent1.getAllItems(); ArrayList<DetectorProcess> toRemoveItems = new ArrayList<DetectorProcess>(); for (FilterProcess process : processes) { for (DetectorProcess detectorProcess : allItems) { if (process.getClass().equals(detectorProcess.getClass())) { toRemoveItems.add(detectorProcess); } } } allItems.removeAll(toRemoveItems); selectionComponent1.getSelectedItems().addChangeListener(PreprocessorComponent.this); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { selectionComponent1 = new de.fub.maps.project.detector.ui.SelectionComponent(); setLayout(new java.awt.BorderLayout()); add(selectionComponent1, java.awt.BorderLayout.CENTER); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private de.fub.maps.project.detector.ui.SelectionComponent selectionComponent1; // End of variables declaration//GEN-END:variables @Override public synchronized void stateChanged(ChangeEvent e) { List<ProcessDescriptor> preprocessorList = detector.getDetectorDescriptor().getPreprocessors().getPreprocessorList(); preprocessorList.clear(); for (DetectorProcess process : selectionComponent1.getSelectedItems()) { if (process instanceof AbstractDetectorProcess) { AbstractDetectorProcess abstractDetectorProcess = (AbstractDetectorProcess) process; preprocessorList.add(abstractDetectorProcess.getProcessDescriptor()); } } } }