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

The following examples show how to use org.eclipse.core.resources.IResource#refreshLocal() . 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: IBuildSupport.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
default void refresh(IResource resource, CHANGE_TYPE changeType, IProgressMonitor monitor) throws CoreException {
	if (resource == null) {
		return;
	}
	if (changeType == CHANGE_TYPE.DELETED) {
		if (IJavaProject.CLASSPATH_FILE_NAME.equals(resource.getName())) {
			IProject project = resource.getProject();
			if (ProjectUtils.isJavaProject(project)) {
				ProjectUtils.removeJavaNatureAndBuilder(project, monitor);
				update(project, true, monitor);
			}
		}
		resource = resource.getParent();
	}
	if (resource != null) {
		resource.refreshLocal(IResource.DEPTH_INFINITE, monitor);
	}
}
 
Example 2
Source File: RefreshHandler.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
    if (selection instanceof IStructuredSelection) {
        for (Object element : ((IStructuredSelection) selection).toList()) {
            if (element instanceof ITmfProjectModelElement) {
                IResource resource = ((ITmfProjectModelElement) element).getResource();
                if (resource != null) {
                    try {
                        resource.refreshLocal(IResource.DEPTH_INFINITE, null);
                    } catch (CoreException e) {
                        Activator.getDefault().logError("Error refreshing projects", e); //$NON-NLS-1$
                    }
                }
            }
        }
    }
    return null;
}
 
Example 3
Source File: RefreshAction.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Refresh the resource (with a check for deleted projects).
 * <p>
 * This method may be extended to refresh model objects related to the resource.
 * </p>
 *
 * @param resource
 *            the resource to refresh. Must not be <code>null</code>.
 * @param monitor
 *            progress monitor
 * @throws CoreException
 *             if things go wrong
 * @since 3.4
 */
protected void refreshResource(final IResource resource, final IProgressMonitor monitor) throws CoreException {
	if (resource.getType() == PROJECT) {
		checkLocationDeleted((IProject) resource);
	} else if (resource.getType() == ROOT) {
		final IProject[] projects = ((IWorkspaceRoot) resource).getProjects();
		for (final IProject project : projects) {
			checkLocationDeleted(project);
		}
	}
	resource.refreshLocal(DEPTH_INFINITE, monitor);
	resource.getParent().refreshLocal(DEPTH_INFINITE, monitor);

	runInUI("Refreshing " + resource.getName(), 0, (m) -> {

		FileMetaDataProvider.getInstance().storeMetaData(resource, null, true);
		FileMetaDataProvider.getInstance().getMetaData(resource, false, true);
		getNavigator().getCommonViewer().refresh(getInstance().findWrappedInstanceOf(resource), true);
	});

}
 
Example 4
Source File: JarWriter3.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void registerInWorkspaceIfNeeded() {
	IPath jarPath= fJarPackage.getAbsoluteJarLocation();
	IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
	for (int i= 0; i < projects.length; i++) {
		IProject project= projects[i];
		// The Jar is always put into the local file system. So it can only be
		// part of a project if the project is local as well. So using getLocation
		// is currently save here.
		IPath projectLocation= project.getLocation();
		if (projectLocation != null && projectLocation.isPrefixOf(jarPath)) {
			try {
				jarPath= jarPath.removeFirstSegments(projectLocation.segmentCount());
				jarPath= jarPath.removeLastSegments(1);
				IResource containingFolder= project.findMember(jarPath);
				if (containingFolder != null && containingFolder.isAccessible())
					containingFolder.refreshLocal(IResource.DEPTH_ONE, null);
			} catch (CoreException ex) {
				// don't refresh the folder but log the problem
				JavaPlugin.log(ex);
			}
		}
	}
}
 
