org.eclipse.jdt.ui.JavaUI Java Examples

The following examples show how to use org.eclipse.jdt.ui.JavaUI. 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: RecentSettingsStore.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String getDefaultDestination(IJavaProject project) {
	if (project != null) {
		URL url= JavaUI.getProjectJavadocLocation(project);
		//uses default if source is has http protocol
		if (url == null || !url.getProtocol().equals("file")) { //$NON-NLS-1$
			// Since Javadoc.exe is a local tool its output is local.
			// So if the project isn't local then the default location
			// can't be local to a project. So use #getLocation() to
			// test this is fine here.
			IPath path= project.getProject().getLocation();
			if (path != null)
				return path.append("doc").toOSString(); //$NON-NLS-1$
		} else {
			//must do this to remove leading "/"
			return JavaDocLocations.toFile(url).getPath();
		}
	}

	return ""; //$NON-NLS-1$

}
 
Example #2
Source File: JavadocLinkDialogLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Image getImage(Object element) {
	if (element instanceof JavadocLinkRef) {
		JavadocLinkRef ref= (JavadocLinkRef) element;
		ImageDescriptor desc;
		if (ref.isProjectRef()) {
			desc= PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(IDE.SharedImages.IMG_OBJ_PROJECT);
		} else {
			desc= JavaUI.getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_JAR);
		}
		if (ref.getURL() == null) {
			return JavaPlugin.getImageDescriptorRegistry().get(new JavaElementImageDescriptor(desc, JavaElementImageDescriptor.WARNING, JavaElementImageProvider.SMALL_SIZE));
		}
		return JavaPlugin.getImageDescriptorRegistry().get(desc);
	}
	return null;
}
 
Example #3
Source File: BugInfoView.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
private boolean matchInput(IEditorInput input) {
    if (file != null && (input instanceof IFileEditorInput)) {
        return file.equals(((IFileEditorInput) input).getFile());
    }
    if (javaElt != null && input != null) {
        IJavaElement javaElement = JavaUI.getEditorInputJavaElement(input);
        if (javaElt.equals(javaElement)) {
            return true;
        }
        IJavaElement parent = javaElt.getParent();
        while (parent != null && !parent.equals(javaElement)) {
            parent = parent.getParent();
        }
        if (parent != null && parent.equals(javaElement)) {
            return true;
        }
    }
    return false;
}
 
Example #4
Source File: OpenEditorTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testOpenEditors() throws Exception {
	IType bar = javaProject.findType("outlinetest.Bar");
	IEditorPart barEditor = globalURIEditorOpener.open(null, bar, true);
	assertEquals(JavaUI.ID_CU_EDITOR, barEditor.getEditorSite().getId());

	IType foo = javaProject.findType("outlinetest.Foo");
	IEditorPart fooJavaEditor = globalURIEditorOpener.open(null, foo, true);
	String expectedEditor = JavaUI.ID_CU_EDITOR;
	try {
		// if we are running in post 3.8 we have an Xtend editor
		if (Class.forName("org.eclipse.ui.ide.IEditorAssociationOverride") != null)
			expectedEditor = "org.eclipse.xtend.core.Xtend";
	} catch (ClassNotFoundException e) {
		// ignore
	}
	assertEquals(expectedEditor, fooJavaEditor.getEditorSite().getId());

	IResource resource = foo.getResource();
	assertTrue(resource instanceof IFile);
	IMarker[] markers = derivedResourceMarkers.findDerivedResourceMarkers(resource);
	assertEquals(1, markers.length);
	String source = derivedResourceMarkers.getSource(markers[0]);
	assertNotNull(source);
	IEditorPart fooXtendEditor = globalURIEditorOpener.open(URI.createURI(source), foo, true);
	assertEquals("org.eclipse.xtend.core.Xtend", fooXtendEditor.getEditorSite().getId());
}
 
