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();
}
}
}
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);
}
});
}
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;
}
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);
}
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;
}
Aggregations