use of org.talend.designer.gefabstractmap.figures.table.ColumnSash in project tdi-studio-se by Talend.
the class MapperDropTargetListener method handleSashDrag.
protected void handleSashDrag(DropTargetEvent event, ISash s) {
if (s instanceof SashSeparator) {
SashSeparator separator = (SashSeparator) s;
final Point dropLocation = getDropLocation();
Rectangle leftBounds = separator.getLeftFigure().getBounds().getCopy();
Rectangle rightBounds = separator.getRightFigure().getBounds().getCopy();
if (dropLocation.x < (leftBounds.x + separator.getZoneMinSize() + separator.getSashWidth()) || dropLocation.x > (rightBounds.x + rightBounds.width - separator.getZoneMinSize() - separator.getSashWidth())) {
event.detail = DND.DROP_NONE;
return;
}
final LayoutManager layoutManager = separator.getParentFigure().getLayoutManager();
if (layoutManager instanceof XmlMapDataLayout) {
XmlMapDataLayout layout = (XmlMapDataLayout) layoutManager;
int X = getDropLocation().x;
final Rectangle separatorBounds = separator.getBounds().getCopy();
separatorBounds.x = X;
layout.setConstraint(separator, separatorBounds);
// left figure width
int wL = X - leftBounds.x;
// right figure width
int wR = rightBounds.getTopRight().x - X - separator.getSashWidth();
int xR = X + separator.getSashWidth();
if (wL < separator.getZoneMinSize()) {
wL = separator.getZoneMinSize();
wR = rightBounds.getTopRight().x - leftBounds.x - separator.getZoneMinSize() - separator.getSashWidth();
xR = leftBounds.x + separator.getZoneMinSize() + separator.getSashWidth();
}
if (wR < separator.getZoneMinSize()) {
wL = rightBounds.getTopRight().x - separator.getZoneMinSize() - separator.getSashWidth() - leftBounds.x;
wR = separator.getZoneMinSize();
xR = rightBounds.getTopRight().x - separator.getZoneMinSize();
}
leftBounds.width = wL;
layout.setConstraint(separator.getLeftFigure(), leftBounds.getCopy());
separator.getLeftFigure().invalidateTree();
rightBounds.x = xR;
rightBounds.width = wR;
layout.setConstraint(separator.getRightFigure(), rightBounds.getCopy());
separator.getRightFigure().invalidateTree();
separator.getParentFigure().revalidate();
}
} else if (s instanceof ColumnSash) {
ColumnSash columnSash = (ColumnSash) s;
ITable t = columnSash.getTable();
// if (t instanceof AbstractTable) {
// AbstractTable table = (AbstractTable) t;
// Rectangle tableBounds = table.getBounds();
// int X = getDropLocation().x;
// if (X < tableBounds.x + columnSash.getSashWidth()
// || X > tableBounds.x + tableBounds.width - columnSash.getSashWidth()) {
// event.detail = DND.DROP_NONE;
// return;
// }
//
// double newExpressionWidth = X - tableBounds.x;
//
// double defaultExpressionWidth = table.getDefaultExpressionWidth();
// double pecnetage = newExpressionWidth / defaultExpressionWidth;
// table.setExpressWidthPecentage(pecnetage);
// } else if (t instanceof Table) {
AbstractTable table = (AbstractTable) t;
Rectangle tableBounds = table.getBounds();
int X = getDropLocation().x;
if (X < tableBounds.x + 10 || X > tableBounds.x + tableBounds.width - 10) {
event.detail = DND.DROP_NONE;
return;
}
TableColumn leftColumn = columnSash.getLeftColumn();
TableColumn rightColumn = columnSash.getRightColumn();
Rectangle leftBounds = leftColumn.getBounds();
Rectangle rightBounds = rightColumn.getBounds();
int LW = X - leftBounds.x;
int RW = rightBounds.x + rightBounds.width - X;
if (LW < 10) {
LW = 10;
}
if (RW < 10) {
RW = 10;
}
double LP = (double) LW / (double) tableBounds.width;
double RP = (double) RW / (double) tableBounds.width;
table.getLayoutManager().setColumnPercentage(leftColumn.getColumnKey(), LP);
table.getLayoutManager().setColumnPercentage(rightColumn.getColumnKey(), RP);
table.invalidateTree();
table.revalidate();
}
// }
}
use of org.talend.designer.gefabstractmap.figures.table.ColumnSash in project tdi-studio-se by Talend.
the class TableLayout method layout.
@Override
public void layout(IFigure container) {
Rectangle clientArea = container.getClientArea();
IFigure tableContainer = getTableContainer(container);
int containerWidth = tableContainer.getBounds().width;
int clientWidth = clientArea.width;
if (ajustToDefaultWidth) {
clientWidth = containerWidth;
}
initColumnPercentage(clientWidth, containerWidth);
int columnNum = columns.size();
int toltalWidth = 0;
Dimension[] prefSizes = new Dimension[columnNum];
int titleHeight = 0;
for (int i = 0; i < columnNum; i++) {
TableColumn column = columns.get(i);
prefSizes[i] = column.getPreferredSize();
titleHeight = Math.max(titleHeight, prefSizes[i].height);
}
int X = clientArea.x;
int Y = clientArea.y;
int previousSashOccupied = 0;
for (int i = 0; i < columns.size(); i++) {
TableColumn currentColumn = columns.get(i);
ColumnSash sash = null;
if (i < columns.size() - 1) {
sash = separators.get(i);
}
Double percent = keyAndPercentage.get(currentColumn.getColumnKey());
int width = (int) Math.round(clientWidth * percent);
if (sash != null) {
int halfSashWidth = sash.getSashWidth() / 2;
toltalWidth += width;
Rectangle newBounds = new Rectangle(X, Y, width - halfSashWidth - previousSashOccupied, titleHeight);
currentColumn.setBounds(newBounds);
keyAndLength.put(currentColumn.getColumnKey(), width);
X += newBounds.width;
// don't add sash width to total width
newBounds = new Rectangle(X, Y, sash.getSashWidth(), titleHeight);
sash.setBounds(newBounds);
X += newBounds.width;
previousSashOccupied = halfSashWidth;
} else {
Rectangle newBounds = new Rectangle(X, Y, width - previousSashOccupied, titleHeight);
currentColumn.setBounds(newBounds);
keyAndLength.put(currentColumn.getColumnKey(), width);
toltalWidth += width;
}
}
// in case some blank width
if (toltalWidth != 0) {
int diff = clientWidth - toltalWidth;
if (diff < 0) {
diff = 0;
}
int avg = diff / columnNum;
int remainder = diff % columnNum;
if (avg != 0) {
for (int i = 0; i < columnNum; i++) {
TableColumn tableColumn = columns.get(i);
Rectangle copy = tableColumn.getBounds().getCopy();
if (i > 0) {
copy.x += avg * i;
}
copy.width += avg;
tableColumn.setBounds(copy);
keyAndLength.put(tableColumn.getColumnKey(), keyAndLength.get(tableColumn.getColumnKey()) + avg);
if (i < separators.size()) {
ColumnSash separator = separators.get(i);
copy = separator.getBounds().getCopy();
copy.x += avg * (i + 1);
separator.setBounds(copy);
}
}
}
if (remainder != 0) {
TableColumn lastChild = columns.get(columns.size() - 1);
final Rectangle bounds = lastChild.getBounds();
bounds.width = bounds.width + remainder;
lastChild.setBounds(bounds);
keyAndLength.put(lastChild.getColumnKey(), keyAndLength.get(lastChild.getColumnKey()) + remainder);
}
}
Dimension itemContainerSize = tableItemContainer.getPreferredSize();
Rectangle newBounds = new Rectangle(clientArea.x, clientArea.y + titleHeight, clientWidth, itemContainerSize.height);
tableItemContainer.setBounds(newBounds);
}
use of org.talend.designer.gefabstractmap.figures.table.ColumnSash in project tdi-studio-se by Talend.
the class XmlMapTableTree method createColumns.
@Override
protected void createColumns() {
layoutManager.setAjustToTableWidth(false);
// table column title
MapperTable xmlTree = tableModelManager.getModel();
boolean hasExpression = false;
if (xmlTree instanceof InputXmlTree) {
InputXmlTree inputTree = (InputXmlTree) xmlTree;
if (inputTree.isLookup()) {
expressionColumn = new TableColumn(ColumnKeyConstant.KEY_EXPRESSION);
expressionColumn.setText("Exp.key");
this.addColumn(expressionColumn);
columnSash = new ColumnSash(this);
columnSash.setLeftColumn(expressionColumn);
this.addSeparator(columnSash);
hasExpression = true;
}
} else {
expressionColumn = new TableColumn(ColumnKeyConstant.KEY_EXPRESSION);
expressionColumn.setText("Expression");
this.addColumn(expressionColumn);
columnSash = new ColumnSash(this);
columnSash.setLeftColumn(expressionColumn);
this.addSeparator(columnSash);
hasExpression = true;
}
nameColumn = new TableColumn(ColumnKeyConstant.KEY_NAME);
nameColumn.setText("Column");
if (columnSash != null) {
columnSash.setRightColumn(nameColumn);
}
this.addColumn(nameColumn);
if (hasExpression) {
layoutManager.setWeight(0, 0.5);
}
}
use of org.talend.designer.gefabstractmap.figures.table.ColumnSash in project tdi-studio-se by Talend.
the class GlobalMapKeysTable method createColumns.
/*
* (non-Javadoc)
*
* @see org.talend.designer.gefabstractmap.figures.table.AbstractTable#createColumns()
*/
@Override
protected void createColumns() {
layoutManager.setAjustToTableWidth(false);
if (inputxmlTree != null && inputxmlTree.isLookup()) {
expressionColumn = new TableColumn(ColumnKeyConstant.KEY_EXPRESSION);
expressionColumn.setText(Messages.getString("InputTreeGlobalMapKeysTable.expressionTitle"));
addColumn(expressionColumn);
columnSash = new ColumnSash(this);
columnSash.setLeftColumn(expressionColumn);
addSeparator(columnSash);
globalMapKeyColumn = new TableColumn(ColumnKeyConstant.KEY_NAME);
globalMapKeyColumn.setText(Messages.getString("InputTreeGlobalMapKeysTable.globalMapKeyTitle"));
columnSash.setRightColumn(globalMapKeyColumn);
addColumn(globalMapKeyColumn);
columnSash = new ColumnSash(this);
columnSash.setLeftColumn(globalMapKeyColumn);
addSeparator(columnSash);
addColumn = new TableColumn(ColumnKeyConstant.KEY_VARIABLE);
addColumn.setIcon(ImageProviderMapper.getImage(ImageInfo.ADD));
addColumn.setLabelAlignment(PositionConstants.BOTTOM);
columnSash.setRightColumn(addColumn);
addColumn.setBorder(new MarginBorder(2));
addColumn(addColumn);
// add Listener
addColumn.addMouseListener(new MouseListener() {
@Override
public void mousePressed(MouseEvent me) {
GlobalMapNode defaultGlobalMapNode = XmlmapFactory.eINSTANCE.createGlobalMapNode();
defaultGlobalMapNode.setExpression("");
defaultGlobalMapNode.setName("\"myKey\"");
inputxmlTree.getGlobalMapKeysValues().add(defaultGlobalMapNode);
}
@Override
public void mouseReleased(MouseEvent me) {
}
@Override
public void mouseDoubleClicked(MouseEvent me) {
}
});
}
}
use of org.talend.designer.gefabstractmap.figures.table.ColumnSash in project tdi-studio-se by Talend.
the class OutputTreeSettingTable method createColumns.
/*
* (non-Javadoc)
*
* @see org.talend.designer.newabstractmap.figures.table.AbstractTable#createColumns()
*/
@Override
protected void createColumns() {
TableColumn column = new TableColumn(ColumnKeyConstant.TREE_SETTING_PROPERTY);
column.setText("Property");
addColumn(column);
ColumnSash sash = new ColumnSash(this);
sash.setLeftColumn(column);
addSeparator(sash);
column = new TableColumn(ColumnKeyConstant.TREE_SETTING_VALUE);
column.setText("Value");
sash.setRightColumn(column);
addColumn(column);
settingsContainer = getTableItemContainer();
rejectRow = new Figure();
rejectRow.setLayoutManager(new RowLayout());
Label label = new Label();
label.setText("Catch Output Reject");
label.setLabelAlignment(PositionConstants.LEFT);
CompoundBorder compoundBorder = new CompoundBorder(new ColumnBorder(), new RowBorder(2, 5, 2, -1));
label.setBorder(compoundBorder);
rejectRow.add(label);
reject = new ComboCellLabel();
reject.setDirectEditType(DirectEditType.OUTPUT_REJECT);
reject.setText(String.valueOf(outputxmlTree.isReject()));
reject.setLabelAlignment(PositionConstants.LEFT);
reject.setBorder(new RowBorder(2, 5, 2, -1));
rejectRow.add(reject);
settingsContainer.add(rejectRow);
innerJoinRejectRow = new Figure();
innerJoinRejectRow.setLayoutManager(new RowLayout());
label = new Label();
label.setText("Catch Lookup Inner Join Reject");
label.setLabelAlignment(PositionConstants.LEFT);
compoundBorder = new CompoundBorder(new ColumnBorder(), new RowBorder(2, 5, 2, -1));
label.setBorder(compoundBorder);
innerJoinRejectRow.add(label);
innerJoinReject = new ComboCellLabel();
innerJoinReject.setDirectEditType(DirectEditType.LOOK_UP_INNER_JOIN_REJECT);
innerJoinReject.setText(String.valueOf(outputxmlTree.isRejectInnerJoin()));
innerJoinReject.setLabelAlignment(PositionConstants.LEFT);
innerJoinReject.setBorder(new RowBorder(2, 5, 2, -1));
innerJoinRejectRow.add(innerJoinReject);
settingsContainer.add(innerJoinRejectRow);
allInOneRow = new Figure();
allInOneRow.setLayoutManager(new RowLayout());
label = new Label();
label.setText("All in one");
label.setLabelAlignment(PositionConstants.LEFT);
compoundBorder = new CompoundBorder(new ColumnBorder(), new RowBorder(2, 5, 2, -1));
label.setBorder(compoundBorder);
allInOneRow.add(label);
allInOne = new ComboCellLabel();
allInOne.setDirectEditType(DirectEditType.ALL_IN_ONE);
allInOne.setText(String.valueOf(outputxmlTree.isAllInOne()));
allInOne.setLabelAlignment(PositionConstants.LEFT);
allInOne.setBorder(new RowBorder(2, 5, 2, -1));
allInOneRow.add(allInOne);
// container.add(allInOneRow);
enableEmptyElementRow = new Figure();
enableEmptyElementRow.setLayoutManager(new RowLayout());
label = new Label();
label.setText("Create empty element");
label.setLabelAlignment(PositionConstants.LEFT);
compoundBorder = new CompoundBorder(new ColumnBorder(), new RowBorder(2, 5, 2, -1));
label.setBorder(compoundBorder);
enableEmptyElementRow.add(label);
enableEmptyElement = new ComboCellLabel();
enableEmptyElement.setDirectEditType(DirectEditType.ENABLE_EMPTY_ELEMENT);
enableEmptyElement.setText(String.valueOf(outputxmlTree.isEnableEmptyElement()));
enableEmptyElement.setLabelAlignment(PositionConstants.LEFT);
enableEmptyElement.setBorder(new RowBorder(2, 5, 2, -1));
enableEmptyElementRow.add(enableEmptyElement);
// container.add(enableEmptyElementRow);
showOrHideDocumentSetting();
settingsContainer.setOpaque(true);
settingsContainer.setBackgroundColor(ColorConstants.white);
// show selection
settingsContainer.addMouseListener(new MouseListener() {
Figure selectedFigure = null;
@Override
public void mousePressed(MouseEvent me) {
boolean joinModel = rejectRow.containsPoint(me.x, me.y);
if (joinModel) {
if (selectedFigure != rejectRow) {
rejectRow.setBackgroundColor(ColorProviderMapper.getColor(ColorInfo.COLOR_COLUMN_TREE_SETTING));
rejectRow.setOpaque(true);
innerJoinRejectRow.setOpaque(false);
allInOneRow.setOpaque(false);
enableEmptyElementRow.setOpaque(false);
}
return;
}
boolean persistentModel = innerJoinRejectRow.containsPoint(me.x, me.y);
if (persistentModel) {
if (selectedFigure != innerJoinRejectRow) {
innerJoinRejectRow.setBackgroundColor(ColorProviderMapper.getColor(ColorInfo.COLOR_COLUMN_TREE_SETTING));
innerJoinRejectRow.setOpaque(true);
rejectRow.setOpaque(false);
allInOneRow.setOpaque(false);
enableEmptyElementRow.setOpaque(false);
}
return;
}
boolean allInOne = allInOneRow.containsPoint(me.x, me.y);
if (allInOne) {
if (selectedFigure != allInOneRow) {
allInOneRow.setBackgroundColor(ColorProviderMapper.getColor(ColorInfo.COLOR_COLUMN_TREE_SETTING));
allInOneRow.setOpaque(true);
rejectRow.setOpaque(false);
innerJoinRejectRow.setOpaque(false);
enableEmptyElementRow.setOpaque(false);
}
return;
}
boolean emptyElement = enableEmptyElementRow.containsPoint(me.x, me.y);
if (emptyElement) {
if (selectedFigure != enableEmptyElementRow) {
enableEmptyElementRow.setBackgroundColor(ColorProviderMapper.getColor(ColorInfo.COLOR_COLUMN_TREE_SETTING));
enableEmptyElementRow.setOpaque(true);
rejectRow.setOpaque(false);
innerJoinRejectRow.setOpaque(false);
allInOneRow.setOpaque(false);
}
}
}
@Override
public void mouseReleased(MouseEvent me) {
}
@Override
public void mouseDoubleClicked(MouseEvent me) {
}
});
}
Aggregations