/* (non-Javadoc) * @see org.eclipse.debug.ui.ILaunchShortcut#launch( * org.eclipse.jface.viewers.ISelection, java.lang.String) */ @Override public void launch(ISelection selection, String mode) { if (selection instanceof IStructuredSelection) { // get the object and the project from it IStructuredSelection structSelect = (IStructuredSelection) selection; Object o = structSelect.getFirstElement(); // get the first (and normally only) element if (o instanceof IAdaptable) { IResource r = (IResource) ((IAdaptable) o).getAdapter(IResource.class); // get the project from the resource if (r != null) { IProject project = r.getProject(); if (project != null) { ProjectState state = Sdk.getProjectState(project); if (state != null && state.isLibrary()) { MessageDialog.openError( PlatformUI.getWorkbench().getDisplay().getActiveShell(), "Android Launch", "Android library projects cannot be launched."); } else { // and launch launch(project, mode); } } } } } }
@Override public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { if (pm.isCanceled()) { return null; } if (!getArguments().getUpdateReferences()) { return null; } CompositeChange result = new CompositeChange(getName()); result.markAsSynthetic(); addManifestFileChanges(result); // Update layout files; we don't just need to react to custom view // changes, we need to update fragment references and even tool:context activity // references addLayoutFileChanges(mProject, result); // Also update in dependent projects ProjectState projectState = Sdk.getProjectState(mProject); if (projectState != null) { Collection<ProjectState> parentProjects = projectState.getFullParentProjects(); for (ProjectState parentProject : parentProjects) { IProject project = parentProject.getProject(); addLayoutFileChanges(project, result); } } return (result.getChildren().length == 0) ? null : result; }
private Pair<List<String>, List<String>> findViews(final boolean layoutsOnly) { final Set<String> customViews = new HashSet<String>(); final Set<String> thirdPartyViews = new HashSet<String>(); ProjectState state = Sdk.getProjectState(mProject); final List<IProject> libraries = state != null ? state.getFullLibraryProjects() : Collections.<IProject>emptyList(); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { // Ignore matches in comments if (match.isInsideDocComment()) { return; } Object element = match.getElement(); if (element instanceof ResolvedBinaryType) { // Third party view ResolvedBinaryType type = (ResolvedBinaryType) element; IPackageFragment fragment = type.getPackageFragment(); IPath path = fragment.getPath(); String last = path.lastSegment(); // Filter out android.jar stuff if (last.equals(FN_FRAMEWORK_LIBRARY)) { return; } if (!isValidView(type, layoutsOnly)) { return; } IProject matchProject = match.getResource().getProject(); if (mProject == matchProject || libraries.contains(matchProject)) { String fqn = type.getFullyQualifiedName(); thirdPartyViews.add(fqn); } } else if (element instanceof ResolvedSourceType) { // User custom view IProject matchProject = match.getResource().getProject(); if (mProject == matchProject || libraries.contains(matchProject)) { ResolvedSourceType type = (ResolvedSourceType) element; if (!isValidView(type, layoutsOnly)) { return; } String fqn = type.getFullyQualifiedName(); fqn = fqn.replace('$', '.'); customViews.add(fqn); } } } }; try { IJavaProject javaProject = BaseProjectHelper.getJavaProject(mProject); if (javaProject != null) { String className = layoutsOnly ? CLASS_VIEWGROUP : CLASS_VIEW; IType viewType = javaProject.findType(className); if (viewType != null) { IJavaSearchScope scope = SearchEngine.createHierarchyScope(viewType); SearchParticipant[] participants = new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}; int matchRule = SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE; SearchPattern pattern = SearchPattern.createPattern( "*", IJavaSearchConstants.CLASS, IJavaSearchConstants.IMPLEMENTORS, matchRule); SearchEngine engine = new SearchEngine(); engine.search(pattern, participants, scope, requestor, new NullProgressMonitor()); } } } catch (CoreException e) { AdtPlugin.log(e, null); } List<String> custom = new ArrayList<String>(customViews); List<String> thirdParty = new ArrayList<String>(thirdPartyViews); if (!layoutsOnly) { // Update our cached answers (unless we were filtered on only layouts) mCustomViews = custom; mThirdPartyViews = thirdParty; } return Pair.of(custom, thirdParty); }