Java Code Examples for org.eclipse.core.resources.IResource.getProject()

The following are Jave code examples for showing how to use getProject() of the org.eclipse.core.resources.IResource class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: gemoc-studio-modeldebugging   File: SelectEcoreProposal.java   Source Code and License Vote up 6 votes
@Override
public String getReplacementText() {
	SelectEcoreIFileDialog dialog = new SelectEcoreIFileDialog();
	if (dialog.open() == Dialog.OK) {
		Object[] selections = dialog.getResult();
		if(selections != null 
			&& selections.length != 0
			&& selections[0] instanceof IResource 
		){
			IResource ecoreFile = (IResource) selections[0];
			ecoreProject = ecoreFile.getProject();
			String path = "/"+ecoreFile.getProject().getName() +"/"+ecoreFile.getProjectRelativePath();
			URI uri = URI.createPlatformResourceURI(path,true);
			String replacementText = "\""+uri.toString()+"\"";
			return replacementText;
		}
	}
	return "";
}
 
Example 2
Project: Equella   File: JPFManifestBuilder.java   Source Code and License Vote up 6 votes
@Override
public boolean visit(IResourceDelta delta) throws CoreException
{
	IResource resource = delta.getResource();
	if( resource.isDerived() )
	{
		return false;
	}
	if( resource.getType() == IResource.FILE )
	{
		IFile file = (IFile) resource;
		IProject project = resource.getProject();
		if( file.equals(JPFProject.getManifest(project)) )
		{
			manifestChanged = true;
			return false;
		}
	}
	return true;
}
 
Example 3
Project: gw4e.project   File: PreferenceManager.java   Source Code and License Vote up 6 votes
/**
 * Return the allowed folder where test can be generated in depending on the
 * user selection if the selected graph is in src/main/resource then
 * src/main/java if the selected graph is in src/test/resource then
 * src/test/java
 * 
 * @return
 */
public static IPath getTargetFolderForGeneratedTests(IResource selectedGraphFile) {

	IProject project = selectedGraphFile.getProject();

	IPath pathResourceTestFolder = project.getFullPath().append(getTestResourceFolder());
	if (ResourceManager.isInFolder(pathResourceTestFolder,
			selectedGraphFile.getParent().getFullPath()))
		return project.getFullPath().append(getTestSourceFolder());

	IPath pathResourceMainFolder = project.getFullPath().append(getMainResourceFolder());
	if (ResourceManager.isInFolder(pathResourceMainFolder,
			selectedGraphFile.getParent().getFullPath()))
		return project.getFullPath().append(getMainSourceFolder());
	return null;
}
 
Example 4
Project: gw4e.project   File: ResourceManager.java   Source Code and License Vote up 6 votes
/**
 * Return a path relative to its package fragment root
 * 
 * @param project
 * @param path
 * @return
 * @throws JavaModelException
 */
public static IPath getPathWithinPackageFragment(IResource ifile) throws JavaModelException {
	IProject project = ifile.getProject();
	IPath path = ifile.getFullPath();
	String[] segments = path.segments();
	IJavaProject jproject = JavaCore.create(project);
	IPackageFragment[] pkgs = jproject.getPackageFragments();
	IPath p = new Path("/");
	for (int i = 0; i < segments.length; i++) {
		for (int j = 0; j < pkgs.length; j++) {
			if (pkgs[j].getPath().equals(p)) {
				IPath ret = path.makeRelativeTo(pkgs[j].getPath());
				return ret;
			}
		}
		p = p.append(segments[i]);
	}
	return null;
}
 
Example 5
Project: pgcodekeeper   File: PgDecorator.java   Source Code and License Vote up 6 votes
@Override
public void decorate(Object element, IDecoration decoration) {
    if (element instanceof IResource) {
        IResource res = (IResource) element;
        IProject proj = res.getProject();
        try {
            if (proj != null && proj.isAccessible() && proj.hasNature(NATURE.ID)) {
                IMarker[] markers = res.findMarkers(MARKER.ERROR, false,
                        IResource.DEPTH_INFINITE);
                if (markers.length > 0) {
                    decoration.addOverlay(PlatformUI.getWorkbench().getSharedImages()
                            .getImageDescriptor(ISharedImages.IMG_DEC_FIELD_ERROR));
                }
            }
        } catch (CoreException e) {
            Log.log(e);
        }
    }
}
 
Example 6
Project: gw4e.project   File: PreferenceManager.java   Source Code and License Vote up 5 votes
/**
 * @param path
 */
public static void setTargetFolderForTestInterface(IResource resource,boolean main) {
	IProject project = resource.getProject();
	String path = resource.getFullPath().removeFirstSegments(1).toString();
	String key = GW4E_MAIN_SOURCE_GENERATED_INTERFACE;
	if (!main) {
		key = GW4E_TEST_SOURCE_GENERATED_INTERFACE;
	}		
	boolean projectScoped = isProjectScoped(key);
	SettingsManager.putValues(project, key,
			new String[] { path }, projectScoped);
}
 
Example 7
Project: EclipseMinifyBuilder   File: PrefsAccess.java   Source Code and License Vote up 2 votes
/**
 * Returns the plugin's project scoped preferences using the given 
 * resource to identify the project.
 * 
 * @param resource a resource from the project
 * @return the preferences
 */
public static Preferences preferences(IResource resource) {
	ProjectScope projectScope = new ProjectScope(resource.getProject());
	return projectScope.getNode(MinifyBuilder.BUILDER_ID);
}