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);
}
}
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;
}
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);
}
}
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);
}
});
}
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();
}
}
Aggregations