Java Code Examples for org.eclipse.jdt.core.search.SearchEngine#createWorkspaceScope()

The following examples show how to use org.eclipse.jdt.core.search.SearchEngine#createWorkspaceScope() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodeAssistFavoritesConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void doBrowseTypes() {
	IRunnableContext context= new BusyIndicatorRunnableContext();
	IJavaSearchScope scope= SearchEngine.createWorkspaceScope();
	int style= IJavaElementSearchConstants.CONSIDER_ALL_TYPES;
	try {
		SelectionDialog dialog= JavaUI.createTypeDialog(getShell(), context, scope, style, false, fNameDialogField.getText());
		dialog.setTitle(PreferencesMessages.FavoriteStaticMemberInputDialog_ChooseTypeDialog_title);
		dialog.setMessage(PreferencesMessages.FavoriteStaticMemberInputDialog_ChooseTypeDialog_description);
		if (dialog.open() == Window.OK) {
			IType res= (IType) dialog.getResult()[0];
			fNameDialogField.setText(res.getFullyQualifiedName('.'));
		}
	} catch (JavaModelException e) {
		ExceptionHandler.handle(e, getShell(), PreferencesMessages.FavoriteStaticMemberInputDialog_ChooseTypeDialog_title, PreferencesMessages.FavoriteStaticMemberInputDialog_ChooseTypeDialog_error_message);
	}
}
 
Example 2
Source File: TypeFilterPreferencePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String[] choosePackage() {
	IJavaSearchScope scope= SearchEngine.createWorkspaceScope();
	BusyIndicatorRunnableContext context= new BusyIndicatorRunnableContext();
	int flags= PackageSelectionDialog.F_SHOW_PARENTS | PackageSelectionDialog.F_HIDE_DEFAULT_PACKAGE | PackageSelectionDialog.F_REMOVE_DUPLICATES;
	PackageSelectionDialog dialog = new PackageSelectionDialog(getShell(), context, flags , scope);
	dialog.setTitle(PreferencesMessages.TypeFilterPreferencePage_choosepackage_label);
	dialog.setMessage(PreferencesMessages.TypeFilterPreferencePage_choosepackage_description);
	dialog.setMultipleSelection(true);
	if (dialog.open() == IDialogConstants.OK_ID) {
		Object[] fragments= dialog.getResult();
		String[] res= new String[fragments.length];
		for (int i= 0; i < res.length; i++) {
			res[i]= ((IPackageFragment) fragments[i]).getElementName() + ".*"; //$NON-NLS-1$
		}
		return res;
	}
	return null;
}
 
Example 3
Source File: FocusOnTypeAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
	Shell parent= fViewPart.getSite().getShell();
	FilteredTypesSelectionDialog dialog= new FilteredTypesSelectionDialog(parent, false,
		PlatformUI.getWorkbench().getProgressService(),
		SearchEngine.createWorkspaceScope(), IJavaSearchConstants.TYPE);

	dialog.setTitle(TypeHierarchyMessages.FocusOnTypeAction_dialog_title);
	dialog.setMessage(TypeHierarchyMessages.FocusOnTypeAction_dialog_message);
	if (dialog.open() != IDialogConstants.OK_ID) {
		return;
	}

	Object[] types= dialog.getResult();
	if (types != null && types.length > 0) {
		IType type= (IType)types[0];
		fViewPart.setInputElement(type);
	}
}
 
Example 4
Source File: OpenTypeInHierarchyAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
	Shell parent= JavaPlugin.getActiveWorkbenchShell();
	OpenTypeSelectionDialog dialog= new OpenTypeSelectionDialog(parent, false,
		PlatformUI.getWorkbench().getProgressService(),
		SearchEngine.createWorkspaceScope(), IJavaSearchConstants.TYPE);

	dialog.setTitle(ActionMessages.OpenTypeInHierarchyAction_dialogTitle);
	dialog.setMessage(ActionMessages.OpenTypeInHierarchyAction_dialogMessage);
	int result= dialog.open();
	if (result != IDialogConstants.OK_ID)
		return;

	Object[] types= dialog.getResult();
	if (types != null && types.length > 0) {
		IType type= (IType)types[0];
		OpenTypeHierarchyUtil.open(new IType[] { type }, fWindow);
	}
}
 
