Skip to content

Commit

Permalink
GLSP-1071: Rename ServerStatus/ServerMessage action
Browse files Browse the repository at this point in the history
Also remove unused `ServerStatus` class
Part of eclipse-glsp/glsp#1071
  • Loading branch information
tortmayr committed Sep 15, 2023
1 parent 9e41d4a commit 1323e76
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import java.util.Set;

import org.eclipse.glsp.server.di.ClientId;
import org.eclipse.glsp.server.di.DiagramType;
import org.eclipse.glsp.server.model.GModelState;
import org.eclipse.glsp.server.protocol.GLSPClient;

import com.google.inject.Inject;
Expand All @@ -39,29 +37,22 @@ public class ClientActionForwarder {
@Inject
protected Provider<GLSPClient> client;

@Inject
protected GModelState modelState;

@Inject
@ClientId
protected String clientId;

@Inject
@DiagramType
protected String diagramType;

@Inject
@Named(CLIENT_ACTIONS)
protected Set<String> clientActionKinds;

/**
* Processes the given action and checks wether it is a
* `clientAction` i.e. andaction that should be forwared to
* `clientAction` i.e. an action that should be forwarded to
* the client to be handled there. If the check is successful
* the action is wrapped in an {@link ActionMessage} and sent to the client.
*
* @param action The action to check and forward
* @return `true` if the action was forwared to the client, `false` otherwise
* @return `true` if the action was forwarded to the client, `false` otherwise
*/
public boolean handle(final Action action) {
if (shouldForwardToClient(action)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,28 @@

import java.util.Optional;

import org.eclipse.glsp.server.types.ServerStatus;
import org.eclipse.glsp.server.types.Severity;

/**
* Instructs the client to show a notification message to the user.
*/
public class ServerMessageAction extends Action {
public class MessageAction extends Action {

public static final String KIND = "serverMessage";
public static final String KIND = "message";

private String severity;
private String message;
private String details;

public ServerMessageAction() {
public MessageAction() {
super(KIND);
}

public ServerMessageAction(final Severity severity, final String message) {
public MessageAction(final Severity severity, final String message) {
this(severity, message, null);
}

public ServerMessageAction(final ServerStatus status) {
this(status.getSeverity(), status.getMessage(), status.getDetails());
}

public ServerMessageAction(final Severity severity, final String message, final String details) {
public MessageAction(final Severity severity, final String message, final String details) {
this();
this.severity = Severity.toString(severity);
this.message = message;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019-2022 EclipseSource and others.
* Copyright (c) 2019-2023 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -15,37 +15,32 @@
******************************************************************************/
package org.eclipse.glsp.server.actions;

import org.eclipse.glsp.server.types.ServerStatus;
import org.eclipse.glsp.server.types.Severity;

/**
* Sent by the server to the client to notify it about a server status.
*/
public class ServerStatusAction extends Action {
public static final String KIND = "serverStatus";
public class StatusAction extends Action {
public static final String KIND = "status";
private static final int NO_TIMEOUT = -1;

private int timeout;

private String severity;
private String message;

public ServerStatusAction() {
public StatusAction() {
super(KIND);
}

public ServerStatusAction(final ServerStatus status) {
this(status.getSeverity(), status.getMessage());
}

public ServerStatusAction(final Severity severity, final String message) {
public StatusAction(final Severity severity, final String message) {
this();
this.severity = Severity.toString(severity);
this.message = message;
this.timeout = NO_TIMEOUT;
}

public ServerStatusAction(final Severity severity, final String message, final int timeout) {
public StatusAction(final Severity severity, final String message, final int timeout) {
this(severity, message);
this.timeout = timeout;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
import org.eclipse.glsp.server.actions.AbstractActionHandler;
import org.eclipse.glsp.server.actions.Action;
import org.eclipse.glsp.server.actions.ActionDispatcher;
import org.eclipse.glsp.server.actions.MessageAction;
import org.eclipse.glsp.server.actions.StatusAction;
import org.eclipse.glsp.server.di.DiagramModule;
import org.eclipse.glsp.server.features.progress.ProgressMonitor;
import org.eclipse.glsp.server.features.progress.ProgressService;
import org.eclipse.glsp.server.features.sourcemodelwatcher.SourceModelWatcher;
import org.eclipse.glsp.server.model.GModelState;
import org.eclipse.glsp.server.types.Severity;
import org.eclipse.glsp.server.utils.ClientOptionsUtil;
import org.eclipse.glsp.server.utils.ServerStatusUtil;
import org.eclipse.glsp.server.utils.StatusActionUtil;

import com.google.inject.Inject;

Expand Down Expand Up @@ -79,6 +82,8 @@ public List<Action> executeAction(final RequestModelAction action) {
if (!isReconnecting) {
sourceModelWatcher.ifPresent(watcher -> watcher.startWatching());
}
this.actionDispatcher.dispatch(new StatusAction(Severity.WARNING, "foo"));
this.actionDispatcher.dispatch(new MessageAction(Severity.WARNING, "foo"));

return modelSubmissionHandler.submitInitialModel(action);
}
Expand All @@ -96,12 +101,12 @@ protected void handleReconnect(final RequestModelAction action) {

protected ProgressMonitor notifyStartLoading() {
String message = "Model loading in progress";
actionDispatcher.dispatch(ServerStatusUtil.info(message));
actionDispatcher.dispatch(StatusActionUtil.info(message));
return progressService.start(message);
}

protected void notifyFinishedLoading(final ProgressMonitor monitor) {
actionDispatcher.dispatch(ServerStatusUtil.clear());
actionDispatcher.dispatch(StatusActionUtil.clear());
monitor.end();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.eclipse.glsp.server.actions.SetDirtyStateAction;
import org.eclipse.glsp.server.features.core.model.ModelSubmissionHandler;
import org.eclipse.glsp.server.model.GModelState;
import org.eclipse.glsp.server.utils.ServerMessageUtil;
import org.eclipse.glsp.server.utils.MessageActionUtil;

import com.google.inject.Inject;

Expand All @@ -47,7 +47,7 @@ public boolean handles(final Action action) {
@Override
public List<Action> executeAction(final Operation operation) {
if (modelState.isReadonly()) {
return listOf(ServerMessageUtil
return listOf(MessageActionUtil
.warn("Server is in readonly-mode! Could not execute operation: " + operation.getKind()));
}
return executeOperation(operation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
********************************************************************************/
package org.eclipse.glsp.server.protocol;

import static org.eclipse.glsp.server.utils.ServerMessageUtil.error;
import static org.eclipse.glsp.server.utils.MessageActionUtil.error;

import java.util.HashMap;
import java.util.LinkedHashSet;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,44 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.glsp.server.actions.ServerMessageAction;
import org.eclipse.glsp.server.actions.MessageAction;
import org.eclipse.glsp.server.types.Severity;

public final class ServerMessageUtil {
private static Logger LOGGER = LogManager.getLogger(ServerMessageUtil.class);
public final class MessageActionUtil {
private static Logger LOGGER = LogManager.getLogger(MessageActionUtil.class);

private ServerMessageUtil() {}
private MessageActionUtil() {}

public static ServerMessageAction message(final Severity severity, final String message) {
return new ServerMessageAction(severity, message);
public static MessageAction message(final Severity severity, final String message) {
return new MessageAction(severity, message);
}

public static ServerMessageAction info(final String message) {
return new ServerMessageAction(Severity.INFO, message);
public static MessageAction info(final String message) {
return new MessageAction(Severity.INFO, message);
}

public static ServerMessageAction warn(final String message) {
return new ServerMessageAction(Severity.WARNING, message);
public static MessageAction warn(final String message) {
return new MessageAction(Severity.WARNING, message);
}

public static ServerMessageAction error(final String message) {
return new ServerMessageAction(Severity.ERROR, message);
public static MessageAction error(final String message) {
return new MessageAction(Severity.ERROR, message);
}

public static ServerMessageAction error(final String message, final String details) {
return new ServerMessageAction(Severity.ERROR, message, details);
public static MessageAction error(final String message, final String details) {
return new MessageAction(Severity.ERROR, message, details);
}

public static ServerMessageAction error(final String message, final Throwable cause) {
return new ServerMessageAction(Severity.ERROR, message, getDetails(cause));
public static MessageAction error(final String message, final Throwable cause) {
return new MessageAction(Severity.ERROR, message, getDetails(cause));
}

public static ServerMessageAction error(final Exception e) {
public static MessageAction error(final Exception e) {
return error(getMessage(e), getDetails(e));
}

public static ServerMessageAction clear() {
return new ServerMessageAction(Severity.NONE, "");
public static MessageAction clear() {
return new MessageAction(Severity.NONE, "");
}

private static String getDetails(final Throwable throwable) {
Expand Down

This file was deleted.

Loading

0 comments on commit 1323e76

Please sign in to comment.