Exemplo n.º 1
0
  BeanItemPanel usageDetails() {
    BeanItemPanel usage = new BeanItemPanel();

    usage.setName(Bundle.getMessage("Usage"));
    usage.setLayout(new BoxLayout(usage, BoxLayout.Y_AXIS));

    usage.addItem(
        new BeanEditItem(null, null, Bundle.getMessage("UsageText", bean.getDisplayName())));

    ArrayList<String> listeners = new ArrayList<String>();
    for (String ref : bean.getListenerRefs()) {
      if (!listeners.contains(ref)) {
        listeners.add(ref);
      }
    }

    Object[] strArray = new Object[listeners.size()];
    listeners.toArray(strArray);
    JList<Object> list = new JList<Object>(strArray);
    list.setLayoutOrientation(JList.VERTICAL);
    list.setVisibleRowCount(-1);
    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    JScrollPane listScroller = new JScrollPane(list);
    listScroller.setPreferredSize(new Dimension(250, 80));
    listScroller.setBorder(
        BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black)));
    usage.addItem(new BeanEditItem(listScroller, Bundle.getMessage("ColumnLocation"), null));

    bei.add(usage);
    return usage;
  }
Exemplo n.º 2
0
 @Override
 public void setValueAt(Object value, int row, int col) {
   switch (col) {
     case USERNAMECOL:
       // Directly changing the username should only be possible if the username was previously
       // null or ""
       // check to see if user name already exists
       if (((String) value).equals("")) {
         value = null;
       } else {
         NamedBean nB = getByUserName((String) value);
         if (nB != null) {
           log.error("User name is not unique " + value);
           String msg = Bundle.getMessage("WarningUserName", new Object[] {("" + value)});
           JOptionPane.showMessageDialog(
               null, msg, Bundle.getMessage("WarningTitle"), JOptionPane.ERROR_MESSAGE);
           return;
         }
       }
       NamedBean nBean = getBySystemName(sysNameList.get(row));
       nBean.setUserName((String) value);
       if (nbMan.inUse(sysNameList.get(row), nBean)) {
         String msg =
             Bundle.getMessage(
                 "UpdateToUserName", new Object[] {getBeanType(), value, sysNameList.get(row)});
         int optionPane =
             JOptionPane.showConfirmDialog(
                 null, msg, Bundle.getMessage("UpdateToUserNameTitle"), JOptionPane.YES_NO_OPTION);
         if (optionPane == JOptionPane.YES_OPTION) {
           // This will update the bean reference from the systemName to the userName
           try {
             nbMan.updateBeanFromSystemToUser(nBean);
           } catch (JmriException ex) {
             // We should never get an exception here as we already check that the username is not
             // valid
           }
         }
       }
       fireTableRowsUpdated(row, row);
       break;
     case COMMENTCOL:
       getBySystemName(sysNameList.get(row)).setComment((String) value);
       fireTableRowsUpdated(row, row);
       break;
     case VALUECOL:
       // button fired, swap state
       NamedBean t = getBySystemName(sysNameList.get(row));
       clickOn(t);
       break;
     case DELETECOL:
       // button fired, delete Bean
       deleteBean(row, col);
       break;
     default:
       break;
   }
 }
Exemplo n.º 3
0
 public void setModel(NamedBean nb) {
   attributes = new Vector<KeyValueModel>(nb.getPropertyKeys().size());
   Iterator<String> ite = nb.getPropertyKeys().iterator();
   while (ite.hasNext()) {
     String key = ite.next();
     KeyValueModel kv = new KeyValueModel(key, nb.getProperty(key));
     attributes.add(kv);
   }
   wasModified = false;
 }
