use of org.eclipse.gef.RootEditPart in project tdi-studio-se by Talend.
the class AbstractTalendEditor method selectPaletteEntry.
public void selectPaletteEntry(String componentName) {
PaletteViewer paletteViewer = getPaletteViewerProvider().getEditDomain().getPaletteViewer();
if (paletteViewer == null) {
return;
}
PaletteRoot root = getPaletteRoot();
RootEditPart part = paletteViewer.getRootEditPart();
if (part != null) {
collapsePalette(part.getChildren());
}
if (root != null) {
selectPaletteEntry(componentName, paletteViewer, root.getChildren());
}
}
use of org.eclipse.gef.RootEditPart in project tdi-studio-se by Talend.
the class MultiPageEditorContributor method setActivePage.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.part.MultiPageEditorActionBarContributor#setActivePage(org.eclipse.ui.IEditorPart)
*/
@Override
public void setActivePage(final IEditorPart activeEditor) {
if ((activeEditorPart == activeEditor) || (activeEditor == null)) {
return;
}
activeEditorPart = activeEditor;
if (activeEditor instanceof TalendEditor) {
RootEditPart editPart = ((TalendEditor) activeEditor).getViewer().getRootEditPart();
if (editPart != null && editPart instanceof TalendScalableFreeformRootEditPart) {
ZoomManager manager = ((TalendScalableFreeformRootEditPart) ((TalendEditor) activeEditor).getViewer().getRootEditPart()).getZoomManager();
item.setZoomManager(manager);
}
} else {
item.setZoomManager(null);
}
IActionBars actionBars = getActionBars();
if (actionBars != null) {
actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), getAction(activeEditor, ActionFactory.DELETE.getId()));
actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), getAction(activeEditor, ActionFactory.UNDO.getId()));
actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), getAction(activeEditor, ActionFactory.REDO.getId()));
actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), getAction(activeEditor, ActionFactory.CUT.getId()));
actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), getAction(activeEditor, ActionFactory.COPY.getId()));
actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), getAction(activeEditor, ActionFactory.PASTE.getId()));
actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), getAction(activeEditor, ActionFactory.SELECT_ALL.getId()));
actionBars.setGlobalActionHandler(ToggleSubjobsAction.ID, getAction(activeEditor, ToggleSubjobsAction.ID));
// see bug 0003656: Actions in the main menu "View" are always disabled.
activateActionsInViewMenu(activeEditor, actionBars, VIEW_MENU_ACTIONS_ID);
// MOD mzhao bug 8710
if (showAndRunProcessAction != null) {
actionBars.setGlobalActionHandler(showAndRunProcessAction.getActionDefinitionId(), showAndRunProcessAction);
}
actionBars.updateActionBars();
}
}
use of org.eclipse.gef.RootEditPart in project tdi-studio-se by Talend.
the class ProcessPart method getAdapter.
/*
* (non-Javadoc)
*
* @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#getAdapter(java.lang.Class)
*/
@Override
public Object getAdapter(final Class adapter) {
if (adapter.equals(RepositoryNode.class)) {
if (node == null) {
RootEditPart rootEditPart = getRoot();
if (rootEditPart instanceof TalendScalableFreeformRootEditPart) {
TalendScalableFreeformRootEditPart rootEditPart2 = (TalendScalableFreeformRootEditPart) rootEditPart;
IEditorInput editorInput = rootEditPart2.getEditorInput();
if (editorInput instanceof ProcessEditorInput) {
ProcessEditorInput processEditorInput = (ProcessEditorInput) editorInput;
node = processEditorInput.getRepositoryNode();
}
}
}
return node;
}
if (adapter == SnapToHelper.class) {
List<Object> snapStrategies = new ArrayList<Object>();
Boolean val = (Boolean) getViewer().getProperty(RulerProvider.PROPERTY_RULER_VISIBILITY);
val = (Boolean) getViewer().getProperty(NodeSnapToGeometry.PROPERTY_SNAP_ENABLED);
if (val != null && val.booleanValue()) {
snapStrategies.add(new NodeSnapToGeometry(this));
}
val = (Boolean) getViewer().getProperty(SnapToGrid.PROPERTY_GRID_ENABLED);
if (val != null && val.booleanValue()) {
snapStrategies.add(new SnapToGrid(this));
}
if (snapStrategies.size() == 0) {
return null;
}
if (snapStrategies.size() == 1) {
return snapStrategies.get(0);
}
SnapToHelper[] ss = new SnapToHelper[snapStrategies.size()];
for (int i = 0; i < snapStrategies.size(); i++) {
ss[i] = (SnapToHelper) snapStrategies.get(i);
}
return new CompoundSnapToHelper(ss);
}
return super.getAdapter(adapter);
}
use of org.eclipse.gef.RootEditPart in project tdi-studio-se by Talend.
the class ComponentChooseDialog method dragOver.
@Override
public void dragOver(DropTargetEvent event) {
// multi-drag for job,context, sqlPattern.
IStructuredSelection selection = getSelection();
if (selection.size() > 1) {
boolean allowed = true;
Item temItem = null;
Iterator iter = selection.iterator();
while (iter.hasNext()) {
Object next = iter.next();
if (next instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) next;
IRepositoryViewObject object = sourceNode.getObject();
if (object != null) {
Item selectItem = object.getProperty().getItem();
if (temItem == null) {
temItem = selectItem;
continue;
}
if (selectItem instanceof ProcessItem && !(temItem instanceof ProcessItem)) {
allowed = false;
} else if (selectItem instanceof ContextItem && !(temItem instanceof ContextItem)) {
allowed = false;
} else if (selectItem instanceof SQLPatternItem && !(temItem instanceof SQLPatternItem)) {
allowed = false;
}
}
}
}
if (!allowed) {
event.detail = DND.DROP_NONE;
}
} else {
CreateRequest req = ((CreateRequest) getTargetRequest());
Object o = null;
try {
o = req.getNewObject();
} catch (Exception e) {
return;
}
if (!(o instanceof Node)) {
return;
}
RootEditPart rep = editor.getViewer().getRootEditPart().getRoot();
Point viewOriginalPosition = new Point();
if (rep instanceof ScalableFreeformRootEditPart) {
ScalableFreeformRootEditPart root = (ScalableFreeformRootEditPart) rep;
Viewport viewport = (Viewport) root.getFigure();
viewOriginalPosition = viewport.getViewLocation();
}
org.eclipse.swt.graphics.Point swtLocation = new org.eclipse.swt.graphics.Point(event.x + viewOriginalPosition.x, event.y + viewOriginalPosition.y);
Canvas canvas = (Canvas) editor.getViewer().getControl();
swtLocation = canvas.toControl(swtLocation);
// System.out.println("topLeft:" + topLeftpoint + " / event:" + swtLocation);
org.eclipse.draw2d.geometry.Point draw2dPosition = new org.eclipse.draw2d.geometry.Point(swtLocation.x, swtLocation.y);
double zoom = 1.0;
if (editor.getViewer().getRootEditPart() instanceof TalendScalableFreeformRootEditPart) {
ZoomManager zoomManager = ((TalendScalableFreeformRootEditPart) editor.getViewer().getRootEditPart()).getZoomManager();
zoom = zoomManager.getZoom();
}
List<ConnectionPart> connectionParts = CreateComponentOnLinkHelper.getConnectionParts(editor.getProcessPart(), draw2dPosition, (Node) o);
double minDistance = 1000000000;
for (ConnectionPart part : connectionParts) {
if (part.getFigure() instanceof PolylineConnection) {
PolylineConnection connection = (PolylineConnection) part.getFigure();
double distance = CreateComponentOnLinkHelper.getDistanceOrthogonal(draw2dPosition.x, draw2dPosition.y, connection, zoom);
if (distance < minDistance) {
selectedConnectionPart = part;
minDistance = Math.min(distance, minDistance);
}
}
}
if (selectedConnectionPart != null && minDistance < 15) {
for (Object child : editor.getProcessPart().getChildren()) {
if (child instanceof SubjobContainerPart) {
CreateComponentOnLinkHelper.unselectAllConnections((SubjobContainerPart) child);
}
}
CreateComponentOnLinkHelper.selectConnection(selectedConnectionPart);
} else {
if (selectedConnectionPart != null) {
CreateComponentOnLinkHelper.unselectConnection(selectedConnectionPart);
}
selectedConnectionPart = null;
}
}
}
use of org.eclipse.gef.RootEditPart in project tdi-studio-se by Talend.
the class ComponentChooseDialog method createComponentOnLink.
private boolean createComponentOnLink(Node node, Point originalPoint) {
boolean executed = false;
RootEditPart rep = editor.getViewer().getRootEditPart().getRoot();
Point viewOriginalPosition = new Point();
if (rep instanceof ScalableFreeformRootEditPart) {
ScalableFreeformRootEditPart root = (ScalableFreeformRootEditPart) rep;
Viewport viewport = (Viewport) root.getFigure();
viewOriginalPosition = viewport.getViewLocation();
}
Point point = new Point(originalPoint.x + viewOriginalPosition.x, originalPoint.y + viewOriginalPosition.y);
point.x = (int) (point.x / AnimatableZoomManager.currentZoom);
point.y = (int) (point.y / AnimatableZoomManager.currentZoom);
org.talend.designer.core.ui.editor.connections.Connection targetConnection = null;
if (selectedConnectionPart != null) {
targetConnection = (org.talend.designer.core.ui.editor.connections.Connection) selectedConnectionPart.getModel();
}
if (targetConnection != null) {
IProcess2 p = editor.getProcess();
NodeContainer nodeContainer = ((Process) node.getProcess()).loadNodeContainer(node, false);
// TDI-21099
if (p instanceof Process) {
CreateNodeContainerCommand createCmd = new CreateNodeContainerCommand((Process) p, nodeContainer, point);
execCommandStack(createCmd);
// reconnect the node
Node originalTarget = (Node) targetConnection.getTarget();
EConnectionType connectionType = EConnectionType.FLOW_MAIN;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
if (camelService.isRouteBuilderNode(node)) {
connectionType = camelService.getTargetConnectionType(node);
}
}
INodeConnector targetConnector = node.getConnectorFromType(connectionType);
for (INodeConnector connector : node.getConnectorsFromType(connectionType)) {
if (connector.getMaxLinkOutput() != 0) {
targetConnector = connector;
break;
}
}
ConnectionCreateCommand.setCreatingConnection(true);
// bug 21411
if (PluginChecker.isJobLetPluginLoaded()) {
IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (service != null && service.isJobletComponent(targetConnection.getTarget())) {
if (targetConnection.getTarget() instanceof Node) {
NodeContainer jobletContainer = ((Node) targetConnection.getTarget()).getNodeContainer();
// remove the old connection in the container
jobletContainer.getInputs().remove(targetConnection);
}
}
}
ConnectionReconnectCommand cmd2 = new ConnectionReconnectCommand(targetConnection);
cmd2.setNewTarget(node);
execCommandStack(cmd2);
List<Object> nodeArgs = CreateComponentOnLinkHelper.getTargetArgs(targetConnection, node);
ConnectionCreateCommand nodeCmd = new ConnectionCreateCommand(node, targetConnector.getName(), nodeArgs, false);
nodeCmd.setTarget(originalTarget);
execCommandStack(nodeCmd);
// Setting,such as the target is TMap
if (node.getOutgoingConnections().size() > 0) {
if (node.getExternalNode() instanceof MapperExternalNode) {
CreateComponentOnLinkHelper.setupTMap(node);
}
if (originalTarget.getExternalNode() instanceof MapperExternalNode) {
CreateComponentOnLinkHelper.updateTMap(originalTarget, targetConnection, node.getOutgoingConnections().get(0));
}
originalTarget.renameData(targetConnection.getName(), node.getOutgoingConnections().get(0).getName());
}
if (!ConnectionCreateCommand.isCreatingConnection()) {
return true;
}
executed = true;
}
}
return executed;
}
Aggregations