Example 5
Source File: NLSAccessorConfigurationDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected void browseForAccessorClass() {
	IProgressService service= PlatformUI.getWorkbench().getProgressService();
	IPackageFragmentRoot root= fAccessorPackage.getSelectedFragmentRoot();

	IJavaSearchScope scope= root != null ? SearchEngine.createJavaSearchScope(new IJavaElement[] { root }) : SearchEngine.createWorkspaceScope();

	FilteredTypesSelectionDialog  dialog= new FilteredTypesSelectionDialog (getShell(), false,
		service, scope, IJavaSearchConstants.CLASS);
	dialog.setTitle(NLSUIMessages.NLSAccessorConfigurationDialog_Accessor_Selection);
	dialog.setMessage(NLSUIMessages.NLSAccessorConfigurationDialog_Choose_the_accessor_file);
	dialog.setInitialPattern("*Messages"); //$NON-NLS-1$
	if (dialog.open() == Window.OK) {
		IType selectedType= (IType) dialog.getFirstResult();
		if (selectedType != null) {
			fAccessorClassName.setText(selectedType.getElementName());
			fAccessorPackage.setSelected(selectedType.getPackageFragment());
		}
	}


}
 
Example 6
Source File: ExpandWithConstructorsConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates the type hierarchy for type selection.
 */
private void doBrowseTypes() {
	IRunnableContext context= new BusyIndicatorRunnableContext();
	IJavaSearchScope scope= SearchEngine.createWorkspaceScope();
	int style= IJavaElementSearchConstants.CONSIDER_ALL_TYPES;
	try {
		SelectionDialog dialog= JavaUI.createTypeDialog(getShell(), context, scope, style, false, fNameDialogField.getText());
		dialog.setTitle(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_title);
		dialog.setMessage(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_description);
		if (dialog.open() == Window.OK) {
			IType res= (IType)dialog.getResult()[0];
			fNameDialogField.setText(res.getFullyQualifiedName('.'));
		}
	} catch (JavaModelException e) {
		ExceptionHandler.handle(e, getShell(), CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_title,
				CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_error_message);
	}
}
 
Example 7
Source File: GotoPackageAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private SelectionDialog createAllPackagesDialog(Shell shell) {
	IProgressService progressService= PlatformUI.getWorkbench().getProgressService();
	IJavaSearchScope scope= SearchEngine.createWorkspaceScope();
	int flag= PackageSelectionDialog.F_HIDE_EMPTY_INNER;
	PackageSelectionDialog dialog= new PackageSelectionDialog(shell, progressService, flag, scope);
	dialog.setFilter(""); //$NON-NLS-1$
	dialog.setIgnoreCase(false);
	dialog.setMultipleSelection(false);
	return dialog;
}
 
Example 8
Source File: SourceType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see IType#newTypeHierarchy(WorkingCopyOwner, IProgressMonitor)
 */
public ITypeHierarchy newTypeHierarchy(
	WorkingCopyOwner owner,
	IProgressMonitor monitor)
	throws JavaModelException {

	ICompilationUnit[] workingCopies = JavaModelManager.getJavaModelManager().getWorkingCopies(owner, true/*add primary working copies*/);
	CreateTypeHierarchyOperation op= new CreateTypeHierarchyOperation(this, workingCopies, SearchEngine.createWorkspaceScope(), true);
	op.runOperation(monitor);
	return op.getResult();
}
 
