use of org.talend.designer.xmlmap.parts.TreeNodeEditPart in project tdi-studio-se by Talend.
the class CreateAttributeAction method calculateEnabled.
@Override
protected boolean calculateEnabled() {
if (getSelectedObjects().isEmpty()) {
return false;
} else {
// get the last selection to run the action
Object s = getSelectedObjects().get(0);
if (s instanceof List && !((List) s).isEmpty()) {
List selectedarts = (List) s;
Object object = selectedarts.get(selectedarts.size() - 1);
if (object instanceof TreeNodeEditPart) {
TreeNodeEditPart nodePart = (TreeNodeEditPart) object;
this.parent = (TreeNode) nodePart.getModel();
if (parent.isChoice() || parent.isSubstitution()) {
return false;
}
boolean isElement = NodeType.ELEMENT.equals(parent.getNodeType());
if (isElement && XmlMapUtil.getXPathLength(parent.getXpath()) > 2) {
return true;
}
}
}
}
return false;
}
use of org.talend.designer.xmlmap.parts.TreeNodeEditPart in project tdi-studio-se by Talend.
the class CreateAttributeAction method run.
@Override
public void run() {
TreeNode treeNode = null;
if (input) {
treeNode = XmlmapFactory.eINSTANCE.createTreeNode();
} else {
treeNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
}
// IInputValidator validataor = new IInputValidator() {
//
// public String isValid(String newText) {
// String xpath = XmlMapUtil.getXPath(parent.getXpath(), newText, NodeType.ATTRIBUT);
// 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 "Atribute '" + newText + "' already exist !";
// } else {
// return null;
// }
// }
//
// };
String label = "";
InputDialog dialog = new InputDialog(null, "Create New Attribute", "Input the new attribute's valid label", "", null);
int open = -1;
while (!StringUtil.validateLabelForXML(label)) {
open = dialog.open();
if (open == InputDialog.OK) {
label = dialog.getValue().trim();
}
if (open == InputDialog.CANCEL) {
return;
}
}
if (open == Window.OK) {
treeNode.setName(label);
treeNode.setNodeType(NodeType.ATTRIBUT);
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);
final EList<TreeNode> children = parent.getChildren();
int index = 0;
for (int i = 0; i < children.size(); i++) {
final TreeNode child = children.get(i);
if (child.getNodeType() == NodeType.NAME_SPACE || child.getNodeType() == NodeType.ATTRIBUT) {
if (i == children.size() - 1) {
index = children.size();
}
continue;
} else {
index = i;
break;
}
}
children.add(index, treeNode);
}
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);
}
}
}
use of org.talend.designer.xmlmap.parts.TreeNodeEditPart in project tdi-studio-se by Talend.
the class CreateNameSpaceAction method run.
@Override
public void run() {
String prefix = null;
String defaultValue = null;
NameSpaceDialog nsDialog = new NameSpaceDialog(null);
nsDialog.setParentNode(parent);
int status = nsDialog.open();
if (status == nsDialog.OK) {
defaultValue = nsDialog.getNSValue();
if (defaultValue != null) {
defaultValue = defaultValue.trim();
}
prefix = nsDialog.getPrefix().trim();
}
if (status == nsDialog.CANCEL) {
return;
}
TreeNode createdNode = null;
if (input) {
createdNode = XmlmapFactory.eINSTANCE.createTreeNode();
} else {
createdNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
}
createdNode.setName(prefix);
createdNode.setNodeType(NodeType.NAME_SPACE);
createdNode.setDefaultValue(defaultValue);
createdNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
String label = createdNode.getName();
if (prefix == null || "".equals(prefix)) {
label = XmlMapUtil.DEFAULT_NAME_SPACE_PREFIX;
createdNode.setName(XmlMapUtil.DEFAULT_NAME_SPACE_PREFIX);
}
String parentXpath = parent.getXpath();
if (parent.isChoice() || parent.isSubstitution()) {
TreeNode realPrant = XmlMapUtil.getRealParentNode(parent);
if (realPrant != null) {
parentXpath = realPrant.getXpath();
}
}
createdNode.setXpath(XmlMapUtil.getXPath(parentXpath, label, NodeType.NAME_SPACE));
final EList<TreeNode> children = parent.getChildren();
int index = 0;
for (int i = 0; i < children.size(); i++) {
final TreeNode treeNode = children.get(i);
if (treeNode.getNodeType() == NodeType.NAME_SPACE) {
if (i == children.size() - 1) {
index = children.size();
}
continue;
} else {
index = i;
break;
}
}
children.add(index, createdNode);
// children.add(createdNode);
// if (input) {
// mapperManager.inputTreeSchemaBeanListModified();
// } else {
// mapperManager.outputTreeSchemaBeanListModified();
// }
Object object = graphicViewer.getEditPartRegistry().get(createdNode);
if (object instanceof TreeNodeEditPart) {
graphicViewer.select((TreeNodeEditPart) object);
}
}
use of org.talend.designer.xmlmap.parts.TreeNodeEditPart in project tdi-studio-se by Talend.
the class MapperManager method onEntitySelection.
private void onEntitySelection(IStructuredSelection selection, AbstractInOutTree selectedTree) {
// do selection in metadata schema editor
EList<? extends TreeNode> nodes = null;
if (selectedTree instanceof InputXmlTree) {
nodes = ((InputXmlTree) selectedTree).getNodes();
} else {
nodes = ((OutputXmlTree) selectedTree).getNodes();
}
List<Integer> selectionIndices = new ArrayList<Integer>();
List<TreeNode> selectedDocChild = new ArrayList<TreeNode>();
Iterator iterator = selection.iterator();
while (iterator.hasNext()) {
Object obj = iterator.next();
if (obj instanceof TreeNodeEditPart) {
TreeNode model = (TreeNode) ((TreeNodeEditPart) obj).getModel();
if (model.eContainer() == selectedTree) {
selectionIndices.add(nodes.indexOf(model));
} else {
AbstractInOutTree abstractInOutTree = XmlMapUtil.getAbstractInOutTree(model);
if (abstractInOutTree == selectedTree) {
selectedDocChild.add(model);
}
}
}
}
int[] selections = new int[selectionIndices.size()];
for (int i = 0; i < selectionIndices.size(); i++) {
selections[i] = selectionIndices.get(i);
}
MetadataTableEditorView metaEditorView = null;
XmlTreeSchemaTableView treeEditorView = null;
if (selectedTree instanceof InputXmlTree) {
metaEditorView = mapperUI.getTabFolderEditors().getInputMetaEditorView();
treeEditorView = mapperUI.getTabFolderEditors().getInputTreeSchemaEditor();
} else {
metaEditorView = mapperUI.getTabFolderEditors().getOutputMetaEditorView();
treeEditorView = mapperUI.getTabFolderEditors().getOutputTreeSchemaEditor();
}
metaEditorView.getTableViewerCreator().getSelectionHelper().setActiveFireSelectionChanged(false);
metaEditorView.getExtendedTableViewer().getTableViewerCreator().getSelectionHelper().setSelection(selections);
metaEditorView.getTableViewerCreator().getSelectionHelper().setActiveFireSelectionChanged(true);
metaEditorView.getExtendedToolbar().updateEnabledStateOfButtons();
// if no, change page
if (!selectedDocChild.isEmpty()) {
treeEditorView.getTableViewerCreator().getSelectionHelper().setActiveFireSelectionChanged(false);
TreeNode firstSelection = null;
if (selectedDocChild.size() > 1) {
selectionIndices = new ArrayList<Integer>();
List<TreeNode> allList = new ArrayList<TreeNode>();
for (TreeNode schemaNodes : nodes) {
if (XmlMapUtil.DOCUMENT.equals(schemaNodes.getType())) {
allList.addAll(SchemaTableUtils.getTreeSchemaEnties(schemaNodes));
}
}
int minIndex = allList.size();
for (TreeNode selected : selectedDocChild) {
int indexOf = allList.indexOf(selected);
if (indexOf != -1 && indexOf < minIndex) {
firstSelection = selected;
}
}
} else {
firstSelection = selectedDocChild.get(0);
}
treeEditorView.getExtendedTableModel().changePageIfNeeded(firstSelection);
// update selection
selectionIndices = new ArrayList<Integer>();
for (TreeNode selected : selectedDocChild) {
int indexOf = treeEditorView.getExtendedTableModel().getBeansList().indexOf(selected);
if (indexOf != -1) {
selectionIndices.add(indexOf);
}
}
selections = new int[selectionIndices.size()];
for (int i = 0; i < selectionIndices.size(); i++) {
selections[i] = selectionIndices.get(i);
}
treeEditorView.getExtendedTableViewer().getTableViewerCreator().getSelectionHelper().setSelection(selections);
treeEditorView.getTableViewerCreator().getSelectionHelper().setActiveFireSelectionChanged(true);
treeEditorView.getExtendedToolbar().updateEnabledStateOfButtons();
}
}
use of org.talend.designer.xmlmap.parts.TreeNodeEditPart in project tdi-studio-se by Talend.
the class SetSubstitutionAction method run.
@Override
public void run() {
TreeNode treeNode = null;
boolean needWarning = false;
if (input) {
treeNode = XmlmapFactory.eINSTANCE.createTreeNode();
if (!selectedNode.getOutgoingConnections().isEmpty()) {
needWarning = true;
}
} else {
treeNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
EList<Connection> incomingConnections = selectedNode.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 a choice for the selected element ?");
}
if (canContinue) {
AbstractUIPlugin plugin = (AbstractUIPlugin) Platform.getPlugin(PlatformUI.PLUGIN_ID);
IDialogSettings workbenchSettings = plugin.getDialogSettings();
//$NON-NLS-1$
IDialogSettings section = workbenchSettings.getSection("SetSubstitutionAction.SubsMessageDialog");
if (section == null) {
//$NON-NLS-1$
section = workbenchSettings.addNewSection("SetSubstitutionAction.SubsMessageDialog");
}
boolean popupMessageDialog = !section.getBoolean(HIDE_MESSAGE);
if (popupMessageDialog) {
String message = "This element will be copied as part of the substitution group automatically." + "\n" + "If this element must be abstract and must be extended only, you can delete it.";
SubsMessageDialog dialog = new SubsMessageDialog(null, message);
int open = dialog.open();
if (open == Window.OK) {
boolean hideDialogNextTime = dialog.getResult();
if (hideDialogNextTime) {
section.put(HIDE_MESSAGE, true);
}
}
if (open == Window.CANCEL) {
return;
}
}
XmlMapUtil.detachNodeConnections(selectedNode, mapperManager.getExternalData(), false);
treeNode.setName(selectedNode.getName() + XSDPopulationUtil2.SUBS);
treeNode.setNodeType(NodeType.ELEMENT);
treeNode.setXpath(selectedNode.getXpath() + XmlMapUtil.XPATH_SEPARATOR + treeNode.getName());
treeNode.setSubstitution(true);
TreeNode parentNode = (TreeNode) selectedNode.eContainer();
int index = parentNode.getChildren().indexOf(selectedNode);
parentNode.getChildren().remove(selectedNode);
treeNode.getChildren().add(selectedNode);
parentNode.getChildren().add(index, treeNode);
if (!input) {
OutputTreeNode output = (OutputTreeNode) selectedNode;
if (!XmlMapUtil.isExpressionEditable(output) && output.isAggregate()) {
output.setAggregate(false);
}
}
Object object = graphicViewer.getEditPartRegistry().get(treeNode);
if (object instanceof TreeNodeEditPart) {
graphicViewer.select((TreeNodeEditPart) object);
}
}
}
Aggregations