Exemple #1
0
 private int removeFromList(Object object) {
   List<?> list = inputPanel.getList(name);
   for (Object entry : list) {
     if (entry.equals(object)) {
       int index = list.indexOf(entry);
       list.remove(entry);
       return index;
     }
   }
   return 0;
 }
Exemple #2
0
 private void performEditing(Object object) {
   refreshDialogs(object);
   String singular = StringUtil.getSingular(name);
   int result =
       JOptionPane.showConfirmDialog(
           null,
           dialogInputs,
           "Edit " + singular,
           JOptionPane.OK_CANCEL_OPTION,
           JOptionPane.PLAIN_MESSAGE,
           null);
   if (result == JOptionPane.OK_OPTION) {
     int index = removeFromList(object);
     try {
       inputPanel.getList(name).add(index, constructor.newInstance(getValuesFromInputs()));
     } catch (InstantiationException ignored) {
     } catch (IllegalAccessException ignored) {
     } catch (InvocationTargetException ignored) {
     }
   }
   inputPanel.refresh();
 }
Exemple #3
0
 @Override
 public void actionPerformed(ActionEvent e) {
   List<?> list = inputPanel.getList(name);
   if (list.isEmpty()) {
     GUI.getInstance().showAttentionMessageDialog("Nothing to edit");
   } else {
     Object[] possibilities = list.toArray();
     String singular = StringUtil.getSingular(name);
     Object result =
         JOptionPane.showInputDialog(
             null,
             "Select " + singular + " to edit:",
             "Edit " + singular,
             JOptionPane.PLAIN_MESSAGE,
             null,
             possibilities,
             list.get(0));
     if (result != null) {
       performEditing(result);
     }
   }
   inputPanel.refresh();
 }