Example #5
Source File: OpenEditorTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testOpenFromOutline() throws Exception {
	XtextEditor bazXtendEditor = workbenchTestHelper.openEditor("outlinetest/Baz.xtend",
			"package outlinetest class Baz extends Foo { int baz }");
	IOutlineTreeProvider.ModeAware tp = (IOutlineTreeProvider.ModeAware) treeProvider;
	tp.setCurrentMode(tp.getOutlineModes().get(1));
	IOutlineNode outlineRoot = treeProvider.createRoot(bazXtendEditor.getDocument());
	IOutlineNode bazNode = outlineRoot.getChildren().get(1);
	assertEquals("Baz - outlinetest", bazNode.getText().toString());
	assertTrue(bazNode.getChildren().size() > 2);
	IOutlineNode baz = bazNode.getChildren().get(0);
	assertEquals("baz : int - Baz", baz.getText().toString());
	outlineNodeElementOpener.open(baz, bazXtendEditor.getInternalSourceViewer());
	assertActiveEditor("org.eclipse.xtend.core.Xtend", "Baz.xtend", "baz");
	IOutlineNode foo = bazNode.getChildren().get(1);
	assertEquals("foo : int - Foo", foo.getText().toString());
	outlineNodeElementOpener.open(foo, bazXtendEditor.getInternalSourceViewer());
	assertActiveEditor("org.eclipse.xtend.core.Xtend", "Foo.xtend", "foo");
	IOutlineNode bar = bazNode.getChildren().get(2);
	assertEquals("bar : int - Bar", bar.getText().toString());
	outlineNodeElementOpener.open(bar, bazXtendEditor.getInternalSourceViewer());
	assertActiveEditor(JavaUI.ID_CU_EDITOR, "Bar.java", "bar");
}
 
Example #6
Source File: CorrectionCommandHandler.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Try to execute the correction command.
 * 
 * @return <code>true</code> iff the correction could be started
 * @since 3.6
 */
public boolean doExecute() {
	ISelection selection= fEditor.getSelectionProvider().getSelection();
	ICompilationUnit cu= JavaUI.getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput());
	IAnnotationModel model= JavaUI.getDocumentProvider().getAnnotationModel(fEditor.getEditorInput());
	if (selection instanceof ITextSelection && cu != null && model != null) {
		if (! ActionUtil.isEditable(fEditor)) {
			return false;
		}
		ICompletionProposal proposal= findCorrection(fId, fIsAssist, (ITextSelection) selection, cu, model);
		if (proposal != null) {
			invokeProposal(proposal, ((ITextSelection) selection).getOffset());
			return true;
		}
	}
	return false;
}
 
Example #7
Source File: TypeResourceUnloaderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
	eventBroker = TestsActivator.getInstance().getInjector(DUMMY_LANG_NAME).getInstance(IStateChangeEventBroker.class);
	projectProvider = new MockJavaProjectProvider();
	projectProvider.setUseSource(true);
	project = projectProvider.getJavaProject(null);
	type = project.findType(NESTED_TYPES);
	compilationUnit = type.getCompilationUnit();
	compilationUnit.becomeWorkingCopy(null);
	
	// wait until the BackgroundThread for the reconciler was started
	editor = waitForElementChangedEvent(new Callable<IEditorPart>() {
		@Override
		public IEditorPart call() throws Exception {
			return JavaUI.openInEditor(compilationUnit);
		}
	}, true);
	
	eventBroker.addListener(this);
	document = getDocument();
	originalContent = document.get();
	subsequentEvents = Lists.newArrayList();
}
 
Example #8
Source File: JavaContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Evaluates a 'java' template in the context of a compilation unit
 *
 * @param template the template to be evaluated
 * @param compilationUnit the compilation unit in which to evaluate the template
 * @param position the position inside the compilation unit for which to evaluate the template
 * @return the evaluated template
 * @throws CoreException in case the template is of an unknown context type
 * @throws BadLocationException in case the position is invalid in the compilation unit
 * @throws TemplateException in case the evaluation fails
 */
public static String evaluateTemplate(Template template, ICompilationUnit compilationUnit, int position) throws CoreException, BadLocationException, TemplateException {

	TemplateContextType contextType= JavaPlugin.getDefault().getTemplateContextRegistry().getContextType(template.getContextTypeId());
	if (!(contextType instanceof CompilationUnitContextType))
		throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, JavaTemplateMessages.JavaContext_error_message, null));

	IDocument document= new Document();
	if (compilationUnit != null && compilationUnit.exists())
		document.set(compilationUnit.getSource());

	CompilationUnitContext context= ((CompilationUnitContextType) contextType).createContext(document, position, 0, compilationUnit);
	context.setForceEvaluation(true);

	TemplateBuffer buffer= context.evaluate(template);
	if (buffer == null)
		return null;
	return buffer.getString();
}
 
