blob: 10ee1ddbec2c7663a108dbb66e9df3fb3778a7ba [file] [log] [blame]
/*********************************************************************
* Copyright (c) 2005, 2019 SAP SE
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Contributors:
* SAP SE - initial API, implementation and documentation
* Bug 336488 - DiagramEditor API
* pjpaulin - Bug 352120 - Now uses IDiagramContainerUI interface
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.graphiti.ui.internal.action;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.graphiti.features.context.ICustomContext;
import org.eclipse.graphiti.features.custom.ICustomFeature;
import org.eclipse.graphiti.internal.command.CommandContainer;
import org.eclipse.graphiti.internal.command.GenericFeatureCommandWithContext;
import org.eclipse.graphiti.internal.command.ICommand;
import org.eclipse.graphiti.ui.editor.DiagramBehavior;
import org.eclipse.graphiti.ui.internal.command.GefCommandWrapper;
import org.eclipse.jface.action.Action;
/**
* @noinstantiate This class is not intended to be instantiated by clients.
* @noextend This class is not intended to be subclassed by clients.
*/
public class CustomAction extends Action {
private ICustomFeature customFeature;
private ICustomContext context;
private DiagramBehavior diagramBehavior;
public CustomAction(ICustomFeature customFeature, ICustomContext context, DiagramBehavior diagramBehavior) {
super();
this.customFeature = customFeature;
this.context = context;
this.diagramBehavior = diagramBehavior;
setText(customFeature.getName());
setToolTipText(customFeature.getDescription());
}
@Override
public boolean isEnabled() {
return customFeature.canExecute(context);
}
@Override
public void run() {
CommandContainer commandContainer = new CommandContainer(customFeature.getFeatureProvider());
commandContainer.add(new GenericFeatureCommandWithContext(customFeature, context));
executeOnCommandStack(commandContainer);
}
protected void executeOnCommandStack(ICommand command) {
CommandStack commandStack = diagramBehavior.getEditDomain().getCommandStack();
commandStack.execute(new GefCommandWrapper(command, diagramBehavior.getEditingDomain()));
}
}