org.eclipse.ui.dialogs.ISelectionStatusValidator Java Examples

The following examples show how to use org.eclipse.ui.dialogs.ISelectionStatusValidator. 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: MoveMembersWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void openTypeSelectionDialog(){
	int elementKinds= IJavaSearchConstants.TYPE;
	final IJavaSearchScope scope= createWorkspaceSourceScope();
	FilteredTypesSelectionDialog dialog= new FilteredTypesSelectionDialog(getShell(), false,
		getWizard().getContainer(), scope, elementKinds);
	dialog.setTitle(RefactoringMessages.MoveMembersInputPage_choose_Type);
	dialog.setMessage(RefactoringMessages.MoveMembersInputPage_dialogMessage);
	dialog.setValidator(new ISelectionStatusValidator(){
		public IStatus validate(Object[] selection) {
			Assert.isTrue(selection.length <= 1);
			if (selection.length == 0)
				return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, RefactoringMessages.MoveMembersInputPage_Invalid_selection, null);
			Object element= selection[0];
			if (! (element instanceof IType))
				return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, RefactoringMessages.MoveMembersInputPage_Invalid_selection, null);
			IType type= (IType)element;
			return validateDestinationType(type, type.getElementName());
		}
	});
	dialog.setInitialPattern(createInitialFilter());
	if (dialog.open() == Window.CANCEL)
		return;
	IType firstResult= (IType)dialog.getFirstResult();
	fDestinationField.setText(firstResult.getFullyQualifiedName('.'));
}
 
Example #2
Source File: WorkspaceResourceSelectionDialog.java    From typescript.java with MIT License 5 votes vote down vote up
public WorkspaceResourceSelectionDialog(Shell parent, Mode mode) {
	super(parent, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
	this.mode = mode;
	setValidator(new ISelectionStatusValidator() {
		public IStatus validate(Object[] selection) {
			if (selection.length > 0 && checkMode(selection[0])) {
				return new Status(IStatus.OK, TypeScriptUIPlugin.PLUGIN_ID, IStatus.OK, EMPTY_STRING, null);
			}
			return new Status(IStatus.ERROR, TypeScriptUIPlugin.PLUGIN_ID, IStatus.ERROR, EMPTY_STRING, null);
		}
	});
	setInput(ResourcesPlugin.getWorkspace().getRoot());
}
 
Example #3
Source File: ChangeExceptionsControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IType chooseException() {
	IJavaElement[] elements= new IJavaElement[] { fProject.getJavaProject() };
	final IJavaSearchScope scope= SearchEngine.createJavaSearchScope(elements);

	FilteredTypesSelectionDialog dialog= new FilteredTypesSelectionDialog(getShell(), false,
			PlatformUI.getWorkbench().getProgressService(), scope, IJavaSearchConstants.CLASS);
	dialog.setTitle(RefactoringMessages.ChangeExceptionsControl_choose_title);
	dialog.setMessage(RefactoringMessages.ChangeExceptionsControl_choose_message);
	dialog.setInitialPattern("*Exception*"); //$NON-NLS-1$
	dialog.setValidator(new ISelectionStatusValidator() {
		public IStatus validate(Object[] selection) {
			if (selection.length == 0)
				return new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$
			try {
				return checkException((IType)selection[0]);
			} catch (JavaModelException e) {
				JavaPlugin.log(e);
				return StatusInfo.OK_STATUS;
			}
		}
	});

	if (dialog.open() == Window.OK) {
		return (IType) dialog.getFirstResult();
	}
	return null;
}
 
Example #4
Source File: AddSourceFolderWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IFolder chooseFolder(String title, String message, IPath initialPath) {
	Class<?>[] acceptedClasses= new Class[] { IFolder.class };
	ISelectionStatusValidator validator= new TypedElementSelectionValidator(acceptedClasses, false);
	ViewerFilter filter= new TypedViewerFilter(acceptedClasses, null);

	ILabelProvider lp= new WorkbenchLabelProvider();
	ITreeContentProvider cp= new WorkbenchContentProvider();

	IProject currProject= fNewElement.getJavaProject().getProject();

	ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(getShell(), lp, cp) {
		@Override
		protected Control createDialogArea(Composite parent) {
			Control result= super.createDialogArea(parent);
			PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IJavaHelpContextIds.BP_CHOOSE_EXISTING_FOLDER_TO_MAKE_SOURCE_FOLDER);
			return result;
		}
	};
	dialog.setValidator(validator);
	dialog.setTitle(title);
	dialog.setMessage(message);
	dialog.addFilter(filter);
	dialog.setInput(currProject);
	dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
	IResource res= currProject.findMember(initialPath);
	if (res != null) {
		dialog.setInitialSelection(res);
	}

	if (dialog.open() == Window.OK) {
		return (IFolder) dialog.getFirstResult();
	}
	return null;
}
 
