use of org.csstudio.trends.databrowser3.persistence.XMLPersistence in project org.csstudio.display.builder by kasemir.
the class DataBrowserEditor method init.
/**
* Initialize model from editor input
* {@inheritDoc}
*/
@Override
public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {
setSite(site);
if (input instanceof DataBrowserModelEditorInput) {
// Received model with input
model = ((DataBrowserModelEditorInput) input).getModel();
setInput(input);
} else {
// Create new model
model = new Model();
setInput(new DataBrowserModelEditorInput(input, model));
// Load model content from file
try (final InputStream stream = SingleSourcePlugin.getResourceHelper().getInputStream(input)) {
if (stream != null)
new XMLPersistence().load(model, stream);
} catch (Exception ex) {
throw new PartInitException(NLS.bind(Messages.ConfigFileErrorFmt, input.getName()), ex);
}
}
// Update the editor's name from "Data Browser" to title of model or file name
// See DataBrowserModelEditorInput.getName()
setPartName(getEditorInput().getName());
model_listener = new ModelListenerAdapter() {
@Override
public void changedSaveChangesBehavior(final boolean save_changes) {
is_dirty = save_changes;
firePropertyChange(IEditorPart.PROP_DIRTY);
}
@Override
public void changedTitle() {
setDirty(true);
}
@Override
public void changedLayout() {
setDirty(true);
}
@Override
public void changedTiming() {
setDirty(true);
}
@Override
public void changedArchiveRescale() {
setDirty(true);
}
@Override
public void changedColorsOrFonts() {
setDirty(true);
}
@Override
public void changedTimerange() {
setDirty(true);
}
@Override
public void changeTimeAxisConfig() {
setDirty(true);
}
@Override
public void changedAxis(final Optional<AxisConfig> axis) {
setDirty(true);
}
@Override
public void itemAdded(final ModelItem item) {
setDirty(true);
}
@Override
public void itemRemoved(final ModelItem item) {
setDirty(true);
}
@Override
public void changedItemVisibility(final ModelItem item) {
setDirty(true);
}
@Override
public void changedItemLook(final ModelItem item) {
site.getShell().getDisplay().asyncExec(() -> setDirty(true));
}
@Override
public void changedItemDataConfig(PVItem item) {
setDirty(true);
}
@Override
public void scrollEnabled(final boolean scroll_enabled) {
setDirty(true);
}
@Override
public void changedAnnotations() {
setDirty(true);
}
};
model.addListener(model_listener);
}
use of org.csstudio.trends.databrowser3.persistence.XMLPersistence in project org.csstudio.display.builder by kasemir.
the class ControllerDemo method debug.
protected void debug() {
for (ModelItem item : model.getItems()) {
if (!(item instanceof PVItem)) {
continue;
}
System.out.println("\n" + item.getName() + ":");
final PlotSamples samples = item.getSamples();
samples.getLock().lock();
try {
if (samples.size() <= 0)
continue;
Instant last = samples.get(0).getPosition();
for (int s = 0; s < samples.size(); ++s) {
final PlotSample sample = samples.get(s);
System.out.println(sample);
final Instant time = sample.getPosition();
if (time.compareTo(last) < 0) {
System.out.println("Time sequence error!");
break;
}
last = time;
}
} finally {
samples.getLock().unlock();
}
}
new XMLPersistence().write(model, System.out);
}
use of org.csstudio.trends.databrowser3.persistence.XMLPersistence in project org.csstudio.display.builder by kasemir.
the class DataBrowserWidget method cloneModel.
public Model cloneModel() {
// XXX: see about copying over live samples from old to new model
final Model model = new Model();
model.setMacros(this.getMacrosOrProperties());
try {
final InputStream input = this.getFileInputStream();
new XMLPersistence().load(model, input);
} catch (Exception ex) {
logger.log(Level.WARNING, "Cannot create copy of data browser", ex);
}
return model;
}
use of org.csstudio.trends.databrowser3.persistence.XMLPersistence in project org.csstudio.display.builder by kasemir.
the class OpenDisplayFile method openDisplay.
/**
* {@inheritDoc}
*/
@Override
public void openDisplay(final String path, final String data) throws Exception {
final Model model = new Model();
// Read file
final ResourceHelper resources = SingleSourcePlugin.getResourceHelper();
final IPath ipath = resources.newPath(path);
try (final InputStream stream = resources.getInputStream(ipath)) {
new XMLPersistence().load(model, stream);
}
final IEditorInput input = new DataBrowserModelEditorInput(new PathEditorInput(ipath), model);
// Create new editor
final DataBrowserEditor editor = DataBrowserEditor.createInstance(input);
if (editor == null)
throw new Exception("Cannot create Data Browser");
}
use of org.csstudio.trends.databrowser3.persistence.XMLPersistence in project org.csstudio.display.builder by kasemir.
the class DataBrowserEditor method save.
/**
* Save current model content, mark editor as clean.
*
* @param monitor <code>IProgressMonitor</code>, may be null.
* @param stream The stream to use.
* @return Returns <code>true</code> when successful.
*/
private void save(final IProgressMonitor monitor, final OutputStream stream) throws Exception {
monitor.beginTask(Messages.Save, IProgressMonitor.UNKNOWN);
try {
new XMLPersistence().write(model, stream);
setDirty(false);
return;
} catch (Exception ex) {
ExceptionDetailsErrorDialog.openError(getSite().getShell(), Messages.Error, ex);
// Writing failed, prompt for different name or 'cancel'
doSaveAs();
} finally {
monitor.done();
}
}
Aggregations