Search in sources :

Example 1 with RoutineItem

use of org.talend.core.model.properties.RoutineItem in project tdi-studio-se by Talend.

the class BusinessAssignmentComposite method createSelectionListener.

private void createSelectionListener() {
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            BusinessAssignment businessAssignment = getBusinessAssignment(event.getSelection());
            if (businessAssignment != null) {
                final IRepositoryView repositoryView = getRepositoryView();
                if (repositoryView != null) {
                    IProjectRepositoryNode rootRepositoryNode = repositoryView.getRoot();
                    TalendItem item = businessAssignment.getTalendItem();
                    //
                    if (item instanceof Routine && rootRepositoryNode instanceof ProjectRepositoryNode) {
                        RepositoryNodeUtilities.expandParentNode(getRepositoryView(), ((ProjectRepositoryNode) rootRepositoryNode).getRootRepositoryNode(ERepositoryObjectType.CODE));
                    }
                    selectChild(item, (IRepositoryNode) rootRepositoryNode);
                }
            }
        }

        private void selectChild(TalendItem item, IRepositoryNode rootRepositoryNode) {
            try {
                RepositoryNode curNode = null;
                JobSettingsView viewer = (JobSettingsView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(JobSettingsView.ID);
                IRepositoryViewObject lastVersion = ProxyRepositoryFactory.getInstance().getLastVersion(item.getId());
                if (lastVersion != null) {
                    curNode = RepositoryNodeUtilities.getRepositoryNode(lastVersion);
                    select(viewer, curNode);
                } else if (item instanceof TableMetadata) {
                    MetadataTable table = MetadataToolHelper.getMetadataTableFromRepository(item.getId());
                    if (table != null) {
                        //$NON-NLS-1$
                        String id = item.getId().split(" - ")[0];
                        RepositoryNode node = RepositoryNodeUtilities.getMetadataTableFromConnection(item.getId());
                        IRepositoryView view = getRepositoryView();
                        if (view != null) {
                            RepositoryNodeUtilities.expandParentNode(view, node);
                            select(viewer, node);
                        }
                    }
                } else if (item instanceof Query) {
                    org.talend.core.model.metadata.builder.connection.Query query = MetadataToolHelper.getQueryFromRepository(item.getId());
                    if (query != null) {
                        //$NON-NLS-1$
                        String id = item.getId().split(" - ")[0];
                        IRepositoryView view = getRepositoryView();
                        RepositoryNode node = RepositoryNodeUtilities.getQueryFromConnection(item.getId());
                        RepositoryNodeUtilities.expandParentNode(view, node);
                        select(viewer, node);
                    }
                } else if (item instanceof SAPFunction) {
                    SAPFunctionUnit function = MetadataToolHelper.getSAPFunctionFromRepository(item.getId());
                    if (function != null) {
                        IRepositoryView view = getRepositoryView();
                        RepositoryNode node = RepositoryNodeUtilities.getSAPFunctionFromConnection(item.getId());
                        RepositoryNodeUtilities.expandParentNode(view, node);
                        select(viewer, node);
                    }
                } else {
                    for (IRepositoryNode node : rootRepositoryNode.getChildren()) {
                        RepositoryNode rNode = (RepositoryNode) node;
                        if (item instanceof SQLPattern && rNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.SQLPATTERNS) {
                            if (rNode.getType() == ENodeType.REPOSITORY_ELEMENT) {
                                SQLPatternItem sqlItem = (SQLPatternItem) rNode.getObject().getProperty().getItem();
                                if (sqlItem.isSystem() && item.getLabel().equals(rNode.getObject().getLabel())) {
                                    select(viewer, rNode);
                                }
                            } else {
                                selectChild(item, rNode);
                            }
                        } else if (item instanceof Routine && rNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.ROUTINES) {
                            if (rNode.getType() == ENodeType.REPOSITORY_ELEMENT) {
                                RoutineItem sqlItem = (RoutineItem) rNode.getObject().getProperty().getItem();
                                if (sqlItem.isBuiltIn() && item.getLabel().equals(rNode.getObject().getLabel())) {
                                    select(viewer, rNode);
                                }
                            } else {
                                selectChild(item, rNode);
                            }
                        }
                    }
                }
            } catch (PersistenceException e) {
                // TODO Auto-generated catch block
                // e.printStackTrace();
                ExceptionHandler.process(e);
            }
        }

        private void select(JobSettingsView viewer, RepositoryNode repositoryNode) {
            if (viewer == null) {
                return;
            }
            if (repositoryNode == null) {
                return;
            }
            CorePlugin.getDefault().getRepositoryService().removeRepositoryTreeViewListener(viewer);
            final IRepositoryView repositoryView = getRepositoryView();
            if (repositoryView != null) {
                repositoryView.getViewer().setSelection(new StructuredSelection(repositoryNode));
            }
            CorePlugin.getDefault().getRepositoryService().addRepositoryTreeViewListener(viewer);
        }
    });
}
Also used : JobSettingsView(org.talend.designer.core.ui.views.jobsettings.JobSettingsView) BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) Query(org.talend.designer.business.model.business.Query) SAPFunctionUnit(org.talend.core.model.metadata.builder.connection.SAPFunctionUnit) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IRepositoryView(org.talend.repository.ui.views.IRepositoryView) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) IProjectRepositoryNode(org.talend.repository.model.nodes.IProjectRepositoryNode) TalendItem(org.talend.designer.business.model.business.TalendItem) IProjectRepositoryNode(org.talend.repository.model.nodes.IProjectRepositoryNode) TableMetadata(org.talend.designer.business.model.business.TableMetadata) SAPFunction(org.talend.designer.business.model.business.SAPFunction) SQLPattern(org.talend.designer.business.model.business.SQLPattern) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) RoutineItem(org.talend.core.model.properties.RoutineItem) Routine(org.talend.designer.business.model.business.Routine) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IProjectRepositoryNode(org.talend.repository.model.nodes.IProjectRepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 2 with RoutineItem

use of org.talend.core.model.properties.RoutineItem in project tdi-studio-se by Talend.

the class GenerateGrammarController method generateJavaFile.

/**
     * Generate java source file
     * 
     * DOC ytao Comment method "generateJavaFile".
     */
private void generateJavaFile() {
    Node node = (Node) elem;
    final String JOB_NAME = node.getProcess().getName().toLowerCase();
    final String COMPONENT_NAME = node.getUniqueName().toLowerCase();
    String javaClassName = StringUtils.capitalize(JOB_NAME) + StringUtils.capitalize(COMPONENT_NAME);
    ITDQItemService service = (ITDQItemService) GlobalServiceRegister.getDefault().getService(ITDQItemService.class);
    File fileCreated = null;
    try {
        fileCreated = service.fileCreatedInRoutines(node, javaClassName);
    } catch (Exception ex) {
        MessageDialog.openError(Display.getDefault().getActiveShell(), //$NON-NLS-1$
        Messages.getString("GenerateGrammarController.prompt"), ex.getMessage());
    }
    if (fileCreated == null) {
        return;
    }
    try {
        RoutineItem returnItem = persistInRoutine(new Path(JOB_NAME), fileCreated, javaClassName);
        addReferenceJavaFile(returnItem, true);
        // ADD (to line 292) xwang 2011-08-12 add routine dependency in job
        if (node.getProcess() instanceof org.talend.designer.core.ui.editor.process.Process) {
            RoutinesParameterType r = TalendFileFactory.eINSTANCE.createRoutinesParameterType();
            r.setId(returnItem.getProperty().getId());
            r.setName(returnItem.getProperty().getLabel());
            List<RoutinesParameterType> routines = new ArrayList<RoutinesParameterType>();
            routines.add(r);
            ((org.talend.designer.core.ui.editor.process.Process) node.getProcess()).addGeneratingRoutines(routines);
        }
        refreshProject();
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    // remove temporary files of grammar
    FilesUtils.removeFolder(new File(fileCreated.getParent()), true);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) RoutinesParameterType(org.talend.designer.core.model.utils.emf.talendfile.RoutinesParameterType) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) RoutineItem(org.talend.core.model.properties.RoutineItem) SystemException(org.talend.commons.exception.SystemException) IOException(java.io.IOException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) ITDQItemService(org.talend.core.ITDQItemService)

Example 3 with RoutineItem

use of org.talend.core.model.properties.RoutineItem in project tdi-studio-se by Talend.

the class GenerateGrammarController method persistInRoutine.

/**
     * Persist item in routines
     * 
     * DOC ytao Comment method "persistInRoutine".
     * 
     * @param path, sub folder named with job id
     * @param label, java file name without suffix
     * @param initFile, File handler
     * @param name, job id as package name
     * @return
     */
private RoutineItem persistInRoutine(IPath inFolder, File fileToFill, String label) {
    // item property to be set
    Property property = PropertiesFactory.eINSTANCE.createProperty();
    property.setAuthor(((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
    property.setVersion(VersionUtils.DEFAULT_VERSION);
    //$NON-NLS-1$
    property.setStatusCode("");
    // Label must match pattern ^[a-zA-Z\_]+[a-zA-Z0-9\_]*$
    // Must be composed with JAVA_PORJECT_NAME + JOB NAME + COMPONENT NAME,
    // since all projects share with the same routines
    property.setLabel(label);
    // add properties to item
    RoutineItem routineItem = PropertiesFactory.eINSTANCE.createRoutineItem();
    routineItem.setProperty(property);
    // get the content of java file as byte array.
    ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
    InputStream stream = null;
    try {
        stream = new FileInputStream(fileToFill);
        byte[] bytes = new byte[stream.available()];
        stream.read(bytes);
        byteArray.setInnerContent(bytes);
    } catch (IOException e) {
        ExceptionHandler.process(e);
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    routineItem.setContent(byteArray);
    // persist item in routines
    IProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
    try {
        property.setId(repositoryFactory.getNextId());
        // create folder with name job id: routines/JOBID (seems from TOS)
        repositoryFactory.createParentFoldersRecursively(ERepositoryObjectType.getItemType(routineItem), inFolder);
        // add the item
        repositoryFactory.create(routineItem, inFolder);
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return routineItem;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ByteArray(org.talend.core.model.properties.ByteArray) RoutineItem(org.talend.core.model.properties.RoutineItem) IOException(java.io.IOException) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) FileInputStream(java.io.FileInputStream) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) SystemException(org.talend.commons.exception.SystemException) IOException(java.io.IOException)

Example 4 with RoutineItem

use of org.talend.core.model.properties.RoutineItem in project tdi-studio-se by Talend.

the class StandAloneTalendJavaEditor method refreshName.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.ui.IUIRefresher#refreshName()
     */
@Override
public void refreshName() {
    ICompilationUnit unit = (ICompilationUnit) this.getInputJavaElement();
    String newName = item.getProperty().getLabel();
    try {
        boolean noError = true;
        // String newName2 = newName + SuffixConstants.SUFFIX_STRING_java;
        //$NON-NLS-1$
        String newName2 = newName + ".java";
        if (item instanceof RoutineItem && !unit.getElementName().equals(newName2)) {
            JavaRenameProcessor processor = new RenameCompilationUnitProcessor(unit);
            processor.setNewElementName(newName2);
            RenameRefactoring ref = new RenameRefactoring(processor);
            final PerformRefactoringOperation operation = new PerformRefactoringOperation(ref, CheckConditionsOperation.ALL_CONDITIONS);
            IRunnableWithProgress r = new IRunnableWithProgress() {

                @Override
                public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                operation.run(monitor);
                            } catch (CoreException e) {
                                ExceptionHandler.process(e);
                            }
                        }
                    });
                }
            };
            PlatformUI.getWorkbench().getProgressService().run(true, true, r);
            RefactoringStatus conditionStatus = operation.getConditionStatus();
            if (conditionStatus != null && conditionStatus.hasError()) {
                //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                String errorMessage = "Rename " + unit.getElementName() + " to " + newName + " has errors!";
                RefactoringStatusEntry[] entries = conditionStatus.getEntries();
                for (RefactoringStatusEntry entry : entries) {
                    //$NON-NLS-1$
                    errorMessage += "\n>>>" + entry.getMessage();
                }
                //$NON-NLS-1$
                MessageDialog.openError(this.getSite().getShell(), "Warning", errorMessage);
                noError = false;
            }
        }
        if (noError) {
            doSave(null);
        }
        setName();
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) RefactoringStatusEntry(org.eclipse.ltk.core.refactoring.RefactoringStatusEntry) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) RoutineItem(org.talend.core.model.properties.RoutineItem) PerformRefactoringOperation(org.eclipse.ltk.core.refactoring.PerformRefactoringOperation) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RenameCompilationUnitProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameCompilationUnitProcessor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) JavaRenameProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameProcessor)

