Skip to content
This repository has been archived by the owner on Jan 15, 2020. It is now read-only.

Commit

Permalink
Refactoring, code cleanup, and minor bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldulca committed Sep 30, 2019
1 parent 2817d55 commit 65d1c32
Show file tree
Hide file tree
Showing 11 changed files with 551 additions and 488 deletions.
18 changes: 4 additions & 14 deletions client/packages/sprotty-client/src/features/change-bounds/edges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,12 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { Action, KeyListener, SModelRoot } from "sprotty/lib";
import { matchesKeystroke } from "sprotty/lib/utils/keyboard";
import { Action } from "sprotty/lib";

import { ElementAndRoutingPoints } from "../tools/change-bounds-tool";

export class SaveModelEdgesAction implements Action {
static readonly KIND = "saveModelEdges";
readonly kind = SaveModelEdgesAction.KIND;
export class ChangeRoutingPointsAction implements Action {
static readonly KIND = "changeRoutingPoints";
readonly kind = ChangeRoutingPointsAction.KIND;
constructor(public newRoutingPoints: ElementAndRoutingPoints[]) { }
}

export class SaveModelKeyboardListener extends KeyListener {
keyDown(element: SModelRoot, event: KeyboardEvent): Action[] {
if (matchesKeystroke(event, 'KeyS', 'ctrlCmd')) {
return [new SaveModelEdgesAction([])];
}
return [];
}
}
438 changes: 20 additions & 418 deletions client/packages/sprotty-client/src/features/tools/change-bounds-tool.ts

Large diffs are not rendered by default.

433 changes: 433 additions & 0 deletions client/packages/sprotty-client/src/features/tools/routing-handler.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions client/packages/sprotty-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export * from './features/tool-feedback/creation-tool-feedback';
export * from './features/tool-feedback/model';
export * from './features/tool-palette/tool-palette';
export * from './features/tools/change-bounds-tool';
export * from './features/tools/routing-handler';
export * from './features/tools/creation-tool';
export * from './features/tools/default-tools';
export * from './features/tools/delete-tool';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { IdentifiableRequestAction } from "../features/request-response/action-d
import { SaveModelAction } from "../features/save/save";
import { GlspRedoAction, GlspUndoAction } from "../features/undo-redo/model";
import { RequestMarkersAction } from "../features/validation/validate";
import { SaveModelEdgesAction } from "../features/change-bounds/edges";
import { ChangeRoutingPointsAction } from "../features/change-bounds/edges";

@injectable()
export class GLSPWebsocketDiagramServer extends DiagramServer {
Expand Down Expand Up @@ -100,7 +100,7 @@ export function registerDefaultGLSPServerActions(registry: ActionHandlerRegistry
registry.register(IdentifiableRequestAction.KIND, diagramServer);
registry.register(RequestMarkersAction.KIND, diagramServer);
registry.register(LayoutAction.KIND, diagramServer);
registry.register(SaveModelEdgesAction.KIND, diagramServer);
registry.register(ChangeRoutingPointsAction.KIND, diagramServer);

// Register an empty handler for SwitchEditMode, to avoid runtime exceptions.
// We don't want to support SwitchEditMode, but sprotty still sends some corresponding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static class Kind {
public static final String LAYOUT = "layout";
public static final String VALIDATE_LABEL_EDIT_ACTION = "validateLabelEdit";
public static final String SET_LABEL_EDIT_VALIDATION_RESULT_ACTION = "setLabelEditValidationResult";
public static final String SAVE_MODEL_EDGES = "saveModelEdges";
public static final String CHANGE_ROUTING_POINTS = "changeRoutingPoints";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*******************************************************************************
* 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
* http://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 com.eclipsesource.glsp.api.action.kind;

import java.util.List;

import com.eclipsesource.glsp.api.action.Action;
import com.eclipsesource.glsp.api.model.ElementAndRoutingPoints;

public class ChangeRoutingPointsAction extends Action{

private List<ElementAndRoutingPoints> newRoutingPoints;

public ChangeRoutingPointsAction() {
super(Action.Kind.CHANGE_ROUTING_POINTS);
}

public ChangeRoutingPointsAction(List<ElementAndRoutingPoints> elementAndRoutingPoints) {
this();
this.newRoutingPoints = elementAndRoutingPoints;
}

public List<ElementAndRoutingPoints> getNewRoutingPoints() {
return newRoutingPoints;
}

public void setNewRoutingPoints(List<ElementAndRoutingPoints> newRoutingPoints) {
this.newRoutingPoints = newRoutingPoints;
}

@Override
public String toString() {
return "ChangeRoutingPointsAction [newRoutingPoints=" + newRoutingPoints + "]";
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*******************************************************************************
* 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
* http://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 com.eclipsesource.glsp.api.model;

import java.util.List;
Expand All @@ -9,10 +24,8 @@ public class ElementAndRoutingPoints {
private String elementId;
private List<GPoint> routingPoints;


public String getElementId() {
return elementId;

return elementId;
}
public void setElementId(String elementId) {
this.elementId = elementId;
Expand Down Expand Up @@ -56,9 +69,4 @@ public boolean equals(Object obj) {
return false;
return true;
}





}
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*******************************************************************************
* 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
* http://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 com.eclipsesource.glsp.server.actionhandler;

import java.util.List;
Expand All @@ -7,7 +22,7 @@
import org.eclipse.emf.common.util.EList;

import com.eclipsesource.glsp.api.action.Action;
import com.eclipsesource.glsp.api.action.kind.SaveModelEdgesAction;
import com.eclipsesource.glsp.api.action.kind.ChangeRoutingPointsAction;
import com.eclipsesource.glsp.api.model.ElementAndRoutingPoints;
import com.eclipsesource.glsp.api.model.GraphicalModelState;
import com.eclipsesource.glsp.graph.GEdge;
Expand All @@ -24,12 +39,12 @@ public class SaveModelEdgesHandler extends AbstractActionHandler{

@Override
public boolean handles(Action action) {
return action instanceof SaveModelEdgesAction;
return action instanceof ChangeRoutingPointsAction;
}
@Override
protected Optional<Action> execute(Action action, GraphicalModelState modelState) {

SaveModelEdgesAction saveModelEdgesAction = (SaveModelEdgesAction)action;
ChangeRoutingPointsAction saveModelEdgesAction = (ChangeRoutingPointsAction)action;
List<ElementAndRoutingPoints> elementAndRoutingPointsList = saveModelEdgesAction.getNewRoutingPoints();
for(ElementAndRoutingPoints elementAndRoutingPoints : elementAndRoutingPointsList) {
Optional<GModelElement> modelElement = modelState.getIndex().get(elementAndRoutingPoints.getElementId());
Expand All @@ -38,9 +53,7 @@ protected Optional<Action> execute(Action action, GraphicalModelState modelState
EList<GPoint> routingPoints = edge.getRoutingPoints();
routingPoints.clear();
routingPoints.addAll(elementAndRoutingPoints.getRoutingPoints());

}

}
return modelSubmissionHandler.doSubmitModel(true, modelState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Set;

import com.eclipsesource.glsp.api.action.Action;
import com.eclipsesource.glsp.api.action.kind.ApplyLabelEditOperationAction;
import com.eclipsesource.glsp.api.action.kind.CenterAction;
import com.eclipsesource.glsp.api.action.kind.ChangeBoundsOperationAction;
import com.eclipsesource.glsp.api.action.kind.ChangeContainerOperationAction;
Expand Down Expand Up @@ -47,18 +48,20 @@
import com.eclipsesource.glsp.api.action.kind.RequestTypeHintsAction;
import com.eclipsesource.glsp.api.action.kind.RerouteConnectionOperationAction;
import com.eclipsesource.glsp.api.action.kind.SaveModelAction;
import com.eclipsesource.glsp.api.action.kind.SaveModelEdgesAction;
import com.eclipsesource.glsp.api.action.kind.ChangeRoutingPointsAction;
import com.eclipsesource.glsp.api.action.kind.SelectAction;
import com.eclipsesource.glsp.api.action.kind.SelectAllAction;
import com.eclipsesource.glsp.api.action.kind.ServerStatusAction;
import com.eclipsesource.glsp.api.action.kind.SetBoundsAction;
import com.eclipsesource.glsp.api.action.kind.SetEditLabelValidationResultAction;
import com.eclipsesource.glsp.api.action.kind.SetLayersAction;
import com.eclipsesource.glsp.api.action.kind.SetModelAction;
import com.eclipsesource.glsp.api.action.kind.SetOperationsAction;
import com.eclipsesource.glsp.api.action.kind.SetPopupModelAction;
import com.eclipsesource.glsp.api.action.kind.ToogleLayerAction;
import com.eclipsesource.glsp.api.action.kind.UndoAction;
import com.eclipsesource.glsp.api.action.kind.UpdateModelAction;
import com.eclipsesource.glsp.api.action.kind.ValidateLabelEditAction;
import com.eclipsesource.glsp.api.provider.ActionProvider;

public class DefaultActionProvider implements ActionProvider {
Expand All @@ -70,7 +73,8 @@ public DefaultActionProvider() {
}

private void addDefaultActions() {
defaultActions.add(new SaveModelEdgesAction());
defaultActions.add(new ApplyLabelEditOperationAction());
defaultActions.add(new ChangeRoutingPointsAction());
defaultActions.add(new CenterAction());
defaultActions.add(new ChangeBoundsOperationAction());
defaultActions.add(new CollapseExpandAction());
Expand Down Expand Up @@ -102,6 +106,7 @@ private void addDefaultActions() {
defaultActions.add(new SetModelAction());
defaultActions.add(new SetOperationsAction());
defaultActions.add(new SetPopupModelAction());
defaultActions.add(new SetEditLabelValidationResultAction());
defaultActions.add(new ToogleLayerAction());
defaultActions.add(new UpdateModelAction());
defaultActions.add(new ExecuteServerCommandAction());
Expand All @@ -110,6 +115,7 @@ private void addDefaultActions() {
defaultActions.add(new ReconnectConnectionOperationAction());
defaultActions.add(new RerouteConnectionOperationAction());
defaultActions.add(new LayoutAction());
defaultActions.add(new ValidateLabelEditAction());
}

@Override
Expand Down

0 comments on commit 65d1c32

Please sign in to comment.