use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class MoveAction method updateInPerspective.
/** {@inheritDoc} */
@Override
public void updateInPerspective(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();
if (!project.isPresent()) {
event.getPresentation().setEnabled(false);
return;
}
final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
if (resource.getResourceType() == FILE) {
event.getPresentation().setEnabled(JavaUtil.isJavaProject(project.get()) && srcFolder.isPresent() && isJavaFile((File) resource));
} else if (resource instanceof Container) {
event.getPresentation().setEnabled(JavaUtil.isJavaProject(project.get()) && srcFolder.isPresent());
}
}
use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class MoveAction method actionPerformed.
/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent actionEvent) {
final Resource[] resources = appContext.getResources();
if (resources == null || resources.length > 1) {
return;
}
final Resource resource = resources[0];
final Optional<Project> project = resource.getRelatedProject();
if (!JavaUtil.isJavaProject(project.get())) {
return;
}
final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
if (!srcFolder.isPresent() || resource.getLocation().equals(srcFolder.get().getLocation())) {
return;
}
RefactoredItemType renamedItemType = null;
if (resource.getResourceType() == FILE && isJavaFile((File) resource)) {
renamedItemType = COMPILATION_UNIT;
} else if (resource instanceof Container) {
renamedItemType = PACKAGE;
}
if (renamedItemType == null) {
return;
}
movePresenter.show(RefactorInfo.of(REFACTOR_MENU, renamedItemType, resources));
}
use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class RenameRefactoringAction method updateInPerspective.
@Override
public void updateInPerspective(ActionEvent event) {
event.getPresentation().setVisible(true);
if (editorInFocus) {
final EditorPartPresenter editorPart = editorAgent.getActiveEditor();
if (editorPart == null || !(editorPart instanceof TextEditor)) {
event.getPresentation().setEnabled(false);
return;
}
final VirtualFile file = editorPart.getEditorInput().getFile();
if (file instanceof File) {
final Optional<Project> project = ((File) file).getRelatedProject();
if (!project.isPresent()) {
event.getPresentation().setEnabled(false);
return;
}
event.getPresentation().setEnabled(JavaUtil.isJavaProject(project.get()) && isJavaFile(file));
} else {
event.getPresentation().setEnabled(isJavaFile(file));
}
} else {
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();
if (!project.isPresent()) {
event.getPresentation().setEnabled(false);
return;
}
final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
if (resource.getResourceType() == FILE) {
event.getPresentation().setEnabled(JavaUtil.isJavaProject(project.get()) && srcFolder.isPresent() && isJavaFile((File) resource));
} else if (resource instanceof Container) {
event.getPresentation().setEnabled(JavaUtil.isJavaProject(project.get()) && srcFolder.isPresent());
}
}
}
use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class RenameRefactoringAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent event) {
if (editorInFocus) {
final EditorPartPresenter editorPart = editorAgent.getActiveEditor();
if (editorPart == null || !(editorPart instanceof TextEditor)) {
return;
}
javaRefactoringRename.refactor((TextEditor) editorPart);
} else {
final Resource[] resources = appContext.getResources();
if (resources == null || resources.length > 1) {
return;
}
final Resource resource = resources[0];
final Optional<Project> project = resource.getRelatedProject();
if (!JavaUtil.isJavaProject(project.get())) {
return;
}
final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
if (!srcFolder.isPresent() || resource.getLocation().equals(srcFolder.get().getLocation())) {
return;
}
RefactoredItemType renamedItemType = null;
if (resource.getResourceType() == FILE && isJavaFile((File) resource)) {
renamedItemType = COMPILATION_UNIT;
} else if (resource instanceof Container) {
renamedItemType = PACKAGE;
}
if (renamedItemType == null) {
return;
}
renamePresenter.show(RefactorInfo.of(renamedItemType, resources));
}
}
use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class ResourceManager method findResource.
private Promise<Optional<Resource>> findResource(final Path absolutePath, boolean quiet) {
//search resource in local cache
final Optional<Resource> optionalCachedResource = store.getResource(absolutePath);
if (optionalCachedResource.isPresent()) {
return promises.resolve(optionalCachedResource);
}
//request from server
final Path projectPath = Path.valueOf(absolutePath.segment(0)).makeAbsolute();
final Optional<Resource> optProject = store.getResource(projectPath);
final boolean isPresent = optProject.isPresent();
checkState(isPresent || quiet, "Resource with path '" + projectPath + "' doesn't exists");
if (!isPresent) {
return promises.resolve(Optional.<Resource>absent());
}
final Resource project = optProject.get();
checkState(project.getResourceType() == PROJECT, "Resource with path '" + projectPath + "' isn't a project");
final int seekDepth = absolutePath.segmentCount() - 1;
return getRemoteResources((Container) project, seekDepth, true).then(new Function<Resource[], Optional<Resource>>() {
@Override
public Optional<Resource> apply(Resource[] resources) throws FunctionException {
for (Resource resource : resources) {
if (absolutePath.equals(resource.getLocation())) {
return of(resource);
}
}
return absent();
}
});
}
Aggregations