Exemplo n.º 4
0
  /** Generic method to change the user name of a Bean */
  public void renameBean(String _newName) {
    NamedBean nBean = bean;
    String oldName = nBean.getUserName();

    String value = _newName;

    if (value.equals(oldName)) {
      // name not changed.
      return;
    } else {
      NamedBean nB = getByUserName(value);
      if (nB != null) {
        log.error("User name is not unique " + value); // NOI18N
        String msg;
        msg =
            java.text.MessageFormat.format(
                Bundle.getMessage("WarningUserName"), new Object[] {("" + value)});
        JOptionPane.showMessageDialog(
            null, msg, Bundle.getMessage("WarningTitle"), JOptionPane.ERROR_MESSAGE);
        return;
      }
    }

    nBean.setUserName(value);
    if (!value.equals("")) {
      if (oldName == null || oldName.equals("")) {
        if (!nbMan.inUse(nBean.getSystemName(), nBean)) {
          return;
        }
        String msg =
            java.text.MessageFormat.format(
                Bundle.getMessage("UpdateToUserName"),
                new Object[] {getBeanType(), value, nBean.getSystemName()});
        int optionPane =
            JOptionPane.showConfirmDialog(
                null, msg, Bundle.getMessage("UpdateToUserNameTitle"), JOptionPane.YES_NO_OPTION);
        if (optionPane == JOptionPane.YES_OPTION) {
          // This will update the bean reference from the systemName to the userName
          try {
            nbMan.updateBeanFromSystemToUser(nBean);
          } catch (jmri.JmriException ex) {
            // We should never get an exception here as we already check that the username is not
            // valid
          }
        }

      } else {
        nbMan.renameBean(oldName, value, nBean);
      }

    } else {
      // This will update the bean reference from the old userName to the SystemName
      nbMan.updateBeanFromUserToSystem(nBean);
    }
  }
Exemplo n.º 5
0
 public synchronized void dispose() {
   getManager().removePropertyChangeListener(this);
   if (sysNameList != null) {
     for (int i = 0; i < sysNameList.size(); i++) {
       NamedBean b = getBySystemName(sysNameList.get(i));
       if (b != null) {
         b.removePropertyChangeListener(this);
       }
     }
   }
 }
Exemplo n.º 6
0
 public void removeName(int row, int column) {
   NamedBean nBean = getBySystemName(sysNameList.get(row));
   String msg = Bundle.getMessage("UpdateToSystemName", new Object[] {getBeanType()});
   int optionPane =
       JOptionPane.showConfirmDialog(
           null, msg, Bundle.getMessage("UpdateToSystemNameTitle"), JOptionPane.YES_NO_OPTION);
   if (optionPane == JOptionPane.YES_OPTION) {
     nbMan.updateBeanFromUserToSystem(nBean);
   }
   nBean.setUserName(null);
   fireTableRowsUpdated(row, row);
 }
Exemplo n.º 7
0
 protected void saveBasicItems(ActionEvent e) {
   String uname = bean.getUserName();
   if (uname == null && !userNameField.getText().equals("")) {
     renameBean(userNameField.getText());
   } else if (uname != null && !uname.equals(userNameField.getText())) {
     if (userNameField.getText().equals("")) {
       removeName();
     } else {
       renameBean(userNameField.getText());
     }
   }
   bean.setComment(commentField.getText());
 }
Exemplo n.º 8
0
 private static Element storePortal(Portal portal) {
   Element elem = new Element("portal");
   elem.setAttribute("systemName", portal.getSystemName());
   elem.setAttribute("portalName", portal.getName());
   OBlock block = portal.getFromBlock();
   if (block != null) {
     Element fromElem = new Element("fromBlock");
     fromElem.setAttribute("blockName", block.getSystemName());
     List<OPath> paths = portal.getFromPaths();
     if (paths != null) {
       for (int i = 0; i < paths.size(); i++) {
         OPath path = paths.get(i);
         fromElem.addContent(storePathKey(path));
       }
     }
     elem.addContent(fromElem);
   } else {
     log.error("Portal \"" + portal.getName() + "\" has no fromBlock!");
   }
   NamedBean signal = portal.getFromSignal();
   if (signal != null) {
     Element fromElem = new Element("fromSignal");
     fromElem.setAttribute("signalName", signal.getSystemName());
     fromElem.setAttribute("signalDelay", "" + portal.getFromSignalOffset());
     elem.addContent(fromElem);
   }
   block = portal.getToBlock();
   if (block != null) {
     Element toElem = new Element("toBlock");
     toElem.setAttribute("blockName", block.getSystemName());
     List<OPath> paths = portal.getToPaths();
     if (paths != null) {
       for (int i = 0; i < paths.size(); i++) {
         OPath path = paths.get(i);
         toElem.addContent(storePathKey(path));
       }
     }
     elem.addContent(toElem);
   } else {
     log.error("Portal \"" + portal.getName() + "\" has no toBlock!");
   }
   signal = portal.getToSignal();
   if (signal != null) {
     Element toElem = new Element("toSignal");
     toElem.setAttribute("signalName", signal.getSystemName());
     toElem.setAttribute("signalDelay", "" + portal.getToSignalOffset());
     elem.addContent(toElem);
   }
   return elem;
 }
