Java Code Examples for org.eclipse.ui.dialogs.SelectionDialog#open()

The following examples show how to use org.eclipse.ui.dialogs.SelectionDialog#open() . 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: ImportOrganizeInputDialog.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.ImportOrganizeInputDialog_ChooseTypeDialog_title);
		dialog.setMessage(PreferencesMessages.ImportOrganizeInputDialog_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.ImportOrganizeInputDialog_ChooseTypeDialog_title, PreferencesMessages.ImportOrganizeInputDialog_ChooseTypeDialog_error_message);
	}
}
 
Example 2
Source File: ProblemSeveritiesConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void doBrowseTypes(StringButtonDialogField dialogField) {
	IRunnableContext context= new BusyIndicatorRunnableContext();
	IJavaSearchScope scope= SearchEngine.createWorkspaceScope();
	int style= IJavaElementSearchConstants.CONSIDER_ANNOTATION_TYPES;
	try {
		SelectionDialog dialog= JavaUI.createTypeDialog(getShell(), context, scope, style, false, dialogField.getText());
		dialog.setTitle(PreferencesMessages.NullAnnotationsConfigurationDialog_browse_title);
		dialog.setMessage(PreferencesMessages.NullAnnotationsConfigurationDialog_choose_annotation);
		if (dialog.open() == Window.OK) {
			IType res= (IType) dialog.getResult()[0];
			dialogField.setText(res.getFullyQualifiedName('.'));
		}
	} catch (JavaModelException e) {
		ExceptionHandler.handle(e, getShell(), PreferencesMessages.NullAnnotationsConfigurationDialog_error_title, PreferencesMessages.NullAnnotationsConfigurationDialog_error_message);
	}
}
 
Example 3
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 4
Source File: JarManifestWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected void handleMainClassBrowseButtonPressed() {
	List<IResource> resources= JarPackagerUtil.asResources(fJarPackage.getElements());
	if (resources == null) {
		setErrorMessage(JarPackagerMessages.JarManifestWizardPage_error_noResourceSelected);
		return;
	}
	IJavaSearchScope searchScope= JavaSearchScopeFactory.getInstance().createJavaSearchScope(resources.toArray(new IResource[resources.size()]), true);
	SelectionDialog dialog= JavaUI.createMainTypeDialog(getContainer().getShell(), getContainer(), searchScope, 0, false, ""); //$NON-NLS-1$
	dialog.setTitle(JarPackagerMessages.JarManifestWizardPage_mainTypeSelectionDialog_title);
	dialog.setMessage(JarPackagerMessages.JarManifestWizardPage_mainTypeSelectionDialog_message);
	if (fJarPackage.getManifestMainClass() != null)
		dialog.setInitialSelections(new Object[] {fJarPackage.getManifestMainClass()});

	if (dialog.open() == Window.OK) {
		fJarPackage.setManifestMainClass((IType)dialog.getResult()[0]);
		fMainClassText.setText(JarPackagerUtil.getMainClassName(fJarPackage));
	} else if (!fJarPackage.isMainClassValid(getContainer())) {
		// user did not cancel: no types were found
		fJarPackage.setManifestMainClass(null);
		fMainClassText.setText(JarPackagerUtil.getMainClassName(fJarPackage));
	}
}
 
