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 tdi-studio-se by Talend.
the class TalendDefaultJavaEditor method doSetInput.
@Override
protected void doSetInput(IEditorInput input) throws CoreException {
if (input instanceof FileEditorInput) {
try {
// IRepositoryService repositoryService = DesignerPlugin.getDefault().getRepositoryService();
// IProxyRepositoryFactory repFactory = repositoryService.getProxyRepositoryFactory();
IRunProcessService runProcessService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
// I think runProcessService can't be null, and should throw exception if it is null
ITalendProcessJavaProject talendJavaProject = runProcessService.getTalendProcessJavaProject();
if (talendJavaProject == null) {
return;
}
//$NON-NLS-1$
final String pathSeperator = "/";
String routinesFolderName = ERepositoryObjectType.ROUTINES.getFolder().split(pathSeperator)[1];
String talendSrcFolderPath = talendJavaProject.getSrcFolder().getLocation().toString() + pathSeperator;
String routineFolderPath = talendSrcFolderPath + routinesFolderName + pathSeperator;
IFile openedFile = ((FileEditorInput) input).getFile();
String openedFilePath = openedFile.getLocation().toString();
boolean isRoutine = openedFilePath.startsWith(routineFolderPath);
boolean isTalendGeneratedFile = openedFilePath.startsWith(talendSrcFolderPath);
//$NON-NLS-1$
String systemRoutineFolderName = "system";
String systemRoutineFolderPath = routineFolderPath + systemRoutineFolderName + pathSeperator;
boolean isSystemRoutine = openedFilePath.startsWith(systemRoutineFolderPath);
if (isSystemRoutine) {
fileType = FILE_TYPE_TALEND_GENERATED_READONLY;
} else if (isRoutine) {
fileType = FILE_TYPE_TALEND_GENERATED_READONLY;
} else if (isTalendGeneratedFile) {
fileType = FILE_TYPE_TALEND_GENERATED_READONLY;
} else {
fileType = FILE_TYPE_OTHERS;
}
} catch (Throwable e) {
CommonExceptionHandler.process(e, Priority.WARN);
fileType = FILE_TYPE_OTHERS;
}
}
super.doSetInput(input);
}
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);
}
}
});
}
}
}
}
use of org.eclipse.ui.part.FileEditorInput in project eclipse.platform.text by eclipse.
the class AbstratGenericEditorTest method createAndOpenFile.
/**
* Creates a new file in the project, opens it, and associate that file with the test state
* @param name name of the file in the project
* @param contents content of the file
* @throws Exception ex
* @since 1.1
*/
protected void createAndOpenFile(String name, String contents) throws Exception {
this.file = project.getFile(name);
this.file.create(new ByteArrayInputStream(contents.getBytes("UTF-8")), true, null);
this.file.setCharset("UTF-8", null);
this.editor = (ExtensionBasedTextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(new FileEditorInput(this.file), "org.eclipse.ui.genericeditor.GenericEditor");
}
use of org.eclipse.ui.part.FileEditorInput in project eclipse.platform.text by eclipse.
the class AbstractDecoratedTextEditor method performSaveAs.
/**
* This implementation asks the user for the workspace path of a file resource and saves the document there.
*
* @param progressMonitor the progress monitor to be used
* @since 3.2
*/
@Override
protected void performSaveAs(IProgressMonitor progressMonitor) {
Shell shell = PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
final IEditorInput input = getEditorInput();
IDocumentProvider provider = getDocumentProvider();
final IEditorInput newInput;
if (input instanceof IURIEditorInput && !(input instanceof IFileEditorInput)) {
FileDialog dialog = new FileDialog(shell, SWT.SAVE);
IPath oldPath = URIUtil.toPath(((IURIEditorInput) input).getURI());
if (oldPath != null && !oldPath.isEmpty()) {
dialog.setFileName(oldPath.lastSegment());
dialog.setFilterPath(oldPath.removeLastSegments(1).toOSString());
}
String path = dialog.open();
if (path == null) {
if (progressMonitor != null)
progressMonitor.setCanceled(true);
return;
}
// Check whether file exists and if so, confirm overwrite
final File localFile = new File(path);
if (localFile.exists()) {
MessageDialog overwriteDialog = new MessageDialog(shell, TextEditorMessages.AbstractDecoratedTextEditor_saveAs_overwrite_title, null, NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_saveAs_overwrite_message, path), MessageDialog.WARNING, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, // 'No' is the default
1);
if (overwriteDialog.open() != Window.OK) {
if (progressMonitor != null) {
progressMonitor.setCanceled(true);
return;
}
}
}
IFileStore fileStore;
try {
fileStore = EFS.getStore(localFile.toURI());
} catch (CoreException ex) {
EditorsPlugin.log(ex.getStatus());
String title = TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_title;
String msg = NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_message, ex.getMessage());
MessageDialog.openError(shell, title, msg);
return;
}
IFile file = getWorkspaceFile(fileStore);
if (file != null)
newInput = new FileEditorInput(file);
else
newInput = new FileStoreEditorInput(fileStore);
} else {
SaveAsDialog dialog = new SaveAsDialog(shell);
IFile original = (input instanceof IFileEditorInput) ? ((IFileEditorInput) input).getFile() : null;
if (original != null)
dialog.setOriginalFile(original);
else
dialog.setOriginalName(input.getName());
dialog.create();
if (provider.isDeleted(input) && original != null) {
String message = NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_warning_saveAs_deleted, original.getName());
dialog.setErrorMessage(null);
dialog.setMessage(message, IMessageProvider.WARNING);
}
if (dialog.open() == Window.CANCEL) {
if (progressMonitor != null)
progressMonitor.setCanceled(true);
return;
}
IPath filePath = dialog.getResult();
if (filePath == null) {
if (progressMonitor != null)
progressMonitor.setCanceled(true);
return;
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IFile file = workspace.getRoot().getFile(filePath);
newInput = new FileEditorInput(file);
}
if (provider == null) {
// editor has programmatically been closed while the dialog was open
return;
}
boolean success = false;
try {
provider.aboutToChange(newInput);
provider.saveDocument(progressMonitor, newInput, provider.getDocument(input), true);
success = true;
} catch (CoreException x) {
final IStatus status = x.getStatus();
if (status == null || status.getSeverity() != IStatus.CANCEL) {
String title = TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_title;
String msg = NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_message, x.getMessage());
MessageDialog.openError(shell, title, msg);
}
} finally {
provider.changed(newInput);
if (success)
setInput(newInput);
}
if (progressMonitor != null)
progressMonitor.setCanceled(!success);
}
Aggregations