Search in sources :

Example 66 with Command

use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.

the class DesignerCoreService method checkRepository.

/**
     * DOC hcw Comment method "checkRepository".
     *
     * @param node
     * @param item
     * @param stack
     */
private void checkRepository(final Node node, Item item, CommandStack stack) {
    final String updataComponentParamName = EParameterName.UPDATE_COMPONENTS.getName();
    final List<IElementParameter> repositoryParam = new ArrayList<IElementParameter>();
    for (IElementParameter param : node.getElementParameters()) {
        if (param.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE) || param.getFieldType().equals(EParameterFieldType.SCHEMA_REFERENCE)) {
            String value = (String) param.getChildParameters().get(EParameterName.SCHEMA_TYPE.getName()).getValue();
            if (value.equals(EmfComponent.REPOSITORY)) {
                IElementParameter schema = param.getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
                if (schema != null && schema.getValue() != null) {
                    //$NON-NLS-1$
                    String[] names = ((String) schema.getValue()).split(" - ");
                    if (names.length > 0) {
                        if (names[0].equals(item.getProperty().getId())) {
                            repositoryParam.add(schema);
                        }
                    }
                }
            }
        } else if (param.getFieldType().equals(EParameterFieldType.PROPERTY_TYPE)) {
            Object value = param.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).getValue();
            if (value.equals(EmfComponent.REPOSITORY)) {
                IElementParameter property = param.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
                if (property != null && property.getValue() != null) {
                    if (property.getValue().equals(item.getProperty().getId())) {
                        repositoryParam.add(property);
                    }
                }
            }
        }
    }
    if (repositoryParam.isEmpty()) {
        return;
    }
    stack.execute(new Command() {

        @Override
        public void execute() {
            node.setPropertyValue(updataComponentParamName, new Boolean(true));
            for (IElementParameter param : repositoryParam) {
                // force to reload label
                param.setListItemsDisplayName(new String[0]);
                param.setListItemsValue(new String[0]);
            }
        }
    });
}
Also used : Command(org.eclipse.gef.commands.Command) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 67 with Command

use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.

the class TNSEditorController method createCommand.

public Command createCommand(Button button) {
    IElementParameter elementParameter = this.curParameter.getElement().getElementParameter("TNS_FILE");
    Command command = null;
    if (elementParameter != null) {
        String filePath = new Path(PathExtractor.extractPath(elementParameter.getValue().toString())).toOSString();
        if (filePath != null && new File(filePath).exists()) {
            boolean flag = false;
            try {
                TnsParser tnsparser = new TnsParser(new File(filePath));
                if (tnsparser.getTree().getChildren().size() == 0) {
                    flag = true;
                }
            } catch (Exception e) {
                flag = true;
            }
            if (flag) {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openInformation(composite.getShell(), "WARNING", "this file is invalid,please recheck!");
                    }
                });
            } else {
                TnsEditorDialog tnsDialog = new TnsEditorDialog(composite.getShell(), new File(filePath));
                if (tnsDialog.open() == Window.OK) {
                    TnsInfo tnsInfo = tnsDialog.getTnsInfo();
                    command = new TnsPropertyCommand(tnsInfo, this.elem);
                }
            }
        } else {
            MessageBox mBox = new MessageBox(composite.getShell(), SWT.ICON_ERROR);
            //$NON-NLS-1$
            mBox.setText("Error");
            //$NON-NLS-1$
            mBox.setMessage("TNS File Not Found");
            mBox.open();
        }
    }
    return command;
}
Also used : Path(org.eclipse.core.runtime.Path) TnsPropertyCommand(org.talend.designer.core.ui.editor.properties.controllers.uidialog.tns.TnsPropertyCommand) TnsEditorDialog(org.talend.designer.core.ui.editor.properties.controllers.uidialog.tns.TnsEditorDialog) TnsParser(org.talend.designer.core.ui.editor.properties.controllers.uidialog.tns.TnsParser) MessageBox(org.eclipse.swt.widgets.MessageBox) TnsInfo(org.talend.designer.core.ui.editor.properties.controllers.uidialog.tns.TnsInfo) TnsPropertyCommand(org.talend.designer.core.ui.editor.properties.controllers.uidialog.tns.TnsPropertyCommand) Command(org.eclipse.gef.commands.Command) IElementParameter(org.talend.core.model.process.IElementParameter) File(java.io.File)