Example 5
Source File: JarWriter2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void registerInWorkspaceIfNeeded() {
	IPath jarPath= fJarPackage.getAbsoluteJarLocation();
	IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
	for (int i= 0; i < projects.length; i++) {
		IProject project= projects[i];
		// The Jar is always put into the local file system. So it can only be
		// part of a project if the project is local as well. So using getLocation
		// is currently save here.
		IPath projectLocation= project.getLocation();
		if (projectLocation != null && projectLocation.isPrefixOf(jarPath)) {
			try {
				jarPath= jarPath.removeFirstSegments(projectLocation.segmentCount());
				jarPath= jarPath.removeLastSegments(1);
				IResource containingFolder= project.findMember(jarPath);
				if (containingFolder != null && containingFolder.isAccessible())
					containingFolder.refreshLocal(IResource.DEPTH_ONE, null);
			} catch (CoreException ex) {
				// don't refresh the folder but log the problem
				JavaPlugin.log(ex);
			}
		}
	}
}
 
Example 6
Source File: JarWriter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void registerInWorkspaceIfNeeded() {
	IPath jarPath= fJarPackage.getAbsoluteJarLocation();
	IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
	for (int i= 0; i < projects.length; i++) {
		IProject project= projects[i];
		// The Jar is always put into the local file system. So it can only be
		// part of a project if the project is local as well. So using getLocation
		// is currently save here.
		IPath projectLocation= project.getLocation();
		if (projectLocation != null && projectLocation.isPrefixOf(jarPath)) {
			try {
				jarPath= jarPath.removeFirstSegments(projectLocation.segmentCount());
				jarPath= jarPath.removeLastSegments(1);
				IResource containingFolder= project.findMember(jarPath);
				if (containingFolder != null && containingFolder.isAccessible())
					containingFolder.refreshLocal(IResource.DEPTH_ONE, null);
			} catch (CoreException ex) {
				// don't refresh the folder but log the problem
				JavaPlugin.log(ex);
			}
		}
	}
}
 
Example 7
Source File: ResourceUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public static void refreshLocalAsync(IResource r, IProgressMonitor monitor) {
  	try {
	r.refreshLocal(IResource.DEPTH_INFINITE, monitor);
} catch (CoreException e) {
	LogHelper.logError(e);
}
  }
 
Example 8
Source File: TracePackageExportOperation.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void exportSupplementaryFiles(IProgressMonitor monitor, Node commonNode, TmfCommonProjectElement commonElement, TracePackageSupplFilesElement element) throws InterruptedException, CoreException {
    Document doc = commonNode.getOwnerDocument();
    if (element.getChildren().length > 0) {

        IPath projectPath = commonElement.getProject().getPath();

        for (TracePackageElement child : element.getChildren()) {
            TracePackageSupplFileElement supplFile = (TracePackageSupplFileElement) child;
            ModalContext.checkCanceled(monitor);
            IResource res = supplFile.getResource();
            // project/.tracing/A/B/statistics.ht -> .tracing/A/B/statistics.ht
            IPath relativeToExportFolder = res.getFullPath().makeRelativeTo(projectPath);

            // project/.traceExport/.tracing/A/B
            IFolder folder = fExportFolder.getFolder(relativeToExportFolder.removeLastSegments(1));
            TraceUtils.createFolder(folder, SubMonitor.convert(monitor));

            res.refreshLocal(0, SubMonitor.convert(monitor));
            createExportResource(folder, res);
            Element suppFileElement = doc.createElement(ITracePackageConstants.SUPPLEMENTARY_FILE_ELEMENT);

            suppFileElement.setAttribute(ITracePackageConstants.SUPPLEMENTARY_FILE_NAME_ATTRIB, relativeToExportFolder.toString());
            commonNode.appendChild(suppFileElement);
        }

        IFolder suppFilesFolder = fExportFolder.getFolder(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER_NAME);
        fResources.add(suppFilesFolder);
    }
}
 