Example #9
Source File: BuildSettingWizardPage.java    From sarl with Apache License 2.0 6 votes vote down vote up
private static File createBackup(IFileStore source, String name) throws CoreException {
	try {
		final File bak = File.createTempFile("eclipse-" + name, ".bak"); //$NON-NLS-1$//$NON-NLS-2$
		copyFile(source, bak);
		return bak;
	} catch (IOException e) {
		final IStatus status = new Status(
				IStatus.ERROR,
				JavaUI.ID_PLUGIN,
				IStatus.ERROR,
				MessageFormat.format(
				NewWizardMessages.NewJavaProjectWizardPageTwo_problem_backup,
				name),
				e);
		throw new CoreException(status);
	}
}
 
Example #10
Source File: FormatterProfileManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected String getSelectedProfileId(IScopeContext instanceScope) {
	String profileId= instanceScope.getNode(JavaUI.ID_PLUGIN).get(PROFILE_KEY, null);
	if (profileId == null) {
		// request from bug 129427
		profileId= DefaultScope.INSTANCE.getNode(JavaUI.ID_PLUGIN).get(PROFILE_KEY, null);
		// fix for bug 89739
		if (DEFAULT_PROFILE.equals(profileId)) { // default default:
			IEclipsePreferences node= instanceScope.getNode(JavaCore.PLUGIN_ID);
			if (node != null) {
				String tabSetting= node.get(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, null);
				if (JavaCore.SPACE.equals(tabSetting)) {
					profileId= JAVA_PROFILE;
				}
			}
		}
	}
    return profileId;
   }
 
Example #11
Source File: FixedFatJarExportPage.java    From sarl with Apache License 2.0 6 votes vote down vote up
public Object[] getSelectedElementsWithoutContainedChildren(ILaunchConfiguration launchconfig, JarPackageData data, IRunnableContext context, MultiStatus status) throws CoreException {
	if (launchconfig == null)
		return new Object[0];

	String projectName= launchconfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$

	IPath[] classpath= getClasspath(launchconfig);
	IPackageFragmentRoot[] classpathResources= getRequiredPackageFragmentRoots(classpath, projectName, status);

	String mainClass= getMainClass(launchconfig, status);
	IType mainType= findMainMethodByName(mainClass, classpathResources, context);
	if (mainType == null) {
		status.add(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, FatJarPackagerMessages.FatJarPackageWizardPage_error_noMainMethod));
	}
	data.setManifestMainClass(mainType);

	return classpathResources;
}
 
Example #12
Source File: ModifyDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IStatus validateProfileName() {
  	final String name= fProfileNameField.getText().trim();

   if (fProfile.isBuiltInProfile()) {
	if (fProfile.getName().equals(name)) {
		return new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, FormatterMessages.ModifyDialog_BuiltIn_Status);
	}
  	}

  	if (fProfile.isSharedProfile()) {
	if (fProfile.getName().equals(name)) {
		return new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, FormatterMessages.ModifyDialog_Shared_Status);
	}
  	}

if (name.length() == 0) {
	return new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, FormatterMessages.ModifyDialog_EmptyName_Status);
}

return StatusInfo.OK_STATUS;
  }
 
Example #13
Source File: OpenTypeHierarchyUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static TypeHierarchyViewPart openInPerspective(IWorkbenchWindow window, IJavaElement[] input) throws WorkbenchException, JavaModelException {
	IWorkbench workbench= JavaPlugin.getDefault().getWorkbench();
	IJavaElement perspectiveInput= input.length == 1 ? input[0] : null;

	if (perspectiveInput != null && input[0] instanceof IMember) {
		if (input[0].getElementType() != IJavaElement.TYPE) {
			perspectiveInput= ((IMember)input[0]).getDeclaringType();
		} else {
			perspectiveInput= input[0];
		}
	}
	IWorkbenchPage page= workbench.showPerspective(JavaUI.ID_HIERARCHYPERSPECTIVE, window, perspectiveInput);

	TypeHierarchyViewPart part= (TypeHierarchyViewPart) page.findView(JavaUI.ID_TYPE_HIERARCHY);
	if (part != null) {
		part.clearNeededRefresh(); // avoid refresh of old hierarchy on 'becomes visible'
	}
	part= (TypeHierarchyViewPart) page.showView(JavaUI.ID_TYPE_HIERARCHY);
	part.setInputElements(input);
	if (perspectiveInput != null) {
		if (page.getEditorReferences().length == 0) {
			JavaUI.openInEditor(input[0], false, false); // only open when the perspective has been created
		}
	}
	return part;
}
 
