Search in sources :

Example 6 with PropertyChangeCommand

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

the class ExtraComposite method useProjectSettingButtonClick.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.designer.core.ui.views.jobsettings.AbstractPreferenceComposite#useProjectSettingButtonClick()
     */
@Override
protected void useProjectSettingButtonClick() {
    boolean flag = useProjectSetting.getSelection();
    setMainCompositeEnable(!flag);
    topComposite.setEnabled(true);
    ElementParameter2ParameterType.setParameterValue(pType, EParameterName.IMPLICITCONTEXT_USE_PROJECT_SETTINGS.getName(), Boolean.valueOf(flag));
    PropertyChangeCommand cmd = new PropertyChangeCommand(elem, EParameterName.IMPLICITCONTEXT_USE_PROJECT_SETTINGS.getName(), Boolean.valueOf(flag));
    getCommandStack().execute(cmd);
    updateContextValue(flag);
    if (flag) {
        useProjectSetting();
    }
}
Also used : PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)

Example 7 with PropertyChangeCommand

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

the class AbstractTraceAction method run.

@Override
public void run() {
    List selection = getSelectedObjects();
    Object input = selection.get(0);
    if (input instanceof ConnectionPart) {
        ConnectionPart connPart = (ConnectionPart) input;
        List childParts = connPart.getChildren();
        for (Object part : childParts) {
            if (part != null && part instanceof ConnectionTraceEditPart) {
                ConnectionTraceEditPart tracePart = (ConnectionTraceEditPart) part;
                Connection conn = (Connection) connPart.getModel();
                execute(new PropertyChangeCommand(conn, EParameterName.TRACES_CONNECTION_ENABLE.getName(), isEnableAction()));
                tracePart.refresh();
                break;
            }
        }
    }
    if (input instanceof ConnLabelEditPart) {
        ConnLabelEditPart labelPart = (ConnLabelEditPart) input;
        ConnectionPart connPart = (ConnectionPart) labelPart.getParent();
        List childParts = connPart.getChildren();
        for (Object part : childParts) {
            if (part != null && part instanceof ConnectionTraceEditPart) {
                ConnectionTraceEditPart tracePart = (ConnectionTraceEditPart) part;
                Connection conn = (Connection) connPart.getModel();
                execute(new PropertyChangeCommand(conn, EParameterName.TRACES_CONNECTION_ENABLE.getName(), isEnableAction()));
                tracePart.refresh();
                break;
            }
        }
    }
    if (input instanceof ConnectionTraceEditPart) {
        ConnectionTraceEditPart tracePart = (ConnectionTraceEditPart) input;
        ConnectionPart connPart = (ConnectionPart) tracePart.getParent();
        Connection conn = (Connection) connPart.getModel();
        execute(new PropertyChangeCommand(conn, EParameterName.TRACES_CONNECTION_ENABLE.getName(), isEnableAction()));
        tracePart.refresh();
    }
}
Also used : ConnectionTraceEditPart(org.talend.designer.core.ui.editor.connections.ConnectionTraceEditPart) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) Connection(org.talend.designer.core.ui.editor.connections.Connection) List(java.util.List) ConnectionPart(org.talend.designer.core.ui.editor.connections.ConnectionPart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)

Example 8 with PropertyChangeCommand

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

the class AbstractElementPropertySectionController method addDragAndDropTarget.

/**
     * Accept Text and StyledText control.
     *
     * @param labelText
     */
public void addDragAndDropTarget(final Control textControl) {
    DropTargetListener dropTargetListener = new DropTargetListener() {

        String propertyName = null;

        @Override
        public void dragEnter(final DropTargetEvent event) {
        }

        @Override
        public void dragLeave(final DropTargetEvent event) {
        }

        @Override
        public void dragOperationChanged(final DropTargetEvent event) {
        }

        @Override
        public void dragOver(final DropTargetEvent event) {
            if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
                propertyName = getParameterName(textControl);
                for (int i = 0; i < elem.getElementParameters().size(); i++) {
                    IElementParameter param = elem.getElementParameters().get(i);
                    if (param.getName().equals(propertyName)) {
                        if (param.isReadOnly()) {
                            event.detail = DND.ERROR_INVALID_DATA;
                        }
                    }
                }
            }
        }

        @Override
        public void drop(final DropTargetEvent event) {
            if (propertyName != null) {
                String text;
                if (textControl instanceof StyledText) {
                    text = ((StyledText) textControl).getText() + (String) event.data;
                    ((StyledText) textControl).setText(text);
                } else {
                    text = ((Text) textControl).getText() + (String) event.data;
                    ((Text) textControl).setText(text);
                }
                Command cmd = new PropertyChangeCommand(elem, propertyName, text);
                // getCommandStack().execute(cmd);
                executeCommand(cmd);
            }
        }

        @Override
        public void dropAccept(final DropTargetEvent event) {
        }
    };
    DropTarget target = new DropTarget(textControl, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
    Transfer[] transfers = new Transfer[] { TextTransfer.getInstance() };
    target.setTransfer(transfers);
    target.addDropListener(dropTargetListener);
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ReconcilerStyledText(org.talend.designer.core.ui.viewer.ReconcilerStyledText) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) Command(org.eclipse.gef.commands.Command) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) IElementParameter(org.talend.core.model.process.IElementParameter) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) ReconcilerStyledText(org.talend.designer.core.ui.viewer.ReconcilerStyledText) DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 9 with PropertyChangeCommand

