Search in sources :

Example 21 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project bndtools by bndtools.

the class ExtensionRegistryTemplateLoader method findTemplates.

@Override
public Promise<List<Template>> findTemplates(String type, Reporter reporter) {
    List<Template> templates;
    String extPoint = typeToExtPoint.get(type);
    if (extPoint != null) {
        IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(Plugin.PLUGIN_ID, extPoint);
        if (elements == null)
            elements = new IConfigurationElement[0];
        templates = new ArrayList<>(elements.length);
        float total = elements.length;
        float worked = 0f;
        for (IConfigurationElement element : elements) {
            String elementName = element.getName();
            IContributor contributor = element.getContributor();
            try {
                Template extTemplate = (Template) element.createExecutableExtension("class");
                templates.add(extTemplate);
            } catch (CoreException e) {
                Plugin.getDefault().getLog().log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, String.format("Error loading template '%s' from bundle %s", elementName, contributor.getName()), e));
            } finally {
                worked += 1f;
                reporter.progress(total / worked, "Loading templates");
            }
        }
    } else {
        templates = Collections.emptyList();
    }
    return Promises.resolved(templates);
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) IContributor(org.eclipse.core.runtime.IContributor) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) Template(org.bndtools.templating.Template)

Example 22 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project bndtools by bndtools.

the class CategorisedPrioritisedConfigurationElementTreeContentProvider method inputChanged.

@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    data.clear();
    // Dump input into categories
    if (newInput instanceof IConfigurationElement[]) {
        IConfigurationElement[] array = (IConfigurationElement[]) newInput;
        for (IConfigurationElement element : array) categorise(element);
    } else if (newInput instanceof Collection) {
        @SuppressWarnings("unchecked") Collection<IConfigurationElement> coll = (Collection<IConfigurationElement>) newInput;
        for (IConfigurationElement element : coll) categorise(element);
    }
    // Sort within each category
    CategorisedConfigurationElementComparator comparator = new CategorisedConfigurationElementComparator(true);
    for (Entry<ConfigurationElementCategory, List<IConfigurationElement>> entry : data.entrySet()) {
        List<IConfigurationElement> list = entry.getValue();
        Collections.sort(list, comparator);
    }
}
Also used : Collection(java.util.Collection) List(java.util.List) LinkedList(java.util.LinkedList) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 23 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project bndtools by bndtools.

the class AbstractTemplateSelectionWizardPage method setSelectionFromConfigElement.

private void setSelectionFromConfigElement(IConfigurationElement element) {
    showTemplateDescription(element);
    IConfigurationElement old = this.selectedElement;
    this.selectedElement = element;
    propSupport.firePropertyChange(PROP_ELEMENT, old, element);
}
Also used : IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 24 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project bndtools by bndtools.

the class PluginsPart method doEdit.

void doEdit() {
    HeaderClause header = (HeaderClause) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
    if (header != null) {
        Attrs copyOfProperties = new Attrs(header.getAttribs());
        IConfigurationElement configElem = configElements.get(header.getName());
        PluginEditWizard wizard = new PluginEditWizard(configElem, copyOfProperties);
        WizardDialog dialog = new WizardDialog(getManagedForm().getForm().getShell(), wizard);
        if (dialog.open() == Window.OK && wizard.isChanged()) {
            header.getAttribs().clear();
            header.getAttribs().putAll(copyOfProperties);
            viewer.update(header, null);
            markDirty();
        }
    }
}
Also used : Attrs(aQute.bnd.header.Attrs) HeaderClause(aQute.bnd.build.model.clauses.HeaderClause) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 25 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project bndtools by bndtools.

the class PluginClassSelectionPage method setSelectedElement.

public void setSelectedElement(IConfigurationElement selectedElement) {
    IConfigurationElement old = this.selectedElement;
    this.selectedElement = selectedElement;
    if (Display.getCurrent() != null && table != null && !table.isDisposed()) {
        if (!programmaticChange) {
            try {
                programmaticChange = true;
                if (selectedElement == null)
                    viewer.setSelection(StructuredSelection.EMPTY);
                else
                    viewer.setSelection(new StructuredSelection(selectedElement), true);
            } finally {
                programmaticChange = false;
            }
        }
        // updateDescription();
        validate();
        getContainer().updateButtons();
    }
    propSupport.firePropertyChange("selectedElement", old, selectedElement);
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Aggregations

IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)62 CoreException (org.eclipse.core.runtime.CoreException)32 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)14 IExtension (org.eclipse.core.runtime.IExtension)12 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)12 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)11 ArrayList (java.util.ArrayList)8 List (java.util.List)5 GridData (org.eclipse.swt.layout.GridData)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)3 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 Image (org.eclipse.swt.graphics.Image)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 HeaderClause (aQute.bnd.build.model.clauses.HeaderClause)2 File (java.io.File)2 URL (java.net.URL)2