Example 68 with Command

use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.

the class NoteEditPart method performRequest.

@Override
public void performRequest(Request request) {
    Note note = (Note) getModel();
    if (note.isReadOnly()) {
        return;
    }
    if (request.getType() == RequestConstants.REQ_OPEN) {
        IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
        if (part instanceof AbstractMultiPageTalendEditor) {
            CommandStack commandStack = (CommandStack) part.getAdapter(CommandStack.class);
            Command command = new ChangeNoteOpacityCommand(note, !note.isOpaque());
            commandStack.execute(command);
        }
    }
    if (request.getType() == RequestConstants.REQ_DIRECT_EDIT) {
        if (directEditManager == null) {
            NoteFigure noteFigure = (NoteFigure) getFigure();
            directEditManager = new NoteDirectEditManager(this, TextCellEditor.class, new NoteCellEditorLocator(noteFigure));
        }
        directEditManager.show();
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ChangeNoteOpacityCommand(org.talend.designer.core.ui.editor.cmd.ChangeNoteOpacityCommand) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ChangeNoteOpacityCommand(org.talend.designer.core.ui.editor.cmd.ChangeNoteOpacityCommand) Command(org.eclipse.gef.commands.Command) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Example 69 with Command

use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.

the class ImportHL7StructureAction method initXmlTreeData.

private void initXmlTreeData(List<String> schemaList, List<HL7FileNode> root, List<HL7TreeNode> treeData) {
    Map<String, HL7TreeNode> mapNodes = new HashMap<String, HL7TreeNode>();
    List<? extends IConnection> incomingConnections = new ArrayList<IConnection>();
    if (hl7ui != null) {
        if (hl7ui.gethl7Manager() instanceof HL7OutputManager) {
            ((HL7OutputManager) hl7ui.gethl7Manager()).getContents().clear();
            incomingConnections = NodeUtil.getIncomingConnections(hl7ui.gethl7Manager().getHl7Component(), IConnectionCategory.FLOW);
        }
    }
    IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
    List<MetadataTable> iMetadataTables = new ArrayList<MetadataTable>();
    HL7TreeNode rootNode = null;
    Map<String, IMetadataTable> schemaNameToInputTable = new HashMap<String, IMetadataTable>();
    Map<String, MetadataTable> schemaNameToOutputTable = new HashMap<String, MetadataTable>();
    for (String schemaName : schemaList) {
        IMetadataTable metadataTable = null;
        for (IConnection connection : incomingConnections) {
            if (connection.getUniqueName().equals(schemaName)) {
                metadataTable = connection.getMetadataTable();
                metadataTable.setLabel(connection.getUniqueName());
                schemaNameToInputTable.put(schemaName, metadataTable);
                break;
            }
        }
        MetadataTable targetMetadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
        targetMetadataTable.setId(factory.getNextId());
        schemaNameToOutputTable.put(schemaName, targetMetadataTable);
        targetMetadataTable.setLabel(schemaName);
        iMetadataTables.add(targetMetadataTable);
    }
    HL7TreeNode current = null;
    HL7TreeNode temp = null;
    String currentPath = null;
    String defaultValue = null;
    int nodeOrder = 0;
    boolean haveOrder = true;
    // build root tree
    for (int i = 0; i < root.size(); i++) {
        HL7FileNode node = root.get(i);
        String newPath = node.getFilePath();
        defaultValue = node.getDefaultValue();
        String columnName = node.getRelatedColumn();
        // String type = node.getType();
        String orderValue = String.valueOf(node.getOrder());
        if (orderValue == null || "".equals(orderValue)) {
            haveOrder = false;
        }
        if (haveOrder) {
            nodeOrder = node.getOrder();
        }
        String rowName = columnName;
        if (columnName != null && columnName.contains(":")) {
            String[] names = columnName.split(":");
            rowName = names[0];
            columnName = names[1];
        } else {
            columnName = null;
        }
        temp = this.addElement(current, currentPath, newPath, defaultValue, mapNodes);
        if (temp == null) {
            // should not happen
            continue;
        }
        // temp.setDataType(type);
        if (rootNode == null) {
            rootNode = temp;
        }
        if (node.getAttribute().equals("main")) {
            temp.setMain(true);
        }
        current = temp;
        currentPath = newPath;
        if (haveOrder) {
            temp.setOrder(nodeOrder);
        }
        if (rowName != null && rowName.length() > 0) {
            temp.setRow(rowName);
        }
        if (columnName != null) {
            IMetadataTable metadataTable = schemaNameToInputTable.get(rowName);
            // group node can not get the metadata table
            if (metadataTable == null) {
                IMetadataTable metadataTableTemp = null;
                for (IConnection connection : incomingConnections) {
                    metadataTableTemp = connection.getMetadataTable();
                    String connectionName = metadataTableTemp.getLabel();
                    if (connectionName == null) {
                        connectionName = connection.getUniqueName();
                    }
                    if (columnName.startsWith(connectionName)) {
                        break;
                    }
                }
                temp.setColumnName(columnName);
                if (metadataTableTemp != null) {
                    temp.setColumn(metadataTableTemp.getColumn(columnName));
                    temp.setTable(metadataTableTemp);
                }
            } else {
                temp.setColumnName(columnName);
                temp.setColumn(metadataTable.getColumn(columnName));
                temp.setTable(metadataTable);
            }
            //
            if (!temp.isMain()) {
                MetadataColumn newColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
                newColumn.setLabel(columnName);
                newColumn.setName(temp.getLabel());
                newColumn.setLength(226);
                newColumn.setTalendType("id_String");
                schemaNameToOutputTable.get(rowName).getColumns().add(newColumn);
            }
        }
    }
    if (rootNode == null) {
        rootNode = new Element("rootTag");
    }
    if (haveOrder) {
        orderNode(rootNode);
    }
    if (rootNode != null) {
        treeData.add(rootNode);
    }
    if (hl7ui != null) {
        if (hl7ui.gethl7Manager() instanceof HL7OutputManager) {
            ((HL7OutputManager) hl7ui.gethl7Manager()).getContents().put(rootNode.getColumnLabel(), treeData);
        }
    } else if (form != null) {
        for (HL7TreeNode hl7Node : treeData) {
            form.getContents().put(rootNode.getColumnLabel(), hl7Node);
        }
    }
    if (hl7ui != null) {
        // execute the commands,initialize the propertiesView .
        List<Command> commands = new ArrayList<Command>();
        for (MetadataTable tableTemp : iMetadataTables) {
            Command hl7Cmd = new RepositoryChangeMetadataForHL7Command(hl7ui.gethl7Manager().getHl7Component(), IHL7Constant.TABLE_SCHEMAS, tableTemp.getLabel(), ConvertionHelper.convert(tableTemp));
            commands.add(hl7Cmd);
        }
        for (Command command : commands) {
            command.execute();
        }
    }
}
Also used : HashMap(java.util.HashMap) HL7FileNode(org.talend.core.model.metadata.builder.connection.HL7FileNode) Element(org.talend.designer.hl7.ui.data.Element) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) RepositoryChangeMetadataForHL7Command(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForHL7Command) Command(org.eclipse.gef.commands.Command) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) RepositoryChangeMetadataForHL7Command(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForHL7Command) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode) HL7OutputManager(org.talend.designer.hl7.managers.HL7OutputManager) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 70 with Command

