@Override public boolean isDirty() { if (editedCommand == null) { return false; } ApplicableContext context = editedCommand.getApplicableContext(); return !(applicableProjectsInitial.equals(context.getApplicableProjects())); }
@Override public int hashCode() { return Objects.hash(name, typeId, commandLine, getAttributes(), getApplicableContext()); }
@Override protected void initialize() { final ApplicableContext context = editedCommand.getApplicableContext(); applicableProjectsInitial = new HashSet<>(context.getApplicableProjects()); refreshProjects(); }
/** * {@inheritDoc} * * @see #equalsIgnoreContext(CommandImpl) */ @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof CommandImpl)) { return false; } CommandImpl other = (CommandImpl) o; return Objects.equals(getName(), other.getName()) && Objects.equals(typeId, other.typeId) && Objects.equals(commandLine, other.commandLine) && Objects.equals(getAttributes(), other.getAttributes()) && Objects.equals(getApplicableContext(), other.getApplicableContext()); }
/** 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); }
/** 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; }
/** Creates copy of the given {@code command}. */ public CommandImpl(CommandImpl command) { this( command.getName(), command.getCommandLine(), command.getType(), new HashMap<>(command.getAttributes()), new ApplicableContext(command.getApplicableContext())); }
@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(); }
if (projectCommand.equalsIgnoreContext(existedCommand)) { existedCommand .getApplicableContext() .addProject(project.getPath()); } else {
/** 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; }); }
final ApplicableContext context = command.getApplicableContext(); if (!context.isWorkspaceApplicable() && context.getApplicableProjects().isEmpty()) { return promiseProvider.reject( (Function<Void, CommandImpl>) aVoid -> { newCommand.getApplicableContext().setWorkspaceApplicable(true); return newCommand; }); (Function<CommandImpl, CommandImpl>) arg -> { newCommand.getApplicableContext().addProject(projectPath); return newCommand; });