ColorComponentAction.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 » ColorComponentAction.java
/**
 * File: ViewsAction.java Created: 23.11.2006
 * 
 * 
 * /****************************************************************************
 * *** Copyright (c) 2005-2010 University of Augsburg, Germany <www.ds-lab.org>
 * 
 * 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: Wolf Fischer, Programming distributed Systems Lab, University
 * of Augsburg - initial API and implementation Christian Saad, Programming
 * distributed Systems Lab, University of Augsburg - added support for external
 * views
 *******************************************************************************/

package de.uniAugsburg.MAF.dfa.jwt.ui.token.actions;

import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.eclipse.draw2d.Figure;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.jface.action.Action;
import org.eclipse.jwt.meta.model.processes.Scope;
import org.eclipse.jwt.we.editors.pages.activityEditor.WEEditorSheet;
import org.eclipse.swt.graphics.Color;

import de.uniAugsburg.MAF.dfa.jwt.metamodel.tokenflow.Component;


/**
 * 
 */
public class ColorComponentAction extends Action
{

  private WEEditorSheet weeditorsheet;
  private Map<EObject, EObject> originalToCopyDisplayMap;
  private Map<EObject, Object> copyAnalysisToOriginalMap;
  private Component component;


  /**
   * The constructor.
   * 
   * @param component
   */
  public ColorComponentAction(WEEditorSheet weeditorsheet,
      Map<EObject, EObject> originalToCopyDisplayMap, Map<EObject, Object> copyAnalysisToOriginalMap,
      Component component, String text)
  {
    super();

    this.weeditorsheet = weeditorsheet;
    this.originalToCopyDisplayMap = originalToCopyDisplayMap;
    this.copyAnalysisToOriginalMap = copyAnalysisToOriginalMap;
    this.component = component;

    this.setText(text);
  }


  /*
   * (non-Javadoc)
   * 
   * @see org.eclipse.jface.action.Action#run()
   */
  @Override
  public void run()
  {
    colorElements(weeditorsheet, originalToCopyDisplayMap, copyAnalysisToOriginalMap.keySet(),
        org.eclipse.draw2d.ColorConstants.red);

    Set<EObject> allTrivialNodes = new HashSet<EObject>();
    Set<EObject> allInnerEdges = new HashSet<EObject>();
    getSubComponentObjects(component, allTrivialNodes, allInnerEdges);
    colorElements(weeditorsheet, originalToCopyDisplayMap, allTrivialNodes,
        org.eclipse.draw2d.ColorConstants.darkGreen);
    colorElements(weeditorsheet, originalToCopyDisplayMap, allInnerEdges,
        org.eclipse.draw2d.ColorConstants.darkGreen);

    colorElements(weeditorsheet, originalToCopyDisplayMap, component.getTrivialNodes(),
        org.eclipse.draw2d.ColorConstants.green);
    colorElements(weeditorsheet, originalToCopyDisplayMap, component.getInnerEdges(),
        org.eclipse.draw2d.ColorConstants.green);
    colorElements(weeditorsheet, originalToCopyDisplayMap, component.getInputEdges(),
        org.eclipse.draw2d.ColorConstants.cyan);
    colorElements(weeditorsheet, originalToCopyDisplayMap, component.getOutputEdges(),
        org.eclipse.draw2d.ColorConstants.cyan);
    colorElements(weeditorsheet, originalToCopyDisplayMap, component.getSccInputPorts(),
        org.eclipse.draw2d.ColorConstants.orange);
    colorElements(weeditorsheet, originalToCopyDisplayMap, component.getSccOutputPorts(),
        org.eclipse.draw2d.ColorConstants.orange);
  }


  private void getSubComponentObjects(Component component, Set<EObject> allTrivialNodes,
      Set<EObject> allInnerEdges)
  {
    for (Component c : component.getSubComponents())
    {
      allInnerEdges.addAll(c.getInnerEdges());
      allTrivialNodes.addAll(c.getTrivialNodes());

      getSubComponentObjects(c, allTrivialNodes, allInnerEdges);
    }
  }


  private void colorElements(WEEditorSheet weeditorsheet,
      Map<EObject, EObject> originalToCopyDisplayMap, Collection<EObject> elements, Color color)
  {
    for (EObject element : elements)
    {
      Object original = copyAnalysisToOriginalMap.get(element);
      Object copyDisplay = originalToCopyDisplayMap.get(original);

      // get editpart figure for element
      EditPart editpart = (EditPart) weeditorsheet.getGraphicalViewer().getEditPartRegistry()
          .get(copyDisplay);

      if (!(editpart instanceof GraphicalEditPart) || editpart.getModel() instanceof Scope)
        continue;

      Figure figure = (Figure) ((GraphicalEditPart) editpart).getFigure();
      figure.setForegroundColor(color);
      figure.setBackgroundColor(color);
    }

  }
}
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.