Java Code Examples for org.eclipse.ui.dialogs.ElementListSelectionDialog#setElements()

The following examples show how to use org.eclipse.ui.dialogs.ElementListSelectionDialog#setElements() . 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: DotnetTestTab.java    From aCute with Eclipse Public License 2.0 6 votes vote down vote up
private void displayMethodSelectorDialog() {
	ElementListSelectionDialog dialog = new ElementListSelectionDialog(classBrowseButton.getShell(),
			new LabelProvider());
	dialog.setTitle(NLS.bind(Messages.DotnetTestTab_methodSelection_title, classText.getText()));
	dialog.setMessage(Messages.DotnetTestTab_methodSelection_message);
	List<String> methods = testMethods.get(classText.getText());
	if(methods!=null) {
		dialog.setElements(methods.toArray());
	}
	dialog.open();
	String selected = (String) dialog.getFirstResult();
	if (selected != null) {
		methodText.setText(selected);
		setDirty(true);
		updateLaunchConfigurationDialog();
	}
}
 
Example 2
Source File: AbstractLauncherTab.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
protected IProject chooseXdsProject() {
    ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
    dialog.setTitle(Messages.LauncherTabMain_ProjectSelection); 
    dialog.setMessage(Messages.LauncherTabMain_SelectXdsProject+':');

    dialog.setElements(ProjectUtils.getXdsProjects().toArray());

    IProject currentProject = getCurrentXdsProject();
    if (currentProject != null) {
        dialog.setInitialSelections(new Object[] { currentProject });
    }
    if (dialog.open() == Window.OK) {			
        return (IProject) dialog.getFirstResult();
    }		
    return null;		
}
 
Example 3
Source File: SimpleListSelectionDialog.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private SimpleListSelectionDialog(
		Shell shell, 
		String title, 
		String message, 
		Image image,
		ITextProvider iTextProvider,
		Object[] items, 
		Object initialSelection) 
{
	this.image = image;
	this.iTextProvider = iTextProvider;
	if (shell == null) {
		shell = SwtUtils.getDefaultShell();
	}
	dialog= new ElementListSelectionDialog(shell, new SimpleLabelProvider());
	dialog.setTitle(title); 
	dialog.setMessage(message);
	dialog.setElements(items);
	if (initialSelection != null) {
		dialog.setInitialSelections(new Object[] { initialSelection });
	}
}
 
Example 4
Source File: TestabilityLaunchConfigurationTab.java    From testability-explorer with Apache License 2.0 6 votes vote down vote up
private void setUpBrowseProjectDialog() {
  ILabelProvider projectLabelProvider = new BrowseProjectLabelProvider();

  IJavaProject[] javaProjects = javaProjectHelper.getJavaProjects();

  ElementListSelectionDialog dialog =
      new ElementListSelectionDialog(getControl().getShell(), projectLabelProvider);
  dialog.setMessage("Choose a project to run testability on:");

  if (javaProjects != null) {
    dialog.setElements(javaProjects);
  }

  if (dialog.open() == Window.OK) {
    IJavaProject project = (IJavaProject) dialog.getFirstResult();
    projectText.setText(project.getElementName());
    setTabDirty();
  }
}
 
Example 5
Source File: LaunchConfigurationUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns a configuration from the given collection of configurations that
 * should be launched, or <code>null</code> to cancel. Default implementation
 * opens a selection dialog that allows the user to choose one of the
 * specified launch configurations. Returns the chosen configuration, or
 * <code>null</code> if the user cancels.
 * 
 * @param configList list of configurations to choose from
 * @return configuration to launch or <code>null</code> to cancel
 */
public static ILaunchConfiguration chooseConfiguration(
    List<ILaunchConfiguration> configList, Shell shell) {
  IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation();
  try {
    ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell,
        labelProvider);
    dialog.setElements(configList.toArray());
    dialog.setTitle("Choose a launch configuration:");
    dialog.setMessage("More than one launch configuration is applicable; please choose one:");
    dialog.setMultipleSelection(false);
    int result = dialog.open();
    if (result == Window.OK) {
      return (ILaunchConfiguration) dialog.getFirstResult();
    }
    return null;
  } finally {
    labelProvider.dispose();
  }
}
 
Example 6
Source File: AbstractLaunchShortcut.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * COPIED/MODIFIED from AntLaunchShortcut
 */
