use of org.eclipse.draw2d.geometry.Dimension in project tdi-studio-se by Talend.
the class ToolBarLayout method calculatePreferredSize.
@Override
protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHint) {
Dimension dimension = super.calculatePreferredSize(container, wHint, hHint);
dimension.height = dimension.height + marginBottom + marginTop;
return dimension;
}
use of org.eclipse.draw2d.geometry.Dimension in project tdi-studio-se by Talend.
the class RowLayout method calculateChildrenSize.
private Dimension calculateChildrenSize(List children, int wHint, int hHint, int tableContainerWidth, Map<Integer, Double> weight) {
Dimension childSize;
IFigure child;
int height = 0, width = 0;
for (int i = 0; i < children.size(); i++) {
child = (IFigure) children.get(i);
childSize = getChildPreferredSize(child, wHint, hHint);
if (weight != null && weight.containsKey(i) && tableContainerWidth > 0) {
childSize.width = (int) (tableContainerWidth * weight.get(i));
}
// height += childSize.height;
width += childSize.width;
}
return new Dimension(width, height);
}
use of org.eclipse.draw2d.geometry.Dimension in project tdi-studio-se by Talend.
the class ConnectionTraceFigure method setTraceData.
public void setTraceData(TraceData data, boolean flag, boolean traceFlag) {
if (data != null) {
List childrens = this.getChildren();
childrens.clear();
boolean noVarNameDefined = false;
Figure outlineFigure = new Figure();
outlineFigure.setLayoutManager(new ToolbarLayout(true));
int title1With = 0;
int title2With = 0;
if (tooltip != null) {
collapseButton = new CollapseFigure();
collapseButton.setCollapsed(connection.getConnectionTrace().isCollapse());
collapseButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
connection.getConnectionTrace().setCollapse(!connection.getConnectionTrace().isCollapse());
collapseButton.setCollapsed(connection.getConnectionTrace().isCollapse());
refreshCollapseStatus();
}
});
if (flag == true) {
outlineFigure.add(collapseButton);
}
}
// int sepIndex = data.indexOf(FIELD_SEP); // index separator for row name
//
// String dataWithoutRowName = data.substring(sepIndex + 1);
// sepIndex = dataWithoutRowName.indexOf(FIELD_SEP);
int lineNumber = data.getNbLine();
SimpleHtmlFigure titleFigure = new SimpleHtmlFigure();
//$NON-NLS-1$
titleFigure.setText("");
titleFigure.setText(//$NON-NLS-1$
"<font color='#0000FF'> <b> " + connection.getConnectionLabel().getLabelText() + //$NON-NLS-1$
"</b></font>");
if (tooltip != null) {
titleFigure.setBackgroundColor(ColorConstants.white);
titleFigure.setOpaque(false);
}
titleFigure.getPreferredSize().expand(20, 2);
title1With = titleFigure.getPreferredSize().width;
SimpleHtmlFigure titleFigureSe = new SimpleHtmlFigure();
//$NON-NLS-1$ //$NON-NLS-2$
titleFigureSe.setText(" <font color='#808080'>Current row : " + lineNumber + "</font>");
if (tooltip != null) {
titleFigureSe.setBackgroundColor(ColorConstants.white);
titleFigureSe.setOpaque(false);
}
titleFigureSe.getPreferredSize().expand(20, 2);
title2With = titleFigureSe.getPreferredSize().width;
if (flag == true) {
outlineFigure.add(titleFigure);
}
ImageFigure figure = new ImageFigure(getTraceConnectionImage(flag));
outlineFigure.add(figure);
if (flag == true) {
outlineFigure.add(titleFigureSe);
}
outlineFigure.setBorder(new LineBorder(ColorConstants.darkGray, SWT.LEFT | SWT.RIGHT | SWT.TOP | SWT.BOTTOM));
outlineFigure.setOpaque(true);
add(outlineFigure);
Dimension size = titleFigure.getPreferredSize().getCopy();
int variableWidth = 0;
int valueWidth = 0;
// String lineInfo = dataWithoutRowName.substring(sepIndex + 1);
// ArrayList columnValueList = new ArrayList();
// int lastLocation = 0;
// int endLocation = lineInfo.indexOf(FIELD_SEP, lastLocation);
// while (endLocation != -1) {
// columnValueList.add(lineInfo.substring(lastLocation, endLocation + 1));
// lastLocation = endLocation + 2;
// endLocation = lineInfo.indexOf(FIELD_SEP, lastLocation);
// }
// if (columnValueList.size() > 0 && connection.traceColumn.size() == 0
// && connection.getPropertyValue(EParameterName.TRACES_CONNECTION_FILTER.getName()) != null) {
// Object value = connection.getPropertyValue(EParameterName.TRACES_CONNECTION_FILTER.getName());
// lineInfo = "";
// for (Object o : columnValueList) {
// for (Object o1 : (ArrayList) value) {
// if (o1 instanceof HashMap) {
// String columnValue = o.toString();
// if (columnValue.indexOf("=") > 0) {
// if (((HashMap) o1).get(IConnection.TRACE_SCHEMA_COLUMN).toString()
// .equals(columnValue.substring(0, columnValue.indexOf("=")).trim())
// && Boolean.TRUE.toString().equals(
// ((HashMap) o1).get(IConnection.TRACE_SCHEMA_COLUMN_CHECKED).toString())) {
// lineInfo += columnValue;
// break;
// }
// }
// }
// }
// }
// }
// if (columnValueList.size() > 0 && (connection.traceColumn.size() > 0 || connection.setNullColumn ==
// true)) {
// lineInfo = "";
// Object value = connection.getPropertyValue(EParameterName.TRACES_CONNECTION_FILTER.getName());
// int columnNum = 0;
// for (Object o : columnValueList) {
// if (connection.traceColumn != null && connection.traceColumn.contains(columnNum)) {
// lineInfo += o.toString();
// } else {
// for (Object o1 : (ArrayList) value) {
// if (((HashMap) o1).get(IConnection.TRACE_SCHEMA_COLUMN).toString()
// .equals(o.toString().substring(0, o.toString().indexOf("=")).trim())
// && Boolean.TRUE.toString().equals(
// ((HashMap) o1).get(IConnection.TRACE_SCHEMA_COLUMN_CHECKED).toString())) {
// lineInfo += o.toString();
// break;
// }
// }
// }
// columnNum++;
// }
// }
// StringTokenizer st = new StringTokenizer(lineInfo, FIELD_SEP);
List<Map<String, Object>> columnsCheckInfo = null;
if (data.getData() != null) {
columnsCheckInfo = TracesConnectionUtils.getTraceConnectionFilterValues(connection);
Iterator<String> iterator = data.getData().keySet().iterator();
while (iterator.hasNext()) {
String columnLabel = iterator.next();
if (columnsCheckInfo != null && !isColumnChecked(columnsCheckInfo, columnLabel)) {
continue;
}
// String str = st.nextToken();
// int valueStart = str.indexOf(FIELD_EQUAL);
// if (valueStart != -1) {
String formatedVariable = //$NON-NLS-1$
"<font color='#000000'> <b>" + columnLabel + //$NON-NLS-1$
"</b></font>";
//$NON-NLS-1$ //$NON-NLS-2$
String formatedValue = "<font color='#FF8040'> <b>" + data.getData().get(columnLabel) + "</b></font>";
SimpleHtmlFigure var = new SimpleHtmlFigure();
var.setText(formatedVariable);
SimpleHtmlFigure value = new SimpleHtmlFigure();
value.setText(formatedValue);
Dimension varSize = var.getPreferredSize();
varSize.expand(0, 3);
var.setPreferredSize(varSize);
if (varSize.width > variableWidth) {
variableWidth = varSize.width;
}
Dimension valueSize = value.getPreferredSize();
valueSize.expand(0, 3);
value.setPreferredSize(valueSize);
if (valueSize.width > valueWidth) {
valueWidth = valueSize.width;
}
size.expand(0, varSize.height);
// } else {
// noVarNameDefined = true;
// String formatedValue = "<font color='#FF8040'> <b>" + str + "</b></font>"; //$NON-NLS-1$ //$NON-NLS-2$
// SimpleHtmlFigure value = new SimpleHtmlFigure();
// value.setText(formatedValue);
// Dimension valueSize = value.getPreferredSize();
// if (valueSize.width > valueWidth) {
// valueWidth = valueSize.width;
// }
// size.expand(0, valueSize.height);
// }
}
}
variableWidth += 10;
valueWidth += 10;
if (variableWidth < title1With) {
variableWidth = title1With;
}
if (valueWidth < title2With) {
valueWidth = title2With;
}
// if (maximized) {
if (variableWidth < MAX_VARIABLE_WIDTH) {
variableWidth = MAX_VARIABLE_WIDTH;
}
if (valueWidth < MAX_VALUE_WIDTH) {
valueWidth = MAX_VALUE_WIDTH;
}
if ((variableWidth + valueWidth) < titleFigure.getPreferredSize().width) {
valueWidth = titleFigure.getPreferredSize().width - variableWidth;
}
if (noVarNameDefined) {
if (titleFigure.getPreferredSize().width > valueWidth) {
valueWidth = titleFigure.getPreferredSize().width;
}
}
// st = new StringTokenizer(lineInfo, FIELD_SEP);
int nbVar = 0;
if (data.getData() != null) {
Iterator<String> iterator = data.getData().keySet().iterator();
while (iterator.hasNext()) {
String columnLabel = iterator.next();
if (columnsCheckInfo != null && !isColumnChecked(columnsCheckInfo, columnLabel)) {
continue;
}
// int valueStart = str.indexOf(FIELD_EQUAL);
// if (valueStart != -1) {
String formatedVariable = //$NON-NLS-1$
"<font color='#000000'> <b>" + columnLabel + //$NON-NLS-1$
"</b></font>";
//$NON-NLS-1$ //$NON-NLS-2$
String formatedValue = "<font color='#FF8040'> <b>" + data.getData().get(columnLabel) + "</b></font>";
SimpleHtmlFigure var = new SimpleHtmlFigure();
var.setText(formatedVariable);
SimpleHtmlFigure value = new SimpleHtmlFigure();
value.setText(formatedValue);
Dimension valueSize = value.getPreferredSize();
valueSize.expand(0, 3);
value.setPreferredSize(valueSize);
value.setPreferredSize(valueWidth, valueSize.height);
var.setBorder(new LineBorder(ColorConstants.darkGray, SWT.RIGHT));
Dimension varSize = var.getPreferredSize();
varSize.expand(0, 3);
var.setPreferredSize(varSize);
var.setPreferredSize(variableWidth, varSize.height);
ToolbarLayout variableLayout = new ToolbarLayout(true);
variableFigure = new Figure();
variableFigure.setLayoutManager(variableLayout);
variableFigure.add(var);
variableFigure.add(value);
if (flag == true) {
add(variableFigure);
}
// } else {
// String formatedValue = "<font color='#FF8040'> <b> " + str + "</b></font>"; //$NON-NLS-1$ //$NON-NLS-2$
// SimpleHtmlFigure value = new SimpleHtmlFigure();
// value.setText(formatedValue);
//
// Dimension valueSize = value.getPreferredSize();
// valueSize.expand(0, 3);
// value.setPreferredSize(valueSize);
// value.setPreferredSize(valueWidth, valueSize.height);
//
// ToolbarLayout variableLayout = new ToolbarLayout(true);
// variableFigure = new Figure();
// variableFigure.setLayoutManager(variableLayout);
// variableFigure.add(value);
// if (flag == true) {
// add(variableFigure);
// }
// }
}
if (tooltip != null) {
if (variableFigure != null) {
variableFigure.setBorder(new LineBorder(ColorConstants.darkGray, SWT.LEFT | SWT.RIGHT));
}
}
if (variableFigure != null) {
variableFigure.setOpaque(true);
}
if ((nbVar % 2) != 0) {
if (tooltip != null) {
if (variableFigure != null) {
variableFigure.setBackgroundColor(ColorConstants.white);
}
}
} else {
if (variableFigure != null) {
variableFigure.setBackgroundColor(BACKGROUND);
}
}
nbVar++;
}
if (tooltip != null) {
if (variableFigure != null) {
variableFigure.setBorder(new LineBorder(ColorConstants.darkGray, SWT.LEFT | SWT.BOTTOM | SWT.RIGHT));
}
}
if (maximized) {
this.setVariableFigureBorder();
}
if (noVarNameDefined) {
size.width = valueWidth;
} else {
size.width = variableWidth + valueWidth;
}
if (size.width < titleFigure.getPreferredSize().width) {
size.width = titleFigure.getPreferredSize().width;
}
// size.width = size.width * 2;
size.expand(5, 3);
setPreferredSize(size);
setVisible(true);
if (!flag) {
this.remove(outlineFigure);
add(figure);
}
} else {
if (traceFlag) {
Image enableImage = getTraceConnectionImage(flag);
setPreferredSize(enableImage.getImageData().width, enableImage.getImageData().height);
this.getChildren().clear();
ImageFigure figure = new ImageFigure(enableImage);
add(figure);
setVisible(true);
} else {
setPreferredSize(0, 0);
setVisible(false);
}
}
if (tooltip != null) {
if (flag) {
tooltip.setTraceData(data, flag, traceFlag);
} else {
tooltip.setTraceData(data, flag, false);
}
}
contents = new ArrayList(getChildren());
refreshCollapseStatus();
}
use of org.eclipse.draw2d.geometry.Dimension in project tdi-studio-se by Talend.
the class JobletContainerFigure method initializejobletContainer.
public void initializejobletContainer(Rectangle rectangle) {
Point location = this.getLocation();
if (location.equals(lastLocation) && !jobletContainer.getNode().isMapReduceStart() && mrFigures.isEmpty()) {
// avoid to calculate locations for nothing
return;
}
lastLocation = location;
collapseFigure.setCollapsed(jobletContainer.isCollapsed());
collapseFigure.setVisible(this.jobletContainer.getNode().isJoblet());
//$NON-NLS-1$ //$NON-NLS-2$
titleFigure.setText("<b> " + title + "</b>");
Dimension preferedSize = titleFigure.getPreferredSize();
preferedSize = preferedSize.getExpanded(0, 3);
collapseFigure.setLocation(new Point(location.x, location.y));
collapseFigure.setSize(preferedSize.height, preferedSize.height);
titleFigure.setSize(preferedSize.width, preferedSize.height - 2);
titleFigure.setLocation(new Point((rectangle.width - preferedSize.width) / 2 + location.x, location.y));
titleFigure.setVisible(showTitle);
outlineFigure.setLocation(new Point(location.x, location.y));
outlineFigure.setVisible(showTitle);
outlineFigure.setForegroundColor(ColorUtils.getCacheColor(new RGB(220, 120, 120)));
outlineFigure.setSize(rectangle.width, preferedSize.height);
refreshMRFigures();
Iterator<Entry<String, SimpleHtmlFigure>> ite = mrFigures.entrySet().iterator();
int i = 0;
while (ite.hasNext()) {
Entry<String, SimpleHtmlFigure> entry = ite.next();
String key = entry.getKey();
SimpleHtmlFigure value = entry.getValue();
int progressHeight = value.getBounds().height + 3;
Integer count = this.jobletContainer.getNode().getMrJobInGroupCount();
i = Integer.parseInt(key.substring(key.indexOf("_") + 1));
int mry = progressHeight * i;
int proWidth = value.getBounds().width;
int jcWidth = this.jobletContainer.getJobletContainerRectangle().width;
if (isSubjobDisplay) {
if (!this.jobletContainer.isMRGroupContainesReduce()) {
if (key.startsWith(KEY_MAP)) {
if (jcWidth > proWidth + 12) {
value.setLocation(new Point(location.x + jcWidth / 2 - proWidth / 2 - 6, location.y + rectangle.height - count * progressHeight + mry));
} else if (jcWidth > proWidth) {
value.setLocation(new Point(location.x + jcWidth / 2 - proWidth / 2, location.y + rectangle.height - count * progressHeight + mry));
} else {
value.setLocation(new Point(location.x, location.y + rectangle.height - count * progressHeight + mry));
}
}
} else {
if (jcWidth / 2 >= 120) {
if (key.startsWith(KEY_MAP)) {
value.setLocation(new Point(location.x + jcWidth / 2 - 120, location.y + rectangle.height - count * progressHeight + mry));
}
if (key.startsWith(KEY_REDUCE)) {
value.setLocation(new Point(location.x + jcWidth / 2, location.y + rectangle.height - count * progressHeight + mry));
}
} else if (jcWidth / 2 > proWidth) {
if (key.startsWith(KEY_MAP)) {
value.setLocation(new Point(location.x + jcWidth / 2 - proWidth, location.y + rectangle.height - count * progressHeight + mry));
}
if (key.startsWith(KEY_REDUCE)) {
value.setLocation(new Point(location.x + jcWidth / 2, location.y + rectangle.height - count * progressHeight + mry));
}
} else {
if (key.startsWith(KEY_MAP)) {
value.setLocation(new Point(location.x, location.y + rectangle.height - count * progressHeight + mry));
}
if (key.startsWith(KEY_REDUCE)) {
value.setLocation(new Point(location.x + 110, location.y + rectangle.height - count * progressHeight + mry));
}
}
}
}
}
rectFig.setLocation(new Point(location.x, /* preferedSize.height + */
location.y));
rectFig.setSize(new Dimension(rectangle.width, rectangle.height));
if (this.jobletContainer.getNode().isJoblet()) {
if (new JobletUtil().isRed(this.jobletContainer)) {
if (isSubjobDisplay) {
rectFig.setBackgroundColor(ColorUtils.getCacheColor(red));
} else {
rectFig.setBackgroundColor(ColorUtils.getCacheColor(white));
}
outlineFigure.setBackgroundColor(ColorUtils.getCacheColor(red));
} else {
if (isSubjobDisplay) {
rectFig.setBackgroundColor(ColorUtils.getCacheColor(green));
} else {
rectFig.setBackgroundColor(ColorUtils.getCacheColor(white));
}
outlineFigure.setBackgroundColor(ColorUtils.getCacheColor(green));
}
} else {
if (isSubjobDisplay) {
rectFig.setBackgroundColor(ColorUtils.getCacheColor(mrGroupColor));
} else {
rectFig.setBackgroundColor(ColorUtils.getCacheColor(white));
}
outlineFigure.setBackgroundColor(ColorUtils.getCacheColor(mrGroupColor));
// progressFigure.setBackgroundColor(new Color(Display.getDefault(), red));
if (!this.jobletContainer.getNode().isMapReduceStart()) {
rectFig.setVisible(false);
outlineFigure.setVisible(false);
}
}
if (isSubjobDisplay) {
if (this.jobletContainer.getNode().isMapReduce()) {
rectFig.setForegroundColor(ColorUtils.getCacheColor(new RGB(121, 157, 175)));
} else {
rectFig.setForegroundColor(ColorUtils.getCacheColor(new RGB(220, 120, 120)));
}
} else {
rectFig.setForegroundColor(ColorUtils.getCacheColor(white));
}
markFigure.setSize(errorMarkImage.getImageData().width, errorMarkImage.getImageData().height);
}
use of org.eclipse.draw2d.geometry.Dimension in project tdi-studio-se by Talend.
the class ConnectionTraceConstraint method relocate.
/*
* (non-Javadoc)
*
* @see org.eclipse.draw2d.Locator#relocate(org.eclipse.draw2d.IFigure)
*/
public void relocate(IFigure figure) {
Dimension nameSize = FigureUtilities.getTextExtents(name, figure.getFont());
figure.setSize(traceSize);
Point location;
if (position.equals("start")) {
//$NON-NLS-1$
location = connFigure.getStart();
} else if (position.equals("end")) {
//$NON-NLS-1$
location = connFigure.getEnd();
} else {
location = connFigure.getPoints().getMidpoint();
}
Point offsetCopy = offset.getCopy();
offsetCopy.translate(location);
if ((connFigure.getStart().y == connFigure.getEnd().y) || (Math.abs(connFigure.getEnd().y - connFigure.getStart().y) < 70)) {
offsetCopy.translate(-(traceSize.width / 2), nameSize.height + 16);
} else {
offsetCopy.translate(-(traceSize.width / 2), -(traceSize.height / 2) + 16);
}
figure.setLocation(offsetCopy);
}
Aggregations