use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class XbaseEditor method getDocumentProvider.
@Override
public IDocumentProvider getDocumentProvider() {
if (expectJavaSelection > 0 && reentrantCallFromSelf == 0) {
if (calleeAnalyzer.isLineBasedOpenEditorAction()) {
expectLineSelection = true;
if (isCompiledWithJSR45()) {
return new DocumentProviderStub() {
@Override
public IDocument getDocument(Object element) {
if (typeRoot == null) {
return XbaseEditor.super.getDocumentProvider().getDocument(element);
}
IResource javaResource = typeRoot.getResource();
if (!(javaResource instanceof IStorage)) {
return XbaseEditor.super.getDocumentProvider().getDocument(element);
}
try {
String string = Files.readStreamIntoString(((IStorage) javaResource).getContents());
final Document document = new Document(string);
return document;
} catch (CoreException e) {
return XbaseEditor.super.getDocumentProvider().getDocument(element);
}
}
@Override
public void connect(Object element) throws CoreException {
// do nothing
}
@Override
public void disconnect(Object element) {
// do nothing
}
};
}
}
}
return super.getDocumentProvider();
}
use of org.eclipse.core.resources.IStorage in project eclipse.platform.text by eclipse.
the class LastSaveReferenceProvider method readDocument.
/**
* Reads in the saved document into <code>fReference</code>.
*
* @param monitor a progress monitor, or <code>null</code>
* @param force <code>true</code> if the reference document should also
* be read if the current document is <code>null</code>,<code>false</code>
* if it should only be updated if it already existed.
*/
private void readDocument(IProgressMonitor monitor, boolean force) {
// protect against concurrent disposal
IDocumentProvider prov = fDocumentProvider;
IEditorInput inp = fEditorInput;
IDocument doc = fReference;
ITextEditor editor = fEditor;
if (prov instanceof IStorageDocumentProvider && inp instanceof IStorageEditorInput) {
IStorageEditorInput input = (IStorageEditorInput) inp;
IStorageDocumentProvider provider = (IStorageDocumentProvider) prov;
if (doc == null)
if (force || fDocumentRead)
doc = new Document();
else
return;
IJobManager jobMgr = Job.getJobManager();
try {
IStorage storage = input.getStorage();
// check for null for backward compatibility (we used to check before...)
if (storage == null)
return;
fProgressMonitor = monitor;
ISchedulingRule rule = getSchedulingRule(storage);
// delay for any other job requiring the lock on file
try {
lockDocument(monitor, jobMgr, rule);
String encoding;
if (storage instanceof IEncodedStorage)
encoding = ((IEncodedStorage) storage).getCharset();
else
encoding = null;
boolean skipUTF8BOM = isUTF8BOM(encoding, storage);
setDocumentContent(doc, storage, encoding, monitor, skipUTF8BOM);
} finally {
unlockDocument(jobMgr, rule);
fProgressMonitor = null;
}
} catch (CoreException e) {
return;
}
if (monitor != null && monitor.isCanceled())
return;
// update state
synchronized (fLock) {
if (fDocumentProvider == provider && fEditorInput == input) {
// only update state if our provider / input pair has not
// been updated in between (dispose or setActiveEditor)
fReference = doc;
fDocumentRead = true;
addElementStateListener(editor, prov);
}
}
}
}
use of org.eclipse.core.resources.IStorage in project eclipse.platform.text by eclipse.
the class StorageDocumentProvider method updateCache.
/**
* Updates the internal cache for the given input.
*
* @param input the input whose cache will be updated
* @throws CoreException if the storage cannot be retrieved from the input
* @since 2.0
*/
protected void updateCache(IStorageEditorInput input) throws CoreException {
StorageInfo info = (StorageInfo) getElementInfo(input);
if (info != null) {
try {
IStorage storage = input.getStorage();
if (storage != null) {
boolean readOnly = storage.isReadOnly();
info.fIsReadOnly = readOnly;
info.fIsModifiable = !readOnly;
}
} catch (CoreException x) {
handleCoreException(x, TextEditorMessages.StorageDocumentProvider_updateCache);
}
info.fUpdateCache = false;
}
}
use of org.eclipse.core.resources.IStorage in project liferay-ide by liferay.
the class TaglibVariableInsertionDialog method _isFreemarkerEditor.
private static boolean _isFreemarkerEditor(IEditorPart editorPart) {
try {
IStorageEditorInput input = (IStorageEditorInput) editorPart.getEditorInput();
IStorage storage = input.getStorage();
if (storage.getName().endsWith(".ftl")) {
return true;
}
} catch (Exception e) {
// ignore just return false
}
return false;
}
use of org.eclipse.core.resources.IStorage in project liferay-ide by liferay.
the class AddMacroLibrary method run.
public void run(IAction action) {
ISelectionProvider provider = part.getSite().getSelectionProvider();
if (null != provider) {
if (provider.getSelection() instanceof IStructuredSelection) {
try {
IStructuredSelection selection = (IStructuredSelection) provider.getSelection();
Object[] obj = selection.toArray();
List documents = new ArrayList();
for (int i = 0; i < obj.length; i++) {
if (obj[i] instanceof IFile) {
IFile file = (IFile) obj[i];
documents.add(file);
} else if (obj[i] instanceof JarEntryFile) {
JarEntryFile jef = (JarEntryFile) obj[i];
documents.add(jef);
System.out.println(jef.getFullPath().makeAbsolute());
System.out.println(jef.getFullPath().makeRelative());
IPath path = jef.getFullPath();
System.out.println(path);
System.out.println(jef.getName());
IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(jef.getFullPath());
System.out.println(resource);
} else if (obj[i] instanceof IStorage) {
}
}
IProject project = null;
if (documents.size() > 0) {
// what project?
HashSet projects = new HashSet();
IProject[] p = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (int i = 0; i < p.length; i++) {
projects.add(p[i]);
}
ProjectSelectionDialog dialog = new ProjectSelectionDialog(Display.getCurrent().getActiveShell(), projects);
dialog.setTitle(Messages.AddMacroLibrary_Title);
dialog.setMessage(Messages.AddMacroLibrary_Message);
int rtn = dialog.open();
if (rtn == IDialogConstants.OK_ID) {
if (dialog.getFirstResult() instanceof IJavaProject) {
project = ((IJavaProject) dialog.getFirstResult()).getProject();
} else {
MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.AddMacroLibrary_Error, Messages.AddMacroLibrary_ErrorDesc);
}
}
}
if (null != project) {
ConfigurationManager.getInstance(project).associateMappingLibraries(documents, Display.getCurrent().getActiveShell());
}
} catch (Exception e) {
Plugin.error(e);
}
}
}
}
Aggregations