use of org.talend.core.ui.IJobletProviderService in project tdi-studio-se by Talend.
the class GEFDeleteAction method createDeleteCommand.
@Override
public Command createDeleteCommand(List objects) {
objects = filterSameObject(objectsToDelete);
if (objects.isEmpty()) {
return null;
}
if (!(objects.get(0) instanceof EditPart)) {
return null;
}
EditPart object = (EditPart) objects.get(0);
// for TUP-1015
boolean isConnAttachedJLTriggerComp = false;
ConnectionPart connectionPart = null;
if (object instanceof ConnectionPart) {
connectionPart = (ConnectionPart) object;
} else if (object instanceof ConnLabelEditPart) {
connectionPart = (ConnectionPart) object.getParent();
}
if (connectionPart != null) {
Node srcNode = null;
Object srcModel = connectionPart.getSource().getModel();
if (srcModel instanceof Node) {
srcNode = (Node) srcModel;
}
Node tarNode = null;
Object tarModel = connectionPart.getTarget().getModel();
if (tarModel instanceof Node) {
tarNode = (Node) tarModel;
}
if (srcNode == null || tarNode == null) {
return null;
}
IProcess process = srcNode.getProcess();
if (AbstractProcessProvider.isExtensionProcessForJoblet(process)) {
IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (service != null && (service.isTriggerNode(srcNode) || service.isTriggerNode(tarNode))) {
isConnAttachedJLTriggerComp = true;
}
}
}
IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
String preKey = TalendDesignerPrefConstants.NOT_SHOW_WARNING_WHEN_DELETE_LINK_WITH_JOBLETTRIGGERLINKCOMPONENT;
if (isConnAttachedJLTriggerComp && !preferenceStore.getBoolean(preKey)) {
MessageDialogWithToggle jlTriggerConfirmDialog = new MessageDialogWithToggle(null, //$NON-NLS-1$
Messages.getString("GEFDeleteAction.deleteConnectionDialog.title"), // accept the default window icon
null, Messages.getString("GEFDeleteAction.deleteConnectionDialog.msg"), MessageDialog.WARNING, new String[] { //$NON-NLS-1$
IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0, //$NON-NLS-1$
Messages.getString("GEFDeleteAction.deleteConnectionDialog.toggleMsg"), preferenceStore.getDefaultBoolean(preKey));
jlTriggerConfirmDialog.setPrefStore(preferenceStore);
jlTriggerConfirmDialog.setPrefKey(preKey);
if (jlTriggerConfirmDialog.open() != IDialogConstants.YES_ID) {
return null;
}
preferenceStore.setValue(preKey, jlTriggerConfirmDialog.getToggleState());
}
List nodeParts = new ArrayList();
List noteParts = new ArrayList();
List others = new ArrayList(objects);
for (Object o : objects) {
if (o instanceof NodePart) {
others.remove(o);
Node model = (Node) ((NodePart) o).getModel();
if (model.getJobletNode() != null) {
continue;
}
if (model.getJunitNode() != null) {
continue;
}
nodeParts.add(o);
} else if (o instanceof NoteEditPart) {
noteParts.add(o);
others.remove(o);
} else if (o instanceof SubjobContainerPart) {
others.remove(o);
SubjobContainerPart subjob = (SubjobContainerPart) o;
for (Iterator iterator = subjob.getChildren().iterator(); iterator.hasNext(); ) {
NodeContainerPart nodeContainerPart = (NodeContainerPart) iterator.next();
if (nodeContainerPart instanceof JobletContainerPart) {
JobletContainer jobletCon = (JobletContainer) ((JobletContainerPart) nodeContainerPart).getModel();
JobletContainerFigure jobletFigure = (JobletContainerFigure) ((JobletContainerPart) nodeContainerPart).getFigure();
if (!jobletCon.isCollapsed()) {
jobletFigure.doCollapse();
}
}
NodePart nodePart = nodeContainerPart.getNodePart();
if (nodePart != null) {
Node model = (Node) nodePart.getModel();
if (model.getJunitNode() != null) {
continue;
}
nodeParts.add(nodePart);
}
}
}
}
if (others.size() == 0) {
// so notes & nodes only
CompoundCommand cpdCmd = new CompoundCommand();
//$NON-NLS-1$
cpdCmd.setLabel(Messages.getString("GEFDeleteAction.DeleteItems"));
if (nodeParts.size() != 0) {
GroupRequest deleteReq = new GroupRequest(RequestConstants.REQ_DELETE);
deleteReq.setEditParts(nodeParts);
cpdCmd.add(((NodePart) nodeParts.get(0)).getCommand(deleteReq));
}
if (noteParts.size() != 0) {
GroupRequest deleteReq = new GroupRequest(RequestConstants.REQ_DELETE);
deleteReq.setEditParts(noteParts);
cpdCmd.add(((NoteEditPart) noteParts.get(0)).getCommand(deleteReq));
}
return cpdCmd;
} else {
GroupRequest deleteReq = new GroupRequest(RequestConstants.REQ_DELETE);
deleteReq.setEditParts(objects);
Command cmd = object.getCommand(deleteReq);
return cmd;
}
}
use of org.talend.core.ui.IJobletProviderService in project tdi-studio-se by Talend.
the class ConnectionCreateAction method getConnectors.
public List<INodeConnector> getConnectors() {
List<INodeConnector> list = new ArrayList<INodeConnector>();
if (getSelectedObjects().isEmpty()) {
return list;
}
List parts = getSelectedObjects();
if (parts.size() == 1) {
Object o = parts.get(0);
if (!(o instanceof NodePart)) {
return list;
}
nodePart = (NodePart) o;
if (!(nodePart.getModel() instanceof Node)) {
return list;
}
Node node = (Node) nodePart.getModel();
if (!node.isActivate()) {
return list;
}
List<INodeConnector> nodeConnectorList = new ArrayList<INodeConnector>(node.getConnectorsFromType(connecType));
List<INodeConnector> toRemove = new ArrayList<INodeConnector>();
for (INodeConnector connector : nodeConnectorList) {
if ((connector.getMaxLinkOutput() != -1) && (connector.getCurLinkNbOutput() >= connector.getMaxLinkOutput())) {
toRemove.add(connector);
} else {
if (PluginChecker.isJobLetPluginLoaded()) {
IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (service != null) {
if (service.isJobletComponent(node) && !service.isBuiltTriggerConnector(node, connector)) {
toRemove.add(connector);
}
// for bug 10973
List<? extends IConnection> outgoingConnections = node.getOutgoingConnections();
if (service.isTriggerInputNode(node) && outgoingConnections != null && outgoingConnections.size() >= 1) {
toRemove.add(connector);
}
}
}
}
}
nodeConnectorList.removeAll(toRemove);
return nodeConnectorList;
}
return list;
}
use of org.talend.core.ui.IJobletProviderService in project tdi-studio-se by Talend.
the class ComponentChooseDialog method createComponentOnLink.
private boolean createComponentOnLink(Node node, Point originalPoint) {
boolean executed = false;
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();
}
Point point = new Point(originalPoint.x + viewOriginalPosition.x, originalPoint.y + viewOriginalPosition.y);
point.x = (int) (point.x / AnimatableZoomManager.currentZoom);
point.y = (int) (point.y / AnimatableZoomManager.currentZoom);
org.talend.designer.core.ui.editor.connections.Connection targetConnection = null;
if (selectedConnectionPart != null) {
targetConnection = (org.talend.designer.core.ui.editor.connections.Connection) selectedConnectionPart.getModel();
}
if (targetConnection != null) {
IProcess2 p = editor.getProcess();
NodeContainer nodeContainer = ((Process) node.getProcess()).loadNodeContainer(node, false);
// TDI-21099
if (p instanceof Process) {
CreateNodeContainerCommand createCmd = new CreateNodeContainerCommand((Process) p, nodeContainer, point);
execCommandStack(createCmd);
// reconnect the node
Node originalTarget = (Node) targetConnection.getTarget();
EConnectionType connectionType = EConnectionType.FLOW_MAIN;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
if (camelService.isRouteBuilderNode(node)) {
connectionType = camelService.getTargetConnectionType(node);
}
}
INodeConnector targetConnector = node.getConnectorFromType(connectionType);
for (INodeConnector connector : node.getConnectorsFromType(connectionType)) {
if (connector.getMaxLinkOutput() != 0) {
targetConnector = connector;
break;
}
}
ConnectionCreateCommand.setCreatingConnection(true);
// bug 21411
if (PluginChecker.isJobLetPluginLoaded()) {
IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (service != null && service.isJobletComponent(targetConnection.getTarget())) {
if (targetConnection.getTarget() instanceof Node) {
NodeContainer jobletContainer = ((Node) targetConnection.getTarget()).getNodeContainer();
// remove the old connection in the container
jobletContainer.getInputs().remove(targetConnection);
}
}
}
ConnectionReconnectCommand cmd2 = new ConnectionReconnectCommand(targetConnection);
cmd2.setNewTarget(node);
execCommandStack(cmd2);
List<Object> nodeArgs = CreateComponentOnLinkHelper.getTargetArgs(targetConnection, node);
ConnectionCreateCommand nodeCmd = new ConnectionCreateCommand(node, targetConnector.getName(), nodeArgs, false);
nodeCmd.setTarget(originalTarget);
execCommandStack(nodeCmd);
// Setting,such as the target is TMap
if (node.getOutgoingConnections().size() > 0) {
if (node.getExternalNode() instanceof MapperExternalNode) {
CreateComponentOnLinkHelper.setupTMap(node);
}
if (originalTarget.getExternalNode() instanceof MapperExternalNode) {
CreateComponentOnLinkHelper.updateTMap(originalTarget, targetConnection, node.getOutgoingConnections().get(0));
}
originalTarget.renameData(targetConnection.getName(), node.getOutgoingConnections().get(0).getName());
}
if (!ConnectionCreateCommand.isCreatingConnection()) {
return true;
}
executed = true;
}
}
return executed;
}
use of org.talend.core.ui.IJobletProviderService in project tdi-studio-se by Talend.
the class ImportItemUtil method importItemRecords.
@SuppressWarnings("unchecked")
public List<ItemRecord> importItemRecords(final ResourcesManager manager, final List<ItemRecord> itemRecords, final IProgressMonitor monitor, final boolean overwrite, final IPath destinationPath, final String contentType) {
TimeMeasure.display = CommonsPlugin.isDebugMode();
TimeMeasure.displaySteps = CommonsPlugin.isDebugMode();
TimeMeasure.measureActive = CommonsPlugin.isDebugMode();
TimeMeasure.begin("importItemRecords");
hasJoblets = false;
statAndLogsSettingsReloaded = false;
implicitSettingsReloaded = false;
restoreFolder = new RestoreFolderUtil();
Collections.sort(itemRecords, new Comparator<ItemRecord>() {
@Override
public int compare(ItemRecord o1, ItemRecord o2) {
if (o1.getProperty().getItem() instanceof RoutineItem && o2.getProperty().getItem() instanceof RoutineItem) {
return 0;
} else if (!(o1.getProperty().getItem() instanceof RoutineItem) && !(o2.getProperty().getItem() instanceof RoutineItem)) {
// TUP-2548 sort items by label
String label = o1.getLabel();
if (label == null) {
return -1;
}
final String label2 = o2.getLabel();
if (label2 == null) {
return 1;
}
return label.compareTo(label2);
} else if (o1.getProperty().getItem() instanceof RoutineItem) {
return -1;
} else {
return 1;
}
}
});
//$NON-NLS-1$
monitor.beginTask(Messages.getString("ImportItemWizardPage.ImportSelectedItems"), itemRecords.size() * 2 + 1);
RepositoryWorkUnit repositoryWorkUnit = new //$NON-NLS-1$
RepositoryWorkUnit(//$NON-NLS-1$
"Import Items") {
@Override
public void run() throws PersistenceException {
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
final IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
// bug 10520
final Set<String> overwriteDeletedItems = new HashSet<String>();
final Set<String> idDeletedBeforeImport = new HashSet<String>();
Map<String, String> nameToIdMap = new HashMap<String, String>();
for (ItemRecord itemRecord : itemRecords) {
if (!monitor.isCanceled()) {
if (itemRecord.isValid()) {
if (itemRecord.getState() == State.ID_EXISTED) {
String id = nameToIdMap.get(itemRecord.getProperty().getLabel() + ERepositoryObjectType.getItemType(itemRecord.getProperty().getItem()).toString());
if (id == null) {
/*
* if id exsist then need to genrate new id for this job,in this case the
* job won't override the old one
*/
id = EcoreUtil.generateUUID();
nameToIdMap.put(itemRecord.getProperty().getLabel() + ERepositoryObjectType.getItemType(itemRecord.getProperty().getItem()).toString(), id);
}
itemRecord.getProperty().setId(id);
}
}
}
}
for (ItemRecord itemRecord : itemRecords) {
if (!monitor.isCanceled()) {
if (itemRecord.isValid()) {
importItemRecord(manager, itemRecord, overwrite, destinationPath, overwriteDeletedItems, idDeletedBeforeImport, contentType, monitor);
IRepositoryViewObject object;
try {
Property property = itemRecord.getProperty();
if (property == null) {
object = factory.getSpecificVersion(itemRecord.getItemId(), itemRecord.getItemVersion(), true);
property = object.getProperty();
}
RelationshipItemBuilder.getInstance().addOrUpdateItem(property.getItem(), true);
itemRecord.setProperty(null);
ProxyRepositoryFactory.getInstance().unloadResources(property);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
statAndLogsSettingsReloaded = false;
implicitSettingsReloaded = false;
monitor.worked(1);
}
}
}
// deploy routines Jar
if (!getRoutineExtModulesMap().isEmpty()) {
Set<String> extRoutines = new HashSet<String>();
for (String id : getRoutineExtModulesMap().keySet()) {
Set<String> set = getRoutineExtModulesMap().get(id);
if (set != null) {
extRoutines.addAll(set);
}
}
if (manager instanceof ProviderManager || manager instanceof ZipFileManager) {
deployJarToDesForArchive(manager, extRoutines);
} else {
deployJarToDes(manager, extRoutines);
}
}
if (PluginChecker.isJobLetPluginLoaded()) {
IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (service != null) {
service.loadComponentsFromProviders();
}
}
checkDeletedFolders();
monitor.done();
TimeMeasure.step("importItemRecords", "before save");
if (RelationshipItemBuilder.getInstance().isNeedSaveRelations()) {
RelationshipItemBuilder.getInstance().saveRelations();
TimeMeasure.step("importItemRecords", "save relations");
} else {
// with relations
try {
factory.saveProject(ProjectManager.getInstance().getCurrentProject());
} catch (PersistenceException e) {
throw new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(), "Import errors", e));
}
TimeMeasure.step("importItemRecords", "save project");
}
}
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
// the update the project files need to be done in the workspace runnable to avoid all
// notification
// of changes before the end of the modifications.
workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
// ?
}
}
};
repositoryWorkUnit.setAvoidUnloadResources(true);
repositoryWorkUnit.setUnloadResourcesAfterRun(true);
ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
monitor.done();
// for (ItemRecord itemRecord : itemRecords) {
// itemRecord.clear();
// }
clearAllData();
if (hasJoblets) {
ComponentsFactoryProvider.getInstance().resetSpecificComponents();
}
TimeMeasure.end("importItemRecords");
TimeMeasure.display = false;
TimeMeasure.displaySteps = false;
TimeMeasure.measureActive = false;
return itemRecords;
}
use of org.talend.core.ui.IJobletProviderService in project tdi-studio-se by Talend.
the class ConnectionCreateActionTest method testGetConnectors.
/**
* Test method for {@link org.talend.designer.core.ui.action.ConnectionCreateAction#getConnectors()}.
*/
@Test
public void testGetConnectors() {
List<INodeConnector> list = new ArrayList<INodeConnector>();
List<INodeConnector> nodeConnectorList = new ArrayList<INodeConnector>(node.getConnectorsFromType(EConnectionType.FLOW_MAIN));
int connecSize = nodeConnectorList.size();
List<INodeConnector> toRemove = new ArrayList<INodeConnector>();
for (INodeConnector connector : nodeConnectorList) {
if ((connector.getMaxLinkOutput() != -1) && (connector.getCurLinkNbOutput() >= connector.getMaxLinkOutput())) {
toRemove.add(connector);
} else {
if (PluginChecker.isJobLetPluginLoaded()) {
IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (service != null) {
if (service.isJobletComponent(node) && !service.isBuiltTriggerConnector(node, connector)) {
toRemove.add(connector);
}
List<? extends IConnection> outgoingConnections = node.getOutgoingConnections();
if (service.isTriggerInputNode(node) && outgoingConnections != null && outgoingConnections.size() >= 1) {
toRemove.add(connector);
}
}
}
}
}
nodeConnectorList.removeAll(toRemove);
assertEquals(nodeConnectorList.size(), connecSize - toRemove.size());
}
Aggregations