Search in sources :

Example 36 with Connection

use of org.talend.designer.core.ui.editor.connections.Connection in project tdi-studio-se by Talend.

the class NodesMoveCommond method undo.

@SuppressWarnings("unchecked")
@Override
public void undo() {
    // remove the current selection
    AbstractMultiPageTalendEditor multiPageTalendEditor = (AbstractMultiPageTalendEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    GraphicalViewer viewer = multiPageTalendEditor.getTalendEditor().getViewer();
    if (!multipleCommand) {
        viewer.deselectAll();
    }
    for (NodeContainer nodeContainer : nodeContainerList) {
        // remove the connections name from the list
        for (Connection connection : (List<Connection>) nodeContainer.getNode().getOutgoingConnections()) {
            process.removeUniqueConnectionName(connection.getName());
        }
        ((Process) process).removeNodeContainer(nodeContainer);
    }
    // check that the created connections are removed, remove them if not
    for (String newConnectionName : createdNames) {
        if (!process.checkValidConnectionName(newConnectionName, true)) {
            process.removeUniqueConnectionName(newConnectionName);
        }
    }
    process.checkStartNodes();
    process.checkProcess();
    // set the old selection active
    if (!multipleCommand) {
        StructuredSelection s = new StructuredSelection(oldSelection);
        viewer.setSelection(s);
    }
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) List(java.util.List) ArrayList(java.util.ArrayList) IProcess(org.talend.core.model.process.IProcess) Process(org.talend.designer.core.ui.editor.process.Process)

Example 37 with Connection

use of org.talend.designer.core.ui.editor.connections.Connection in project tdi-studio-se by Talend.

the class AbstractSchemaController method createComboCommand.

@Override
protected Command createComboCommand(CCombo combo) {
    IMetadataTable repositoryMetadata = null;
    String fullParamName = (String) combo.getData(PARAMETER_NAME);
    IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    //$NON-NLS-1$
    String value = new String("");
    IElementParameter param = elem.getElementParameter(fullParamName);
    for (int j = 0; j < param.getListItemsValue().length; j++) {
        if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
            value = (String) param.getListItemsValue()[j];
        }
    }
    // if change to build-in, unuse the validation rule if the component has.
    boolean isValRulesLost = false;
    IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(elem);
    if (value.equals(EmfComponent.BUILTIN) && currentValRuleObj != null) {
        if (!MessageDialog.openConfirm(combo.getShell(), //$NON-NLS-1$
        Messages.getString("AbstractSchemaController.validationrule.title.confirm"), Messages.getString("AbstractSchemaController.validationrule.selectBuildInMsg"))) {
            //$NON-NLS-1$
            return null;
        } else {
            isValRulesLost = true;
        }
    }
    org.talend.core.model.metadata.builder.connection.Connection connection = null;
    if (elem instanceof Node) {
        Node node = (Node) elem;
        Command baseCommand = null;
        boolean isReadOnly = false;
        String newRepositoryIdValue = null;
        if (node.getMetadataFromConnector(param.getContext()) != null) {
            isReadOnly = node.getMetadataFromConnector(param.getContext()).isReadOnly();
        }
        if (//$NON-NLS-1$
        value.equals(EmfComponent.BUILTIN) && isReadOnly && !"tLogCatcher".equals(node.getComponent().getName()) && !"tStatCatcher".equals(node.getComponent().getName())) {
            //$NON-NLS-1$
            boolean hasMetadataInput = false;
            if (node.getCurrentActiveLinksNbInput(EConnectionType.FLOW_MAIN) > 0 || node.getCurrentActiveLinksNbInput(EConnectionType.TABLE) > 0) {
                hasMetadataInput = true;
            }
            repositoryMetadata = new MetadataTable();
            if (hasMetadataInput) {
                for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
                    if (connec.isActivate() && (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connec.getLineStyle().equals(EConnectionType.TABLE))) {
                        repositoryMetadata = connec.getMetadataTable().clone();
                    }
                }
            }
        } else if (value.equals(EmfComponent.REPOSITORY)) {
            // Map<String, IMetadataTable> repositoryTableMap = dynamicProperty.getRepositoryTableMap();
            IElementParameter property = ((Node) elem).getElementParameter(EParameterName.PROPERTY_TYPE.getName());
            if ((property != null) && EmfComponent.REPOSITORY.equals(property.getValue())) {
                String propertySelected = (String) ((Node) elem).getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue();
                IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                /* 16969 */
                Item item = null;
                try {
                    IRepositoryViewObject repobj = factory.getLastVersion(propertySelected);
                    if (repobj != null) {
                        Property tmpproperty = repobj.getProperty();
                        if (tmpproperty != null) {
                            item = tmpproperty.getItem();
                        }
                    }
                // item = factory.getLastVersion(propertySelected).getProperty().getItem();
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
                if (item != null && item instanceof ConnectionItem) {
                    final ConnectionItem connectionItem = (ConnectionItem) item;
                    if (connectionItem != null) {
                        connection = connectionItem.getConnection();
                    }
                }
            }
            IElementParameter repositorySchemaType = param.getParentParameter().getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
            String schemaSelected = (String) repositorySchemaType.getValue();
            if (schemaSelected == null) {
                //$NON-NLS-1$
                schemaSelected = "";
            }
            /* value can be devided means the value like "connectionid - label" */
            //$NON-NLS-1$
            String[] keySplitValues = schemaSelected.toString().split(" - ");
            if (keySplitValues.length > 1) {
                String connectionId = keySplitValues[0];
                String tableLabel = keySplitValues[1];
                IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                Item item = null;
                try {
                    IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
                    if (repobj != null) {
                        Property tmpproperty = repobj.getProperty();
                        if (tmpproperty != null) {
                            item = tmpproperty.getItem();
                        }
                    }
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
                if (item != null && item instanceof ConnectionItem) {
                    final ConnectionItem connectionItem = (ConnectionItem) item;
                    if (connectionItem != null) {
                        connection = connectionItem.getConnection();
                    }
                }
                if (item != null && item instanceof ConnectionItem) {
                    boolean findTable = false;
                    Set<org.talend.core.model.metadata.builder.connection.MetadataTable> tables = null;
                    IGenericWizardService wizardService = null;
                    if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
                        wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
                    }
                    if (wizardService != null && wizardService.isGenericItem(item)) {
                        tables = new HashSet<>(wizardService.getMetadataTables(connection));
                    } else {
                        tables = ConnectionHelper.getTables(connection);
                    }
                    for (org.talend.core.model.metadata.builder.connection.MetadataTable table : tables) {
                        if (table.getLabel().equals(tableLabel)) {
                            repositoryMetadata = ConvertionHelper.convert(table);
                            newRepositoryIdValue = schemaSelected;
                            findTable = true;
                            break;
                        }
                    }
                    if (!findTable) {
                        repositoryMetadata = new MetadataTable();
                    }
                } else {
                    repositoryMetadata = new MetadataTable();
                }
            } else {
                // value only got a empty string
                repositoryMetadata = new MetadataTable();
            }
        } else {
            baseCommand = new PropertyChangeCommand(elem, fullParamName, value);
        }
        if (switchParam != null) {
            switchParam.setValue(Boolean.FALSE);
        }
        CompoundCommand cc = new CompoundCommand();
        if (baseCommand != null) {
            cc.add(baseCommand);
        } else {
            RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) elem, fullParamName, value, repositoryMetadata, newRepositoryIdValue, null);
            changeMetadataCommand.setConnection(connection);
            cc.add(changeMetadataCommand);
        }
        // unuse the validation rules of the component.
        if (isValRulesLost) {
            ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, elem);
        }
        return cc;
    }
    return null;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) IGenericWizardService(org.talend.core.runtime.services.IGenericWizardService) List(java.util.List) ArrayList(java.util.ArrayList) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) HashSet(java.util.HashSet) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) Point(org.eclipse.swt.graphics.Point) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 38 with Connection

