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;
}
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 xtext-xtend by eclipse.
the class FieldInitializerUtil method getSelectedResource.
@SuppressWarnings("cast")
public IJavaElement getSelectedResource(IStructuredSelection selection) {
IJavaElement elem = null;
if (selection != null && !selection.isEmpty()) {
Object o = selection.getFirstElement();
if (o instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) o;
elem = (IJavaElement) adaptable.getAdapter(IJavaElement.class);
if (elem == null) {
elem = getPackage(adaptable);
}
}
}
if (elem == null) {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IWorkbenchPart part = activePage.getActivePart();
if (part instanceof ContentOutline) {
part = activePage.getActiveEditor();
}
if (part instanceof XtextEditor) {
IXtextDocument doc = ((XtextEditor) part).getDocument();
IFile file = doc.getAdapter(IFile.class);
elem = getPackage(file);
}
}
if (elem == null || elem.getElementType() == IJavaElement.JAVA_MODEL) {
try {
IJavaProject[] projects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects();
if (projects.length == 1) {
elem = projects[0];
}
} catch (JavaModelException e) {
throw new RuntimeException(e.getMessage());
}
}
return elem;
}
use of org.eclipse.core.runtime.IAdaptable in project Palladio-Editors-Sirius by PalladioSimulator.
the class AllocationCreationWizard method finish.
@Override
protected void finish() {
Allocation allocation = (Allocation) modelObject;
Session session = SessionManager.INSTANCE.getSession(modelObject);
TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
String fileString = modelURI.toPlatformString(true);
IPath path = new Path(fileString);
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
List<IFile> list = new ArrayList<IFile>();
list.add(file);
AbstractTransactionalCommand command = new AbstractTransactionalCommand(domain, "Save Allocation model.", list) {
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
allocation.setTargetResourceEnvironment_Allocation(resourceEnvironmentSelectorpage.getSelectedResourceEnvironment(session));
allocation.setSystem_Allocation(systemSelectorPage.getSelectedSystem(session));
return CommandResult.newOKCommandResult();
}
};
try {
OperationHistoryFactory.getOperationHistory().execute(command, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
System.out.println("Unable to save allocation model.");
e.printStackTrace();
}
}
use of org.eclipse.core.runtime.IAdaptable in project eclipse.platform.text by eclipse.
the class MarkerRulerAction method execute.
/**
* Execute the specified undoable operation.
*
* @param operation the operation to execute
* @since 3.3
*/
private void execute(IUndoableOperation operation) {
final Shell shell = getTextEditor().getSite().getShell();
IAdaptable context = new IAdaptable() {
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> adapter) {
if (adapter == Shell.class)
return (T) shell;
return null;
}
};
IOperationHistory operationHistory = PlatformUI.getWorkbench().getOperationSupport().getOperationHistory();
try {
operationHistory.execute(operation, null, context);
} catch (ExecutionException e) {
Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID);
ILog log = Platform.getLog(bundle);
// $NON-NLS-2$ //$NON-NLS-1$
String msg = getString(fBundle, fPrefix + "error.dialog.message", fPrefix + "error.dialog.message");
log.log(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, msg, e));
}
}
Aggregations