20 package net.sf.gridarta.gui.dialog.findarchetypes;
22 import java.awt.Component;
23 import java.awt.GridBagConstraints;
24 import java.awt.GridBagLayout;
25 import java.awt.Rectangle;
26 import java.awt.event.MouseAdapter;
27 import java.awt.event.MouseEvent;
28 import java.awt.event.MouseListener;
29 import javax.swing.JButton;
30 import javax.swing.JDialog;
31 import javax.swing.JOptionPane;
32 import javax.swing.JPanel;
33 import javax.swing.JScrollPane;
34 import javax.swing.JTable;
35 import javax.swing.JTextField;
36 import javax.swing.JViewport;
37 import javax.swing.ListSelectionModel;
38 import javax.swing.ScrollPaneConstants;
39 import javax.swing.WindowConstants;
40 import javax.swing.event.DocumentEvent;
41 import javax.swing.event.DocumentListener;
42 import javax.swing.event.ListSelectionEvent;
43 import javax.swing.event.ListSelectionListener;
44 import javax.swing.text.JTextComponent;
53 import net.
sf.japi.swing.action.ActionBuilder;
54 import net.
sf.japi.swing.action.ActionBuilderFactory;
55 import net.
sf.japi.swing.action.ActionMethod;
56 import org.jetbrains.annotations.NotNull;
57 import org.jetbrains.annotations.Nullable;
74 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
92 private final JTextComponent
nameField =
new JTextField();
138 final JPanel panel =
new JPanel(
new GridBagLayout());
144 final DocumentListener documentListener =
new DocumentListener() {
147 public void changedUpdate(@NotNull
final DocumentEvent e) {
152 public void insertUpdate(@NotNull
final DocumentEvent e) {
157 public void removeUpdate(@NotNull
final DocumentEvent e) {
162 nameField.getDocument().addDocumentListener(documentListener);
166 resultTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
169 final ListSelectionListener listSelectionListener =
new ListSelectionListener() {
172 public void valueChanged(
final ListSelectionEvent e) {
177 resultTable.getSelectionModel().addListSelectionListener(listSelectionListener);
179 final MouseListener mouseListener =
new MouseAdapter() {
182 public void mousePressed(
final MouseEvent e) {
184 if (e.getClickCount() > 1) {
192 scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
193 scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
194 scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
196 final GridBagConstraints gbc =
new GridBagConstraints();
202 gbc.fill = GridBagConstraints.HORIZONTAL;
208 gbc.fill = GridBagConstraints.BOTH;
212 final JButton searchButton =
new JButton(
ACTION_BUILDER.createAction(
false,
"findArchetypesSearch",
this));
213 final JButton closeButton =
new JButton(
ACTION_BUILDER.createAction(
false,
"findArchetypesClose",
this));
214 final JOptionPane optionPane =
new JOptionPane(panel, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION,
null,
new JButton[] { searchButton, closeButton, },
nameField);
216 dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
218 dialog.setResizable(
true);
220 dialog.setLocationRelativeTo(parent);
227 scrollPane.getVerticalScrollBar().setValue(0);
263 @Nullable
final R selectedArchetype;
275 final CharSequence lowerCaseName = name.toLowerCase();
276 R exactArchetypeNameMatch =
null;
277 R exactDisplayNameMatch =
null;
279 if (!archetype.isTail()) {
280 final String archetypeName = archetype.getArchetypeName();
281 final String objName = archetype.getObjName();
282 if (archetypeName.toLowerCase().contains(lowerCaseName) || objName.toLowerCase().contains(lowerCaseName)) {
283 if (exactArchetypeNameMatch !=
null) {
285 }
else if (archetypeName.equals(name)) {
286 exactArchetypeNameMatch = archetype;
287 }
else if (exactDisplayNameMatch !=
null) {
289 }
else if (objName.equals(name)) {
290 exactDisplayNameMatch = archetype;
297 if (exactArchetypeNameMatch !=
null) {
298 selectedArchetype = exactArchetypeNameMatch;
299 }
else if (exactDisplayNameMatch !=
null) {
300 selectedArchetype = exactDisplayNameMatch;
302 selectedArchetype =
null;