Search in sources :

Example 46 with TableItem

use of org.eclipse.swt.widgets.TableItem in project tdi-studio-se by Talend.

the class WebServiceTableLiner method onXPathValueChanged.

public void onXPathValueChanged(Table sourceTable, Table targetTable, String oldValue, String newValue, String inComeName, int itemIndex) {
    TableItem tabletraItem = targetTable.getItem(itemIndex);
    boolean needAddLink = true;
    TableItem[] items = sourceTable.getItems();
    List<TableItem> itemList = new ArrayList<TableItem>();
    for (int i = 0; i < items.length; i++) {
        String columnLabel = null;
        IMetadataColumn column = null;
        ParameterInfo parame = null;
        if (items[i].getData() instanceof IMetadataColumn) {
            column = (IMetadataColumn) items[i].getData();
            columnLabel = column.getLabel();
        } else // }
        if (items[i].getData() instanceof OutPutMappingData) {
            parame = ((OutPutMappingData) items[i].getData()).getParameter();
            if (!parame.getParameterInfos().isEmpty()) {
                continue;
            }
            // columnLabel = parame.getName();
            columnLabel = ((OutPutMappingData) items[i].getData()).getParameterName();
            int m = columnLabel.lastIndexOf(".");
            columnLabel = columnLabel.substring(m + 1);
        }
        if (newValue.contains(columnLabel)) {
            // if (!pattern(columnLabel, newValue)) {
            if (inComeName != null) {
                WebServiceExpressionParser webParser = new WebServiceExpressionParser("\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*");
                Map<String, String> itemNamemap = webParser.parseInTableEntryLocations(newValue);
                Set<Entry<String, String>> set = itemNamemap.entrySet();
                Iterator<Entry<String, String>> ite = set.iterator();
                while (ite.hasNext()) {
                    Entry<String, String> entry = ite.next();
                    String columnValue = entry.getKey();
                    String rowValue = entry.getValue();
                    if (!isPatternWord(inComeName + "." + columnLabel, rowValue + "." + columnValue)) {
                        linksManager.removeLinksFromDataItem2(tabletraItem.getData());
                        if (tabletraItem.getData() instanceof InputMappingData) {
                            InputMappingData data = (InputMappingData) tabletraItem.getData();
                            List<IMetadataColumn> list = data.getMetadataColumnList();
                            if (column != null) {
                                list.remove(column);
                            }
                        }
                        needAddLink = false;
                        for (TableItem item : itemList) {
                            addLinks(item, item.getData(), targetTable, tabletraItem.getData(), "INPUTMAPPING");
                        }
                        getBackgroundRefresher().refreshBackground();
                    // return;
                    }
                }
            } else {
                WebServiceExpressionParser webParser = new WebServiceExpressionParser("\\s*\\w+(\\[\\d+?\\])?\\s*");
                Set<String> set = webParser.parseOutTableEntryLocations(newValue);
                Iterator<String> ite = set.iterator();
                while (ite.hasNext()) {
                    String columnValue = ite.next();
                    // if (columnValue.equals(columnLabel)) {
                    if (!isPatternWord(columnLabel, columnValue)) {
                        linksManager.removeLinksFromDataItem2(tabletraItem.getData());
                        OutPutMappingData data = (OutPutMappingData) tabletraItem.getData();
                        if (parame != null) {
                            data.getParameterList().remove(parame);
                        }
                        needAddLink = false;
                        for (TableItem item : itemList) {
                            addLinks(item, item.getData(), targetTable, tabletraItem.getData(), "OUTPUTMAPPING");
                        }
                        getBackgroundRefresher().refreshBackground();
                    // return;
                    // }
                    }
                }
            }
            if (true) {
                // if (!mark) {
                if (inComeName != null) {
                    WebServiceExpressionParser webParser = new WebServiceExpressionParser("\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*");
                    Map<String, String> itemNamemap = webParser.parseInTableEntryLocations(newValue);
                    Set<Entry<String, String>> set = itemNamemap.entrySet();
                    Iterator<Entry<String, String>> ite = set.iterator();
                    while (ite.hasNext()) {
                        Entry<String, String> entry = ite.next();
                        String columnValue = entry.getKey();
                        String rowValue = entry.getValue();
                        if (isPatternWord(inComeName + "." + columnLabel, rowValue + "." + columnValue)) {
                            itemList.add(items[i]);
                            addLinks(items[i], items[i].getData(), targetTable, tabletraItem.getData(), "INPUTMAPPING");
                            getBackgroundRefresher().refreshBackground();
                            if (tabletraItem.getData() instanceof InputMappingData) {
                                InputMappingData data = (InputMappingData) tabletraItem.getData();
                                List<IMetadataColumn> list = data.getMetadataColumnList();
                                if (column != null && !list.contains(column)) {
                                    list.add(column);
                                }
                            }
                        }
                    }
                } else {
                    WebServiceExpressionParser webParser = new WebServiceExpressionParser("\\s*\\w+(\\[\\d+?\\])?\\s*");
                    Set<String> set = webParser.parseOutTableEntryLocations(newValue);
                    Iterator<String> ite = set.iterator();
                    while (ite.hasNext()) {
                        String columnValue = ite.next();
                        if (isPatternWord(columnLabel, columnValue)) {
                            itemList.add(items[i]);
                            addLinks(items[i], items[i].getData(), targetTable, tabletraItem.getData(), "OUTPUTMAPPING");
                            getBackgroundRefresher().refreshBackground();
                        }
                    }
                }
            }
        } else if (oldValue.contains(columnLabel)) {
            linksManager.removeLinksFromDataItem2(tabletraItem.getData());
            if (tabletraItem.getData() instanceof InputMappingData) {
                InputMappingData data = (InputMappingData) tabletraItem.getData();
                List<IMetadataColumn> list = data.getMetadataColumnList();
                if (column != null) {
                    list.remove(column);
                }
            } else if (tabletraItem.getData() instanceof OutPutMappingData) {
                OutPutMappingData data = (OutPutMappingData) tabletraItem.getData();
                if (parame != null) {
                    data.getParameterList().remove(parame);
                }
            }
            for (TableItem item : itemList) {
                if (inComeName != null) {
                    addLinks(item, item.getData(), targetTable, tabletraItem.getData(), "INPUTMAPPING");
                } else {
                    addLinks(item, item.getData(), targetTable, tabletraItem.getData(), "OUTPUTMAPPING");
                }
            }
            getBackgroundRefresher().refreshBackground();
        }
    }
// createFieldLinks(newValue, tableItem, null);
}
Also used : OutPutMappingData(org.talend.designer.webservice.data.OutPutMappingData) InputMappingData(org.talend.designer.webservice.data.InputMappingData) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) ParameterInfo(org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo) Point(org.eclipse.swt.graphics.Point) Entry(java.util.Map.Entry) WebServiceExpressionParser(org.talend.designer.webservice.ui.WebServiceExpressionParser) ArrayList(java.util.ArrayList) List(java.util.List)

