use of org.eclipse.ui.IEditorInput in project tdi-studio-se by Talend.
the class JobLaunchShortcut method launch.
/**
* Locates a launchable entity in the given active editor, and launches an application in the specified mode.
*
* @see org.eclipse.debug.ui.ILaunchShortcut#launch(org.eclipse.ui.IEditorPart, java.lang.String)
*
* @param editor the active editor in the workbench
* @param mode one of the launch modes defined by the launch manager
* @see org.eclipse.debug.core.ILaunchManager
*/
@Override
public void launch(IEditorPart editor, String mode) {
IEditorInput input = editor.getEditorInput();
if (input instanceof RepositoryEditorInput) {
RepositoryEditorInput rInput = (RepositoryEditorInput) input;
launch(rInput.getItem(), mode);
}
}
use of org.eclipse.ui.IEditorInput in project tdi-studio-se by Talend.
the class AbstractMultiPageTalendEditor method createPage2.
// create jobscript editor
protected void createPage2() {
if (!GlobalServiceRegister.getDefault().isServiceRegistered(ICreateXtextProcessService.class)) {
return;
}
String scriptValue = "";
try {
IProject currentProject = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
String jobScriptVersion = "";
if (getEditorInput() != null && getEditorInput() instanceof RepositoryEditorInput) {
Item item = ((RepositoryEditorInput) getEditorInput()).getItem();
if (item != null) {
Property property = item.getProperty();
if (property != null) {
jobScriptVersion = "_" + property.getVersion();
}
}
}
IFile file = currentProject.getFolder("temp").getFile(getEditorInput().getName() + jobScriptVersion + "_job" + ".jobscript");
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(scriptValue.getBytes());
if (file.exists()) {
file.delete(true, null);
file.create(byteArrayInputStream, true, null);
file.setContents(byteArrayInputStream, 0, null);
} else {
file.create(byteArrayInputStream, true, null);
}
String pointId = "org.talend.metalanguage.jobscript.JobScriptForMultipage";
// the way to get the xtextEditor programmly
IEditorInput editorInput = new FileEditorInput(file);
IExtensionPoint ep = RegistryFactory.getRegistry().getExtensionPoint("org.eclipse.ui.editors");
IExtension[] extensions = ep.getExtensions();
IExtension ex;
IConfigurationElement confElem = null;
for (IExtension extension : extensions) {
ex = extension;
if (ex.getContributor().getName().equals("org.talend.metalanguage.jobscript.ui")) {
for (IConfigurationElement c : ex.getConfigurationElements()) {
if (c.getName().equals("editor") && c.getAttribute("id").equals(pointId)) {
confElem = c;
break;
}
}
}
}
if (confElem != null) {
jobletEditor = (AbstractDecoratedTextEditor) confElem.createExecutableExtension("class");
if (jobletEditor != null) {
int index = addPage(jobletEditor, editorInput);
setPageText(index, "Jobscript");
}
}
} catch (PartInitException e) {
ExceptionHandler.process(e);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
use of org.eclipse.ui.IEditorInput in project tdi-studio-se by Talend.
the class AbstractMultiPageTalendEditor method createPage1.
/**
* Creates page 1 of the multi-page editor, which allows you to change the font used in page 2.
*/
protected void createPage1() {
IProcess2 process = getProcess();
codeEditor = CodeEditorFactory.getInstance().getCodeEditor(getCurrentLang(), process);
processor = ProcessorUtilities.getProcessor(process, process.getProperty(), process.getContextManager().getDefaultContext());
if (processor instanceof IJavaBreakpointListener) {
JDIDebugModel.addJavaBreakpointListener((IJavaBreakpointListener) processor);
}
processor.setProcessorStates(IProcessor.STATES_EDIT);
if (codeEditor instanceof ISyntaxCheckableEditor) {
processor.setSyntaxCheckableEditor((ISyntaxCheckableEditor) codeEditor);
}
if (useCodeView) {
try {
IEditorInput editorInput = createFileEditorInput();
if (!(process.getProperty().getItem() instanceof ProcessItem)) {
// shouldn't work for joblet
editorInput = new JobletCodeEditInput();
}
int index = addPage(codeEditor, editorInput);
// init Syntax Validation.
//$NON-NLS-1$
setPageText(index, "Code");
} catch (PartInitException pie) {
// pie.printStackTrace();
ExceptionHandler.process(pie);
}
}
if (DesignerPlugin.getDefault().getPreferenceStore().getBoolean(TalendDesignerPrefConstants.GENERATE_CODE_WHEN_OPEN_JOB)) {
generateCode();
}
}
use of org.eclipse.ui.IEditorInput in project tdi-studio-se by Talend.
the class ComponentChooseDialog method createContext.
private void createContext(List<Object> sourceList) {
if (sourceList.size() == 0) {
return;
}
boolean created = false;
for (Object source : sourceList) {
if (source instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) source;
Item item = sourceNode.getObject().getProperty().getItem();
if (item instanceof ContextItem) {
ContextItem contextItem = (ContextItem) item;
EList context = contextItem.getContext();
Set<String> contextSet = new HashSet<String>();
Iterator iterator = context.iterator();
while (iterator.hasNext()) {
Object obj = iterator.next();
if (obj instanceof ContextTypeImpl) {
EList contextParameters = ((ContextTypeImpl) obj).getContextParameter();
Iterator contextParas = contextParameters.iterator();
while (contextParas.hasNext()) {
ContextParameterTypeImpl contextParameterType = (ContextParameterTypeImpl) contextParas.next();
String name = contextParameterType.getName();
contextSet.add(name);
}
}
}
IEditorInput editorInput = editor.getEditorInput();
if (editorInput instanceof JobEditorInput) {
JobEditorInput jobInput = (JobEditorInput) editorInput;
IProcess2 process = jobInput.getLoadedProcess();
IContextManager contextManager = process.getContextManager();
List<IContext> listContext = contextManager.getListContext();
// context group will reflect absolutely if no context variable in contextViewer
// if (!ConnectionContextHelper.containsVariable(contextManager)) {
// for bug 15608
// ConnectionContextHelper.addContextVarForJob(process, contextItem, contextManager);
// ConnectionContextHelper.checkAndAddContextsVarDND(contextItem, contextManager);
Set<String> addedVars = ConnectionContextHelper.checkAndAddContextVariables(contextItem, contextSet, process.getContextManager(), false);
if (addedVars != null && !addedVars.isEmpty() && !ConnectionContextHelper.isAddContextVar(contextItem, contextManager, contextSet)) {
// show
Map<String, Set<String>> addedVarsMap = new HashMap<String, Set<String>>();
addedVarsMap.put(item.getProperty().getLabel(), contextSet);
if (ConnectionContextHelper.showContextdialog(process, contextItem, process.getContextManager(), addedVarsMap, contextSet)) {
created = true;
}
}
// } else {
// Set<String> addedContext = ConnectionContextHelper.checkAndAddContextVariables(contextItem,
// contextSet, contextManager, false);
// if (addedContext != null && addedContext.size() > 0) {
// ConnectionContextHelper.addContextVarForJob(process, contextItem, contextSet);
// created = true;
// }
// }
}
}
}
}
if (created) {
RepositoryPlugin.getDefault().getDesignerCoreService().switchToCurContextsView();
}
}
use of org.eclipse.ui.IEditorInput in project tdi-studio-se by Talend.
the class InfoPage method doSave.
/**
* Saves the changed editor contents.
*
* @param monitor The progress monitor
*/
protected void doSave(IProgressMonitor monitor) {
IEditorInput input = editor.getEditorInput();
IFile resourceFile = null;
File file = null;
InputStream inputStream = null;
String comments = commentsText.getText();
try {
if (input instanceof IFileEditorInput) {
resourceFile = ((IFileEditorInput) input).getFile();
inputStream = new BufferedInputStream(resourceFile.getContents());
file = resourceFile.getRawLocation().toFile();
} else if (input instanceof FileStoreEditorInput) {
file = new File(((FileStoreEditorInput) input).getURI().getPath());
inputStream = new FileInputStream(file);
} else {
return;
}
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream);
Element root = document.getDocumentElement();
//$NON-NLS-1$
root.setAttribute("comments", comments);
DOMSource source = new DOMSource(root);
StreamResult result = new StreamResult(file);
TransformerFactory.newInstance().newTransformer().transform(source, result);
if (resourceFile != null) {
resourceFile.refreshLocal(0, monitor);
}
lastComments = comments;
editor.firePropertyChange(IEditorPart.PROP_DIRTY);
} catch (CoreException e) {
Activator.log(IStatus.ERROR, Messages.saveFileFailedMsg, e);
} catch (SAXException e) {
Activator.log(IStatus.ERROR, Messages.saveFileFailedMsg, e);
} catch (IOException e) {
Activator.log(IStatus.ERROR, Messages.saveFileFailedMsg, e);
} catch (ParserConfigurationException e) {
Activator.log(IStatus.ERROR, Messages.saveFileFailedMsg, e);
} catch (TransformerException e) {
Activator.log(IStatus.ERROR, Messages.saveFileFailedMsg, e);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
// do nothing
}
}
}
}
Aggregations