Exemplo n.º 9
0
  /**
   * Creates a generic panel that holds the basic bean information System Name, User Name and
   * Comment
   */
  BeanItemPanel basicDetails() {
    BeanItemPanel basic = new BeanItemPanel();

    basic.setName(Bundle.getMessage("Basic"));
    basic.setLayout(new BoxLayout(basic, BoxLayout.Y_AXIS));

    basic.addItem(
        new BeanEditItem(
            new JLabel(bean.getSystemName()), Bundle.getMessage("ColumnSystemName"), null));

    basic.addItem(new BeanEditItem(userNameField, Bundle.getMessage("ColumnUserName"), null));

    basic.addItem(new BeanEditItem(commentFieldScroller, Bundle.getMessage("ColumnComment"), null));

    basic.setSaveItem(
        new AbstractAction() {
          /** */
          private static final long serialVersionUID = -1823311798750191527L;

          public void actionPerformed(ActionEvent e) {
            saveBasicItems(e);
          }
        });
    basic.setResetItem(
        new AbstractAction() {
          /** */
          private static final long serialVersionUID = 2590436299984618901L;

          public void actionPerformed(ActionEvent e) {
            resetBasicItems(e);
          }
        });
    bei.add(basic);
    return basic;
  }
Exemplo n.º 10
0
 /** Make sure to free up additional resources for a running SCWarrant. */
 public synchronized void stopWarrant(boolean abort) {
   if (_nextSignal != null) {
     _nextSignal.removePropertyChangeListener(this);
     _nextSignal = null;
   }
   super.stopWarrant(abort);
 }
Exemplo n.º 11
0
 protected synchronized void updateNameList() {
   // first, remove listeners from the individual objects
   if (sysNameList != null) {
     for (int i = 0; i < sysNameList.size(); i++) {
       // if object has been deleted, it's not here; ignore it
       NamedBean b = getBySystemName(sysNameList.get(i));
       if (b != null) {
         b.removePropertyChangeListener(this);
       }
     }
   }
   sysNameList = getManager().getSystemNameList();
   // and add them back in
   for (int i = 0; i < sysNameList.size(); i++) {
     getBySystemName(sysNameList.get(i)).addPropertyChangeListener(this, null, "Table View");
   }
 }
Exemplo n.º 12
0
  public void actionPerformed(ActionEvent e) {
    if (bean == null) {
      log.error("No bean set so unable to edit a null bean"); // IN18N
      return;
    }
    if (f == null) {
      f = new JmriJFrame("Edit " + getBeanType() + " " + bean.getDisplayName(), false, false);
      f.addHelpMenu(helpTarget(), true);
      java.awt.Container containerPanel = f.getContentPane();
      initPanelsFirst();
      initPanels();
      initPanelsLast();

      for (BeanItemPanel bi : bei) {
        addToPanel(bi, bi.getListOfItems());
        detailsTab.addTab(bi.getName(), bi);
      }

      containerPanel.add(detailsTab, BorderLayout.CENTER);
      JPanel buttons = new JPanel();
      JButton applyBut = new JButton(Bundle.getMessage("ButtonApply"));
      applyBut.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              applyButtonAction(e);
            }
          });
      JButton okBut = new JButton(Bundle.getMessage("ButtonOK"));
      okBut.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              applyButtonAction(e);
              f.dispose();
            }
          });
      JButton cancelBut = new JButton(Bundle.getMessage("ButtonCancel"));
      cancelBut.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              cancelButtonAction(e);
            }
          });
      buttons.add(applyBut);
      buttons.add(okBut);
      buttons.add(cancelBut);
      containerPanel.add(buttons, BorderLayout.SOUTH);
    }
    for (BeanItemPanel bi : bei) {
      bi.resetField();
    }
    if (selectedTab != null) {
      detailsTab.setSelectedComponent(selectedTab);
    }
    f.pack();
    f.setVisible(true);
  }
