/** * Update combo box of this view. * * @param model_changed set true if the model was changed. */ private void update(final boolean model_changed) { if (model == null) { // Clear/disable GUI items.setItems(new String[] {Messages.SampleView_NoPlot}); items.select(0); items.setEnabled(false); sample_table.setInput(null); return; } // Show PV names. // Also build array for following index-based check of selected item final List<ModelItem> model_items = new ArrayList<>(); final List<String> names_list = new ArrayList<>(); names_list.add(Messages.SampleView_SelectItem); for (ModelItem item : model.getItems()) { model_items.add(item); names_list.add(item.getName()); } final String[] names = names_list.toArray(new String[names_list.size()]); if (!model_changed && items.getSelectionIndex() > 0) { // Is the previously selected item still valid? if (sample_table.getInput() instanceof ModelItem) { final ModelItem selected_item = (ModelItem) sample_table.getInput(); if (model_items.indexOf(selected_item) != -1) { // Show same PV name again in combo box items.setItems(names); items.select(model_items.indexOf(selected_item) + 1); items.setEnabled(true); // Update sample table size. Not locking for size() sample_table.setItemCount(selected_item.getSamples().size()); sample_table.refresh(); return; } } } // Previously selected item no longer valid. // Show new items, clear rest items.setItems(names); items.select(0); items.setEnabled(true); sample_table.setInput(null); }
/** * Initialize * * @param item Item from which to get samples /** @param start Start time /** @param end End time */ public ModelSampleIterator(final ModelItem item, final Instant start, final Instant end) { this.samples = item.getSamples(); this.end = end; samples.getLock().lock(); try { // Anything? if (samples.size() <= 0) index = -1; // All data after start time? else if (samples.get(0).getPosition().compareTo(start) >= 0) index = 0; else { // There is data before the start time. Find sample just before start time. index = findSampleLessOrEqual(start); } // Is first sample already after end time? if (index >= 0) { final PlotSample sample = samples.get(index); value = sample.getVType(); if (sample.getPosition().compareTo(end) > 0) index = -1; } } finally { samples.getLock().unlock(); } }