-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support selection of Bndtools Template in PDE Project Wizards
PDE already offers a templating mechanism based on extension points, BndTools has one as well that is based on services. This is an attempt to make BndTools based items available for the new automatic manifest generation that currently lacks any wizards. Fix #704
- Loading branch information
Showing
16 changed files
with
661 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
ui/org.eclipse.pde.bnd.ui/src/org/eclipse/pde/bnd/ui/internal/TemplateAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Christoph Läubrich and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.pde.bnd.ui.internal; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URI; | ||
|
||
import org.bndtools.templating.Template; | ||
import org.eclipse.core.runtime.AdapterTypes; | ||
import org.eclipse.core.runtime.IAdapterFactory; | ||
import org.eclipse.jface.resource.ImageDescriptor; | ||
import org.eclipse.jface.resource.ImageRegistry; | ||
import org.eclipse.jface.viewers.ILabelProvider; | ||
import org.eclipse.pde.bnd.ui.templating.RepoTemplateLabelProvider; | ||
import org.eclipse.swt.graphics.Image; | ||
import org.eclipse.swt.widgets.Display; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Deactivate; | ||
|
||
@Component | ||
@AdapterTypes(adaptableClass = Template.class, adapterNames = { ILabelProvider.class, Image.class }) | ||
public class TemplateAdapter implements IAdapterFactory { | ||
|
||
private RepoTemplateLabelProvider labelProvider = new RepoTemplateLabelProvider(); | ||
private ImageRegistry imageRegistry; | ||
|
||
@Override | ||
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) { | ||
if (adaptableObject instanceof Template template) { | ||
if (adapterType == ILabelProvider.class) { | ||
return adapterType.cast(labelProvider); | ||
} | ||
if (adapterType == Image.class) { | ||
URI icon = template.getIcon(); | ||
ImageRegistry registry = getImageRegistry(); | ||
String key = icon.toASCIIString(); | ||
ImageDescriptor descriptor = registry.getDescriptor(key); | ||
if (descriptor == null) { | ||
try { | ||
registry.put(key, ImageDescriptor.createFromURL(icon.toURL())); | ||
} catch (MalformedURLException e) { | ||
return null; | ||
} | ||
} | ||
return adapterType.cast(registry.get(key)); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Deactivate | ||
void dispose() { | ||
labelProvider.dispose(); | ||
synchronized (this) { | ||
if (imageRegistry != null) { | ||
imageRegistry.dispose(); | ||
} | ||
} | ||
} | ||
|
||
private ImageRegistry getImageRegistry() { | ||
synchronized (this) { | ||
if (imageRegistry == null) { | ||
imageRegistry = new ImageRegistry(Display.getCurrent()); | ||
} | ||
return imageRegistry; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.