Exemplo n.º 13
0
 private void updateSensorList() {
   String[] nameList = jmri.InstanceManager.sensorManagerInstance().getSystemNameArray();
   String[] displayList = new String[nameList.length];
   for (int i = 0; i < nameList.length; i++) {
     NamedBean nBean =
         jmri.InstanceManager.sensorManagerInstance().getBeanBySystemName(nameList[i]);
     if (nBean != null) {
       displayList[i] = nBean.getDisplayName();
     }
   }
   java.util.Arrays.sort(displayList);
   sensorList = new String[displayList.length + 1];
   sensorList[0] = "";
   int i = 1;
   for (String name : displayList) {
     sensorList[i] = name;
     i++;
   }
 }
Exemplo n.º 14
0
 @Override
 public boolean isCellEditable(int row, int col) {
   String uname;
   switch (col) {
     case VALUECOL:
     case COMMENTCOL:
     case DELETECOL:
       return true;
     case USERNAMECOL:
       NamedBean b = getBySystemName(sysNameList.get(row));
       uname = b.getUserName();
       if ((uname == null) || uname.equals("")) {
         return true;
       }
       // $FALL-THROUGH$
     default:
       return false;
   }
 }
Exemplo n.º 15
0
 /**
  * Find the next signal along our route and setup subscription for status changes on that signal.
  */
 public void getAndGetNotifiedFromNextSignal() {
   if (_nextSignal != null) {
     log.debug(
         _trainName
             + " getAndGetNotifiedFromNextSignal removing property listener for signal "
             + _nextSignal.getDisplayName());
     _nextSignal.removePropertyChangeListener(this);
     _nextSignal = null;
   }
   for (int i = _idxCurrentOrder + 1; i <= _orders.size() - 1; i++) {
     BlockOrder bo = getBlockOrderAt(i);
     if (bo == null) {
       log.debug(
           _trainName
               + " getAndGetNotifiedFromNextSignal could not find a BlockOrder for index "
               + i);
     } else if (bo.getEntryName().equals("")) {
       log.debug(
           _trainName
               + " getAndGetNotifiedFromNextSignal could not find an entry to Block for index "
               + i);
     } else {
       log.debug(
           _trainName
               + " getAndGetNotifiedFromNextSignal examines block "
               + bo.getBlock().getDisplayName()
               + " with entryname = "
               + bo.getEntryName());
       _nextSignal = bo.getSignal();
       if (_nextSignal != null) {
         log.debug(
             _trainName
                 + " getAndGetNotifiedFromNextSignal found a new signal to listen to: "
                 + _nextSignal.getDisplayName());
         break;
       }
     }
   }
   if (_nextSignal != null) {
     _nextSignal.addPropertyChangeListener(this);
   }
 }
Exemplo n.º 16
0
 /** override. only interested in additions and deletions */
 public void propertyChange(java.beans.PropertyChangeEvent e) {
   if (e.getPropertyName().equals("length")) {
     // a NamedBean added or deleted
     makePickList();
     fireTableDataChanged();
   }
   if (e.getSource() instanceof NamedBean) {
     NamedBean bean = (NamedBean) e.getSource();
     for (int i = 0; i < _pickList.size(); i++) {
       if (bean.equals(_pickList.get(i))) {
         fireTableRowsUpdated(i, i);
         break;
       }
     }
   }
   if (log.isDebugEnabled()) {
     log.debug(
         "propertyChange of \"" + e.getPropertyName() + "\" for " + e.getSource().toString());
   }
 }
Exemplo n.º 17
0
 /** Generic method to remove the user name from a bean. */
 public void removeName() {
   String msg =
       java.text.MessageFormat.format(
           Bundle.getMessage("UpdateToSystemName"), new Object[] {getBeanType()});
   int optionPane =
       JOptionPane.showConfirmDialog(
           null, msg, Bundle.getMessage("UpdateToSystemNameTitle"), JOptionPane.YES_NO_OPTION);
   if (optionPane == JOptionPane.YES_OPTION) {
     nbMan.updateBeanFromUserToSystem(bean);
   }
   bean.setUserName(null);
 }
Exemplo n.º 18
0
 @Override
 public Object getValueAt(int row, int col) {
   NamedBean b;
   switch (col) {
     case SYSNAMECOL: // slot number
       return sysNameList.get(row);
     case USERNAMECOL: // return user name
       // sometimes, the TableSorter invokes this on rows that no longer exist, so we check
       b = getBySystemName(sysNameList.get(row));
       return (b != null) ? b.getUserName() : null;
     case VALUECOL: //
       return getValue(sysNameList.get(row));
     case COMMENTCOL:
       b = getBySystemName(sysNameList.get(row));
       return (b != null) ? b.getComment() : null;
     case DELETECOL: //
       return Bundle.getMessage("ButtonDelete");
     default:
       log.error("internal state inconsistent with table requst for " + row + " " + col);
       return null;
   }
 }