Example #5
Source File: BuildPathsBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IContainer chooseContainer() {
	Class<?>[] acceptedClasses= new Class[] { IProject.class, IFolder.class };
	ISelectionStatusValidator validator= new TypedElementSelectionValidator(acceptedClasses, false);
	IProject[] allProjects= fWorkspaceRoot.getProjects();
	ArrayList<IProject> rejectedElements= new ArrayList<IProject>(allProjects.length);
	IProject currProject= fCurrJProject.getProject();
	for (int i= 0; i < allProjects.length; i++) {
		if (!allProjects[i].equals(currProject)) {
			rejectedElements.add(allProjects[i]);
		}
	}
	ViewerFilter filter= new TypedViewerFilter(acceptedClasses, rejectedElements.toArray());

	ILabelProvider lp= new WorkbenchLabelProvider();
	ITreeContentProvider cp= new WorkbenchContentProvider();

	IResource initSelection= null;
	if (fOutputLocationPath != null) {
		initSelection= fWorkspaceRoot.findMember(fOutputLocationPath);
	}

	FolderSelectionDialog dialog= new FolderSelectionDialog(getShell(), lp, cp);
	dialog.setTitle(NewWizardMessages.BuildPathsBlock_ChooseOutputFolderDialog_title);
	dialog.setValidator(validator);
	dialog.setMessage(NewWizardMessages.BuildPathsBlock_ChooseOutputFolderDialog_description);
	dialog.addFilter(filter);
	dialog.setInput(fWorkspaceRoot);
	dialog.setInitialSelection(initSelection);
	dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));

	if (dialog.open() == Window.OK) {
		return (IContainer)dialog.getFirstResult();
	}
	return null;
}
 
Example #6
Source File: JarManifestWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates and returns a dialog to choose an existing workspace file.
 * @param title the title
 * @param message the dialog message
 * @return the dialog
 */
protected ElementTreeSelectionDialog createWorkspaceFileSelectionDialog(String title, String message) {
	int labelFlags= JavaElementLabelProvider.SHOW_BASICS
					| JavaElementLabelProvider.SHOW_OVERLAY_ICONS
					| JavaElementLabelProvider.SHOW_SMALL_ICONS;
	final DecoratingLabelProvider provider= new DecoratingLabelProvider(new JavaElementLabelProvider(labelFlags), new ProblemsLabelDecorator(null));
	ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(getShell(), provider, new StandardJavaElementContentProvider());
	dialog.setComparator(new JavaElementComparator());
	dialog.setAllowMultiple(false);
	dialog.setValidator(new ISelectionStatusValidator() {
		public IStatus validate(Object[] selection) {
			StatusInfo res= new StatusInfo();
			// only single selection
			if (selection.length == 1 && (selection[0] instanceof IFile))
				res.setOK();
			else
				res.setError(""); //$NON-NLS-1$
			return res;
		}
	});
	dialog.addFilter(new EmptyInnerPackageFilter());
	dialog.addFilter(new LibraryFilter());
	dialog.setTitle(title);
	dialog.setMessage(message);
	dialog.setStatusLineAboveButtons(true);
	dialog.setInput(JavaCore.create(JavaPlugin.getWorkspace().getRoot()));
	return dialog;
}
 
Example #7
Source File: PackageFragmentRootSelectionDialog.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new package fragment root selection dialog.
 * 
 * @param shell The parent shell for the dialog.
 * @param title The title of the dialog.
 * @param message The message of the dialog.
 * @param errorMessage the error message to display if an invalid selection is made.
 */
