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);
}
});
}
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);
}
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;
}
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);
}
}
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 + "*")));
}
Aggregations