use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class ComponentChooseDialog method createNewComponent.
public void createNewComponent(DropTargetEvent event1) {
boolean quickCreateInput = event1.detail == DND.DROP_LINK;
boolean quickCreateOutput = event1.detail == DND.DROP_COPY;
Iterator iterator = getSelection().iterator();
List<TempStore> list = new ArrayList<TempStore>();
List<IComponent> components = new ArrayList<IComponent>();
while (iterator.hasNext()) {
Object obj = iterator.next();
if (obj instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) obj;
if (equalsJobInCurrentEditor(sourceNode)) {
continue;
}
Item item = sourceNode.getObject().getProperty().getItem();
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
if (testContainerService != null && testContainerService.isTestContainerItem(item)) {
continue;
}
}
ERepositoryObjectType type = sourceNode.getObjectType();
if (!(item instanceof ConnectionItem) && !(item instanceof ProcessItem) && !(item instanceof JobletProcessItem) && !(item instanceof RulesItem) && !(item instanceof LinkRulesItem)) {
// RulesItem
return;
}
{
/**
* Remove this limitation for feature: TDI-32362, I think it should be ok, don't know why adding
* this limitation to forbid to d&d salseforce connection, I keep those code in case this behavior
* will cause some bugs when d&d salseforce connection, then maybe need to review
*/
// if (item instanceof SalesforceSchemaConnectionItem && type ==
// ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA) {
// return;
// }
}
TempStore store = new TempStore();
store.seletetedNode = sourceNode;
getAppropriateComponent(item, quickCreateInput, quickCreateOutput, store, type);
if (store.component != null) {
list.add(store);
} else {
MessageDialog.openInformation(editor.getEditorSite().getShell(), //$NON-NLS-1$
Messages.getString("TalendEditorDropTargetListener.dngsupportdialog.title"), //$NON-NLS-1$
Messages.getString("TalendEditorDropTargetListener.dngsupportdialog.content"));
}
}
org.eclipse.swt.graphics.Point swtLocation = new org.eclipse.swt.graphics.Point(event1.x, event1.y);
Canvas canvas = (Canvas) editor.getViewer().getControl();
/*
* translate to Canvas coordinate
*/
swtLocation = canvas.toControl(swtLocation);
org.eclipse.swt.graphics.Point size = canvas.getSize();
/*
* translate to Viewport coordinate with zoom
*/
org.eclipse.draw2d.geometry.Point draw2dPosition = new org.eclipse.draw2d.geometry.Point(swtLocation.x, swtLocation.y);
/*
* calcule the view port position. Take into acounte the scroll position
*/
ProcessPart part = (ProcessPart) editor.getViewer().getRootEditPart().getRoot().getChildren().get(0);
IFigure targetFigure = part.getFigure();
translateAbsolateToRelative(targetFigure, draw2dPosition);
//$NON-NLS-1$
String lastUniqname = "";
// creates every node
for (TempStore store : list) {
RepositoryNode selectedNode = store.seletetedNode;
IComponent element = store.component;
if (!components.contains(element)) {
components.add(element);
}
Node node = new Node(element);
// for bug4564(metadata label format)
// IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
// if (preferenceStore.getBoolean(TalendDesignerPrefConstants.USE_REPOSITORY_NAME)) {
// node.setPropertyValue(EParameterName.LABEL.getName(), selectedNode.getObject().getLabel());
// }
IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
if (preferenceStore.getBoolean(TalendDesignerPrefConstants.USE_REPOSITORY_NAME)) {
String LabelValue = null;
RepositoryNode repositoryNode = null;
repositoryNode = (RepositoryNode) getSelection().getFirstElement();
// dnd a table
IElementParameter dbTableParam = node.getElementParameterFromField(EParameterFieldType.DBTABLE);
boolean hasDbTableField = dbTableParam != null;
if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_TABLE && repositoryNode.getObject() != null && repositoryNode.getObject().getProperty().getItem() instanceof DatabaseConnectionItem && hasDbTableField) {
LabelValue = DesignerUtilities.getParameterVar(dbTableParam.getName());
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS || repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS_MR || repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS_STORM) {
// dnd a job
LabelValue = DesignerUtilities.getParameterVar(EParameterName.PROCESS);
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.JOBLET || repositoryNode.getObjectType() == ERepositoryObjectType.SPARK_JOBLET || repositoryNode.getObjectType() == ERepositoryObjectType.SPARK_STREAMING_JOBLET) {
LabelValue = element.getName();
} else if (CorePlugin.getDefault().getDesignerCoreService().getPreferenceStore(TalendDesignerPrefConstants.DEFAULT_LABEL).equals(node.getPropertyValue(EParameterName.LABEL.getName()))) {
// dnd a default
LabelValue = selectedNode.getObject().getLabel();
}
if (LabelValue != null) {
node.setPropertyValue(EParameterName.LABEL.getName(), LabelValue);
}
}
processSpecificDBTypeIfSameProduct(store.componentName, node);
NodeContainer nc = ((Process) node.getProcess()).loadNodeContainer(node, false);
;
// create component on link
boolean executed = false;
if (getSelection().size() == 1 && getTargetEditPart() instanceof SubjobContainerPart) {
executed = createComponentOnLink(node, draw2dPosition);
}
if (!executed) {
// create the node on the design sheet
execCommandStack(new CreateNodeContainerCommand((Process) editor.getProcess(), nc, draw2dPosition));
}
// initialize the propertiesView
CompoundCommand cc = new CompoundCommand();
createRefreshingPropertiesCommand(cc, selectedNode, node);
execCommandStack(cc);
// for (Command command : commands) {
// }
propaHadoopCfgChanges(selectedNode);
draw2dPosition = draw2dPosition.getCopy();
draw2dPosition.x += TalendEditor.GRID_SIZE;
draw2dPosition.y += TalendEditor.GRID_SIZE;
node.checkNode();
lastUniqname = node.getUniqueName();
}
// setselecte(part, lastUniqname);
}
// Shell shell = Display.getCurrent().getActiveShell();
// ModulesInstallerUtil.installModules(new Shell(shell), components);
}
use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class ComponentChooseDialog method extractComponents.
/**
* Extracts the components which have the same palette type as process. Added by Marvin Wang on Feb 27, 2013.
*
* @param neededComponents
* @return
*/
protected List<IComponent> extractComponents(List<IComponent> neededComponents) {
if (neededComponents != null && neededComponents.size() > 0) {
Iterator<IComponent> componentsIterator = neededComponents.iterator();
while (componentsIterator.hasNext()) {
IComponent component = componentsIterator.next();
String compType = component.getPaletteType();
if (compType != null && !compType.equals(editor.getProcess().getComponentsType())) {
componentsIterator.remove();
}
}
}
return neededComponents;
}
use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class ConvertRepositoryNodeToProcessNode method convertToProcessNode.
public void convertToProcessNode(ConnectionItem connectionItem, String tableName) throws ProcessorException {
EDatabaseComponentName name = EDatabaseComponentName.getCorrespondingComponentName(connectionItem, ERepositoryObjectType.METADATA_CONNECTIONS);
String componentName = null;
componentName = name.getDefaultComponentName();
IComponent dbInputComponent = ComponentsFactoryProvider.getInstance().get(componentName, ComponentCategory.CATEGORY_4_DI.getName());
Process process = new Process(GuessSchemaProcess.getNewmockProperty());
node = new Node(dbInputComponent, process);
selectedContext = node.getProcess().getContextManager().getDefaultContext();
// TDI-20011
IMetadataTable table = UpdateRepositoryUtils.getTableByName(connectionItem, tableName);
if (table == null) {
table = new MetadataTable();
table.setTableName(tableName);
table.setLabel(tableName);
}
IElementParameter propertyParam = ((Node) node).getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
IElementParameter schemaParam = ((Node) node).getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
if (schemaParam == null) {
schemaParam = ((Node) node).getElementParameterFromField(EParameterFieldType.SCHEMA_REFERENCE);
}
String propertyId = connectionItem.getProperty().getId();
String schema = databaseConnection.getUiSchema();
String dbType = databaseConnection.getDatabaseType();
//$NON-NLS-1$
String value = connectionItem.getProperty().getId() + " - " + table.getLabel();
CompoundCommand cc = new CompoundCommand();
// inital parameters command
ChangeValuesFromRepository changeValueCommand = new ChangeValuesFromRepository(node, databaseConnection, propertyParam.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), //$NON-NLS-1$
propertyId);
changeValueCommand.ignoreContextMode(true);
cc.add(changeValueCommand);
// change metadata command
RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) node, //$NON-NLS-1$
schemaParam.getName() + ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName(), value, table, null, null);
cc.add(changeMetadataCommand);
// guess query command
QueryGuessCommand queryGuessCommand = new QueryGuessCommand(node, node.getMetadataList().get(0), schema, dbType, databaseConnection);
cc.add(queryGuessCommand);
// execute the commands
cc.execute();
//$NON-NLS-1$
IElementParameter query = node.getElementParameter("QUERY");
//
memoSQL = query.getValue().toString();
String memoSQLTemp = TalendTextUtils.removeQuotesIfExist(memoSQL);
if ((memoSQLTemp == null || memoSQLTemp.equals("")) && tableName != null && !tableName.equals("")) {
//$NON-NLS-1$
boolean check = !Pattern.matches("^\\w+$", tableName);
boolean isJDBCForMysql = databaseConnection.getURL() == null ? false : databaseConnection.getURL().startsWith("jdbc:mysql");
if ((dbType.equals(EDatabaseTypeName.MYSQL.getDisplayName()) || isJDBCForMysql) && check) {
tableName = TalendQuoteUtils.addQuotes(tableName, TalendQuoteUtils.ANTI_QUOTE);
}
memoSQL = "select * from " + tableName;
memoSQL = TalendTextUtils.addSQLQuotes(memoSQL);
}
}
use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class ComponentChooseDialog method chooseOneComponent.
/**
* Let the user choose which component he would like to create.
*
* @param neededComponents
* @param name
* @param quickCreateInput
* @param quickCreateOutput
*/
private IComponent chooseOneComponent(List<IComponent> neededComponents, IComponentName name, boolean quickCreateInput, boolean quickCreateOutput) {
if (neededComponents.isEmpty()) {
return null;
}
if (neededComponents.size() == 1) {
return neededComponents.get(0);
}
IComponent inputComponent = getComponentByName(name.getInputComponentName(), quickCreateInput, neededComponents);
if (inputComponent != null) {
return inputComponent;
}
IComponent outputComponent = getComponentByName(name.getOutPutComponentName(), quickCreateOutput, neededComponents);
if (outputComponent != null) {
return outputComponent;
}
ComponentChooseDialog dialog = new ComponentChooseDialog(editor.getSite().getShell(), neededComponents);
IComponent defaultComponent = getComponentByName(name.getDefaultComponentName(), true, neededComponents);
if (defaultComponent != null) {
dialog.setInitialSelections(new Object[] { defaultComponent });
} else {
dialog.setInitialSelections(new Object[] { neededComponents.get(0) });
}
if (dialog.open() == IDialogConstants.OK_ID) {
return dialog.getResultComponent();
}
//$NON-NLS-1$
throw new OperationCanceledException(Messages.getString("TalendEditorDropTargetListener.cancelOperation"));
}
use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class ComponentChooseDialog method getAppropriateComponent.
private void getAppropriateComponent(Item item, boolean quickCreateInput, boolean quickCreateOutput, TempStore store, ERepositoryObjectType type) {
IComponentName rcSetting = RepositoryComponentManager.getSetting(item, type);
// For handler, need check for esb
if (rcSetting == null) {
for (IDragAndDropServiceHandler handler : DragAndDropManager.getHandlers()) {
rcSetting = handler.getCorrespondingComponentName(item, type);
if (rcSetting != null) {
break;
}
}
if (rcSetting == null) {
return;
}
}
boolean isCurrentProject = true;
String projectName = null;
if (store.seletetedNode.getObject() != null) {
projectName = store.seletetedNode.getObject().getProjectLabel();
isCurrentProject = projectName.equals(ProjectManager.getInstance().getCurrentProject().getLabel());
}
List<IComponent> neededComponents = RepositoryComponentManager.filterNeededComponents(item, store.seletetedNode, type, isCurrentProject, projectName);
for (IDragAndDropServiceHandler handler : DragAndDropManager.getHandlers()) {
List<IComponent> comList = handler.filterNeededComponents(item, store.seletetedNode, type);
if (comList != null) {
for (IComponent handlerComp : comList) {
if (!neededComponents.contains(handlerComp) && !handlerComp.isTechnical()) {
neededComponents.add(handlerComp);
}
}
}
}
// special handle hbase to support tpigLoad
String hbaseName = EDatabaseTypeName.HBASE.getDisplayName().toUpperCase();
if (rcSetting != null && (hbaseName).equals(rcSetting.toString())) {
IComponentsService service = (IComponentsService) GlobalServiceRegister.getDefault().getService(IComponentsService.class);
String componentProductname = null;
Set<IComponent> components = service.getComponentsFactory().getComponents();
for (IComponent component : components) {
componentProductname = component.getRepositoryType();
if (componentProductname != null && componentProductname.contains(hbaseName) && !neededComponents.contains(component) && !component.isTechnical()) {
neededComponents.add(component);
}
}
}
neededComponents = (List<IComponent>) ComponentUtilities.filterVisibleComponents(neededComponents);
// Check if the components in the list neededComponents have the same category that is required by Process.
IComponent component = chooseOneComponent(extractComponents(neededComponents), rcSetting, quickCreateInput, quickCreateOutput);
store.component = component;
store.componentName = rcSetting;
}
Aggregations