Exemplo n.º 19
0
    public void updateModel(NamedBean nb) {
      if (!wasModified()) {
        return; // No changed made
      } // add and update keys
      for (int i = 0; i < attributes.size(); i++) {
        KeyValueModel kv = attributes.get(i);
        if ((kv.key != null)
            && // only update if key value defined, will do the remove to
            ((nb.getProperty(kv.key) == null) || (!kv.value.equals(nb.getProperty(kv.key))))) {
          nb.setProperty(kv.key, kv.value);
        }
      }
      // remove undefined keys

      Iterator<String> ite = nb.getPropertyKeys().iterator();
      while (ite.hasNext()) {
        if (!keyExist(ite.next())) // not very efficient algorithm!
        {
          ite.remove();
        }
      }
      wasModified = false;
    }
Exemplo n.º 20
0
 public void addNamedBean(NamedBean nb) throws JmriException {
   if (!list.isEmpty()) {
     if (list.get(list.size() - 1) == nb) {
       log.debug("Bean is the same as the last one so will not add or error");
       return;
     }
     // Run through a series of checks that this bean is reachable from the previous
     if ((nb instanceof SignalMast) && (list.get(list.size() - 1) instanceof SignalMast)) {
       jmri.SignalMastLogicManager smlm = InstanceManager.signalMastLogicManagerInstance();
       jmri.SignalMastLogic sml =
           smlm.getSignalMastLogic(((SignalMast) list.get(list.size() - 1)));
       if (sml == null || !sml.isDestinationValid((SignalMast) nb)) {
         String error =
             Bundle.getMessage(
                 "TCTErrorMastPairsNotValid",
                 nb.getDisplayName(),
                 list.get(list.size() - 1).getDisplayName());
         log.error(error);
         throw new JmriException(error);
       }
       if (sml.getAssociatedSection((SignalMast) nb) == null) {
         String error =
             Bundle.getMessage(
                 "TCTErrorMastPairsNoSection",
                 list.get(list.size() - 1).getDisplayName(),
                 nb.getDisplayName());
         log.error(error);
         throw new JmriException(error);
       }
     } else {
       // Need to add the method to get layout block connectivity.  Also work checking that the
       // Layout Block routing has been initialised.
     }
   }
   list.add(nb);
 }
Exemplo n.º 21
0
 /**
  * Set a NamedBean (Turnout, Sensor, SignalHead, ...) to a specific value in a thread-safe way.
  *
  * <p>You can't assume that all the consequences of that setting will have propagated through when
  * this returns; those might take a long time. But the set operation itself will be complete.
  *
  * @param NamedBean
  * @param state
  */
 public static void setBeanState(NamedBean bean, int state) {
   try {
     javax.swing.SwingUtilities.invokeAndWait(
         () -> {
           try {
             bean.setState(state);
           } catch (JmriException e) {
             log.error("Threw exception while setting state: ", e);
           }
         });
   } catch (InterruptedException e) {
     log.warn("Interrupted while setting state: ", e);
   } catch (InvocationTargetException e) {
     log.warn("Failed during invocation while setting state: ", e);
   }
 }