Example 5
Source File: GenerateToStringDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void browseForBuilderClass() {
	try {
		IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new IJavaElement[] { getType().getJavaProject() });
		SelectionDialog dialog= JavaUI.createTypeDialog(getShell(), PlatformUI.getWorkbench().getProgressService(), scope,
				IJavaElementSearchConstants.CONSIDER_CLASSES, false, "*ToString", fExtension); //$NON-NLS-1$
		dialog.setTitle(JavaUIMessages.GenerateToStringDialog_customBuilderConfig_classSelection_windowTitle);
		dialog.setMessage(JavaUIMessages.GenerateToStringDialog_customBuilderConfig_classSelection_message);
		dialog.open();
		if (dialog.getReturnCode() == OK) {
			IType type= (IType)dialog.getResult()[0];
			fBuilderClassName.setText(type.getFullyQualifiedParameterizedName());
			List<String> suggestions= fValidator.getAppendMethodSuggestions(type);
			if (!suggestions.contains(fAppendMethodName.getText()))
				fAppendMethodName.setText(suggestions.get(0));
			suggestions= fValidator.getResultMethodSuggestions(type);
			if (!suggestions.contains(fResultMethodName.getText()))
				fResultMethodName.setText(suggestions.get(0));
		}
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
	}
}
 
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: GotoTypeAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
	Shell shell= JavaPlugin.getActiveWorkbenchShell();
	SelectionDialog dialog= null;
	try {
		dialog= JavaUI.createTypeDialog(shell, new ProgressMonitorDialog(shell),
			SearchEngine.createWorkspaceScope(), IJavaElementSearchConstants.CONSIDER_ALL_TYPES, false);
	} catch (JavaModelException e) {
		String title= getDialogTitle();
		String message= PackagesMessages.GotoType_error_message;
		ExceptionHandler.handle(e, title, message);
		return;
	}

	dialog.setTitle(getDialogTitle());
	dialog.setMessage(PackagesMessages.GotoType_dialog_message);
	if (dialog.open() == IDialogConstants.CANCEL_ID) {
		return;
	}

	Object[] types= dialog.getResult();
	if (types != null && types.length > 0) {
		gotoType((IType) types[0]);
	}
}
 
Example 8
Source File: OpenOppositeFileHandler.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected List<FileOpener> selectOpeners(IWorkbenchPage page, Collection<FileOpener> openers) {
	Shell shell = page.getWorkbenchWindow().getShell();
	SelectionDialog dialog = new FileOpenerSelector(shell, openers);
	if (dialog.open() == Window.OK) {
		List<FileOpener> result = Lists.newArrayList();
		for (Object item : dialog.getResult())
			if (item instanceof FileOpener)
				result.add((FileOpener) item);
		return result;
	}
	return Collections.emptyList();
}
 
Example 9
Source File: GotoPackageAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run() {
	Shell shell= JavaPlugin.getActiveWorkbenchShell();
	SelectionDialog dialog= createAllPackagesDialog(shell);
	dialog.setTitle(getDialogTitle());
	dialog.setMessage(PackagesMessages.GotoPackage_dialog_message);
	dialog.open();
	Object[] res= dialog.getResult();
	if (res != null && res.length == 1)
		gotoPackage((IPackageFragment)res[0]);
}
 
Example 10
Source File: JarManifestWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void handleUnSealPackagesDetailsButtonPressed() {
	SelectionDialog dialog= createPackageDialog(getPackagesForSelectedResources());
	dialog.setTitle(JarPackagerMessages.JarManifestWizardPage_unsealedPackagesSelectionDialog_title);
	dialog.setMessage(JarPackagerMessages.JarManifestWizardPage_unsealedPackagesSelectionDialog_message);
	dialog.setInitialSelections(fJarPackage.getPackagesToUnseal());
	if (dialog.open() == Window.OK)
		fJarPackage.setPackagesToUnseal(getPackagesFromDialog(dialog));
	updateSealingInfo();
}
 
Example 11
Source File: JarManifestWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void handleSealPackagesDetailsButtonPressed() {
	SelectionDialog dialog= createPackageDialog(getPackagesForSelectedResources());
	dialog.setTitle(JarPackagerMessages.JarManifestWizardPage_sealedPackagesSelectionDialog_title);
	dialog.setMessage(JarPackagerMessages.JarManifestWizardPage_sealedPackagesSelectionDialog_message);
	dialog.setInitialSelections(fJarPackage.getPackagesToSeal());
	if (dialog.open() == Window.OK)
		fJarPackage.setPackagesToSeal(getPackagesFromDialog(dialog));
	updateSealingInfo();
}
 
