use of org.eclipse.core.runtime.IAdaptable in project linuxtools by eclipse.
the class SpecfileEditorRPMBuildHandler method getResource.
/**
* Extract the IResource that was selected when the event was fired.
* @param event The fired execution event.
* @return The resource that was selected.
*/
private static IResource getResource(ExecutionEvent event) {
final boolean actOnEditor = Boolean.valueOf(event.getParameter(ON_EDITOR));
if (actOnEditor) {
IEditorPart epart = HandlerUtil.getActiveEditor(event);
if (epart != null) {
IEditorInput input = epart.getEditorInput();
if (input instanceof IFileEditorInput) {
return ((IFileEditorInput) input).getFile();
}
}
return null;
}
IWorkbenchPart part = HandlerUtil.getActivePart(event);
if (part == null) {
return null;
}
if (part instanceof EditorPart) {
IEditorInput input = ((EditorPart) part).getEditorInput();
if (input instanceof IFileEditorInput) {
return ((IFileEditorInput) input).getFile();
}
return null;
}
IWorkbenchSite site = part.getSite();
if (site == null) {
return null;
}
ISelectionProvider provider = site.getSelectionProvider();
if (provider == null) {
return null;
}
ISelection selection = provider.getSelection();
if (selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof IResource) {
return (IResource) element;
} else if (element instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) element;
return adaptable.getAdapter(IResource.class);
} else {
return null;
}
}
return null;
}
use of org.eclipse.core.runtime.IAdaptable in project linuxtools by eclipse.
the class CachegrindLabelProvider method update.
@Override
public void update(ViewerCell cell) {
ICachegrindElement element = ((ICachegrindElement) cell.getElement());
int index = cell.getColumnIndex();
if (index == 0) {
if (element instanceof CachegrindFile) {
// Try to use the CElementLabelProvider
IAdaptable model = ((CachegrindFile) element).getModel();
if (model != null) {
cell.setText(cLabelProvider.getText(model));
cell.setImage(cLabelProvider.getImage(model));
} else {
// Fall back
String name = ((CachegrindFile) element).getName();
cell.setText(name);
cell.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE));
}
} else if (element instanceof CachegrindFunction) {
// Try to use the CElementLabelProvider
IAdaptable model = ((CachegrindFunction) element).getModel();
if (model != null) {
cell.setText(cLabelProvider.getText(model));
cell.setImage(cLabelProvider.getImage(model));
} else {
// Fall back
String name = ((CachegrindFunction) element).getName();
cell.setText(name);
cell.setImage(FUNC_IMG);
}
} else if (element instanceof CachegrindLine) {
// $NON-NLS-1$
cell.setText(NLS.bind(Messages.getString("CachegrindViewPart.line"), ((CachegrindLine) element).getLine()));
cell.setImage(DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_INSTRUCTION_POINTER_TOP));
} else if (element instanceof CachegrindOutput) {
// $NON-NLS-1$
cell.setText(NLS.bind(Messages.getString("CachegrindViewPart.Total_PID"), ((CachegrindOutput) element).getPid()));
cell.setImage(DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_REGISTER));
}
} else if (element instanceof CachegrindFunction) {
cell.setText(df.format(((CachegrindFunction) element).getTotals()[index - 1]));
} else if (element instanceof CachegrindLine) {
cell.setText(df.format(((CachegrindLine) element).getValues()[index - 1]));
} else if (element instanceof CachegrindOutput) {
cell.setText(df.format(((CachegrindOutput) element).getSummary()[index - 1]));
}
}
use of org.eclipse.core.runtime.IAdaptable in project linuxtools by eclipse.
the class StubifyHandler method execute.
@Override
public Object execute(ExecutionEvent event) {
IFile featureFile = null;
IStructuredSelection selection = HandlerUtil.getCurrentStructuredSelection(event);
for (Object element : selection.toList()) {
if (element instanceof IFile) {
featureFile = (IFile) element;
} else if (element instanceof IAdaptable) {
featureFile = ((IAdaptable) element).getAdapter(IFile.class);
}
if (featureFile != null) {
Generator generator = new Generator(getInputType());
generator.generate(featureFile);
}
}
return null;
}
use of org.eclipse.core.runtime.IAdaptable in project linuxtools by eclipse.
the class PrepareChangeLogAction method prepareChangeLog.
private void prepareChangeLog(IProgressMonitor monitor) {
Object element = selected.getFirstElement();
IResource resource = null;
Vector<PatchFile> newList = new Vector<>();
Vector<PatchFile> removeList = new Vector<>();
Vector<PatchFile> changeList = new Vector<>();
int totalChanges = 0;
if (element instanceof IResource) {
resource = (IResource) element;
} else if (element instanceof ISynchronizeModelElement) {
ISynchronizeModelElement sme = (ISynchronizeModelElement) element;
resource = sme.getResource();
} else if (element instanceof IAdaptable) {
resource = ((IAdaptable) element).getAdapter(IResource.class);
}
if (resource == null)
return;
IProject project = resource.getProject();
// Get the repository provider so we can support multiple types of
// code repositories without knowing exactly which (e.g. CVS, SVN, etc..).
RepositoryProvider r = RepositoryProvider.getProvider(project);
if (r == null)
return;
SyncInfoSet set = new SyncInfoSet();
Subscriber s = r.getSubscriber();
if (s == null)
return;
if (element instanceof ISynchronizeModelElement) {
// We can extract the ChangeLog list from the synchronize view which
// allows us to skip items removed from the view
ISynchronizeModelElement d = (ISynchronizeModelElement) element;
while (d.getParent() != null) d = (ISynchronizeModelElement) d.getParent();
extractSynchronizeModelInfo(d, new Path(""), newList, removeList, changeList);
totalChanges = newList.size() + removeList.size() + changeList.size();
} else {
// We can then get a list of all out-of-sync resources.
IResource[] resources = new IResource[] { project };
try {
s.refresh(resources, IResource.DEPTH_INFINITE, monitor);
} catch (TeamException e) {
// Ignore, continue anyways
}
s.collectOutOfSync(resources, IResource.DEPTH_INFINITE, set, monitor);
SyncInfo[] infos = set.getSyncInfos();
totalChanges = infos.length;
// New, Removed, and Changed lists.
for (SyncInfo info : infos) {
int kind = SyncInfo.getChange(info.getKind());
PatchFile p = new PatchFile(info.getLocal());
// for ChangeLog files.
if (!(p.getPath().lastSegment().equals("ChangeLog"))) {
// $NON-NLS-1$
switch(kind) {
case SyncInfo.ADDITION:
p.setNewfile(true);
newList.add(p);
break;
case SyncInfo.DELETION:
p.setRemovedFile(true);
removeList.add(p);
break;
case SyncInfo.CHANGE:
if (info.getLocal().getType() == IResource.FILE) {
changeList.add(p);
}
break;
}
} else {
this.changeLogModified = true;
}
}
}
if (totalChanges == 0)
// nothing to parse
return;
PatchFile[] patchFileInfoList = new PatchFile[totalChanges];
// Group like changes together and sort them by path name.
// We want removed files, then new files, then changed files.
// To get this, we put them in the array in reverse order.
int index = 0;
if (changeList.size() > 0) {
// Get the repository provider so we can support multiple types of
// code repositories without knowing exactly which (e.g. CVS, SVN, etc..).
Collections.sort(changeList, new PatchFileComparator());
int size = changeList.size();
for (int i = 0; i < size; ++i) {
PatchFile p = changeList.get(i);
getChangedLines(s, p, monitor);
patchFileInfoList[index + (size - i - 1)] = p;
}
index += size;
}
if (newList.size() > 0) {
Collections.sort(newList, new PatchFileComparator());
int size = newList.size();
for (int i = 0; i < size; ++i) patchFileInfoList[index + (size - i - 1)] = newList.get(i);
index += size;
}
if (removeList.size() > 0) {
Collections.sort(removeList, new PatchFileComparator());
int size = removeList.size();
for (int i = 0; i < size; ++i) patchFileInfoList[index + (size - i - 1)] = removeList.get(i);
}
// now, find out modified functions/classes.
// try to use the the extension point. so it can be extended easily
// for all files in patch file info list, get function guesses of each
// file.
// $NON-NLS-1$
monitor.subTask(Messages.getString("ChangeLog.WritingMessage"));
int unitwork = 250 / patchFileInfoList.length;
for (PatchFile pf : patchFileInfoList) {
// for each file
if (pf != null) {
// any ChangeLog changes will have null entries for them
String[] funcGuessList = guessFunctionNames(pf);
outputMultipleEntryChangeLog(pf, funcGuessList);
}
monitor.worked(unitwork);
}
}
use of org.eclipse.core.runtime.IAdaptable in project linuxtools by eclipse.
the class PrepareChangelogKeyHandler method execute.
@Override
public Object execute(ExecutionEvent event) {
IStructuredSelection tempResult = null;
// try getting currently selected project
IWorkbenchPage ref = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
IWorkbenchPart part = HandlerUtil.getActivePart(event);
if (part instanceof IEditorPart) {
// If we are in an editor, check if the file being edited is an IResource
// that belongs to a project in the workspace
IEditorPart editorPart = (IEditorPart) part;
IEditorInput input = editorPart.getEditorInput();
IResource r = input.getAdapter(IResource.class);
if (r != null) {
// We have an IResource to work with, so create a selection we can use
// in PrepareChangeLogAction
tempResult = new StructuredSelection(r);
}
} else {
// Otherwise, our view is not an editor, see if we have an IResource or something
// that will lead us to an IResource
ISelection selected = ref.getSelection();
if (selected instanceof IStructuredSelection) {
IResource r = null;
IStructuredSelection iss = (IStructuredSelection) selected;
Object o = ((IStructuredSelection) selected).getFirstElement();
if (o instanceof ISynchronizeModelElement) {
r = ((ISynchronizeModelElement) o).getResource();
} else if (o instanceof IAdaptable) {
r = ((IAdaptable) o).getAdapter(IResource.class);
}
if (r != null)
tempResult = iss;
}
}
if (tempResult == null) {
// choice to fall back on.
for (IViewReference view : ref.getViewReferences()) {
if (view.getId().equals("org.eclipse.team.sync.views.SynchronizeView")) {
// $NON-NLS-1$
IViewPart v = view.getView(false);
ISelection s = null;
ISelectionProvider sp = v.getViewSite().getSelectionProvider();
if (sp != null) {
s = sp.getSelection();
}
if (s instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection) s;
Object element = ss.getFirstElement();
IResource r = null;
if (element instanceof ISynchronizeModelElement) {
r = ((ISynchronizeModelElement) element).getResource();
} else if (element instanceof IAdaptable) {
r = ((IAdaptable) element).getAdapter(IResource.class);
}
if (r != null) {
tempResult = ss;
}
}
}
}
}
// If we can't find the project directly, let the user know.
if (tempResult == null) {
// $NON-NLS-1$,
MessageDialog.openInformation(// $NON-NLS-1$,
getActiveWorkbenchShell(), // $NON-NLS-1$,
Messages.getString("ChangeLog.PrepareChangeLog"), // $NON-NLS-1$
Messages.getString("PrepareChangeLog.InfoNoProjectFound"));
return null;
}
final IStructuredSelection result = tempResult;
IAction exampleAction = new PrepareChangeLogAction() {
@Override
public void run() {
setSelection(result);
doRun();
}
};
exampleAction.run();
return null;
}
Aggregations