Search in sources :

Example 1 with ContentDescriptor

use of org.csstudio.autocomplete.parser.ContentDescriptor in project yamcs-studio by yamcs.

the class AutoCompleteService method retrieveProviders.

/* Associate 1 provider per descriptor */
private List<ScheduledContent> retrieveProviders(AutoCompleteType acType, List<ContentDescriptor> tokens) {
    // retrieve the list from preferences
    String type = acType.value();
    if (providersByType.get(type) == null)
        providersByType.put(type, parseProviderList(Preferences.getProviders(type)));
    List<ProviderSettings> definedProviderList = new ArrayList<ProviderSettings>(providersByType.get(type));
    // associate descriptor to a provider
    List<ScheduledContent> acceptedProviderList = new ArrayList<ScheduledContent>();
    for (ContentDescriptor desc : tokens) {
        Iterator<ProviderSettings> it = definedProviderList.iterator();
        while (it.hasNext()) {
            ProviderSettings settings = it.next();
            if (settings.getProvider().accept(desc.getContentType())) {
                ScheduledContent sc = new ScheduledContent();
                sc.desc = desc;
                sc.settings = settings;
                acceptedProviderList.add(sc);
                it.remove();
            }
        }
    }
    Collections.sort(acceptedProviderList);
    return acceptedProviderList;
}
Also used : ContentDescriptor(org.csstudio.autocomplete.parser.ContentDescriptor) ArrayList(java.util.ArrayList)

Example 2 with ContentDescriptor

use of org.csstudio.autocomplete.parser.ContentDescriptor in project yamcs-studio by yamcs.

the class AutoCompleteService method get.

public int get(final Long uniqueId, final AutoCompleteType acType, final String content, final IAutoCompleteResultListener listener) {
    AutoCompletePlugin.getLogger().log(Level.FINE, ">> ChannelNameService get: " + content + " for type: " + acType.value() + " <<");
    if (content == null || content.isEmpty())
        // no result
        return 0;
    // Useful to handle default data source
    ContentDescriptor desc = new ContentDescriptor();
    final IPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.csstudio.utility.pv");
    // They need to be kept synchronized.
    if (store != null)
        desc.setDefaultDataSource(store.getString("default_type") + "://");
    desc.setContentType(ContentType.Undefined);
    desc.setAutoCompleteType(acType);
    desc.setOriginalContent(content);
    desc.setValue(content);
    List<ContentDescriptor> descList = parseContent(desc);
    if (DEBUG) {
        System.out.println("=============================================");
        System.out.println("--- ContentDescriptor list ---");
        for (ContentDescriptor ct : descList) System.out.println(ct);
    }
    // Useful to keep the order
    int index = 0;
    List<ScheduledContent> providerList = retrieveProviders(acType, descList);
    if (DEBUG) {
        System.out.println("--- Associated Content ---");
    }
    // Execute them in parallel
    for (ScheduledContent sc : providerList) {
        if (DEBUG) {
            System.out.println(sc.settings + " => " + sc.desc);
        }
        final ProviderTask task = new ProviderTask(uniqueId, index, sc.desc, sc.settings, listener);
        synchronized (workQueue) {
            workQueue.add(task);
        }
        new Thread(task).start();
        index++;
    }
    return index;
}
Also used : ContentDescriptor(org.csstudio.autocomplete.parser.ContentDescriptor) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ScopedPreferenceStore(org.eclipse.ui.preferences.ScopedPreferenceStore)

Example 3 with ContentDescriptor

use of org.csstudio.autocomplete.parser.ContentDescriptor in project yamcs-studio by yamcs.

the class AutoCompleteService method parseContent.

/* Handle recursive parsing of a content desc. */
private List<ContentDescriptor> parseContent(ContentDescriptor desc) {
    List<ContentDescriptor> tokenList = new ArrayList<ContentDescriptor>();
    ContentDescriptor newDesc = null;
    // backup data
    int startIndex = desc.getStartIndex();
    int endIndex = desc.getEndIndex();
    AutoCompleteType acType = desc.getAutoCompleteType();
    String defaultDatasource = desc.getDefaultDataSource();
    String originalContent = desc.getOriginalContent();
    // cancel replay
    desc.setReplay(false);
    for (IContentParser parser : parsers) {
        if (parser.accept(desc) && (newDesc = parser.parse(desc)) != null) {
            newDesc.setAutoCompleteType(acType);
            newDesc.setDefaultDataSource(defaultDatasource);
            newDesc.setOriginalContent(originalContent);
            // update indexes
            newDesc.setStartIndex(newDesc.getStartIndex() + startIndex);
            newDesc.setEndIndex(newDesc.getEndIndex() + endIndex);
            if (newDesc.isReplay()) {
                // recursive
                tokenList.addAll(parseContent(newDesc));
            } else {
                tokenList.add(newDesc);
            }
        }
    }
    if (tokenList.isEmpty()) {
        desc.setContentType(ContentType.Undefined);
        tokenList.add(desc);
    }
    return tokenList;
}
Also used : ContentDescriptor(org.csstudio.autocomplete.parser.ContentDescriptor) ArrayList(java.util.ArrayList) IContentParser(org.csstudio.autocomplete.parser.IContentParser)

Example 4 with ContentDescriptor

use of org.csstudio.autocomplete.parser.ContentDescriptor in project yamcs-studio by yamcs.

the class DataSourceParser method parse.

@Override
public ContentDescriptor parse(final ContentDescriptor desc) {
    ContentDescriptor currentToken = new ContentDescriptor();
    currentToken.setContentType(ContentType.PVDataSource);
    currentToken.setValue(desc.getValue());
    return currentToken;
}
Also used : ContentDescriptor(org.csstudio.autocomplete.parser.ContentDescriptor)

Example 5 with ContentDescriptor

use of org.csstudio.autocomplete.parser.ContentDescriptor in project yamcs-studio by yamcs.

the class ParameterContentParser method parse.

@Override
public ContentDescriptor parse(ContentDescriptor desc) {
    int startIndex = 0;
    String contentToParse = desc.getValue();
    if (contentToParse.startsWith(PARA_SOURCE)) {
        contentToParse = contentToParse.substring(PARA_SOURCE.length());
    // startIndex = PARA_SOURCE.length();
    }
    ContentDescriptor currentDesc = new ContentDescriptor();
    currentDesc.setContentType(ContentType.PVName);
    currentDesc.setStartIndex(startIndex);
    currentDesc.setValue(contentToParse);
    return currentDesc;
}
Also used : ContentDescriptor(org.csstudio.autocomplete.parser.ContentDescriptor)

Aggregations

ContentDescriptor (org.csstudio.autocomplete.parser.ContentDescriptor)5 ArrayList (java.util.ArrayList)2 IContentParser (org.csstudio.autocomplete.parser.IContentParser)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 ScopedPreferenceStore (org.eclipse.ui.preferences.ScopedPreferenceStore)1