Java Code Examples for org.eclipse.ui.texteditor.IDocumentProvider#canSaveDocument()

The following examples show how to use org.eclipse.ui.texteditor.IDocumentProvider#canSaveDocument() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestEditor.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean isDirty() {
    final IDocumentProvider p = getDocumentProvider();
    return p == null ? false : p.canSaveDocument(getEditorInput());
}
 
Example 2
Source File: EditorManager.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Programmatically saves the given editor IF and only if the file is registered as a connected
 * file.
 *
 * <p>Calling this method will trigger a call to all registered SharedEditorListeners (independent
 * of the success of this method) BEFORE the file is actually saved.
 *
 * <p>Calling this method will NOT trigger a {@link EditorActivity} of type Save to be sent to the
 * other clients.
 *
 * @param wrappedFile the file that is supposed to be saved to disk.
 * @swt This method must be called from the SWT thread
 * @nonReentrant This method cannot be called twice at the same time.
 */
public void saveEditor(saros.filesystem.IFile wrappedFile) {
  checkThreadAccess();

  IFile file = ((EclipseFileImpl) wrappedFile).getDelegate();

  log.trace(".saveEditor (" + file.getName() + ") invoked");

  if (!file.exists()) {
    log.warn("File not found for saving: " + wrappedFile.toString(), new StackTrace());
    return;
  }

  FileEditorInput input = new FileEditorInput(file);
  IDocumentProvider provider = EditorAPI.connect(input);

  if (provider == null) return;

  if (!provider.canSaveDocument(input)) {
    /*
     * This happens when a file which is already saved is saved again by
     * a user.
     */
    log.debug(".saveEditor File " + file.getName() + " does not need to be saved");
    provider.disconnect(input);
    return;
  }

  log.trace(".saveEditor File " + file.getName() + " will be saved");

  final boolean isConnected = isManaged(file);

  /*
   * connect to the file so the SharedResourceManager /
   * ProjectDeltaVisitor will ignore the file change because it is
   * possible that no editor is open for this file
   */
  if (!isConnected) connect(file);

  IDocument doc = provider.getDocument(input);

  // TODO Why do we need to connect to the annotation model here?
  IAnnotationModel model = provider.getAnnotationModel(input);
  if (model != null) model.connect(doc);

  log.trace(".saveEditor Annotations on the IDocument are set");

  editorPool.setElementStateListenerEnabled(false);

  try {
    provider.saveDocument(new NullProgressMonitor(), input, doc, true);
    log.debug("Saved document: " + wrappedFile);
  } catch (CoreException e) {
    log.error("Failed to save document: " + wrappedFile, e);
  }

  editorPool.setElementStateListenerEnabled(true);

  if (model != null) model.disconnect(doc);

  provider.disconnect(input);

  if (!isConnected) disconnect(file);
}
 
Example 3
Source File: TestEditor.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean isDirty() {
	IDocumentProvider p = getDocumentProvider();
	return p == null ? false : p.canSaveDocument(getEditorInput());
}