Example 5 with RoutineItem

use of org.talend.core.model.properties.RoutineItem in project tdi-studio-se by Talend.

the class StandAloneTalendJavaEditor method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    super.init(site, input);
    Bundle bundle = FrameworkUtil.getBundle(StandAloneTalendJavaEditor.class);
    lockService = bundle.getBundleContext().registerService(EventHandler.class.getName(), new EventHandler() {

        @Override
        public void handleEvent(Event event) {
            String lockTopic = Constant.REPOSITORY_ITEM_EVENT_PREFIX + Constant.ITEM_LOCK_EVENT_SUFFIX;
            if (lockTopic.equals(event.getTopic())) {
                if (!isEditable) {
                    Object o = event.getProperty(Constant.ITEM_EVENT_PROPERTY_KEY);
                    if (o instanceof FileItem) {
                        boolean isTheCorrectEditor = false;
                        Property property = ((FileItem) o).getProperty();
                        if (property != null) {
                            String eventItemId = property.getId();
                            //$NON-NLS-1$
                            String currentOpenedItemId = "";
                            if (rEditorInput != null) {
                                currentOpenedItemId = rEditorInput.getId();
                            }
                            isTheCorrectEditor = currentOpenedItemId.equals(eventItemId);
                        }
                        if (!isTheCorrectEditor) {
                            return;
                        }
                        item.getProperty().eAdapters().remove(dirtyListener);
                        item = (FileItem) o;
                        item.getProperty().eAdapters().add(dirtyListener);
                        if (isEditable()) {
                            isEditable = true;
                            rEditorInput.getFile().setReadOnly(false);
                            getSite().getShell().getDisplay().asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    setFocus();
                                    ISourceViewer viewer = getViewer();
                                    if (viewer != null) {
                                        StyledText styledText = viewer.getTextWidget();
                                        if (styledText != null) {
                                            styledText.setBackground(bgColorForEditabeItem);
                                            styledText.setDragDetect(true);
                                        }
                                    }
                                }
                            });
                            try {
                                ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
                                if (o instanceof RoutineItem) {
                                    ITalendSynchronizer routineSynchronizer = service.createJavaRoutineSynchronizer();
                                    routineSynchronizer.syncRoutine((RoutineItem) o, true);
                                } else if (o instanceof SQLPatternItem) {
                                    ISQLPatternSynchronizer sqlPatternSynchronizer = service.getSQLPatternSynchronizer();
                                    sqlPatternSynchronizer.syncSQLPattern((SQLPatternItem) o, true);
                                } else {
                                    //$NON-NLS-1$
                                    org.talend.commons.exception.ExceptionHandler.process(new Exception("Uncatched case"));
                                }
                                setName();
                            } catch (Exception e) {
                                org.talend.commons.exception.ExceptionHandler.process(e);
                            }
                        }
                    }
                }
            }
        }
    }, new Hashtable<String, String>(//$NON-NLS-1$
    Collections.singletonMap(EventConstants.EVENT_TOPIC, Constant.REPOSITORY_ITEM_EVENT_PREFIX + "*")));
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) StyledText(org.eclipse.swt.custom.StyledText) Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) ISQLPatternSynchronizer(org.talend.designer.codegen.ISQLPatternSynchronizer) EventHandler(org.osgi.service.event.EventHandler) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) FileItem(org.talend.core.model.properties.FileItem) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) ResourceChangeEvent(org.eclipse.core.internal.events.ResourceChangeEvent) Event(org.osgi.service.event.Event) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Property(org.talend.core.model.properties.Property)

Aggregations

RoutineItem (org.talend.core.model.properties.RoutineItem)39 PersistenceException (org.talend.commons.exception.PersistenceException)15 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)15 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)13 Item (org.talend.core.model.properties.Item)12 Property (org.talend.core.model.properties.Property)12 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)9 CoreException (org.eclipse.core.runtime.CoreException)8 ProcessItem (org.talend.core.model.properties.ProcessItem)8 SQLPatternItem (org.talend.core.model.properties.SQLPatternItem)8 File (java.io.File)7 IFile (org.eclipse.core.resources.IFile)7 IMPORTType (org.talend.designer.core.model.utils.emf.component.IMPORTType)7 Project (org.talend.core.model.general.Project)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 HashSet (java.util.HashSet)5 PartInitException (org.eclipse.ui.PartInitException)5 SystemException (org.talend.commons.exception.SystemException)5 List (java.util.List)4