-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GLSP-211: Revise TypeHints and server side feedback for creation actions
- Add a new parameter to EdgeTypeHint, 'dynamic', indicating that new edges need to check with the server before allowing creation - Make source/target element type ids in `EdgeTypeHint` optional If not defined, all potential element types are considered to be valid sources/targets - Add `RequestEdgeCheckAction` and `EdgeCheckResultAction` response to implement the dynamic check - Add a optional `EdegeCreationchecker` component that can be implemented by adopters to provide dynamic typehints - Adapt workflow example to use dynamic edge hints for weighted edges - Move typehints related components into feature subpackage - Move progress actions into progress feature subpackage Co-authored-by: Camille Letavernier <[email protected] >
- Loading branch information
1 parent
7f8495b
commit b2cb25f
Showing
19 changed files
with
448 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...workflow/src/org/eclipse/glsp/example/workflow/typehints/WorkflowEdgeCreationChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 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.example.workflow.typehints; | ||
|
||
import static org.eclipse.glsp.example.workflow.utils.ModelTypes.DECISION_NODE; | ||
import static org.eclipse.glsp.example.workflow.utils.ModelTypes.FORK_NODE; | ||
import static org.eclipse.glsp.example.workflow.utils.ModelTypes.JOIN_NODE; | ||
import static org.eclipse.glsp.example.workflow.utils.ModelTypes.WEIGHTED_EDGE; | ||
|
||
import org.eclipse.glsp.example.workflow.wfgraph.TaskNode; | ||
import org.eclipse.glsp.graph.GModelElement; | ||
import org.eclipse.glsp.server.features.typehints.EdegeCreationChecker; | ||
|
||
public class WorkflowEdgeCreationChecker implements EdegeCreationChecker { | ||
|
||
@Override | ||
public boolean isValidSource(final String edgeType, final GModelElement sourceElement) { | ||
return edgeType.equals(WEIGHTED_EDGE) && sourceElement.getType().equals(DECISION_NODE); | ||
} | ||
|
||
@Override | ||
public boolean isValidTarget(final String edgeType, final GModelElement sourceElement, | ||
final GModelElement targetElement) { | ||
|
||
if (!edgeType.equals(WEIGHTED_EDGE)) { | ||
return false; | ||
} | ||
String targetType = targetElement.getType(); | ||
return targetElement instanceof TaskNode || targetType.equals(FORK_NODE) | ||
|| targetType.equals(JOIN_NODE); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...sp.server/src/org/eclipse/glsp/server/features/typehints/CheckEdgeTargetResultAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 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.features.typehints; | ||
|
||
import java.util.Optional; | ||
|
||
import org.eclipse.glsp.server.actions.ResponseAction; | ||
|
||
/** | ||
* Response Action for a {@link RequestCheckEdgeAction}. It provides | ||
* a boolean indicating whether the requested element is a valid target | ||
* for the edge being created and the context edge context information (type, source, target). | ||
*/ | ||
public class CheckEdgeTargetResultAction extends ResponseAction { | ||
|
||
public static final String KIND = "checkEdgeResult"; | ||
|
||
/** | ||
* true if the selected element is a valid target for this edge, | ||
* false otherwise. | ||
*/ | ||
private boolean isValid; | ||
|
||
/** | ||
* The element type of the Edge that has been checked. | ||
*/ | ||
private String edgeType; | ||
|
||
/** | ||
* The ID of the source element of the edge that has been checked. | ||
*/ | ||
private String sourceElementId; | ||
/** | ||
* The ID of the target element of the edge that has been checked. | ||
*/ | ||
private String targetElementId; | ||
|
||
public CheckEdgeTargetResultAction() { | ||
super(KIND); | ||
} | ||
|
||
public CheckEdgeTargetResultAction(final boolean isValid, final RequestCheckEdgeAction requestAction) { | ||
super(KIND); | ||
this.setValid(isValid); | ||
this.setEdgeType(requestAction.getEdgeType()); | ||
this.setSourceElementId(requestAction.getSourceElementId()); | ||
this.setTargetElementId(requestAction.getTargetElementId().orElse(null)); | ||
} | ||
|
||
public String getEdgeType() { return edgeType; } | ||
|
||
public void setEdgeType(final String edgeType) { this.edgeType = edgeType; } | ||
|
||
public String getSourceElementId() { return sourceElementId; } | ||
|
||
public void setSourceElementId(final String sourceElementId) { this.sourceElementId = sourceElementId; } | ||
|
||
public Optional<String> getTargetElementId() { return Optional.ofNullable(this.targetElementId); } | ||
|
||
public void setTargetElementId(final String targetElementId) { this.targetElementId = targetElementId; } | ||
|
||
public boolean isValid() { return isValid; } | ||
|
||
public void setValid(final boolean isValid) { this.isValid = isValid; } | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...ipse.glsp.server/src/org/eclipse/glsp/server/features/typehints/EdegeCreationChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 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.features.typehints; | ||
|
||
import org.eclipse.glsp.graph.GModelElement; | ||
import org.eclipse.glsp.server.types.EdgeTypeHint; | ||
|
||
/** | ||
* Optional service used to check the validity of an edge being created. Used in combination with `dynamic` | ||
* {@link EdgeTypeHint}s. | ||
* A dynamic edge type hint is used for cases where a plain list of allowed source and target element ids is not enough | ||
* to determine | ||
* wether an edge beeing created is valid. In this cases the client will query the server to determine wether the edge | ||
* is valid. | ||
* The `EdegeCreationChecker` then checks the given edge information and returns wether the edge beeing created is | ||
* valid. | ||
* If no `EdgeTargetChecker` implementation is bound the creation of dynamic edge will always be rejected. | ||
* | ||
*/ | ||
public interface EdegeCreationChecker { | ||
/** | ||
* Checks wether the given source element for an edge beeing created is valid i.e. if the | ||
* given source is and allowed source element for the given edge type. | ||
* | ||
* @return `true` if the edge source is valid, `false` otherwise | ||
*/ | ||
boolean isValidSource(String edgeType, GModelElement sourceElement); | ||
|
||
/** | ||
* Checks wether the given information for an edge beeing created is valid i.e. if the | ||
* given target is an allowed target for the given source and edge type. | ||
* | ||
* @return `true` if the edge target is valid, `false` otherwise | ||
*/ | ||
boolean isValidTarget(String edgeType, GModelElement sourceElement, GModelElement targetElement); | ||
} |
Oops, something went wrong.