Search in sources :

Example 1 with ConnectJob

use of org.csstudio.trends.databrowser3.archive.ConnectJob in project org.csstudio.display.builder by kasemir.

the class ArchiveListGUI method connectToArchiveServer.

/**
 * Connect to archive data server.
 *  <p>
 *  On success, set <code>server</code>, update <code>archive_table</code>
 *  @param url Server URL
 */
private void connectToArchiveServer(final String url) {
    new ConnectJob(url) {

        @Override
        protected void archiveServerConnected(final String server_info, final ArchiveInfo[] infos) {
            ArchiveListGUI.this.server_info = server_info;
            if (urls.isDisposed())
                return;
            urls.getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    if (info.isDisposed())
                        return;
                    ArchiveListGUI.this.url = url;
                    final List<ArchiveDataSource> archives = new ArrayList<>();
                    for (ArchiveInfo info : infos) archives.add(new ArchiveDataSource(url, info.getKey(), info.getName(), info.getDescription()));
                    archive_table.setInput(archives);
                    // Select all default archive data sources for this URL
                    final List<ArchiveDataSource> selected = new ArrayList<>();
                    for (ArchiveDataSource dataSource : default_archives) if (dataSource.getUrl().equals(url) && archives.contains(dataSource))
                        selected.add(dataSource);
                    archive_table.setSelection(new StructuredSelection(selected));
                    // Enable operations on server resp. archives
                    info.setEnabled(true);
                    handleArchiveUpdate();
                }
            });
        }

        @Override
        protected void archiveServerError(final String url, final Exception ex) {
            // Called from non-UI thread
            if (info.isDisposed())
                return;
            info.getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    if (info.isDisposed())
                        return;
                    info.setEnabled(false);
                    handleServerError(url, ex);
                }
            });
        }
    }.schedule();
}
Also used : ArchiveInfo(org.csstudio.archive.reader.ArchiveInfo) ConnectJob(org.csstudio.trends.databrowser3.archive.ConnectJob) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource)

Aggregations

ArrayList (java.util.ArrayList)1 ArchiveInfo (org.csstudio.archive.reader.ArchiveInfo)1 ConnectJob (org.csstudio.trends.databrowser3.archive.ConnectJob)1 ArchiveDataSource (org.csstudio.trends.databrowser3.model.ArchiveDataSource)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1