/** @return Model for demo */ private Model getTestModel() throws Exception { final Model model = new Model(); model.addItem(createPVItem("DTL_LLRF:IOC1:Load")); model.addItem(createPVItem("DTL_Vac:CCG301:Pcalc")); model.addItem(createPVItem("SCL_LLRF:IOC01a:Load")); model.getItem("DTL_LLRF:IOC1:Load").setDisplayName("CPU Load"); model.setTimerange("-48 hours", "now"); return model; }
/** {@inheritDoc} */ @Override protected void updateModel(final Model old_model, final Model model) { this.model = model; if (old_model != model) { if (old_model != null) old_model.removeListener(model_listener); if (model != null) model.addListener(model_listener); } update(old_model != model); }
/** Export channels to Matlab file */ @Test public void matlabExport() throws Exception { final Model model = getTestModel(); final ExportJob export = new MatlabScriptExportJob( model, model.getStartTime(), model.getEndTime(), Source.RAW_ARCHIVE, 10, "/tmp/matlab.m", this); export.run(new SysoutProgressMonitor()); }
/** * Export channels in a spreadsheet * * @throws Exception on error */ @Test public void speadsheetExport() throws Exception { final Model model = getTestModel(); final ExportJob export = new SpreadsheetExportJob( model, model.getStartTime(), model.getEndTime(), Source.RAW_ARCHIVE, 10, new ValueWithInfoFormatter(Style.Exponential, 3), "/tmp/sheet.dat", this); export.run(new SysoutProgressMonitor()); }
/** * Export channels one-by-one * * @throws Exception on error */ @Test public void plainExport() throws Exception { final Model model = getTestModel(); final ExportJob export = new PlainExportJob( model, model.getStartTime(), model.getEndTime(), Source.OPTIMIZED_ARCHIVE, 60, new ValueWithInfoFormatter(Style.Exponential, 6), "/tmp/plain.dat", this); export.run(new SysoutProgressMonitor()); }
/** * Run the 'add PV' dialog with optional defaults * * @param name Suggested PV name, for example from drag-n-drop * @param archive Archive data source for the new PV * @return <code>true</code> if PV name was added, <code>false</code> if canceled by user */ public boolean runWithSuggestedName(final String name, final ArchiveDataSource archive) { // Prompt for PV name final Set<String> existing_names = new HashSet<>(); for (ModelItem item : model.getItems()) existing_names.add(item.getName()); final List<AxisConfig> axes = new ArrayList<>(); final List<String> axes_names = new ArrayList<>(); for (AxisConfig axis : model.getAxes()) { axes.add(axis); axes_names.add(axis.getName()); } final AddPVDialog dlg = new AddPVDialog(shell, existing_names, axes_names, formula); dlg.setName(name); if (dlg.open() != Window.OK) return false; // Did user select axis? final AxisConfig axis; if (dlg.getAxisIndex() >= 0) axis = axes.get(dlg.getAxisIndex()); else // Use first empty axis, or create a new one axis = model .getEmptyAxis() .orElseGet(() -> new AddAxisCommand(operations_manager, model).getAxis()); // Create item if (formula) { final Optional<AddModelItemCommand> command = AddModelItemCommand.forFormula(shell, operations_manager, model, dlg.getName(), axis); if (!command.isPresent()) return false; // Open configuration dialog final FormulaItem formula = (FormulaItem) command.get().getItem(); final EditFormulaDialog edit = new EditFormulaDialog(operations_manager, shell, formula); edit.open(); } else AddModelItemCommand.forPV( shell, operations_manager, model, dlg.getName(), dlg.getScanPeriod(), axis, archive); return true; }
/** * 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); }
@Override void setModel(Model model) { super.setModel(model); this.automaticRefresh = model.isAutomaticHistoryRefresh(); }