org.eclipse.glsp.server.emf.EMFCreateOperationHandler Maven / Gradle / Ivy
The newest version!
/********************************************************************************
* 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.emf;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.eclipse.glsp.server.actions.ActionDispatcher;
import org.eclipse.glsp.server.actions.GhostElement;
import org.eclipse.glsp.server.actions.TriggerElementCreationAction;
import org.eclipse.glsp.server.actions.TriggerNodeCreationAction;
import org.eclipse.glsp.server.operations.CreateNodeOperation;
import org.eclipse.glsp.server.operations.CreateOperation;
import org.eclipse.glsp.server.operations.CreateOperationHandler;
import com.google.common.collect.Lists;
import com.google.inject.Inject;
public abstract class EMFCreateOperationHandler
extends EMFOperationHandler implements CreateOperationHandler {
@Inject
protected ActionDispatcher actionDispatcher;
protected List handledElementTypeIds;
public EMFCreateOperationHandler(final String... elementTypeIds) {
this(Lists.newArrayList(elementTypeIds));
}
public EMFCreateOperationHandler(final List handledElementTypeIds) {
this.handledElementTypeIds = handledElementTypeIds;
}
@Override
public List getHandledElementTypeIds() { return handledElementTypeIds; }
public void setHandledElementTypeIds(final List handledElementTypeIds) {
this.handledElementTypeIds = handledElementTypeIds;
}
@Override
public List getTriggerActions() {
if (CreateNodeOperation.class.isAssignableFrom(getHandledOperationType())) {
return getHandledElementTypeIds().stream().map(this::createTriggerNodeCreationAction)
.collect(Collectors.toList());
}
return CreateOperationHandler.super.getTriggerActions();
}
protected TriggerNodeCreationAction createTriggerNodeCreationAction(final String elementTypeId) {
return new TriggerNodeCreationAction(elementTypeId,
createTriggerArgs(elementTypeId),
createTriggerGhostElement(elementTypeId));
}
protected GhostElement createTriggerGhostElement(final String elementTypeId) {
return null;
}
protected Map createTriggerArgs(final String elementTypeId) {
return null;
}
}