Package org.eclipse.bpmn2.modeler.ui.features.lane

Source Code of org.eclipse.bpmn2.modeler.ui.features.lane.CreateLaneFeature

/*******************************************************************************
* Copyright (c) 2011 Red Hat, Inc.
*  All rights reserved.
* This program is 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:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.eclipse.bpmn2.modeler.ui.features.lane;

import java.io.IOException;

import org.eclipse.bpmn2.Lane;
import org.eclipse.bpmn2.modeler.core.Activator;
import org.eclipse.bpmn2.modeler.core.ModelHandler;
import org.eclipse.bpmn2.modeler.core.ModelHandlerLocator;
import org.eclipse.bpmn2.modeler.core.utils.FeatureSupport;
import org.eclipse.bpmn2.modeler.ui.ImageProvider;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICreateContext;
import org.eclipse.graphiti.features.impl.AbstractCreateFeature;

public class CreateLaneFeature extends AbstractCreateFeature {

  private static int index = 1;

  public CreateLaneFeature(IFeatureProvider fp) {
    super(fp, "Lane", "A sub-partition in a process that helps to organize and categorize activities");
  }

  @Override
  public boolean canCreate(ICreateContext context) {
    boolean intoDiagram = context.getTargetContainer().equals(getDiagram());
    boolean intoLane = FeatureSupport.isTargetLane(context);
    boolean intoParticipant = FeatureSupport.isTargetParticipant(context);
    boolean intoSubProcess = FeatureSupport.isTargetSubProcess(context);
    return intoDiagram || intoLane || intoParticipant || intoSubProcess;
  }

  @Override
  public Object[] create(ICreateContext context) {
    Lane lane = null;
    try {
      ModelHandler mh = ModelHandlerLocator.getModelHandler(getDiagram().eResource());
      Object o = getBusinessObjectForPictogramElement(context.getTargetContainer());
      if (FeatureSupport.isTargetLane(context)) {
        Lane targetLane = (Lane) o;
        lane = mh.createLane(targetLane);
      } else {
        lane = mh.createLane(o);
      }
      lane.setName("Lane nr " + index++);
    } catch (IOException e) {
      Activator.logError(e);
    }
    addGraphicalRepresentation(context, lane);
    return new Object[] { lane };
  }

  @Override
  public String getCreateImageId() {
    return ImageProvider.IMG_16_LANE;
  }

  @Override
  public String getCreateLargeImageId() {
    return getCreateImageId(); // FIXME
  }
}
TOP

Related Classes of org.eclipse.bpmn2.modeler.ui.features.lane.CreateLaneFeature

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.