private void drawDurationItem(
      final GanttRenderingData data, final IDuration d, final GanttDraw ganttDrawData) {
    final TaskLaneEntry taskFigure = lanes.get(d.getOwner().getName());

    // if task is filtered out
    if (taskFigure == null) {
      return;
    }
    final int y = LANE_START + taskFigure.getLane() * LANE_HEIGHT + DURATION_MARGIN;

    int xStart = ruler.toScreen(d.getStartTime()) - data.getBounds().x / 2;

    final Rectangle dataArea = getDataArea(data);
    dataArea.x = 0;
    if (xStart < dataArea.x) {
      xStart = dataArea.x;
    }
    int xEnd = ruler.toScreen(d.getStartTime() + d.getDurationTime()) - data.getBounds().x / 2;
    if (xEnd < dataArea.x) {
      return;
    }
    if (xEnd - xStart < 1) {
      xEnd = xStart + 1;
    }

    final Rectangle rect = new Rectangle(xStart, y, (xEnd - xStart), DURATION_HEIGHT);

    // If the rectangle width is enormous (when zooming a lot) the clipping
    // mechanism is not working, therefore limit the width below manually
    if (rect.width > dataArea.width) {
      rect.width = dataArea.width;
    }

    final ObjectFigure exec = new TaskExecution(d, rect);
    exec.setBackgroundColor(taskFigure.getBackgroundColor());

    doDrawEvents =
        SeUiPlugin.getDefault()
            .getPreferenceStore()
            .getBoolean(GanttPreferencePage.TAG_SHOW_EVENTS);
    if (doDrawEvents) {
      String idz =
          SeUiPlugin.getDefault()
              .getPreferenceStore()
              .getString(GanttPreferencePage.TAG_SHOW_EVENTS_IDS);
      if (typeReg != null && idz.length() > 0) {
        this.typeArray = idz.split(GanttPreferencePage.SEPARATOR);
      }
      if (typeArray != null && typeArray.length > 0) {
        drawLogEvents(data, d, ganttDrawData, y);
      }
    }
    ganttDrawData.add(exec);
  }
  @Override
  public void runSafe(final IAction action) {
    if (guardFail()) {
      return;
    }
    if (!(getSelection() instanceof IStructuredSelection)) {
      return;
    }
    final IStructuredSelection struct = (IStructuredSelection) getSelection();
    final Object firstElement = struct.getFirstElement();
    if (!(firstElement instanceof ArtifactSelection)) {
      return;
    }
    Object element = null;
    final ArtifactSelection artifactSelection = (ArtifactSelection) firstElement;
    element = artifactSelection.getItem();
    if (element instanceof IActivity) {
      final IActivity activity = (IActivity) element;
      element = activity.getOwner();
    } else if (element instanceof IDuration) {
      final IDuration abstractDuration = (IDuration) element;
      element = abstractDuration.getOwner();
    }

    if (!(element instanceof IArtifact) && !(element instanceof ILogEvent)) {
      return;
    }
    final ArtifactColorMap colorMap = artifactSelection.getSource().getLog().getColorMap();
    final ColorDialog dlg = new ColorDialog(Display.getDefault().getActiveShell());
    final RGB color = dlg.open();
    if (color == null) {
      return;
    }

    if (element instanceof IArtifact) {
      final IArtifact abstractArtifact = (IArtifact) element;
      colorMap.setColor(abstractArtifact, color);
    } else if (element instanceof ILogEvent) {
      ILogEvent o = (ILogEvent) element;
      final ILogEvent event = (ILogEvent) o;
      final IEventColorProvider colorProvider =
          getServiceProvider().getService(IEventColorProvider.class);
      final IColor clr = ColorAdapter.valueOf(color);
      colorProvider.setColor(event.getType(), clr);
    }
  }