Example 9
Source File: SourceType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ITypeHierarchy newTypeHierarchy(
	ICompilationUnit[] workingCopies,
	IProgressMonitor monitor)
	throws JavaModelException {

	CreateTypeHierarchyOperation op= new CreateTypeHierarchyOperation(this, workingCopies, SearchEngine.createWorkspaceScope(), true);
	op.runOperation(monitor);
	return op.getResult();
}
 
Example 10
Source File: FilteredTypesSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates new FilteredTypesSelectionDialog instance.
 *
 * @param shell
 *            shell to parent the dialog on
 * @param multi
 *            <code>true</code> if multiple selection is allowed
 * @param context
 *            context used to execute long-running operations associated
 *            with this dialog
 * @param scope
 *            scope used when searching for types. If the scope is <code>null</code>,
 *            then workspace is scope is used as default, and the user can
 *            choose a working set as scope.
 * @param elementKinds
 *            flags defining nature of searched elements; the only valid
 *            values are: <code>IJavaSearchConstants.TYPE</code>
 * 	<code>IJavaSearchConstants.ANNOTATION_TYPE</code>
 * 	<code>IJavaSearchConstants.INTERFACE</code>
 * 	<code>IJavaSearchConstants.ENUM</code>
 * 	<code>IJavaSearchConstants.CLASS_AND_INTERFACE</code>
 * 	<code>IJavaSearchConstants.CLASS_AND_ENUM</code>.
 *            Please note that the bitwise OR combination of the elementary
 *            constants is not supported.
 * @param extension
 *            an extension of the standard type selection dialog; See
 *            {@link TypeSelectionExtension}
 */
public FilteredTypesSelectionDialog(Shell shell, boolean multi, IRunnableContext context, IJavaSearchScope scope, int elementKinds, TypeSelectionExtension extension) {
	super(shell, multi);

	setSelectionHistory(new TypeSelectionHistory());

	if (scope == null) {
		fAllowScopeSwitching= true;
		scope= SearchEngine.createWorkspaceScope();
	}

	fElementKinds= elementKinds;
	fExtension= extension;
	fFilterExtension= (extension == null) ? null : extension.getFilterExtension();
	fSearchScope= scope;

	if (extension != null) {
		fValidator= extension.getSelectionValidator();
	}

	fTypeInfoUtil= new TypeInfoUtil(extension != null ? extension.getImageProvider() : null);

	fTypeInfoLabelProvider= new TypeItemLabelProvider();
	
	setListLabelProvider(fTypeInfoLabelProvider);
	setListSelectionLabelDecorator(fTypeInfoLabelProvider);

	setDetailsLabelProvider(new TypeItemDetailsLabelProvider(fTypeInfoUtil));

	fTypeItemsComparator= new TypeItemsComparator();
}
 
Example 11
Source File: JavaSearchScopeFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public IJavaSearchScope createWorkspaceScope(int includeMask) {
	if ((includeMask & NO_PROJ) != NO_PROJ) {
		try {
			IJavaProject[] projects= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects();
			return SearchEngine.createJavaSearchScope(projects, getSearchFlags(includeMask));
		} catch (JavaModelException e) {
			// ignore, use workspace scope instead
		}
	}
	return SearchEngine.createWorkspaceScope();
}
 
Example 12
Source File: JavaMethodFilterInputDialog.java    From jdt-codemining with Eclipse Public License 1.0 5 votes vote down vote up
private void doButtonPressed() {
	IJavaSearchScope scope= SearchEngine.createWorkspaceScope();
	BusyIndicatorRunnableContext context= new BusyIndicatorRunnableContext();
	int flags= PackageSelectionDialog.F_SHOW_PARENTS | PackageSelectionDialog.F_HIDE_DEFAULT_PACKAGE | PackageSelectionDialog.F_REMOVE_DUPLICATES;
	PackageSelectionDialog dialog = new PackageSelectionDialog(getShell(), context, flags , scope);
	dialog.setTitle(PreferencesMessages.TypeFilterInputDialog_choosepackage_label);
	dialog.setMessage(PreferencesMessages.TypeFilterInputDialog_choosepackage_description);
	dialog.setMultipleSelection(false);
	dialog.setFilter(fNameDialogField.getText());
	if (dialog.open() == IDialogConstants.OK_ID) {
		IPackageFragment res= (IPackageFragment) dialog.getFirstResult();
		fNameDialogField.setText(res.getElementName() + "*"); //$NON-NLS-1$
	}
}
 