Exemplo n.º 22
0
    @Override
    public Void doInBackground() throws Exception {
      StringBuilder message = new StringBuilder();
      try {
        getManager().deleteBean(t, "CanDelete"); // IN18N
      } catch (PropertyVetoException e) {
        if (e.getPropertyChangeEvent().getPropertyName().equals("DoNotDelete")) { // IN18N
          log.warn(e.getMessage());
          message.append(
              Bundle.getMessage(
                  "VetoDeleteBean",
                  t.getBeanType(),
                  t.getFullyFormattedDisplayName(),
                  e.getMessage()));
          JOptionPane.showMessageDialog(
              null,
              message.toString(),
              Bundle.getMessage("WarningTitle"),
              JOptionPane.ERROR_MESSAGE);
          return null;
        }
        message.append(e.getMessage());
      }
      int count = t.getNumPropertyChangeListeners();
      if (log.isDebugEnabled()) {
        log.debug("Delete with " + count);
      }
      if (getDisplayDeleteMsg() == 0x02 && message.toString().equals("")) {
        doDelete(t);
      } else {
        final JDialog dialog = new JDialog();
        dialog.setTitle(Bundle.getMessage("WarningTitle"));
        dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        JPanel container = new JPanel();
        container.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
        container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
        if (count > 0) { // warn of listeners attached before delete

          JLabel question =
              new JLabel(Bundle.getMessage("DeletePrompt", t.getFullyFormattedDisplayName()));
          question.setAlignmentX(Component.CENTER_ALIGNMENT);
          container.add(question);

          ArrayList<String> listenerRefs = t.getListenerRefs();
          if (listenerRefs.size() > 0) {
            ArrayList<String> listeners = new ArrayList<>();
            for (int i = 0; i < listenerRefs.size(); i++) {
              if (!listeners.contains(listenerRefs.get(i))) {
                listeners.add(listenerRefs.get(i));
              }
            }

            message.append("<br>");
            message.append(Bundle.getMessage("ReminderInUse", count));
            message.append("<ul>");
            for (int i = 0; i < listeners.size(); i++) {
              message.append("<li>");
              message.append(listeners.get(i));
              message.append("</li>");
            }
            message.append("</ul>");

            JEditorPane pane = new JEditorPane();
            pane.setContentType("text/html");
            pane.setText("<html>" + message.toString() + "</html>");
            pane.setEditable(false);
            JScrollPane jScrollPane = new JScrollPane(pane);
            container.add(jScrollPane);
          }
        } else {
          String msg =
              MessageFormat.format(
                  Bundle.getMessage("DeletePrompt"), new Object[] {t.getSystemName()});
          JLabel question = new JLabel(msg);
          question.setAlignmentX(Component.CENTER_ALIGNMENT);
          container.add(question);
        }

        final JCheckBox remember = new JCheckBox(Bundle.getMessage("MessageRememberSetting"));
        remember.setFont(remember.getFont().deriveFont(10f));
        remember.setAlignmentX(Component.CENTER_ALIGNMENT);

        JButton yesButton = new JButton(Bundle.getMessage("ButtonYes"));
        JButton noButton = new JButton(Bundle.getMessage("ButtonNo"));
        JPanel button = new JPanel();
        button.setAlignmentX(Component.CENTER_ALIGNMENT);
        button.add(yesButton);
        button.add(noButton);
        container.add(button);

        noButton.addActionListener(
            (ActionEvent e) -> {
              // there is no point in remembering this the user will never be
              // able to delete a bean!
              dialog.dispose();
            });

        yesButton.addActionListener(
            (ActionEvent e) -> {
              if (remember.isSelected()) {
                setDisplayDeleteMsg(0x02);
              }
              doDelete(t);
              dialog.dispose();
            });
        container.add(remember);
        container.setAlignmentX(Component.CENTER_ALIGNMENT);
        container.setAlignmentY(Component.CENTER_ALIGNMENT);
        dialog.getContentPane().add(container);
        dialog.pack();
        dialog.setLocation(
            (Toolkit.getDefaultToolkit().getScreenSize().width) / 2 - dialog.getWidth() / 2,
            (Toolkit.getDefaultToolkit().getScreenSize().height) / 2 - dialog.getHeight() / 2);
        dialog.setModal(true);
        dialog.setVisible(true);
      }
      return null;
    }