public PackageFragmentRootSelectionDialog(Shell shell, String title, String message,
		String errorMessage) {
	super(shell, new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT),
		new StandardJavaElementContentProvider());
	setTitle(title);
	setMessage(message);
	setAllowMultiple(false);
	setInput(JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()));

	setValidator(new ISelectionStatusValidator() {

		@Override
		public IStatus validate(Object[] sel) {
			if (sel.length == 1 && sel[0] instanceof IPackageFragmentRoot) {
				return new Status(IStatus.OK, Activator.PLUGIN_ID, IStatus.OK, "", null);
			}
			return new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, errorMessage,
				null);
		}
	});

	addFilter(new ViewerFilter() {
		@Override
		public boolean select(Viewer viewer, Object parentObject, Object element) {

			if (element instanceof IPackageFragmentRoot) {
				IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) element;
				return !packageFragmentRoot.isArchive() && !packageFragmentRoot.isExternal();
			}

			return element instanceof IJavaModel || element instanceof IJavaProject;
		}
	});
}
 
Example #8
Source File: NewSourceFolderWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IFolder chooseFolder(String title, String message, IPath initialPath) {
	Class<?>[] acceptedClasses= new Class[] { IFolder.class };
	ISelectionStatusValidator validator= new TypedElementSelectionValidator(acceptedClasses, false);
	ViewerFilter filter= new TypedViewerFilter(acceptedClasses, null);

	ILabelProvider lp= new WorkbenchLabelProvider();
	ITreeContentProvider cp= new WorkbenchContentProvider();

	IProject currProject= fCurrJProject.getProject();

	ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(getShell(), lp, cp);
	dialog.setValidator(validator);
	dialog.setTitle(title);
	dialog.setMessage(message);
	dialog.addFilter(filter);
	dialog.setInput(currProject);
	dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
	IResource res= currProject.findMember(initialPath);
	if (res != null) {
		dialog.setInitialSelection(res);
	}

	if (dialog.open() == Window.OK) {
		return (IFolder) dialog.getFirstResult();
	}
	return null;
}
 
Example #9
Source File: GenerateToStringDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ISelectionStatusValidator getSelectionValidator() {
	return getValidator();
}
 
Example #10
Source File: SelectExistingOrCreateNewDialog.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a special validator that considers that items may be gotten from what's filtered (not only actually selected).
 */
private ISelectionStatusValidator createValidator() {
    return new ISelectionStatusValidator() {

        @Override
        public IStatus validate(Object[] selection) {
            if (selection != null && selection.length == 1) {
                return new Status(IStatus.OK, PydevPlugin.getPluginID(), getEntry(selection[0].toString()));
            }
            TreeItem[] items = getTreeViewer().getTree().getItems();
            if (selection == null || selection.length == 0) {
                //not available in selection
                if (items != null) {
                    if (items.length == 1) {
                        return new Status(IStatus.OK, PydevPlugin.getPluginID(), getEntry(items[0].getData()
                                .toString()));
                    }
                    if (items.length > 0) {
                        String textInEditor = text.getText();
                        for (TreeItem item : items) {
                            if (item.getData().toString().equals(textInEditor)) {
                                //exact match of what's written to an item, so, just use it.
                                return new Status(IStatus.OK, PydevPlugin.getPluginID(), textInEditor);
                            }
                        }
                    }
                }
            }

            if ((selection == null || selection.length == 0) && (items == null || items.length == 0)) {
                return new Status(IStatus.ERROR, PydevPlugin.getPluginID(), "No selection available.");
            }

            return new Status(IStatus.ERROR, PydevPlugin.getPluginID(), "Only 1 entry may be selected or visible.");
        }

        private String getEntry(String string) {
            if (NEW_ENTRY_TEXT.equals(string)) {
                return text.getText();
            }
            return string;
        }
    };
}
 
Example #11
Source File: NewResourceFileDialog.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void setValidator( ISelectionStatusValidator validator )
{
	fValidator = validator;
}
 
Example #12
Source File: MoveResourceDialog.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Constructs a dialog for moving resource.
 * 
 * @param files
 */