Example 13
Source File: SourceType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ITypeHierarchy newSupertypeHierarchy(
	ICompilationUnit[] workingCopies,
	IProgressMonitor monitor)
	throws JavaModelException {

	CreateTypeHierarchyOperation op= new CreateTypeHierarchyOperation(this, workingCopies, SearchEngine.createWorkspaceScope(), false);
	op.runOperation(monitor);
	return op.getResult();
}
 
Example 14
Source File: WebXmlValidator.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static boolean classExists(IJavaProject project, String typeName) {
  if (Strings.isNullOrEmpty(typeName)) {
    return false;
  }
  SearchPattern pattern = SearchPattern.createPattern(typeName,
      IJavaSearchConstants.CLASS,
      IJavaSearchConstants.DECLARATIONS,
      SearchPattern.R_EXACT_MATCH | SearchPattern.R_ERASURE_MATCH);
  IJavaSearchScope scope = project == null ? SearchEngine.createWorkspaceScope()
      : SearchEngine.createJavaSearchScope(new IJavaElement[] {project});
  return performSearch(pattern, scope, null);
}
 
Example 15
Source File: TemplateCustomPropertiesPage.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Opens the class selection dialog.
 * 
 * @param tokenViewer
 *            the token {@link Viewer}
 * @param servicesTable
 *            the service {@link Viewer}
 * @param customProperties
 *            the {@link TemplateCustomProperties}
 */
private void openClassSelectionDialog(Viewer tokenViewer, Viewer servicesTable,
        final TemplateCustomProperties customProperties) {
    final IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
    final FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(
            Display.getCurrent().getActiveShell(), true, PlatformUI.getWorkbench().getProgressService(), scope,
            IJavaSearchConstants.CLASS);
    if (dialog.open() == Dialog.OK && dialog.getResult() != null && dialog.getResult().length != 0) {
        for (Object object : dialog.getResult()) {
            IPath parentPath = ((IType) object).getParent().getPath();
            if (parentPath.getFileExtension().equals("jar")) {
                int indexOfUnderscore = parentPath.lastSegment().indexOf('_');
                if (indexOfUnderscore > -1) {
                    final String pluginName = parentPath.lastSegment().substring(0, indexOfUnderscore);
                    customProperties.getServiceClasses().put(((IType) object).getFullyQualifiedName(), pluginName);
                } else {
                    customProperties.getServiceClasses().put(((IType) object).getFullyQualifiedName(), "");
                }
            } else {
                final String bundleName = getBundleName((IType) object);
                if (bundleName != null) {
                    customProperties.getServiceClasses().put(((IType) object).getFullyQualifiedName(), bundleName);
                } else {
                    customProperties.getServiceClasses().put(((IType) object).getFullyQualifiedName(),
                            ((IType) object).getJavaProject().getProject().getName());
                }
            }
        }
        tokenViewer.refresh();
        servicesTable.refresh();
        templateVariablesProperties.validatePage(customProperties);
    }
}
 
Example 16
Source File: BinaryType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ITypeHierarchy newTypeHierarchy(
	ICompilationUnit[] workingCopies,
	IProgressMonitor monitor)
	throws JavaModelException {

	CreateTypeHierarchyOperation op= new CreateTypeHierarchyOperation(this, workingCopies, SearchEngine.createWorkspaceScope(), true);
	op.runOperation(monitor);
	return op.getResult();
}
 
