use of org.eclipse.core.filesystem.IFileStore in project bndtools by bndtools.
the class NewTypeWizardPage method typeNameChanged.
/**
* Hook method that gets called when the type name has changed. The method validates the type name and returns the
* status of the validation.
* <p>
* Subclasses may extend this method to perform their own validation.
* </p>
*
* @return the status of the validation
*/
protected IStatus typeNameChanged() {
StatusInfo status = new StatusInfo();
fCurrType = null;
String typeNameWithParameters = getTypeName();
// must not be empty
if (typeNameWithParameters.length() == 0) {
status.setError(NewWizardMessages.NewTypeWizardPage_error_EnterTypeName);
return status;
}
String typeName = getTypeNameWithoutParameters();
if (typeName.indexOf('.') != -1) {
status.setError(NewWizardMessages.NewTypeWizardPage_error_QualifiedName);
return status;
}
IJavaProject project = getJavaProject();
IStatus val = validateJavaTypeName(typeName, project);
if (val.getSeverity() == IStatus.ERROR) {
status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, val.getMessage()));
return status;
} else if (val.getSeverity() == IStatus.WARNING) {
status.setWarning(Messages.format(NewWizardMessages.NewTypeWizardPage_warning_TypeNameDiscouraged, val.getMessage()));
// continue checking
}
// must not exist
if (!isEnclosingTypeSelected()) {
IPackageFragment pack = getPackageFragment();
if (pack != null) {
ICompilationUnit cu = pack.getCompilationUnit(getCompilationUnitName(typeName));
fCurrType = cu.getType(typeName);
IResource resource = cu.getResource();
if (resource.exists()) {
status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists);
return status;
}
if (!ResourcesPlugin.getWorkspace().validateFiltered(resource).isOK()) {
status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameFiltered);
return status;
}
URI location = resource.getLocationURI();
if (location != null) {
try {
IFileStore store = EFS.getStore(location);
if (store.fetchInfo().exists()) {
status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExistsDifferentCase);
return status;
}
} catch (CoreException e) {
status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_uri_location_unkown, BasicElementLabels.getURLPart(Resources.getLocationString(resource))));
}
}
}
} else {
IType type = getEnclosingType();
if (type != null) {
fCurrType = type.getType(typeName);
if (fCurrType.exists()) {
status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists);
return status;
}
}
}
if (!typeNameWithParameters.equals(typeName) && project != null) {
if (!JavaModelUtil.is50OrHigher(project)) {
status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeParameters);
return status;
}
//$NON-NLS-1$//$NON-NLS-2$
String typeDeclaration = "class " + typeNameWithParameters + " {}";
ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setSource(typeDeclaration.toCharArray());
parser.setProject(project);
CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null);
IProblem[] problems = compilationUnit.getProblems();
if (problems.length > 0) {
status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, problems[0].getMessage()));
return status;
}
}
return status;
}
use of org.eclipse.core.filesystem.IFileStore 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);
}
use of org.eclipse.core.filesystem.IFileStore in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method testGetFileStoreAnnotationModel.
/*
* Tests isSynchronized.
*/
@Test
public void testGetFileStoreAnnotationModel() throws Exception {
IFileStore fileStore = EFS.getNullFileSystem().getStore(new Path("/dev/null"));
assertNotNull(fileStore);
fManager.connectFileStore(fileStore, null);
try {
ITextFileBuffer fileBuffer = fManager.getFileStoreTextFileBuffer(fileStore);
IAnnotationModel model = fileBuffer.getAnnotationModel();
Class<IAnnotationModel> clazz = getAnnotationModelClass();
if (clazz != null)
assertTrue(clazz.isInstance(model));
else
assertNotNull(model);
} finally {
fManager.disconnectFileStore(fileStore, null);
}
}
use of org.eclipse.core.filesystem.IFileStore in project eclipse.platform.text by eclipse.
the class FileBuffersForFilesInLinkedFolders method modifyUnderlyingFile.
@Override
protected boolean modifyUnderlyingFile() throws Exception {
IFileStore fileStore = FileBuffers.getFileStoreAtLocation(getPath());
assertTrue(fileStore.fetchInfo().exists());
OutputStream out = fileStore.openOutputStream(EFS.NONE, null);
try {
out.write("Changed content of file in linked folder".getBytes());
out.flush();
} catch (IOException x) {
fail();
} finally {
out.close();
}
IFileInfo fileInfo = fileStore.fetchInfo();
fileInfo.setLastModified(1000);
fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null);
IFile iFile = FileBuffers.getWorkspaceFileAtLocation(getPath());
iFile.refreshLocal(IResource.DEPTH_INFINITE, null);
return true;
}
use of org.eclipse.core.filesystem.IFileStore in project eclipse.platform.text by eclipse.
the class FileBuffersForNonExistingExternalFiles method setReadOnly.
/*
* @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#markReadOnly()
*/
@Override
protected void setReadOnly(boolean state) throws Exception {
IFileStore fileStore = FileBuffers.getFileStoreAtLocation(getPath());
assertNotNull(fileStore);
fileStore.fetchInfo().setAttribute(EFS.ATTRIBUTE_READ_ONLY, state);
}
Aggregations