use of org.talend.core.model.properties.ByteArray in project tdi-studio-se by Talend.
the class ExtractDocumentationAction method doRun.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.Action#run()
*/
protected void doRun() {
RepositoryNode node = (RepositoryNode) ((IStructuredSelection) getSelection()).getFirstElement();
final Item item = node.getObject().getProperty().getItem();
if (item == null) {
return;
}
String initialFileName = null;
String initialExtension = null;
if (item instanceof DocumentationItem) {
DocumentationItem documentationItem = (DocumentationItem) item;
initialFileName = documentationItem.getName();
if (documentationItem.getExtension() != null) {
initialExtension = documentationItem.getExtension();
}
} else if (item instanceof LinkDocumentationItem) {
// link documenation
LinkDocumentationItem linkDocItem = (LinkDocumentationItem) item;
if (!LinkUtils.validateLink(linkDocItem.getLink())) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.getString(//$NON-NLS-1$
"ExtractDocumentationAction.fileErrorTitle"), //$NON-NLS-1$
Messages.getString("ExtractDocumentationAction.fileErrorMessages"));
return;
}
initialFileName = linkDocItem.getName();
if (linkDocItem.getExtension() != null) {
initialExtension = linkDocItem.getExtension();
}
}
if (initialFileName != null) {
FileDialog fileDlg = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
if (initialExtension != null) {
//$NON-NLS-1$
initialFileName = initialFileName + LinkUtils.DOT + initialExtension;
//$NON-NLS-1$ //$NON-NLS-2$
fileDlg.setFilterExtensions(new String[] { "*." + initialExtension, "*.*" });
}
fileDlg.setFileName(initialFileName);
String filename = fileDlg.open();
if (filename != null) {
final File file = new File(filename);
ProgressDialog progressDialog = new ProgressDialog(Display.getCurrent().getActiveShell()) {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
if (item instanceof DocumentationItem) {
DocumentationItem documentationItem = (DocumentationItem) item;
documentationItem.getContent().setInnerContentToFile(file);
} else if (item instanceof LinkDocumentationItem) {
// link documenation
LinkDocumentationItem linkDocItem = (LinkDocumentationItem) item;
ByteArray byteArray = LinkDocumentationHelper.getLinkItemContent(linkDocItem);
if (byteArray != null) {
byteArray.setInnerContentToFile(file);
}
}
} catch (IOException ioe) {
MessageBoxExceptionHandler.process(ioe);
}
}
};
try {
progressDialog.executeProcess();
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
// Nothing to do
}
}
}
}
use of org.talend.core.model.properties.ByteArray in project tdi-studio-se by Talend.
the class AddCopyBookXc2jFileMigrationTask method updateXc2jFilePath.
private boolean updateXc2jFilePath(Item item) throws PersistenceException, IOException {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
boolean update = false;
if (item instanceof ConnectionItem) {
ConnectionItem connectionItem = (ConnectionItem) item;
Connection con = connectionItem.getConnection();
if (con instanceof EbcdicConnection) {
ReferenceFileItem createReferenceFileItem = null;
// the old copybook version depands MidFile
String midFile = ((EbcdicConnection) con).getMidFile();
if (midFile != null) {
File xc2jMidFile = new File(midFile);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
if (xc2jMidFile.exists()) {
readXc2jFile(xc2jMidFile, baos);
}
// create a referenceItem first,maybe it has content,maybe is empty,decide by the midFile
if (connectionItem.getReferenceResources().isEmpty()) {
createReferenceFileItem = PropertiesFactory.eINSTANCE.createReferenceFileItem();
ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
createReferenceFileItem.setContent(byteArray);
createReferenceFileItem.setExtension("xc2j");
connectionItem.getReferenceResources().add(createReferenceFileItem);
} else {
createReferenceFileItem = (ReferenceFileItem) connectionItem.getReferenceResources().get(0);
}
createReferenceFileItem.getContent().setInnerContent(baos.toByteArray());
// create the phyhical x2cj file and set referenceFileItem content for it
String xc2jFilePath = getReferenceXc2jFile(connectionItem).getLocation().makeAbsolute().toFile().getAbsolutePath();
getXc2jFileFromBytes(createReferenceFileItem.getContent().getInnerContent(), xc2jFilePath);
update = true;
}
}
if (update) {
factory.save(connectionItem, true);
}
}
return update;
}
use of org.talend.core.model.properties.ByteArray in project tdi-studio-se by Talend.
the class NewRoutineWizard method updateRoutineContent.
private void updateRoutineContent() {
if (routineItem == null) {
return;
}
ByteArray content = routineItem.getContent();
if (content != null) {
String routineContent = new String(content.getInnerContent());
String label = routineItem.getProperty().getLabel();
if (routineContent != null && !label.equals(ITalendSynchronizer.TEMPLATE)) {
routineContent = routineContent.replaceAll(ITalendSynchronizer.TEMPLATE, label);
content.setInnerContent(routineContent.getBytes());
}
}
}
use of org.talend.core.model.properties.ByteArray in project tdi-studio-se by Talend.
the class SaveAsSQLPatternWizard method performFinish.
public boolean performFinish() {
boolean ok = false;
try {
isUpdate = isUpdate();
if (isUpdate) {
assginVlaues(oldProperty, property);
repositoryFactory.save(oldSqlpatternItem);
// assign value
sqlpatternItem = oldSqlpatternItem;
} else {
property.setId(repositoryFactory.getNextId());
// copy the byte[] content, the new routineItem get the old saved content, it is not the newest.
SQLPatternItem oldItem = (SQLPatternItem) repositoryEditorInput.getItem();
ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
byteArray.setInnerContent(oldItem.getContent().getInnerContent());
sqlpatternItem.setContent(byteArray);
// don't need to add depended routines.
repositoryFactory.create(sqlpatternItem, mainPage.getDestinationPath());
}
ok = true;
} catch (Exception e) {
MessageDialog.openError(getShell(), "Error", "SQLTemplate could not be saved" + " : " + e.getMessage());
ExceptionHandler.process(e);
}
return ok;
}
use of org.talend.core.model.properties.ByteArray in project tdi-studio-se by Talend.
the class EditPropertiesAction method processRename.
protected void processRename(IRepositoryNode node, String originalName) {
try {
IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
ITalendProcessJavaProject talendProcessJavaProject = runProcessService.getTalendProcessJavaProject();
if (talendProcessJavaProject == null) {
return;
}
IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
IPackageFragmentRoot root = talendProcessJavaProject.getJavaProject().getPackageFragmentRoot(srcFolder);
// add for bug TDI-24379 on August 23, 2013.
IFolder srcInterFolder = srcFolder.getFolder(JavaUtils.JAVA_INTERNAL_DIRECTORY);
if (srcInterFolder.exists()) {
File file = new File(srcInterFolder.getLocationURI());
for (File f : file.listFiles()) {
if (f.isFile()) {
f.delete();
}
}
}
// qli modified to fix the bug 5400 and 6185.
// update for fix [TESB-6784]
IPackageFragment routinesPkg = getPackageFragment(root, node);
// ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName +
// SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName + ".java");
if (unit == null) {
return;
}
String newName = node.getObject().getProperty().getLabel();
JavaRenameProcessor processor = new RenameCompilationUnitProcessor(unit);
// processor.setNewElementName(newName + SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
processor.setNewElementName(newName + ".java");
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.hasError()) {
//$NON-NLS-1$
String errorMessage = Messages.getString("EditPropertiesAction.renameError", unit.getElementName(), newName);
RefactoringStatusEntry[] entries = conditionStatus.getEntries();
for (RefactoringStatusEntry entry : entries) {
//$NON-NLS-1$
errorMessage += "\n>>>" + entry.getMessage();
}
Shell shell = null;
IRepositoryView viewPart = getViewPart();
if (viewPart != null) {
shell = viewPart.getViewSite().getShell();
} else {
shell = Display.getCurrent().getActiveShell();
}
//$NON-NLS-1$
MessageDialog.openError(shell, Messages.getString("EditPropertiesAction.warning"), errorMessage);
return;
}
// ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + ".java");
if (newUnit == null) {
return;
}
RoutineItem item = (RoutineItem) node.getObject().getProperty().getItem();
IFile javaFile = (IFile) newUnit.getAdapter(IResource.class);
try {
ByteArray byteArray = item.getContent();
byteArray.setInnerContentFromFile(javaFile);
IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
repFactory.save(item);
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
Aggregations