use of org.eclipse.jface.dialogs.InputDialog in project tdi-studio-se by Talend.
the class CreateHL7ElementAction method createChildNode.
/**
* Create the child node of the input node
*
* @param node
*/
private boolean createChildNode(final HL7TreeNode node) {
if (node.getColumn() != null) {
if (!MessageDialog.openConfirm(xmlViewer.getControl().getShell(), "Warning", "Do you want to disconnect the existing linker and then add an sub element for the selected element" + node.getLabel() + "\"?")) {
return false;
}
node.setColumn(null);
}
String label = "";
final String nodeLabel = node.getLabel() + "-";
while (!StringUtil.validateLabelForXML(label)) {
// add validator
IInputValidator validator = new IInputValidator() {
@Override
public String isValid(String newText) {
if (newText != null) {
String text = newText.trim();
for (HL7TreeNode children : node.getChildren()) {
if (text.equals(children.getLabel())) {
//$NON-NLS-1$
return "The name already existed.";
}
}
}
return null;
}
};
InputDialog dialog = new InputDialog(null, "Input element's label", "Input the new element's valid label", nodeLabel, validator) {
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
*/
@Override
protected void okPressed() {
super.okPressed();
}
};
dialog.setErrorMessage("name is error");
int status = dialog.open();
if (status == InputDialog.OK) {
label = dialog.getValue().trim();
}
if (status == InputDialog.CANCEL) {
return false;
}
}
HL7TreeNode child = new Element(label);
// if the root not have CurSchema
if (node.getRow() == null || node.getRow().equals("")) {
if (hl7ui != null && hl7ui.gethl7Manager() instanceof HL7OutputManager) {
if (label.length() == 3) {
child.setRow(label);
IMetadataTable table = null;
for (IMetadataTable curTable : hl7ui.gethl7Manager().getHl7Component().getMetadataList()) {
if (label.equals(curTable.getLabel())) {
table = curTable;
break;
}
}
if (table == null) {
table = new MetadataTable();
table.setLabel(label);
table.setTableName(label);
hl7ui.gethl7Manager().getHl7Component().getMetadataList().add(table);
}
List<Map<String, String>> maps = (List<Map<String, String>>) hl7ui.gethl7Manager().getHl7Component().getElementParameter("SCHEMAS").getValue();
boolean found = false;
for (Map<String, String> map : maps) {
if (map.get("SCHEMA").equals(table.getTableName())) {
found = true;
}
}
if (!found) {
Map<String, String> hl7Schema = new HashMap<String, String>();
maps.add(hl7Schema);
hl7Schema.put("SCHEMA", table.getTableName());
}
}
} else if (label.length() == 3) {
child.setRow(label);
}
} else {
child.setRow(node.getRow());
}
node.addChild(child);
this.xmlViewer.refresh();
return true;
}
use of org.eclipse.jface.dialogs.InputDialog in project tdi-studio-se by Talend.
the class MapperUI method openNewOutputCreationDialog.
public String openNewOutputCreationDialog() {
final IProcess process = mapperManager.getMapperComponent().getProcess();
//$NON-NLS-1$
String outputName = process.generateUniqueConnectionName("out");
InputDialog id = new InputDialog(mapperShell, "Add a output", "New Output :", outputName, new IInputValidator() {
@Override
public String isValid(String newText) {
if (!process.checkValidConnectionName(newText)) {
return "Output is invalid.";
}
return null;
}
});
int response = id.open();
if (response == InputDialog.OK) {
return id.getValue();
}
return null;
}
use of org.eclipse.jface.dialogs.InputDialog in project tdi-studio-se by Talend.
the class RenameAction method getNewName.
/**
* Gets the new file name.
*
* @return The new file name
*/
private String getNewName() {
IFileStore fileStore = snapshot.getFileStore();
List<String> oldNames = new ArrayList<String>();
try {
for (String oldName : fileStore.getParent().childNames(EFS.NONE, null)) {
oldNames.add(removeSuffix(oldName));
}
} catch (CoreException e) {
Activator.log(IStatus.ERROR, NLS.bind(Messages.accessFileFailedMsg, fileStore.getName()), e);
return null;
}
String oldName = fileStore.getName();
IInputValidator validator = new InputValidator(oldNames, oldName);
InputDialog dialog = new InputDialog(treeViewer.getControl().getShell(), Messages.renameTitle, Messages.newNameLabel, removeSuffix(oldName), validator);
if (dialog.open() == Window.OK) {
return oldName.replace(removeSuffix(oldName), dialog.getValue());
}
return null;
}
use of org.eclipse.jface.dialogs.InputDialog in project tdi-studio-se by Talend.
the class CreateJSONElementAction method createChildNode.
private boolean createChildNode(FOXTreeNode node) {
if (node.getColumn() != null) {
if (!MessageDialog.openConfirm(jsonViewer.getControl().getShell(), "Warning", "Do you want to disconnect the existing linker and then add an sub element for the selected element " + node.getLabel() + " \"?")) {
return false;
}
node.setColumn(null);
}
String label = "";
while (!JSONUtil.validateLabelForJSON(label)) {
InputDialog dialog = new InputDialog(null, "Input element's label", "Input the new element's valid label", "", null);
int status = dialog.open();
if (status == InputDialog.OK) {
label = dialog.getValue().trim();
}
if (status == InputDialog.CANCEL) {
return false;
}
}
FOXTreeNode child = new Element(label);
// child.setRow(node.getRow());
node.addChild(child);
// fix for TDI-18802
if (node.getParent() == null && node.isLoop()) {
node.setLoop(false);
}
this.jsonViewer.refresh();
this.jsonViewer.expandAll();
return true;
}
use of org.eclipse.jface.dialogs.InputDialog in project tdi-studio-se by Talend.
the class CreateElementAction method run.
@Override
public void run() {
TreeNode treeNode = null;
boolean needWarning = false;
if (input) {
treeNode = XmlmapFactory.eINSTANCE.createTreeNode();
if (!parent.getOutgoingConnections().isEmpty()) {
needWarning = true;
}
} else {
treeNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
OutputTreeNode outputTreeNode = (OutputTreeNode) treeNode;
EList<Connection> incomingConnections = parent.getIncomingConnections();
if (!incomingConnections.isEmpty()) {
needWarning = true;
}
}
boolean canContinue = true;
// Shell shell = this.part.getSite().getShell();
if (needWarning) {
canContinue = MessageDialog.openConfirm(null, "Warning", "Do you want to disconnect the existing linker and then add an sub element for the selected element ?");
}
if (canContinue) {
// IInputValidator validataor = new IInputValidator() {
//
// public String isValid(String newText) {
// String xpath = XmlMapUtil.getXPath(parent.getXpath(), newText, NodeType.ELEMENT);
// EList<TreeNode> children = parent.getChildren();
// boolean exist = false;
// for (TreeNode child : children) {
// if (child.getXpath() != null && child.getXpath().equals(xpath)) {
// exist = true;
// break;
// }
// }
//
// if (exist) {
// return "Element '" + newText + "' already exist !";
// } else {
// return null;
// }
// }
//
// };
InputDialog dialog = new InputDialog(null, "Create New Element", "Input the new element's valid label", "", null);
int open = -1;
String label = "";
while (!StringUtil.validateLabelForXML(label)) {
open = dialog.open();
if (open == InputDialog.OK) {
label = dialog.getValue().trim();
}
if (open == InputDialog.CANCEL) {
return;
}
}
if (open == Window.OK) {
XmlMapUtil.detachNodeConnections(parent, mapperManager.getExternalData(), false);
treeNode.setName(label);
treeNode.setNodeType(NodeType.ELEMENT);
String parentXpath = parent.getXpath();
if (parent.isChoice() || parent.isSubstitution()) {
TreeNode realPrant = XmlMapUtil.getRealParentNode(parent);
if (realPrant != null) {
parentXpath = realPrant.getXpath();
}
}
treeNode.setXpath(XmlMapUtil.getXPath(parentXpath, treeNode.getName(), treeNode.getNodeType()));
treeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
parent.getChildren().add(treeNode);
parent.setExpression("");
if (!input) {
OutputTreeNode output = (OutputTreeNode) parent;
if (!XmlMapUtil.isExpressionEditable(output) && output.isAggregate()) {
output.setAggregate(false);
}
}
}
if (open == Window.OK && mapperManager != null) {
// if (input) {
// mapperManager.inputTreeSchemaBeanListModified();
// } else {
// mapperManager.outputTreeSchemaBeanListModified();
// }
Object object = graphicViewer.getEditPartRegistry().get(treeNode);
if (object instanceof TreeNodeEditPart) {
graphicViewer.select((TreeNodeEditPart) object);
}
}
}
}
Aggregations