package com.onaro.sanscreen.client.view.actions.migration; import com.jidesoft.popup.JidePopup; import com.jidesoft.swing.JideScrollPane; import com.jidesoft.swing.SearchableUtils; import com.onaro.sanscreen.client.MainDirector; import com.onaro.sanscreen.client.view.actions.Messages; import javax.swing.*; import java.awt.*; import java.awt.event.*; /** * If more than one violation exist for a path, this popup will let the user select the one to analyze */ public class SelectViolationTypePopup extends JidePopup { private static final long serialVersionUID = 1L; //shows the violation types private JList list; //Committing the analyze requeues through the action private AnalyzeMigrationTaskViolations action; //if of the task to analyze private long taskId; //string triple that represents a path private String pathIdTriple; public SelectViolationTypePopup(AnalyzeMigrationTaskViolations action, long taskId, String pathIdTriple, String[] violationTypesStr) { this.action = action; this.taskId = taskId; this.pathIdTriple = pathIdTriple; list = new JList(violationTypesStr); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); SearchableUtils.installSearchable(list); JPanel popupPanel = new JPanel(new BorderLayout()); popupPanel.add(new JLabel("" + Messages.INSTANCE.getSelectViolationToAnalyzeLabel() + ""), BorderLayout.BEFORE_FIRST_LINE); //$NON-NLS-1$ //$NON-NLS-2$ popupPanel.add(new JideScrollPane(list)); getContentPane().add(popupPanel); setOwner(MainDirector.getFrameDirector().getAppFrame()); setDefaultFocusComponent(list); //select when ENTER is pressed list.registerKeyboardAction(new SelectionActionListener(), KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); //select when the user double click on the item in the list list.addMouseListener(new DoubleClickListener()); } private void selected() { action.analyse(taskId, pathIdTriple, list.getSelectedValue()); hidePopup(); } private class SelectionActionListener implements ActionListener { public void actionPerformed(ActionEvent e) { selected(); } } private class DoubleClickListener extends MouseAdapter { public void mouseClicked(MouseEvent e) { if (e.getClickCount() > 1) { selected(); } } } }