Example #14
Source File: AbstractSaveParticipantPreferenceConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void initialize(final IScopeContext context, IAdaptable element) {
	boolean enabled= isEnabled(context);
	fEnableField.setSelection(enabled);

	fEnableField.setDialogFieldListener(new IDialogFieldListener() {
		public void dialogFieldChanged(DialogField field) {
			fContext.getNode(JavaUI.ID_PLUGIN).putBoolean(getPreferenceKey(), fEnableField.isSelected());
			enabled(fEnableField.isSelected());
		}

	});

	fContext= context;

	enabled(enabled);
}
 
Example #15
Source File: ContributedJavadocWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static ContributedJavadocWizardPage[] getContributedPages(JavadocOptionsManager store) {
	ArrayList<ContributedJavadocWizardPage> pages= new ArrayList<ContributedJavadocWizardPage>();

	IConfigurationElement[] elements= Platform.getExtensionRegistry().getConfigurationElementsFor(JavaUI.ID_PLUGIN, ATT_EXTENSION);
	for (int i = 0; i < elements.length; i++) {
		IConfigurationElement curr= elements[i];
		String id= curr.getAttribute(ATT_ID);
		String description= curr.getAttribute(ATT_DESCRIPTION);
		String pageClassName= curr.getAttribute(ATT_PAGE_CLASS);

		if (id == null || description == null || pageClassName == null) {
			JavaPlugin.logErrorMessage("Invalid extension " + curr.toString()); //$NON-NLS-1$
			continue;
		}
		pages.add(new ContributedJavadocWizardPage(elements[i], store));
	}
	return pages.toArray(new ContributedJavadocWizardPage[pages.size()]);
}
 
Example #16
Source File: PackageExplorerPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Object getInputFromEditor(IEditorInput editorInput) {
	Object input= JavaUI.getEditorInputJavaElement(editorInput);
	if (input instanceof ICompilationUnit) {
		ICompilationUnit cu= (ICompilationUnit) input;
		if (!cu.getJavaProject().isOnClasspath(cu)) { // test needed for Java files in non-source folders (bug 207839)
			input= cu.getResource();
		}
	}
	if (input == null) {
		input= editorInput.getAdapter(IFile.class);
	}
	if (input == null && editorInput instanceof IStorageEditorInput) {
		try {
			input= ((IStorageEditorInput) editorInput).getStorage();
		} catch (CoreException e) {
			// ignore
		}
	}
	return input;
}
 
Example #17
Source File: OpenTypeHierarchyUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static TypeHierarchyViewPart openInViewPart(IWorkbenchWindow window, IJavaElement[] input) {
	IWorkbenchPage page= window.getActivePage();
	try {
		TypeHierarchyViewPart result= (TypeHierarchyViewPart) page.findView(JavaUI.ID_TYPE_HIERARCHY);
		if (result != null) {
			result.clearNeededRefresh(); // avoid refresh of old hierarchy on 'becomes visible'
		}
		result= (TypeHierarchyViewPart) page.showView(JavaUI.ID_TYPE_HIERARCHY);
		result.setInputElements(input);
		return result;
	} catch (CoreException e) {
		ExceptionHandler.handle(e, window.getShell(),
			JavaUIMessages.OpenTypeHierarchyUtil_error_open_view, e.getMessage());
	}
	return null;
}
 
Example #18
Source File: JavadocView.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Compute the textual representation of a 'static' 'final' field's constant initializer value.
 *
 * @param activePart the part that triggered the computation, or <code>null</code>
 * @param selection the selection that references the field, or <code>null</code>
 * @param resolvedField the filed whose constant value will be computed
 * @param monitor the progress monitor
 *
 * @return the textual representation of the constant, or <code>null</code> if the
 *   field is not a constant field, the initializer value could not be computed, or
 *   the progress monitor was cancelled
 * @since 3.4
 */
