Search in sources :

Example 1 with KeyValue

use of com.amalto.workbench.models.KeyValue in project tmdm-studio-se by Talend.

the class SchematronExpressBuilder method parseFunxml.

private void parseFunxml() throws Exception {
    InputStream in = null;
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        org.w3c.dom.Document document;
        if (isSchematron) {
            // $NON-NLS-1$
            in = SchematronExpressBuilder.class.getResourceAsStream("XPathFunc.xml");
        } else {
            // $NON-NLS-1$
            in = SchematronExpressBuilder.class.getResourceAsStream("StandardXPathFunc.xml");
        }
        document = builder.parse(in);
        // $NON-NLS-1$
        NodeList list = document.getElementsByTagName("category");
        categories = new ArrayList<XPathFunc>();
        for (int i = 0; i < list.getLength(); i++) {
            XPathFunc xpathFunc = new XPathFunc();
            // get the number i node
            Node node = list.item(i);
            NamedNodeMap map = node.getAttributes();
            // $NON-NLS-1$
            Node nameNode = map.getNamedItem("name");
            xpathFunc.setCategory(nameNode.getTextContent());
            java.util.List<KeyValue> keylist = new ArrayList<KeyValue>();
            for (int j = 0; j < node.getChildNodes().getLength(); j++) {
                Node n = node.getChildNodes().item(j);
                NamedNodeMap fmap = n.getAttributes();
                if (fmap != null && fmap.getLength() > 0) {
                    // $NON-NLS-1$
                    Node n1 = fmap.getNamedItem("name");
                    // $NON-NLS-1$
                    Node n2 = fmap.getNamedItem("help");
                    String help = n2.getTextContent();
                    // $NON-NLS-1$//$NON-NLS-2$
                    help = help.replaceAll("\\n", "\n");
                    KeyValue kv = new KeyValue(n1.getTextContent(), help);
                    keylist.add(kv);
                }
            }
            Collections.sort(keylist, new Comparator<KeyValue>() {

                public int compare(KeyValue o1, KeyValue o2) {
                    if (o1 != null && o2 != null) {
                        return o1.key.compareTo(o2.key);
                    }
                    return 0;
                }
            });
            xpathFunc.setFuncs(keylist);
            categories.add(xpathFunc);
        }
    } finally {
        if (in != null) {
            in.close();
        }
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NamedNodeMap(org.w3c.dom.NamedNodeMap) KeyValue(com.amalto.workbench.models.KeyValue) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) XPathFunc(com.amalto.workbench.models.XPathFunc) Point(org.eclipse.swt.graphics.Point) DocumentBuilder(javax.xml.parsers.DocumentBuilder)

Example 2 with KeyValue

use of com.amalto.workbench.models.KeyValue in project tmdm-studio-se by Talend.

the class ComplexTableViewer method createRightmostPortion.

protected void createRightmostPortion(Composite parent) {
    // $NON-NLS-1$
    addButton = toolkit.createButton(parent, "", SWT.PUSH | SWT.CENTER);
    addButton.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 1));
    addButton.setImage(ImageCache.getCreatedImage(EImage.ADD_OBJ.getPath()));
    addButton.setToolTipText(Messages.ComplexTableViewer_Add);
    addButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        }

        @SuppressWarnings("unchecked")
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            // $NON-NLS-1$
            String uniqueVal = "";
            // $NON-NLS-1$
            String keyVal = "";
            // Make sure texts are not nill (empty) where not authorized
            for (ComplexTableViewerColumn column : columns) {
                // $NON-NLS-1$
                String text = "";
                if (column.isCombo()) {
                    text = ((CCombo) column.getControl()).getText();
                } else if (column.isText()) {
                    text = ((Text) column.getControl()).getText();
                } else if (column.isXPATH()) {
                    Control text1 = ((Composite) column.getControl()).getChildren()[0];
                    if (text1 instanceof Text) {
                        text = ((Text) text1).getText();
                    }
                }
                if (text.length() == 0) {
                    if (column.isNillable()) {
                        text = column.getNillValue();
                        if (column.isCombo()) {
                            ((CCombo) column.getControl()).setText(text);
                        } else {
                            ((Text) column.getControl()).setText(text);
                        }
                    } else {
                        MessageDialog.openError(ComplexTableViewer.this.getViewer().getControl().getShell(), Messages.ComplexTableViewer_InputError, Messages.ComplexTableViewer_ErrorMsg + column.getName() + Messages.ComplexTableViewer_ErrorMsgA);
                        return;
                    }
                }
                if (keyColumns != null && Arrays.asList(keyColumns).indexOf(column) >= 0) {
                    keyVal += text;
                }
                // $NON-NLS-1$
                uniqueVal += "." + text;
            }
            // check uniqueness by concatenating all the values
            List<Line> list = (List<Line>) getViewer().getInput();
            for (Line line : list) {
                // $NON-NLS-1$
                String thisLineVal = "";
                for (KeyValue keyvalue : line.keyValues) {
                    // $NON-NLS-1$
                    thisLineVal += "." + keyvalue.value;
                }
                if (thisLineVal.equals(uniqueVal) || (keyVal.length() > 0 && thisLineVal.indexOf(keyVal) >= 0)) {
                    MessageDialog.openInformation(null, ERROR_ITEMALREADYEXISTS_TITLE, ERROR_ITEMALREADYEXISTS_CONTENT);
                    return;
                }
            }
            // Update the model
            Line line = new Line(columns.toArray(new ComplexTableViewerColumn[columns.size()]), getTextValues());
            list.add(line);
            // update the instances viewer
            markDirty();
            viewer.setSelection(null);
            viewer.refresh();
            viewer.getTable().select(viewer.getTable().getItemCount() - 1);
        }
    });
}
Also used : KeyValue(com.amalto.workbench.models.KeyValue) Composite(org.eclipse.swt.widgets.Composite) Text(org.eclipse.swt.widgets.Text) Line(com.amalto.workbench.models.Line) Control(org.eclipse.swt.widgets.Control) CCombo(org.eclipse.swt.custom.CCombo) GridData(org.eclipse.swt.layout.GridData) List(java.util.List) ListenerList(org.eclipse.core.runtime.ListenerList) ArrayList(java.util.ArrayList) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with KeyValue

