private String handleBrowse(String filter) { IJavaSearchScope scope = null; if (_project == null) { scope = SearchEngine.createWorkspaceScope(); } else { scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {_project}); } try { SelectionDialog dialog = JavaUI.createTypeDialog( Display.getCurrent().getActiveShell(), null, scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, filter.isEmpty() ? "* " : filter); if (dialog.open() == SelectionDialog.OK) { Object[] result = dialog.getResult(); if (result.length > 0 && result[0] instanceof IType) { return ((IType) result[0]).getFullyQualifiedName(); } } } catch (JavaModelException e) { e.printStackTrace(); } return null; }
/** * Creates and opens a dialog enabling the user to select one or more elements from the specified * input tree. * * @param shell The parent shell for the dialog. * @param input The input for the dialog's tree. * @param allowMultipleSelections Whether or not to allow multiple items to be selected. If false, * then only one item may be selected from the tree, otherwise the tree's selection will be * determined by checkboxes. * @return The result of the dialog, usually either {@link Window#OK} or {@link Window#CANCEL}. */ public int openDialog(Shell shell, Object input, boolean allowMultipleSelections) { // Create the dialog if necessary. final SelectionDialog dialog; // Set up the content and label providers. These are required for // any TreeViewer. ITreeContentProvider contentProvider = createContentProvider(); ILabelProvider labelProvider = createLabelProvider(); // Create a dialog with or without checkboxes in the tree. if (allowMultipleSelections) { dialog = createCheckedTreeSelectionDialog(shell, labelProvider, contentProvider); } else { dialog = createElementTreeSelectionDialog(shell, labelProvider, contentProvider); } // Set its title and message. dialog.setTitle(title); dialog.setMessage(message); setInput(input); // Set the input and refresh the viewer. if (allowMultipleSelections) { CheckedTreeSelectionDialog treeDialog = (CheckedTreeSelectionDialog) dialog; treeDialog.setInput(root); if (!initialSelection.isEmpty()) { treeDialog.setInitialSelections(initialSelection.toArray()); newSelection.addAll(initialSelection); } } else { ElementTreeSelectionDialog treeDialog = (ElementTreeSelectionDialog) dialog; treeDialog.setInput(root); if (!initialSelection.isEmpty()) { Node initialNode = initialSelection.iterator().next(); treeDialog.setInitialSelection(initialNode); newSelection.add(initialNode); } } // Return the result of opening the dialog. int result = dialog.open(); // If the dialog was closed or cancelled, reset the selection to the // initial one. if (result != Window.OK) { newSelection.clear(); for (Node node : initialSelection) { newSelection.add(node); } } return result; }
/** * Restores the modules. Is called when the user changed something in the editor and applies the * change. * * <p>Gathers all the info and calls the hook that really restores things within a thread, so that * the user can get information on the progress. * * <p>Only the information on the default interpreter is stored. * * @param editorChanged whether the editor was changed (if it wasn't, we'll ask the user what to * restore). * @return true if the info was restored and false otherwise. */ protected void restoreInterpreterInfos(boolean editorChanged) { final Set<String> interpreterNamesToRestore = pathEditor.getInterpreterExeOrJarToRestoreAndClear(); final IInterpreterInfo[] exesList = pathEditor.getExesList(); if (!editorChanged && interpreterNamesToRestore.size() == 0) { IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); SelectionDialog listDialog = createChooseIntepreterInfoDialog( workbenchWindow, exesList, "Select interpreters to be restored", true); int open = listDialog.open(); if (open != ListDialog.OK) { return; } Object[] result = (Object[]) listDialog.getResult(); if (result == null || result.length == 0) { return; } for (Object o : result) { interpreterNamesToRestore.add(((IInterpreterInfo) o).getExecutableOrJar()); } } // this is the default interpreter ProgressMonitorDialog monitorDialog = new AsynchronousProgressMonitorDialog(this.getShell()); monitorDialog.setBlockOnOpen(false); try { IRunnableWithProgress operation = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Restoring PYTHONPATH", IProgressMonitor.UNKNOWN); try { // clear all but the ones that appear getInterpreterManager().setInfos(exesList, interpreterNamesToRestore, monitor); } finally { monitor.done(); } } }; monitorDialog.run(true, true, operation); } catch (Exception e) { Log.log(e); } }
/** * @param shell Shell for the window * @param superTypeName supertype to search for * @param project project to look in * @return IType the type created * @throws JavaModelException exception thrown */ public IType selectType(Shell shell, String superTypeName, IProject project) throws JavaModelException { IJavaSearchScope searchScope = null; if (project == null) { ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); IStructuredSelection selectionToPass = StructuredSelection.EMPTY; if (selection instanceof IStructuredSelection) { selectionToPass = (IStructuredSelection) selection; if (selectionToPass.getFirstElement() instanceof IFile) { project = ((IFile) selectionToPass.getFirstElement()).getProject(); } } } if (superTypeName != null && !superTypeName.equals("java.lang.Object")) { // $NON-NLS-1$ if (project == null) { project = model.getProject(); } IJavaProject javaProject = JavaCore.create(project); IType superType = javaProject.findType(superTypeName); if (superType != null) { searchScope = SearchEngine.createStrictHierarchyScope(javaProject, superType, true, false, null); } } else { searchScope = SearchEngine.createWorkspaceScope(); } SelectionDialog dialog = JavaUI.createTypeDialog( shell, new ProgressMonitorDialog(shell), searchScope, IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES, false); dialog.setTitle("Select Class"); dialog.setMessage("Matching items"); if (dialog.open() == IDialogConstants.CANCEL_ID) { return null; } Object[] types = dialog.getResult(); if (types == null || types.length == 0) { return null; } return (IType) types[0]; }
private void handleBrowsePackages(Shell dialogParrentShell) { try { IResource sourceContainer = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(getSourceFolder())); IJavaProject javaProject = JDTUtil.getJavaProject(sourceContainer.getProject().getName()); SelectionDialog dialog = JavaUI.createPackageDialog(dialogParrentShell, javaProject, 0); dialog.setTitle("Package selection"); dialog.setMessage("&Choose a package:"); if (dialog.open() == SelectionDialog.OK) { Object[] selectedPackages = dialog.getResult(); if (selectedPackages.length == 1) { m_packageNameText.setText(((IPackageFragment) selectedPackages[0]).getElementName()); } } } catch (JavaModelException e) { updateStatus("Failed to list packages."); } }
private void addScriptComponent() throws Exception { IJavaProject javaProject = editorContext.javaProject; IJavaSearchScope scope = createHierarchyScope(javaProject.findType(SceneNodeComponent.class.getName())); ProgressMonitorDialog monitor = new ProgressMonitorDialog(getShell()); SelectionDialog dialog = JavaUI.createTypeDialog(getShell(), monitor, scope, CONSIDER_CLASSES, false); if (dialog.open() != IDialogConstants.OK_ID) { return; } Object[] types = dialog.getResult(); if (types != null && types.length > 0) { IType type = (IType) types[0]; ClassLoader classLoader = editorContext.classLoader; Class<?> resolvedClass = classLoader.loadClass(type.getFullyQualifiedName()); Constructor<?> constructor = resolvedClass.getDeclaredConstructor(new Class[0]); constructor.setAccessible(true); SceneNodeComponent component = Values.cast(constructor.newInstance(new Object[0])); addComponent(component); } }
public String chooseClass() { SelectionDialog dialog; try { dialog = JavaUI.createTypeDialog( shell, new ProgressMonitorDialog(shell), SearchEngine.createWorkspaceScope(), IJavaElementSearchConstants.CONSIDER_CLASSES, false); } catch (Exception e) { Activator.logError(e); return null; } if (dialog.open() != SelectionDialog.OK) { return null; } Object[] result = dialog.getResult(); String clazz = ((IType) result[0]).getFullyQualifiedName(); IJavaProject containerProject = ((IType) result[0]).getJavaProject(); DiagramEditor diagramEditor = Bpmn2Editor.getActiveEditor(); IProject currentProject = getProjectFromDiagram(diagramEditor.getDiagramTypeProvider().getDiagram()); try { doProjectReferenceChange(currentProject, containerProject, clazz); } catch (Exception e) { return null; } return clazz; }
private void addType() { Shell shell = fAddTypeButton.getDisplay().getActiveShell(); SelectionDialog dialog = null; try { dialog = JavaUI.createTypeDialog( shell, PlatformUI.getWorkbench().getProgressService(), SearchEngine.createJavaSearchScope( new IJavaElement[] {fEditor.getJavaProject()}, true), IJavaElementSearchConstants.CONSIDER_ALL_TYPES, false); } catch (JavaModelException jme) { String title = SnippetMessages.getString("SelectImportsDialog.Add_Type_as_Import_12"); // $NON-NLS-1$ String message = SnippetMessages.getString( "SelectImportsDialog.Could_not_open_class_selection_dialog_13"); //$NON-NLS-1$ ExceptionHandler.handle(jme, title, message); return; } dialog.setTitle( SnippetMessages.getString("SelectImportsDialog.Add_Type_as_Import_12")); // $NON-NLS-1$ dialog.setMessage( SnippetMessages.getString( "SelectImportsDialog.&Select_a_type_to_add_to_add_as_an_import_15")); //$NON-NLS-1$ if (dialog.open() == IDialogConstants.CANCEL_ID) { return; } Object[] types = dialog.getResult(); if (types != null && types.length > 0) { IType type = (IType) types[0]; fImportContentProvider.addImport(type.getFullyQualifiedName()); } }
/** * @param pythonNatures the natures from were we can get info * @param additionalInfo the additional informations * @param selectedText the text that should be initially set as a filter */ public static void doSelect( List<IPythonNature> pythonNatures, List<AbstractAdditionalTokensInfo> additionalInfo, String selectedText) { SelectionDialog dialog = GlobalsDialogFactory.create(getShell(), additionalInfo, selectedText, pythonNatures); dialog.open(); Object[] result = dialog.getResult(); if (result != null && result.length > 0) { for (Object obj : result) { IInfo entry; if (obj instanceof AdditionalInfoAndIInfo) { entry = ((AdditionalInfoAndIInfo) obj).info; } else { entry = (IInfo) obj; } List<ItemPointer> pointers = new ArrayList<ItemPointer>(); CompletionCache completionCache = new CompletionCache(); for (IPythonNature pythonNature : pythonNatures) { // try to find in one of the natures... ICodeCompletionASTManager astManager = pythonNature.getAstManager(); if (astManager == null) { continue; } AnalysisPlugin.getDefinitionFromIInfo( pointers, astManager, pythonNature, entry, completionCache); if (pointers.size() > 0) { new PyOpenAction().run(pointers.get(0)); break; // don't check the other natures } } } } }
/** * Opens a type selection dialog. If the user selects a type (and does not cancel), an editor is * opened on the selected type. * * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event) */ @Override public void runWithEvent(Event e) { Shell parent = DartToolsPlugin.getActiveWorkbenchShell(); if (!doCreateProjectFirstOnEmptyWorkspace(parent)) { return; } SelectionDialog dialog = new OpenTypeSelectionDialog( parent, true, PlatformUI.getWorkbench().getProgressService(), null, SEARCH_ELEMENT_KINDS); dialog.setTitle(DartUIMessages.OpenTypeAction_dialogTitle); dialog.setMessage(DartUIMessages.OpenTypeAction_dialogMessage); int result = dialog.open(); if (result != IDialogConstants.OK_ID) { return; } Object[] types = dialog.getResult(); if (types == null || types.length == 0) { return; } if (types.length == 1) { try { DartUI.openInEditor((Element) types[0], true, true); } catch (CoreException x) { ExceptionHandler.handle( x, DartUIMessages.OpenTypeAction_errorTitle, DartUIMessages.OpenTypeAction_errorMessage); } return; } final IWorkbenchPage workbenchPage = DartToolsPlugin.getActivePage(); if (workbenchPage == null) { IStatus status = new Status( IStatus.ERROR, DartToolsPlugin.getPluginId(), DartUIMessages.OpenTypeAction_no_active_WorkbenchPage); ExceptionHandler.handle( status, DartUIMessages.OpenTypeAction_errorTitle, DartUIMessages.OpenTypeAction_errorMessage); return; } MultiStatus multiStatus = new MultiStatus( DartToolsPlugin.getPluginId(), DartStatusConstants.INTERNAL_ERROR, DartUIMessages.OpenTypeAction_multiStatusMessage, null); for (int i = 0; i < types.length; i++) { Type type = (Type) types[i]; try { DartUI.openInEditor(type, true, true); } catch (CoreException x) { multiStatus.merge(x.getStatus()); } } if (!multiStatus.isOK()) { ExceptionHandler.handle( multiStatus, DartUIMessages.OpenTypeAction_errorTitle, DartUIMessages.OpenTypeAction_errorMessage); } }
@Override public String browse(final Presentation context) { final Property property = property(); final EnumSet<JavaTypeKind> kinds = EnumSet.noneOf(JavaTypeKind.class); if (this.paramKinds != null) { for (String kindString : this.paramKinds.split(",")) { kindString = kindString.trim(); if (kindString.equalsIgnoreCase(JavaTypeKind.CLASS.name())) { kinds.add(JavaTypeKind.CLASS); } else if (kindString.equalsIgnoreCase(JavaTypeKind.ABSTRACT_CLASS.name())) { kinds.add(JavaTypeKind.ABSTRACT_CLASS); } else if (kindString.equalsIgnoreCase(JavaTypeKind.INTERFACE.name())) { kinds.add(JavaTypeKind.INTERFACE); } else if (kindString.equalsIgnoreCase(JavaTypeKind.ANNOTATION.name())) { kinds.add(JavaTypeKind.ANNOTATION); } else if (kindString.equalsIgnoreCase(JavaTypeKind.ENUM.name())) { kinds.add(JavaTypeKind.ENUM); } else { final String msg = typeKindNotRecognized.format(kindString); Sapphire.service(LoggingService.class).logError(msg); } } } else { final JavaTypeConstraintService javaTypeConstraintService = property.service(JavaTypeConstraintService.class); if (javaTypeConstraintService != null) { kinds.addAll(javaTypeConstraintService.kinds()); } } int browseDialogStyle = IJavaElementSearchConstants.CONSIDER_ALL_TYPES; int count = kinds.size(); if (count == 1) { final JavaTypeKind kind = kinds.iterator().next(); switch (kind) { case CLASS: browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES; break; case ABSTRACT_CLASS: browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES; break; case INTERFACE: browseDialogStyle = IJavaElementSearchConstants.CONSIDER_INTERFACES; break; case ANNOTATION: browseDialogStyle = IJavaElementSearchConstants.CONSIDER_ANNOTATION_TYPES; break; case ENUM: browseDialogStyle = IJavaElementSearchConstants.CONSIDER_ENUMS; break; default: throw new IllegalStateException(); } } else if (count == 2) { if (kinds.contains(JavaTypeKind.CLASS) || kinds.contains(JavaTypeKind.ABSTRACT_CLASS)) { if (kinds.contains(JavaTypeKind.INTERFACE)) { browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES; } else if (kinds.contains(JavaTypeKind.ENUM)) { browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES_AND_ENUMS; } } } final IProject project = property.element().adapt(IProject.class); try { final SelectionDialog dlg = JavaUI.createTypeDialog( ((FormComponentPresentation) context).shell(), null, project, browseDialogStyle, false); dlg.setTitle( dialogTitle.format( property.definition().getLabel(true, CapitalizationType.TITLE_STYLE, false))); if (dlg.open() == SelectionDialog.OK) { Object results[] = dlg.getResult(); assert results != null && results.length == 1; if (results[0] instanceof IType) { return ((IType) results[0]).getFullyQualifiedName(); } } } catch (JavaModelException e) { Sapphire.service(LoggingService.class).log(e); } return null; }