@Override public Promise<CommandImpl> createCommand(String goalId, String typeId) { return createCommand(goalId, typeId, null, null, new HashMap<>(), new ApplicableContext()); }
/** Creates copy of the given {@code context}. */ public ApplicableContext(ApplicableContext context) { this(context.isWorkspaceApplicable(), new HashSet<>(context.getApplicableProjects())); }
/** 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; }
commands.put( workspaceCommand.getName(), new CommandImpl(workspaceCommand, new ApplicableContext()))); new CommandImpl( projectCommand, new ApplicableContext(project.getPath()))); } else { if (projectCommand.equalsIgnoreContext(existedCommand)) { existedCommand .getApplicableContext() .addProject(project.getPath()); } else {
if (!context.isWorkspaceApplicable() && context.getApplicableProjects().isEmpty()) { return promiseProvider.reject( new Exception("Command has to be applicable to the workspace or at least one project")); if (context.isWorkspaceApplicable()) { Promise<CommandImpl> p = workspaceCommandManager (Function<Void, CommandImpl>) aVoid -> { newCommand.getApplicableContext().setWorkspaceApplicable(true); return newCommand; }); for (final String projectPath : context.getApplicableProjects()) { final Project project = getProjectByPath(projectPath); (Function<CommandImpl, CommandImpl>) arg -> { newCommand.getApplicableContext().addProject(projectPath); return newCommand; });
/** 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(); }
private Promise<CommandImpl> addCommand(Project project, CommandDto commandDto) { final String name = project.getName() + ": " + commandDto.getName(); final String absoluteProjectPath = appContext.getProjectsRoot().append(project.getPath()).toString(); final String commandLine = commandDto.getCommandLine().replaceAll(PROJECT_PATH_MACRO_REGEX, absoluteProjectPath); final CommandImpl command = new CommandImpl( name, commandLine, commandDto.getType(), commandDto.getAttributes(), new ApplicableContext(project.getPath())); return commandManager.createCommand(command); }
/** 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(); }
/** Creates new {@link CommandImpl} based on the provided data. */ public CommandImpl( String name, String commandLine, String typeId, Map<String, String> attributes) { this.name = name; this.commandLine = commandLine; this.typeId = typeId; this.attributes = attributes; this.context = new ApplicableContext(); }
@Override public Promise<CommandImpl> createCommand( String goalId, String typeId, String name, String commandLine, Map<String, String> attributes) { return createCommand(goalId, typeId, name, commandLine, attributes, new ApplicableContext()); }
/** 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 boolean isDirty() { if (editedCommand == null) { return false; } ApplicableContext context = editedCommand.getApplicableContext(); return !(applicableProjectsInitial.equals(context.getApplicableProjects())); }
/** 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); }