/** * Returns {@code true} if current represents a file. * * @return true if current resource is file based resource. * @see Resource#getResourceType() * @see Resource#FILE * @since 4.4.0 */ default boolean isFile() { return getResourceType() == FILE; }
@Override public final void intercept(Resource resource) { checkArgument(resource != null, "Null resource occurred"); if (resource.isFolder()) { final Optional<Project> project = resource.getRelatedProject(); if (project.isPresent() && isJavaProject(project.get())) { final Path resourcePath = resource.getLocation(); for (Path path : getPaths(project.get(), getAttribute())) { if (path.equals(resourcePath)) { resource.addMarker(new SourceFolderMarker(getContentRoot())); return; } } } } }
/** {@inheritDoc} */ @Override public void intercept(Resource resource) { if (resource.isFile() && POM_XML.equals(resource.getName())) { Project project = resource.getProject(); if (project != null && project.isTypeOf(MAVEN_ID) && resource.getParent().getLocation().equals(project.getLocation())) { String artifact = project.getAttribute(ARTIFACT_ID); if (!isNullOrEmpty(artifact) && !UNKNOWN_VALUE.equals(artifact)) { resource.addMarker(new PresentableTextMarker(artifact)); } } } } }
@Override public boolean isRenameAllowed(Resource resource) { boolean inSource = resource.getParentWithMarker(SourceFolderMarker.ID).isPresent(); boolean isJavaClass = resource.isFile() && "java".equals(((File) resource).getExtension()); return !inSource || !resource.isFolder() && !isJavaClass; } }
protected void setResources(Resource[] resources, boolean move) { if (this.resources != null) { for (Resource resource : this.resources) { resource.deleteMarker(CutResourceMarker.ID); } } this.resources = resources; this.move = move; if (move) { for (Resource resource : resources) { resource.addMarker(new CutResourceMarker()); } } }
if (resource.isFile()) { VcsStatus oldVcsStatus = resource.asFile().getVcsStatus(); VcsStatus newVcsStatus = vcsStatusMap.remove(resource.getName()); resource.asFile().setVcsStatus(newVcsStatus); .forEach(outdated -> store.dispose(outdated.getLocation(), false)); store.register(tempResource); if (tempResource.isProject()) { inspectProject(tempResource.asProject());
if (rootProject.getLocation().equals(delta.getFromPath()) && resource.isProject()) { rootProjects.set(rootProjects.indexOf(rootProject), resource.asProject()); break; if (selectedResource.getLocation().equals(delta.getFromPath())) { selectedResources.set(selectedResources.indexOf(selectedResource), resource); break; } else if (resource.getLocation().segmentCount() == 1 && resource.isProject()) { boolean exists = rootProjects.stream().anyMatch(it -> it.getLocation().equals(resource.getLocation())); rootProjects.add(resource.asProject()); rootProjects.sort(ResourcePathComparator.getInstance()); if (rootProject.getLocation().equals(resource.getLocation()) && resource.isProject()) { rootProjects.remove(rootProjects.indexOf(rootProject)); break; if (selectedResource.getLocation().equals(resource.getLocation())) { selectedResources.remove(selectedResources.indexOf(selectedResource)); break; if (rootProject.getLocation().equals(resource.getLocation()) && resource.isProject()) { rootProjects.set(rootProjects.indexOf(rootProject), resource.asProject()); break; if (selectedResource.getLocation().equals(resource.getLocation())) { selectedResources.set(selectedResources.indexOf(selectedResource), resource);
ResourceDelta delta = event.getDelta(); Resource resource = delta.getResource(); if (resource.isProject() && resource.getLocation().segmentCount() == 1) { if (isProjectUnderGit(resource.asProject())) { if (delta.getKind() == ResourceDelta.ADDED) { if ((delta.getFlags() & (MOVED_FROM | MOVED_TO)) != 0) { } else { changes.put(resource.getName(), new MutableAlteredFiles(resource.asProject())); view.addRepository(resource.getName()); changes.remove(resource.getName()); view.removeRepository(resource.getName());
private void analyzeProjectTreeSelection(Presentation presentation) { Resource[] resources = appContext.getResources(); if (resources == null || resources.length > 1) { presentation.setEnabled(false); return; } Resource resource = resources[0]; if (resource.isProject() && isJavaProject((Project) resource)) { testDetector.setContextType(PROJECT); presentation.setEnabled(true); return; } Project project = resource.getProject(); if (!isJavaProject(project)) { presentation.setEnabled(false); return; } if (isJavaTestFile(resource)) { testDetector.setContextType(TestExecutionContext.ContextType.FILE); } else if (resource instanceof Container) { Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID); if (!srcFolder.isPresent() || resource.getLocation().equals(srcFolder.get().getLocation())) { presentation.setEnabled(false); return; } testDetector.setContextType(TestExecutionContext.ContextType.FOLDER); } presentation.setEnabled(true); selectedNodePath = resource.getLocation().toString(); }
/** {@inheritDoc} */ @Override public void intercept(Resource resource) { if (!Boolean.valueOf(preferencesManager.getValue(PREF_SHOW_ARTIFACT_ID))) { return; } if (resource.isProject() && ((Project) resource).isTypeOf(MAVEN_ID)) { final String artifact = ((Project) resource).getAttribute(ARTIFACT_ID); if (!isNullOrEmpty(artifact) && !artifact.equals(resource.getName())) { resource.addMarker(new PresentableTextMarker(resource.getName() + " [" + artifact + "]")); } } } }
/** {@inheritDoc} */ @Override public Path getFromPath() { if ((status & MOVED_FROM) != 0 || (status & COPIED_FROM) != 0) { return oldResource.getLocation(); } return null; }
protected String getUrl(Resource resource) { checkArgument(!resource.getLocation().isRoot(), "Workspace root doesn't have export URL"); final String baseUrl = appContext.getWsAgentServerApiEndpoint() + "/project/export"; if (resource.getResourceType() == FILE) { return baseUrl + "/file" + resource.getLocation(); } return urlModifier.modify(baseUrl + resource.getLocation()); }
@Override public void actionPerformed(ActionEvent event) { Resource resource = appContext.get().getResource(); if (resource.isFile()) { final Container parent = resource.getParent(); resource = parent; } Path path = appContext.get().getProjectsRoot().append(resource.getLocation()); Command cmdTmpl = GWT.create(Command.class); String command = cmdTmpl.openInTerminalCommand(path.toString()).asString(); processesPanelPresenter.newTerminal(TerminalOptionsJso.create().withCommand(command), true); } }
/** * Shows dialog which contains information about file fqn and path calculated from passed element. * * @param resource element for which fqn and path will be calculated */ public void show(Resource resource) { final Optional<Project> project = resource.getRelatedProject(); if (project.isPresent()) { final FqnProvider provider = providers.get(project.get().getType()); try { view.show(provider.getFqn(resource), resource.getLocation()); } catch (RuntimeException e) { view.show("", resource.getLocation()); } } } }
/** Registers events handlers. */ private void registerEventHandlers(EventBus eventBus) { eventBus.addHandler( EditorOpenedEvent.TYPE, event -> onOpenEditor(event.getFile().getLocation().toString(), event.getEditor())); eventBus.addHandler( ResourceChangedEvent.getType(), event -> { if (event.getDelta().getKind() == ResourceDelta.REMOVED) { final Resource resource = event.getDelta().getResource(); Path path = resource.getLocation(); if (resource.isFolder()) { deleteBreakpoints(path.addTrailingSeparator().toString()); } else if (resource.isFile()) { deleteBreakpoints(path.toString()); } } }); }
protected Promise<Optional<File>> getFile(final Path absolutePath) { final Optional<Resource> resourceOptional = store.getResource(absolutePath); if (resourceOptional.isPresent() && resourceOptional.get().isFile()) { return promises.resolve(of(resourceOptional.get().asFile())); } if (store.getResource(absolutePath.parent()).isPresent()) { return findResource(absolutePath) .thenPromise( optionalFile -> { if (optionalFile.isPresent()) { final Resource resource = optionalFile.get(); checkState(resource.getResourceType() == FILE, "Not a file"); return promises.resolve(of((File) resource)); } return promises.resolve(absent()); }); } else { return findResourceForExternalOperation(absolutePath) .thenPromise( optionalFile -> { if (optionalFile.isPresent()) { final Resource resource = optionalFile.get(); checkState(resource.getResourceType() == FILE, "Not a file"); return promises.resolve(of((File) resource)); } return promises.resolve(absent()); }); } }
@Override public void actionPerformed(ActionEvent e) { final Resource[] resources = appContext.getResources(); checkState(resources != null && resources.length == 1); final Resource project = resources[0].getProject(); checkState(project != null); if (project.getResourceType() == PROJECT) { final MutableProjectConfig config = new MutableProjectConfig((Project) project); projectWizard.show(config); } }
protected Promise<Void> delete(final Resource resource) { checkArgument(!resource.getLocation().isRoot(), "Workspace root is not allowed to be moved"); return ps.deleteItem(resource.getLocation()) .then( (Function<Void, Void>) store.getAll(resource.getLocation()); store.dispose(resource.getLocation(), !resource.isFile()); deletedFilesController.add(resource.getLocation().toString()); for (Resource toRemove : descToRemove) { if (isResourceOpened(toRemove)) { deletedFilesController.add(toRemove.getLocation().toString());