CreateTokenLabelsAction.java :  » UML » model-analysis-framework » de » uniAugsburg » MAF » dfa » jwt » ui » token » actions » Java Open Source

Java Open Source » UML » model analysis framework 
model analysis framework » de » uniAugsburg » MAF » dfa » jwt » ui » token » actions » CreateTokenLabelsAction.java
package de.uniAugsburg.MAF.dfa.jwt.ui.token.actions;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.eclipse.draw2d.ConnectionEndpointLocator;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.Locator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.jwt.we.figures.processes.ActivityEdgeFigure;
import org.eclipse.swt.graphics.Color;

import de.uniAugsburg.MAF.dfa.jwt.metamodel.tokenflow.Token;
import de.uniAugsburg.MAF.dfa.jwt.ui.HighlightElementsAction;
import de.uniAugsburg.MAF.dfa.jwt.ui.UIVisualizerHelper;


public class CreateTokenLabelsAction extends HighlightElementsAction
{
  private Map<List<EObject>, Set<Token>> tokensInitialSetForElement;

  private Map<List<EObject>, Set<Token>> tokensFinalSetForElement;


  public CreateTokenLabelsAction(String text,
      Map<List<EObject>, Map<EObject, EObject>> activityPathCopyMap,
      Map<List<EObject>, Set<Token>> tokensInitialSetForElement,
      Map<List<EObject>, Set<Token>> tokensFinalSetForElement)
  {
    super(text, activityPathCopyMap, new HashSet<List<EObject>>(), null);

    this.tokensInitialSetForElement = tokensInitialSetForElement;
    this.tokensFinalSetForElement = tokensFinalSetForElement;
  }


  /*
   * (non-Javadoc)
   * 
   * @see
   * de.uniAugsburg.MAF.bridge.jwt.ui.actions.HighlightElementsAction#elementFound
   * (java.util.List, java.lang.Object, org.eclipse.gef.EditPart,
   * org.eclipse.draw2d.Figure)
   */
  @Override
  protected void elementFound(List<EObject> activityPath, List<EObject> elementPath,
      Object origElement, EditPart editpart, Figure figure)
  {
  }


  /*
   * (non-Javadoc)
   * 
   * @see de.uniAugsburg.MAF.bridge.jwt.ui.actions.HighlightElementsAction#
   * elementNotFound(java.util.List, java.lang.Object,
   * org.eclipse.gef.EditPart, org.eclipse.draw2d.Figure)
   */
  @Override
  protected void elementNotFound(List<EObject> activityPath, Object origElement,
      EditPart editpart, Figure figure)
  {
    if (!(figure instanceof ActivityEdgeFigure))
      return;

    createTokenDescription(activityPath, "initial", origElement, figure,
        tokensInitialSetForElement);
    createTokenDescription(activityPath, "final", origElement, figure, tokensFinalSetForElement);
  }


  /**
   * @param activityPath
   * @param origElement
   * @param figure
   * @param tokenMap
   */
  private void createTokenDescription(List<EObject> activityPath, String type,
      Object origElement, Figure figure, Map<List<EObject>, Set<Token>> tokenMap)
  {
    for (Entry<List<EObject>, Set<Token>> entry : tokenMap.entrySet())
    {
      List<EObject> elementPath = entry.getKey();
      List<EObject> resultElementActivityPath = UIVisualizerHelper
          .extractActivityPath(elementPath);
      Object resultElement = UIVisualizerHelper.extractElement(elementPath);

      // if in the current activity -> display
      if (activityPath.equals(resultElementActivityPath) && resultElement.equals(origElement))
      {
        String text = "";
        for (Token token : entry.getValue())
          text += token.toString() + "\n";

        Locator locator;
        Color color;
        if (type.equals("initial"))
        {
          Label label = new Label(text);
          label.setFont(UIVisualizerHelper.font);
          label.setOpaque(true);
          label.setForegroundColor(org.eclipse.draw2d.ColorConstants.blue);
          figure.setToolTip(label);
        }
        else
        {
          color = org.eclipse.draw2d.ColorConstants.blue;
          locator = new ConnectionEndpointLocator((ActivityEdgeFigure) figure, true);
          Label label = new Label(text);
          label.setFont(UIVisualizerHelper.font);
          label.setOpaque(true);
          label.setForegroundColor(color);
          ((ActivityEdgeFigure) figure).add(label, locator);
        }

        break;
      }
    }
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.