use of org.eclipse.core.runtime.IAdaptable in project ow by vtst.
the class EasyResourcePropertyPage method getResource.
/**
* @return The project resource edited by this page.
*/
protected IResource getResource() {
IAdaptable element = getElement();
if (element instanceof IResource)
return (IResource) element;
Object resource = element.getAdapter(IResource.class);
if (resource instanceof IResource)
return (IResource) resource;
return null;
}
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 sling by apache.
the class ServersActionModeFiddlerActionDelegate method initToolbarContributedActions.
private void initToolbarContributedActions() {
cleanAction = new Action("Clean Publish...", IAction.AS_PUSH_BUTTON) {
public void run() {
if (server == null) {
MessageDialog.openInformation(view.getSite().getShell(), "No server selected", "A server must be selected");
return;
}
int selection = 2;
if (!doNotAskAgain) {
MessageDialog dialog = new MessageDialog(view.getSite().getShell(), Messages.defaultDialogTitle, null, Messages.dialogPublishClean, MessageDialog.QUESTION_WITH_CANCEL, new String[] { "Cancel", "OK (do not ask again)", "OK" }, 1) {
@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
setShellStyle(getShellStyle() | SWT.SHEET);
}
};
selection = dialog.open();
}
if (selection != 0) {
if (selection == 1) {
doNotAskAgain = true;
}
IAdaptable info = new IAdaptable() {
public Object getAdapter(Class adapter) {
if (Shell.class.equals(adapter))
return view.getSite().getShell();
if (String.class.equals(adapter))
return "user";
return null;
}
};
server.publish(IServer.PUBLISH_CLEAN, modules, info, null);
}
}
};
cleanAction.setText("Clean Publish...");
cleanAction.setToolTipText("Clean and Publish...");
ImageDescriptor cleanAndPublishImageDesc = new DecorationOverlayIcon(ImageResource.getImageDescriptor(ImageResource.IMG_CLCL_PUBLISH).createImage(), ImageDescriptor.createFromFile(SharedImages.class, "refresh.gif"), IDecoration.BOTTOM_RIGHT);
cleanAction.setImageDescriptor(cleanAndPublishImageDesc);
cleanAction.setId("org.apache.sling.ide.eclipse.ui.actions.CleanPublishAction");
publishAction = new Action("Publish", IAction.AS_PUSH_BUTTON) {
public void run() {
if (server == null) {
MessageDialog.openInformation(view.getSite().getShell(), "No server selected", "A server must be selected");
return;
}
IAdaptable info = new IAdaptable() {
public Object getAdapter(Class adapter) {
if (Shell.class.equals(adapter))
return view.getSite().getShell();
if (String.class.equals(adapter))
return "user";
return null;
}
};
server.publish(IServer.PUBLISH_INCREMENTAL, modules, info, null);
}
};
publishAction.setText("Publish");
publishAction.setToolTipText("Publish");
publishAction.setImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_CLCL_PUBLISH));
publishAction.setId("org.apache.sling.ide.eclipse.ui.actions.PublishAction");
cleanAction.setEnabled(false);
publishAction.setEnabled(false);
cleanActionContributionItem = new ActionContributionItem(cleanAction);
publishActionContributionItem = new ActionContributionItem(publishAction);
appendedToolbarActionContributionItems.add(publishActionContributionItem);
appendedToolbarActionContributionItems.add(cleanActionContributionItem);
}
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]);
}
use of org.eclipse.core.runtime.IAdaptable in project bndtools by bndtools.
the class SelectionUtils method getSelectionMembers.
public static <T> Collection<T> getSelectionMembers(ISelection selection, Class<T> clazz, Predicate<? super T> filter) throws Exception {
if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
return Collections.emptyList();
}
IStructuredSelection structSel = (IStructuredSelection) selection;
List<T> result = new ArrayList<T>(structSel.size());
Iterator<?> iter = structSel.iterator();
while (iter.hasNext()) {
Object element = iter.next();
if (clazz.isInstance(element)) {
@SuppressWarnings("unchecked") T casted = (T) element;
if (filter == null || filter.test(casted)) {
result.add(casted);
}
} else if (element instanceof IAdaptable) {
@SuppressWarnings("unchecked") T adapted = (T) ((IAdaptable) element).getAdapter(clazz);
if (adapted != null) {
if (filter == null || filter.test(adapted)) {
result.add(adapted);
}
}
}
}
return result;
}
Aggregations