Search in sources :

Example 1 with PathEditorInput

use of org.csstudio.utility.singlesource.PathEditorInput in project org.csstudio.display.builder by kasemir.

the class DataBrowserEditor method doSaveAs.

/**
 * {@inheritDoc}
 */
@Override
public void doSaveAs() {
    final Shell shell = getSite().getShell();
    final ResourceHelper resources = SingleSourcePlugin.getResourceHelper();
    final IPath original = resources.getPath(getEditorInput());
    // Prompt & save until success or cancel
    while (true) {
        final IPath file = SingleSourcePlugin.getUIHelper().openSaveDialog(shell, original, Model.FILE_EXTENSION);
        if (file == null)
            return;
        try {
            final PathEditorInput new_input = new PathEditorInput(file);
            try (final OutputStream stream = resources.getOutputStream(new_input)) {
                save(new NullProgressMonitor(), stream);
            }
            // Set that file as editor's input, so that just 'save' instead of
            // 'save as' is possible from now on
            final DataBrowserModelEditorInput db_input = new DataBrowserModelEditorInput(new_input, model);
            setInput(db_input);
            setPartName(db_input.getName());
            setTitleToolTip(db_input.getToolTipText());
            return;
        } catch (Exception ex) {
            ExceptionDetailsErrorDialog.openError(getSite().getShell(), Messages.Error, ex);
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Shell(org.eclipse.swt.widgets.Shell) IPath(org.eclipse.core.runtime.IPath) OutputStream(java.io.OutputStream) ResourceHelper(org.csstudio.utility.singlesource.ResourceHelper) PartInitException(org.eclipse.ui.PartInitException) PathEditorInput(org.csstudio.utility.singlesource.PathEditorInput)

Example 2 with PathEditorInput

use of org.csstudio.utility.singlesource.PathEditorInput 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");
}
Also used : IPath(org.eclipse.core.runtime.IPath) DataBrowserModelEditorInput(org.csstudio.trends.databrowser3.editor.DataBrowserModelEditorInput) InputStream(java.io.InputStream) Model(org.csstudio.trends.databrowser3.model.Model) ResourceHelper(org.csstudio.utility.singlesource.ResourceHelper) XMLPersistence(org.csstudio.trends.databrowser3.persistence.XMLPersistence) IEditorInput(org.eclipse.ui.IEditorInput) DataBrowserEditor(org.csstudio.trends.databrowser3.editor.DataBrowserEditor) PathEditorInput(org.csstudio.utility.singlesource.PathEditorInput)

Example 3 with PathEditorInput

use of org.csstudio.utility.singlesource.PathEditorInput 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);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) DataBrowserModelEditorInput(org.csstudio.trends.databrowser3.editor.DataBrowserModelEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput) PathEditorInput(org.csstudio.utility.singlesource.PathEditorInput)

Example 4 with PathEditorInput

use of org.csstudio.utility.singlesource.PathEditorInput 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);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) DataBrowserModelEditorInput(org.csstudio.trends.databrowser3.editor.DataBrowserModelEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput) PathEditorInput(org.csstudio.utility.singlesource.PathEditorInput)

Aggregations

PathEditorInput (org.csstudio.utility.singlesource.PathEditorInput)4 IPath (org.eclipse.core.runtime.IPath)4 DataBrowserModelEditorInput (org.csstudio.trends.databrowser3.editor.DataBrowserModelEditorInput)3 IEditorInput (org.eclipse.ui.IEditorInput)3 ResourceHelper (org.csstudio.utility.singlesource.ResourceHelper)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 DataBrowserEditor (org.csstudio.trends.databrowser3.editor.DataBrowserEditor)1 Model (org.csstudio.trends.databrowser3.model.Model)1 XMLPersistence (org.csstudio.trends.databrowser3.persistence.XMLPersistence)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Shell (org.eclipse.swt.widgets.Shell)1 PartInitException (org.eclipse.ui.PartInitException)1