use of org.talend.designer.core.ui.editor.connections.Connection in project tdi-studio-se by Talend.

the class MergeOrderDialog method createDialogArea.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
     */
@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    Composite tableComposite = new Composite(composite, SWT.None);
    tableComposite.setLayout(new GridLayout());
    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.widthHint = WIDTH;
    gridData.minimumWidth = WIDTH;
    gridData.heightHint = HEIGHT;
    gridData.minimumHeight = HEIGHT;
    tableComposite.setLayoutData(gridData);
    final TableViewerCreator tableViewerCreator = new TableViewerCreator(tableComposite);
    tableViewerCreator.setBorderVisible(true);
    tableViewerCreator.setCheckboxInFirstColumn(false);
    tableViewerCreator.setColumnsResizableByDefault(true);
    tableViewerCreator.setColumnsSortableByDefault(true);
    tableViewerCreator.setLayoutMode(LAYOUT_MODE.FILL_HORIZONTAL);
    Table table = tableViewerCreator.createTable();
    table.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
    TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
    //$NON-NLS-1$
    column.setTitle(Messages.getString("MergeOrderDialog.Order"));
    column.setModifiable(true);
    column.setWidth(50);
    //$NON-NLS-1$
    column.setToolTipHeader(Messages.getString("MergeOrderDialog.CurrentOrderConnection"));
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<Connection, String>() {

        public String get(Connection bean) {
            return String.valueOf(connectionList.indexOf(bean) + 1);
        }

        public void set(Connection bean, String value) {
        // bean.setName(value);
        }
    });
    column = new TableViewerCreatorColumn(tableViewerCreator);
    //$NON-NLS-1$
    column.setTitle(Messages.getString("MergeOrderDialog.ConnectionName"));
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<Connection, String>() {

        public String get(Connection bean) {
            return getDisplayStr(bean);
        }

        public void set(Connection bean, String value) {
        // bean.setName(value);
        }
    });
    column.setModifiable(false);
    column.setWidth(200);
    tableViewerCreator.init(connectionList);
    Composite buttonComposite = new Composite(composite, SWT.None);
    buttonComposite.setLayout(new RowLayout(SWT.HORIZONTAL));
    Button moveUp = new Button(buttonComposite, SWT.PUSH);
    //$NON-NLS-1$
    moveUp.setToolTipText(Messages.getString("MergeOrderDialog.MoveUp"));
    moveUp.setImage(ImageProvider.getImage(EImage.UP_ICON));
    moveUp.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            IStructuredSelection selection = (IStructuredSelection) tableViewerCreator.getTableViewer().getSelection();
            Connection connection = (Connection) selection.getFirstElement();
            int connId = connectionList.indexOf(connection);
            if (connId > 0) {
                Collections.swap(connectionList, connId - 1, connId);
                tableViewerCreator.getTableViewer().refresh();
            }
        }
    });
    Button moveDown = new Button(buttonComposite, SWT.PUSH);
    //$NON-NLS-1$
    moveDown.setToolTipText(Messages.getString("MergeOrderDialog.MoveDown"));
    moveDown.setImage(ImageProvider.getImage(EImage.DOWN_ICON));
    if (getMergeNode() != null && getMergeNode().isReadOnly()) {
        moveUp.setEnabled(false);
        moveDown.setEnabled(false);
    }
    final int nbConn = getConnectionQty();
    moveDown.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            IStructuredSelection selection = (IStructuredSelection) tableViewerCreator.getTableViewer().getSelection();
            if (selection.size() > 0) {
                Connection connection = (Connection) selection.getFirstElement();
                int connId = connectionList.indexOf(connection);
                if (connId < (nbConn - 1)) {
                    Collections.swap(connectionList, connId + 1, connId);
                    tableViewerCreator.getTableViewer().refresh();
                }
            }
        }
    });
    return composite;
}
Also used : TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) Table(org.eclipse.swt.widgets.Table) Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)