use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.

the class NameAndLabelsReferenceController method createControl.

@Override
public Control createControl(final Composite subComposite, final IElementParameter param, final int numInRow, final int nbInRow, final int top, final Control lastControl) {
    this.curParameter = param;
    CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName());
    FormData data = new FormData();
    if (lastControl != null) {
        data.left = new FormAttachment(lastControl, 0);
    } else {
        data.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
    }
    data.top = new FormAttachment(0, top);
    labelLabel.setLayoutData(data);
    if (numInRow != 1) {
        labelLabel.setAlignment(SWT.RIGHT);
    }
    //$NON-NLS-1$
    Button btnEdit = getWidgetFactory().createButton(subComposite, "", SWT.PUSH);
    btnEdit.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));
    data = new FormData();
    data.left = new FormAttachment(((numInRow * MAX_PERCENT) / nbInRow), -STANDARD_BUTTON_WIDTH);
    data.right = new FormAttachment(((numInRow * MAX_PERCENT) / nbInRow), 0);
    data.top = new FormAttachment(labelLabel, 0, SWT.CENTER);
    data.height = STANDARD_HEIGHT - 2;
    btnEdit.setLayoutData(data);
    btnEdit.setData(NAME, MODULE);
    btnEdit.setData(PARAM_OBJ, param);
    btnEdit.setData(PARAMETER_NAME, param.getName());
    btnEdit.setEnabled(!param.isRepositoryValueUsed());
    // btnEdit.setEnabled(!param.isReadOnly());
    btnEdit.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Command cmd = createCommand((Button) e.getSource());
            executeCommand(cmd);
        }
    });
    DecoratedField dField = new DecoratedField(subComposite, SWT.BORDER, new SelectAllTextControlCreator());
    if (param.isRequired()) {
        FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
        dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.TOP, false);
    }
    if (param.isRepositoryValueUsed()) {
        FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
        //$NON-NLS-1$
        decoration.setDescription(Messages.getString("FileController.decoration.description"));
        dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.BOTTOM, false);
    }
    Control cLayout = dField.getLayoutControl();
    Text moduleText = (Text) dField.getControl();
    moduleText.setData(PARAMETER_NAME, param.getName());
    moduleText.setEditable(false);
    cLayout.setBackground(subComposite.getBackground());
    addDragAndDropTarget(moduleText);
    if (elem instanceof Node) {
        moduleText.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }
    hashCurControls.put(param.getName(), moduleText);
    data = new FormData();
    int currentLabelWidth = STANDARD_LABEL_WIDTH;
    GC gc = new GC(labelLabel);
    Point labelSize = gc.stringExtent(param.getDisplayName());
    gc.dispose();
    if ((labelSize.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth) {
        currentLabelWidth = labelSize.x + ITabbedPropertyConstants.HSPACE;
    }
    if (numInRow == 1) {
        if (lastControl != null) {
            data.left = new FormAttachment(lastControl, currentLabelWidth);
        } else {
            data.left = new FormAttachment(0, currentLabelWidth);
        }
    } else {
        data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
    }
    data.right = new FormAttachment(btnEdit, 0);
    data.top = new FormAttachment(labelLabel, 0, SWT.CENTER);
    cLayout.setLayoutData(data);
    Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return btnEdit;
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) FormData(org.eclipse.swt.layout.FormData) FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Node(org.talend.designer.core.ui.editor.nodes.Node) Text(org.eclipse.swt.widgets.Text) DecoratedField(org.eclipse.jface.fieldassist.DecoratedField) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) SelectAllTextControlCreator(org.talend.designer.core.ui.editor.properties.controllers.creator.SelectAllTextControlCreator) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GC(org.eclipse.swt.graphics.GC) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

Command (org.eclipse.gef.commands.Command)100 ArrayList (java.util.ArrayList)38 List (java.util.List)35 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)35 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)28 IElementParameter (org.talend.core.model.process.IElementParameter)22 Node (org.talend.designer.core.ui.editor.nodes.Node)20 INode (org.talend.core.model.process.INode)17 EditPart (org.eclipse.gef.EditPart)15 CommandStack (org.eclipse.gef.commands.CommandStack)15 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)15 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)14 IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)14 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)13 RepositoryNode (org.talend.repository.model.RepositoryNode)13 RepositoryChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand)12 Request (org.eclipse.gef.Request)11 NonResizableEditPolicy (org.eclipse.gef.editpolicies.NonResizableEditPolicy)11 DirectEditRequest (org.eclipse.gef.requests.DirectEditRequest)11 LabelDirectEditPolicy (org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy)11