Java Code Examples for org.eclipse.jdt.ui.JavaElementLabelProvider#SHOW_DEFAULT

The following examples show how to use org.eclipse.jdt.ui.JavaElementLabelProvider#SHOW_DEFAULT . 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: 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 2
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 3
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 4
Source File: JavaProjectSelectionDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private JavaProjectSelectionDialog(Shell parent, List<IJavaProject> projects,
    IJavaProject initialSelection) {
  super(parent, new JavaElementLabelProvider(
      JavaElementLabelProvider.SHOW_DEFAULT));
  setTitle("Project Selection");
  setMessage("Choose a project:");
  setElements(projects.toArray(new IJavaProject[0]));
  setInitialSelections(new Object[] {initialSelection});
  setHelpAvailable(false);
}
 
Example 5
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 6
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 7
Source File: NewHostPageWizardPage.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private IJavaProject chooseProject() {
  IJavaProject[] projects;
  try {
    projects = JavaCore.create(Util.getWorkspaceRoot()).getJavaProjects();
  } catch (JavaModelException e) {
    JavaPlugin.log(e);
    projects = new IJavaProject[0];
  }

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

  // TODO: refactor this into utility function
  ILabelProvider labelProvider = new JavaElementLabelProvider(
      JavaElementLabelProvider.SHOW_DEFAULT);
  ElementListSelectionDialog dialog = new ElementListSelectionDialog(
      getShell(), labelProvider);
  dialog.setTitle("Project Selection");
  dialog.setMessage("Choose a project for the new HTML page");
  dialog.setElements(gwtProjects.toArray(new IJavaProject[0]));
  dialog.setInitialSelections(new Object[] {getJavaProject()});
  dialog.setHelpAvailable(false);
  if (dialog.open() == Window.OK) {
    return (IJavaProject) dialog.getFirstResult();
  }
  return null;
}
 
Example 8
Source File: ClientBundleResourceSelectionDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private ClientBundleResourceSelectionDialog(Shell shell,
    IJavaProject javaProject, boolean multiSelection) {
  super(shell, new JavaElementLabelProvider(
      JavaElementLabelProvider.SHOW_DEFAULT),
      new StandardJavaElementContentProvider());
  setValidator(new TypedElementSelectionValidator(new Class[] {IFile.class},
      multiSelection));
  setComparator(new JavaElementComparator());
  setTitle("Resource Selection");
  String message = MessageFormat.format("Choose {0} to bundle:",
      (multiSelection ? "one or more resources" : "a resource"));
  setMessage(message);
  addFilter(new ViewerFilter(javaProject));
}
 
Example 9
Source File: SourceContainerDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private SourceContainerDialog(Shell shell) {
	super(shell,new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT),new StandardJavaElementContentProvider());
	setValidator(new PackageAndProjectSelectionValidator());
	setComparator(new JavaElementComparator());
	setTitle(NewWizardMessages.NewContainerWizardPage_ChooseSourceContainerDialog_title);
	setMessage(NewWizardMessages.NewContainerWizardPage_ChooseSourceContainerDialog_description);
	addFilter(new JavaTypedViewerFilter());
}
 
Example 10
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 11
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 12
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 13
Source File: JavadocTreeWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void createInputGroup(Composite composite) {

		createLabel(composite, SWT.NONE, JavadocExportMessages.JavadocTreeWizardPage_checkboxtreeandlistgroup_label, createGridData(6));
		Composite c= new Composite(composite, SWT.NONE);
		GridLayout layout= new GridLayout();
		layout.numColumns= 1;
		layout.makeColumnsEqualWidth= true;
		layout.marginWidth= 0;
		layout.marginHeight= 0;
		c.setLayout(layout);
		c.setLayoutData(createGridData(GridData.FILL_BOTH, 6, 0));

		ITreeContentProvider treeContentProvider= new JavadocProjectContentProvider();
		ITreeContentProvider listContentProvider= new JavadocMemberContentProvider();
		fInputGroup= new CheckboxTreeAndListGroup(c, this, treeContentProvider, new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT), listContentProvider, new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT), SWT.NONE, convertWidthInCharsToPixels(60), convertHeightInCharsToPixels(7));

		fInputGroup.addCheckStateListener(new ICheckStateListener() {
			public void checkStateChanged(CheckStateChangedEvent e) {
				doValidation(TREESTATUS);
			}
		});
		fInputGroup.setTreeComparator(new JavaElementComparator());

		SWTUtil.setAccessibilityText(fInputGroup.getTree(), JavadocExportMessages.JavadocTreeWizardPage_tree_accessibility_message);
		SWTUtil.setAccessibilityText(fInputGroup.getTable(), JavadocExportMessages.JavadocTreeWizardPage_table_accessibility_message);

		IJavaElement[] elements= fStore.getInitialElements();
		setTreeChecked(elements);
		if (elements.length > 0) {
			fInputGroup.setTreeSelection(new StructuredSelection(elements[0].getJavaProject()));
		}

		fInputGroup.aboutToOpen();
	}
 
Example 14
Source File: PackageSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ILabelProvider createLabelProvider(int dialogFlags) {
	int flags= JavaElementLabelProvider.SHOW_DEFAULT;
	if ((dialogFlags & F_REMOVE_DUPLICATES) == 0) {
		flags= flags | JavaElementLabelProvider.SHOW_ROOT;
	}
	return new JavaElementLabelProvider(flags);
}
 
Example 15
Source File: RenameTypeWizardSimilarElementsPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public SimilarLabelProvider() {
	super(JavaElementLabelProvider.SHOW_DEFAULT | JavaElementLabelProvider.SHOW_SMALL_ICONS);
}
 
Example 16
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;
}