Skip to content

Commit

Permalink
TEIIDDES-2279 Added decorator to T-diagram node and change color of a…
Browse files Browse the repository at this point in the history
…rrow if error in transformation
  • Loading branch information
blafond committed Aug 22, 2014
1 parent 901417a commit 343a745
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 51 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ interface Images {
String EXPRESSION_BUILDER_ICON = "icons/full/cview20/launch_expression_builder.gif"; //$NON-NLS-1$
String RECONCILER_ICON = "icons/full/cview16/tb_reconcile_sql.gif"; //$NON-NLS-1$;
String TRANSFORMATION_NODE_ICON = "icons/full/cview20/transformation_node.gif"; //$NON-NLS-1$
String TRANSFORMATION_NODE_ICON_ERROR = "icons/full/cview20/transformation_node_red.gif"; //$NON-NLS-1$
String ARROW_TRANSFORMATION_NODE_ICON = "icons/full/cview20/arrow_transformation_node.gif"; //$NON-NLS-1$
String ARROW_TRANSFORMATION_NODE_ICON_ERROR = "icons/full/cview20/arrow_transformation_node_red.gif"; //$NON-NLS-1$
String XTRANSFORMATION_NODE_ICON = "icons/full/cview20/Xtransformation_node.gif"; //$NON-NLS-1$
String ARROW_XTRANSFORMATION_NODE_ICON = "icons/full/cview20/arrow_xtransformation_node.gif"; //$NON-NLS-1$
String REVALIDATE_TRANSFORMATION_ICON = "icons/full/cview16/validate.gif"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.teiid.designer.diagram.ui.DiagramUiConstants;
import org.teiid.designer.diagram.ui.DiagramUiPlugin;
import org.teiid.designer.diagram.ui.figure.AbstractDiagramFigureFactory;
import org.teiid.designer.diagram.ui.figure.DiagramFigure;
import org.teiid.designer.diagram.ui.model.DiagramModelNode;
import org.teiid.designer.diagram.ui.notation.NotationFigureGenerator;
import org.teiid.designer.diagram.ui.util.colors.ColorPalette;
Expand Down Expand Up @@ -110,6 +111,16 @@ public Figure createFigure(Object modelObject) {
if( tNode.isUnion() ) {
((TransformationFigure)newFigure).setSubscript("u"); //$NON-NLS-1$
}

// Need to notify t-objects to update their error/warning status
if( newFigure != null && modelObject instanceof DiagramModelNode ) {
DiagramModelNode node = (DiagramModelNode)modelObject;
((DiagramFigure)newFigure).setDiagramModelNode(node);
if( node.hasErrors())
((DiagramFigure)newFigure).updateForError(true);
else if( node.hasWarnings() )
((DiagramFigure)newFigure).updateForWarning(true);
}
} break;

// Delegate to the UML figure factory to make figures for all other model types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
package org.teiid.designer.transformation.ui.figure;

import java.util.List;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.FigureUtilities;
import org.eclipse.draw2d.IFigure;
Expand All @@ -16,6 +18,7 @@
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.swt.graphics.Font;
import org.teiid.designer.diagram.ui.DiagramUiPlugin;
import org.teiid.designer.diagram.ui.figure.AbstractDiagramFigure;
import org.teiid.designer.diagram.ui.util.DiagramUiUtilities;
import org.teiid.designer.diagram.ui.util.colors.ColorPalette;
Expand All @@ -37,13 +40,16 @@
*/
public class TransformationFigure extends AbstractDiagramFigure {
// private static final Font tFont = new Font(null, "Comic Sans MS", 16, 3); //$NON-NLS-1$
// private Polygon transformOutline;

private ImageFigure transformationIcon;
// private Label nameLabel;

private Label subscript = new Label("u"); //$NON-NLS-1$
private TransformationNode tNode = null;
private ImageFigure errorIcon;
private ImageFigure warningIcon;

private int status = IStatus.OK;

// private PointList transformPoints = new PointList();

/**
*
Expand Down Expand Up @@ -73,33 +79,9 @@ private void init(String name) {
}
this.add(transformationIcon);
transformationIcon.setSize(transformationIcon.getPreferredSize());
// transformOutline = new Polygon();
// transformPoints.addPoint(0, 20);
// transformPoints.addPoint(20, 0);
// transformPoints.addPoint(40, 20);
// transformPoints.addPoint(20, 40);
// transformPoints.addPoint(0, 20);
// transformOutline.setPoints(transformPoints);
//
// this.add(transformOutline);

// transformOutline.setLineWidth(2);
// transformOutline.setForegroundColor(ColorConstants.darkBlue);
// transformOutline.setBackgroundColor(getColor(ColorPalette.SECONDARY_BKGD_COLOR_ID));

// if( name != null ) {
//
// nameLabel = new Label(name);
// nameLabel.setFont(tFont);
// this.add(nameLabel);
//
// nameLabel.setForegroundColor(ColorConstants.black);
// nameLabel.setBackgroundColor(this.getBackgroundColor());
// setLabelSize(nameLabel);
// }

if( subscript != null ) {
subscript.setFont(DiagramUiUtilities.getToolTipFont());
// this.add(subscript);
subscript.setForegroundColor(ColorConstants.black);
subscript.setBackgroundColor(this.getBackgroundColor());
setLabelSize(subscript);
Expand Down Expand Up @@ -138,11 +120,6 @@ private void layoutThisFigure(Dimension newSize) {
int centerX = newSize.width/2;
int centerY = newSize.height/2;

// if( nameLabel != null ) {
// nameLabel.setLocation(
// new Point(centerX - nameLabel.getBounds().width/2,
// centerY - nameLabel.getBounds().height/2) );
// }
if( this.getChildren().contains(subscript)) {
if( isOnDependencyDiagram() ) {
subscript.setLocation( new Point(centerX + 3, centerY - 2) );
Expand All @@ -151,23 +128,12 @@ private void layoutThisFigure(Dimension newSize) {
}

}
// new Point(8 + centerX - nameLabel.getBounds().width/2,
// 12 + centerY - nameLabel.getBounds().height/2) );

}

@Override
public void updateForSize(Dimension size){

// int thisHeight = size.height;
// int thisWidth = size.width;
// replacePoint( 0, 0, thisHeight/2);
// replacePoint( 1, thisWidth/2, 0);
// replacePoint( 2, thisWidth, thisHeight/2);
// replacePoint( 3, thisWidth/2, thisHeight);
// replacePoint( 4, 0, thisHeight/2);
// transformOutline.setPoints(transformPoints);


this.layoutThisFigure(size);

this.repaint();
Expand All @@ -182,16 +148,13 @@ public void updateSize() {

}

// private void replacePoint(int index, int newX, int newY ) {
// transformPoints.setPoint(new Point(newX, newY), index);
// }
/**
* @see org.eclipse.draw2d.IFigure#getToolTip()
* @since 4.2
*/
@Override
public IFigure getToolTip() {
List toolTips = tNode.getToolTipStrings();
List<String> toolTips = tNode.getToolTipStrings();
if( toolTips != null && !toolTips.isEmpty() )
super.setToolTip(super.createToolTip(toolTips));

Expand Down Expand Up @@ -230,6 +193,88 @@ private boolean isOnDependencyDiagram() {

return false;
}

/*
* (non-Javadoc)
* @See org.teiid.designer.diagram.ui.figure.DiagramFigure#updateForError(boolean)
*/
@Override
public void updateForError(boolean hasErrors) {
if( hasErrors ) {
if( errorIcon == null ) {
updateTransformationIcon(IStatus.ERROR);

errorIcon = new ImageFigure(DiagramUiPlugin.getDefault().getImage(PluginConstants.Images.ERROR_ICON));
if( errorIcon != null ) {
this.add(errorIcon);
int centerX = this.getBounds().width/2;
int centerY = this.getBounds().height/2;

if( isOnDependencyDiagram() ) {
errorIcon.setLocation( new Point(centerX - 11, centerY -2 ) );
} else {
errorIcon.setLocation( new Point(centerX - 7, centerY) );
}
errorIcon.setSize(errorIcon.getPreferredSize());
}
}
status = IStatus.ERROR;
} else if( errorIcon != null ) {
updateTransformationIcon(IStatus.OK);
this.remove(errorIcon);
errorIcon = null;
status = IStatus.OK;
}
}

/*
* (non-Javadoc)
* @See org.teiid.designer.diagram.ui.figure.DiagramFigure#updateForWarning(boolean)
*/
@Override
public void updateForWarning(boolean hasWarnings) {
if( hasWarnings ) {
if( warningIcon == null ) {
updateTransformationIcon(IStatus.WARNING);

warningIcon = new ImageFigure(DiagramUiPlugin.getDefault().getImage(PluginConstants.Images.WARNING_ICON));
if( warningIcon != null ) {
this.add(warningIcon);
int centerX = this.getBounds().width/2;
int centerY = this.getBounds().height/2;

if( isOnDependencyDiagram() ) {
warningIcon.setLocation( new Point(centerX - 3, centerY + 2) );
} else {
warningIcon.setLocation( new Point(centerX - 7, centerY) );
}
warningIcon.setSize(warningIcon.getPreferredSize());
}
}
status = IStatus.WARNING;
} else if( warningIcon != null ) {
updateTransformationIcon(IStatus.OK);
this.remove(warningIcon);
warningIcon = null;
status = IStatus.OK;
}
}

private void updateTransformationIcon(int newStatus) {
if( newStatus == status ) return;

this.remove(transformationIcon);

if( isOnDependencyDiagram() ) {
if( newStatus > IStatus.INFO ) transformationIcon = new ImageFigure(UiPlugin.getDefault().getImage(PluginConstants.Images.TRANSFORMATION_NODE_ICON_ERROR));
else transformationIcon = new ImageFigure(UiPlugin.getDefault().getImage(PluginConstants.Images.TRANSFORMATION_NODE_ICON));
} else {
if( newStatus > IStatus.INFO ) transformationIcon = new ImageFigure(UiPlugin.getDefault().getImage(PluginConstants.Images.ARROW_TRANSFORMATION_NODE_ICON_ERROR));
else transformationIcon = new ImageFigure(UiPlugin.getDefault().getImage(PluginConstants.Images.ARROW_TRANSFORMATION_NODE_ICON));
}
this.add(transformationIcon);
transformationIcon.setSize(transformationIcon.getPreferredSize());
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
package org.teiid.designer.transformation.ui.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.notify.Notification;
Expand Down Expand Up @@ -1325,4 +1327,42 @@ private boolean showLinksInTransformation( DiagramModelNode diagramModelNode ) {
protected void setHideLinksAlways( boolean theHideLinksAlways ) {
this.hideLinksAlways = theHideLinksAlways;
}

@Override
public void handleLabelProviderChanged(DiagramModelNode diagramModelNode, List eObjects) {
HashMap updateNodes = new HashMap(eObjects.size());

Iterator iter = eObjects.iterator();
while( iter.hasNext() ) {
EObject nextEObject = (EObject)iter.next();
DiagramModelNode nextNode = getModelNode(diagramModelNode, nextEObject);
if( nextNode != null ) {
updateNodes.put(nextNode, "x"); //$NON-NLS-1$
DiagramModelNode parentClassNode = DiagramUiUtilities.getClassifierParentNode(nextNode);
if( parentClassNode != null ) {
updateNodes.put(parentClassNode, "x"); //$NON-NLS-1$
}


// Need to check for Transformation Targets
if( TransformationHelper.isValidTransformationTarget(nextEObject) ) {
EObject tRoot = TransformationHelper.getMappingRoot(nextEObject);
if( tRoot != null ) {
DiagramModelNode tNode = getModelNode(diagramModelNode, tRoot);
if( tNode != null ) {
updateNodes.put(tNode, "x"); //$NON-NLS-1$
}
}
}
}
}

iter = updateNodes.keySet().iterator();
while( iter.hasNext() ) {
DiagramModelNode nextNode = (DiagramModelNode)iter.next();
if( nextNode != null ) {
nextNode.updateForErrorsAndWarnings();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.ecore.EObject;
import org.teiid.designer.core.query.QueryValidator;
import org.teiid.designer.diagram.ui.DiagramUiConstants;
import org.teiid.designer.diagram.ui.editor.DiagramEditorUtil;
import org.teiid.designer.diagram.ui.model.AbstractDiagramModelNode;
import org.teiid.designer.metamodels.diagram.Diagram;
import org.teiid.designer.metamodels.transformation.SqlTransformationMappingRoot;
import org.teiid.designer.transformation.util.SqlMappingRootCache;
import org.teiid.designer.transformation.util.TransformationHelper;
import org.teiid.designer.transformation.validation.SqlTransformationResult;
import org.teiid.query.ui.sqleditor.sql.SqlFormattingStrategy;


Expand Down Expand Up @@ -52,8 +60,8 @@ public String getSubscript() {
return null;
}

public List getToolTipStrings() {
List returnList = new ArrayList();
public List<String> getToolTipStrings() {
List<String> returnList = new ArrayList<String>();
// Defect 23027
// Putting in defensive code here because the model may be in the process of being deleted and therefore will have no
// eResource.
Expand All @@ -66,6 +74,62 @@ public List getToolTipStrings() {
}
return returnList;
}


/*
* (non-Javadoc)
* @see org.teiid.designer.diagram.ui.model.AbstractDiagramModelNode#setErrorState()
*/
@Override
public void setErrorState() {
int state = DiagramUiConstants.NO_ERRORS;
errorState = false;
warningState = false;

if (getModelObject() != null) {
// The modelObject for the t-node is the SQL mapping root. need to get the Target table to find it's "errors"
EObject targetTable = TransformationHelper.getTransformationTarget(getModelObject());
state = DiagramEditorUtil.getErrorState(targetTable);
if (state == DiagramUiConstants.HAS_ERROR) {
// Note that if a virtual table has an ERROR it MAY NOT be the transformation.
// So check the SQL cached status

SqlTransformationResult result = SqlMappingRootCache.getSqlTransformationStatus(
(SqlTransformationMappingRoot)getModelObject(), QueryValidator.SELECT_TRNS, true, null);

if( result != null && result.getMaxSeverity() == IStatus.ERROR) {
errorState = true;
return;
}

result = SqlMappingRootCache.getSqlTransformationStatus(
(SqlTransformationMappingRoot)getModelObject(), QueryValidator.INSERT_TRNS, true, null);

if( result != null && result.getMaxSeverity() == IStatus.ERROR) {
errorState = true;
return;
}

result = SqlMappingRootCache.getSqlTransformationStatus(
(SqlTransformationMappingRoot)getModelObject(), QueryValidator.UPDATE_TRNS, true, null);

if( result != null && result.getMaxSeverity() == IStatus.ERROR) {
errorState = true;
return;
}

result = SqlMappingRootCache.getSqlTransformationStatus(
(SqlTransformationMappingRoot)getModelObject(), QueryValidator.DELETE_TRNS, true, null);

if( result != null && result.getMaxSeverity() == IStatus.ERROR) {
errorState = true;
return;
}

}
}

}
}


Expand Down

0 comments on commit 343a745

Please sign in to comment.