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 14, 2023
1 parent 525dd82 commit efa7901
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 148 deletions.
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.

Original file line number Diff line number Diff line change
@@ -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, "");
}
}

0 comments on commit efa7901

Please sign in to comment.