Search in sources :

Example 21 with SQLPatternItem

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

the class EditPropertiesAction method init.

@Override
public void init(TreeViewer viewer, IStructuredSelection selection) {
    boolean canWork = selection.size() == 1;
    if (canWork) {
        Object o = selection.getFirstElement();
        if (o instanceof IRepositoryNode) {
            IRepositoryNode node = (IRepositoryNode) o;
            switch(node.getType()) {
                case REPOSITORY_ELEMENT:
                    if (node.getObjectType() == ERepositoryObjectType.BUSINESS_PROCESS || node.getObjectType() == ERepositoryObjectType.PROCESS) {
                        canWork = true;
                    } else if (node.getObjectType() == ERepositoryObjectType.ROUTINES) {
                        Item item = node.getObject().getProperty().getItem();
                        if (item instanceof RoutineItem) {
                            canWork = !((RoutineItem) item).isBuiltIn();
                        } else {
                            canWork = false;
                        }
                    } else if (node.getObjectType() == ERepositoryObjectType.SQLPATTERNS) {
                        Item item = node.getObject().getProperty().getItem();
                        if (item instanceof SQLPatternItem) {
                            canWork = !((SQLPatternItem) item).isSystem();
                        } else {
                            canWork = false;
                        }
                    } else if (node.getObjectType() == ERepositoryObjectType.JOB_SCRIPT) {
                        Item item = node.getObject().getProperty().getItem();
                        if (item instanceof JobScriptItem) {
                            canWork = true;
                        } else {
                            canWork = false;
                        }
                    } else {
                        canWork = isInstanceofCamelRoutes(node.getObjectType()) || isInstanceofCamelBeans(node.getObjectType());
                    }
                    break;
                default:
                    canWork = false;
                    break;
            }
            if (canWork) {
                canWork = (node.getObject().getRepositoryStatus() != ERepositoryStatus.DELETED);
            }
            if (canWork) {
                canWork = isLastVersion(node);
            }
        }
    }
    setEnabled(canWork);
}
Also used : Item(org.talend.core.model.properties.Item) JobScriptItem(org.talend.core.model.properties.JobScriptItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IRepositoryNode(org.talend.repository.model.IRepositoryNode) JobScriptItem(org.talend.core.model.properties.JobScriptItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem)

Example 22 with SQLPatternItem

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

the class SQLTemplateRepoViewLinker method isRelation.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.repository.link.AbstractRepositoryEditorInputLinker#isRelation(org.eclipse.ui.IEditorInput,
     * java.lang.String)
     */
@Override
public boolean isRelation(IEditorInput editorInput, String repoNodeId) {
    if (editorInput instanceof RepositoryEditorInput) {
        RepositoryEditorInput repoEditorInput = (RepositoryEditorInput) editorInput;
        Item item = repoEditorInput.getItem();
        if (item instanceof SQLPatternItem) {
            // must be SQL template item
            return super.isRelation(editorInput, repoNodeId);
        }
    }
    return false;
}
Also used : Item(org.talend.core.model.properties.Item) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) IRepositoryEditorInput(org.talend.core.model.repository.IRepositoryEditorInput) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem)

Example 23 with SQLPatternItem

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

the class ReadSqlpatternAction method doRun.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
protected void doRun() {
    RepositoryNode node = (RepositoryNode) ((IStructuredSelection) getSelection()).getFirstElement();
    Property property = (Property) node.getObject().getProperty();
    Property updatedProperty = null;
    try {
        updatedProperty = ProxyRepositoryFactory.getInstance().getLastVersion(new Project(ProjectManager.getInstance().getProject(property.getItem())), property.getId()).getProperty();
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    // update the property of the node repository object
    // node.getObject().setProperty(updatedProperty);
    SQLPatternItem sqlpatternItem = (SQLPatternItem) node.getObject().getProperty().getItem();
    try {
        openSQLPatternEditor(sqlpatternItem, true);
    } catch (PartInitException e) {
        MessageBoxExceptionHandler.process(e);
    } catch (SystemException e) {
        MessageBoxExceptionHandler.process(e);
    }
}
Also used : Project(org.talend.core.model.general.Project) SystemException(org.talend.commons.exception.SystemException) PersistenceException(org.talend.commons.exception.PersistenceException) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) PartInitException(org.eclipse.ui.PartInitException) RepositoryNode(org.talend.repository.model.RepositoryNode) Property(org.talend.core.model.properties.Property)

