use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.
the class DesignerCoreService method checkRepository.
/**
* DOC hcw Comment method "checkRepository".
*
* @param node
* @param item
* @param stack
*/
private void checkRepository(final Node node, Item item, CommandStack stack) {
final String updataComponentParamName = EParameterName.UPDATE_COMPONENTS.getName();
final List<IElementParameter> repositoryParam = new ArrayList<IElementParameter>();
for (IElementParameter param : node.getElementParameters()) {
if (param.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE) || param.getFieldType().equals(EParameterFieldType.SCHEMA_REFERENCE)) {
String value = (String) param.getChildParameters().get(EParameterName.SCHEMA_TYPE.getName()).getValue();
if (value.equals(EmfComponent.REPOSITORY)) {
IElementParameter schema = param.getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
if (schema != null && schema.getValue() != null) {
//$NON-NLS-1$
String[] names = ((String) schema.getValue()).split(" - ");
if (names.length > 0) {
if (names[0].equals(item.getProperty().getId())) {
repositoryParam.add(schema);
}
}
}
}
} else if (param.getFieldType().equals(EParameterFieldType.PROPERTY_TYPE)) {
Object value = param.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).getValue();
if (value.equals(EmfComponent.REPOSITORY)) {
IElementParameter property = param.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
if (property != null && property.getValue() != null) {
if (property.getValue().equals(item.getProperty().getId())) {
repositoryParam.add(property);
}
}
}
}
}
if (repositoryParam.isEmpty()) {
return;
}
stack.execute(new Command() {
@Override
public void execute() {
node.setPropertyValue(updataComponentParamName, new Boolean(true));
for (IElementParameter param : repositoryParam) {
// force to reload label
param.setListItemsDisplayName(new String[0]);
param.setListItemsValue(new String[0]);
}
}
});
}
use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.
the class TNSEditorController method createCommand.
public Command createCommand(Button button) {
IElementParameter elementParameter = this.curParameter.getElement().getElementParameter("TNS_FILE");
Command command = null;
if (elementParameter != null) {
String filePath = new Path(PathExtractor.extractPath(elementParameter.getValue().toString())).toOSString();
if (filePath != null && new File(filePath).exists()) {
boolean flag = false;
try {
TnsParser tnsparser = new TnsParser(new File(filePath));
if (tnsparser.getTree().getChildren().size() == 0) {
flag = true;
}
} catch (Exception e) {
flag = true;
}
if (flag) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openInformation(composite.getShell(), "WARNING", "this file is invalid,please recheck!");
}
});
} else {
TnsEditorDialog tnsDialog = new TnsEditorDialog(composite.getShell(), new File(filePath));
if (tnsDialog.open() == Window.OK) {
TnsInfo tnsInfo = tnsDialog.getTnsInfo();
command = new TnsPropertyCommand(tnsInfo, this.elem);
}
}
} else {
MessageBox mBox = new MessageBox(composite.getShell(), SWT.ICON_ERROR);
//$NON-NLS-1$
mBox.setText("Error");
//$NON-NLS-1$
mBox.setMessage("TNS File Not Found");
mBox.open();
}
}
return command;
}
use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.
the class NoteEditPart method performRequest.
@Override
public void performRequest(Request request) {
Note note = (Note) getModel();
if (note.isReadOnly()) {
return;
}
if (request.getType() == RequestConstants.REQ_OPEN) {
IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (part instanceof AbstractMultiPageTalendEditor) {
CommandStack commandStack = (CommandStack) part.getAdapter(CommandStack.class);
Command command = new ChangeNoteOpacityCommand(note, !note.isOpaque());
commandStack.execute(command);
}
}
if (request.getType() == RequestConstants.REQ_DIRECT_EDIT) {
if (directEditManager == null) {
NoteFigure noteFigure = (NoteFigure) getFigure();
directEditManager = new NoteDirectEditManager(this, TextCellEditor.class, new NoteCellEditorLocator(noteFigure));
}
directEditManager.show();
}
}
use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.
the class ImportHL7StructureAction method initXmlTreeData.
private void initXmlTreeData(List<String> schemaList, List<HL7FileNode> root, List<HL7TreeNode> treeData) {
Map<String, HL7TreeNode> mapNodes = new HashMap<String, HL7TreeNode>();
List<? extends IConnection> incomingConnections = new ArrayList<IConnection>();
if (hl7ui != null) {
if (hl7ui.gethl7Manager() instanceof HL7OutputManager) {
((HL7OutputManager) hl7ui.gethl7Manager()).getContents().clear();
incomingConnections = NodeUtil.getIncomingConnections(hl7ui.gethl7Manager().getHl7Component(), IConnectionCategory.FLOW);
}
}
IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
List<MetadataTable> iMetadataTables = new ArrayList<MetadataTable>();
HL7TreeNode rootNode = null;
Map<String, IMetadataTable> schemaNameToInputTable = new HashMap<String, IMetadataTable>();
Map<String, MetadataTable> schemaNameToOutputTable = new HashMap<String, MetadataTable>();
for (String schemaName : schemaList) {
IMetadataTable metadataTable = null;
for (IConnection connection : incomingConnections) {
if (connection.getUniqueName().equals(schemaName)) {
metadataTable = connection.getMetadataTable();
metadataTable.setLabel(connection.getUniqueName());
schemaNameToInputTable.put(schemaName, metadataTable);
break;
}
}
MetadataTable targetMetadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
targetMetadataTable.setId(factory.getNextId());
schemaNameToOutputTable.put(schemaName, targetMetadataTable);
targetMetadataTable.setLabel(schemaName);
iMetadataTables.add(targetMetadataTable);
}
HL7TreeNode current = null;
HL7TreeNode temp = null;
String currentPath = null;
String defaultValue = null;
int nodeOrder = 0;
boolean haveOrder = true;
// build root tree
for (int i = 0; i < root.size(); i++) {
HL7FileNode node = root.get(i);
String newPath = node.getFilePath();
defaultValue = node.getDefaultValue();
String columnName = node.getRelatedColumn();
// String type = node.getType();
String orderValue = String.valueOf(node.getOrder());
if (orderValue == null || "".equals(orderValue)) {
haveOrder = false;
}
if (haveOrder) {
nodeOrder = node.getOrder();
}
String rowName = columnName;
if (columnName != null && columnName.contains(":")) {
String[] names = columnName.split(":");
rowName = names[0];
columnName = names[1];
} else {
columnName = null;
}
temp = this.addElement(current, currentPath, newPath, defaultValue, mapNodes);
if (temp == null) {
// should not happen
continue;
}
// temp.setDataType(type);
if (rootNode == null) {
rootNode = temp;
}
if (node.getAttribute().equals("main")) {
temp.setMain(true);
}
current = temp;
currentPath = newPath;
if (haveOrder) {
temp.setOrder(nodeOrder);
}
if (rowName != null && rowName.length() > 0) {
temp.setRow(rowName);
}
if (columnName != null) {
IMetadataTable metadataTable = schemaNameToInputTable.get(rowName);
// group node can not get the metadata table
if (metadataTable == null) {
IMetadataTable metadataTableTemp = null;
for (IConnection connection : incomingConnections) {
metadataTableTemp = connection.getMetadataTable();
String connectionName = metadataTableTemp.getLabel();
if (connectionName == null) {
connectionName = connection.getUniqueName();
}
if (columnName.startsWith(connectionName)) {
break;
}
}
temp.setColumnName(columnName);
if (metadataTableTemp != null) {
temp.setColumn(metadataTableTemp.getColumn(columnName));
temp.setTable(metadataTableTemp);
}
} else {
temp.setColumnName(columnName);
temp.setColumn(metadataTable.getColumn(columnName));
temp.setTable(metadataTable);
}
//
if (!temp.isMain()) {
MetadataColumn newColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
newColumn.setLabel(columnName);
newColumn.setName(temp.getLabel());
newColumn.setLength(226);
newColumn.setTalendType("id_String");
schemaNameToOutputTable.get(rowName).getColumns().add(newColumn);
}
}
}
if (rootNode == null) {
rootNode = new Element("rootTag");
}
if (haveOrder) {
orderNode(rootNode);
}
if (rootNode != null) {
treeData.add(rootNode);
}
if (hl7ui != null) {
if (hl7ui.gethl7Manager() instanceof HL7OutputManager) {
((HL7OutputManager) hl7ui.gethl7Manager()).getContents().put(rootNode.getColumnLabel(), treeData);
}
} else if (form != null) {
for (HL7TreeNode hl7Node : treeData) {
form.getContents().put(rootNode.getColumnLabel(), hl7Node);
}
}
if (hl7ui != null) {
// execute the commands,initialize the propertiesView .
List<Command> commands = new ArrayList<Command>();
for (MetadataTable tableTemp : iMetadataTables) {
Command hl7Cmd = new RepositoryChangeMetadataForHL7Command(hl7ui.gethl7Manager().getHl7Component(), IHL7Constant.TABLE_SCHEMAS, tableTemp.getLabel(), ConvertionHelper.convert(tableTemp));
commands.add(hl7Cmd);
}
for (Command command : commands) {
command.execute();
}
}
}
use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.
the class NameAndLabelsReferenceController method createControl.
@Override
public Control createControl(final Composite subComposite, final IElementParameter param, final int numInRow, final int nbInRow, final int top, final Control lastControl) {
this.curParameter = param;
CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName());
FormData data = new FormData();
if (lastControl != null) {
data.left = new FormAttachment(lastControl, 0);
} else {
data.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
}
data.top = new FormAttachment(0, top);
labelLabel.setLayoutData(data);
if (numInRow != 1) {
labelLabel.setAlignment(SWT.RIGHT);
}
//$NON-NLS-1$
Button btnEdit = getWidgetFactory().createButton(subComposite, "", SWT.PUSH);
btnEdit.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));
data = new FormData();
data.left = new FormAttachment(((numInRow * MAX_PERCENT) / nbInRow), -STANDARD_BUTTON_WIDTH);
data.right = new FormAttachment(((numInRow * MAX_PERCENT) / nbInRow), 0);
data.top = new FormAttachment(labelLabel, 0, SWT.CENTER);
data.height = STANDARD_HEIGHT - 2;
btnEdit.setLayoutData(data);
btnEdit.setData(NAME, MODULE);
btnEdit.setData(PARAM_OBJ, param);
btnEdit.setData(PARAMETER_NAME, param.getName());
btnEdit.setEnabled(!param.isRepositoryValueUsed());
// btnEdit.setEnabled(!param.isReadOnly());
btnEdit.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Command cmd = createCommand((Button) e.getSource());
executeCommand(cmd);
}
});
DecoratedField dField = new DecoratedField(subComposite, SWT.BORDER, new SelectAllTextControlCreator());
if (param.isRequired()) {
FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.TOP, false);
}
if (param.isRepositoryValueUsed()) {
FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
//$NON-NLS-1$
decoration.setDescription(Messages.getString("FileController.decoration.description"));
dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.BOTTOM, false);
}
Control cLayout = dField.getLayoutControl();
Text moduleText = (Text) dField.getControl();
moduleText.setData(PARAMETER_NAME, param.getName());
moduleText.setEditable(false);
cLayout.setBackground(subComposite.getBackground());
addDragAndDropTarget(moduleText);
if (elem instanceof Node) {
moduleText.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
}
hashCurControls.put(param.getName(), moduleText);
data = new FormData();
int currentLabelWidth = STANDARD_LABEL_WIDTH;
GC gc = new GC(labelLabel);
Point labelSize = gc.stringExtent(param.getDisplayName());
gc.dispose();
if ((labelSize.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth) {
currentLabelWidth = labelSize.x + ITabbedPropertyConstants.HSPACE;
}
if (numInRow == 1) {
if (lastControl != null) {
data.left = new FormAttachment(lastControl, currentLabelWidth);
} else {
data.left = new FormAttachment(0, currentLabelWidth);
}
} else {
data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
}
data.right = new FormAttachment(btnEdit, 0);
data.top = new FormAttachment(labelLabel, 0, SWT.CENTER);
cLayout.setLayoutData(data);
Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
return btnEdit;
}
Aggregations