Example 47 with TableItem

use of org.eclipse.swt.widgets.TableItem in project tdi-studio-se by Talend.

the class WebServiceTableLiner method addLinks.

public void addLinks(TableItem itemSource, Object data1, Table tableTarget, Object data2, String mark) {
    LinkDescriptor<TableItem, Object, Table, Object> link = new LinkDescriptor<TableItem, Object, Table, Object>(new TableExtremityDescriptor(itemSource, data1), new ExtremityLink<Table, Object>(tableTarget, data2));
    link.setStyleLink(createStandardLink(new Color(getBgDrawableComposite().getDisplay(), 255, 102, 102)));
    getLinksManager().addLink(link);
    if (mark.equals("INPUTMAPPING")) {
        sourceInList.add(((IMetadataColumn) itemSource.getData()).getLabel());
    } else if (mark.equals("OUTPUTMAPPING")) {
        if (((OutPutMappingData) itemSource.getData()).getParameterName() != null) {
            String sourseName = ((OutPutMappingData) itemSource.getData()).getParameterName();
            // int m = sourseName.lastIndexOf(".");
            // sourseName = sourseName.substring(m + 1);
            sourceOutList.add(sourseName);
        } else {
            sourceOutList.add(((OutPutMappingData) itemSource.getData()).getParameter().getName());
        }
    }
}
Also used : TableExtremityDescriptor(org.talend.commons.ui.swt.drawing.link.TableExtremityDescriptor) Table(org.eclipse.swt.widgets.Table) OutPutMappingData(org.talend.designer.webservice.data.OutPutMappingData) TableItem(org.eclipse.swt.widgets.TableItem) Color(org.eclipse.swt.graphics.Color) LinkDescriptor(org.talend.commons.ui.swt.drawing.link.LinkDescriptor)