protected ILaunchConfiguration chooseConfig(List<ILaunchConfiguration> configs) {
    if (configs.isEmpty()) {
        return null;
    }
    ILabelProvider labelProvider = DebugUITools.newDebugModelPresentation();
    ElementListSelectionDialog dialog = new ElementListSelectionDialog(Display.getDefault().getActiveShell(),
            labelProvider);
    dialog.setElements(configs.toArray(new ILaunchConfiguration[configs.size()]));
    dialog.setTitle("Pick a Python configuration");
    dialog.setMessage("Choose a python configuration to run");
    dialog.setMultipleSelection(false);
    int result = dialog.open();
    labelProvider.dispose();
    if (result == Window.OK) {
        return (ILaunchConfiguration) dialog.getFirstResult();
    } else {
        return null;
    }
}
 
Example 7
Source File: NewSourceFolderWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IJavaProject chooseProject() {
	IJavaProject[] projects;
	try {
		projects= JavaCore.create(fWorkspaceRoot).getJavaProjects();
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
		projects= new IJavaProject[0];
	}

	ILabelProvider labelProvider= new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT);
	ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), labelProvider);
	dialog.setTitle(NewWizardMessages.NewSourceFolderWizardPage_ChooseProjectDialog_title);
	dialog.setMessage(NewWizardMessages.NewSourceFolderWizardPage_ChooseProjectDialog_description);
	dialog.setElements(projects);
	dialog.setInitialSelections(new Object[] { fCurrJProject });
	dialog.setHelpAvailable(false);
	if (dialog.open() == Window.OK) {
		return (IJavaProject) dialog.getFirstResult();
	}
	return null;
}
 
Example 8
Source File: ProjectField.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
protected IProject chooseProject() throws OperationCancellation {
	Shell shell = button.getShell();
	ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell, new WorkbenchLabelProvider());
	dialog.setTitle(LangUIMessages.projectField_chooseProject_title);
	dialog.setMessage(LangUIMessages.projectField_chooseProject_message);

	try {
		final IProject[] projects = getDialogChooseElements(); 
		dialog.setElements(projects);
	} catch (CoreException ce) {
		EclipseCore.logStatus(ce);
	}
	
	final IProject project = getProject();
	if (project != null && project.isOpen()) {
		dialog.setInitialSelections(new Object[] { project });
	}
	
	if (dialog.open() == Window.OK) {
		return (IProject) dialog.getFirstResult();
	}
	throw new OperationCancellation();
}
 
Example 9
Source File: SelectionConverter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Shows a dialog for resolving an ambiguous Java element. Utility method that can be called by subclasses.
 *
 * @param elements the elements to select from
 * @param shell the parent shell
 * @param title the title of the selection dialog
 * @param message the message of the selection dialog
 * @return returns the selected element or <code>null</code> if the dialog has been cancelled
 */
public static IJavaElement selectJavaElement(IJavaElement[] elements, Shell shell, String title, String message) {
	int nResults= elements.length;
	if (nResults == 0)
		return null;
	if (nResults == 1)
		return elements[0];

	int flags= JavaElementLabelProvider.SHOW_DEFAULT | JavaElementLabelProvider.SHOW_QUALIFIED | JavaElementLabelProvider.SHOW_ROOT;

	ElementListSelectionDialog dialog= new ElementListSelectionDialog(shell, new JavaElementLabelProvider(flags));
	dialog.setTitle(title);
	dialog.setMessage(message);
	dialog.setElements(elements);

	if (dialog.open() == Window.OK) {
		return (IJavaElement) dialog.getFirstResult();
	}
	return null;
}
 
Example 10
Source File: PackageBrowseAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void changeControlPressed(DialogField field) {
	ElementListSelectionDialog dialog= new ElementListSelectionDialog(
		Display.getCurrent().getActiveShell(), new JavaElementLabelProvider());
       dialog.setIgnoreCase(false);
       dialog.setTitle(NLSUIMessages.PackageBrowseAdapter_package_selection);
       dialog.setMessage(NLSUIMessages.PackageBrowseAdapter_choose_package);
       dialog.setElements(createPackageListInput(fCu, null));
       if (dialog.open() == Window.OK) {
       	IPackageFragment selectedPackage= (IPackageFragment)dialog.getFirstResult();
       	if (selectedPackage != null) {
       		fReceiver.setPackage(selectedPackage);
       	}
       }
}
 
Example 11
Source File: AbstractSarlScriptInteractiveSelector.java    From sarl with Apache License 2.0 5 votes vote down vote up
/**
 * Prompts the user to select an element from the given element types.
 *
 * @param elements the element types to choose from.
 * @return the selected element or {@code null} if none.
 */
private ElementDescription chooseElement(List<ElementDescription> elements) {
	final ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(),
			new LabelProvider());
	dialog.setElements(elements.toArray());
	dialog.setTitle(MessageFormat.format(Messages.AbstractSarlScriptInteractiveSelector_3, getElementLabel()));
	dialog.setMessage(MessageFormat.format(Messages.AbstractSarlScriptInteractiveSelector_3,
			getElementLongLabel()));
	dialog.setMultipleSelection(false);
	final int result = dialog.open();
	if (result == Window.OK) {
		return (ElementDescription) dialog.getFirstResult();
	}
	return null;
}
 
