Search in sources :

Example 1 with ResourceHelper

use of org.csstudio.utility.singlesource.ResourceHelper in project yamcs-studio by yamcs.

the class OPIBuilderPlugin method start.

@Override
public void start(BundleContext context) throws Exception {
    super.start(context);
    resources = new ResourceHelper();
    ui = new UIHelper();
    // set this to resolve Xincludes in XMLs
    System.setProperty("org.apache.xerces.xni.parser.XMLParserConfiguration", "org.apache.xerces.parsers.XIncludeParserConfiguration");
    ScriptService.getInstance();
    if (PreferencesHelper.isDisplaySystemOutput()) {
        ConsoleService.getInstance().turnOnSystemOutput();
    }
    preferenceLisener = new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(PreferencesHelper.COLOR_FILE))
                MediaService.getInstance().reloadColorFile();
            else if (event.getProperty().equals(PreferencesHelper.FONT_FILE))
                MediaService.getInstance().reloadFontFile();
            else if (event.getProperty().equals(PreferencesHelper.OPI_GUI_REFRESH_CYCLE))
                GUIRefreshThread.getInstance(true).reLoadGUIRefreshCycle();
            else if (event.getProperty().equals(PreferencesHelper.DISABLE_ADVANCED_GRAPHICS)) {
                // $NON-NLS-1$ //$NON-NLS-2$
                String disabled = PreferencesHelper.isAdvancedGraphicsDisabled() ? "true" : "false";
                // for swt.widgets
                System.setProperty("org.csstudio.swt.widget.prohibit_advanced_graphics", // $NON-NLS-1$
                disabled);
                // for XYGraph
                // $NON-NLS-1$
                System.setProperty("prohibit_advanced_graphics", disabled);
            } else if (event.getProperty().equals(PreferencesHelper.URL_FILE_LOADING_TIMEOUT))
                System.setProperty(// $NON-NLS-1$
                "org.csstudio.swt.widget.url_file_load_timeout", Integer.toString(PreferencesHelper.getURLFileLoadingTimeout()));
            else if (event.getProperty().equals(PreferencesHelper.SCHEMA_OPI)) {
                SchemaService.getInstance().reLoad();
            } else if (event.getProperty().equals(PreferencesHelper.DISPLAY_SYSTEM_OUTPUT)) {
                if (PreferencesHelper.isDisplaySystemOutput())
                    ConsoleService.getInstance().turnOnSystemOutput();
                else
                    ConsoleService.getInstance().turnOffSystemOutput();
            }
        }
    };
    getPluginPreferences().addPropertyChangeListener(preferenceLisener);
    @SuppressWarnings("serial")
    class HackPropertyChangeEvent extends PropertyChangeEvent {

        public HackPropertyChangeEvent(Object source, String property, Object oldValue, Object newValue) {
            super(source, property, oldValue, newValue);
        }
    }
    preferenceLisener.propertyChange(new HackPropertyChangeEvent(this, PreferencesHelper.DISABLE_ADVANCED_GRAPHICS, null, null));
    preferenceLisener.propertyChange(new HackPropertyChangeEvent(this, PreferencesHelper.URL_FILE_LOADING_TIMEOUT, null, null));
}
Also used : IPropertyChangeListener(org.eclipse.core.runtime.Preferences.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.core.runtime.Preferences.PropertyChangeEvent) ResourceHelper(org.csstudio.utility.singlesource.ResourceHelper) UIHelper(org.csstudio.utility.singlesource.UIHelper)

Example 2 with ResourceHelper

use of org.csstudio.utility.singlesource.ResourceHelper 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 3 with ResourceHelper

use of org.csstudio.utility.singlesource.ResourceHelper 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 4 with ResourceHelper

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

the class ImportArchiveReader method getRawValues.

@Override
public ValueIterator getRawValues(final int key, final String name, final Instant start, final Instant end) throws UnknownChannelException, Exception {
    if (values == null) {
        // Locate file
        final ResourceHelper resources = SingleSourcePlugin.getResourceHelper();
        final IPath ipath = resources.newPath(path);
        // Import data
        values = importer.importValues(resources.getInputStream(ipath));
    }
    return new ArrayValueIterator(values);
}
Also used : IPath(org.eclipse.core.runtime.IPath) ResourceHelper(org.csstudio.utility.singlesource.ResourceHelper)

Aggregations

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