use of org.eclipse.che.ide.api.resources.Container 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);
}
});
}
use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class ComparePresenter method onClose.
@Override
public void onClose(final String newContent) {
if (!compareWithLatest || this.localContent == null || newContent.equals(localContent)) {
view.hide();
return;
}
ConfirmCallback confirmCallback = new ConfirmCallback() {
@Override
public void accepted() {
comparedFile.updateContent(newContent).then(new Operation<Void>() {
@Override
public void apply(Void ignored) throws OperationException {
final Container parent = comparedFile.getParent();
if (parent != null) {
parent.synchronize();
}
eventBus.fireEvent(new FileContentUpdateEvent(comparedFile.getLocation().toString()));
view.hide();
}
});
}
};
CancelCallback cancelCallback = new CancelCallback() {
@Override
public void cancelled() {
view.hide();
}
};
dialogFactory.createConfirmDialog(locale.compareSaveTitle(), locale.compareSaveQuestion(), locale.buttonYes(), locale.buttonNo(), confirmCallback, cancelCallback).show();
}
use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class AddToIndexPresenter method showDialog.
public void showDialog() {
Resource[] resources = appContext.getResources();
checkState(resources != null && resources.length > 0);
if (resources.length == 1) {
Resource resource = appContext.getResource();
if (resource instanceof Container) {
view.setMessage(constant.addToIndexFolder(resource.getName()));
} else {
view.setMessage(constant.addToIndexFile(resource.getName()));
}
} else {
view.setMessage(constant.addToIndexMultiSelect());
}
view.setUpdated(false);
view.showDialog();
}
use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class RemoveFromIndexPresenter method showDialog.
public void showDialog(Project project) {
Resource[] resources = appContext.getResources();
checkState(resources != null && resources.length > 0);
this.project = project;
if (resources.length == 1) {
Resource resource = appContext.getResource();
String selectedItemName = resource.getName();
if (resource instanceof Container) {
view.setMessage(constant.removeFromIndexFolder(selectedItemName));
} else {
view.setMessage(constant.removeFromIndexFile(selectedItemName));
}
} else {
view.setMessage(constant.removeFromIndexAll());
}
view.setRemoved(false);
view.showDialog();
}
use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class CutJavaSourceAction method update.
@Override
public void update(ActionEvent event) {
event.getPresentation().setVisible(true);
final Resource[] resources = appContext.getResources();
if (resources == null || resources.length > 1) {
event.getPresentation().setEnabled(false);
return;
}
final Resource resource = resources[0];
final Optional<Project> project = resource.getRelatedProject();
final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
if (resource.getResourceType() == FILE) {
event.getPresentation().setEnabled(!isEditorPartActive && isJavaProject(project.get()) && srcFolder.isPresent() && isJavaFile((File) resource));
} else if (resource instanceof Container) {
event.getPresentation().setEnabled(!isEditorPartActive && isJavaProject(project.get()) && srcFolder.isPresent());
}
}
Aggregations