Skip to content

Commit

Permalink
CHE-5188: fix a bug with showing commands when a ws has started (ecli…
Browse files Browse the repository at this point in the history
  • Loading branch information
Valeriy Svydenko authored Jun 9, 2017
1 parent a5dec28 commit 1e9e912
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public interface CommandManager {
/** Returns all commands. */
List<CommandImpl> getCommands();

/** Fetches all commands related to the workspace. */
void fetchCommands();

/** Returns optional command by the specified name or {@link Optional#empty()} if none. */
Optional<CommandImpl> getCommand(String name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class CommandsExplorerPresenter extends BasePresenter implements Commands
private final AppContext appContext;
private final EventBus eventBus;

private boolean isFirstActivation;

@Inject
public CommandsExplorerPresenter(CommandsExplorerView view,
CommandResources commandResources,
Expand Down Expand Up @@ -109,6 +111,17 @@ public CommandsExplorerPresenter(CommandsExplorerView view,
view.setDelegate(this);
}

@Override
public void onOpen() {
super.onOpen();

if (isFirstActivation) {
commandManager.fetchCommands();
refreshView();
isFirstActivation = false;
}
}

@Override
public void start(Callback<WsAgentComponent, Exception> callback) {
callback.onSuccess(this);
Expand All @@ -126,6 +139,7 @@ public void start(Callback<WsAgentComponent, Exception> callback) {

@Override
public void go(AcceptsOneWidget container) {
isFirstActivation = true;
refreshView();

container.setWidget(getView());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,30 +100,45 @@ private void fetchCommands(Callback<WsAgentComponent, Exception> callback) {
workspaceCommands.forEach(workspaceCommand -> commands.put(workspaceCommand.getName(),
new CommandImpl(workspaceCommand, new ApplicableContext())));

// get all commands related to the projects
Arrays.stream(appContext.getProjects())
.forEach(project -> projectCommandManager.getCommands(project).forEach(projectCommand -> {
final CommandImpl existedCommand = commands.get(projectCommand.getName());

if (existedCommand == null) {
commands.put(projectCommand.getName(),
new CommandImpl(projectCommand, new ApplicableContext(project.getPath())));
} else {
if (projectCommand.equalsIgnoreContext(existedCommand)) {
existedCommand.getApplicableContext().addProject(project.getPath());
} else {
// normally, should never happen
Log.error(CommandManagerImpl.this.getClass(), "Different commands with the same names found");
}
}
}));
addCommands();

callback.onSuccess(this);

notifyCommandsLoaded();
});
}

public void fetchCommands() {
workspaceCommandManager.getCommands(appContext.getWorkspaceId()).then(workspaceCommands -> {
workspaceCommands.forEach(workspaceCommand -> commands.put(workspaceCommand.getName(),
new CommandImpl(workspaceCommand, new ApplicableContext())));

addCommands();

notifyCommandsLoaded();
});
}

private void addCommands() {
// get all commands related to the projects
Arrays.stream(appContext.getProjects())
.forEach(project -> projectCommandManager.getCommands(project).forEach(projectCommand -> {
final CommandImpl existedCommand = commands.get(projectCommand.getName());

if (existedCommand == null) {
commands.put(projectCommand.getName(),
new CommandImpl(projectCommand, new ApplicableContext(project.getPath())));
} else {
if (projectCommand.equalsIgnoreContext(existedCommand)) {
existedCommand.getApplicableContext().addProject(project.getPath());
} else {
// normally, should never happen
Log.error(CommandManagerImpl.this.getClass(), "Different commands with the same names found");
}
}
}));
}

@Override
public List<CommandImpl> getCommands() {
return commands.values()
Expand Down

0 comments on commit 1e9e912

Please sign in to comment.