use of org.eclipse.ui.part.FileEditorInput in project tdi-studio-se by Talend.
the class Problems method computeCompilationUnit.
@SuppressWarnings("restriction")
private static List<Problem> computeCompilationUnit(IFile file, ProblemType type, Item item) throws CoreException {
ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(item);
// FIXME, only for standard job first, also for JobLaunchShortcut.launch
if (itemType == null || !itemType.equals(ERepositoryObjectType.PROCESS)) {
return Collections.emptyList();
}
List<Problem> compilProblems = new ArrayList<Problem>();
final ICompilationUnit unit = JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(new FileEditorInput(file), false);
if (unit != null) {
CompilationUnit ast = unit.reconcile(ASTProvider.SHARED_AST_LEVEL, ICompilationUnit.FORCE_PROBLEM_DETECTION, null, null);
IProblem[] problems = ast.getProblems();
if (problems != null) {
for (IProblem p : problems) {
String[] arguments = p.getArguments();
int id = p.getID();
String message = p.getMessage();
int sourceLineNumber = p.getSourceLineNumber();
int sourceStart = p.getSourceStart();
int sourceEnd = p.getSourceEnd();
String uniName = null;
IPath location = file.getLocation();
if (location != null) {
String path = location.toString();
uniName = setErrorMark(path, sourceLineNumber);
}
ProblemStatus status = ProblemStatus.WARNING;
if (p.isError()) {
status = ProblemStatus.ERROR;
}
TalendProblem tp = new TalendProblem(status, item, null, message, sourceLineNumber, uniName, sourceStart, sourceEnd, type);
compilProblems.add(tp);
}
}
}
return compilProblems;
}
use of org.eclipse.ui.part.FileEditorInput 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.part.FileEditorInput in project bndtools by bndtools.
the class BndEditor method resourceChanged.
@Override
public void resourceChanged(IResourceChangeEvent event) {
IResource myResource = ResourceUtil.getResource(getEditorInput());
IResourceDelta delta = event.getDelta();
if (delta == null)
return;
IPath fullPath = myResource.getFullPath();
delta = delta.findMember(fullPath);
if (delta == null)
return;
// Delegate to any interested pages
for (Object page : pages) {
if (page instanceof IResourceChangeListener) {
((IResourceChangeListener) page).resourceChanged(event);
}
}
// Close editor if file removed or switch to new location if file moved
if (delta.getKind() == IResourceDelta.REMOVED) {
if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(delta.getMovedToPath());
final FileEditorInput newInput = new FileEditorInput(file);
setInput(newInput);
Display display = getEditorSite().getShell().getDisplay();
if (display != null) {
SWTConcurrencyUtil.execForDisplay(display, true, new Runnable() {
@Override
public void run() {
setPartNameForInput(newInput);
sourcePage.setInput(newInput);
}
});
}
} else {
close(false);
}
} else // File content updated externally => reload all pages
if ((delta.getKind() & IResourceDelta.CHANGED) > 0 && (delta.getFlags() & IResourceDelta.CONTENT) > 0) {
if (!saving.get()) {
final IDocumentProvider docProvider = sourcePage.getDocumentProvider();
// #1625: Ensure the IDocumentProvider is not null.
if (docProvider != null) {
final IDocument document = docProvider.getDocument(getEditorInput());
SWTConcurrencyUtil.execForControl(getEditorSite().getShell(), true, new Runnable() {
@Override
public void run() {
try {
model.loadFrom(new IDocumentWrapper(document));
updateIncludedPages();
} catch (IOException e) {
logger.logError("Failed to reload document", e);
}
}
});
}
}
}
}
Aggregations