private String computeFieldConstant(IWorkbenchPart activePart, ISelection selection, IField resolvedField, IProgressMonitor monitor) {

	if (!JavadocHover.isStaticFinal(resolvedField))
		return null;

	Object constantValue;
	IJavaProject preferenceProject;

	if (selection instanceof ITextSelection && activePart instanceof JavaEditor) {
		IEditorPart editor= (IEditorPart) activePart;
		ITypeRoot activeType= JavaUI.getEditorInputTypeRoot(editor.getEditorInput());
		preferenceProject= activeType.getJavaProject();
		constantValue= getConstantValueFromActiveEditor(activeType, resolvedField, (ITextSelection) selection, monitor);
		if (constantValue == null) // fall back - e.g. when selection is inside Javadoc of the element
			constantValue= computeFieldConstantFromTypeAST(resolvedField, monitor);
	} else {
		constantValue= computeFieldConstantFromTypeAST(resolvedField, monitor);
		preferenceProject= resolvedField.getJavaProject();
	}

	if (constantValue != null)
		return JavadocHover.getFormattedAssignmentOperator(preferenceProject) + formatCompilerConstantValue(constantValue);

	return null;
}
 
Example #19
Source File: FatJarPackageWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static Object[] getSelectedElementsWithoutContainedChildren(ILaunchConfiguration launchconfig, JarPackageData data, IRunnableContext context, MultiStatus status) throws CoreException {
	if (launchconfig == null)
		return new Object[0];

	String projectName= launchconfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$

	IPath[] classpath= getClasspath(launchconfig);
	IPackageFragmentRoot[] classpathResources= getRequiredPackageFragmentRoots(classpath, projectName, status);

	String mainClass= getMainClass(launchconfig, status);
	IType mainType= findMainMethodByName(mainClass, classpathResources, context);
	if (mainType == null) {
		status.add(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, FatJarPackagerMessages.FatJarPackageWizardPage_error_noMainMethod));
	}
	data.setManifestMainClass(mainType);

	return classpathResources;
}
 
Example #20
Source File: BuildPathDialogAccess.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Shows the UI for configuring a javadoc location attribute of the classpath entry. <code>null</code> is returned
 * if the user cancels the dialog. The dialog does not apply any changes.
 *
 * @param shell The parent shell for the dialog.
 * @param initialEntry The entry to edit. The kind of the classpath entry must be either
 * <code>IClasspathEntry.CPE_LIBRARY</code> or <code>IClasspathEntry.CPE_VARIABLE</code>.
 * @return Returns the resulting classpath entry containing a potentially modified javadoc location attribute
 * The resulting entry can be used to replace the original entry on the classpath.
 * Note that the dialog does not make any changes on the passed entry nor on the classpath that
 * contains it.
 *
 * @since 3.1
 */
public static IClasspathEntry configureJavadocLocation(Shell shell, IClasspathEntry initialEntry) {
	if (initialEntry == null) {
		throw new IllegalArgumentException();
	}
	int entryKind= initialEntry.getEntryKind();
	if (entryKind != IClasspathEntry.CPE_LIBRARY && entryKind != IClasspathEntry.CPE_VARIABLE) {
		throw new IllegalArgumentException();
	}

	URL location= JavaUI.getLibraryJavadocLocation(initialEntry);
	JavadocLocationDialog dialog=  new JavadocLocationDialog(shell, BasicElementLabels.getPathLabel(initialEntry.getPath(), false), location);
	if (dialog.open() == Window.OK) {
		CPListElement element= CPListElement.createFromExisting(initialEntry, null);
		URL res= dialog.getResult();
		element.setAttribute(CPListElement.JAVADOC, res != null ? res.toExternalForm() : null);
		return element.getClasspathEntry();
	}
	return null;
}
 
Example #21
Source File: JavaSourceViewerConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the hierarchy presenter which will determine and shown type hierarchy
 * information requested for the current cursor position.
 *
 * @param sourceViewer the source viewer to be configured by this configuration
 * @param doCodeResolve a boolean which specifies whether code resolve should be used to compute the Java element
 * @return an information presenter
 * @since 3.0
 */
