-
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.
Centralize model loading and GModel creation (#96)
* Centralize model loading and GModel creation Fixes eclipse-glsp/glsp#119 * Update copyright * Make fields protected
- Loading branch information
Showing
14 changed files
with
222 additions
and
180 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
47 changes: 0 additions & 47 deletions
47
...sp.example.workflow/src/org/eclipse/glsp/example/workflow/model/WorkflowModelFactory.java
This file was deleted.
Oops, something went wrong.
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
69 changes: 69 additions & 0 deletions
69
...rg.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/GModelFactory.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,69 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019-2020 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.core.model; | ||
|
||
import org.eclipse.glsp.graph.GModelIndex; | ||
import org.eclipse.glsp.graph.GModelRoot; | ||
import org.eclipse.glsp.server.actions.ActionHandler; | ||
import org.eclipse.glsp.server.model.GModelState; | ||
import org.eclipse.glsp.server.operations.OperationHandler; | ||
|
||
/** | ||
* A graph model factory produces a graph model from the model state; typically its contained source model. | ||
* <p> | ||
* The responsibility of a {@link GModelFactory} implementation is to define how a {@link GModelState} is to be | ||
* translated into a {@link GModelRoot} that is sent to the client for rendering. Before a {@link GModelFactory} | ||
* is invoked, the {@link ModelSourceLoader} has already been executed for loading the source model into the | ||
* {@link GModelState}. The {@link GModelFactory} then produces the {@link GModelRoot} from the source model in the | ||
* {@link GModelState}. Implementations of {@link GModelFactory} are usually specific to the type of source model, as | ||
* they need to understand the source model in order to translate it into a graph model. | ||
* </p> | ||
* <p> | ||
* The graph model factory is invoked after initial load of the source model and after each operation that is applied | ||
* to the source model by an {@link OperationHandler} in order to update the graph model before sending it to the client | ||
* for rendering. | ||
* </p> | ||
* <p> | ||
* If an index is needed for mapping between the graph model and the source model, as is typically the case for | ||
* {@link ActionHandler action handlers} and {@link OperationHandler operation handlers}, it is the responsibility of | ||
* the graph model factory to create such an index while producing the graph model from the source model. The index | ||
* shall be put into the model state too. Typically the {@link GModelIndex} is extended for a particular model source | ||
* type as well. | ||
* </p> | ||
* | ||
* @see ModelSourceLoader | ||
* @see GModelIndex | ||
*/ | ||
public interface GModelFactory { | ||
/** | ||
* Create a {@link GModelRoot} from the specified <code>modelState</code> and puts it into the | ||
* <code>modelState</code>. Optionally, this step also produces and sets a {@link GModelIndex} in the model state | ||
* that allows mapping from graph model elements to source model elements and vice versa. | ||
* | ||
* @param modelState The model state into which the created graph model and index shall be put. | ||
*/ | ||
void createGModel(GModelState modelState); | ||
|
||
/** | ||
* Graph model factory to be used if the graph model is already available from the model source. | ||
*/ | ||
final class NullImpl implements GModelFactory { | ||
@Override | ||
public void createGModel(final GModelState modelState) { | ||
// noop | ||
} | ||
} | ||
} |
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
34 changes: 0 additions & 34 deletions
34
...org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ModelFactory.java
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
...clipse.glsp.server/src/org/eclipse/glsp/server/features/core/model/ModelSourceLoader.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,43 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2020 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.core.model; | ||
|
||
import org.eclipse.glsp.server.model.GModelState; | ||
import org.eclipse.glsp.server.utils.ClientOptions; | ||
|
||
/** | ||
* A source model loader loads models into the model state. | ||
* <p> | ||
* A <i>source model</i> is an arbitrary model from which the graph model of the diagram is to be created. | ||
* Implementations of source model loaders are specific to the type of source model or persistence format that is used | ||
* for a type of source model. A source model loader obtains the information on which source model shall loaded from a | ||
* {@link RequestModelAction}; typically its client options. Once the source model is loaded, a model loader is expected | ||
* to put the loaded source model into the model state for further processing, such as transforming the loaded model | ||
* into a graph model (see {@link GModelFactory}). | ||
* </p> | ||
* | ||
* @see ClientOptions | ||
* @see GModelFactory | ||
*/ | ||
public interface ModelSourceLoader { | ||
/** | ||
* Loads a source model into the <code>modelState</code>. | ||
* | ||
* @param action Action sent by the client to specifying the information needed to load the source model. | ||
* @param modelState The model state into which the source model shall be put. | ||
*/ | ||
void loadSourceModel(RequestModelAction action, GModelState modelState); | ||
} |
Oops, something went wrong.