Example 39 with Connection

use of org.talend.designer.core.ui.editor.connections.Connection in project tdi-studio-se by Talend.

the class NodeAnchor method getLocation.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.draw2d.ChopboxAnchor#getLocation(org.eclipse.draw2d.geometry.Point)
     */
@Override
public Point getLocation(Point reference) {
    if (target != null && !target.equals(source)) {
        sourceLocation = new Point(source.getLocation());
        targetLocation = new Point(target.getLocation());
        Point diff = new Point(0, 0);
        if (!isTargetAnchor) {
            if (((reference.y - (target.getSize().height / 2)) != targetLocation.y) || ((reference.x - (target.getSize().width / 2)) != targetLocation.x)) {
                FreeformViewport viewport = getViewport();
                if (viewport != null) {
                    int y = viewport.getVerticalRangeModel().getValue();
                    int x = viewport.getHorizontalRangeModel().getValue();
                    diff = new Point(-x, -y);
                }
            }
        } else {
            if (((reference.y - (source.getSize().height / 2)) != sourceLocation.y) || ((reference.x - (source.getSize().width / 2)) != sourceLocation.x)) {
                FreeformViewport viewport = getViewport();
                if (viewport != null) {
                    int y = viewport.getVerticalRangeModel().getValue();
                    int x = viewport.getHorizontalRangeModel().getValue();
                    diff = new Point(-x, -y);
                }
            }
        }
        ScalableFreeformLayeredPane pane = getScalableFreeform();
        sourceRect = new Rectangle(sourceLocation, source.getSize());
        targetRect = new Rectangle(targetLocation, target.getSize());
        if (pane != null) {
            double scale = pane.getScale();
            sourceLocation.performScale(scale);
            targetLocation.performScale(scale);
            sourceRect.performScale(scale);
            targetRect.performScale(scale);
        }
        sourceLocation = sourceLocation.getTranslated(diff);
        targetLocation = targetLocation.getTranslated(diff);
        sourceRect = sourceRect.getTranslated(diff);
        targetRect = targetRect.getTranslated(diff);
        int nb = 0;
        int connectionId = 0;
        for (Connection connection : (List<Connection>) source.getOutgoingConnections()) {
            if (connection.getTarget().equals(target)) {
                nb++;
                if (connection.equals(this.connection)) {
                    connectionId = nb;
                }
            }
        }
        if (nb <= 1) {
            return getLocationForSimpleConnection(reference);
        } else {
            return getLocationForMultipleConnections(connectionId);
        }
    }
    return super.getLocation(reference);
}
Also used : ScalableFreeformLayeredPane(org.eclipse.draw2d.ScalableFreeformLayeredPane) FreeformViewport(org.eclipse.draw2d.FreeformViewport) Rectangle(org.eclipse.draw2d.geometry.Rectangle) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) ArrayList(java.util.ArrayList) List(java.util.List) KeyPoint(org.talend.commons.ui.gmf.draw2d.LineSeg.KeyPoint) Point(org.eclipse.draw2d.geometry.Point) KeyPoint(org.talend.commons.ui.gmf.draw2d.LineSeg.KeyPoint) Point(org.eclipse.draw2d.geometry.Point)

