use of org.eclipse.core.runtime.IAdaptable in project bndtools by bndtools.
the class BndProjectPropertyPage method getProject.
IProject getProject() {
IAdaptable elem = getElement();
if (elem instanceof IProject)
return (IProject) elem;
IProject project = (IProject) elem.getAdapter(IProject.class);
if (project != null)
return project;
throw new IllegalArgumentException("Target element does not adapt to IProject");
}
use of org.eclipse.core.runtime.IAdaptable in project bndtools by bndtools.
the class ToggleNatureAction method run.
/*
* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
@Override
public void run(IAction action) {
if (selection instanceof IStructuredSelection) {
for (Iterator<?> it = ((IStructuredSelection) selection).iterator(); it.hasNext(); ) {
Object element = it.next();
IProject project = null;
if (element instanceof IProject) {
project = (IProject) element;
} else if (element instanceof IAdaptable) {
project = (IProject) ((IAdaptable) element).getAdapter(IProject.class);
}
if (project != null) {
boolean isJavaProject = false;
try {
isJavaProject = project.hasNature(JavaCore.NATURE_ID);
} catch (CoreException e) {
/* swallow */
}
if (isJavaProject) {
IStatus status = toggleNature(JavaCore.create(project));
if (!status.isOK())
ErrorDialog.openError(targetPart.getSite().getShell(), "Toggle Bnd Nature", null, status);
}
}
}
}
}
use of org.eclipse.core.runtime.IAdaptable in project bndtools by bndtools.
the class WorkingSetTracker method doWorkingSets.
static void doWorkingSets(final Project model, final IProject targetProject) {
IWorkbench workbench = PlatformUI.getWorkbench();
final IWorkingSetManager workingSetManager = workbench.getWorkingSetManager();
String mergeProperties = model.mergeProperties("-workingset");
if (mergeProperties == null)
return;
Parameters memberShips = new Parameters(mergeProperties);
IWorkingSet[] allWorkingSets = workingSetManager.getAllWorkingSets();
for (IWorkingSet currentWorkingSet : allWorkingSets) {
Attrs attrs = memberShips.remove(currentWorkingSet.getName());
boolean shouldBeMember = attrs != null && Processor.isTrue(attrs.get("member", "true"));
IAdaptable[] elements = currentWorkingSet.getElements();
List<IAdaptable> members = new ExtList<>(elements);
boolean foundProjectInCurrentWorkingSet = false;
for (Iterator<IAdaptable> it = members.iterator(); it.hasNext(); ) {
IAdaptable member = it.next();
if (member.getAdapter(IProject.class) == targetProject) {
foundProjectInCurrentWorkingSet = true;
if (!shouldBeMember) {
it.remove();
}
}
}
if (!foundProjectInCurrentWorkingSet && shouldBeMember) {
members.add(targetProject);
}
if (elements.length != members.size()) {
updateWorkingSet(currentWorkingSet, members);
}
}
for (final Entry<String, Attrs> e : memberShips.entrySet()) {
String name = e.getKey();
boolean isMember = Processor.isTrue(e.getValue().get("member", "true"));
if (!isMember)
continue;
if (!JAVAID_P.matcher(name).matches()) {
SetLocation error = model.warning("Invalid working set name '%s'. Must use pattern of Java identifier", name);
error.file(model.getPropertiesFile().getAbsolutePath());
error.header("-workingset");
continue;
}
IAdaptable[] members = new IAdaptable[1];
members[0] = targetProject;
IWorkingSet newWorkingSet = workingSetManager.createWorkingSet(name, members);
newWorkingSet.setId("org.eclipse.jdt.ui.JavaWorkingSetPage");
newWorkingSet.setLabel(null);
workingSetManager.addWorkingSet(newWorkingSet);
}
}
Aggregations