use of org.eclipse.che.ide.resources.reveal.RevealResourceEvent in project che by eclipse.
the class LinkWithEditorAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
final String linkWithEditorValue = preferencesManager.getValue(LINK_WITH_EDITOR);
boolean value = !parseBoolean(linkWithEditorValue);
preferencesManager.setValue(LINK_WITH_EDITOR, Boolean.toString(value));
if (!value) {
return;
}
final EditorPartPresenter activeEditor = editorAgentProvider.get().getActiveEditor();
if (activeEditor == null) {
return;
}
final EditorInput editorInput = activeEditor.getEditorInput();
if (editorInput == null) {
return;
}
eventBus.fireEvent(new RevealResourceEvent(editorInput.getFile().getLocation()));
}
use of org.eclipse.che.ide.resources.reveal.RevealResourceEvent in project che by eclipse.
the class RevealResourceAction method actionPerformed.
/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent e) {
final Resource[] resources = appContext.getResources();
checkState(resources != null && resources.length == 1);
eventBus.fireEvent(new RevealResourceEvent(resources[0]));
}
use of org.eclipse.che.ide.resources.reveal.RevealResourceEvent in project che by eclipse.
the class CopyPasteManager method moveResource.
private Promise<Void> moveResource(final Resource resource, final Path destination) {
//simple move without overwriting
return resource.move(destination).thenPromise(new Function<Resource, Promise<Void>>() {
@Override
public Promise<Void> apply(Resource resource) throws FunctionException {
eventBus.fireEvent(new RevealResourceEvent(resource));
return promises.resolve(null);
}
}).catchErrorPromise(new Function<PromiseError, Promise<Void>>() {
@Override
public Promise<Void> apply(final PromiseError error) throws FunctionException {
//resource may already exists
if (error.getMessage().contains("exists")) {
//create dialog with overwriting option
return createFromAsyncRequest(new RequestCall<Void>() {
@Override
public void makeCall(final AsyncCallback<Void> callback) {
//handle overwrite operation
final ConfirmCallback overwrite = new ConfirmCallback() {
@Override
public void accepted() {
//copy with overwriting
resource.move(destination, true).then(new Operation<Resource>() {
@Override
public void apply(Resource ignored) throws OperationException {
callback.onSuccess(null);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
callback.onFailure(error.getCause());
}
});
}
};
//skip this resource
final ConfirmCallback skip = new ConfirmCallback() {
@Override
public void accepted() {
callback.onSuccess(null);
}
};
//change destination name
final ConfirmCallback rename = new ConfirmCallback() {
@Override
public void accepted() {
dialogFactory.createInputDialog("Enter new name", "Enter new name", new InputCallback() {
@Override
public void accepted(String value) {
final Path newPath = destination.parent().append(value);
moveResource(resource, newPath).then(new Operation<Void>() {
@Override
public void apply(Void result) throws OperationException {
callback.onSuccess(result);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
callback.onFailure(error.getCause());
}
});
}
}, new CancelCallback() {
@Override
public void cancelled() {
}
}).show();
}
};
dialogFactory.createChoiceDialog("Error", error.getMessage(), "Overwrite", "Skip", "Change Name", overwrite, skip, rename).show();
}
});
} else {
//notify user about failed copying
notificationManager.notify("Error moving resource", error.getMessage(), FAIL, FLOAT_MODE);
return promises.resolve(null);
}
}
});
}
use of org.eclipse.che.ide.resources.reveal.RevealResourceEvent in project che by eclipse.
the class CopyPasteManager method copyResource.
private Promise<Void> copyResource(final Resource resource, final Path destination) {
//simple copy without overwriting
return resource.copy(destination).thenPromise(new Function<Resource, Promise<Void>>() {
@Override
public Promise<Void> apply(Resource resource) throws FunctionException {
eventBus.fireEvent(new RevealResourceEvent(resource));
return promises.resolve(null);
}
}).catchErrorPromise(new Function<PromiseError, Promise<Void>>() {
@Override
public Promise<Void> apply(final PromiseError error) throws FunctionException {
//resource may already exists
if (error.getMessage().contains("exists")) {
//create dialog with overwriting option
return createFromAsyncRequest(new RequestCall<Void>() {
@Override
public void makeCall(final AsyncCallback<Void> callback) {
//handle overwrite operation
final ConfirmCallback overwrite = new ConfirmCallback() {
@Override
public void accepted() {
//copy with overwriting
resource.copy(destination, true).then(new Operation<Resource>() {
@Override
public void apply(Resource ignored) throws OperationException {
callback.onSuccess(null);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
callback.onFailure(error.getCause());
}
});
}
};
//skip this resource
final ConfirmCallback skip = new ConfirmCallback() {
@Override
public void accepted() {
callback.onSuccess(null);
}
};
//change destination name
final ConfirmCallback rename = new ConfirmCallback() {
@Override
public void accepted() {
dialogFactory.createInputDialog("Enter new name", "Enter new name", new InputCallback() {
@Override
public void accepted(String value) {
final Path newPath = destination.parent().append(value);
copyResource(resource, newPath).then(new Operation<Void>() {
@Override
public void apply(Void result) throws OperationException {
callback.onSuccess(result);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
callback.onFailure(error.getCause());
}
});
}
}, new CancelCallback() {
@Override
public void cancelled() {
}
}).show();
}
};
dialogFactory.createChoiceDialog("Error", error.getMessage(), "Overwrite", "Skip", "Change Name", overwrite, skip, rename).show();
}
});
} else {
//notify user about failed copying
notificationManager.notify("Error copying resource", error.getMessage(), FAIL, FLOAT_MODE);
return promises.resolve(null);
}
}
});
}
use of org.eclipse.che.ide.resources.reveal.RevealResourceEvent in project che by eclipse.
the class AbstractNewResourceAction method createFile.
final void createFile(String nameWithoutExtension) {
final String name = getExtension().isEmpty() ? nameWithoutExtension : nameWithoutExtension + '.' + getExtension();
Resource resource = appContext.getResource();
if (!(resource instanceof Container)) {
final Container parent = resource.getParent();
checkState(parent != null, "Parent should be a container");
resource = parent;
}
((Container) resource).newFile(name, getDefaultContent()).then(new Operation<File>() {
@Override
public void apply(File newFile) throws OperationException {
eventBus.fireEvent(FileEvent.createOpenFileEvent(newFile));
eventBus.fireEvent(new RevealResourceEvent(newFile));
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify("Failed to create resource", error.getMessage(), FAIL, FLOAT_MODE);
}
});
}
Aggregations