/* * 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.postprocessors.tasks.Task; 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.List; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.openide.util.Lookup; /** * * @author Serdar */ public class PostprocessorComponent extends javax.swing.JPanel implements ChangeListener { private static final long serialVersionUID = 1L; private Detector detector; /** * Creates new form PostprocessorComponent */ public PostprocessorComponent() { initComponents(); selectionComponent1.getAllItemListTitle().setText("Registered Postprocessors"); //NO18N selectionComponent1.getSelectedItemListTitle().setText("Selected Postprocessors"); //NO18N selectionComponent1.getAllItems().addAll(Lookup.getDefault().lookupResult(Task.class).allInstances()); } public PostprocessorComponent(Lookup lookup) { this(); detector = lookup.lookup(Detector.class); assert detector != null; Collection<Task> processes = detector.getPostProcessorPipeline().getProcesses(); selectionComponent1.getSelectedItems().addAll(processes); ObservableList<DetectorProcess> allItems = selectionComponent1.getAllItems(); ArrayList<DetectorProcess> toRemoveItems = new ArrayList<DetectorProcess>(); for (Task process : processes) { for (DetectorProcess detectorProcess : allItems) { if (process.getClass().equals(detectorProcess.getClass())) { toRemoveItems.add(detectorProcess); } } } allItems.removeAll(toRemoveItems); selectionComponent1.getSelectedItems().addChangeListener(PostprocessorComponent.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 void stateChanged(ChangeEvent e) { List<ProcessDescriptor> postprocessorList = detector.getDetectorDescriptor().getPostprocessors().getPostprocessorList(); postprocessorList.clear(); for (DetectorProcess process : selectionComponent1.getSelectedItems()) { if (process instanceof AbstractDetectorProcess) { AbstractDetectorProcess abstractDetectorProcess = (AbstractDetectorProcess) process; postprocessorList.add(abstractDetectorProcess.getProcessDescriptor()); } } } }