Skip to content

Commit

Permalink
Logging node click event (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
fantonangeli authored and caponetto committed May 18, 2022
1 parent abd7460 commit c07592b
Showing 1 changed file with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2022 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.kie.workbench.common.stunner.sw.client.editor;

import javax.enterprise.event.Observes;
import javax.inject.Singleton;

import elemental2.dom.DomGlobal;
import org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler;
import org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent;
import org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent;
import org.kie.workbench.common.stunner.core.graph.Node;
import org.kie.workbench.common.stunner.core.graph.content.view.View;
import org.kie.workbench.common.stunner.sw.definition.State;

@Singleton
public class ShapeEventsHandler {

void onCanvasSelectionEvent(@Observes CanvasSelectionEvent event) {
if (null != event.getCanvasHandler()) {
if (event.getIdentifiers().size() == 1) {
final String uuid = event.getIdentifiers().iterator().next();
String stateName = obtainStateName(event.getCanvasHandler(), uuid);
// TODO: This stateName is what you have to send to the multiplyach...
DomGlobal.console.log("Selected state with name = " + stateName);
}
}
}

private String obtainStateName(CanvasHandler<?,?> handler, String uuid) {
Node<?,?> node = handler.getDiagram().getGraph().getNode(uuid);
Object content = node.getContent();
if (content instanceof View) {
Object bean = ((View) content).getDefinition();
if (bean instanceof State) {
return ((State)bean).name;
}
}
return null;
}

void onCanvasClearSelectionEvent(@Observes CanvasClearSelectionEvent event) {
if (null != event.getCanvasHandler()) {
// TODO: Selection is cleard, nothing selected
}
}

}

0 comments on commit c07592b

Please sign in to comment.