use of org.talend.designer.core.IDesignerCoreService in project tdi-studio-se by Talend.
the class JobDesignImportHandler method afterApplyMigrationTasks.
@Override
protected void afterApplyMigrationTasks(ImportItem importItem) throws Exception {
Item tmpItem = importItem.getItem();
if (tmpItem instanceof ProcessItem) {
ProcessItem processItem = (ProcessItem) tmpItem;
ParametersType paType = processItem.getProcess().getParameters();
boolean statsPSettingRemoved = false;
// for commanline import project setting
if (importItem.isRemoveProjectStatslog()) {
if (paType != null) {
//$NON-NLS-1$
String paramName = "STATANDLOG_USE_PROJECT_SETTINGS";
EList listParamType = paType.getElementParameter();
for (int j = 0; j < listParamType.size(); j++) {
ElementParameterType pType = (ElementParameterType) listParamType.get(j);
if (pType != null && paramName.equals(pType.getName())) {
pType.setValue(Boolean.FALSE.toString());
statsPSettingRemoved = true;
break;
}
}
}
}
// 14446: item apply project setting param if use project setting
String statslogUsePSetting = null;
String implicitUsePSetting = null;
if (paType != null) {
EList listParamType = paType.getElementParameter();
for (int j = 0; j < listParamType.size(); j++) {
ElementParameterType pType = (ElementParameterType) listParamType.get(j);
if (pType != null) {
if (!statsPSettingRemoved && "STATANDLOG_USE_PROJECT_SETTINGS".equals(pType.getName())) {
//$NON-NLS-1$
statslogUsePSetting = pType.getValue();
}
if ("IMPLICITCONTEXT_USE_PROJECT_SETTINGS".equals(pType.getName())) {
//$NON-NLS-1$
implicitUsePSetting = pType.getValue();
}
if (statsPSettingRemoved && implicitUsePSetting != null || !statsPSettingRemoved && implicitUsePSetting != null && statslogUsePSetting != null) {
break;
}
}
}
}
if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreService.class)) {
IDesignerCoreService designerCoreService = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
if (statslogUsePSetting != null && Boolean.parseBoolean(statslogUsePSetting)) {
//$NON-NLS-1$
designerCoreService.reloadParamFromProjectSettings(paType, "STATANDLOG_USE_PROJECT_SETTINGS");
}
if (implicitUsePSetting != null && Boolean.parseBoolean(implicitUsePSetting)) {
//$NON-NLS-1$
designerCoreService.reloadParamFromProjectSettings(paType, "IMPLICITCONTEXT_USE_PROJECT_SETTINGS");
}
}
}
}
use of org.talend.designer.core.IDesignerCoreService in project tdi-studio-se by Talend.
the class ComponentSearcher method search.
/**
* DOC hcw Comment method "search".
*
* @param monitor
* @param nodeName
* @param found
*/
protected void search(IProgressMonitor monitor, String nodeName, List<IRepositoryViewObject> found) {
IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
try {
List<IRepositoryViewObject> repositoryObjectList = factory.getAll(ERepositoryObjectType.PROCESS, false);
repositoryObjectList.addAll(factory.getAll(ERepositoryObjectType.PROCESS_MR, false));
repositoryObjectList.addAll(factory.getAll(ERepositoryObjectType.valueOf("PROCESS_STORM"), false));
if (ProjectManager.getInstance().getReferencedProjects(ProjectManager.getInstance().getCurrentProject()).size() > 0) {
for (Project refProject : ProjectManager.getInstance().getReferencedProjects(ProjectManager.getInstance().getCurrentProject())) {
repositoryObjectList.addAll(factory.getAll(refProject, ERepositoryObjectType.PROCESS, false));
repositoryObjectList.addAll(factory.getAll(refProject, ERepositoryObjectType.PROCESS_MR, false));
repositoryObjectList.addAll(factory.getAll(refProject, ERepositoryObjectType.valueOf("PROCESS_STORM"), false));
}
}
//$NON-NLS-1$
monitor.beginTask("Searching Component in Jobs ", repositoryObjectList.size());
for (IRepositoryViewObject rObject : repositoryObjectList) {
if (monitor.isCanceled()) {
break;
}
//$NON-NLS-1$
monitor.setTaskName("Search " + rObject.getLabel());
monitor.worked(1);
Item item = rObject.getProperty().getItem();
if (item instanceof ProcessItem) {
ProcessItem processItem = (ProcessItem) item;
IProcess process = designerCoreService.getProcessFromProcessItem(processItem);
List<INode> nodes = (List<INode>) process.getGraphicalNodes();
for (INode node : nodes) {
if (node.getComponent().getName().equals(nodeName)) {
found.add(rObject);
break;
}
}
}
}
monitor.done();
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
// JobletEditorInput fileEditorInput = new JobletEditorInput(processItem, true);
// IEditorPart editorPart = page.findEditor(fileEditorInput);
}
use of org.talend.designer.core.IDesignerCoreService in project tdi-studio-se by Talend.
the class TalendCompletionProposalComputer method computeCompletionProposals.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer#computeCompletionProposals(org.eclipse.jdt.ui.text
* .java.ContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
*/
public List computeCompletionProposals(ITextViewer textViewer, String prefix, int offset, IProgressMonitor monitor) {
List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
IDesignerCoreService service = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
IProcess process = service.getCurrentProcess();
if (process == null) {
return Collections.EMPTY_LIST;
}
// Compute the length of replacement for proposal. See bug 0004266: Replace value with context value using
// CTRL+Space.
int replacementLength = textViewer.getSelectedRange().y;
if (replacementLength == 0) {
replacementLength = prefix.length();
}
// Proposals based on process context
List<IContextParameter> ctxParams = process.getContextManager().getDefaultContext().getContextParameterList();
for (IContextParameter ctxParam : ctxParams) {
String display = CONTEXT_PREFIX + ctxParam.getName();
String code = getContextContent(ctxParam);
String description = getContextDescription(ctxParam, display);
String ctxName = ctxParam.getName();
if (prefix.equals("") || display.startsWith(prefix)) {
//$NON-NLS-1$
TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.CONTEXT_ICON), display, null, description);
proposal.setType(TalendCompletionProposal.CONTEXT);
proposals.add(proposal);
} else if (prefix.equals("") || ctxName.startsWith(prefix)) {
//$NON-NLS-1$
if (code.startsWith(CONTEXT_PREFIX)) {
code = code.replaceFirst(CONTEXT_PREFIX, "");
}
TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.CONTEXT_ICON), display, null, description);
proposal.setType(TalendCompletionProposal.CONTEXT);
proposals.add(proposal);
}
}
// Proposals based on global variables
List<? extends INode> nodes = process.getGraphicalNodes();
for (INode node : nodes) {
List<? extends INodeReturn> nodeReturns = node.getReturns();
for (INodeReturn nodeReturn : nodeReturns) {
//$NON-NLS-1$
String display = node.getLabel() + "." + nodeReturn.getName();
if (prefix.equals("") || display.startsWith(prefix)) {
//$NON-NLS-1$
String code = getNodeReturnContent(nodeReturn, node);
String description = getNodeReturnDescription(nodeReturn, node, display);
TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), CoreImageProvider.getComponentIcon(node.getComponent(), ICON_SIZE.ICON_16), display, null, description);
proposal.setType(TalendCompletionProposal.NODE_RETURN);
proposals.add(proposal);
}
}
}
// Proposals based on global variables(only perl ).
// add proposals on global variables in java (bugtracker 2554)
// add variables in java
IContentProposal[] javavars = JavaGlobalUtils.getProposals();
for (IContentProposal javavar : javavars) {
String display = javavar.getLabel();
if (prefix.equals("") || display.startsWith(prefix)) {
//$NON-NLS-1$
String code = javavar.getContent();
String description = getGlobalVarDescription(javavar, display);
TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.PROCESS_ICON), display, null, description);
proposal.setType(TalendCompletionProposal.VARIABLE);
proposals.add(proposal);
}
}
FunctionManager functionManager = new FunctionManager();
List<TalendType> talendTypes = functionManager.getTalendTypes();
for (TalendType type : talendTypes) {
for (Object objectFunction : type.getFunctions()) {
Function function = (Function) objectFunction;
//$NON-NLS-1$
String display = function.getCategory() + "." + function.getName();
if (prefix.equals("") || display.startsWith(prefix)) {
//$NON-NLS-1$
String code = FunctionManager.getFunctionMethod(function);
String description = getFunctionDescription(function, display, code);
TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.ROUTINE_ICON), display, null, description);
proposal.setType(TalendCompletionProposal.ROUTINE);
proposals.add(proposal);
}
}
}
for (IExternalProposals externalProposals : ProposalFactory.getInstances()) {
proposals.addAll(externalProposals.getAdvancedProposals(offset, prefix));
}
return proposals;
}
use of org.talend.designer.core.IDesignerCoreService in project tdi-studio-se by Talend.
the class TalendCompletionProposalComputer method computeCompletionProposals.
@Override
public List computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
//$NON-NLS-1$
String prefix = "";
try {
if (context != null) {
prefix = context.computeIdentifierPrefix().toString();
//$NON-NLS-1$
String tmpPrefix = "";
IDocument doc = context.getDocument();
if ((!prefix.equals("")) || (doc.get().length() == 0)) {
//$NON-NLS-1$
tmpPrefix = prefix;
} else {
int offset = context.getInvocationOffset();
if (doc.getChar(offset - 1) == '.') {
// set by default to avoid other completions
//$NON-NLS-1$
tmpPrefix = ".";
if (offset >= CONTEXT_PREFIX.length() && doc.get(offset - CONTEXT_PREFIX.length(), CONTEXT_PREFIX.length()).equals(CONTEXT_PREFIX)) {
tmpPrefix = CONTEXT_PREFIX;
} else if (offset >= PERL_GLOBAL_PREFIX.length() & doc.get(offset - PERL_GLOBAL_PREFIX.length(), PERL_GLOBAL_PREFIX.length()).equals(PERL_GLOBAL_PREFIX)) {
switch(LanguageManager.getCurrentLanguage()) {
case JAVA:
// do nothing
break;
case PERL:
default:
tmpPrefix = PERL_GLOBAL_PREFIX;
}
} else {
// test each component label.
IDesignerCoreService service = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
IProcess process = service.getCurrentProcess();
if (process == null) {
return Collections.EMPTY_LIST;
}
List<? extends INode> nodes = process.getGraphicalNodes();
for (INode node : nodes) {
//$NON-NLS-1$
String toTest = node.getLabel() + ".";
if (offset >= toTest.length() && doc.get(offset - toTest.length(), toTest.length()).equals(toTest)) {
tmpPrefix = toTest;
break;
}
}
}
}
}
prefix = tmpPrefix;
if (".".equals(prefix) && LanguageManager.getCurrentLanguage().equals(ECodeLanguage.PERL)) {
//$NON-NLS-1$
//$NON-NLS-1$
prefix = "";
}
}
} catch (BadLocationException e) {
throw new RuntimeException(e);
}
return computeCompletionProposals(context.getViewer(), prefix, context.getInvocationOffset(), monitor);
}
use of org.talend.designer.core.IDesignerCoreService in project tdi-studio-se by Talend.
the class HTMLDocGenerator method generateSourceCodeInfo.
/**
* DOC qwei Comment method "generateSourceCodeInfo".
*/
private void generateSourceCodeInfo(ProcessItem item, Element element) {
if (CorePlugin.getDefault().getPreferenceStore().getBoolean(ITalendCorePrefConstants.DOC_GENERATESOURCECODE)) {
IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
IProcess process = service.getProcessFromProcessItem(item);
IProcessor processor = ProcessorUtilities.getProcessor(process, null, process.getContextManager().getDefaultContext());
// hidePasswordInSourceCode4Doc(process);
try {
processor.cleanBeforeGenerate(TalendProcessOptionConstants.CLEAN_JAVA_CODES | TalendProcessOptionConstants.CLEAN_CONTEXTS | TalendProcessOptionConstants.CLEAN_DATA_SETS);
processor.generateCode(false, true, false);
} catch (ProcessorException e) {
ExceptionHandler.process(e);
}
//$NON-NLS-1$
Element sourceCodeInfoElement = DocumentHelper.createElement("sourcecodes");
ITalendSynchronizer synchronizer = CorePlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer();
// StringBuffer componentsCode = new StringBuffer();
try {
IFile codeFile = synchronizer.getFile(item);
if (codeFile == null) {
return;
}
//$NON-NLS-1$
String tempStr = "";
InputStream in = codeFile.getContents();
BufferedReader buffer = new BufferedReader(new InputStreamReader(in));
while ((tempStr = buffer.readLine()) != null) {
//$NON-NLS-1$
Element codeElement = DocumentHelper.createElement("code");
// componentsCode.append(tempStr).append("\n");
//$NON-NLS-1$
codeElement.addAttribute("content", tempStr);
sourceCodeInfoElement.add(codeElement);
}
buffer.close();
in.close();
} catch (Exception e) {
// TODO Auto-generated catch block
// e.printStackTrace();
ExceptionHandler.process(e);
}
element.add(sourceCodeInfoElement);
}
}
Aggregations