Example 12
Source File: DialogUtils.java    From typescript.java with MIT License 5 votes vote down vote up
public static IResource openFolderDialog(String initialFolder, IProject project, boolean showAllProjects,
		Shell shell) {
	SelectionDialog dialog = createFolderDialog(initialFolder, project, showAllProjects, true, shell);
	if (dialog.open() != Window.OK) {
		return null;
	}
	Object[] results = dialog.getResult();
	if (results != null && results.length > 0) {
		return (IResource) results[0];
	}
	return null;
}
 
Example 13
Source File: DialogUtils.java    From typescript.java with MIT License 5 votes vote down vote up
public static IProject openProjectDialog(String initialProject, Shell shell) {
	SelectionDialog dialog = createFolderDialog(initialProject, null, true, false, shell);
	if (dialog.open() != Window.OK) {
		return null;
	}
	Object[] results = dialog.getResult();
	if (results != null && results.length > 0) {
		return (IProject) results[0];
	}
	return null;
}
 
Example 14
Source File: AssignWorkingSetsAction.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run() {
	// fail if the action hasn't been initialized
	if (site == null) {
		return;
	}

	final Object[] selectionElements = getStructuredSelection().toArray();

	// get Iterable of selected project names
	Iterable<String> selectionProjectNames = Arrays.asList(selectionElements)
			.stream().filter(item -> item instanceof IProject)
			.map(item -> ((IProject) item).getName())
			.collect(Collectors.toList());

	// double-check that the active Working Sets Manager is {@link ManualAssociationAwareWorkingSetManager}
	if (!(broker.getActiveManager() instanceof ManualAssociationAwareWorkingSetManager)) {
		return;
	}

	// open the dialog
	SelectionDialog dialog = createDialog(Arrays.asList(((ManualAssociationAwareWorkingSetManager) broker
			.getActiveManager()).getWorkingSets()), selectionElements.length);

	dialog.open();

	// Abort if user didn't press OK
	if (dialog.getReturnCode() != Window.OK) {
		return;
	}

	// perform specified working set updates
	performWorkingSetUpdate(dialog.getResult(), selectionProjectNames);
}
 
Example 15
Source File: AbstractInterpreterEditor.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public void restoreInterpreterInfos(boolean editorChanged,
        Shell shell, IInterpreterManager iInterpreterManager) {
    final Set<String> interpreterNamesToRestore = this.getInterpreterExeOrJarToRestoreAndClear();
    final IInterpreterInfo[] exesList = this.getExesList();

    if (!editorChanged && interpreterNamesToRestore.size() == 0) {
        IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        SelectionDialog listDialog = AbstractInterpreterPreferencesPage.createChooseIntepreterInfoDialog(
                workbenchWindow, exesList,
                "Select interpreters to be restored", true);

        int open = listDialog.open();
        if (open != ListDialog.OK) {
            return;
        }
        Object[] result = 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(shell);
    monitorDialog.setBlockOnOpen(false);

    try {
        IRunnableWithProgress operation = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Restoring PYTHONPATH", IProgressMonitor.UNKNOWN);
                try {
                    pushExpectedSetInfos();
                    //clear all but the ones that appear
                    iInterpreterManager.setInfos(exesList, interpreterNamesToRestore, monitor);
                } finally {
                    popExpectedSetInfos();
                    monitor.done();
                }
            }
        };

        monitorDialog.run(true, true, operation);

    } catch (Exception e) {
        Log.log(e);
    }
}
 
