use of org.eclipse.che.ide.api.resources.Project in project che by eclipse.
the class AppContextImpl method onResourceChanged.
/** {@inheritDoc} */
@Override
public void onResourceChanged(ResourceChangedEvent event) {
final ResourceDelta delta = event.getDelta();
final Resource resource = delta.getResource();
if (!(resource.getResourceType() == PROJECT && resource.getLocation().segmentCount() == 1)) {
return;
}
if (projects == null) {
//Normal situation, workspace config updated and project has not been loaded fully. Just skip this situation.
return;
}
if (delta.getKind() == ADDED) {
Project[] newProjects = copyOf(projects, projects.length + 1);
newProjects[projects.length] = (Project) resource;
projects = newProjects;
sort(projects, ResourcePathComparator.getInstance());
} else if (delta.getKind() == REMOVED) {
int size = projects.length;
int index = java.util.Arrays.binarySearch(projects, resource, ResourcePathComparator.getInstance());
int numMoved = projects.length - index - 1;
if (numMoved > 0) {
System.arraycopy(projects, index + 1, projects, index, numMoved);
}
projects = copyOf(projects, --size);
if (currentResource != null && currentResource.equals(delta.getResource())) {
currentResource = null;
}
if (currentResources != null) {
for (Resource currentResource : currentResources) {
if (currentResource.equals(delta.getResource())) {
currentResources = Arrays.remove(currentResources, currentResource);
}
}
}
} else if (delta.getKind() == UPDATED) {
int index = -1;
if (delta.getFlags() == MOVED_FROM) {
for (int i = 0; i < projects.length; i++) {
if (projects[i].getLocation().equals(delta.getFromPath())) {
index = i;
break;
}
}
} else {
index = binarySearch(projects, resource);
}
if (index != -1) {
projects[index] = (Project) resource;
}
sort(projects, ResourcePathComparator.getInstance());
} else if (delta.getKind() == SYNCHRONIZED && resource.isProject() && resource.getLocation().segmentCount() == 1) {
for (int i = 0; i < projects.length; i++) {
if (projects[i].getLocation().equals(resource.getLocation())) {
projects[i] = (Project) resource;
}
}
if (currentResources != null) {
for (int i = 0; i < currentResources.length; i++) {
if (currentResources[i].getLocation().equals(resource.getLocation())) {
currentResources[i] = resource;
break;
}
}
}
if (currentResource != null && currentResource.getLocation().equals(resource.getLocation())) {
currentResource = resource;
}
}
}
use of org.eclipse.che.ide.api.resources.Project in project che by eclipse.
the class ExplorerCurrentProjectTypeMacro method expand.
/** {@inheritDoc} */
@Override
public Promise<String> expand() {
List<Node> selectedNodes = projectExplorer.getTree().getSelectionModel().getSelectedNodes();
if (selectedNodes.isEmpty() || selectedNodes.size() > 1) {
return promises.resolve("");
}
final Node node = selectedNodes.get(0);
if (node instanceof ResourceNode) {
final Optional<Project> project = ((ResourceNode) node).getData().getRelatedProject();
if (!project.isPresent()) {
return promises.resolve("");
}
return promises.resolve(project.get().getType());
}
return promises.resolve("");
}
use of org.eclipse.che.ide.api.resources.Project in project che by eclipse.
the class GdbDebugger method fqnToPath.
@Override
protected String fqnToPath(@NotNull Location location) {
final Resource resource = appContext.getResource();
if (resource == null) {
return location.getTarget();
}
final Optional<Project> project = resource.getRelatedProject();
if (project.isPresent()) {
return project.get().getLocation().append(location.getTarget()).toString();
}
return location.getTarget();
}
use of org.eclipse.che.ide.api.resources.Project in project che by eclipse.
the class NewJavaSourceFileAction method updateProjectAction.
@Override
public void updateProjectAction(ActionEvent e) {
final Resource resource = appContext.getResource();
if (resource == null) {
e.getPresentation().setEnabledAndVisible(false);
return;
}
final Optional<Project> project = resource.getRelatedProject();
if (!project.isPresent()) {
e.getPresentation().setEnabledAndVisible(false);
return;
}
e.getPresentation().setEnabledAndVisible(isJavaProject(project.get()) && resource.getParentWithMarker(ID).isPresent());
}
use of org.eclipse.che.ide.api.resources.Project in project che by eclipse.
the class OutputDirMacro method expand.
@Override
public Promise<String> expand() {
final Resource[] resources = appContext.getResources();
if (resources != null && resources.length == 1) {
final Resource resource = resources[0];
final Optional<Project> project = resource.getRelatedProject();
if (!project.isPresent()) {
return promises.resolve("");
}
Project relatedProject = project.get();
if (!isJavaProject(relatedProject)) {
return promises.resolve("");
}
if (relatedProject.getAttributes().containsKey(OUTPUT_FOLDER)) {
return promises.resolve(appContext.getProjectsRoot().append(relatedProject.getLocation()).append(relatedProject.getAttributes().get(OUTPUT_FOLDER).get(0)).toString());
} else {
return promises.resolve(appContext.getProjectsRoot().append(relatedProject.getLocation()).toString());
}
}
return promises.resolve("");
}
Aggregations