use of org.eclipse.core.runtime.IAdaptable in project tdi-studio-se by Talend.
the class JobSettingsView method selectionChanged.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.
* SelectionChangedEvent )
*/
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
if (selection instanceof StructuredSelection) {
Object input = ((IStructuredSelection) selection).getFirstElement();
if (!(input instanceof RepositoryNode)) {
if (input instanceof IAdaptable) {
// see ProcessPart.getAdapter()
IAdaptable adaptable = (IAdaptable) input;
input = adaptable.getAdapter(RepositoryNode.class);
}
}
if (input instanceof RepositoryNode) {
RepositoryNode repositoryNode = (RepositoryNode) input;
Object obj = repositoryNode.getProperties(EProperties.CONTENT_TYPE);
String type = null;
if (obj != null) {
type = obj.toString();
if (obj instanceof ERepositoryObjectType) {
ERepositoryObjectType objType = (ERepositoryObjectType) obj;
if (objType == ERepositoryObjectType.PROCESS) {
type = getViewNameLable();
} else if (objType == ERepositoryObjectType.JOBLET) {
type = VIEW_NAME_JOBLET;
}
}
} else {
return;
}
IRepositoryViewObject repositoryObject = repositoryNode.getObject();
if (repositoryObject == null) {
repositoryObject = new EmptyRepositoryObject();
return;
}
String title = repositoryObject.getLabel();
if (allowVerchange) {
if (repositoryObject.getVersion() != null) {
//$NON-NLS-1$
title = repositoryObject.getLabel() + " " + repositoryObject.getVersion();
}
}
Image jobSettingImage = null;
ERepositoryObjectType repositoryObjectType = repositoryNode.getObjectType();
if (repositoryObjectType == ERepositoryObjectType.PROCESS_MR || repositoryObjectType == ERepositoryObjectType.PROCESS_STORM) {
jobSettingImage = getImage(repositoryObject);
}
if (jobSettingImage == null) {
jobSettingImage = getImageFromFramework(repositoryObjectType);
}
if (jobSettingImage == null) {
jobSettingImage = ImageProvider.getImage(repositoryNode.getIcon());
}
setElement(repositoryObject, type + SEPARATOR + title, jobSettingImage);
}
}
}
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);
}
}
use of org.eclipse.core.runtime.IAdaptable in project bndtools by bndtools.
the class RepositoriesView method convertSelectionToFiles.
private static File[] convertSelectionToFiles(ISelection selection) {
if (!(selection instanceof IStructuredSelection))
return new File[0];
IStructuredSelection structSel = (IStructuredSelection) selection;
List<File> files = new ArrayList<File>(structSel.size());
for (Iterator<?> iter = structSel.iterator(); iter.hasNext(); ) {
Object element = iter.next();
if (element instanceof IFile)
files.add(((IFile) element).getLocation().toFile());
else if (element instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) element;
IFile ifile = (IFile) adaptable.getAdapter(IFile.class);
if (ifile != null) {
files.add(ifile.getLocation().toFile());
} else {
File file = (File) adaptable.getAdapter(File.class);
if (file != null) {
files.add(file);
}
}
}
}
return files.toArray(new File[0]);
}
Aggregations