public CreateCommand(String label, Process process, Point location) { super(label); this.process = process; this.location = location; if (process.isGridEnabled()) { // replace the component to set it on the grid if it's enabled int tempVar = location.x / TalendEditor.GRID_SIZE; this.location.x = tempVar * TalendEditor.GRID_SIZE; tempVar = location.y / TalendEditor.GRID_SIZE; this.location.y = tempVar * TalendEditor.GRID_SIZE; } }
/* * (non-Javadoc) * * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) */ public String getText(Object objects) { Node node = null; if (objects == null || objects.equals(StructuredSelection.EMPTY)) { return "No items selected"; //$NON-NLS-1$ } if (!(objects instanceof IStructuredSelection)) { return null; } final boolean[] multiple = {false}; Object object = getObject(objects, multiple); if (object == null /* || ((IStructuredSelection) objects).size() > 1 */) { return "No items selected"; //$NON-NLS-1$ } else { if (object instanceof NodeContainerPart) { NodeContainerPart nContainer = (NodeContainerPart) object; Process process = (Process) nContainer.getParent().getModel(); return process.getName(); } else if (object instanceof ProcessPart) { Process process = (Process) ((ProcessPart) object).getModel(); return process.getLabel(); } else if (object instanceof ProcessTreeEditPart) { Process process = (Process) ((ProcessTreeEditPart) object).getModel(); return process.getName(); } if (object instanceof ConnectionPart) { Connection conn = (Connection) ((ConnectionPart) object).getModel(); return conn.getName(); } if (object instanceof NoteEditPart) { return Note.class.getSimpleName(); } if (object instanceof ConnLabelEditPart) { Connection conn = (Connection) ((ConnectionLabel) ((ConnLabelEditPart) object).getModel()).getConnection(); return conn.getName(); } if (object instanceof NodeTreeEditPart) { node = (Node) ((NodeTreeEditPart) object).getModel(); } else { if (object instanceof NodeReturnsTreeEditPart) { node = lastNode; } else { if (object instanceof NodeLabelEditPart) { node = ((NodeContainer) ((NodeLabelEditPart) object).getParent().getModel()).getNode(); } if (!(object instanceof NodePart)) { return null; } if (node == null) { node = (Node) ((NodePart) object).getModel(); } } } if (lastNode != node) { lastNode = node; } String name = node.getUniqueName(); // if (!node.getComponent().getTranslatedName().equals(node.getComponent().getName())) { // name += " (" + node.getComponent().getName() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ // } return name; } }
@Override public void execute() { if (result == null) { return; } Object job = result.getJob(); if (job == null) { return; } if (job instanceof IProcess2) { Process process = (Process) job; EComponentCategory category = null; IUpdateItemType updateType = result.getUpdateType(); if (updateType instanceof EUpdateItemType) { switch ((EUpdateItemType) updateType) { case JOB_PROPERTY_EXTRA: category = EComponentCategory.EXTRA; break; case JOB_PROPERTY_STATS_LOGS: category = EComponentCategory.STATSANDLOGS; break; case JOB_PROPERTY_HEADERFOOTER: category = EComponentCategory.HEADERFOOTER; break; case JOB_PROPERTY_MAPREDUCE: category = EComponentCategory.MAPREDUCE_JOB_CONFIG_FOR_HADOOP; break; default: } if (category == EComponentCategory.HEADERFOOTER) { if (result.getResultType() == EUpdateResult.UPDATE) { if (result.isChecked()) { for (IElementParameter param : process.getElementParameters()) { if (param.getCategory() == EComponentCategory.HEADERFOOTER) { IElementParameter headerIDParameter = process.getElementParameter(EParameterName.HEADERFOOTER_HEADERID.getName()); if (headerIDParameter != null) { IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById( (String) headerIDParameter.getValue()); HeaderFooterConnection repositoryConnection = null; if (lastVersion != null) { final Item item = lastVersion.getProperty().getItem(); if (item != null && item instanceof ConnectionItem) { repositoryConnection = (HeaderFooterConnection) ((HeaderFooterConnectionItem) item).getConnection(); if (repositoryConnection != null) { Boolean isHeader = repositoryConnection.isIsHeader(); String libraries = repositoryConnection.getLibraries(); String mainCode = repositoryConnection.getMainCode(); String imports = repositoryConnection.getImports(); process .getElementParameter(EParameterName.HEADER_ENABLED.getName()) .setValue(isHeader); process .getElementParameter(EParameterName.HEADER_LIBRARY.getName()) .setValue(libraries); process .getElementParameter(EParameterName.HEADER_CODE.getName()) .setValue(mainCode); process .getElementParameter(EParameterName.HEADER_IMPORT.getName()) .setValue(imports); } } } } IElementParameter footerIDParameter = process.getElementParameter(EParameterName.HEADERFOOTER_FOOTERID.getName()); if (footerIDParameter != null) { IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById( (String) footerIDParameter.getValue()); HeaderFooterConnection repositoryConnection = null; if (lastVersion != null) { final Item item = lastVersion.getProperty().getItem(); if (item != null && item instanceof ConnectionItem) { repositoryConnection = (HeaderFooterConnection) ((HeaderFooterConnectionItem) item).getConnection(); if (repositoryConnection != null) { Boolean isHeader = repositoryConnection.isIsHeader(); String libraries = repositoryConnection.getLibraries(); String mainCode = repositoryConnection.getMainCode(); String imports = repositoryConnection.getImports(); process .getElementParameter(EParameterName.FOOTER_ENABLED.getName()) .setValue(!isHeader); process .getElementParameter(EParameterName.FOOTER_LIBRARY.getName()) .setValue(libraries); process .getElementParameter(EParameterName.FOOTER_CODE.getName()) .setValue(mainCode); process .getElementParameter(EParameterName.FOOTER_IMPORT.getName()) .setValue(imports); } } } } } } } } } else if (category != null) { boolean repository = false; if (result.getResultType() == EUpdateResult.UPDATE) { // upgrade from repository if (result.isChecked()) { IElementParameter property = process.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, category); if (property != null) { Map<String, IElementParameter> childParameters = property.getChildParameters(); if (childParameters != null) { IElementParameter elementParameter = childParameters.get(EParameterName.PROPERTY_TYPE.getName()); // is repository if (elementParameter != null && EmfComponent.REPOSITORY.equals(elementParameter.getValue())) { for (IElementParameter param : process.getElementParameters()) { if (param.getCategory() != category) { continue; } String repositoryValue = param.getRepositoryValue(); if (param.isShow(process.getElementParameters()) && (repositoryValue != null) && (!param.getName().equals(EParameterName.PROPERTY_TYPE.getName()))) { Object objectValue = RepositoryToComponentProperty.getValue( (org.talend.core.model.metadata.builder.connection.Connection) result.getParameter(), repositoryValue, null); if (objectValue != null) { if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && repositoryValue.equals(UpdatesConstants.TYPE)) { boolean found = false; String[] items = param.getListRepositoryItems(); for (int i = 0; (i < items.length) && (!found); i++) { if (objectValue.equals(items[i])) { found = true; process.setPropertyValue( param.getName(), param.getListItemsValue()[i]); } } } else if (EParameterName.HADOOP_ADVANCED_PROPERTIES .getName() .equals(param.getName())) { List<Map> list = (ArrayList) param.getValue(); for (Map map : list) { if (map.get("BUILDIN") != null && map.get("BUILDIN").equals("TRUE")) { if (objectValue instanceof List) { ((List) objectValue).add(map); } } } process.setPropertyValue(param.getName(), objectValue); } else { process.setPropertyValue(param.getName(), objectValue); } param.setRepositoryValueUsed(true); param.setReadOnly(true); repository = true; } } } } } } } } if (!repository) { IElementParameter property = process.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, category); if (property != null) { Map<String, IElementParameter> childParameters = property.getChildParameters(); if (childParameters != null) { IElementParameter elementParameter = childParameters.get(EParameterName.PROPERTY_TYPE.getName()); elementParameter.setValue(EmfComponent.BUILTIN); } } // built-in IElementParameter dbTypeParam = null; IElementParameter impliciteDbType = null; for (IElementParameter param : process.getElementParameters()) { if (param.getCategory() != category) { continue; } String repositoryValue = param.getRepositoryValue(); if (param.isShow(process.getElementParameters()) && (repositoryValue != null)) { // for mysql db verion if (EParameterName.DB_TYPE.getName().equals(param.getName()) && "TYPE".equals(repositoryValue)) { dbTypeParam = param; } if ("DB_TYPE_IMPLICIT_CONTEXT".equals(param.getName()) && "TYPE".equals(repositoryValue)) { impliciteDbType = param; } if (EParameterName.DB_VERSION.getName().equals(repositoryValue) && dbTypeParam != null && dbTypeParam.getValue() != null) { final int indexOfItem = dbTypeParam.getIndexOfItemFromList(dbTypeParam.getValue().toString()); String dbType = dbTypeParam.getListItemsDisplayCodeName()[indexOfItem]; setDBVersionForMysql(param, dbType); } else if (EParameterName.DB_VERSION.getName().equals(repositoryValue) && impliciteDbType != null && impliciteDbType.getValue() != null) { final int indexOfItem = impliciteDbType.getIndexOfItemFromList(impliciteDbType.getValue().toString()); String dbType = impliciteDbType.getListItemsDisplayCodeName()[indexOfItem]; setDBVersionForMysql(param, dbType); } param.setRepositoryValueUsed(false); param.setReadOnly(false); } } } } } // else { // for extension } }