diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/ClientActionForwarder.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/ClientActionForwarder.java index 94696cdb..83861998 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/ClientActionForwarder.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/ClientActionForwarder.java @@ -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; @@ -39,29 +37,22 @@ public class ClientActionForwarder { @Inject protected Provider client; - @Inject - protected GModelState modelState; - @Inject @ClientId protected String clientId; - @Inject - @DiagramType - protected String diagramType; - @Inject @Named(CLIENT_ACTIONS) protected Set 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)) { diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/ServerMessageAction.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/MessageAction.java similarity index 75% rename from plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/ServerMessageAction.java rename to plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/MessageAction.java index 274fd7ae..a7c3580c 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/ServerMessageAction.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/MessageAction.java @@ -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; diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/ServerStatusAction.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/StatusAction.java similarity index 74% rename from plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/ServerStatusAction.java rename to plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/StatusAction.java index 067c3e0f..f136e45f 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/ServerStatusAction.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/StatusAction.java @@ -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 @@ -15,14 +15,13 @@ ******************************************************************************/ 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; @@ -30,22 +29,18 @@ public class ServerStatusAction extends Action { 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; } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/RequestModelActionHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/RequestModelActionHandler.java index fafdf4e2..c99f372c 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/RequestModelActionHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/RequestModelActionHandler.java @@ -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; @@ -79,6 +82,8 @@ public List 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); } @@ -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(); } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/OperationActionHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/OperationActionHandler.java index 30b0d059..82a12d80 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/OperationActionHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/OperationActionHandler.java @@ -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; @@ -47,7 +47,7 @@ public boolean handles(final Action action) { @Override public List 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); diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/protocol/DefaultGLSPServer.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/protocol/DefaultGLSPServer.java index 9c96df3e..e6a25ab6 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/protocol/DefaultGLSPServer.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/protocol/DefaultGLSPServer.java @@ -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; diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/types/ServerStatus.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/types/ServerStatus.java deleted file mode 100644 index 73be2d92..00000000 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/types/ServerStatus.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2019 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 - * https://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the Eclipse - * Public License v. 2.0 are satisfied: GNU General Public License, version 2 - * with the GNU Classpath Exception which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - ******************************************************************************/ -package org.eclipse.glsp.server.types; - -public class ServerStatus { - private final Severity severity; - private final String message; - private String details; - - public ServerStatus(final Severity severity, final String message) { - super(); - this.severity = severity; - this.message = message; - } - - public ServerStatus(final Severity severity, final String message, final String details) { - this(severity, message); - this.details = details; - } - - public String getMessage() { return message; } - - public Severity getSeverity() { return severity; } - - public String getDetails() { return details; } -} diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/ServerMessageUtil.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/MessageActionUtil.java similarity index 63% rename from plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/ServerMessageUtil.java rename to plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/MessageActionUtil.java index 7ee2357c..0972b681 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/ServerMessageUtil.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/MessageActionUtil.java @@ -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) { diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/ServerStatusUtil.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/ServerStatusUtil.java deleted file mode 100644 index fdd5705d..00000000 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/ServerStatusUtil.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2019-2021 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 - * https://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the Eclipse - * Public License v. 2.0 are satisfied: GNU General Public License, version 2 - * with the GNU Classpath Exception which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - ******************************************************************************/ -package org.eclipse.glsp.server.utils; - -import org.eclipse.glsp.server.actions.ServerStatusAction; -import org.eclipse.glsp.server.types.Severity; - -/** - * Utility methods to simplify the creation of {@link ServerStatusAction}s. - */ -public final class ServerStatusUtil { - private ServerStatusUtil() {} - - public static ServerStatusAction status(final Severity severity, final String message) { - return new ServerStatusAction(severity, message); - } - - public static ServerStatusAction info(final String message) { - return new ServerStatusAction(Severity.INFO, message); - } - - public static ServerStatusAction warn(final String message) { - return new ServerStatusAction(Severity.WARNING, message); - } - - public static ServerStatusAction error(final String message) { - return new ServerStatusAction(Severity.ERROR, message); - } - - public static ServerStatusAction status(final Severity severity, final String message, - final int timeout) { - return new ServerStatusAction(severity, message, timeout); - } - - public static ServerStatusAction info(final String message, final int timeout) { - return new ServerStatusAction(Severity.INFO, message, timeout); - } - - public static ServerStatusAction warn(final String message, final int timeout) { - return new ServerStatusAction(Severity.WARNING, message, timeout); - } - - public static ServerStatusAction error(final String message, final int timeout) { - return new ServerStatusAction(Severity.ERROR, message, timeout); - } - - public static ServerStatusAction clear() { - return new ServerStatusAction(Severity.NONE, ""); - } -} diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/StatusActionUtil.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/StatusActionUtil.java new file mode 100644 index 00000000..32a0446f --- /dev/null +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/StatusActionUtil.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * 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 + * https://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ******************************************************************************/ +package org.eclipse.glsp.server.utils; + +import org.eclipse.glsp.server.actions.StatusAction; +import org.eclipse.glsp.server.types.Severity; + +/** + * Utility methods to simplify the creation of {@link StatusAction}s. + */ +public final class StatusActionUtil { + private StatusActionUtil() {} + + public static StatusAction status(final Severity severity, final String message) { + return new StatusAction(severity, message); + } + + public static StatusAction info(final String message) { + return new StatusAction(Severity.INFO, message); + } + + public static StatusAction warn(final String message) { + return new StatusAction(Severity.WARNING, message); + } + + public static StatusAction error(final String message) { + return new StatusAction(Severity.ERROR, message); + } + + public static StatusAction status(final Severity severity, final String message, + final int timeout) { + return new StatusAction(severity, message, timeout); + } + + public static StatusAction info(final String message, final int timeout) { + return new StatusAction(Severity.INFO, message, timeout); + } + + public static StatusAction warn(final String message, final int timeout) { + return new StatusAction(Severity.WARNING, message, timeout); + } + + public static StatusAction error(final String message, final int timeout) { + return new StatusAction(Severity.ERROR, message, timeout); + } + + public static StatusAction clear() { + return new StatusAction(Severity.NONE, ""); + } +}