use of org.eclipse.che.ide.api.resources.ExternalResourceDelta in project che by eclipse.
the class RefactoringUpdater method updateAfterRefactoring.
/**
* Iterates over each refactoring change and according to change type performs specific update operation.
* i.e. for {@code ChangeName#UPDATE} updates only opened editors, for {@code ChangeName#MOVE or ChangeName#RENAME_COMPILATION_UNIT}
* updates only new paths and opened editors, for {@code ChangeName#RENAME_PACKAGE} reloads package structure and restore expansion.
*
* @param changes
* applied changes
*/
public void updateAfterRefactoring(List<ChangeInfo> changes) {
if (changes == null || changes.isEmpty()) {
return;
}
ExternalResourceDelta[] deltas = new ExternalResourceDelta[0];
final List<String> pathChanged = new ArrayList<>();
for (ChangeInfo change : changes) {
final ExternalResourceDelta delta;
final Path newPath = Path.valueOf(change.getPath());
final Path oldPath = !isNullOrEmpty(change.getOldPath()) ? Path.valueOf(change.getOldPath()) : Path.EMPTY;
switch(change.getName()) {
case MOVE:
case RENAME_COMPILATION_UNIT:
delta = new ExternalResourceDelta(newPath, oldPath, ADDED | MOVED_FROM | MOVED_TO);
registerRemovedFile(change);
break;
case RENAME_PACKAGE:
delta = new ExternalResourceDelta(newPath, oldPath, ADDED | MOVED_FROM | MOVED_TO);
break;
case UPDATE:
if (!isFileRemoved(change.getPath(), changes)) {
pathChanged.add(change.getPath());
registerRemovedFile(change);
}
default:
continue;
}
final int index = deltas.length;
deltas = Arrays.copyOf(deltas, index + 1);
deltas[index] = delta;
}
//here we need to remove file for file that moved or renamed JDT lib sent it to
for (int i = 0; i < deltas.length; i++) {
if (pathChanged.contains(deltas[i].getToPath().toString())) {
pathChanged.remove(deltas[i].getToPath().toString());
}
if (pathChanged.contains(deltas[i].getFromPath().toString())) {
pathChanged.remove(deltas[i].getFromPath().toString());
}
}
if (deltas.length > 0) {
appContext.getWorkspaceRoot().synchronize(deltas).then(new Operation<ResourceDelta[]>() {
@Override
public void apply(final ResourceDelta[] appliedDeltas) throws OperationException {
for (ResourceDelta delta : appliedDeltas) {
eventBus.fireEvent(new RevealResourceEvent(delta.getToPath()));
}
for (EditorPartPresenter editorPartPresenter : editorAgent.getOpenedEditors()) {
final String path = editorPartPresenter.getEditorInput().getFile().getLocation().toString();
if (pathChanged.contains(path)) {
eventBus.fireEvent(new FileContentUpdateEvent(editorPartPresenter.getEditorInput().getFile().getLocation().toString()));
}
}
setActiveEditor();
}
});
} else {
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
for (EditorPartPresenter editorPartPresenter : editorAgent.getOpenedEditors()) {
eventBus.fireEvent(new FileContentUpdateEvent(editorPartPresenter.getEditorInput().getFile().getLocation().toString()));
}
setActiveEditor();
}
});
}
}
use of org.eclipse.che.ide.api.resources.ExternalResourceDelta in project che by eclipse.
the class EditorFileStatusNotificationOperation method apply.
public void apply(String endpointId, FileStateUpdateDto params) {
final FileWatcherEventType status = params.getType();
final String stringPath = params.getPath();
final String name = stringPath.substring(stringPath.lastIndexOf("/") + 1);
switch(status) {
case MODIFIED:
{
Log.debug(getClass(), "Received updated file event status: " + stringPath);
eventBus.fireEvent(new FileContentUpdateEvent(stringPath, params.getHashCode()));
break;
}
case DELETED:
{
Log.debug(getClass(), "Received removed file event status: " + stringPath);
final Path path = Path.valueOf(stringPath);
appContext.getWorkspaceRoot().synchronize(new ExternalResourceDelta(path, path, REMOVED));
if (notificationManager != null && !deletedFilesController.remove(stringPath)) {
notificationManager.notify("External operation", "File '" + name + "' is removed", SUCCESS, EMERGE_MODE);
}
break;
}
}
}
use of org.eclipse.che.ide.api.resources.ExternalResourceDelta in project che by eclipse.
the class ProjectTreeStateNotificationOperation method apply.
@Override
public void apply(String endpointId, ProjectTreeStateUpdateDto params) throws JsonRpcException {
final String path = params.getPath();
final FileWatcherEventType type = params.getType();
final int status;
switch(type) {
case CREATED:
{
status = ADDED;
break;
}
case DELETED:
{
status = REMOVED;
break;
}
case MODIFIED:
{
status = UPDATED;
break;
}
default:
{
status = UPDATED;
break;
}
}
Log.debug(getClass(), "Received request\npath: " + path + "\ntype:" + type + "\nstatus:" + status);
if (path == null || path.isEmpty()) {
appContext.getWorkspaceRoot().synchronize();
} else {
appContext.getWorkspaceRoot().synchronize(new ExternalResourceDelta(Path.valueOf(path), Path.valueOf(path), status));
}
if (status == ADDED) {
appContext.getWorkspaceRoot().getFile(Path.valueOf(path)).then(new Operation<Optional<File>>() {
@Override
public void apply(Optional<File> arg) throws OperationException {
if (arg.isPresent()) {
appContext.getWorkspaceRoot().synchronize(new ExternalResourceDelta(Path.valueOf(path), Path.valueOf(path), UPDATED));
}
}
});
}
}
Aggregations