public MoveResourceDialog( final Collection<File> files )
{
	super( false, false, null );
	setTitle( Messages.getString( "MoveResourceDialog.Title" ) );
	setMessage( Messages.getString( "MoveResourceDialog.Message" ) );
	setDoubleClickSelects( true );
	setAllowMultiple( false );
	setHelpAvailable( false );
	setEmptyFolderShowStatus( IResourceContentProvider.ALWAYS_SHOW_EMPTYFOLDER );
	setValidator( new ISelectionStatusValidator( ) {

		public IStatus validate( Object[] selection )
		{
			for ( Object s : selection )
			{
				if ( s instanceof ResourceEntry )
				{
					URL url = ( (ResourceEntry) s ).getURL( );
					try {
						url = URIUtil.toURI(url).toURL();
					} catch (Exception e1) {
					}
					for ( File f : files )
					{
						try
						{
							if ( url.equals( f.getParentFile( )
									.toURI( )
									.toURL( ) )
									|| url.equals( f.toURI( ).toURL( ) ) )
								return new Status( IStatus.ERROR,
										ReportPlugin.REPORT_UI,
										"" );
						}
						catch ( MalformedURLException e )
						{
						}
					}
				}
			}
			return new Status( IStatus.OK, ReportPlugin.REPORT_UI, "" );
		}
	} );
}
 
Example #13
Source File: OutputLocationDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private IContainer chooseOutputLocation() {
	IWorkspaceRoot root= fCurrProject.getWorkspace().getRoot();
	final Class<?>[] acceptedClasses= new Class[] { IProject.class, IFolder.class };
	IProject[] allProjects= root.getProjects();
	ArrayList<IProject> rejectedElements= new ArrayList<IProject>(allProjects.length);
	for (int i= 0; i < allProjects.length; i++) {
		if (!allProjects[i].equals(fCurrProject)) {
			rejectedElements.add(allProjects[i]);
		}
	}
	ViewerFilter filter= new TypedViewerFilter(acceptedClasses, rejectedElements.toArray());

	ILabelProvider lp= new WorkbenchLabelProvider();
	ITreeContentProvider cp= new WorkbenchContentProvider();

	IResource initSelection= null;
	if (fOutputLocation != null) {
		initSelection= root.findMember(fOutputLocation);
	}

	FolderSelectionDialog dialog= new FolderSelectionDialog(getShell(), lp, cp);
	dialog.setTitle(NewWizardMessages.OutputLocationDialog_ChooseOutputFolder_title);

       dialog.setValidator(new ISelectionStatusValidator() {
           ISelectionStatusValidator validator= new TypedElementSelectionValidator(acceptedClasses, false);
           public IStatus validate(Object[] selection) {
               IStatus typedStatus= validator.validate(selection);
               if (!typedStatus.isOK())
                   return typedStatus;
               if (selection[0] instanceof IFolder) {
                   IFolder folder= (IFolder) selection[0];
                   try {
                   	IStatus result= ClasspathModifier.checkSetOutputLocationPrecondition(fEntryToEdit, folder.getFullPath(), fAllowInvalidClasspath, fCPJavaProject);
                   	if (result.getSeverity() == IStatus.ERROR)
                    	return result;
                   } catch (CoreException e) {
                    JavaPlugin.log(e);
                   }
                   return new StatusInfo();
               } else {
               	return new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$
               }
           }
       });
	dialog.setMessage(NewWizardMessages.OutputLocationDialog_ChooseOutputFolder_description);
	dialog.addFilter(filter);
	dialog.setInput(root);
	dialog.setInitialSelection(initSelection);
	dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));

	if (dialog.open() == Window.OK) {
		return (IContainer)dialog.getFirstResult();
	}
	return null;
}
 
Example #14
Source File: JarManifestWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a selection dialog that lists all packages under the given package
 * fragment root.
 * The caller is responsible for opening the dialog with <code>Window.open</code>,
 * and subsequently extracting the selected packages (of type
 * <code>IPackageFragment</code>) via <code>SelectionDialog.getResult</code>.
 *
 * @param packageFragments the package fragments
 * @return a new selection dialog
 */
