@Nullable @Override public String apply(@Nullable Resource input) { checkNotNull(input); final Container parent = input.getParent(); if (parent == null) { return ""; } return appContext.getProjectsRoot().append(parent.getLocation()).toString(); } };
@Override public void actionPerformed(ActionEvent e) { final Resource[] resources = appContext.getResources(); final boolean inJavaProject = resources != null && resources.length == 1 && isJavaProject(resources[0].getRelatedProject().get()); checkState(inJavaProject && resources[0].getParentWithMarker(ID).isPresent()); final Resource resource = resources[0]; if (resource instanceof Container) { newJavaSourceFilePresenter.showDialog((Container) resource); } else { final Container parent = resource.getParent(); if (parent != null) { newJavaSourceFilePresenter.showDialog(parent); } else { throw new IllegalStateException("Failed to get parent container"); } } }
@Override public void actionPerformed(ActionEvent e) { final Resource[] resources = appContext.getResources(); if (resources == null || resources.length != 1) { return; } final Resource resource = resources[0]; if (resource instanceof Container) { ((Container) resource).synchronize(); } else { final Container parent = resource.getParent(); if (parent != null) { parent.synchronize(); } } }
private void updateResource(String path) { appContext .getWorkspaceRoot() .getResource(Path.valueOf(path)) .then( resource -> { if (resource.isPresent()) { resource.get().getProject().synchronize(); resource.get().getParent().synchronize(); } }); }
final void createFolder(String name) { 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) .newFolder(name) .then( new Operation<Folder>() { @Override public void apply(Folder folder) throws OperationException { eventBus.fireEvent(new RevealResourceEvent(folder)); } }) .catchError( new Operation<PromiseError>() { @Override public void apply(PromiseError error) throws OperationException { dialogFactory.createMessageDialog("Error", error.getMessage(), null).show(); } }); }
/** {@inheritDoc} */ @Override public void actionPerformed(ActionEvent e) { final Resource[] resources = appContext.getResources(); final Path searchPath; if (resources == null || resources.length == 0 || resources.length > 1) { searchPath = Path.ROOT; } else { if (resources[0] instanceof Container) { searchPath = resources[0].getLocation(); } else { final Container parent = resources[0].getParent(); searchPath = parent != null ? parent.getLocation() : Path.ROOT; } } presenter.showDialog(searchPath); } }
@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); } }
/** {@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)); } } } } }
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 { editorAgentProvider.get().openEditor(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); } }); }
@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); } }
Container parent = resource.getParent(); checkState(parent != null, "Parent of the resource wasn't found"); container = parent;
@Override public void updateInPerspective(@NotNull ActionEvent event) { if (!(activePart instanceof ProjectExplorerPresenter)) { event.getPresentation().setEnabledAndVisible(false); return; } event.getPresentation().setText("Refresh"); 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]; if (resource instanceof Container) { event.getPresentation().setText("Refresh '" + resource.getName() + "'"); } else { final Container parent = resource.getParent(); if (parent != null) { event.getPresentation().setText("Refresh '" + parent.getName() + "'"); } else { event.getPresentation().setEnabled(false); return; } } event.getPresentation().setEnabled(true); }