Example 24 with SQLPatternItem

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

the class AbstractSqlpatternAction method openSQLPatternEditor.

/**
     * DOC smallet Comment method "openRoutineEditor".
     * 
     * @param item
     * @throws SystemException
     * @throws PartInitException
     */
public IEditorPart openSQLPatternEditor(SQLPatternItem item, boolean readOnly) throws SystemException, PartInitException {
    if (item == null) {
        return null;
    }
    ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
    ECodeLanguage lang = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject().getLanguage();
    ISQLPatternSynchronizer routineSynchronizer = service.getSQLPatternSynchronizer();
    // check if the related editor is open.
    IWorkbenchPage page = getActivePage();
    IEditorReference[] editorParts = page.getEditorReferences();
    //$NON-NLS-1$ //$NON-NLS-2$
    String talendEditorID = "org.talend.designer.core.ui.editor.StandAloneTalend" + lang.getCaseName() + "Editor";
    boolean found = false;
    IEditorPart talendEditor = null;
    for (IEditorReference reference : editorParts) {
        IEditorPart editor = reference.getEditor(false);
        if (talendEditorID.equals(editor.getSite().getId())) {
            // TextEditor talendEditor = (TextEditor) editor;
            RepositoryEditorInput editorInput = (RepositoryEditorInput) editor.getEditorInput();
            Item item2 = editorInput.getItem();
            if (item2 != null && item2 instanceof SQLPatternItem && item2.getProperty().getId().equals(item.getProperty().getId())) {
                if (item2.getProperty().getVersion().equals(item.getProperty().getVersion())) {
                    page.bringToTop(editor);
                    found = true;
                    talendEditor = editor;
                    break;
                } else {
                    page.closeEditor(editor, false);
                }
            }
        }
    }
    if (!found) {
        routineSynchronizer.syncSQLPattern(item, true);
        IFile file = routineSynchronizer.getSQLPatternFile(item);
        if (file == null) {
            return null;
        }
        RepositoryEditorInput input = new RepositoryEditorInput(file, item);
        input.setReadOnly(readOnly);
        //$NON-NLS-1$            
        talendEditor = page.openEditor(input, talendEditorID);
    }
    return talendEditor;
}
Also used : RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) IFile(org.eclipse.core.resources.IFile) ISQLPatternSynchronizer(org.talend.designer.codegen.ISQLPatternSynchronizer) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IEditorPart(org.eclipse.ui.IEditorPart) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) Item(org.talend.core.model.properties.Item) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Aggregations

SQLPatternItem (org.talend.core.model.properties.SQLPatternItem)24 PersistenceException (org.talend.commons.exception.PersistenceException)11 Item (org.talend.core.model.properties.Item)11 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)11 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)8 PartInitException (org.eclipse.ui.PartInitException)7 ConnectionItem (org.talend.core.model.properties.ConnectionItem)7 RepositoryNode (org.talend.repository.model.RepositoryNode)7 IRepositoryNode (org.talend.repository.model.IRepositoryNode)6 RoutineItem (org.talend.core.model.properties.RoutineItem)5 RepositoryEditorInput (org.talend.core.repository.ui.editor.RepositoryEditorInput)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ArrayList (java.util.ArrayList)4 CoreException (org.eclipse.core.runtime.CoreException)4 Project (org.talend.core.model.general.Project)4 IElementParameter (org.talend.core.model.process.IElementParameter)4 FileItem (org.talend.core.model.properties.FileItem)4 ProcessItem (org.talend.core.model.properties.ProcessItem)4 Property (org.talend.core.model.properties.Property)4 HashMap (java.util.HashMap)3