Example 16
Source File: PySelectInterpreter.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void run(IAction action) {
    try {
        PyEdit editor = getPyEdit();
        IPythonNature nature = editor.getPythonNature();
        if (nature != null) {
            IInterpreterManager interpreterManager = nature.getRelatedInterpreterManager();

            final IInterpreterInfo[] interpreterInfos = interpreterManager.getInterpreterInfos();
            if (interpreterInfos == null || interpreterInfos.length == 0) {
                PyDialogHelpers.openWarning("No interpreters available",
                        "Unable to change default interpreter because no interpreters are available (add more interpreters in the related preferences page).");
                return;
            }
            if (interpreterInfos.length == 1) {
                PyDialogHelpers.openWarning("Only 1 interpreters available",
                        "Unable to change default interpreter because only 1 interpreter is configured (add more interpreters in the related preferences page).");
                return;
            }
            // Ok, more than 1 found.
            IWorkbenchWindow workbenchWindow = EditorUtils.getActiveWorkbenchWindow();
            Assert.isNotNull(workbenchWindow);
            SelectionDialog listDialog = AbstractInterpreterPreferencesPage.createChooseIntepreterInfoDialog(
                    workbenchWindow, interpreterInfos,
                    "Select interpreter to be made the default.", false);

            int open = listDialog.open();
            if (open != ListDialog.OK || listDialog.getResult().length != 1) {
                return;
            }
            Object[] result = listDialog.getResult();
            if (result == null || result.length == 0) {
                return;

            }
            final IInterpreterInfo selectedInterpreter = ((IInterpreterInfo) result[0]);
            if (selectedInterpreter != interpreterInfos[0]) {
                // Ok, some interpreter (which wasn't already the default) was selected.
                Arrays.sort(interpreterInfos, (a, b) -> {
                    if (a == selectedInterpreter) {
                        return -1;
                    }
                    if (b == selectedInterpreter) {
                        return 1;
                    }
                    return 0; // Don't change order for the others.
                });

                Shell shell = EditorUtils.getShell();

                setInterpreterInfosWithProgressDialog(interpreterManager, interpreterInfos, shell);
            }
        }
    } catch (Exception e) {
        Log.log(e);
    }
}
 
Example 17
Source File: PrimitiveSection.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public void handleEvent(Event event) {
  valueChanged = false;
  OperationalProperties ops = getOperationalProperties();
  if (event.widget == findButton) {
    String className = null;
    try {
      String implKind = editor.getAeDescription().getFrameworkImplementation();
      if (Constants.CPP_FRAMEWORK_NAME.equals(implKind)) {
        FileDialog dialog = new FileDialog(getSection().getShell(), SWT.NONE);
        String[] extensions = { "*.dll" };
        dialog.setFilterExtensions(extensions);
        String sStartDir = Platform.getLocation().toString();
        dialog.setFilterPath(sStartDir);
        className = dialog.open();

      } else {
        SelectionDialog typeDialog = JavaUI.createTypeDialog(getSection().getShell(), editor
                .getEditorSite().getWorkbenchWindow(), editor.getSearchScopeForDescriptorType(),
                IJavaElementSearchConstants.CONSIDER_CLASSES, false, "*");
        typeDialog.setTitle(MessageFormat.format("Choose the {0} implementation class",
                new Object[] { editor.descriptorTypeString() }));
        typeDialog.setMessage("Filter/mask:");
        if (typeDialog.open() == Window.CANCEL)
          return;
        Object[] result = typeDialog.getResult();
        if (result != null && result.length > 0)
          className = ((IType) result[0]).getFullyQualifiedName();
      }
      if (className == null || className.equals("")) //$NON-NLS-1$
        return;
      implName.setText(className);
      editor.getAeDescription().setAnnotatorImplementationName(className);
      valueChanged = true;
    } catch (JavaModelException e) {
      throw new InternalErrorCDE("unexpected Exception", e);
    }
  } else if (event.widget == modifiesCas) {
    ops.setModifiesCas(setValueChangedBoolean(modifiesCas.getSelection(), ops.getModifiesCas()));
  } else if (event.widget == multipleDeploymentAllowed) {
    ops.setMultipleDeploymentAllowed(setValueChangedBoolean(multipleDeploymentAllowed
            .getSelection(), ops.isMultipleDeploymentAllowed()));
  } else if (event.widget == outputsNewCASes) {
    ops.setOutputsNewCASes(setValueChangedBoolean(outputsNewCASes.getSelection(), ops
            .getOutputsNewCASes()));
  } else if (event.widget == implName) {
    editor.getAeDescription().setAnnotatorImplementationName(
            setValueChanged(implName.getText(), editor.getAeDescription()
                    .getAnnotatorImplementationName()));
  }
  if (valueChanged)
    editor.setFileDirty();
}