use of org.talend.core.model.properties.ContextItem in project tesb-studio-se by Talend.
the class CamelEditorDropTargetListener method checkSelectionSource.
/**
* Routelet and context types are validated
*
* @return true if validated
*/
private boolean checkSelectionSource() {
isContextSource = false;
selectSourceList.clear();
boolean isRouteletSource = false;
LocalSelectionTransfer transfer = (LocalSelectionTransfer) getTransfer();
IStructuredSelection selection = (IStructuredSelection) transfer.getSelection();
Iterator iterator = selection.iterator();
while (iterator.hasNext()) {
Object obj = iterator.next();
if (obj instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) obj;
if (sourceNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.PROCESS_ROUTELET) {
selectSourceList.add(obj);
isRouteletSource = true;
}
Item item = sourceNode.getObject().getProperty().getItem();
if (item instanceof ContextItem) {
selectSourceList.add(obj);
isContextSource = true;
}
} else if (obj instanceof PaletteEditPart) {
selectSourceList.add(obj);
Object newObject = ((CreateRequest) getTargetRequest()).getNewObject();
if (newObject != null && newObject instanceof INode) {
if (((INode) newObject).getComponent().getComponentType() == EComponentType.JOBLET) {
selectSourceList.add(newObject);
isRouteletSource = true;
}
}
}
}
if (selectSourceList.size() == 0) {
return false;
}
if (isRouteletSource) {
List<String> routeletList = new ArrayList<String>();
for (INode node : editor.getProcess().getGraphicalNodes()) {
if (node.getComponent().getComponentType() == EComponentType.JOBLET) {
routeletList.add(node.getComponent().getName());
}
}
boolean isDuplicateRoutelet = false;
String duplicatesName = "";
for (Object object : selectSourceList) {
if (object instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) object;
if (sourceNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.PROCESS_ROUTELET) {
if (routeletList.contains(sourceNode.getProperties(EProperties.LABEL))) {
isDuplicateRoutelet = true;
//$NON-NLS-1$
duplicatesName += " ," + sourceNode.getProperties(EProperties.LABEL);
}
}
} else if (object instanceof INode) {
INode node = (INode) object;
if (node.getComponent().getComponentType() == EComponentType.JOBLET) {
if (routeletList.contains(node.getComponent().getName())) {
isDuplicateRoutelet = true;
//$NON-NLS-1$
duplicatesName += " ," + node.getComponent().getName();
}
}
}
}
if (isDuplicateRoutelet) {
//$NON-NLS-1$
MessageDialog.openInformation(//$NON-NLS-1$
editor.getEditorSite().getShell(), //$NON-NLS-1$
"Adding Routelet", //$NON-NLS-1$
"Do not allow duplicate Routelets\nRoutelet \"" + duplicatesName.substring(2) + "\" already exist.");
return false;
}
}
return true;
}
use of org.talend.core.model.properties.ContextItem in project tdi-studio-se by Talend.
the class ContextRepositoryCommand method loadContextFromId.
private boolean loadContextFromId(String repositoryId) {
IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
List<ContextItem> contextItemList = null;
try {
contextItemList = factory.getContextItem();
} catch (PersistenceException e) {
throw new RuntimeException(e);
}
if (contextItemList != null) {
for (ContextItem item : contextItemList) {
if (factory.getStatus(item) != ERepositoryStatus.DELETED) {
String id = item.getProperty().getId();
if (id.equals(repositoryId)) {
contextManager.loadFromEmf(item.getContext(), item.getDefaultContext());
return true;
}
}
}
}
return false;
}
use of org.talend.core.model.properties.ContextItem in project tdi-studio-se by Talend.
the class ComponentChooseDialog method dragOver.
@Override
public void dragOver(DropTargetEvent event) {
// multi-drag for job,context, sqlPattern.
IStructuredSelection selection = getSelection();
if (selection.size() > 1) {
boolean allowed = true;
Item temItem = null;
Iterator iter = selection.iterator();
while (iter.hasNext()) {
Object next = iter.next();
if (next instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) next;
IRepositoryViewObject object = sourceNode.getObject();
if (object != null) {
Item selectItem = object.getProperty().getItem();
if (temItem == null) {
temItem = selectItem;
continue;
}
if (selectItem instanceof ProcessItem && !(temItem instanceof ProcessItem)) {
allowed = false;
} else if (selectItem instanceof ContextItem && !(temItem instanceof ContextItem)) {
allowed = false;
} else if (selectItem instanceof SQLPatternItem && !(temItem instanceof SQLPatternItem)) {
allowed = false;
}
}
}
}
if (!allowed) {
event.detail = DND.DROP_NONE;
}
} else {
CreateRequest req = ((CreateRequest) getTargetRequest());
Object o = null;
try {
o = req.getNewObject();
} catch (Exception e) {
return;
}
if (!(o instanceof Node)) {
return;
}
RootEditPart rep = editor.getViewer().getRootEditPart().getRoot();
Point viewOriginalPosition = new Point();
if (rep instanceof ScalableFreeformRootEditPart) {
ScalableFreeformRootEditPart root = (ScalableFreeformRootEditPart) rep;
Viewport viewport = (Viewport) root.getFigure();
viewOriginalPosition = viewport.getViewLocation();
}
org.eclipse.swt.graphics.Point swtLocation = new org.eclipse.swt.graphics.Point(event.x + viewOriginalPosition.x, event.y + viewOriginalPosition.y);
Canvas canvas = (Canvas) editor.getViewer().getControl();
swtLocation = canvas.toControl(swtLocation);
// System.out.println("topLeft:" + topLeftpoint + " / event:" + swtLocation);
org.eclipse.draw2d.geometry.Point draw2dPosition = new org.eclipse.draw2d.geometry.Point(swtLocation.x, swtLocation.y);
double zoom = 1.0;
if (editor.getViewer().getRootEditPart() instanceof TalendScalableFreeformRootEditPart) {
ZoomManager zoomManager = ((TalendScalableFreeformRootEditPart) editor.getViewer().getRootEditPart()).getZoomManager();
zoom = zoomManager.getZoom();
}
List<ConnectionPart> connectionParts = CreateComponentOnLinkHelper.getConnectionParts(editor.getProcessPart(), draw2dPosition, (Node) o);
double minDistance = 1000000000;
for (ConnectionPart part : connectionParts) {
if (part.getFigure() instanceof PolylineConnection) {
PolylineConnection connection = (PolylineConnection) part.getFigure();
double distance = CreateComponentOnLinkHelper.getDistanceOrthogonal(draw2dPosition.x, draw2dPosition.y, connection, zoom);
if (distance < minDistance) {
selectedConnectionPart = part;
minDistance = Math.min(distance, minDistance);
}
}
}
if (selectedConnectionPart != null && minDistance < 15) {
for (Object child : editor.getProcessPart().getChildren()) {
if (child instanceof SubjobContainerPart) {
CreateComponentOnLinkHelper.unselectAllConnections((SubjobContainerPart) child);
}
}
CreateComponentOnLinkHelper.selectConnection(selectedConnectionPart);
} else {
if (selectedConnectionPart != null) {
CreateComponentOnLinkHelper.unselectConnection(selectedConnectionPart);
}
selectedConnectionPart = null;
}
}
}
use of org.talend.core.model.properties.ContextItem in project tdi-studio-se by Talend.
the class UpdateContextParameterCommand method doExecute.
private void doExecute() {
if (result == null) {
return;
}
Object job = result.getJob();
if (job == null) {
return;
}
if (job instanceof IProcess2) {
IProcess2 process = (IProcess2) job;
ContextParameterMap deleteParameters = new ContextParameterMap();
Object updateObject = result.getUpdateObject();
List<IContext> listContext = process.getContextManager().getListContext();
if (updateObject instanceof Set) {
Set<String> names = (Set<String>) updateObject;
if (result.getResultType() == EUpdateResult.ADD && result.isChecked()) {
// check parameters that have been added to repository context group
checkNewRepositoryParameters(process, names);
return;
}
for (IContext context : listContext) {
for (IContextParameter param : context.getContextParameterList()) {
ContextItem item = null;
if (names != null && names.contains(param.getName())) {
switch(result.getResultType()) {
case DELETE:
item = (ContextItem) result.getParameter();
if (item != null && item.getProperty().getId().equals(param.getSource()) && result.isChecked()) {
// delete it later
deleteParameters.addParameter(context, param);
} else {
param.setSource(IContextParameter.BUILT_IN);
}
break;
case UPDATE:
item = (ContextItem) result.getParameter();
if (item != null && item.getProperty().getId().equals(param.getSource()) && result.isChecked()) {
ContextUtils.updateParameterFromRepository(item, param, context.getName());
} else {
param.setSource(IContextParameter.BUILT_IN);
}
break;
case RENAME:
List<Object> parameter = (List<Object>) result.getParameter();
if (parameter.size() >= 3) {
item = (ContextItem) parameter.get(0);
String sourceId = item.getProperty().getId();
String oldName = (String) parameter.get(1);
String newName = (String) parameter.get(2);
if (oldName.equals(param.getName()) && sourceId.equals(param.getSource())) {
if (newName != null) {
param.setName(newName);
ContextUtils.updateParameterFromRepository(item, param, context.getName());
}
}
}
break;
// built-in
case BUIL_IN:
default:
param.setSource(IContextParameter.BUILT_IN);
break;
}
}
}
}
}
if (updateObject instanceof JobContext) {
if (result.getResultType() == EUpdateResult.ADD && result.getUpdateType() == EUpdateItemType.CONTEXT_GROUP && result.isChecked()) {
IContext context = (IContext) updateObject;
String name = context.getName();
if (!listContext.contains(context) && result.getParameter() instanceof ContextItem) {
ContextItem item = (ContextItem) result.getParameter();
JobContext newContext = new JobContext(name);
List<IContextParameter> newParamList = new ArrayList<IContextParameter>();
newContext.setContextParameterList(newParamList);
JobContextParameter param = null;
// add other context params to the new group
for (IContextParameter contextParam : process.getContextManager().getDefaultContext().getContextParameterList()) {
boolean exist = false;
for (IContextParameter existParam : context.getContextParameterList()) {
if (contextParam.getName().equals(existParam.getName())) {
exist = true;
}
}
if (exist) {
continue;
}
param = (JobContextParameter) contextParam.clone();
param.setContext(newContext);
newParamList.add(param);
}
// current context params for the new group
for (int i = 0; i < context.getContextParameterList().size(); i++) {
IContextParameter oldParam = context.getContextParameterList().get(i);
param = (JobContextParameter) oldParam.clone();
param.setSource(item.getProperty().getId());
param.setContext(newContext);
newParamList.add(param);
}
listContext.add(newContext);
}
} else if (result.getResultType() == EUpdateResult.DELETE && result.getUpdateType() == EUpdateItemType.CONTEXT_GROUP && result.isChecked()) {
IContext context = (IContext) updateObject;
if (result.getParameter() instanceof ContextItem) {
ContextItem item = (ContextItem) result.getParameter();
List<IContext> listC = new ArrayList<IContext>(listContext);
for (IContext con : listC) {
if (con.getName().equals(context.getName())) {
for (IContextParameter oldParam : con.getContextParameterList()) {
if (item.getProperty().getId().equals(oldParam.getSource())) {
listContext.remove(con);
}
}
}
}
}
return;
} else if (result.getResultType() == EUpdateResult.RENAME && result.getUpdateType() == EUpdateItemType.CONTEXT_GROUP && result.isChecked()) {
IContext context = (IContext) updateObject;
IContextManager contextManager = process.getContextManager();
Map<IContext, String> renameGroupContext = ((JobContextManager) contextManager).getRenameGroupContext();
String oldName = renameGroupContext.get(context);
if (result.getParameter() instanceof ContextItem) {
ContextItem item = (ContextItem) result.getParameter();
for (IContext con : listContext) {
if (con.getName().equals(oldName)) {
for (IContextParameter oldParam : con.getContextParameterList()) {
if (item.getProperty().getId().equals(oldParam.getSource())) {
con.setName(context.getName());
}
}
}
}
}
}
return;
}
// delete parameters
deleteParameters.removeFromContext();
// update parameters
if (result.getResultType() == EUpdateResult.RENAME) {
List<Object> parameter = (List<Object>) result.getParameter();
if (parameter.size() >= 3) {
String oldName = (String) parameter.get(1);
String newName = (String) parameter.get(2);
UpdateContextVariablesHelper.updateProcessForRenamed(process, oldName, newName);
// tRunJob parameters rename
IEditorReference[] reference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
List<IProcess2> processes = RepositoryPlugin.getDefault().getDesignerCoreService().getOpenedProcess(reference);
Map<String, String> renamedMap = new HashMap<String, String>();
renamedMap.put(newName, oldName);
UpdateRunJobComponentContextHelper.updateOpenedJobRunJobComponentReference(processes, renamedMap, process.getId(), null);
try {
// perhaps, need optimize.
UpdateRunJobComponentContextHelper.updateItemRunJobComponentReference(DesignerPlugin.getDefault().getProxyRepositoryFactory(), renamedMap, process.getId(), null);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
}
}
}
use of org.talend.core.model.properties.ContextItem in project tdi-studio-se by Talend.
the class ComponentChooseDialog method createContext.
private void createContext(List<Object> sourceList) {
if (sourceList.size() == 0) {
return;
}
boolean created = false;
for (Object source : sourceList) {
if (source instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) source;
Item item = sourceNode.getObject().getProperty().getItem();
if (item instanceof ContextItem) {
ContextItem contextItem = (ContextItem) item;
EList context = contextItem.getContext();
Set<String> contextSet = new HashSet<String>();
Iterator iterator = context.iterator();
while (iterator.hasNext()) {
Object obj = iterator.next();
if (obj instanceof ContextTypeImpl) {
EList contextParameters = ((ContextTypeImpl) obj).getContextParameter();
Iterator contextParas = contextParameters.iterator();
while (contextParas.hasNext()) {
ContextParameterTypeImpl contextParameterType = (ContextParameterTypeImpl) contextParas.next();
String name = contextParameterType.getName();
contextSet.add(name);
}
}
}
IEditorInput editorInput = editor.getEditorInput();
if (editorInput instanceof JobEditorInput) {
JobEditorInput jobInput = (JobEditorInput) editorInput;
IProcess2 process = jobInput.getLoadedProcess();
IContextManager contextManager = process.getContextManager();
List<IContext> listContext = contextManager.getListContext();
// context group will reflect absolutely if no context variable in contextViewer
// if (!ConnectionContextHelper.containsVariable(contextManager)) {
// for bug 15608
// ConnectionContextHelper.addContextVarForJob(process, contextItem, contextManager);
// ConnectionContextHelper.checkAndAddContextsVarDND(contextItem, contextManager);
Set<String> addedVars = ConnectionContextHelper.checkAndAddContextVariables(contextItem, contextSet, process.getContextManager(), false);
if (addedVars != null && !addedVars.isEmpty() && !ConnectionContextHelper.isAddContextVar(contextItem, contextManager, contextSet)) {
// show
Map<String, Set<String>> addedVarsMap = new HashMap<String, Set<String>>();
addedVarsMap.put(item.getProperty().getLabel(), contextSet);
if (ConnectionContextHelper.showContextdialog(process, contextItem, process.getContextManager(), addedVarsMap, contextSet)) {
created = true;
}
}
// } else {
// Set<String> addedContext = ConnectionContextHelper.checkAndAddContextVariables(contextItem,
// contextSet, contextManager, false);
// if (addedContext != null && addedContext.size() > 0) {
// ConnectionContextHelper.addContextVarForJob(process, contextItem, contextSet);
// created = true;
// }
// }
}
}
}
}
if (created) {
RepositoryPlugin.getDefault().getDesignerCoreService().switchToCurContextsView();
}
}
Aggregations