public IInformationPresenter getHierarchyPresenter(ISourceViewer sourceViewer, boolean doCodeResolve) {

	// Do not create hierarchy presenter if there's no CU.
	if (getEditor() != null && getEditor().getEditorInput() != null && JavaUI.getEditorInputJavaElement(getEditor().getEditorInput()) == null)
		return null;

	InformationPresenter presenter= new InformationPresenter(getHierarchyPresenterControlCreator());
	presenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
	presenter.setAnchor(AbstractInformationControlManager.ANCHOR_GLOBAL);
	IInformationProvider provider= new JavaElementProvider(getEditor(), doCodeResolve);
	presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_MULTI_LINE_COMMENT);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_SINGLE_LINE_COMMENT);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_STRING);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_CHARACTER);
	presenter.setSizeConstraints(50, 20, true, false);
	return presenter;
}
 
Example #22
Source File: OpenJavaPerspectiveAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
	IWorkbench workbench= JavaPlugin.getDefault().getWorkbench();
	IWorkbenchWindow window= workbench.getActiveWorkbenchWindow();
	IWorkbenchPage page= window.getActivePage();
	IAdaptable input;
	if (page != null)
		input= page.getInput();
	else
		input= ResourcesPlugin.getWorkspace().getRoot();
	try {
		workbench.showPerspective(JavaUI.ID_PERSPECTIVE, window, input);
	} catch (WorkbenchException e) {
		ExceptionHandler.handle(e, window.getShell(),
			ActionMessages.OpenJavaPerspectiveAction_dialog_title,
			ActionMessages.OpenJavaPerspectiveAction_error_open_failed);
	}
}
 
Example #23
Source File: TypeHierarchyViewPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object getAdapter(Class key) {
	if (key == IShowInSource.class) {
		return getShowInSource();
	}
	if (key == IShowInTargetList.class) {
		return new IShowInTargetList() {
			public String[] getShowInTargetIds() {
				return new String[] { JavaUI.ID_PACKAGES, JavaPlugin.ID_RES_NAV  };
			}

		};
	}
	if (key == IContextProvider.class) {
		return JavaUIHelp.getHelpContextProvider(this, IJavaHelpContextIds.TYPE_HIERARCHY_VIEW);
	}
	return super.getAdapter(key);
}
 
Example #24
Source File: JavaSearchPageScoreComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public int computeScore(String id, Object element) {
	if (!JavaSearchPage.EXTENSION_POINT_ID.equals(id))
		// Can't decide
		return ISearchPageScoreComputer.UNKNOWN;

	if (element instanceof IJavaElement || element instanceof IClassFileEditorInput || element instanceof LogicalPackage
			|| (element instanceof IEditorInput && JavaUI.getEditorInputJavaElement((IEditorInput)element) != null))
		return 90;

	return ISearchPageScoreComputer.LOWEST;
}
 
Example #25
Source File: QuickAssistLightBulbUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ICompilationUnit getCompilationUnit() {
	IJavaElement elem= JavaUI.getEditorInputJavaElement(fEditor.getEditorInput());
	if (elem instanceof ICompilationUnit) {
		return (ICompilationUnit) elem;
	}
	return null;
}
 