protected SelectionDialog createPackageDialog(Set<IJavaElement> packageFragments) {
	List<IPackageFragment> packages= new ArrayList<IPackageFragment>(packageFragments.size());
	for (Iterator<IJavaElement> iter= packageFragments.iterator(); iter.hasNext();) {
		IPackageFragment fragment= (IPackageFragment)iter.next();
		boolean containsJavaElements= false;
		int kind;
		try {
			kind= fragment.getKind();
			containsJavaElements= fragment.getChildren().length > 0;
		} catch (JavaModelException ex) {
			ExceptionHandler.handle(ex, getContainer().getShell(), JarPackagerMessages.JarManifestWizardPage_error_jarPackageWizardError_title, Messages.format(JarPackagerMessages.JarManifestWizardPage_error_jarPackageWizardError_message, JavaElementLabels.getElementLabel(fragment, JavaElementLabels.ALL_DEFAULT)));
			continue;
		}
		if (kind != IPackageFragmentRoot.K_BINARY && containsJavaElements)
			packages.add(fragment);
	}
	StandardJavaElementContentProvider cp= new StandardJavaElementContentProvider() {
		@Override
		public boolean hasChildren(Object element) {
			// prevent the + from being shown in front of packages
			return !(element instanceof IPackageFragment) && super.hasChildren(element);
		}
	};
	final DecoratingLabelProvider provider= new DecoratingLabelProvider(new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT), new ProblemsLabelDecorator(null));
	ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(getContainer().getShell(), provider, cp);
	dialog.setDoubleClickSelects(false);
	dialog.setComparator(new JavaElementComparator());
	dialog.setInput(JavaCore.create(JavaPlugin.getWorkspace().getRoot()));
	dialog.addFilter(new EmptyInnerPackageFilter());
	dialog.addFilter(new LibraryFilter());
	dialog.addFilter(new SealPackagesFilter(packages));
	dialog.setValidator(new ISelectionStatusValidator() {
		public IStatus validate(Object[] selection) {
			StatusInfo res= new StatusInfo();
			for (int i= 0; i < selection.length; i++) {
				if (!(selection[i] instanceof IPackageFragment)) {
					res.setError(JarPackagerMessages.JarManifestWizardPage_error_mustContainPackages);
					return res;
				}
			}
			res.setOK();
			return res;
		}
	});
	return dialog;
}
 
Example #15
Source File: AddGetterSetterAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static ISelectionStatusValidator createValidator(int entries) {
	AddGetterSetterSelectionStatusValidator validator= new AddGetterSetterSelectionStatusValidator(entries);
	return validator;
}
 
Example #16
Source File: TypeSelectionDialog2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void setValidator(ISelectionStatusValidator validator) {
	fValidator= validator;
}
 
Example #17
Source File: FilteredTypesSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Sets a new validator.
 *
 * @param validator
 *            the new validator
 */
public void setValidator(ISelectionStatusValidator validator) {
	fValidator= validator;
}
 
Example #18
Source File: TypeSelectionExtension.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns the selection validator or <code>null</code> if
 * selection validation is not required. The elements passed
 * to the selection validator are of type {@link IType}.
 *
 * @return the selection validator or <code>null</code>
 */
public ISelectionStatusValidator getSelectionValidator() {
	return null;
}
 
Example #19
Source File: ElementTreeSelectionDialog.java    From translationstudio8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets an optional validator to check if the selection is valid.
 * The validator is invoked whenever the selection changes.
 * @param validator the validator to validate the selection.
 */
public void setValidator(ISelectionStatusValidator validator) {
    fValidator = validator;
}
 
Example #20
Source File: ElementTreeSelectionDialog.java    From tmxeditor8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets an optional validator to check if the selection is valid.
 * The validator is invoked whenever the selection changes.
 * @param validator the validator to validate the selection.
 */
public void setValidator(ISelectionStatusValidator validator) {
    fValidator = validator;
}
 
Example #21
Source File: TimeGraphFilterDialog.java    From tracecompass with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Sets an optional validator to check if the selection is valid. The
 * validator is invoked whenever the selection changes.
 *
 * @param validator
 *            the validator to validate the selection.
 */
public void setValidator(ISelectionStatusValidator validator) {
    fValidator = validator;
}
 
Example #22
Source File: AbstractHistoryElementListSelectionDialog.java    From Pydev with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Sets an optional validator to check if the selection is valid.
 * The validator is invoked whenever the selection changes.
 * @param validator the validator to validate the selection.
 */
public void setValidator(ISelectionStatusValidator validator) {
    fValidator = validator;
}