/** * Add item to the model. * * <p>If the item has no color, this will define its color based on the model's next available * color. * * <p>If the model is already 'running', the item will be 'start'ed. * * @param item {@link ModelItem} to add * @throws RuntimeException if item is already in model * @throws Exception on error trying to start a PV Item that's added to a running model */ public void addItem(final ModelItem item) throws Exception { // A new item with the same PV name are allowed to be added in the // model. This way Data Browser can show the trend of the same PV // in different axes or with different waveform indexes. For example, // one may want to show the first element of epics://aaa:bbb in axis 1 // while showing the third element of the same PV in axis 2 to compare // their trends in one chart. // // if (getItem(item.getName()) != null) // throw new RuntimeException("Item " + item.getName() + " already in Model"); // But, if exactly the same instance of the given ModelItem already exists in this // model, it will not be added. if (items.indexOf(item) != -1) throw new RuntimeException("Item " + item.getName() + " already in Model"); // Assign default color if (item.getColor() == null) item.setColor(getNextItemColor()); // Force item to be on an axis if (item.getAxis() == null) { if (axes.size() == 0) addAxis(item.getDisplayName()); item.setAxis(axes.get(0)); } // Check item axis if (!axes.contains(item.getAxis())) throw new Exception("Item " + item.getName() + " added with invalid axis " + item.getAxis()); // Add to model items.add(item); item.setModel(this); if (is_running && item instanceof PVItem) ((PVItem) item).start(scanner); // Notify listeners of new item for (ModelListener listener : listeners) listener.itemAdded(item); }