Example 17
Source File: BinaryType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ITypeHierarchy newTypeHierarchy(
	WorkingCopyOwner owner,
	IProgressMonitor monitor)
	throws JavaModelException {

	ICompilationUnit[] workingCopies = JavaModelManager.getJavaModelManager().getWorkingCopies(owner, true/*add primary working copies*/);
	CreateTypeHierarchyOperation op= new CreateTypeHierarchyOperation(this, workingCopies, SearchEngine.createWorkspaceScope(), true);
	op.runOperation(monitor);
	return op.getResult();
}
 
Example 18
Source File: SourceType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see IType#newSupertypeHierarchy(WorkingCopyOwner, IProgressMonitor)
 */
public ITypeHierarchy newSupertypeHierarchy(
	WorkingCopyOwner owner,
	IProgressMonitor monitor)
	throws JavaModelException {

	ICompilationUnit[] workingCopies = JavaModelManager.getJavaModelManager().getWorkingCopies(owner, true/*add primary working copies*/);
	CreateTypeHierarchyOperation op= new CreateTypeHierarchyOperation(this, workingCopies, SearchEngine.createWorkspaceScope(), false);
	op.runOperation(monitor);
	return op.getResult();
}
 
Example 19
Source File: SearchBrokenNLSKeysUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static void search(String scopeName, IType[] accessorClasses, IFile[] propertieFiles) {
	NLSSearchQuery query= new NLSSearchQuery(accessorClasses, propertieFiles, SearchEngine.createWorkspaceScope(), scopeName);
	NewSearchUI.runQueryInBackground(query);
}
 
Example 20
Source File: TypeSelectionComponent.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void fillViewMenu(IMenuManager viewMenu) {
	if (!fMultipleSelection) {
		ToggleStatusLineAction showStatusLineAction= new ToggleStatusLineAction();
		showStatusLineAction.setChecked(fSettings.getBoolean(SHOW_STATUS_LINE));
		viewMenu.add(showStatusLineAction);
	}
	FullyQualifyDuplicatesAction fullyQualifyDuplicatesAction= new FullyQualifyDuplicatesAction();
	fullyQualifyDuplicatesAction.setChecked(fSettings.getBoolean(FULLY_QUALIFY_DUPLICATES));
	viewMenu.add(fullyQualifyDuplicatesAction);
	if (fScope == null) {
		fFilterActionGroup= new WorkingSetFilterActionGroup(getShell(),
			JavaPlugin.getActivePage(),
			new IPropertyChangeListener() {
				public void propertyChange(PropertyChangeEvent event) {
					IWorkingSet ws= (IWorkingSet)event.getNewValue();
					if (ws == null || (ws.isAggregateWorkingSet() && ws.isEmpty())) {
						fScope= SearchEngine.createWorkspaceScope();
						fTitleLabel.setText(null);
					} else {
						fScope= JavaSearchScopeFactory.getInstance().createJavaSearchScope(ws, true);
						fTitleLabel.setText(ws.getLabel());
					}
					fViewer.setSearchScope(fScope, true);
				}
			});
		String setting= fSettings.get(WORKINGS_SET_SETTINGS);
		if (setting != null) {
			try {
				IMemento memento= XMLMemento.createReadRoot(new StringReader(setting));
				fFilterActionGroup.restoreState(memento);
			} catch (WorkbenchException e) {
			}
		}
		IWorkingSet ws= fFilterActionGroup.getWorkingSet();
		if (ws == null || (ws.isAggregateWorkingSet() && ws.isEmpty())) {
			fScope= SearchEngine.createWorkspaceScope();
			fTitleLabel.setText(null);
		} else {
			fScope= JavaSearchScopeFactory.getInstance().createJavaSearchScope(ws, true);
			fTitleLabel.setText(ws.getLabel());
		}
		fFilterActionGroup.fillViewMenu(viewMenu);
	}
}