Example 40 with Connection

use of org.talend.designer.core.ui.editor.connections.Connection in project tdi-studio-se by Talend.

the class NodeGraphicalEditPolicy method getReconnectTargetCommand.

@Override
protected Command getReconnectTargetCommand(ReconnectRequest request) {
    Connection conn = (Connection) request.getConnectionEditPart().getModel();
    Node newTarget = (Node) getHost().getModel();
    if (newTarget.isReadOnly()) {
        return null;
    }
    ConnectionReconnectCommand cmd = new ConnectionReconnectCommand(conn);
    cmd.setNewTarget(newTarget);
    return cmd;
}
Also used : Connection(org.talend.designer.core.ui.editor.connections.Connection) TalendDummyConnection(org.talend.designer.core.ui.editor.connections.TalendDummyConnection) ConnectionReconnectCommand(org.talend.designer.core.ui.editor.cmd.ConnectionReconnectCommand)

Aggregations

Connection (org.talend.designer.core.ui.editor.connections.Connection)84 IConnection (org.talend.core.model.process.IConnection)52 ArrayList (java.util.ArrayList)47 List (java.util.List)46 Node (org.talend.designer.core.ui.editor.nodes.Node)44 INode (org.talend.core.model.process.INode)35 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)28 Process (org.talend.designer.core.ui.editor.process.Process)24 IElementParameter (org.talend.core.model.process.IElementParameter)20 INodeConnector (org.talend.core.model.process.INodeConnector)18 HashMap (java.util.HashMap)12 IComponent (org.talend.core.model.components.IComponent)12 ConnectionPart (org.talend.designer.core.ui.editor.connections.ConnectionPart)12 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)11 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)11 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)10 Property (org.talend.core.model.properties.Property)10 Test (org.junit.Test)9 ConnLabelEditPart (org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)9 Map (java.util.Map)8