Example 9
Source File: RefreshHandler.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
protected void simpleRefresh(final IResource resource, final IProgressMonitor monitor) throws CoreException {
	if (resource.getType() == IResource.PROJECT) {
		checkLocationDeleted((IProject) resource);
	} else if (resource.getType() == IResource.ROOT) {
		final IProject[] projects = ((IWorkspaceRoot) resource).getProjects();
		for (final IProject project : projects) {
			checkLocationDeleted(project);
		}
	}
	resource.refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
 
Example 10
Source File: Util.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Save local history
 * 
 * @param resource
 * @throws CoreException
 */
public static void saveLocalHistory(IResource resource) throws CoreException {
	if (resource instanceof IFile && resource.exists()) {
		if (!resource.isSynchronized(IResource.DEPTH_ZERO))
			resource.refreshLocal(IResource.DEPTH_ZERO, null);
		((IFile)resource).appendContents(new ByteArrayInputStream(new byte[0]),IResource.KEEP_HISTORY, null);
	}
}
 
Example 11
Source File: FileTransferDragAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void handleRefresh() {
	final Set<IResource> roots= collectRoots(getResources());

	WorkspaceModifyOperation op= new WorkspaceModifyOperation() {
		@Override
		public void execute(IProgressMonitor monitor) throws CoreException {
			try {
				monitor.beginTask(PackagesMessages.DragAdapter_refreshing, roots.size());
				MultiStatus status= createMultiStatus();
				Iterator<IResource> iter= roots.iterator();
				while (iter.hasNext()) {
					IResource r= iter.next();
					try {
						r.refreshLocal(IResource.DEPTH_ONE, new SubProgressMonitor(monitor, 1));
					} catch (CoreException e) {
						status.add(e.getStatus());
					}
				}
				if (!status.isOK()) {
					throw new CoreException(status);
				}
			} finally {
				monitor.done();
			}
		}
	};

	runOperation(op, true, false);
}
 
Example 12
Source File: RelativeFileSelectionDialog.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void refreshResource( File file )
{
	IPath resPath = Path.fromOSString( file.getAbsolutePath( ) );

	IResource[] res = ResourcesPlugin.getWorkspace( )
			.getRoot( )
			.findFilesForLocation( resPath );

	if ( res.length == 0 )
	{
		res = ResourcesPlugin.getWorkspace( )
				.getRoot( )
				.findContainersForLocation( resPath );

		if ( res.length == 0 )
		{
			// not resources within the workspace
			return;
		}
	}

	try
	{
		final IResource[] targes = res;

		for ( IResource rc : targes )
		{
			rc.refreshLocal( IResource.DEPTH_INFINITE, null );
		}
	}
	catch ( Exception e )
	{
		// ignore
	}

}
 
Example 13
Source File: ResourceUtils.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static void refresh(IResource resource, IOperationMonitor om) throws CommonException {
	try {
		resource.refreshLocal(IResource.DEPTH_INFINITE, EclipseUtils.pm(om));
	} catch(CoreException e) {
		throw EclipseUtils.createCommonException(e);
	}
}
 
Example 14
Source File: ExportBosArchiveOperation.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void addChildrenFile(IResource resource, Set<IResource> resourcesToExport) throws CoreException {
    if (resource instanceof IFile) {
        resourcesToExport.add(resource);
    } else if (resource instanceof IFolder && !isMetadataFolder(resource) && !isBuildOutputFolder(resource)) {
        resource.refreshLocal(IResource.DEPTH_ONE, Repository.NULL_PROGRESS_MONITOR);
        for (final IResource r : ((IFolder) resource).members()) {
            addChildrenFile(r, resourcesToExport);
        }
    }
}
 
Example 15
Source File: ResourceUtil.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.9
 */
public static void sync(IResource resource, int depth, IProgressMonitor progressMonitor) throws CoreException {
	if (canSync(resource)) {
		resource.refreshLocal(depth, progressMonitor);
	}
}
 
Example 16
Source File: UndoDeleteResourceChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Change perform(IProgressMonitor pm) throws CoreException {
	IResource created= fResourceDescription.createResource(pm);
	created.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(pm, 1));
	return new DeleteResourceChange(created.getFullPath(), true);
}