Example 48 with TableItem

use of org.eclipse.swt.widgets.TableItem in project tesb-studio-se by Talend.

the class XmlTableForm method addFieldsListeners.

private void addFieldsListeners() {
    nameFilter.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            String pattern = nameFilter.getText();
            SearchPattern matcher = new SearchPattern();
            matcher.setPattern(pattern);
            final List<Item> newList = new ArrayList<Item>();
            for (Item item : items) {
                if (matcher.matches(item.getLabel())) {
                    newList.add(item);
                }
            }
            reftesTableContent(newList);
            completeListener.setComplete(!getSelectionItems().isEmpty());
        }
    });
    // Event checkBox action
    table.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (e.detail == SWT.CHECK) {
                ((Item) e.item.getData()).setCheck(((TableItem) e.item).getChecked());
                if (null != completeListener) {
                    completeListener.setComplete(!getSelectionItems().isEmpty());
                }
            }
        }
    });
    table.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            table.getColumns()[0].setWidth(table.getClientArea().width - 2 * table.getBorderWidth());
        }
    });
    selectAllTablesButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            setChecked(true);
        }
    });
    selectNoneTablesButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            setChecked(false);
        }
    });
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) ControlAdapter(org.eclipse.swt.events.ControlAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) TableItem(org.eclipse.swt.widgets.TableItem) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SearchPattern(org.eclipse.ui.dialogs.SearchPattern) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 49 with TableItem

use of org.eclipse.swt.widgets.TableItem in project tdi-studio-se by Talend.

the class DataSetTableKeyListener method keyPressed.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
     */
