package jetbrains.mps.ide.platform.actions.core; /*Generated by MPS */ import jetbrains.mps.ide.platform.refactoring.RefactoringDialog; import java.util.List; import javax.swing.JCheckBox; import jetbrains.mps.internal.collections.runtime.ListSequence; import java.util.ArrayList; import com.intellij.openapi.project.Project; import javax.swing.JComponent; import javax.swing.JPanel; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Insets; import javax.swing.JLabel; public class SelectOptionsDialog extends RefactoringDialog { private List<String> myOptions; private String myMessage; private List<JCheckBox> myCheckBoxes = ListSequence.fromList(new ArrayList<JCheckBox>()); private List<Integer> mySelected; public SelectOptionsDialog(Project project, List<String> options, String title, String message) { super(project, true); myOptions = options; myMessage = message; init(); setTitle(title); } @Override protected JComponent createCenterPanel() { JPanel panel = new JPanel(new GridBagLayout()); int i = 0; { GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.insets = new Insets(3, 3, 3, 3); c.gridx = 0; c.gridy = i++; c.weightx = 1; c.weighty = 1; panel.add(new JLabel(myMessage), c); } for (String option : myOptions) { GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.insets = new Insets(3, 3, 3, 3); c.gridx = 0; c.gridy = i++; c.weightx = 1; c.weighty = 1; JCheckBox checkBox = new JCheckBox(option, true); ListSequence.fromList(myCheckBoxes).addElement(checkBox); panel.add(checkBox, c); } return panel; } @Override protected void doRefactoringAction() { mySelected = ListSequence.fromList(new ArrayList<Integer>()); for (int i = 0; i < ListSequence.fromList(myCheckBoxes).count(); i++) { if (ListSequence.fromList(myCheckBoxes).getElement(i).isSelected()) { ListSequence.fromList(mySelected).addElement(i); } } super.doRefactoringAction(); } public static List<Integer> selectOptions(Project project, List<String> options, String title, String message) { SelectOptionsDialog dialog = new SelectOptionsDialog(project, options, title, message); dialog.show(); return dialog.mySelected; } }