use of org.eclipse.che.ide.resources.reveal.RevealResourceEvent 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.resources.reveal.RevealResourceEvent in project che by eclipse.
the class NewJavaSourceFilePresenter method createSourceFile.
private void createSourceFile(final String nameWithoutExtension, String packageFragment, final String content) {
if (!isNullOrEmpty(packageFragment)) {
parent.newFolder(packageFragment.replace('.', '/')).then(pkg -> {
pkg.newFile(nameWithoutExtension + ".java", content).then(file -> {
eventBus.fireEvent(FileEvent.createOpenFileEvent(file));
eventBus.fireEvent(new RevealResourceEvent(file));
});
});
} else {
parent.newFile(nameWithoutExtension + ".java", content).then(file -> {
eventBus.fireEvent(FileEvent.createOpenFileEvent(file));
eventBus.fireEvent(new RevealResourceEvent(file));
});
}
}
use of org.eclipse.che.ide.resources.reveal.RevealResourceEvent in project che by eclipse.
the class UploadFilePresenter method onSubmitComplete.
/** {@inheritDoc} */
@Override
public void onSubmitComplete(String result) {
if (!isNullOrEmpty(result)) {
view.closeDialog();
notificationManager.notify(locale.failedToUploadFiles(), parseMessage(result), StatusNotification.Status.FAIL, FLOAT_MODE);
return;
}
container.getFile(Path.valueOf(view.getFileName())).then(new Operation<Optional<File>>() {
@Override
public void apply(final Optional<File> file) throws OperationException {
if (file.isPresent()) {
eventBus.fireEvent(new RevealResourceEvent(file.get()));
final NotificationListener notificationListener = new NotificationListener() {
boolean clicked = false;
@Override
public void onClick(Notification notification) {
if (!clicked) {
eventBus.fireEvent(FileEvent.createOpenFileEvent(file.get()));
clicked = true;
notification.setListener(null);
notification.setContent("");
}
}
@Override
public void onDoubleClick(Notification notification) {
//stub
}
@Override
public void onClose(Notification notification) {
//stub
}
};
notificationManager.notify("File '" + view.getFileName() + "' has uploaded successfully", "Click here to open it", StatusNotification.Status.SUCCESS, FLOAT_MODE, notificationListener);
view.closeDialog();
}
}
});
//TODO this should process editor agent
// if (view.isOverwriteFileSelected()) {
// String path = ((HasStorablePath)getResourceBasedNode()).getStorablePath() + "/" + view.getFileName();
// eventBus.fireEvent(new FileContentUpdateEvent(path));
// }
}
use of org.eclipse.che.ide.resources.reveal.RevealResourceEvent in project che by eclipse.
the class NewPackageAction method onAccepted.
private void onAccepted(String value) {
final Resource resource = appContext.getResource();
checkState(resource instanceof Container, "Parent should be a container");
((Container) resource).newFolder(value.replace('.', '/')).then(new Operation<Folder>() {
@Override
public void apply(Folder pkg) throws OperationException {
eventBus.fireEvent(new RevealResourceEvent(pkg));
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
dialogFactory.createMessageDialog(coreLocalizationConstant.invalidName(), error.getMessage(), null).show();
}
});
}
use of org.eclipse.che.ide.resources.reveal.RevealResourceEvent in project che by eclipse.
the class EditorAgentImpl method onActivePartChanged.
@Override
public void onActivePartChanged(ActivePartChangedEvent event) {
activePart = event.getActivePart();
if (!(event.getActivePart() instanceof EditorPartPresenter)) {
return;
}
activeEditor = (EditorPartPresenter) event.getActivePart();
activeEditor.activate();
final String isLinkedWithEditor = preferencesManager.getValue(LinkWithEditorAction.LINK_WITH_EDITOR);
if (parseBoolean(isLinkedWithEditor)) {
final VirtualFile file = activeEditor.getEditorInput().getFile();
eventBus.fireEvent(new RevealResourceEvent(file.getLocation()));
}
}
Aggregations