Example 12
Source File: AddImportOnSelectionAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public TypeNameMatch chooseImport(TypeNameMatch[] results, String containerName) {
	int nResults= results.length;

	if (nResults == 0) {
		return null;
	} else if (nResults == 1) {
		return results[0];
	}

	if (containerName.length() != 0) {
		for (int i= 0; i < nResults; i++) {
			TypeNameMatch curr= results[i];
			if (containerName.equals(curr.getTypeContainerName())) {
				return curr;
			}
		}
	}
	fIsShowing= true;
	ElementListSelectionDialog dialog= new ElementListSelectionDialog(fShell, new TypeNameMatchLabelProvider(TypeNameMatchLabelProvider.SHOW_FULLYQUALIFIED)) {
		@Override
		protected FilteredList createFilteredList(Composite parent) {
			FilteredList filteredList= super.createFilteredList(parent);
			filteredList.setComparator(ADD_IMPORT_COMPARATOR);
			return filteredList;
		}
	};
	dialog.setTitle(JavaEditorMessages.AddImportOnSelection_dialog_title);
	dialog.setMessage(JavaEditorMessages.AddImportOnSelection_dialog_message);
	dialog.setElements(results);
	if (dialog.open() == Window.OK) {
		fIsShowing= false;
		TypeNameMatch result= (TypeNameMatch) dialog.getFirstResult();
		QualifiedTypeNameHistory.remember(result.getFullyQualifiedName());
		return result;
	}
	fIsShowing= false;
	return null;
}
 
Example 13
Source File: NewTypeWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Opens a selection dialog that allows to select a package.
 *
 * @return returns the selected package or <code>null</code> if the dialog has been canceled.
 * The caller typically sets the result to the package input field.
 * <p>
 * Clients can override this method if they want to offer a different dialog.
 * </p>
 *
 * @since 3.2
 */
protected IPackageFragment choosePackage() {
	IPackageFragmentRoot froot= getPackageFragmentRoot();
	IJavaElement[] packages= null;
	try {
		if (froot != null && froot.exists()) {
			packages= froot.getChildren();
		}
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
	}
	if (packages == null) {
		packages= new IJavaElement[0];
	}

	ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT));
	dialog.setIgnoreCase(false);
	dialog.setTitle(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_title);
	dialog.setMessage(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_description);
	dialog.setEmptyListMessage(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_empty);
	dialog.setElements(packages);
	dialog.setHelpAvailable(false);

	IPackageFragment pack= getPackageFragment();
	if (pack != null) {
		dialog.setInitialSelections(new Object[] { pack });
	}

	if (dialog.open() == Window.OK) {
		return (IPackageFragment) dialog.getFirstResult();
	}
	return null;
}
 
Example 14
Source File: FindAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IJavaElement findType(ICompilationUnit cu, boolean silent) {
	IType[] types= null;
	try {
		types= cu.getAllTypes();
	} catch (JavaModelException ex) {
		if (JavaModelUtil.isExceptionToBeLogged(ex))
			ExceptionHandler.log(ex, SearchMessages.JavaElementAction_error_open_message);
		if (silent)
			return RETURN_WITHOUT_BEEP;
		else
			return null;
	}
	if (types.length == 1 || (silent && types.length > 0))
		return types[0];
	if (silent)
		return RETURN_WITHOUT_BEEP;
	if (types.length == 0)
		return null;
	String title= SearchMessages.JavaElementAction_typeSelectionDialog_title;
	String message = SearchMessages.JavaElementAction_typeSelectionDialog_message;
	int flags= (JavaElementLabelProvider.SHOW_DEFAULT);

	ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), new JavaElementLabelProvider(flags));
	dialog.setTitle(title);
	dialog.setMessage(message);
	dialog.setElements(types);

	if (dialog.open() == Window.OK)
		return (IType)dialog.getFirstResult();
	else
		return RETURN_WITHOUT_BEEP;
}
 
Example 15
Source File: NLSAccessorConfigurationDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void browseForPropertyFile() {
	ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), new JavaElementLabelProvider());
	dialog.setIgnoreCase(false);
	dialog.setTitle(NLSUIMessages.NLSAccessorConfigurationDialog_Property_File_Selection);
	dialog.setMessage(NLSUIMessages.NLSAccessorConfigurationDialog_Choose_the_property_file);
	dialog.setElements(createFileListInput());
	dialog.setFilter('*' + NLSRefactoring.PROPERTY_FILE_EXT);
	if (dialog.open() == Window.OK) {
		IFile selectedFile= (IFile) dialog.getFirstResult();
		if (selectedFile != null)
			fResourceBundleFile.setText(selectedFile.getName());
	}
}
 
