/** * Returns {@code true} if current represents a folder. * * @return true if current resource is folder based resource. * @see Resource#getResourceType() * @see Resource#FOLDER * @since 4.4.0 */ default boolean isFolder() { return getResourceType() == FOLDER; }
/** * 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; }
/** * Returns {@code true} if current represents a project. * * @return true if current resource is project based resource. * @see Resource#getResourceType() * @see Resource#PROJECT * @since 4.4.0 */ default boolean isProject() { return getResourceType() == PROJECT; }
private String getDisplayType(Resource resource) { if (resource.getResourceType() == PROJECT) { return "project"; } else if (resource.getResourceType() == FOLDER) { return "folder"; } else if (resource.getResourceType() == FILE) { return "file"; } else { return "resource"; } }
private boolean isJavaTestFile(Resource resource) { if (resource.getResourceType() != FILE) { return false; } final String ext = ((File) resource).getExtension(); return newHashSet("java", "class", "xml").contains(ext); } }
@Override public boolean isLeaf() { return getData().getResourceType() == Resource.FILE; }
private int getClassIndex(Node node) { if (node instanceof ResourceNode && (((ResourceNode) node).getData().getResourceType() == FOLDER || ((ResourceNode) node).getData().getResourceType() == PROJECT)) { return 1; } if (node instanceof ResourceNode && ((ResourceNode) node).getData().getResourceType() == FILE) { return 2; } if (node instanceof SyntheticNode<?>) { return 3; } return 0; }
protected Node createNode(Resource resource) { checkArgument(resource != null, "Not a resource"); switch (resource.getResourceType()) { case PROJECT: case FOLDER: return nodeFactory.newPackage((Container) resource, getSettings()); case FILE: return nodeFactory.newFileNode((File) resource, getSettings()); default: throw new IllegalArgumentException("Resource type was not recognized"); } }
@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); } }
@Override public void updateInPerspective(@NotNull ActionEvent event) { super.updateInPerspective(event); final Resource resource = appContext.getResource(); event.getPresentation().setEnabled(resource != null && resource.getResourceType() == FILE); } }
protected Node createNode(Resource resource) { checkArgument(resource != null, "Not a resource"); switch (resource.getResourceType()) { case PROJECT: case FOLDER: return nodeFactory.newContainerNode((Container) resource, getSettings()); case FILE: return nodeFactory.newFileNode((File) resource, getSettings()); default: throw new IllegalArgumentException("Resource type was not recognized"); } } }
@Override public SVGResource getIcon(Resource resource) { if (resource.getResourceType() != Resource.FILE) { return null; } FileType fileType = fileTypeRegistry.getFileTypeByFile((File) resource); return fileType.equals(unknownFileType) ? null : fileType.getImage(); } }
/** {@inheritDoc} */ @Override public void actionPerformed(ActionEvent e) { final Resource resource = appContext.getResource(); if (resource == null || resource.getResourceType() != PROJECT) { return; } final Project project = (Project) resource; downloadContainer.setUrl(project.getURL()); }
/** {@inheritDoc} */ @Override public void performCut(AppContext appContext) { final Resource[] resources = appContext.getResources(); // check general state checkState(resources != null && resources.length > 0); for (Resource resource : resources) { // if there is at least one root project if (resource.getResourceType() == PROJECT && resource.getLocation().segmentCount() == 1) { throw new IllegalStateException( "Project '" + resource.getLocation() + "' can not be cut"); } } copyPasteManager.setResources(resources, true); }
/** {@inheritDoc} */ @Override public void updateInPerspective(@NotNull ActionEvent e) { final Resource[] resources = appContext.getResources(); e.getPresentation().setVisible(true); e.getPresentation() .setEnabled( resources != null && resources.length == 1 && resources[0].getResourceType() == PROJECT); } }
@Override public void actionPerformed(ActionEvent e) { final Resource selectedResource = appContext.getResource(); if (Resource.FILE == selectedResource.getResourceType()) { final String contentUrl = ((File) selectedResource).getContentUrl(); BrowserUtils.openInNewTab(agentURLModifier.modify(contentUrl)); } } }
@Override public void actionPerformed(ActionEvent e) { final Resource selectedResource = appContext.getResource(); if (Resource.FILE == selectedResource.getResourceType()) { final String contentUrl = ((File) selectedResource).getContentUrl(); BrowserUtils.openInNewTab(agentURLModifier.modify(contentUrl)); } } }
/** {@inheritDoc} */ @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Resource)) { return false; } Resource resource = (Resource) o; return getResourceType() == resource.getResourceType() && getLocation().equals(resource.getLocation()); }
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 updateInPerspective(ActionEvent e) { final Resource[] resources = appContext.getResources(); if (resources != null && resources.length == 1) { final Resource selectedResource = resources[0]; if (Resource.FILE == selectedResource.getResourceType()) { final String fileExtension = ((File) selectedResource).getExtension(); e.getPresentation().setEnabledAndVisible(extensions.contains(fileExtension)); return; } } e.getPresentation().setEnabledAndVisible(false); }