public void keyPressed(KeyEvent e) {
    switch(e.character) {
        case CTRL_C:
            try {
                Clipboard clipBoard = new Clipboard(Display.getCurrent());
                TextTransfer textTransfer = TextTransfer.getInstance();
                TableItem[] items = ptable.getSelection();
                if (items == null || items.length == 0) {
                    return;
                }
                int columnIndex = pcursor.getColumn();
                clipBoard.setContents(new Object[] { items[0].getText(columnIndex) }, new Transfer[] { textTransfer });
            } catch (Exception ex) {
                //$NON-NLS-1$
                SqlBuilderPlugin.log(Messages.getString("DataSetTableKeyListener.logMessage1"), ex);
            }
            break;
        case CTRL_F:
            // column name typeahead
            createPopup();
            break;
        default:
            return;
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Clipboard(org.eclipse.swt.dnd.Clipboard) Point(org.eclipse.swt.graphics.Point) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 50 with TableItem

use of org.eclipse.swt.widgets.TableItem in project tdi-studio-se by Talend.

the class SQLPatternComposite method createCodeControl.

/**
     * DOC bqian Comment method "createCodeControl".
     * 
     * @param panel
     * @param
     */
private void createCodeControl(Composite panel, Control reference) {
    codeText = new Text(panel, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    codeText.setEditable(false);
    FormData fd = new FormData();
    fd.left = new FormAttachment(10, 0);
    fd.right = new FormAttachment(90, 0);
    fd.top = new FormAttachment(reference, 2);
    fd.bottom = new FormAttachment(95, 0);
    codeText.setLayoutData(fd);
    codeText.addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent e) {
            if (tableViewer.getTable().getSelection().length == 0) {
                return;
            }
            TableItem item = tableViewer.getTable().getSelection()[0];
            if (item == null || item.getText() == null) {
                return;
            }
            String sqlpatternName = item.getText();
            SQLPatternItem patternItem = SQLPatternUtils.getSQLPatternItem(SQLPatternComposite.this.element, sqlpatternName);
            if (patternItem.isSystem()) {
                boolean answer = //$NON-NLS-1$
                MessageDialog.openQuestion(//$NON-NLS-1$
                getShell(), //$NON-NLS-1$
                Messages.getString("SQLPatternComposite.TOS"), //$NON-NLS-1$
                Messages.getString("SQLPatternComposite.forbidModification"));
                if (!answer) {
                    return;
                }
                IRepositoryService repositoryService = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
                IElementParameter parameter = element.getElementParameter(EParameterName.SQLPATTERN_DB_NAME.getName());
                String dbName = (String) parameter.getValue();
                //$NON-NLS-1$
                String path = dbName + "/" + RepositoryConstants.USER_DEFINED;
                repositoryService.createSqlpattern(path, true);
            } else if (sqlPatternAndProject.get(patternItem) != null) {
                MessageDialog.openInformation(getShell(), "Information", "Forbid modification on sql template from reference project");
            } else {
                boolean answer = //$NON-NLS-1$
                MessageDialog.openQuestion(//$NON-NLS-1$
                getShell(), //$NON-NLS-1$
                Messages.getString("SQLPatternComposite.TOS"), //$NON-NLS-1$
                Messages.getString("SQLPatternComposite.modifySQLPattern"));
                if (!answer) {
                    return;
                }
                IRepositoryService repositoryService = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
                repositoryService.openSQLPatternEditor(patternItem, false);
            }
        }

        @Override
        public void mouseDown(MouseEvent e) {
        // do nothing
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            mouseUp(e);
        }
    });
}
Also used : FormData(org.eclipse.swt.layout.FormData) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) TableItem(org.eclipse.swt.widgets.TableItem) IElementParameter(org.talend.core.model.process.IElementParameter) Text(org.eclipse.swt.widgets.Text) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) FormAttachment(org.eclipse.swt.layout.FormAttachment) IRepositoryService(org.talend.repository.model.IRepositoryService)

Aggregations

TableItem (org.eclipse.swt.widgets.TableItem)475 Point (org.eclipse.swt.graphics.Point)136 Table (org.eclipse.swt.widgets.Table)125 TableColumn (org.eclipse.swt.widgets.TableColumn)79 SelectionEvent (org.eclipse.swt.events.SelectionEvent)73 GridData (org.eclipse.swt.layout.GridData)70 GridLayout (org.eclipse.swt.layout.GridLayout)61 Composite (org.eclipse.swt.widgets.Composite)56 ArrayList (java.util.ArrayList)55 Image (org.eclipse.swt.graphics.Image)55 Button (org.eclipse.swt.widgets.Button)53 Rectangle (org.eclipse.swt.graphics.Rectangle)52 Label (org.eclipse.swt.widgets.Label)51 Shell (org.eclipse.swt.widgets.Shell)49 Color (org.eclipse.swt.graphics.Color)48 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)43 Text (org.eclipse.swt.widgets.Text)42 FillLayout (org.eclipse.swt.layout.FillLayout)40 Test (org.junit.Test)39 SelectionListener (org.eclipse.swt.events.SelectionListener)36