use of org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand 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 10 with PropertyChangeCommand

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

the class ComponentListController method updateComponentList.

protected static void updateComponentList(Collection<INode> nodeList, INode currentNode, IElementParameter param, boolean isSelectDefaultItem) {
    final Collection<String> componentDisplayNames = new ArrayList<String>();
    final Collection<String> componentUniqueNames = new ArrayList<String>();
    for (INode node : nodeList) {
        if (node.getJobletNode() != null) {
            node = node.getJobletNode();
        }
        final String uniqueName = node.getUniqueName();
        if (uniqueName.equals(currentNode.getUniqueName())) {
            continue;
        }
        //$NON-NLS-1$
        String displayName = (String) node.getElementParameter("LABEL").getValue();
        if (displayName == null) {
            displayName = uniqueName;
        }
        if (displayName.indexOf("__UNIQUE_NAME__") != -1) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            displayName = displayName.replaceAll("__UNIQUE_NAME__", uniqueName);
        }
        if (!displayName.equals(uniqueName)) {
            //$NON-NLS-1$
            displayName = uniqueName + " - " + displayName;
        }
        componentUniqueNames.add(uniqueName);
        componentDisplayNames.add(displayName);
    }
    param.setListItemsDisplayName(componentDisplayNames.toArray(new String[0]));
    final String[] componentValueList = componentUniqueNames.toArray(new String[0]);
    param.setListItemsValue(componentValueList);
    Object value = param.getValue();
    if (!componentUniqueNames.contains(value) && isSelectDefaultItem) {
        String newValue = null;
        if (!param.isDynamicSettings()) {
            if (!componentUniqueNames.isEmpty()) {
                if (value == null || value.equals("")) {
                    //$NON-NLS-1$
                    currentNode.setPropertyValue(getParameterName(param), componentValueList[0]);
                    if (currentNode instanceof IGraphicalNode) {
                        IGraphicalNode node = (IGraphicalNode) currentNode;
                        node.checkAndRefreshNode();
                        ((IProcess2) node.getProcess()).setProcessModified(true);
                    } else if (currentNode instanceof IConnection) {
                        ((IProcess2) ((IConnection) currentNode).getSource().getProcess()).setProcessModified(true);
                    }
                } else {
                    newValue = componentValueList[0];
                }
            } else {
                // removed the old value.
                //$NON-NLS-1$
                newValue = "";
            }
        }
        if (!("".equals(newValue)) && newValue != null) {
            //$NON-NLS-1$
            IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
            if (part instanceof AbstractMultiPageTalendEditor) {
                AbstractTalendEditor te = ((AbstractMultiPageTalendEditor) part).getTalendEditor();
                CommandStack cmdStack = (CommandStack) te.getAdapter(CommandStack.class);
                cmdStack.execute(new PropertyChangeCommand(currentNode, getParameterName(param), ""));
            }
        }
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) INode(org.talend.core.model.process.INode) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) IEditorPart(org.eclipse.ui.IEditorPart) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) AbstractTalendEditor(org.talend.designer.core.ui.editor.AbstractTalendEditor) IProcess2(org.talend.core.model.process.IProcess2)

Aggregations

PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)69 IElementParameter (org.talend.core.model.process.IElementParameter)34 Command (org.eclipse.gef.commands.Command)24 Point (org.eclipse.swt.graphics.Point)18 INode (org.talend.core.model.process.INode)18 Node (org.talend.designer.core.ui.editor.nodes.Node)18 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)16 Control (org.eclipse.swt.widgets.Control)14 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)13 RepositoryNode (org.talend.repository.model.RepositoryNode)12 CCombo (org.eclipse.swt.custom.CCombo)11 IConnection (org.talend.core.model.process.IConnection)11 ConnectionItem (org.talend.core.model.properties.ConnectionItem)11 ArrayList (java.util.ArrayList)10 List (java.util.List)10 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)10 Item (org.talend.core.model.properties.Item)10 Button (org.eclipse.swt.widgets.Button)9 Text (org.eclipse.swt.widgets.Text)8 MetadataTable (org.talend.core.model.metadata.MetadataTable)8