blob: 1927f93ef04603a754d843de1ded503093691725 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2005, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.bpel.ui.actions.editpart;
import org.eclipse.bpel.model.BPELPackage;
import org.eclipse.bpel.model.ElseIf;
import org.eclipse.bpel.model.If;
import org.eclipse.bpel.ui.BPELEditor;
import org.eclipse.bpel.ui.BPELUIPlugin;
import org.eclipse.bpel.ui.IBPELUIConstants;
import org.eclipse.bpel.ui.Messages;
import org.eclipse.bpel.ui.commands.CompoundCommand;
import org.eclipse.bpel.ui.commands.InsertInContainerCommand;
import org.eclipse.bpel.ui.commands.SetNameAndDirectEditCommand;
import org.eclipse.bpel.ui.factories.UIObjectFactoryProvider;
import org.eclipse.bpel.ui.util.ModelHelper;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
public class CreateElseIfAction extends AbstractAction {
public CreateElseIfAction(EditPart editPart) {
super(editPart);
}
public ImageDescriptor getIcon() {
return BPELUIPlugin.INSTANCE.getImageDescriptor(IBPELUIConstants.ICON_ACTION_CASE);
}
public Image getIconImg() {
return BPELUIPlugin.INSTANCE.getImage(IBPELUIConstants.ICON_ACTION_CASE);
}
public Image getImageIcon() {
return BPELUIPlugin.INSTANCE.getImage(IBPELUIConstants.ICON_ACTION_CASE);
}
public boolean onButtonPressed() {
CompoundCommand command = new CompoundCommand();
final ElseIf child = (ElseIf)UIObjectFactoryProvider.getInstance().getFactoryFor(
BPELPackage.eINSTANCE.getElseIf()).createInstance();
EObject before = null;
If ifObject = (If)modelObject;
if (ifObject.getElse()!=null)
before = ifObject.getElse();
command.add(new InsertInContainerCommand((EObject)modelObject, child, before));
command.add(new SetNameAndDirectEditCommand(child, viewer));
BPELEditor bpelEditor = ModelHelper.getBPELEditor(modelObject);
bpelEditor.getCommandStack().execute(command);
return true;
}
public String getToolTip() {
return Messages.CreateElseIfAction_Add_ElseIf_1;
}
@Override
public ImageDescriptor getDisabledIcon() { return ImageDescriptor.getMissingImageDescriptor(); }
@Override
public boolean isEnabled() { return true; }
}