Example #26
Source File: JavaBrowsingPerspectiveFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void createHorizontalLayout(IPageLayout layout) {
	String relativePartId= IPageLayout.ID_EDITOR_AREA;
	int relativePos= IPageLayout.TOP;

	if (shouldShowProjectsView()) {
		layout.addView(JavaUI.ID_PROJECTS_VIEW, IPageLayout.TOP, (float)0.25, IPageLayout.ID_EDITOR_AREA);
		relativePartId= JavaUI.ID_PROJECTS_VIEW;
		relativePos= IPageLayout.RIGHT;
	}
	if (shouldShowPackagesView()) {
		layout.addView(JavaUI.ID_PACKAGES_VIEW, relativePos, (float)0.25, relativePartId);
		relativePartId= JavaUI.ID_PACKAGES_VIEW;
		relativePos= IPageLayout.RIGHT;
	}
	layout.addView(JavaUI.ID_TYPES_VIEW, relativePos, (float)0.33, relativePartId);
	layout.addView(JavaUI.ID_MEMBERS_VIEW, IPageLayout.RIGHT, (float)0.50, JavaUI.ID_TYPES_VIEW);

	IPlaceholderFolderLayout placeHolderLeft= layout.createPlaceholderFolder("left", IPageLayout.LEFT, (float)0.25, IPageLayout.ID_EDITOR_AREA); //$NON-NLS-1$
	placeHolderLeft.addPlaceholder(JavaUI.ID_TYPE_HIERARCHY);
	placeHolderLeft.addPlaceholder(IPageLayout.ID_OUTLINE);
	placeHolderLeft.addPlaceholder(JavaUI.ID_PACKAGES);
	placeHolderLeft.addPlaceholder(JavaPlugin.ID_RES_NAV);
	placeHolderLeft.addPlaceholder(IPageLayout.ID_PROJECT_EXPLORER);


	IPlaceholderFolderLayout placeHolderBottom= layout.createPlaceholderFolder("bottom", IPageLayout.BOTTOM, (float)0.75, IPageLayout.ID_EDITOR_AREA); //$NON-NLS-1$
	placeHolderBottom.addPlaceholder(IPageLayout.ID_PROBLEM_VIEW);
	placeHolderBottom.addPlaceholder(NewSearchUI.SEARCH_VIEW_ID);
	placeHolderBottom.addPlaceholder(IConsoleConstants.ID_CONSOLE_VIEW);
	placeHolderBottom.addPlaceholder(IPageLayout.ID_BOOKMARKS);
	placeHolderBottom.addPlaceholder(JavaUI.ID_SOURCE_VIEW);
	placeHolderBottom.addPlaceholder(JavaUI.ID_JAVADOC_VIEW);
	placeHolderBottom.addPlaceholder(IProgressConstants.PROGRESS_VIEW_ID);
}
 
Example #27
Source File: JavadocHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run() {
	JavadocBrowserInformationControlInput infoInput= (JavadocBrowserInformationControlInput) fInfoControl.getInput(); //TODO: check cast
	fInfoControl.notifyDelayedInputChange(null);
	fInfoControl.dispose(); //FIXME: should have protocol to hide, rather than dispose
	try {
		JavadocView view= (JavadocView) JavaPlugin.getActivePage().showView(JavaUI.ID_JAVADOC_VIEW);
		view.setInput(infoInput);
	} catch (PartInitException e) {
		JavaPlugin.log(e);
	}
}
 
Example #28
Source File: XImportSectionContentAssistTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testStaticFavoriteImports_operation() {
  try {
    final String defaultprefs = PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, null);
    final IEclipsePreferences jdtPreference = InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN);
    try {
      String _name = StaticClassExample.class.getName();
      String _plus = (_name + ".*");
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, _plus);
      ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("package mypack");
      _builder.newLine();
      _builder.append("class Bar{");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("def void foo(){");
      _builder.newLine();
      ContentAssistProcessorTestBuilder _applyProposal = _newBuilder.append(_builder.toString()).applyProposal("staticMethod()");
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("package mypack");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("import static org.eclipse.xtend.ide.tests.data.contentassist.StaticClassExample.staticMethod");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("class Bar{");
      _builder_1.newLine();
      _builder_1.append("\t");
      _builder_1.append("def void foo(){");
      _builder_1.newLine();
      _builder_1.append("staticMethod()");
      _applyProposal.expectContent(_builder_1.toString());
    } finally {
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, defaultprefs);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #29
Source File: JavaBrowsingPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the element contained in the EditorInput
 * @param input the editor input
 * @return the input element
 */
Object getElementOfInput(IEditorInput input) {
	if (input instanceof IFileEditorInput)
		return ((IFileEditorInput)input).getFile();
	if (input != null)
		return JavaUI.getEditorInputJavaElement(input);
	return null;
}
 
Example #30
Source File: XImportSectionContentAssistTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testStaticFavoriteImports_no_constructor() {
  try {
    final String defaultprefs = PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, null);
    final IEclipsePreferences jdtPreference = InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN);
    try {
      String _name = StaticClassExample.class.getName();
      String _plus = (_name + ".*");
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, _plus);
      ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("package mypack");
      _builder.newLine();
      _builder.append("class Bar{");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("def void foo(){");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("<|>");
      _newBuilder.append(_builder.toString()).assertNoProposalAtCursor("StaticClassExample");
    } finally {
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, defaultprefs);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}