Example 16
Source File: PackageSelectionStringButtonAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void changeControlPressed(DialogField field) {
	IPackageFragmentRoot root= fPackageSelectionField.getSelectedFragmentRoot();

	IJavaElement[] packages= null;
	try {
		if (root != null && root.exists()) {
			packages= root.getChildren();
		}
	} catch (JavaModelException e) {
		// no need to react
	}

	if (packages == null) {
		packages= new IJavaElement[0];
	}

	ElementListSelectionDialog dialog= new ElementListSelectionDialog(field.getLabelControl(null).getShell(),
		new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT));
	dialog.setIgnoreCase(true);

	dialog.setTitle(fTitle);
	dialog.setMessage(fMessage);
	dialog.setEmptyListMessage(fEmtpyListMessage);
	dialog.setElements(packages);

	// TODO initial selection
	//    List selection = new ArrayList();
	//    selection.add(fPackageSelectionField.fPackageSelection.getPackageFragment());
	//    dialog.setInitialElementSelections(selection);

	if (dialog.open() == Window.OK) {
		IPackageFragment fragment= (IPackageFragment)dialog.getFirstResult();
		fPackageSelectionField.setSelected(fragment);
	}
}
 
Example 17
Source File: CdtProjectFieldEditor.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected String changePressed() {
	ElementListSelectionDialog dialog =
		new ElementListSelectionDialog(getShell(), new LabelProvider());
	dialog.setTitle("CDT project selection");
	dialog.setMessage("Select an open CDT project:");
	dialog.setElements(CdtUtils.getCDTProjects().stream().map(p -> p.getName()).toArray());
	dialog.open();
	Object[] result = dialog.getResult();
	if (result != null && result.length > 0 && result[0] instanceof String) {
		return (String) result[0];
	}
	return null;
}
 
Example 18
Source File: NewModuleWizardPage.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private IPackageFragment choosePackage() {
  IPackageFragmentRoot root = getPackageFragmentRoot();
  IJavaElement[] packages = null;
  try {
    if (root != null && root.exists()) {
      packages = root.getChildren();
    }
  } catch (JavaModelException e) {
    JavaPlugin.log(e);
  }
  if (packages == null) {
    packages = new IJavaElement[0];
  }

  ElementListSelectionDialog dialog = new ElementListSelectionDialog(
      getShell(), new JavaElementLabelProvider(
          JavaElementLabelProvider.SHOW_DEFAULT));
  dialog.setIgnoreCase(false);
  dialog.setTitle(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_title);
  dialog.setMessage(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_description);
  dialog.setEmptyListMessage(NewWizardMessages.NewTypeWizardPage_ChoosePackageDialog_empty);
  dialog.setElements(packages);
  dialog.setHelpAvailable(false);

  if (dialog.open() == Window.OK) {
    return (IPackageFragment) dialog.getFirstResult();
  }
  return null;
}
 
Example 19
Source File: GWTCompileDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private IJavaProject chooseProject() {
  IJavaProject[] javaProjects;

  try {
    javaProjects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects();
  } catch (JavaModelException e) {
    GWTPluginLog.logError(e);
    javaProjects = new IJavaProject[0];
  }

  // Filter the list to only show GWT projects
  List<IJavaProject> gwtProjects = new ArrayList<IJavaProject>();
  for (IJavaProject javaProject : javaProjects) {
    if (GWTNature.isGWTProject(javaProject.getProject())) {
      gwtProjects.add(javaProject);
    }
  }

  ILabelProvider labelProvider = new JavaElementLabelProvider(
      JavaElementLabelProvider.SHOW_DEFAULT);
  ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider);
  dialog.setTitle("Project Selection");
  dialog.setMessage("Choose a project to compile");
  dialog.setElements(gwtProjects.toArray(new IJavaProject[0]));
  dialog.setInitialSelections(new Object[] {JavaCore.create(project)});

  dialog.setHelpAvailable(false);
  if (dialog.open() == Window.OK) {
    return (IJavaProject) dialog.getFirstResult();
  }
  return null;
}
 
Example 20
Source File: ControlUtils.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T setElementsAndOpenDialog(ElementListSelectionDialog elementListDialog, Object[] elements)
		throws OperationCancellation {
	elementListDialog.setElements(elements);
	int result = elementListDialog.open();
	if(result != Window.OK) {
		throw new OperationCancellation();
	}
	
	return (T) elementListDialog.getFirstResult();
}