| /******************************************************************************* |
| * Copyright (c) 2009 Zoltan Ujhelyi and Daniel Varro. |
| * 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: |
| * Zoltan Ujhelyi - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.viatra2.visualisation.patterns.sources; |
| |
| import org.eclipse.draw2d.IFigure; |
| import org.eclipse.swt.graphics.Color; |
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern; |
| import org.eclipse.viatra2.gtasmmodel.vpm.editmodel.ModelElement; |
| import org.eclipse.viatra2.gtasmmodel.vpm.editmodel.Relation; |
| import org.eclipse.viatra2.gtasmmodel.vpm.editmodel.Relationship; |
| import org.eclipse.viatra2.gtasmmodel.vpm.editmodel.TypeOf; |
| import org.eclipse.viatra2.visualisation.ViatraColoredLabelProvider; |
| import org.eclipse.viatra2.visualisation.patterns.viewmodel.AbstractViewModelElement; |
| import org.eclipse.viatra2.visualisation.patterns.viewmodel.ViewParameterAssignment; |
| import org.eclipse.viatra2.visualisation.patterns.viewmodel.ViewPattern; |
| import org.eclipse.viatra2.visualisation.patterns.viewmodel.ViewPatternModelElement; |
| import org.eclipse.zest.core.viewers.IConnectionStyleProvider; |
| import org.eclipse.zest.core.viewers.IEntityStyleProvider; |
| import org.eclipse.zest.core.viewers.IFigureProvider; |
| import org.eclipse.zest.core.widgets.ZestStyles; |
| |
| /** |
| * A Label Provider for the Pattern Visualisation. It uses the color scheme |
| * defined in the color registry. |
| * @author Zoltan Ujhelyi |
| */ |
| public class PatternLabelProvider extends ViatraColoredLabelProvider implements |
| IConnectionStyleProvider, IFigureProvider, IEntityStyleProvider { |
| |
| |
| private String getTypeString(ModelElement element){ |
| for (Relationship rel : element.getSuperRelationships()) { |
| if (rel instanceof TypeOf) { |
| return rel.getSupplierStr(); |
| } |
| } |
| return ""; |
| } |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) |
| */ |
| @Override |
| public String getText(Object element) { |
| if (element instanceof GTPattern) { |
| return null;// "<<Pattern>>\n" + ((GTPattern) element).getName(); |
| } else if (element instanceof Relation) { |
| Relation relation = (Relation) element; |
| //return relation.getName(); |
| |
| return relation.getName() + ":" + getTypeString(relation);//relation.getType().toString(); |
| |
| } else if (element instanceof AbstractViewModelElement) { |
| String prefix = ""; |
| if (element instanceof ViewPattern) { |
| prefix = "<<Pattern>>\n"; |
| // return null; |
| } |
| return prefix + ((AbstractViewModelElement) element).getName() + ":" + ((AbstractViewModelElement) element).getTypeString(); |
| } |
| return super.getText(element); |
| } |
| |
| public Color getColor(Object rel) { |
| if (rel instanceof ViewParameterAssignment) { |
| return PARAM; |
| } else { |
| return ARC; |
| } |
| } |
| |
| public int getConnectionStyle(Object rel) { |
| if (rel instanceof ViewParameterAssignment) { |
| return ZestStyles.CONNECTIONS_DASH_DOT |
| | ZestStyles.CONNECTIONS_DIRECTED; |
| } |
| return ZestStyles.CONNECTIONS_SOLID | ZestStyles.CONNECTIONS_DIRECTED; |
| } |
| |
| public Color getHighlightColor(Object rel) { |
| if (rel instanceof ViewParameterAssignment) { |
| return PARAM_HL; |
| } else { |
| return ARC_HL; |
| } |
| } |
| |
| public int getLineWidth(Object rel) { |
| return 1; |
| } |
| |
| public IFigure getTooltip(Object entity) { |
| return null; |
| } |
| |
| public IFigure getFigure(Object element) { |
| // TODO it is not called until the fix of bug #282728 is not present in |
| // Zest |
| // it is already available in CVS |
| /* |
| * if (element instanceof ViewPattern) { RectangleFigure rec = new |
| * RectangleFigure(); rec.setSize(100, 100); return rec; } |
| */ |
| return null; |
| } |
| |
| public boolean fisheyeNode(Object entity) { |
| return false; |
| } |
| |
| public Color getBackgroundColour(Object entity) { |
| if (entity instanceof ViewPatternModelElement) { |
| ViewPatternModelElement modelElement = (ViewPatternModelElement) entity; |
| if (modelElement.isEntity()) { |
| return ENTITY_BG; |
| } else if (modelElement.isRelation()) { |
| return RELATION_BG; |
| } |
| } else if (entity instanceof ViewPattern) { |
| return PATTERN_BG; |
| } |
| return null; |
| } |
| |
| public Color getBorderColor(Object entity) { |
| if (entity instanceof ViewPatternModelElement) { |
| ViewPatternModelElement modelElement = (ViewPatternModelElement) entity; |
| if (modelElement.isEntity()) { |
| return ENTITY_BO; |
| } else if (modelElement.isRelation()) { |
| return RELATION_BO; |
| } |
| } else if (entity instanceof ViewPattern) { |
| return PATTERN_BO; |
| } |
| return null; |
| } |
| |
| public Color getBorderHighlightColor(Object entity) { |
| if (entity instanceof ViewPatternModelElement) { |
| ViewPatternModelElement modelElement = (ViewPatternModelElement) entity; |
| if (modelElement.isEntity()) { |
| return ENTITY_BOHL; |
| } else if (modelElement.isRelation()) { |
| return RELATION_BOHL; |
| } |
| } else if (entity instanceof ViewPattern) { |
| return PATTERN_BOHL; |
| } |
| return null; |
| } |
| |
| public int getBorderWidth(Object entity) { |
| return 1; |
| } |
| |
| public Color getForegroundColour(Object entity) { |
| if (entity instanceof ViewPatternModelElement) { |
| ViewPatternModelElement modelElement = (ViewPatternModelElement) entity; |
| if (modelElement.isEntity()) { |
| return ENTITY_FG; |
| } else if (modelElement.isRelation()) { |
| return RELATION_FG; |
| } |
| } else if (entity instanceof ViewPattern) { |
| return PATTERN_FG; |
| } |
| return null; |
| } |
| |
| public Color getNodeHighlightColor(Object entity) { |
| if (entity instanceof ViewPatternModelElement) { |
| ViewPatternModelElement modelElement = (ViewPatternModelElement) entity; |
| if (modelElement.isEntity()) { |
| return ENTITY_HL; |
| } else if (modelElement.isRelation()) { |
| return RELATION_HL; |
| } |
| } else if (entity instanceof ViewPattern) { |
| return PATTERN_HL; |
| } |
| return null; |
| } |
| |
| } |