use of com.amalto.workbench.models.KeyValue in project tmdm-studio-se by Talend.

the class UserSecurityCellModifier method getValue.

public Object getValue(Object element, String property) {
    int columnIndex = Arrays.asList(viewer.getColumnProperties()).indexOf(property);
    Line line = (Line) element;
    if (isAColumnWithCombo(columnIndex)) {
        String value = line.keyValues.get(columnIndex).value;
        String[] attrs = conditionColumns[columnIndex].getComboValues();
        return Arrays.asList(attrs).indexOf(value);
    }
    for (KeyValue keyvalue : line.keyValues) {
        if (property.equals(keyvalue.key)) {
            if (keyvalue.value == null) {
                return conditionColumns[columnIndex].getNillDisplay();
            }
            return keyvalue.value;
        }
    }
    return null;
}
Also used : Line(com.amalto.workbench.models.Line) KeyValue(com.amalto.workbench.models.KeyValue)

Example 4 with KeyValue

use of com.amalto.workbench.models.KeyValue in project tmdm-studio-se by Talend.

the class FKFilterParserTest method testGetDeParseredFilter.

@Test
public void testGetDeParseredFilter() {
    // $NON-NLS-1$
    String criteria = "Store/Long$$=$$111$$And#Store/Address$$Contains$$shanghai$$Or#";
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    String[] keyNames = { "XPath", "Operator", "Value", "Predicate" };
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    String[] values1 = { "Store/Long", "=", "111", "And" };
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    String[] values2 = { "Store/Address", "Contains", "shanghai", "Or" };
    List<KeyValue> keyValues1 = new ArrayList<KeyValue>();
    List<KeyValue> keyValues2 = new ArrayList<KeyValue>();
    for (int i = 0; i < keyNames.length && i < values1.length; i++) {
        keyValues1.add(new KeyValue(keyNames[i], values1[i]));
        keyValues2.add(new KeyValue(keyNames[i], values2[i]));
    }
    Line line1 = new Line(keyValues1);
    Line line2 = new Line(keyValues2);
    String deParseredFilter = FKFilterParser.getDeParseredFilter(Arrays.asList(line1, line2));
    assertEquals(criteria, deParseredFilter);
    deParseredFilter = FKFilterParser.getDeParseredFilter(null);
    // $NON-NLS-1$
    assertEquals("", deParseredFilter);
}
Also used : Line(com.amalto.workbench.models.Line) KeyValue(com.amalto.workbench.models.KeyValue) ArrayList(java.util.ArrayList) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with KeyValue

use of com.amalto.workbench.models.KeyValue in project tmdm-studio-se by Talend.

the class UpdateAutoIncrementDialog method getInput.

private List<Line> getInput() {
    List<Line> lines = new ArrayList<Line>();
    Iterator<String> iterator = entityValues.keySet().iterator();
    while (iterator.hasNext()) {
        String entity = iterator.next();
        String value = entityValues.get(entity);
        List<KeyValue> keyvalues = new ArrayList<KeyValue>();
        // $NON-NLS-1$
        keyvalues.add(new KeyValue("Entity", entity));
        // $NON-NLS-1$
        keyvalues.add(new KeyValue("Value", value));
        Line line = new Line(keyvalues);
        lines.add(line);
    }
    return lines;
}
Also used : Line(com.amalto.workbench.models.Line) KeyValue(com.amalto.workbench.models.KeyValue) ArrayList(java.util.ArrayList)

Aggregations

KeyValue (com.amalto.workbench.models.KeyValue)12 Line (com.amalto.workbench.models.Line)10 ArrayList (java.util.ArrayList)9 SelectionListener (org.eclipse.swt.events.SelectionListener)4 GridData (org.eclipse.swt.layout.GridData)4 Composite (org.eclipse.swt.widgets.Composite)4 List (java.util.List)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 TableItem (org.eclipse.swt.widgets.TableItem)3 EImage (com.amalto.workbench.image.EImage)2 XPathFunc (com.amalto.workbench.models.XPathFunc)2 ListenerList (org.eclipse.core.runtime.ListenerList)2 CellEditor (org.eclipse.jface.viewers.CellEditor)2 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)2 ICellModifier (org.eclipse.jface.viewers.ICellModifier)2 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)2 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 ITableLabelProvider (org.eclipse.jface.viewers.ITableLabelProvider)2 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)2