Search in sources :

Example 1 with IProjectNatureDescriptor

use of org.eclipse.core.resources.IProjectNatureDescriptor in project translationstudio8 by heartsome.

the class NewFolderDialogOfHs method isValidContainer.

/**
		 * Returns whether the container specified in the constructor is
		 * a valid parent for creating linked resources.
		 * 
		 * @return boolean <code>true</code> if the container specified in 
		 * 	the constructor is a valid parent for creating linked resources.
		 * 	<code>false</code> if no linked resources may be created with the
		 * 	specified container as a parent. 
		 */
private boolean isValidContainer() {
    if (container.getType() != IResource.PROJECT && container.getType() != IResource.FOLDER) {
        return false;
    }
    try {
        IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
        IProject project = container.getProject();
        String[] natureIds = project.getDescription().getNatureIds();
        for (int i = 0; i < natureIds.length; i++) {
            IProjectNatureDescriptor descriptor = workspace.getNatureDescriptor(natureIds[i]);
            if (descriptor != null && descriptor.isLinkingAllowed() == false) {
                return false;
            }
        }
    } catch (CoreException exception) {
        // project does not exist or is closed
        return false;
    }
    return true;
}
Also used : IProjectNatureDescriptor(org.eclipse.core.resources.IProjectNatureDescriptor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject) Point(org.eclipse.swt.graphics.Point)

Example 2 with IProjectNatureDescriptor

use of org.eclipse.core.resources.IProjectNatureDescriptor in project eclipse.platform.text by eclipse.

the class NatureLabelHoverProvider method getHoverInfo.

@Override
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
    String contents = textViewer.getDocument().get();
    int offset = hoverRegion.getOffset();
    int endIndex = contents.indexOf("</nature>", offset);
    if (endIndex == -1)
        return "";
    int startIndex = contents.substring(0, offset).lastIndexOf("<nature>");
    if (startIndex == -1)
        return "";
    String selection = contents.substring(startIndex + "<nature>".length(), endIndex);
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProjectNatureDescriptor[] natureDescriptors = workspace.getNatureDescriptors();
    for (int i = 0; i < natureDescriptors.length; i++) {
        if (natureDescriptors[i].getNatureId().equals(selection))
            return natureDescriptors[i].getLabel();
    }
    return null;
}
Also used : IProjectNatureDescriptor(org.eclipse.core.resources.IProjectNatureDescriptor) IWorkspace(org.eclipse.core.resources.IWorkspace)

Example 3 with IProjectNatureDescriptor

use of org.eclipse.core.resources.IProjectNatureDescriptor in project eclipse.platform.text by eclipse.

the class NaturesAndProjectsContentAssistProcessor method computeCompletionProposals.

@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    String text = viewer.getDocument().get();
    String natureTag = "<nature>";
    String projectReferenceTag = "<project>";
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    int natureTagLength = natureTag.length();
    if (text.length() >= natureTagLength && offset >= natureTagLength && text.substring(offset - natureTagLength, offset).equals(natureTag)) {
        IProjectNatureDescriptor[] natureDescriptors = workspace.getNatureDescriptors();
        ICompletionProposal[] proposals = new ICompletionProposal[natureDescriptors.length];
        for (int i = 0; i < natureDescriptors.length; i++) {
            IProjectNatureDescriptor descriptor = natureDescriptors[i];
            proposals[i] = new CompletionProposal(descriptor.getNatureId(), offset, 0, descriptor.getNatureId().length());
        }
        return proposals;
    }
    int projectReferenceTagLength = projectReferenceTag.length();
    if (text.length() >= projectReferenceTagLength && offset >= projectReferenceTagLength && text.substring(offset - projectReferenceTagLength, offset).equals(projectReferenceTag)) {
        IProject[] projects = workspace.getRoot().getProjects();
        // TODO - filter out the project this file is in
        ICompletionProposal[] proposals = new ICompletionProposal[projects.length];
        for (int i = 0; i < projects.length; i++) {
            proposals[i] = new CompletionProposal(projects[i].getName(), offset, 0, projects[i].getName().length());
        }
        return proposals;
    }
    return new ICompletionProposal[0];
}
Also used : IProjectNatureDescriptor(org.eclipse.core.resources.IProjectNatureDescriptor) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) IWorkspace(org.eclipse.core.resources.IWorkspace) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IProject(org.eclipse.core.resources.IProject)

Aggregations

IProjectNatureDescriptor (org.eclipse.core.resources.IProjectNatureDescriptor)3 IWorkspace (org.eclipse.core.resources.IWorkspace)3 IProject (org.eclipse.core.resources.IProject)2 CoreException (org.eclipse.core.runtime.CoreException)1 CompletionProposal (org.eclipse.jface.text.contentassist.CompletionProposal)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 Point (org.eclipse.swt.graphics.Point)1