use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.
the class XmlDropTargetListener method handleDrop.
@Override
protected void handleDrop() {
final Object object = TemplateTransfer.getInstance().getObject();
if (object == null || !(object instanceof TransferedObject)) {
return;
}
updateTargetRequest();
updateTargetEditPart();
DropContextAnalyzer analyzer = new DropContextAnalyzer((TransferedObject) object, (AbstractGraphicalEditPart) getTargetEditPart(), getDropLocation());
if (analyzer.isDropValid()) {
NodeType selectedNodeType = NodeType.ELEMENT;
DropType dropType = analyzer.getDropType();
if (dropType == DropType.DROP_OUTPUT_DOC_CHILD && getTargetEditPart() instanceof OutputTreeNodeEditPart) {
OutputTreeNode targetOutputNode = (OutputTreeNode) ((OutputTreeNodeEditPart) getTargetEditPart()).getModel();
Shell shell = getViewer().getControl().getShell();
// if allNamespace , create output as namespace , if allsubTree , create output subtree , no need prompt
boolean needPrompt = false;
boolean hasSubTree = false;
for (Object o : ((TransferedObject) object).getToTransfer()) {
if (o instanceof VarNodeEditPart) {
needPrompt = true;
} else if (o instanceof TreeNodeEditPart) {
TreeNode treeNode = (TreeNode) ((TreeNodeEditPart) o).getModel();
if (NodeType.ATTRIBUT.equals(treeNode.getNodeType())) {
needPrompt = true;
}
if (NodeType.ELEMENT.equals(treeNode.getNodeType())) {
if (treeNode.getChildren().isEmpty()) {
needPrompt = true;
} else {
hasSubTree = true;
}
}
}
}
if (needPrompt) {
DragAndDrogDialog selectDialog = new DragAndDrogDialog(shell, !targetOutputNode.getChildren().isEmpty());
int open = selectDialog.open();
if (open == Window.OK) {
if (DragAndDrogDialog.CREATE_AS_SUBELEMENT.equals(selectDialog.getSelectValue())) {
selectedNodeType = NodeType.ELEMENT;
} else if (DragAndDrogDialog.CREATE_AS_ATTRIBUTE.equals(selectDialog.getSelectValue())) {
selectedNodeType = NodeType.ATTRIBUT;
} else if (DragAndDrogDialog.CREATE_AS_SUBELEMENT.equals(selectDialog.getSelectValue())) {
selectedNodeType = NodeType.NAME_SPACE;
} else if (DragAndDrogDialog.CREATE_AS_TEXT.equals(selectDialog.getSelectValue())) {
dropType = DropType.DROP_EXPRESSION;
}
} else {
return;
}
}
if (dropType != DropType.DROP_EXPRESSION) {
if (!targetOutputNode.getIncomingConnections().isEmpty() && ((selectedNodeType != NodeType.ATTRIBUT && selectedNodeType != NodeType.NAME_SPACE) || hasSubTree)) {
boolean 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) {
MapperManager mapperManager = ((XmlMapGraphicViewer) getViewer()).getMapperManager();
if (mapperManager != null && mapperManager.getExternalData() != null) {
XmlMapUtil.detachNodeConnections(targetOutputNode, mapperManager.getExternalData(), false);
}
} else {
return;
}
}
}
}
NewNodeCreationFactory factory = new NewNodeCreationFactory(dropType, selectedNodeType);
getCreateRequest().setFactory(factory);
}
if (getTargetEditPart() != null) {
Command command = getCommand();
if (command != null && command.canExecute()) {
getViewer().getEditDomain().getCommandStack().execute(command);
} else {
getCurrentEvent().detail = DND.DROP_NONE;
}
} else {
getCurrentEvent().detail = DND.DROP_NONE;
}
selectAddedObject();
}
use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.
the class XmlMapInputZoneToolBar method changProperty.
/*
* (non-Javadoc)
*
* @see org.talend.designer.newabstractmap.figures.treetools.zone.InputZoneTooBar#changProperty()
*/
@Override
public void changProperty() {
boolean dieOnError = mapperManger.isDieOnError();
PropertySetDialog propertySet = new PropertySetDialog(null, dieOnError);
if (propertySet.open() == Window.OK) {
if (graphicViewer != null && propertySet.isValueChanged()) {
final boolean newValue = !dieOnError;
CommandStack commandStack = graphicViewer.getEditDomain().getCommandStack();
commandStack.execute(new Command() {
@Override
public void execute() {
mapperManger.setDieOnError(newValue);
if (newValue) {
if (!externalData.getOutputTrees().isEmpty()) {
OutputXmlTree outputTree = externalData.getOutputTrees().get(0);
if (outputTree.isErrorReject()) {
// mapperComponent.getMetadataList().add(metadataTable);
externalData.getOutputTrees().remove(0);
mapperComponent.getProcess().removeUniqueConnectionName(outputTree.getName());
removeMetadataTableByName(outputTree.getName());
if (!externalData.getOutputTrees().isEmpty()) {
int indexOf = externalPart.getModelChildren().indexOf(externalData.getOutputTrees().get(0));
if (indexOf != -1) {
graphicViewer.select((EditPart) externalPart.getChildren().get(indexOf));
}
}
}
}
} else {
boolean hasRejectTable = false;
if (!externalData.getOutputTrees().isEmpty()) {
OutputXmlTree outputTree = externalData.getOutputTrees().get(0);
if (outputTree.isErrorReject()) {
hasRejectTable = true;
}
}
if (!hasRejectTable) {
String baseName = MapperManager.ERROR_REJECT;
IProcess process = mapperComponent.getProcess();
String tableName = baseName;
if (!process.checkValidConnectionName(baseName) && process instanceof IProcess2) {
final String uniqueName = ((IProcess2) process).generateUniqueConnectionName("row", baseName);
tableName = uniqueName;
((IProcess2) process).addUniqueConnectionName(uniqueName);
} else if (process instanceof IProcess2) {
tableName = baseName;
((IProcess2) process).addUniqueConnectionName(baseName);
}
OutputXmlTree outputXmlTree = XmlmapFactory.eINSTANCE.createOutputXmlTree();
outputXmlTree.setErrorReject(true);
outputXmlTree.setName(tableName);
externalData.getOutputTrees().add(0, outputXmlTree);
MetadataTable metadataTable = new MetadataTable();
metadataTable.setLabel(tableName);
metadataTable.setTableName(tableName);
MetadataColumn errorMessageCol = new MetadataColumn();
errorMessageCol.setLabel(MapperManager.ERROR_REJECT_MESSAGE);
errorMessageCol.setTalendType(DesignerPlugin.getDefault().getPreferenceStore().getString(MetadataTypeLengthConstants.FIELD_DEFAULT_TYPE));
errorMessageCol.setNullable(true);
errorMessageCol.setOriginalDbColumnName(MapperManager.ERROR_REJECT_MESSAGE);
errorMessageCol.setReadOnly(true);
errorMessageCol.setCustom(true);
metadataTable.getListColumns().add(errorMessageCol);
MetadataColumn errorStackTrace = new MetadataColumn();
errorStackTrace.setLabel(MapperManager.ERROR_REJECT_STACK_TRACE);
errorStackTrace.setTalendType(DesignerPlugin.getDefault().getPreferenceStore().getString(MetadataTypeLengthConstants.FIELD_DEFAULT_TYPE));
errorStackTrace.setNullable(true);
errorStackTrace.setOriginalDbColumnName(MapperManager.ERROR_REJECT_STACK_TRACE);
errorStackTrace.setReadOnly(true);
errorStackTrace.setCustom(true);
metadataTable.getListColumns().add(errorStackTrace);
mapperComponent.getMetadataList().add(metadataTable);
OutputTreeNode errorMessageNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
errorMessageNode.setName(MapperManager.ERROR_REJECT_MESSAGE);
errorMessageNode.setType(errorMessageCol.getTalendType());
errorMessageNode.setNullable(true);
outputXmlTree.getNodes().add(errorMessageNode);
OutputTreeNode errorStackTraceNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
errorStackTraceNode.setName(MapperManager.ERROR_REJECT_STACK_TRACE);
errorStackTraceNode.setType(errorStackTrace.getTalendType());
errorStackTraceNode.setNullable(true);
outputXmlTree.getNodes().add(errorStackTraceNode);
int indexOf = externalPart.getModelChildren().indexOf(outputXmlTree);
if (indexOf != -1) {
graphicViewer.select((EditPart) externalPart.getChildren().get(indexOf));
}
}
}
}
});
}
}
}
use of org.eclipse.gef.commands.Command in project tesb-studio-se by Talend.
the class RestResponseSchemaController method createComboCommand.
@Override
public Command createComboCommand(SelectionEvent event) {
//Change the body type according to selected return body type
Command changePropertyCommand = super.createComboCommand(event);
Object newReturnType = null;
if (changePropertyCommand != null) {
newReturnType = ((PropertyChangeCommand) changePropertyCommand).getNewValue();
}
if (newReturnType == null) {
return null;
}
//get old metadata column
List<IMetadataTable> metadataList = ((INode) elem).getMetadataList();
IMetadataTable oldMetadataTable = null;
if (metadataList != null && metadataList.size() > 0) {
oldMetadataTable = metadataList.get(0);
} else {
metadataList = new ArrayList<IMetadataTable>();
((INode) elem).setMetadataList(metadataList);
}
//create new metadata column
IMetadataTable newMetadataTable = oldMetadataTable == null ? new MetadataTable() : oldMetadataTable.clone();
List<IMetadataColumn> listColumns = newMetadataTable.getListColumns();
if (listColumns == null) {
listColumns = new ArrayList<IMetadataColumn>();
newMetadataTable.setListColumns(listColumns);
}
IMetadataColumn bodyColumn = listColumns.size() > 0 ? listColumns.get(0) : new MetadataColumn();
bodyColumn.setId("body");
bodyColumn.setTalendType(newReturnType.toString());
listColumns.clear();
listColumns.add(bodyColumn);
metadataList.clear();
metadataList.add(newMetadataTable);
//construct change metadata command
ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand((INode) elem, null, oldMetadataTable, newMetadataTable);
//construct compound command by combining above 2 commands
CompoundCommand compoundCommand = new CompoundCommand();
compoundCommand.add(changePropertyCommand);
compoundCommand.add(changeMetadataCommand);
return compoundCommand;
}
use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.
the class MapperUI method closeMapperDialog.
public void closeMapperDialog(int response) {
mapperResponse = response;
if (response == SWT.OK || response == SWT.APPLICATION_MODAL) {
prepareClosing(response);
mapperComponent.setExternalEmfData(copyOfMapData);
if (response == SWT.APPLICATION_MODAL) {
IExternalNode externalNode = mapperComponent;
IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (externalNode != null && (part instanceof AbstractMultiPageTalendEditor)) {
INode node = externalNode.getOriginalNode();
if (node != null && node instanceof Node) {
Command cmd = new ExternalNodeChangeCommand((Node) node, externalNode);
CommandStack cmdStack = (CommandStack) part.getAdapter(CommandStack.class);
cmdStack.execute(cmd);
}
}
}
IElementParameter elementParameter = mapperComponent.getElementParameter("DIE_ON_ERROR");
if (elementParameter != null) {
elementParameter.setValue(mapperManager.isDieOnError());
}
}
if (response == SWT.OK) {
closeWithoutPrompt = true;
}
if (response == SWT.OK || response == SWT.CANCEL) {
mapperShell.close();
}
}
use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.
the class XmlDirectEditPolicy method getDirectEditCommand.
@Override
protected Command getDirectEditCommand(DirectEditRequest request) {
Command command = null;
CellEditor editor = request.getCellEditor();
Object directEditFeature = request.getDirectEditFeature();
if (directEditFeature instanceof DirectEditType) {
DirectEditType type = (DirectEditType) directEditFeature;
if (getHost().getModel() instanceof AbstractNode) {
AbstractNode model = (AbstractNode) getHost().getModel();
switch(type) {
case EXPRESSION:
case NODE_NAME:
command = new DirectEditCommand(getHost(), model, type, request.getCellEditor().getValue());
break;
case VAR_NODE_TYPE:
if (editor instanceof ComboBoxCellEditor) {
ComboBoxCellEditor combo = (ComboBoxCellEditor) editor;
int selectIndex = (Integer) combo.getValue();
command = new DirectEditCommand(getHost(), model, type, combo.getItems()[selectIndex]);
}
break;
case LOOKUP_MODEL:
case MATCH_MODEL:
case JOIN_MODEL:
case PERSISTENT_MODEL:
case OUTPUT_REJECT:
case LOOK_UP_INNER_JOIN_REJECT:
if (editor instanceof ComboBoxCellEditor) {
ComboBoxCellEditor combo = (ComboBoxCellEditor) editor;
int selectIndex = (Integer) combo.getValue();
command = new TreeSettingDirectEditCommand(model, type, combo.getItems()[selectIndex]);
}
break;
case EXPRESSION_FILTER:
if (editor instanceof TextCellEditor) {
command = new TreeSettingDirectEditCommand(model, type, request.getCellEditor().getValue());
}
default:
break;
}
} else {
switch(type) {
case LOOKUP_MODEL:
case MATCH_MODEL:
case JOIN_MODEL:
case PERSISTENT_MODEL:
case OUTPUT_REJECT:
case LOOK_UP_INNER_JOIN_REJECT:
case ALL_IN_ONE:
case ENABLE_EMPTY_ELEMENT:
if ((editor instanceof ComboBoxCellEditor)) {
ComboBoxCellEditor combo = (ComboBoxCellEditor) editor;
int selectIndex = (Integer) combo.getValue();
command = new TreeSettingDirectEditCommand(getHost().getModel(), type, combo.getItems()[selectIndex]);
}
break;
case EXPRESSION_FILTER:
command = new TreeSettingDirectEditCommand(getHost().getModel(), type, request.getCellEditor().getValue());
}
}
}
return command;
}
Aggregations