Search in sources :

Example 6 with SQLPatternItem

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

the class StandAloneTalendJavaEditor method dispose.

@SuppressWarnings("restriction")
@Override
public void dispose() {
    // remove the Runtines .java file in the .Java Project.
    // try {
    // rEditorInput.getFile().delete(true, null);
    // } catch (CoreException e1) {
    // RuntimeExceptionHandler.process(e1);
    // }
    super.dispose();
    if (lockService != null) {
        lockService.unregister();
    }
    // Unlock the process :
    IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
    IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
    try {
        item.getProperty().eAdapters().remove(dirtyListener);
        repFactory.unlock(item);
    } catch (PersistenceException e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    } catch (LoginException e) {
        ExceptionHandler.process(e);
    }
    // }
    if (!isEditable) {
        rEditorInput.getFile().setReadOnly(false);
    }
    // dispose custom color
    if (bgColorForReadOnlyItem != null) {
        bgColorForReadOnlyItem.dispose();
    }
    if (bgColorForEditabeItem != null) {
        bgColorForEditabeItem.dispose();
    }
    ITalendProcessJavaProject talendProcessJavaProject = CorePlugin.getDefault().getRunProcessService().getTalendProcessJavaProject();
    if (talendProcessJavaProject != null) {
        talendProcessJavaProject.updateRoutinesPom(true, true);
    }
    // only for sql template
    if (item instanceof SQLPatternItem) {
        IProject jProject = talendProcessJavaProject.getProject();
        ResourceChangeEvent event = new ResourceChangeEvent(item, IResourceChangeEvent.PRE_CLOSE, 1, null);
        try {
            //$NON-NLS-1$
            Field resourceField = event.getClass().getDeclaredField("resource");
            resourceField.setAccessible(true);
            resourceField.set(event, jProject);
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
        Workspace ws = (Workspace) ResourcesPlugin.getWorkspace();
        ws.getNotificationManager().broadcastChanges(ws.getElementTree(), event, false);
    }
}
Also used : Field(java.lang.reflect.Field) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) ResourceChangeEvent(org.eclipse.core.internal.events.ResourceChangeEvent) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IProject(org.eclipse.core.resources.IProject) 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) IRepositoryService(org.talend.repository.model.IRepositoryService) Workspace(org.eclipse.core.internal.resources.Workspace) IWorkspace(org.eclipse.core.resources.IWorkspace)

Example 7 with SQLPatternItem

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

the class SQLPatternComposite method getAllSqlPatterns.

