/** Returns the default {@link ApplicableContext} for the new command. */ private ApplicableContext getDefaultContext() { final ApplicableContext context = new ApplicableContext(); if (appContext.getProjects().length > 0) { context.setWorkspaceApplicable(false); Arrays.stream(appContext.getProjects()).forEach(p -> context.addProject(p.getPath())); } return context; }
@Override public void onApplicableProjectChanged(Project project, boolean applicable) { final ApplicableContext context = editedCommand.getApplicableContext(); if (applicable) { // if command is bound with one project at least // then remove command from the workspace if (context.getApplicableProjects().isEmpty()) { context.setWorkspaceApplicable(false); } context.addProject(project.getPath()); } else { context.removeProject(project.getPath()); // if command isn't bound to any project // then save it to the workspace if (context.getApplicableProjects().isEmpty()) { context.setWorkspaceApplicable(true); } } notifyDirtyStateChanged(); }
(Function<Void, CommandImpl>) aVoid -> { newCommand.getApplicableContext().setWorkspaceApplicable(true); return newCommand; });