/** Refresh 'Projects' section in the view. */ private void refreshProjects() { final Map<Project, Boolean> projectsStates = new HashMap<>(); for (Project project : appContext.getProjects()) { ApplicableContext context = editedCommand.getApplicableContext(); boolean applicable = context.getApplicableProjects().contains(project.getPath()); projectsStates.put(project, applicable); } view.setProjects(projectsStates); }
@Override public boolean isDirty() { if (editedCommand == null) { return false; } ApplicableContext context = editedCommand.getApplicableContext(); return !(applicableProjectsInitial.equals(context.getApplicableProjects())); }
/** Creates copy of the given {@code context}. */ public ApplicableContext(ApplicableContext context) { this(context.isWorkspaceApplicable(), new HashSet<>(context.getApplicableProjects())); }
if (!context.isWorkspaceApplicable() && context.getApplicableProjects().isEmpty()) { return promiseProvider.reject( new Exception("Command has to be applicable to the workspace or at least one project")); for (final String projectPath : context.getApplicableProjects()) { final Project project = getProjectByPath(projectPath);
/** Removes the command without notifying listeners. */ private Promise<Void> doRemoveCommand(String name) { final CommandImpl command = commands.get(name); if (command == null) { return promiseProvider.reject(new Exception("Command '" + name + "' does not exist.")); } final ApplicableContext context = command.getApplicableContext(); final ArrayOf<Promise<?>> commandPromises = Collections.arrayOf(); if (context.isWorkspaceApplicable()) { commandPromises.push(workspaceCommandManager.removeCommand(name)); } for (final String projectPath : context.getApplicableProjects()) { final Project project = getProjectByPath(projectPath); if (project == null) { continue; } commandPromises.push(projectCommandManager.removeCommand(project, name)); } return promiseProvider .all2(commandPromises) .then( (Function<ArrayOf<?>, Void>) arg -> { commands.remove(command.getName()); return null; }); }
@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(); }
/** Checks whether the given command is applicable to the current project. */ private boolean isCommandApplicableToCurrentProject(CommandImpl command) { final Set<String> applicableProjects = command.getApplicableContext().getApplicableProjects(); if (applicableProjects.isEmpty()) { return true; } final Resource currentResource = appContext.getResource(); if (currentResource != null) { final Project currentProject = currentResource.getProject(); if (currentProject != null) { return applicableProjects.contains(currentProject.getPath()); } } return false; }
@Override protected void initialize() { final ApplicableContext context = editedCommand.getApplicableContext(); applicableProjectsInitial = new HashSet<>(context.getApplicableProjects()); refreshProjects(); }