use of org.csstudio.trends.databrowser3.editor.DataBrowserModelEditorInput 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.editor.DataBrowserModelEditorInput 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.editor.DataBrowserModelEditorInput in project org.csstudio.display.builder by kasemir.
the class OpenDataBrowserAction method run.
@Override
public void run() {
IPath filename;
try {
filename = SingleSourcePlugin.getResourceHelper().newPath(widget.getExpandedFilename());
} catch (Exception ex) {
logger.log(Level.WARNING, "Cannot determine path", ex);
return;
}
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
final IEditorInput input = new PathEditorInput(filename);
final DataBrowserModelEditorInput model_input = new DataBrowserModelEditorInput(input, widget.cloneModel());
page.openEditor(model_input, DataBrowserEditor.ID, true);
} catch (Exception ex) {
ExceptionDetailsErrorDialog.openError(page.getActivePart().getSite().getShell(), Messages.Error, NLS.bind(Messages.OpenDataBrowserErrorFmt, filename.toString()), ex);
}
}
use of org.csstudio.trends.databrowser3.editor.DataBrowserModelEditorInput in project org.csstudio.display.builder by kasemir.
the class OpenDataBrowserAction method run.
@Override
public void run() {
final DataBrowserWidgedModel model = edit_part.getWidgetModel();
IPath filename = model.getExpandedFilename();
if (!filename.isAbsolute())
filename = ResourceUtil.buildAbsolutePath(model, filename);
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
final IEditorInput input = new PathEditorInput(filename);
final DataBrowserModelEditorInput model_input = new DataBrowserModelEditorInput(input, model.createDataBrowserModel());
page.openEditor(model_input, DataBrowserEditor.ID, true);
} catch (Exception ex) {
ExceptionDetailsErrorDialog.openError(page.getActivePart().getSite().getShell(), Messages.Error, NLS.bind(Messages.OpenDataBrowserErrorFmt, filename.toString()), ex);
}
}
Aggregations