private List<SQLPatternInfor> getAllSqlPatterns(List<Map> tableInput, boolean modifySQL) {
    IElementParameter elementParam = element.getElementParameter(EParameterName.SQLPATTERN_DB_NAME.getName());
    if (elementParam == null) {
        return Collections.EMPTY_LIST;
    }
    // String dbName = (String) elementParam.getValue();
    List<SQLPatternInfor> patternInfor = new ArrayList<SQLPatternInfor>();
    try {
        List<IRepositoryViewObject> list = null;
        if (isItemIndexChecked() && modifySQL) {
            List<Relation> relations = new ArrayList<Relation>();
            IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
            List<IRepositoryViewObject> updateList = new ArrayList<IRepositoryViewObject>();
            for (Map map : tableInput) {
                String id = (String) map.get(SQLPatternUtils.SQLPATTERNLIST);
                relations.addAll(RelationshipItemBuilder.getInstance().getItemsRelatedTo(id, ItemCacheManager.LATEST_VERSION, RelationshipItemBuilder.SQLPATTERN_RELATION));
            }
            for (Relation relation : relations) {
                try {
                    IRepositoryViewObject obj = factory.getLastVersion(relation.getId());
                    if (obj != null) {
                        updateList.add(obj);
                    }
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
            }
            list = updateList;
        } else {
            list = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().getAll(ERepositoryObjectType.SQLPATTERNS, false);
            // add reference sql pattern
            addReferencedSQLTemplate(list, ProjectManager.getInstance().getCurrentProject());
        }
        for (IRepositoryViewObject repositoryObject : list) {
            Item item = repositoryObject.getProperty().getItem();
            if (item instanceof SQLPatternItem) {
                SQLPatternItem sqlitem = (SQLPatternItem) repositoryObject.getProperty().getItem();
                // disable this test as there is now only Generic ELT components
                // if (item.getEltName().equals(dbName)) {
                patternInfor.add(new SQLPatternInfor(sqlitem.getProperty().getId() + SQLPatternUtils.ID_SEPARATOR + sqlitem.getProperty().getLabel(), sqlitem.getProperty().getLabel()));
            // }
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return patternInfor;
}
Also used : ArrayList(java.util.ArrayList) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) PartInitException(org.eclipse.ui.PartInitException) PersistenceException(org.talend.commons.exception.PersistenceException) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) TableItem(org.eclipse.swt.widgets.TableItem) Relation(org.talend.core.model.relationship.Relation) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) Map(java.util.Map) HashMap(java.util.HashMap) BidiMap(org.apache.commons.collections.BidiMap) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 8 with SQLPatternItem

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

the class SQLPatternComposite method addReferencedSQLTemplate.

private void addReferencedSQLTemplate(List<IRepositoryViewObject> list, Project project) {
    try {
        Context ctx = CorePlugin.getContext();
        if (ctx == null) {
            return;
        }
        String parentBranch = ProjectManager.getInstance().getMainProjectBranch(project);
        List<ProjectReference> referencedProjects = project.getEmfProject().getReferencedProjects();
        for (ProjectReference referenced : referencedProjects) {
            if (referenced.getBranch() != null && !parentBranch.equals(referenced.getBranch())) {
                continue;
            }
            org.talend.core.model.properties.Project referencedEmfProject = referenced.getReferencedProject();
            EList refeInRef = referencedEmfProject.getReferencedProjects();
            Project newProject = new Project(referencedEmfProject);
            if (refeInRef != null && refeInRef.size() > 0) {
                addReferencedSQLTemplate(list, newProject);
            }
            List<IRepositoryViewObject> refList;
            refList = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().getAll(newProject, ERepositoryObjectType.SQLPATTERNS, false);
            for (IRepositoryViewObject repositoryObject : refList) {
                Item item = repositoryObject.getProperty().getItem();
                if (item instanceof SQLPatternItem) {
                    if (!((SQLPatternItem) item).isSystem()) {
                        list.add(repositoryObject);
                        sqlPatternAndProject.put((SQLPatternItem) item, project);
                    }
                }
            }
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
}
Also used : Context(org.talend.core.context.Context) ProjectReference(org.talend.core.model.properties.ProjectReference) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) Project(org.talend.core.model.general.Project) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) TableItem(org.eclipse.swt.widgets.TableItem) EList(org.eclipse.emf.common.util.EList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 9 with SQLPatternItem

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

the class SQLPatternComposite method createCodeControl.

/**
     * DOC bqian Comment method "createCodeControl".
     * 
     * @param panel
     * @param
     */
private void createCodeControl(Composite panel, Control reference) {
    codeText = new Text(panel, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    codeText.setEditable(false);
    FormData fd = new FormData();
    fd.left = new FormAttachment(10, 0);
    fd.right = new FormAttachment(90, 0);
    fd.top = new FormAttachment(reference, 2);
    fd.bottom = new FormAttachment(95, 0);
    codeText.setLayoutData(fd);
    codeText.addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent e) {
            if (tableViewer.getTable().getSelection().length == 0) {
                return;
            }
            TableItem item = tableViewer.getTable().getSelection()[0];
            if (item == null || item.getText() == null) {
                return;
            }
            String sqlpatternName = item.getText();
            SQLPatternItem patternItem = SQLPatternUtils.getSQLPatternItem(SQLPatternComposite.this.element, sqlpatternName);
            if (patternItem.isSystem()) {
                boolean answer = //$NON-NLS-1$
                MessageDialog.openQuestion(//$NON-NLS-1$
                getShell(), //$NON-NLS-1$
                Messages.getString("SQLPatternComposite.TOS"), //$NON-NLS-1$
                Messages.getString("SQLPatternComposite.forbidModification"));
                if (!answer) {
                    return;
                }
                IRepositoryService repositoryService = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
                IElementParameter parameter = element.getElementParameter(EParameterName.SQLPATTERN_DB_NAME.getName());
                String dbName = (String) parameter.getValue();
                //$NON-NLS-1$
                String path = dbName + "/" + RepositoryConstants.USER_DEFINED;
                repositoryService.createSqlpattern(path, true);
            } else if (sqlPatternAndProject.get(patternItem) != null) {
                MessageDialog.openInformation(getShell(), "Information", "Forbid modification on sql template from reference project");
            } else {
                boolean answer = //$NON-NLS-1$
                MessageDialog.openQuestion(//$NON-NLS-1$
                getShell(), //$NON-NLS-1$
                Messages.getString("SQLPatternComposite.TOS"), //$NON-NLS-1$
                Messages.getString("SQLPatternComposite.modifySQLPattern"));
                if (!answer) {
                    return;
                }
                IRepositoryService repositoryService = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
                repositoryService.openSQLPatternEditor(patternItem, false);
            }
        }

        @Override
        public void mouseDown(MouseEvent e) {
        // do nothing
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            mouseUp(e);
        }
    });
}
Also used : FormData(org.eclipse.swt.layout.FormData) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) TableItem(org.eclipse.swt.widgets.TableItem) IElementParameter(org.talend.core.model.process.IElementParameter) Text(org.eclipse.swt.widgets.Text) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) FormAttachment(org.eclipse.swt.layout.FormAttachment) IRepositoryService(org.talend.repository.model.IRepositoryService)

Example 10 with SQLPatternItem

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

the class SQLPatternComposite method resourceChanged.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent
     * )
     */
@Override
public void resourceChanged(IResourceChangeEvent event) {
    boolean needRefresh = false;
    boolean modifySQL = true;
    if (event.getSource() instanceof SQLPatternItem && event.getType() == IResourceChangeEvent.PRE_CLOSE) {
        needRefresh = true;
        modifySQL = false;
        // if still have sql template editor to be opened.
        if (getCurrentOpenedEditors() != null) {
            for (IEditorReference editor : getCurrentOpenedEditors()) {
                ERepositoryObjectType type = null;
                try {
                    type = getCurrentOpenEditorType(editor);
                } catch (PartInitException e) {
                    e.printStackTrace();
                }
                if (type != null && ERepositoryObjectType.SQLPATTERNS.equals(type)) {
                    modifySQL = true;
                }
            }
        }
    }
    if (event.getSource() instanceof SQLPatternItem && event.getType() == IResourceChangeEvent.POST_CHANGE) {
        needRefresh = true;
    }
    if (needRefresh) {
        refreshComboContent(this.tableViewer, modifySQL);
        refresh();
    }
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) PartInitException(org.eclipse.ui.PartInitException) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

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