use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.
the class AbstractNewResourceAction method updateInPerspective.
@Override
public void updateInPerspective(@NotNull ActionEvent e) {
e.getPresentation().setVisible(true);
final Resource[] resources = appContext.getResources();
if (resources != null && resources.length == 1) {
final Resource resource = resources[0];
if (resource instanceof Container) {
e.getPresentation().setEnabled(true);
} else {
e.getPresentation().setEnabled(resource.getParent() != null);
}
} else {
e.getPresentation().setEnabled(false);
}
}
use of org.eclipse.che.ide.api.resources.Resource 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.Resource in project che by eclipse.
the class EditorContentSynchronizerImplTest method shouldUpdatePathForGroupWhenFolderLocationIsChanged.
@Test
public void shouldUpdatePathForGroupWhenFolderLocationIsChanged() {
Resource resource = mock(Resource.class);
ResourceDelta delta = mock(ResourceDelta.class);
ResourceChangedEvent resourceChangedEvent = new ResourceChangedEvent(delta);
Path fromPath = new Path(FOLDER_PATH);
Path toPath = new Path("testProject/src/main/java/org/eclipse/che/samples/");
Path oldFilePath = new Path(FILE_PATH);
Path newFilePath = new Path("testProject/src/main/java/org/eclipse/che/samples/" + FILE_NAME);
EditorPartPresenter openedEditor1 = mock(EditorPartPresenter.class);
when(openedEditor1.getEditorInput()).thenReturn(editorInput);
when(delta.getKind()).thenReturn(ResourceDelta.ADDED);
when(delta.getFlags()).thenReturn(5632);
when(delta.getFromPath()).thenReturn(fromPath);
when(delta.getToPath()).thenReturn(toPath);
when(delta.getResource()).thenReturn(resource);
when(resource.isFile()).thenReturn(false);
editorContentSynchronizer.trackEditor(openedEditor1);
editorContentSynchronizer.onResourceChanged(resourceChangedEvent);
final EditorGroupSynchronization oldGroup = editorContentSynchronizer.editorGroups.get(oldFilePath);
final EditorGroupSynchronization newGroup = editorContentSynchronizer.editorGroups.get(newFilePath);
assertNull(oldGroup);
assertNotNull(newGroup);
}
use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.
the class ResetFilesPresenter method showDialog.
/** Show dialog. */
public void showDialog(Project project) {
this.project = project;
service.getStatus(appContext.getDevMachine(), project.getLocation()).then(new Operation<Status>() {
@Override
public void apply(Status status) throws OperationException {
if (status.isClean()) {
dialogFactory.createMessageDialog(constant.messagesWarningTitle(), constant.indexIsEmpty(), null).show();
return;
}
indexedFiles = new IndexFile[0];
for (String path : status.getAdded()) {
indexedFiles = add(indexedFiles, wrap(path));
}
for (String path : status.getChanged()) {
indexedFiles = add(indexedFiles, wrap(path));
}
for (String path : status.getRemoved()) {
indexedFiles = add(indexedFiles, wrap(path));
}
if (indexedFiles.length == 0) {
dialogFactory.createMessageDialog(constant.messagesWarningTitle(), constant.indexIsEmpty(), null).show();
return;
}
//Mark selected items to reset from index
Resource[] resources = appContext.getResources();
if (resources != null) {
for (Resource selectedItem : resources) {
String selectedItemPath = selectedItem.getLocation().removeFirstSegments(1).toString();
for (IndexFile file : indexedFiles) if (file.getPath().startsWith(selectedItemPath)) {
file.setIndexed(false);
}
}
}
view.setIndexedFiles(indexedFiles);
view.showDialog();
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
String errorMassage = error.getMessage() != null ? error.getMessage() : constant.statusFailed();
GitOutputConsole console = gitOutputConsoleFactory.create(STATUS_COMMAND_NAME);
console.printError(errorMassage);
consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
notificationManager.notify(errorMassage);
}
});
}
use of org.eclipse.che.ide.api.resources.Resource 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();
}
Aggregations