Exemplo n.º 23
0
  public void moveBean(int row, int column) {
    final NamedBean t = getBySystemName(sysNameList.get(row));
    String currentName = t.getUserName();
    NamedBean oldNameBean = getBySystemName(sysNameList.get(row));

    if ((currentName == null) || currentName.equals("")) {
      JOptionPane.showMessageDialog(null, "Can not move an empty UserName");
      return;
    }

    JComboBox<String> box = new JComboBox<>();
    List<String> nameList = getManager().getSystemNameList();
    for (int i = 0; i < nameList.size(); i++) {
      NamedBean nb = getBySystemName(nameList.get(i));
      // Only add items that do not have a username assigned.
      if (nb.getDisplayName().equals(nameList.get(i))) {
        box.addItem(nameList.get(i));
      }
    }

    int retval =
        JOptionPane.showOptionDialog(
            null,
            "Move " + getBeanType() + " " + currentName + " from " + oldNameBean.getSystemName(),
            "Move UserName",
            0,
            JOptionPane.INFORMATION_MESSAGE,
            null,
            new Object[] {"Cancel", "OK", box},
            null);
    log.debug(
        "Dialog value "
            + retval
            + " selected "
            + box.getSelectedIndex()
            + ":"
            + box.getSelectedItem());
    if (retval != 1) {
      return;
    }
    String entry = (String) box.getSelectedItem();
    NamedBean newNameBean = getBySystemName(entry);
    if (oldNameBean != newNameBean) {
      oldNameBean.setUserName("");
      newNameBean.setUserName(currentName);
      InstanceManager.getDefault(NamedBeanHandleManager.class)
          .moveBean(oldNameBean, newNameBean, currentName);
      if (nbMan.inUse(newNameBean.getSystemName(), newNameBean)) {
        String msg =
            Bundle.getMessage(
                "UpdateToUserName",
                new Object[] {getBeanType(), currentName, sysNameList.get(row)});
        int optionPane =
            JOptionPane.showConfirmDialog(
                null, msg, Bundle.getMessage("UpdateToUserNameTitle"), JOptionPane.YES_NO_OPTION);
        if (optionPane == JOptionPane.YES_OPTION) {
          try {
            nbMan.updateBeanFromSystemToUser(newNameBean);
          } catch (JmriException ex) {
            // We should never get an exception here as we already check that the username is not
            // valid
          }
        }
      }
      fireTableRowsUpdated(row, row);
      InstanceManager.getDefault(UserPreferencesManager.class)
          .showInfoMessage(
              "Reminder",
              getBeanType() + " " + Bundle.getMessage("UpdateComplete"),
              getMasterClassName(),
              "remindSaveReLoad");
      // JOptionPane.showMessageDialog(null, getBeanType() + " " +
      // Bundle.getMessage("UpdateComplete"));
    }
  }
Exemplo n.º 24
0
 protected void resetBasicItems(ActionEvent e) {
   userNameField.setText(bean.getUserName());
   commentField.setText(bean.getComment());
 }
Exemplo n.º 25
0
  public void renameBean(int row, int column) {
    NamedBean nBean = getBySystemName(sysNameList.get(row));
    String oldName = nBean.getUserName();
    JTextField _newName = new JTextField(20);
    _newName.setText(oldName);
    Object[] renameBeanOption = {"Cancel", "OK", _newName};
    int retval =
        JOptionPane.showOptionDialog(
            null,
            "Rename UserName From " + oldName,
            "Rename " + getBeanType(),
            0,
            JOptionPane.INFORMATION_MESSAGE,
            null,
            renameBeanOption,
            renameBeanOption[2]);

    if (retval != 1) {
      return;
    }
    String value = _newName.getText().trim();

    if (value.equals(oldName)) {
      // name not changed.
      return;
    } else {
      NamedBean nB = getByUserName(value);
      if (nB != null) {
        log.error("User name is not unique " + value);
        String msg = Bundle.getMessage("WarningUserName", new Object[] {("" + value)});
        JOptionPane.showMessageDialog(
            null, msg, Bundle.getMessage("WarningTitle"), JOptionPane.ERROR_MESSAGE);
        return;
      }
    }

    nBean.setUserName(value);
    fireTableRowsUpdated(row, row);
    if (!value.equals("")) {
      if (oldName == null || oldName.equals("")) {
        if (!nbMan.inUse(sysNameList.get(row), nBean)) {
          return;
        }
        String msg =
            Bundle.getMessage(
                "UpdateToUserName", new Object[] {getBeanType(), value, sysNameList.get(row)});
        int optionPane =
            JOptionPane.showConfirmDialog(
                null, msg, Bundle.getMessage("UpdateToUserNameTitle"), JOptionPane.YES_NO_OPTION);
        if (optionPane == JOptionPane.YES_OPTION) {
          // This will update the bean reference from the systemName to the userName
          try {
            nbMan.updateBeanFromSystemToUser(nBean);
          } catch (JmriException ex) {
            // We should never get an exception here as we already check that the username is not
            // valid
          }
        }

      } else {
        nbMan.renameBean(oldName, value, nBean);
      }

    } else {
      // This will update the bean reference from the old userName to the SystemName
      nbMan.updateBeanFromUserToSystem(nBean);
    }
  }
Exemplo n.º 26
0
 public void copyName(int row, int column) {
   NamedBean nBean = getBySystemName(sysNameList.get(row));
   Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
   StringSelection name = new StringSelection(nBean.getUserName());
   clipboard.setContents(name, null);
 }