use of org.eclipse.draw2d.IFigure in project tdi-studio-se by Talend.
the class ComponentChooseDialog method createNewComponent.
public void createNewComponent(DropTargetEvent event1) {
boolean quickCreateInput = event1.detail == DND.DROP_LINK;
boolean quickCreateOutput = event1.detail == DND.DROP_COPY;
Iterator iterator = getSelection().iterator();
List<TempStore> list = new ArrayList<TempStore>();
List<IComponent> components = new ArrayList<IComponent>();
while (iterator.hasNext()) {
Object obj = iterator.next();
if (obj instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) obj;
if (equalsJobInCurrentEditor(sourceNode)) {
continue;
}
Item item = sourceNode.getObject().getProperty().getItem();
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
if (testContainerService != null && testContainerService.isTestContainerItem(item)) {
continue;
}
}
ERepositoryObjectType type = sourceNode.getObjectType();
if (!(item instanceof ConnectionItem) && !(item instanceof ProcessItem) && !(item instanceof JobletProcessItem) && !(item instanceof RulesItem) && !(item instanceof LinkRulesItem)) {
// RulesItem
return;
}
{
/**
* Remove this limitation for feature: TDI-32362, I think it should be ok, don't know why adding
* this limitation to forbid to d&d salseforce connection, I keep those code in case this behavior
* will cause some bugs when d&d salseforce connection, then maybe need to review
*/
// if (item instanceof SalesforceSchemaConnectionItem && type ==
// ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA) {
// return;
// }
}
TempStore store = new TempStore();
store.seletetedNode = sourceNode;
getAppropriateComponent(item, quickCreateInput, quickCreateOutput, store, type);
if (store.component != null) {
list.add(store);
} else {
MessageDialog.openInformation(editor.getEditorSite().getShell(), //$NON-NLS-1$
Messages.getString("TalendEditorDropTargetListener.dngsupportdialog.title"), //$NON-NLS-1$
Messages.getString("TalendEditorDropTargetListener.dngsupportdialog.content"));
}
}
org.eclipse.swt.graphics.Point swtLocation = new org.eclipse.swt.graphics.Point(event1.x, event1.y);
Canvas canvas = (Canvas) editor.getViewer().getControl();
/*
* translate to Canvas coordinate
*/
swtLocation = canvas.toControl(swtLocation);
org.eclipse.swt.graphics.Point size = canvas.getSize();
/*
* translate to Viewport coordinate with zoom
*/
org.eclipse.draw2d.geometry.Point draw2dPosition = new org.eclipse.draw2d.geometry.Point(swtLocation.x, swtLocation.y);
/*
* calcule the view port position. Take into acounte the scroll position
*/
ProcessPart part = (ProcessPart) editor.getViewer().getRootEditPart().getRoot().getChildren().get(0);
IFigure targetFigure = part.getFigure();
translateAbsolateToRelative(targetFigure, draw2dPosition);
//$NON-NLS-1$
String lastUniqname = "";
// creates every node
for (TempStore store : list) {
RepositoryNode selectedNode = store.seletetedNode;
IComponent element = store.component;
if (!components.contains(element)) {
components.add(element);
}
Node node = new Node(element);
// for bug4564(metadata label format)
// IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
// if (preferenceStore.getBoolean(TalendDesignerPrefConstants.USE_REPOSITORY_NAME)) {
// node.setPropertyValue(EParameterName.LABEL.getName(), selectedNode.getObject().getLabel());
// }
IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
if (preferenceStore.getBoolean(TalendDesignerPrefConstants.USE_REPOSITORY_NAME)) {
String LabelValue = null;
RepositoryNode repositoryNode = null;
repositoryNode = (RepositoryNode) getSelection().getFirstElement();
// dnd a table
IElementParameter dbTableParam = node.getElementParameterFromField(EParameterFieldType.DBTABLE);
boolean hasDbTableField = dbTableParam != null;
if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_TABLE && repositoryNode.getObject() != null && repositoryNode.getObject().getProperty().getItem() instanceof DatabaseConnectionItem && hasDbTableField) {
LabelValue = DesignerUtilities.getParameterVar(dbTableParam.getName());
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS || repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS_MR || repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS_STORM) {
// dnd a job
LabelValue = DesignerUtilities.getParameterVar(EParameterName.PROCESS);
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.JOBLET || repositoryNode.getObjectType() == ERepositoryObjectType.SPARK_JOBLET || repositoryNode.getObjectType() == ERepositoryObjectType.SPARK_STREAMING_JOBLET) {
LabelValue = element.getName();
} else if (CorePlugin.getDefault().getDesignerCoreService().getPreferenceStore(TalendDesignerPrefConstants.DEFAULT_LABEL).equals(node.getPropertyValue(EParameterName.LABEL.getName()))) {
// dnd a default
LabelValue = selectedNode.getObject().getLabel();
}
if (LabelValue != null) {
node.setPropertyValue(EParameterName.LABEL.getName(), LabelValue);
}
}
processSpecificDBTypeIfSameProduct(store.componentName, node);
NodeContainer nc = ((Process) node.getProcess()).loadNodeContainer(node, false);
;
// create component on link
boolean executed = false;
if (getSelection().size() == 1 && getTargetEditPart() instanceof SubjobContainerPart) {
executed = createComponentOnLink(node, draw2dPosition);
}
if (!executed) {
// create the node on the design sheet
execCommandStack(new CreateNodeContainerCommand((Process) editor.getProcess(), nc, draw2dPosition));
}
// initialize the propertiesView
CompoundCommand cc = new CompoundCommand();
createRefreshingPropertiesCommand(cc, selectedNode, node);
execCommandStack(cc);
// for (Command command : commands) {
// }
propaHadoopCfgChanges(selectedNode);
draw2dPosition = draw2dPosition.getCopy();
draw2dPosition.x += TalendEditor.GRID_SIZE;
draw2dPosition.y += TalendEditor.GRID_SIZE;
node.checkNode();
lastUniqname = node.getUniqueName();
}
// setselecte(part, lastUniqname);
}
// Shell shell = Display.getCurrent().getActiveShell();
// ModulesInstallerUtil.installModules(new Shell(shell), components);
}
use of org.eclipse.draw2d.IFigure in project tdi-studio-se by Talend.
the class ZoneContentLayout method layout.
@Override
public void layout(IFigure parent) {
Rectangle vBounds = null;
if (parent.getParent() instanceof Viewport) {
vBounds = ((Viewport) parent.getParent()).getBounds();
}
int wHint = -1;
int hHint = -1;
if (isHorizontal()) {
hHint = parent.getClientArea(Rectangle.SINGLETON).height;
} else {
wHint = parent.getClientArea(Rectangle.SINGLETON).width;
}
List children = parent.getChildren();
int numChildren = children.size();
Rectangle clientArea = transposer.t(parent.getClientArea());
int x = clientArea.x;
int y = clientArea.y;
int availableHeight = clientArea.height;
Dimension[] prefSizes = new Dimension[numChildren];
Dimension[] minSizes = new Dimension[numChildren];
IFigure child;
int totalHeight = 0;
int totalMinHeight = 0;
int prefMinSumHeight = 0;
int connSize = 0;
// boolean isLookupConnMax = true;
for (int i = 0; i < numChildren; i++) {
child = (IFigure) children.get(i);
prefSizes[i] = transposer.t(getChildPreferredSize(child, wHint, hHint));
minSizes[i] = transposer.t(getChildMinimumSize(child, wHint, hHint));
totalHeight += prefSizes[i].height;
totalMinHeight += minSizes[i].height;
if (child instanceof AbstractTableContainer) {
connSize = getLookupConnectionSize((AbstractTableContainer) child);
}
}
totalHeight += (numChildren - 1) * spacing;
totalMinHeight += (numChildren - 1) * spacing;
prefMinSumHeight = totalHeight - totalMinHeight;
int defaultSize = DEFAULT_OFFSET;
for (int i = 0; i < numChildren; i++) {
int amntShrinkCurrentHeight = 0;
int prefHeight = prefSizes[i].height;
int minHeight = minSizes[i].height;
int prefWidth = prefSizes[i].width;
int minWidth = minSizes[i].width;
child = (IFigure) children.get(i);
Rectangle newBounds = new Rectangle(x, y, prefWidth, prefHeight);
if (connSize > 0) {
newBounds = new Rectangle(x + (connSize - 1) * defaultSize, y, prefWidth, prefHeight);
}
Border border = parent.getBorder();
Insets insets = border.getInsets(child);
if (vBounds != null) {
newBounds.width = vBounds.width - insets.left - insets.right;
if (connSize > 0) {
newBounds.width = newBounds.width - (connSize - 1) * defaultSize;
}
}
newBounds.height -= amntShrinkCurrentHeight;
child.setBounds(transposer.t(newBounds));
prefMinSumHeight -= (prefHeight - minHeight);
y += newBounds.height + spacing;
}
}
use of org.eclipse.draw2d.IFigure in project tdi-studio-se by Talend.
the class ZoneToolBarLayout method layout.
@Override
public void layout(IFigure parent) {
List children = parent.getChildren();
int numChildren = children.size();
Rectangle clientArea = parent.getClientArea();
int x = clientArea.x + spacing;
int y = clientArea.y;
Dimension[] prefSizes = new Dimension[numChildren];
Dimension[] minSizes = new Dimension[numChildren];
int wHint = -1;
int hHint = -1;
if (isHorizontal()) {
hHint = parent.getClientArea(Rectangle.SINGLETON).height;
} else {
wHint = parent.getClientArea(Rectangle.SINGLETON).width;
}
IFigure child;
int totalHeight = 0;
int totalMinHeight = 0;
int maxHeight = 0;
for (int i = 0; i < numChildren; i++) {
child = (IFigure) children.get(i);
prefSizes[i] = getChildPreferredSize(child, wHint, hHint);
minSizes[i] = getChildMinimumSize(child, wHint, hHint);
totalHeight += prefSizes[i].height;
totalMinHeight += minSizes[i].height;
maxHeight = Math.max(maxHeight, prefSizes[i].height);
}
totalHeight += (numChildren - 1) * spacing;
totalMinHeight += (numChildren - 1) * spacing;
y = y + (clientArea.height - maxHeight) / 2;
for (int i = 0; i < numChildren; i++) {
int prefHeight = prefSizes[i].height;
int minHeight = minSizes[i].height;
int prefWidth = prefSizes[i].width;
Rectangle newBounds = new Rectangle(x, y, prefWidth, prefHeight);
child = (IFigure) children.get(i);
child.setBounds(newBounds);
x = x + newBounds.width + spacing;
}
}
use of org.eclipse.draw2d.IFigure in project tdi-studio-se by Talend.
the class RowSelectionEditPolicy method getLocatorFigure.
private IFigure getLocatorFigure(GraphicalEditPart owner) {
IFigure figure = owner.getFigure();
if (owner instanceof TableEntityPart) {
TableEntityFigure treeNodeFigure = (TableEntityFigure) figure;
// table figure to restrict the width
MapperTablePart abstractInOutTreePart = MapperUtils.getMapperTablePart((TableEntityPart) owner);
IFigure parentFigure = ((GraphicalEditPart) abstractInOutTreePart).getFigure();
Rectangle treeBounds = parentFigure.getBounds();
Rectangle rowBounds = treeNodeFigure.getElement().getBounds();
Rectangle treeNodeBounds = figure.getBounds();
figure = new Figure();
if (treeBounds.x + 1 != treeNodeBounds.x || treeNodeBounds.width > treeBounds.width) {
figure.setBounds(new Rectangle(treeBounds.x + 1, treeNodeBounds.y, treeBounds.width - 2, rowBounds.height));
return figure;
} else {
figure.setBounds(owner.getFigure().getBounds().getCopy());
figure.getBounds().height = rowBounds.height;
return figure;
}
} else if (figure instanceof VarEntityFigure) {
Rectangle copy = figure.getBounds().getCopy();
figure = new Figure();
figure.setBounds(copy);
return figure;
}
return owner.getFigure();
}
use of org.eclipse.draw2d.IFigure in project tdi-studio-se by Talend.
the class TableTreeEntityFigure method getContents.
@Override
public TreeAnimatingLayer getContents() {
if (this.contentPane == null) {
contentPane = new TreeAnimatingLayer() {
public void setBounds(Rectangle rect) {
int x = bounds.x, y = bounds.y;
boolean resize = (rect.width != bounds.width) || (rect.height != bounds.height), translate = (rect.x != x) || (rect.y != y);
if (isVisible() && (resize || translate))
erase();
if (translate) {
int dx = rect.x - x;
int dy = rect.y - y;
primTranslate(dx, dy);
}
bounds.width = rect.width;
bounds.height = rect.height;
if (resize)
invalidate();
if (resize || translate) {
fireFigureMoved();
fireCoordinateSystemChanged();
repaint();
}
}
};
ToolbarLayout layout = new ToolbarLayout() {
@Override
public void layout(IFigure parent) {
TreeAnimation.recordInitialState(parent);
if (TreeAnimation.playbackState(parent)) {
return;
}
super.layout(parent);
}
@Override
protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHint) {
return super.calculatePreferredSize(container, wHint, hHint);
}
};
layout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);
contentPane.setLayoutManager(layout);
this.add(contentPane);
// ///////test
// contentPane.setOpaque(true);
// contentPane.setBackgroundColor(ColorConstants.yellow);
}
return contentPane;
}
Aggregations