CHE-4010: Remove deprecation related to texteditor

Signed-off-by: Roman Nikitenko <rnikitenko@codenvy.com>
6.19.x
Roman Nikitenko 2017-02-23 11:16:45 +02:00 committed by RomanNikitenko
parent f1a880735d
commit 035c3fe63f
24 changed files with 85 additions and 1990 deletions

View File

@ -13,7 +13,6 @@ package org.eclipse.che.ide.api.editor.events;
import com.google.gwt.event.shared.GwtEvent;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.texteditor.EditorHandle;
/**
* Event will be fired then document fully initialized in editor
@ -23,26 +22,13 @@ public class DocumentReadyEvent extends GwtEvent<DocumentReadyHandler> {
/** The type instance for this event. */
public static final Type<DocumentReadyHandler> TYPE = new Type<>();
/** The editor. */
private final EditorHandle editorHandle;
/** The document. */
private final Document document;
/**
* Use {@link DocumentReadyEvent(Document)}
*
*/
@Deprecated
public DocumentReadyEvent(final EditorHandle editorHandle, final Document document) {
this.editorHandle = editorHandle;
this.document = document;
}
/**
* @param document the related initialized document
*/
public DocumentReadyEvent(final Document document) {
this.editorHandle = null;
this.document = document;
}
@ -59,13 +45,4 @@ public class DocumentReadyEvent extends GwtEvent<DocumentReadyHandler> {
public Document getDocument() {
return document;
}
/**
* Don't use this method because {@link EditorHandle} will be removed in next version.
* It useless interface dont have any implementation and don't need in future
*/
@Deprecated
public EditorHandle getEditorHandle() {
return editorHandle;
}
}

View File

@ -10,34 +10,29 @@
*******************************************************************************/
package org.eclipse.che.ide.api.editor.events.doc;
import org.eclipse.che.commons.annotation.Nullable;
import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.event.shared.HandlerRegistration;
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.ide.api.editor.document.DocumentHandle;
import org.eclipse.che.ide.api.editor.events.DocumentReadyEvent;
import org.eclipse.che.ide.api.editor.events.DocumentReadyHandler;
import org.eclipse.che.ide.api.editor.texteditor.EditorHandle;
import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.event.shared.HandlerRegistration;
/**
* Wrapper around components that need to wait for documents to be ready.
*/
public class DocReadyWrapper<T> {
private final EditorHandle editorHandle;
private DocReadyInit<T> docReadyInit;
private final T wrapped;
private HandlerRegistration docReadyRegistration;
private DocumentHandle documentHandle;
public DocReadyWrapper(final EventBus generalEventBus, final EditorHandle editor, final T wrapped) {
this(generalEventBus, editor, null, wrapped);
public DocReadyWrapper(final EventBus generalEventBus, final T wrapped) {
this(generalEventBus, null, wrapped);
}
public DocReadyWrapper(final EventBus generalEventBus, final EditorHandle editor,
@Nullable final DocReadyInit<T> init, final T wrapped) {
this.editorHandle = editor;
public DocReadyWrapper(final EventBus generalEventBus, @Nullable final DocReadyInit<T> init, final T wrapped) {
this.docReadyInit = init;
this.wrapped = wrapped;
this.docReadyRegistration = generalEventBus.addHandler(DocumentReadyEvent.TYPE,
@ -48,15 +43,7 @@ public class DocReadyWrapper<T> {
if (event == null) {
return;
}
if (event.getEditorHandle() == null) {
return;
}
EditorHandle eventHandle = event.getEditorHandle();
EditorHandle constantHandle = editorHandle;
boolean equal = eventHandle.equals(constantHandle);
if (!equal) {
return;
}
// stop listening DocReady events
if (docReadyRegistration != null) {
docReadyRegistration.removeHandler();

View File

@ -1,73 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.api.editor.texteditor;
import java.util.List;
import org.eclipse.che.ide.api.editor.texteditor.EditorWidget;
import org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo;
import org.eclipse.che.ide.api.editor.codeassist.AdditionalInfoCallback;
import org.eclipse.che.ide.api.editor.codeassist.CompletionProposal;
import org.eclipse.che.ide.api.editor.codeassist.CompletionsSource;
import org.eclipse.che.ide.api.editor.position.PositionConverter;
import org.eclipse.che.ide.api.editor.texteditor.LineStyler;
import com.google.gwt.user.client.ui.Composite;
public abstract class CompositeEditorWidget extends Composite implements EditorWidget {
@Override
public LineStyler getLineStyler() {
return null;
}
@Override
public void onResize() {
// Does nothing by default
}
@Override
public HandlesUndoRedo getUndoRedo() {
return null;
}
@Override
public PositionConverter getPositionConverter() {
return null;
}
@Override
public void showCompletionsProposals(final List<CompletionProposal> proposals) {
// does nothing by default
}
@Override
public void showCompletionProposals(final CompletionsSource completionsSource) {
// does nothing by default
}
@Override
public void showCompletionProposals() {
// does nothing by default
}
@Override
public void showCompletionProposals(final CompletionsSource completionsSource,
final AdditionalInfoCallback additionalInfoCallback) {
showCompletionProposals(completionsSource);
}
@Override
public void refresh() {
}
}

View File

@ -22,12 +22,10 @@ public interface CursorModel {
*/
void setCursorPosition(int offset);
/**
* Get cursor position
*
* @return the position of cursor.
*/
Position getCursorPosition();
}

View File

@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.che.ide.api.editor.texteditor;
import org.eclipse.che.ide.api.editor.texteditor.CursorModel;
import org.eclipse.che.ide.util.ListenerRegistrar.Remover;
/**

View File

@ -1,20 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.api.editor.texteditor;
/**
* Handle on an editor view instance.
* Don't use it for now doesn't have any implementation and will be removed in next version
*/
@Deprecated
public interface EditorHandle {
}

View File

@ -1,112 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.api.editor.texteditor;
import org.eclipse.che.ide.api.editor.EditorLocalizationConstants;
import org.eclipse.che.ide.api.editor.document.DocumentStorage.DocumentCallback;
import org.eclipse.che.ide.rest.AsyncRequestLoader;
import org.eclipse.che.ide.ui.loaders.request.LoaderFactory;
/**
* Composite callback that waits for both the editor module initialization and the document content.
* @param <T> the type of the editor widget
*/
@Deprecated
abstract class EditorInitCallback<T extends EditorWidget> implements DocumentCallback, EditorModule.EditorModuleReadyCallback {
/** Loader used to wait for editor impl initialization. */
private final AsyncRequestLoader loader;
/** The message displayed while waiting for the editor init. */
private final String waitEditorMessageString;
/** Flag that tells if the editor initialization was finished. */
private boolean editorModuleReady;
/** The content of the document to open. */
private String receivedContent;
/** Tells if editor init loader was shown. */
private boolean loaderWasShown = false;
/**
* Constructor.
* @param moduleAlreadyReady if set to true, the callback will not wait for editor module initialization.
* @param loader loader used to wait for editor impl initialization
*/
public EditorInitCallback(final boolean moduleAlreadyReady,
final LoaderFactory loaderFactory,
final EditorLocalizationConstants constants) {
this.editorModuleReady = moduleAlreadyReady;
this.loader = loaderFactory.newLoader();
this.waitEditorMessageString = constants.waitEditorInitMessage();
}
@Override
public void onEditorModuleReady() {
this.editorModuleReady = true;
checkReadyAndContinue();
}
@Override
public void onEditorModuleError() {
if (this.loaderWasShown) {
this.loader.hide();
}
onError();
}
@Override
public void onDocumentReceived(final String content) {
if (content != null) {
this.receivedContent = content;
} else {
this.receivedContent = "";
}
checkReadyAndContinue();
}
@Override
public void onDocumentLoadFailure(final Throwable cause) {
if (this.loaderWasShown) {
this.loader.hide();
}
onFileError();
}
private void checkReadyAndContinue() {
if (this.receivedContent != null && this.editorModuleReady) {
if (this.loaderWasShown) {
this.loader.hide();
}
onReady(this.receivedContent);
} else if (! this.editorModuleReady) {
// Show a loader for the editor preparation
this.loaderWasShown = true;
this.loader.show(this.waitEditorMessageString);
}
}
/**
* Action when the editor is ready AND we have the document content.
* @param content the content
*/
public abstract void onReady(final String content);
/**
* Action when editor init failed.
*/
public abstract void onError();
/**
* Action when file load failed.
*/
public abstract void onFileError();
}

View File

@ -1,45 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.api.editor.texteditor;
/**
* Front for an editor module, that allows to be warned when it's initialized.
*/
@Deprecated
public interface EditorModule {
/**
* Tells if the editor module is initialized.
* @return true if the module is ready
*/
boolean isReady();
/**
* Tells if the module initialization failed.
* @return true iff the initialization failed
*/
boolean isError();
/**
* Asks the module to warn the caller by using the provided callback.
* @param callback the callback to call when the module is ready or failed
*/
void waitReady(EditorModuleReadyCallback callback);
/** Callback to call when the module is ready of failed. */
@Deprecated
interface EditorModuleReadyCallback {
/** Used when the initialization is done. */
void onEditorModuleReady();
/** Used when the initialization failed. */
void onEditorModuleError();
}
}

View File

@ -12,7 +12,6 @@ package org.eclipse.che.ide.api.editor.texteditor;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.resources.client.ImageResource;
/** Resources interface for the editor. */
public interface EditorResources extends ClientBundle {

View File

@ -1,73 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.api.editor.texteditor;
import org.eclipse.che.ide.api.editor.text.Position;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.events.CursorActivityEvent;
import org.eclipse.che.ide.api.editor.events.CursorActivityHandler;
import org.eclipse.che.ide.api.editor.text.TextPosition;
import org.eclipse.che.ide.util.ListenerManager;
import org.eclipse.che.ide.util.ListenerManager.Dispatcher;
import org.eclipse.che.ide.util.ListenerRegistrar.Remover;
/**
* {@link CursorModelWithHandler} implementation for the text editors.
*
* @author "Mickaël Leduque"
*/
@Deprecated
class TextEditorCursorModel implements CursorModelWithHandler, CursorActivityHandler {
private final Document document;
private final ListenerManager<CursorHandler> cursorHandlerManager = ListenerManager.create();
public TextEditorCursorModel(final Document document) {
this.document = document;
this.document.addCursorHandler(this);
}
@Override
public void setCursorPosition(int offset) {
TextPosition position = document.getPositionFromIndex(offset);
document.setCursorPosition(position);
}
@Override
public Position getCursorPosition() {
TextPosition position = document.getCursorPosition();
int offset = document.getIndexFromPosition(position);
return new Position(offset);
}
@Override
public Remover addCursorHandler(CursorHandler handler) {
return this.cursorHandlerManager.add(handler);
}
private void dispatchCursorChange(final boolean isExplicitChange) {
final TextPosition position = this.document.getCursorPosition();
cursorHandlerManager.dispatch(new Dispatcher<CursorModelWithHandler.CursorHandler>() {
@Override
public void dispatch(CursorHandler listener) {
listener.onCursorChange(position.getLine(), position.getCharacter(), isExplicitChange);
}
});
}
@Override
public void onCursorActivity(final CursorActivityEvent event) {
dispatchCursorChange(true);
}
}

View File

@ -1,334 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.api.editor.texteditor;
import elemental.events.KeyboardEvent.KeyCode;
import com.google.web.bindery.event.shared.EventBus;
import org.eclipse.che.ide.api.editor.events.DocumentReadyEvent;
import org.eclipse.che.ide.api.editor.formatter.ContentFormatter;
import org.eclipse.che.ide.api.editor.text.TypedRegion;
import org.eclipse.che.ide.api.editor.annotation.AnnotationModel;
import org.eclipse.che.ide.api.editor.annotation.HasAnnotationRendering;
import org.eclipse.che.ide.api.editor.annotation.QueryAnnotationsEvent;
import org.eclipse.che.ide.api.editor.changeintercept.ChangeInterceptorProvider;
import org.eclipse.che.ide.api.editor.changeintercept.TextChange;
import org.eclipse.che.ide.api.editor.changeintercept.TextChangeInterceptor;
import org.eclipse.che.ide.api.editor.codeassist.CodeAssistCallback;
import org.eclipse.che.ide.api.editor.codeassist.CodeAssistProcessor;
import org.eclipse.che.ide.api.editor.codeassist.CodeAssistant;
import org.eclipse.che.ide.api.editor.codeassist.CodeAssistantFactory;
import org.eclipse.che.ide.api.editor.codeassist.CompletionProposal;
import org.eclipse.che.ide.api.editor.codeassist.CompletionReadyCallback;
import org.eclipse.che.ide.api.editor.codeassist.CompletionsSource;
import org.eclipse.che.ide.api.editor.document.DocumentHandle;
import org.eclipse.che.ide.api.editor.editorconfig.TextEditorConfiguration;
import org.eclipse.che.ide.api.editor.events.CompletionRequestEvent;
import org.eclipse.che.ide.api.editor.events.CompletionRequestHandler;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.events.TextChangeEvent;
import org.eclipse.che.ide.api.editor.events.TextChangeHandler;
import org.eclipse.che.ide.api.editor.events.doc.DocReadyWrapper;
import org.eclipse.che.ide.api.editor.events.doc.DocReadyWrapper.DocReadyInit;
import org.eclipse.che.ide.api.editor.keymap.KeyBindingAction;
import org.eclipse.che.ide.api.editor.keymap.KeyBinding;
import org.eclipse.che.ide.api.editor.partition.DocumentPartitioner;
import org.eclipse.che.ide.api.editor.position.PositionConverter;
import org.eclipse.che.ide.api.editor.quickfix.QuickAssistAssistant;
import org.eclipse.che.ide.api.editor.reconciler.Reconciler;
import org.eclipse.che.ide.api.editor.text.TextPosition;
import org.eclipse.che.ide.util.browser.UserAgent;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
/**
* Initialization controller for the text editor.
* Sets-up (when available) the different components that depend on the document being ready.
*/
@Deprecated
public class TextEditorInit<T extends EditorWidget> {
/** The logger. */
private static final Logger LOG = Logger.getLogger(TextEditorInit.class.getName());
private static final String CONTENT_ASSIST = "Content assist";
private static final String QUICK_FIX = "Quick fix";
private final TextEditorConfiguration configuration;
private final EventBus generalEventBus;
private final CodeAssistantFactory codeAssistantFactory;
private final TextEditorPresenter<T> textEditor;
private final QuickAssistAssistant quickAssist;
/**
* The quick assist assistant.
*/
public TextEditorInit(final TextEditorConfiguration configuration,
final EventBus generalEventBus,
final CodeAssistantFactory codeAssistantFactory,
final QuickAssistAssistant quickAssist,
final TextEditorPresenter<T> textEditor) {
this.configuration = configuration;
this.generalEventBus = generalEventBus;
this.codeAssistantFactory = codeAssistantFactory;
this.quickAssist = quickAssist;
this.textEditor = textEditor;
}
/**
* Initialize the text editor.
* Sets itself as {@link DocumentReadyEvent} handler.
*/
public void init() {
final DocReadyInit<TextEditorInit<T>> init = new DocReadyInit<TextEditorInit<T>>() {
@Override
public void initialize(final DocumentHandle documentHandle, final TextEditorInit<T> wrapped) {
configurePartitioner(documentHandle);
configureReconciler(documentHandle);
configureAnnotationModel(documentHandle);
configureCodeAssist(documentHandle);
configureChangeInterceptors(documentHandle);
addQuickAssistKeyBinding();
configureFormatter(textEditor);
}
};
new DocReadyWrapper<TextEditorInit<T>>(generalEventBus, this.textEditor.getEditorHandle(), init, this);
}
private void configureFormatter(TextEditorPresenter<T> textEditor) {
ContentFormatter formatter = configuration.getContentFormatter();
if (formatter != null) {
formatter.install(textEditor);
}
}
public void uninstall() {
Reconciler reconciler = configuration.getReconciler();
if (reconciler != null) {
reconciler.uninstall();
}
}
/**
* Configures the editor's DocumentPartitioner.
* @param documentHandle the handle to the document
*/
private void configurePartitioner(final DocumentHandle documentHandle) {
final DocumentPartitioner partitioner = configuration.getPartitioner();
if (partitioner != null) {
partitioner.setDocumentHandle(documentHandle);
documentHandle.getDocEventBus().addHandler(DocumentChangeEvent.TYPE, partitioner);
partitioner.initialize();
}
}
/**
* Configures the editor's Reconciler.
* @param documentHandle the handle to the document
*/
private void configureReconciler(final DocumentHandle documentHandle) {
final Reconciler reconciler = configuration.getReconciler();
if (reconciler != null) {
reconciler.setDocumentHandle(documentHandle);
documentHandle.getDocEventBus().addHandler(DocumentChangeEvent.TYPE, reconciler);
reconciler.install(textEditor);
}
}
/**
* Configures the editor's annotation model.
* @param documentHandle the handle on the editor
*/
private void configureAnnotationModel(final DocumentHandle documentHandle) {
final AnnotationModel annotationModel = configuration.getAnnotationModel();
if (annotationModel == null) {
return;
}
// add the renderers (event handler) before the model (event source)
if(textEditor instanceof HasAnnotationRendering){
((HasAnnotationRendering)textEditor).configure(annotationModel, documentHandle);
}
annotationModel.setDocumentHandle(documentHandle);
documentHandle.getDocEventBus().addHandler(DocumentChangeEvent.TYPE, annotationModel);
// the model listens to QueryAnnotation events
documentHandle.getDocEventBus().addHandler(QueryAnnotationsEvent.TYPE, annotationModel);
}
/**
* Configure the editor's code assistant.
* @param documentHandle the handle on the document
*/
private void configureCodeAssist(final DocumentHandle documentHandle) {
if (this.codeAssistantFactory == null) {
return;
}
final Map<String, CodeAssistProcessor> processors = configuration.getContentAssistantProcessors();
if (processors != null && !processors.isEmpty()) {
LOG.info("Creating code assistant.");
final CodeAssistant codeAssistant = this.codeAssistantFactory.create(this.textEditor,
this.configuration.getPartitioner());
for (String key: processors.keySet()) {
codeAssistant.setCodeAssistantProcessor(key, processors.get(key));
}
final KeyBindingAction action = new KeyBindingAction() {
@Override
public boolean action() {
showCompletion(codeAssistant, true);
return true;
}
};
final HasKeyBindings hasKeyBindings = this.textEditor.getHasKeybindings();
hasKeyBindings.addKeyBinding(new KeyBinding(true, false, false, false, KeyCode.SPACE, action), CONTENT_ASSIST);
// handle CompletionRequest events that come from text operations instead of simple key binding
documentHandle.getDocEventBus().addHandler(CompletionRequestEvent.TYPE, new CompletionRequestHandler() {
@Override
public void onCompletionRequest(final CompletionRequestEvent event) {
showCompletion(codeAssistant, false);
}
});
} else {
final KeyBindingAction action = new KeyBindingAction() {
@Override
public boolean action() {
showCompletion();
return true;
}
};
final HasKeyBindings hasKeyBindings = this.textEditor.getHasKeybindings();
if(UserAgent.isMac()){
hasKeyBindings.addKeyBinding(new KeyBinding(false, false, false, true, KeyCode.SPACE, action), CONTENT_ASSIST);
hasKeyBindings.addKeyBinding(new KeyBinding(false, false, true, true, KeyCode.SPACE, action), CONTENT_ASSIST);
} else {
hasKeyBindings.addKeyBinding(new KeyBinding(true, false, false, false, KeyCode.SPACE, action), CONTENT_ASSIST);
}
// handle CompletionRequest events that come from text operations instead of simple key binding
documentHandle.getDocEventBus().addHandler(CompletionRequestEvent.TYPE, new CompletionRequestHandler() {
@Override
public void onCompletionRequest(final CompletionRequestEvent event) {
showCompletion();
}
});
}
}
/**
* Show the available completions.
*
* @param codeAssistant the code assistant
* @param triggered if triggered by the content assist key binding
*/
private void showCompletion(final CodeAssistant codeAssistant, final boolean triggered) {
final int cursor = textEditor.getCursorOffset();
if (cursor < 0) {
return;
}
final CodeAssistProcessor processor = codeAssistant.getProcessor(cursor);
if (processor != null) {
this.textEditor.showCompletionProposals(new CompletionsSource() {
@Override
public void computeCompletions(final CompletionReadyCallback callback) {
// cursor must be computed here again so it's original value is not baked in
// the SMI instance closure - important for completion update when typing
final int cursor = textEditor.getCursorOffset();
codeAssistant.computeCompletionProposals(cursor, triggered, new CodeAssistCallback() {
@Override
public void proposalComputed(final List<CompletionProposal> proposals) {
callback.onCompletionReady(proposals);
}
});
}
});
} else {
showCompletion();
}
}
/** Show the available completions. */
private void showCompletion() {
this.textEditor.showCompletionProposals();
}
/**
* Add key binding to quick assist assistant.
*/
private void addQuickAssistKeyBinding() {
if (this.quickAssist != null) {
final KeyBindingAction action = new KeyBindingAction() {
@Override
public boolean action() {
final PositionConverter positionConverter = textEditor.getPositionConverter();
if (positionConverter != null) {
textEditor.showQuickAssist();
}
return true;
}
};
final HasKeyBindings hasKeyBindings = this.textEditor.getHasKeybindings();
hasKeyBindings.addKeyBinding(new KeyBinding(false, false, true, false, KeyCode.ENTER, action), QUICK_FIX);
}
}
private void configureChangeInterceptors(final DocumentHandle documentHandle) {
final ChangeInterceptorProvider interceptors = configuration.getChangeInterceptorProvider();
if (interceptors != null) {
documentHandle.getDocEventBus().addHandler(TextChangeEvent.TYPE, new TextChangeHandler() {
@Override
public void onTextChange(final TextChangeEvent event) {
final TextChange change = event.getChange();
if (change == null) {
return;
}
final TextPosition from = change.getFrom();
if (from == null) {
return;
}
final int startOffset = documentHandle.getDocument().getIndexFromPosition(from);
final TypedRegion region = configuration.getPartitioner().getPartition(startOffset);
if (region == null) {
return;
}
final List<TextChangeInterceptor> filteredInterceptors = interceptors.getInterceptors(region.getType());
if (filteredInterceptors == null || filteredInterceptors.isEmpty()) {
return;
}
// don't apply the interceptors if the range end doesn't belong to the same partition
final TextPosition to = change.getTo();
if (to != null && ! from.equals(to)) {
final int endOffset = documentHandle.getDocument().getIndexFromPosition(to);
if (endOffset < region.getOffset() || endOffset > region.getOffset() + region.getLength()) {
return;
}
}
// stop as soon as one interceptors has modified the content
for (final TextChangeInterceptor interceptor: filteredInterceptors) {
final TextChange result = interceptor.processChange(change,
documentHandle.getDocument().getReadOnlyDocument());
if (result != null) {
event.update(result);
break;
}
}
}
});
}
}
}

View File

@ -15,7 +15,7 @@ package org.eclipse.che.ide.api.editor.texteditor;
* the clients about the ability of the target to perform the specified
* operation at the current point in time.
*
* @author <a href="mailto:evidolob@exoplatform.com">Evgen Vidolob</a>
* @author Evgen Vidolob
* @version $Id:
*/
public interface TextEditorOperations {

View File

@ -18,8 +18,6 @@ import org.eclipse.che.ide.api.editor.EditorWithErrors;
import org.eclipse.che.ide.api.editor.codeassist.CompletionsSource;
import org.eclipse.che.ide.api.editor.keymap.Keymap;
import org.eclipse.che.ide.api.editor.text.TextPosition;
import org.eclipse.che.ide.api.editor.texteditor.EditorWidget;
import org.eclipse.che.ide.api.editor.texteditor.HasNotificationPanel;
/**
* View interface for the text editors components.

View File

@ -1,953 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.api.editor.texteditor;
import com.google.common.base.Optional;
import com.google.gwt.core.client.Callback;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.event.shared.HandlerRegistration;
import org.eclipse.che.api.promises.client.Operation;
import org.eclipse.che.api.promises.client.OperationException;
import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.api.promises.client.callback.CallbackPromiseHelper;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.debug.BreakpointManager;
import org.eclipse.che.ide.api.debug.BreakpointRenderer;
import org.eclipse.che.ide.api.debug.BreakpointRendererFactory;
import org.eclipse.che.ide.api.debug.HasBreakpointRenderer;
import org.eclipse.che.ide.api.dialogs.CancelCallback;
import org.eclipse.che.ide.api.dialogs.ConfirmCallback;
import org.eclipse.che.ide.api.dialogs.DialogFactory;
import org.eclipse.che.ide.api.editor.AbstractEditorPresenter;
import org.eclipse.che.ide.api.editor.EditorAgent.OpenEditorCallback;
import org.eclipse.che.ide.api.editor.EditorInput;
import org.eclipse.che.ide.api.editor.EditorLocalizationConstants;
import org.eclipse.che.ide.api.editor.EditorWithAutoSave;
import org.eclipse.che.ide.api.editor.EditorWithErrors;
import org.eclipse.che.ide.api.editor.codeassist.CodeAssistProcessor;
import org.eclipse.che.ide.api.editor.codeassist.CodeAssistantFactory;
import org.eclipse.che.ide.api.editor.codeassist.CompletionsSource;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.document.DocumentStorage;
import org.eclipse.che.ide.api.editor.document.DocumentStorage.DocumentCallback;
import org.eclipse.che.ide.api.editor.editorconfig.EditorUpdateAction;
import org.eclipse.che.ide.api.editor.editorconfig.TextEditorConfiguration;
import org.eclipse.che.ide.api.editor.events.CompletionRequestEvent;
import org.eclipse.che.ide.api.editor.events.DocumentReadyEvent;
import org.eclipse.che.ide.api.editor.events.GutterClickEvent;
import org.eclipse.che.ide.api.editor.events.GutterClickHandler;
import org.eclipse.che.ide.api.editor.filetype.FileTypeIdentifier;
import org.eclipse.che.ide.api.editor.formatter.ContentFormatter;
import org.eclipse.che.ide.api.editor.gutter.Gutters;
import org.eclipse.che.ide.api.editor.gutter.HasGutter;
import org.eclipse.che.ide.api.editor.keymap.KeyBinding;
import org.eclipse.che.ide.api.editor.keymap.KeyBindingAction;
import org.eclipse.che.ide.api.editor.position.PositionConverter;
import org.eclipse.che.ide.api.editor.quickfix.QuickAssistAssistant;
import org.eclipse.che.ide.api.editor.quickfix.QuickAssistProcessor;
import org.eclipse.che.ide.api.editor.quickfix.QuickAssistantFactory;
import org.eclipse.che.ide.api.editor.reconciler.Reconciler;
import org.eclipse.che.ide.api.editor.reconciler.ReconcilerWithAutoSave;
import org.eclipse.che.ide.api.editor.text.LinearRange;
import org.eclipse.che.ide.api.editor.text.TextPosition;
import org.eclipse.che.ide.api.editor.text.TextRange;
import org.eclipse.che.ide.api.editor.texteditor.EditorWidget.WidgetInitializedCallback;
import org.eclipse.che.ide.api.editor.texteditor.TextEditorPartView.Delegate;
import org.eclipse.che.ide.api.event.FileContentUpdateEvent;
import org.eclipse.che.ide.api.event.FileContentUpdateHandler;
import org.eclipse.che.ide.api.hotkeys.HasHotKeyItems;
import org.eclipse.che.ide.api.hotkeys.HotKeyItem;
import org.eclipse.che.ide.api.notification.NotificationManager;
import org.eclipse.che.ide.api.parts.WorkspaceAgent;
import org.eclipse.che.ide.api.resources.File;
import org.eclipse.che.ide.api.resources.Resource;
import org.eclipse.che.ide.api.resources.ResourceChangedEvent;
import org.eclipse.che.ide.api.resources.ResourceDelta;
import org.eclipse.che.ide.api.resources.VirtualFile;
import org.eclipse.che.ide.api.selection.Selection;
import org.eclipse.che.ide.resource.Path;
import org.eclipse.che.ide.ui.loaders.request.LoaderFactory;
import org.vectomatic.dom.svg.ui.SVGResource;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.NOT_EMERGE_MODE;
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL;
import static org.eclipse.che.ide.api.resources.ResourceDelta.ADDED;
import static org.eclipse.che.ide.api.resources.ResourceDelta.DERIVED;
import static org.eclipse.che.ide.api.resources.ResourceDelta.MOVED_FROM;
import static org.eclipse.che.ide.api.resources.ResourceDelta.MOVED_TO;
import static org.eclipse.che.ide.api.resources.ResourceDelta.REMOVED;
import static org.eclipse.che.ide.api.resources.ResourceDelta.UPDATED;
/**
* Presenter part for the editor implementations.
*
* @deprecated use {@link TextEditor} instead
*/
@Deprecated
public class TextEditorPresenter<T extends EditorWidget> extends AbstractEditorPresenter implements TextEditor,
UndoableEditor,
HasBreakpointRenderer,
HasReadOnlyProperty,
HandlesTextOperations,
EditorWithAutoSave,
EditorWithErrors,
HasHotKeyItems,
Delegate {
/** File type used when we have no idea of the actual content type. */
public static final String DEFAULT_CONTENT_TYPE = "text/plain";
private static final String TOGGLE_LINE_BREAKPOINT = "Toggle line breakpoint";
private final CodeAssistantFactory codeAssistantFactory;
private final BreakpointManager breakpointManager;
private final BreakpointRendererFactory breakpointRendererFactory;
private final DialogFactory dialogFactory;
private final DocumentStorage documentStorage;
private final EditorLocalizationConstants constant;
private final EditorWidgetFactory<T> editorWidgetFactory;
private final EditorModule editorModule;
private final TextEditorPartView editorView;
private final EventBus generalEventBus;
private final FileTypeIdentifier fileTypeIdentifier;
private final QuickAssistantFactory quickAssistantFactory;
private final WorkspaceAgent workspaceAgent;
private final NotificationManager notificationManager;
private final AppContext appContext;
/** The editor handle for this editor. */
private final EditorHandle handle;
private HasKeyBindings keyBindingsManager;
private List<EditorUpdateAction> updateActions;
private TextEditorConfiguration configuration;
private EditorWidget editorWidget;
private Document document;
private CursorModelWithHandler cursorModel;
private QuickAssistAssistant quickAssistant;
private LoaderFactory loaderFactory;
/** The editor's error state. */
private EditorState errorState;
private boolean delayedFocus;
private boolean isFocused;
private BreakpointRenderer breakpointRenderer;
private List<String> fileTypes;
private TextPosition cursorPosition;
private HandlerRegistration resourceChangeHandler;
private TextEditorInit<T> editorInit;
@AssistedInject
public TextEditorPresenter(final CodeAssistantFactory codeAssistantFactory,
final BreakpointManager breakpointManager,
final BreakpointRendererFactory breakpointRendererFactory,
final DialogFactory dialogFactory,
final DocumentStorage documentStorage,
final EditorLocalizationConstants constant,
@Assisted final EditorWidgetFactory<T> editorWidgetFactory,
final EditorModule editorModule,
final TextEditorPartView editorView,
final EventBus eventBus,
final FileTypeIdentifier fileTypeIdentifier,
final QuickAssistantFactory quickAssistantFactory,
final WorkspaceAgent workspaceAgent,
final NotificationManager notificationManager,
final AppContext appContext
) {
this.codeAssistantFactory = codeAssistantFactory;
this.breakpointManager = breakpointManager;
this.breakpointRendererFactory = breakpointRendererFactory;
this.dialogFactory = dialogFactory;
this.documentStorage = documentStorage;
this.constant = constant;
this.editorWidgetFactory = editorWidgetFactory;
this.editorModule = editorModule;
this.editorView = editorView;
this.generalEventBus = eventBus;
this.fileTypeIdentifier = fileTypeIdentifier;
this.quickAssistantFactory = quickAssistantFactory;
this.workspaceAgent = workspaceAgent;
this.notificationManager = notificationManager;
this.appContext = appContext;
keyBindingsManager = new TemporaryKeyBindingsManager();
handle = new EditorHandle() {
};
this.editorView.setDelegate(this);
}
@Override
protected void initializeEditor(final OpenEditorCallback callback) {
QuickAssistProcessor processor = configuration.getQuickAssistProcessor();
if (quickAssistantFactory != null && processor != null) {
quickAssistant = quickAssistantFactory.createQuickAssistant(this);
quickAssistant.setQuickAssistProcessor(processor);
}
Promise<Document> documentPromice = CallbackPromiseHelper.createFromCallback(new CallbackPromiseHelper.Call<Document, Throwable>() {
@Override
public void makeCall(Callback<Document, Throwable> callback) {
}
});
editorInit = new TextEditorInit<>(configuration,
generalEventBus,
this.codeAssistantFactory,
this.quickAssistant,
this);
editorInit.init();
if (editorModule.isError()) {
displayErrorPanel(constant.editorInitErrorMessage());
return;
}
final boolean moduleReady = editorModule.isReady();
EditorInitCallback<T> dualCallback = new EditorInitCallback<T>(moduleReady, loaderFactory, constant) {
@Override
public void onReady(final String content) {
createEditor(content);
}
@Override
public void onError() {
displayErrorPanel(constant.editorInitErrorMessage());
callback.onInitializationFailed();
}
@Override
public void onFileError() {
displayErrorPanel(constant.editorFileErrorMessage());
callback.onInitializationFailed();
}
};
documentStorage.getDocument(input.getFile(), dualCallback);
if (!moduleReady) {
editorModule.waitReady(dualCallback);
}
}
/**
* Show the quick assist assistant.
*/
public void showQuickAssist() {
if (quickAssistant == null) {
return;
}
PositionConverter positionConverter = getPositionConverter();
if (positionConverter != null) {
TextPosition cursor = getCursorPosition();
PositionConverter.PixelCoordinates pixelPos = positionConverter.textToPixel(cursor);
quickAssistant.showPossibleQuickAssists(getCursorModel().getCursorPosition().getOffset(),
pixelPos.getX(),
pixelPos.getY());
}
}
private void createEditor(final String content) {
this.fileTypes = detectFileType(getEditorInput().getFile());
editorWidgetFactory.createEditorWidget(fileTypes, new EditorWidgetInitializedCallback(content));
}
private void setupEventHandlers() {
this.editorWidget.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(final ChangeEvent event) {
handleDocumentChanged();
}
});
this.editorWidget.addGutterClickHandler(new GutterClickHandler() {
@Override
public void onGutterClick(final GutterClickEvent event) {
if (Gutters.BREAKPOINTS_GUTTER.equals(event.getGutterId())
|| Gutters.LINE_NUMBERS_GUTTER.equals(event.getGutterId())) {
breakpointManager.changeBreakpointState(event.getLineNumber());
}
}
});
this.editorWidget.addKeyBinding(new KeyBinding(true, false, false, false, KeyCodes.KEY_F8, new KeyBindingAction() {
@Override
public boolean action() {
int currentLine = editorWidget.getDocument().getCursorPosition().getLine();
breakpointManager.changeBreakpointState(currentLine);
return true;
}
}), TOGGLE_LINE_BREAKPOINT);
}
private void setupFileContentUpdateHandler() {
resourceChangeHandler =
generalEventBus.addHandler(ResourceChangedEvent.getType(), new ResourceChangedEvent.ResourceChangedHandler() {
@Override
public void onResourceChanged(ResourceChangedEvent event) {
final ResourceDelta delta = event.getDelta();
switch (delta.getKind()) {
case ADDED:
onResourceCreated(delta);
break;
case REMOVED:
onResourceRemoved(delta);
break;
case UPDATED:
onResourceUpdated(delta);
}
}
});
this.generalEventBus.addHandler(FileContentUpdateEvent.TYPE, new FileContentUpdateHandler() {
@Override
public void onFileContentUpdate(final FileContentUpdateEvent event) {
if (event.getFilePath() != null && Path.valueOf(event.getFilePath()).equals(document.getFile().getLocation())) {
updateContent();
}
}
});
}
private void onResourceCreated(ResourceDelta delta) {
if ((delta.getFlags() & (MOVED_FROM | MOVED_TO)) == 0) {
return;
}
//file moved directly
if (delta.getFromPath().equals(document.getFile().getLocation())) {
final Resource resource = delta.getResource();
final Path movedFrom = delta.getFromPath();
if (document.getFile().getLocation().equals(movedFrom)) {
document.setFile((File)resource);
input.setFile((File)resource);
}
updateContent();
} else if (delta.getFromPath().isPrefixOf(document.getFile().getLocation())) { //directory where file moved
final Path relPath = document.getFile().getLocation().removeFirstSegments(delta.getFromPath().segmentCount());
final Path newPath = delta.getToPath().append(relPath);
appContext.getWorkspaceRoot().getFile(newPath).then(new Operation<Optional<File>>() {
@Override
public void apply(Optional<File> file) throws OperationException {
if (file.isPresent()) {
document.setFile(file.get());
input.setFile(file.get());
updateContent();
}
}
});
}
}
private void onResourceRemoved(ResourceDelta delta) {
if ((delta.getFlags() & DERIVED) == 0) {
return;
}
final Resource resource = delta.getResource();
if (resource.isFile() && document.getFile().getLocation().equals(resource.getLocation())) {
handleClose();
}
}
private void onResourceUpdated(ResourceDelta delta) {
if ((delta.getFlags() & DERIVED) == 0) {
return;
}
final Resource resource = delta.getResource();
if (resource.isFile() && document.getFile().getLocation().equals(resource.getLocation())) {
updateContent();
}
}
private void updateContent() {
/* -save current cursor and (ideally) viewport
* -set editor content which is also expected to
* -reset dirty flag
* -clear history
* -restore current cursor position
*/
final TextPosition currentCursor = getCursorPosition();
this.documentStorage.getDocument(document.getFile(), new DocumentCallback() {
@Override
public void onDocumentReceived(final String content) {
editorWidget.setValue(content, new ContentInitializedHandler() {
@Override
public void onContentInitialized() {
document.setCursorPosition(currentCursor);
}
});
}
@Override
public void onDocumentLoadFailure(final Throwable caught) {
displayErrorPanel(constant.editorFileErrorMessage());
}
});
}
private void displayErrorPanel(final String message) {
this.editorView.showPlaceHolder(new Label(message));
}
private void handleDocumentChanged() {
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
updateDirtyState(editorWidget.isDirty());
}
});
}
@Override
public void storeState() {
cursorPosition = getCursorPosition();
}
@Override
public void restoreState() {
if (cursorPosition != null) {
setFocus();
getDocument().setCursorPosition(cursorPosition);
}
}
@Override
public void close(final boolean save) {
this.documentStorage.documentClosed(this.document);
editorInit.uninstall();
workspaceAgent.removePart(this);
}
@Inject
public void injectAsyncLoader(final LoaderFactory loaderFactory) {
this.loaderFactory = loaderFactory;
}
@Override
public boolean isEditable() {
return false;
}
@Override
public void doRevertToSaved() {
// do nothing
}
@NotNull
protected Widget getWidget() {
return this.editorView.asWidget();
}
@Override
public void go(final AcceptsOneWidget container) {
container.setWidget(getWidget());
}
@Override
public String getTitleToolTip() {
return null;
}
@Override
public void onClose(@NotNull final AsyncCallback<Void> callback) {
if (isDirty()) {
dialogFactory.createConfirmDialog(
constant.askWindowCloseTitle(),
constant.askWindowSaveChangesMessage(getEditorInput().getName()),
new ConfirmCallback() {
@Override
public void accepted() {
doSave();
handleClose();
callback.onSuccess(null);
}
},
new CancelCallback() {
@Override
public void cancelled() {
handleClose();
callback.onSuccess(null);
}
}).show();
} else {
handleClose();
callback.onSuccess(null);
}
}
@Override
protected void handleClose() {
if (resourceChangeHandler != null) {
resourceChangeHandler.removeHandler();
resourceChangeHandler = null;
}
super.handleClose();
}
@Override
public TextEditorPartView getView() {
return this.editorView;
}
@Override
public void activate() {
if (editorWidget != null) {
editorWidget.refresh();
editorWidget.setFocus();
setSelection(new Selection<>(input.getFile()));
} else {
this.delayedFocus = true;
}
}
@Override
public void initialize(@NotNull final TextEditorConfiguration configuration) {
this.configuration = configuration;
}
@Override
public TextEditorConfiguration getConfiguration() {
return configuration;
}
@Override
public SVGResource getTitleImage() {
return input.getSVGResource();
}
@NotNull
@Override
public String getTitle() {
return input.getFile().getDisplayName();
}
@Override
public void doSave() {
doSave(new AsyncCallback<EditorInput>() {
@Override
public void onSuccess(final EditorInput result) {
// do nothing
}
@Override
public void onFailure(final Throwable caught) {
// do nothing
}
});
}
@Override
public void doSave(final AsyncCallback<EditorInput> callback) {
this.documentStorage.saveDocument(getEditorInput(), this.document, false, new AsyncCallback<EditorInput>() {
@Override
public void onSuccess(EditorInput editorInput) {
updateDirtyState(false);
editorWidget.markClean();
afterSave();
if (callback != null) {
callback.onSuccess(editorInput);
}
}
@Override
public void onFailure(Throwable caught) {
notificationManager.notify(constant.failedToUpdateContentOfFiles(), caught.getMessage(), FAIL, NOT_EMERGE_MODE);
if (callback != null) {
callback.onFailure(caught);
}
}
});
}
/** Override this method for handling after save actions. */
protected void afterSave() {
}
@Override
public void doSaveAs() {
}
@Override
public HandlesUndoRedo getUndoRedo() {
if (this.editorWidget != null) {
return this.editorWidget.getUndoRedo();
} else {
return null;
}
}
@Override
public EditorState getErrorState() {
return this.errorState;
}
@Override
public void setErrorState(final EditorState errorState) {
this.errorState = errorState;
firePropertyChange(ERROR_STATE);
}
@Override
public BreakpointRenderer getBreakpointRenderer() {
if (this.breakpointRenderer == null && this.editorWidget != null && this instanceof HasGutter) {
this.breakpointRenderer = this.breakpointRendererFactory.create(((HasGutter)this).getGutter(),
this.editorWidget.getLineStyler(),
this.document);
}
return this.breakpointRenderer;
}
@Override
public Document getDocument() {
return this.document;
}
@Override
public String getContentType() {
// Before the editor content is ready, the content type is not defined
if (this.fileTypes == null || this.fileTypes.isEmpty()) {
return null;
} else {
return this.fileTypes.get(0);
}
}
@Override
public TextRange getSelectedTextRange() {
return getDocument().getSelectedTextRange();
}
@Override
public LinearRange getSelectedLinearRange() {
return getDocument().getSelectedLinearRange();
}
@Override
public void showMessage(final String message) {
this.editorWidget.showMessage(message);
}
@Override
public TextPosition getCursorPosition() {
return getDocument().getCursorPosition();
}
@Override
public int getCursorOffset() {
final TextPosition textPosition = getDocument().getCursorPosition();
return getDocument().getIndexFromPosition(textPosition);
}
@Override
public int getTopVisibleLine() {
throw new UnsupportedOperationException("getTopVisibleLine is not supported");
}
@Override
public void setTopLine(int line) {
throw new UnsupportedOperationException("setTopLine(int line) is not supported");
}
@Override
public void refreshEditor() {
if (this.updateActions != null) {
for (final EditorUpdateAction action : this.updateActions) {
action.doRefresh();
}
}
}
@Override
public void addEditorUpdateAction(final EditorUpdateAction action) {
if (action == null) {
return;
}
if (this.updateActions == null) {
this.updateActions = new ArrayList<>();
}
this.updateActions.add(action);
}
@Override
public void addKeybinding(final KeyBinding keyBinding) {
// the actual HasKeyBindings object can change, so use indirection
getHasKeybindings().addKeyBinding(keyBinding);
}
private List<String> detectFileType(final VirtualFile file) {
final List<String> result = new ArrayList<>();
if (file != null) {
// use the identification patterns
final List<String> types = this.fileTypeIdentifier.identifyType(file);
if (types != null && !types.isEmpty()) {
result.addAll(types);
}
}
// ultimate fallback - can't make more generic for text
result.add(DEFAULT_CONTENT_TYPE);
return result;
}
public HasTextMarkers getHasTextMarkers() {
if (this.editorWidget != null) {
return this.editorWidget;
} else {
return null;
}
}
public HasKeyBindings getHasKeybindings() {
return this.keyBindingsManager;
}
@Override
public CursorModelWithHandler getCursorModel() {
return this.cursorModel;
}
@Override
public PositionConverter getPositionConverter() {
return this.editorWidget.getPositionConverter();
}
public void showCompletionProposals(final CompletionsSource source) {
this.editorView.showCompletionProposals(this.editorWidget, source);
}
public boolean isCompletionProposalsShowing() {
return editorWidget.isCompletionProposalsShowing();
}
public void showCompletionProposals() {
this.editorView.showCompletionProposals(this.editorWidget);
}
public EditorHandle getEditorHandle() {
return this.handle;
}
private void switchHasKeybinding() {
final HasKeyBindings current = getHasKeybindings();
if (!(current instanceof TemporaryKeyBindingsManager)) {
return;
}
// change the key binding instance and add all bindings to the new one
this.keyBindingsManager = this.editorWidget;
final List<KeyBinding> bindings = ((TemporaryKeyBindingsManager)current).getbindings();
for (final KeyBinding binding : bindings) {
this.keyBindingsManager.addKeyBinding(binding);
}
}
@Override
public List<HotKeyItem> getHotKeys() {
return editorWidget.getHotKeys();
}
@Override
public void onResize() {
if (this.editorWidget != null) {
this.editorWidget.onResize();
}
}
@Override
public void editorLostFocus() {
this.editorView.updateInfoPanelUnfocused(this.document.getLineCount());
this.isFocused = false;
}
@Override
public void editorGotFocus() {
this.isFocused = true;
this.editorView.updateInfoPanelPosition(this.document.getCursorPosition());
}
@Override
public void editorCursorPositionChanged() {
this.editorView.updateInfoPanelPosition(this.document.getCursorPosition());
}
@Override
public boolean canDoOperation(final int operation) {
if (TextEditorOperations.CODEASSIST_PROPOSALS == operation) {
Map<String, CodeAssistProcessor> contentAssistProcessors = getConfiguration().getContentAssistantProcessors();
if (contentAssistProcessors != null && !contentAssistProcessors.isEmpty()) {
return true;
}
}
if (TextEditorOperations.FORMAT == operation) {
if (getConfiguration().getContentFormatter() != null) {
return true;
}
}
return false;
}
@Override
public void doOperation(final int operation) {
switch (operation) {
case TextEditorOperations.CODEASSIST_PROPOSALS:
if (this.document != null) {
this.document.getDocumentHandle().getDocEventBus().fireEvent(new CompletionRequestEvent());
}
break;
case TextEditorOperations.FORMAT:
ContentFormatter formatter = getConfiguration().getContentFormatter();
if (this.document != null && formatter != null) {
formatter.format(getDocument());
}
break;
default:
throw new UnsupportedOperationException("Operation code: " + operation + " is not supported!");
}
}
@Override
public boolean isReadOnly() {
return this.editorWidget.isReadOnly();
}
@Override
public void setReadOnly(final boolean readOnly) {
this.editorWidget.setReadOnly(readOnly);
}
@Override
public EditorWidget getEditorWidget() {
return this.editorWidget;
}
@Override
public boolean isFocused() {
return this.isFocused;
}
@Override
public void setFocus() {
editorWidget.setFocus();
}
@Override
public boolean isAutoSaveEnabled() {
ReconcilerWithAutoSave autoSave = getAutoSave();
return autoSave != null && autoSave.isAutoSaveEnabled();
}
private ReconcilerWithAutoSave getAutoSave() {
Reconciler reconciler = getConfiguration().getReconciler();
if (reconciler != null && reconciler instanceof ReconcilerWithAutoSave) {
return ((ReconcilerWithAutoSave)reconciler);
}
return null;
}
@Override
public void enableAutoSave() {
ReconcilerWithAutoSave autoSave = getAutoSave();
if (autoSave != null) {
autoSave.enableAutoSave();
}
}
@Override
public void disableAutoSave() {
ReconcilerWithAutoSave autoSave = getAutoSave();
if (autoSave != null) {
autoSave.disableAutoSave();
}
}
private class EditorWidgetInitializedCallback implements WidgetInitializedCallback {
private final String content;
private boolean isInitialized;
private EditorWidgetInitializedCallback(String content) {
this.content = content;
}
@Override
public void initialized(EditorWidget widget) {
editorWidget = widget;
// finish editor initialization
editorView.setEditorWidget(editorWidget);
document = editorWidget.getDocument();
document.setFile(input.getFile());
cursorModel = new TextEditorCursorModel(document);
editorWidget.setTabSize(configuration.getTabWidth());
// initialize info panel
editorView.initInfoPanel(editorWidget.getMode(),
editorWidget.getKeymap(),
document.getLineCount(),
configuration.getTabWidth());
//TODO: delayed activation
// handle delayed focus (initialization editor widget)
// should also check if I am visible, but how ?
if (delayedFocus) {
editorWidget.refresh();
editorWidget.setFocus();
setSelection(new Selection<>(input.getFile()));
delayedFocus = false;
}
// delayed keybindings creation ?
switchHasKeybinding();
editorWidget.setValue(content, new ContentInitializedHandler() {
@Override
public void onContentInitialized() {
if (isInitialized) {
return;
}
generalEventBus.fireEvent(new DocumentReadyEvent(document));
firePropertyChange(PROP_INPUT);
setupEventHandlers();
setupFileContentUpdateHandler();
isInitialized = true;
}
});
}
}
}

View File

@ -1,30 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.api.editor.texteditor;
/**
* Factory for {@link TextEditorPresenter} objects.
*
* @param <T>
* the type of the editor
*/
@Deprecated
public interface TextEditorPresenterFactory<T extends EditorWidget> {
/**
* Create an instance of {@link TextEditorPresenter}.
*
* @param editorWidgetFactory
* the {@link EditorWidget} factory tu use
* @return a new {@link TextEditorPresenter}
*/
TextEditorPresenter<T> createTextEditor(EditorWidgetFactory<T> editorWidgetFactory);
}

View File

@ -1,224 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.api.editor.texteditor;
import com.google.gwt.core.client.Scheduler;
import com.google.gwtmockito.GwtMockitoTestRunner;
import com.google.web.bindery.event.shared.EventBus;
import org.eclipse.che.ide.api.editor.EditorAgent;
import org.eclipse.che.ide.api.editor.EditorInitException;
import org.eclipse.che.ide.api.editor.EditorInput;
import org.eclipse.che.ide.api.editor.EditorLocalizationConstants;
import org.eclipse.che.ide.api.editor.codeassist.CodeAssistProcessor;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.document.DocumentStorage;
import org.eclipse.che.ide.api.editor.editorconfig.TextEditorConfiguration;
import org.eclipse.che.ide.api.editor.formatter.ContentFormatter;
import org.eclipse.che.ide.api.editor.quickfix.QuickAssistantFactory;
import org.eclipse.che.ide.api.editor.texteditor.EditorWidget.WidgetInitializedCallback;
import org.eclipse.che.ide.api.resources.VirtualFile;
import org.eclipse.che.ide.ui.loaders.request.LoaderFactory;
import org.eclipse.che.ide.ui.loaders.request.MessageLoader;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Matchers;
import org.mockito.Mock;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
/**
* @author Andrienko Alexander
*/
@RunWith(GwtMockitoTestRunner.class)
public class TextEditorPresenterTest {
@Mock
private DocumentStorage documentStorage;
@Mock
private EditorLocalizationConstants constant;
@Mock
private EditorWidgetFactory<EditorWidget> editorWidgetFactory;
@Mock
private EditorModule editorModule;
@Mock
private TextEditorPartView editorView;
@Mock
private EventBus eventBus;
@Mock
private QuickAssistantFactory quickAssistantFactory;
@Mock
private EditorInput editorInput;
@Mock
private EditorWidget editorWidget;
@Mock
private Document document;
@Mock
private TextEditorConfiguration configuration;
@Mock
private LoaderFactory loaderFactory;
@Mock
private MessageLoader loader;
@Mock
private ContentFormatter contentFormatter;
@Mock
private Map<String, CodeAssistProcessor> codeAssistProcessors;
@InjectMocks
private TextEditorPresenter<EditorWidget> textEditorPresenter;
@Test
public void activateEditorIfEditorWidgetNotNull() throws EditorInitException {
initializeAndInitEditor();
textEditorPresenter.activate();
verify(editorWidget).refresh();
verify(editorWidget).setFocus();
}
@Test
public void activateEditorIfEditorWidgetNull() throws Exception {
reset(editorView, eventBus);
textEditorPresenter.activate();
Field delayedFocus = TextEditorPresenter.class.getDeclaredField("delayedFocus");
delayedFocus.setAccessible(true);
boolean fieldValue = (boolean)delayedFocus.get(textEditorPresenter);
assertTrue(fieldValue);
}
@Test
public void shouldFormatOperation() throws EditorInitException {
doReturn(contentFormatter).when(configuration).getContentFormatter();
initializeAndInitEditor();
textEditorPresenter.doOperation(TextEditorOperations.FORMAT);
verify(contentFormatter).format(document);
}
@Test
public void shouldFormatOperationWhenDocumentAndFormatterAreNull() throws EditorInitException {
textEditorPresenter.initialize(configuration);
textEditorPresenter.doOperation(TextEditorOperations.FORMAT);
verify(contentFormatter, never()).format(document);
}
@Test
public void shouldFormatOperationWhenFormatterIsNotNullButDocumentIsNull() throws EditorInitException {
doReturn(contentFormatter).when(configuration).getContentFormatter();
textEditorPresenter.initialize(configuration);
textEditorPresenter.doOperation(TextEditorOperations.FORMAT);
verify(contentFormatter, never()).format(document);
}
@Test
public void shouldFormatOperationWhenDocumentIsNotNullButFormatterIsNull() throws EditorInitException {
doReturn(null).when(configuration).getContentFormatter();
initializeAndInitEditor();
textEditorPresenter.doOperation(TextEditorOperations.FORMAT);
verify(contentFormatter, never()).format(document);
}
@Test
public void shouldCanDoOperationCodeAssistProposal() throws EditorInitException {
doReturn(codeAssistProcessors).when(configuration).getContentAssistantProcessors();
doReturn(false).when(codeAssistProcessors).isEmpty();
initializeAndInitEditor();
assertTrue(textEditorPresenter.canDoOperation(TextEditorOperations.CODEASSIST_PROPOSALS));
}
@Test
public void shouldNOtCanDoOperationCodeAssistProposalBecauseProcessorsDontExistInMap() throws EditorInitException {
doReturn(codeAssistProcessors).when(configuration).getContentAssistantProcessors();
doReturn(true).when(codeAssistProcessors).isEmpty();
initializeAndInitEditor();
assertFalse(textEditorPresenter.canDoOperation(TextEditorOperations.CODEASSIST_PROPOSALS));
}
@Test
public void shouldNOtCanDoOperationCodeAssistProposalBecauseMapOfProcessorsIsNull() throws EditorInitException {
doReturn(null).when(configuration).getContentAssistantProcessors();
initializeAndInitEditor();
assertFalse(textEditorPresenter.canDoOperation(TextEditorOperations.CODEASSIST_PROPOSALS));
}
@Test
public void shouldCanDoOperationFormat() throws EditorInitException {
doReturn(contentFormatter).when(configuration).getContentFormatter();
initializeAndInitEditor();
assertTrue(textEditorPresenter.canDoOperation(TextEditorOperations.FORMAT));
}
@Test
public void shouldNotCanDoOperationFormat() throws EditorInitException {
doReturn(null).when(configuration).getContentFormatter();
initializeAndInitEditor();
assertFalse(textEditorPresenter.canDoOperation(TextEditorOperations.FORMAT));
}
/**
* This method initialize TextEditorPresenter for testing
* @throws EditorInitException
*/
public void initializeAndInitEditor() throws EditorInitException {
reset(Scheduler.get());
ArgumentCaptor<EditorInitCallback> callBackCaptor = ArgumentCaptor.forClass(EditorInitCallback.class);
ArgumentCaptor<WidgetInitializedCallback> widgetInitializedCallbackCaptor =
ArgumentCaptor.forClass(WidgetInitializedCallback.class);
final EditorAgent.OpenEditorCallback editorCallback = mock(EditorAgent.OpenEditorCallback.class);
doReturn(loader).when(loaderFactory).newLoader();
doReturn(editorWidget).when(editorWidgetFactory).createEditorWidget(Matchers.<List<String>>anyObject(),
Matchers.<WidgetInitializedCallback>anyObject());
doReturn(document).when(editorWidget).getDocument();
textEditorPresenter.injectAsyncLoader(loaderFactory);
textEditorPresenter.initialize(configuration);
textEditorPresenter.init(editorInput, editorCallback);
verify(documentStorage).getDocument(any(VirtualFile.class), callBackCaptor.capture());
EditorInitCallback editorInitCallBack = callBackCaptor.getValue();
editorInitCallBack.onReady("test");
verify(editorWidgetFactory).createEditorWidget(anyListOf(String.class), widgetInitializedCallbackCaptor.capture());
WidgetInitializedCallback callback = widgetInitializedCallbackCaptor.getValue();
callback.initialized(editorWidget);
}
}

View File

@ -11,7 +11,6 @@
package org.eclipse.che.ide.ext.java.client.editor;
import org.eclipse.che.ide.api.editor.partition.DocumentPositionMap;
import org.eclipse.che.ide.api.editor.texteditor.EditorHandle;
/**
* Factory for {@link JavaAnnotationModel} instances.
@ -20,7 +19,6 @@ public interface JavaAnnotationModelFactory {
/**
* Builds an instance of {@link JavaAnnotationModel}.
*
* @param editorHandle an {@link EditorHandle}
* @param docPositionMap a doc position map model
* @return a java annotation model
*/

View File

@ -14,9 +14,9 @@ import com.google.gwtmockito.GwtMockitoTestRunner;
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.editor.EditorAgent;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
import org.eclipse.che.ide.ext.java.client.JavaLocalizationConstant;
import org.eclipse.che.ide.ext.java.client.organizeimports.OrganizeImportsPresenter;
import org.eclipse.che.ide.api.editor.texteditor.TextEditorPresenter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -42,7 +42,7 @@ public class OrganizeImportsActionTest {
private ActionEvent actionEvent;
@Mock
private TextEditorPresenter editor;
private TextEditor editor;
@Mock(answer = Answers.RETURNS_MOCKS)
private JavaLocalizationConstant locale;
@ -73,5 +73,4 @@ public class OrganizeImportsActionTest {
verify(organizeImportsPresenter).organizeImports(editor);
}
}
}

View File

@ -17,7 +17,7 @@ import com.google.web.bindery.event.shared.HandlerRegistration;
import org.eclipse.che.ide.api.editor.EditorInput;
import org.eclipse.che.ide.api.editor.annotation.AnnotationModel;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.texteditor.TextEditorPresenter;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
import org.eclipse.che.ide.api.resources.Container;
import org.eclipse.che.ide.api.resources.File;
import org.eclipse.che.ide.api.resources.Project;
@ -61,7 +61,7 @@ public class JavaReconcilerStrategyTest {
@Mock
private EventBus eventBus;
@Mock
private TextEditorPresenter<?> editor;
private TextEditor editor;
@Mock
private JavaCodeAssistProcessor codeAssistProcessor;
@Mock

View File

@ -17,9 +17,12 @@ import org.eclipse.che.api.promises.client.Operation;
import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.api.promises.client.PromiseError;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.data.tree.Node;
import org.eclipse.che.ide.api.editor.EditorAgent;
import org.eclipse.che.ide.api.editor.EditorInput;
import org.eclipse.che.ide.api.data.tree.Node;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.text.LinearRange;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
import org.eclipse.che.ide.api.resources.Container;
import org.eclipse.che.ide.api.resources.File;
import org.eclipse.che.ide.api.resources.Project;
@ -30,9 +33,6 @@ import org.eclipse.che.ide.ext.java.shared.dto.Region;
import org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit;
import org.eclipse.che.ide.ext.java.shared.dto.model.Member;
import org.eclipse.che.ide.resource.Path;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.text.LinearRange;
import org.eclipse.che.ide.api.editor.texteditor.TextEditorPresenter;
import org.eclipse.che.ide.ui.loaders.request.LoaderFactory;
import org.eclipse.che.ide.ui.loaders.request.MessageLoader;
import org.junit.Before;
@ -70,29 +70,29 @@ public class FileStructurePresenterTest {
private LoaderFactory loaderFactory;
@Mock
private TextEditorPresenter editorPartPresenter;
private TextEditor editor;
@Mock
private EditorInput editorInput;
@Mock
private File file;
private File file;
@Mock
private Project relatedProject;
private Project relatedProject;
@Mock
private Container srcFolder;
private Container srcFolder;
@Mock
private Promise<CompilationUnit> promise;
private Promise<CompilationUnit> promise;
@Mock
private Promise<Node> nodePromise;
@Mock
private CompilationUnit compilationUnit;
@Mock
private Member member;
private Member member;
@Mock
private Node node;
private Node node;
@Mock
private Region region;
private Region region;
@Mock
private Document document;
private Document document;
@Captor
private ArgumentCaptor<Operation<CompilationUnit>> operationSuccessCapture;
@ -110,10 +110,10 @@ public class FileStructurePresenterTest {
@Before
public void setUp() throws Exception {
when(editorPartPresenter.getEditorInput()).thenReturn(editorInput);
when(editorPartPresenter.getDocument()).thenReturn(document);
when(editor.getEditorInput()).thenReturn(editorInput);
when(editor.getDocument()).thenReturn(document);
when(editorInput.getFile()).thenReturn(file);
when(editorPartPresenter.getCursorOffset()).thenReturn(0);
when(editor.getCursorOffset()).thenReturn(0);
when(file.getRelatedProject()).thenReturn(Optional.of(relatedProject));
when(file.getParentWithMarker(eq(SourceFolderMarker.ID))).thenReturn(Optional.of(srcFolder));
when(file.getName()).thenReturn("A.java");
@ -137,7 +137,7 @@ public class FileStructurePresenterTest {
@Test
public void fileStructureShouldBeShow() throws Exception {
presenter.show(editorPartPresenter);
presenter.show(editor);
verify(loader).show();
verify(view).setTitle("A.java");
@ -152,7 +152,7 @@ public class FileStructurePresenterTest {
@Test
public void loaderShouldBeHideIfSomethingIsWrong() throws Exception {
PromiseError promiseError = Mockito.mock(PromiseError.class);
presenter.show(editorPartPresenter);
presenter.show(editor);
verify(promise).catchError(operationErrorCapture.capture());
operationErrorCapture.getValue().apply(promiseError);
@ -167,7 +167,7 @@ public class FileStructurePresenterTest {
when(member.isBinary()).thenReturn(true);
when(nodePromise.then(Matchers.<Operation<Node>>anyObject())).thenReturn(nodePromise);
presenter.show(editorPartPresenter);
presenter.show(editor);
}
@Test
@ -175,17 +175,17 @@ public class FileStructurePresenterTest {
when(member.isBinary()).thenReturn(false);
when(nodePromise.then(Matchers.<Function<Node, Node>>anyObject())).thenReturn(nodePromise);
presenter.show(editorPartPresenter);
presenter.show(editor);
}
@Test
public void cursorShouldBeReturnedInPreviousPositionAfterDialogClosingByEscapeButton() {
presenter.show(editorPartPresenter);
presenter.show(editor);
presenter.onEscapeClicked();
verify(editorPartPresenter).setFocus();
verify(editorPartPresenter).getDocument();
verify(editor).setFocus();
verify(editor).getDocument();
verify(document).setSelectedRange(Matchers.<LinearRange>anyObject(), eq(true));
}
}

View File

@ -18,6 +18,8 @@ import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.editor.EditorAgent;
import org.eclipse.che.ide.api.editor.EditorInput;
import org.eclipse.che.ide.api.editor.position.PositionConverter;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
import org.eclipse.che.ide.api.resources.Container;
import org.eclipse.che.ide.api.resources.File;
import org.eclipse.che.ide.api.resources.Project;
@ -31,10 +33,8 @@ import org.eclipse.che.ide.ext.java.client.resource.SourceFolderMarker;
import org.eclipse.che.ide.ext.java.shared.JarEntry;
import org.eclipse.che.ide.ext.java.shared.dto.ImplementationsDescriptorDTO;
import org.eclipse.che.ide.ext.java.shared.dto.model.Type;
import org.eclipse.che.ide.ui.popup.PopupResources;
import org.eclipse.che.ide.api.editor.position.PositionConverter;
import org.eclipse.che.ide.api.editor.texteditor.TextEditorPresenter;
import org.eclipse.che.ide.resource.Path;
import org.eclipse.che.ide.ui.popup.PopupResources;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -79,7 +79,7 @@ public class OpenImplementationPresenterTest {
//other mocks
@Mock
private TextEditorPresenter editorPartPresenter;
private TextEditor editor;
@Mock
private EditorInput editorInput;
@Mock
@ -138,7 +138,7 @@ public class OpenImplementationPresenterTest {
@Test
public void testShouldDisplayOneImplementationIsRealFile() throws Exception {
when(editorPartPresenter.getEditorInput()).thenReturn(editorInput);
when(editor.getEditorInput()).thenReturn(editorInput);
when(editorInput.getFile()).thenReturn(file);
when(file.getRelatedProject()).thenReturn(Optional.of(relatedProject));
when(file.getParentWithMarker(eq(SourceFolderMarker.ID))).thenReturn(Optional.of(srcFolder));
@ -148,7 +148,7 @@ public class OpenImplementationPresenterTest {
when(file.getExtension()).thenReturn("java");
when(file.getName()).thenReturn("file.java");
when(relatedProject.getLocation()).thenReturn(Path.valueOf("/a"));
when(editorPartPresenter.getCursorOffset()).thenReturn(123);
when(editor.getCursorOffset()).thenReturn(123);
when(implementationsPromise.then(any(Operation.class))).thenReturn(implementationsPromise);
when(javaNavigationService.getImplementations(eq(Path.valueOf("/a")), eq("c.d.file"), eq(123))).thenReturn(implementationsPromise);
@ -162,7 +162,7 @@ public class OpenImplementationPresenterTest {
when(workspaceRoot.getFile(anyString())).thenReturn(realFilePromise);
when(realFilePromise.then(any(Operation.class))).thenReturn(realFilePromise);
presenter.show(editorPartPresenter);
presenter.show(editor);
verify(implementationsPromise).then(implementationsOperation.capture());
implementationsOperation.getValue().apply(implementationDescriptor);
@ -174,7 +174,7 @@ public class OpenImplementationPresenterTest {
@Test
public void testShouldDisplayNoImplementations() throws Exception {
when(editorPartPresenter.getEditorInput()).thenReturn(editorInput);
when(editor.getEditorInput()).thenReturn(editorInput);
when(editorInput.getFile()).thenReturn(file);
when(file.getRelatedProject()).thenReturn(Optional.of(relatedProject));
when(file.getParentWithMarker(eq(SourceFolderMarker.ID))).thenReturn(Optional.of(srcFolder));
@ -184,7 +184,7 @@ public class OpenImplementationPresenterTest {
when(file.getExtension()).thenReturn("java");
when(file.getName()).thenReturn("file.java");
when(relatedProject.getLocation()).thenReturn(Path.valueOf("/a"));
when(editorPartPresenter.getCursorOffset()).thenReturn(123);
when(editor.getCursorOffset()).thenReturn(123);
when(implementationsPromise.then(any(Operation.class))).thenReturn(implementationsPromise);
when(javaNavigationService.getImplementations(eq(Path.valueOf("/a")), eq("c.d.file"), eq(123))).thenReturn(implementationsPromise);
@ -194,10 +194,10 @@ public class OpenImplementationPresenterTest {
when(type1.getFlags()).thenReturn(-1);
when(dtoFactory.createDto(eq(Type.class))).thenReturn(type1);
when(editorPartPresenter.getPositionConverter()).thenReturn(positionConverter);
when(editor.getPositionConverter()).thenReturn(positionConverter);
when(positionConverter.offsetToPixel(anyInt())).thenReturn(new PositionConverter.PixelCoordinates(1, 1));
presenter.show(editorPartPresenter);
presenter.show(editor);
verify(implementationsPromise).then(implementationsOperation.capture());
implementationsOperation.getValue().apply(implementationDescriptor);

View File

@ -96,7 +96,6 @@ import org.eclipse.che.ide.api.editor.texteditor.HandlesTextOperations;
import org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo;
import org.eclipse.che.ide.api.editor.texteditor.HasKeyBindings;
import org.eclipse.che.ide.api.editor.texteditor.HasReadOnlyProperty;
import org.eclipse.che.ide.api.editor.texteditor.TemporaryKeyBindingsManager;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
import org.eclipse.che.ide.api.editor.texteditor.TextEditorOperations;
import org.eclipse.che.ide.api.editor.texteditor.TextEditorPartView;

View File

@ -28,6 +28,7 @@ import com.google.gwt.json.client.JSONObject;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
@ -39,6 +40,7 @@ import org.eclipse.che.api.promises.client.OperationException;
import org.eclipse.che.ide.api.dialogs.DialogFactory;
import org.eclipse.che.ide.api.editor.annotation.AnnotationModel;
import org.eclipse.che.ide.api.editor.annotation.AnnotationModelEvent;
import org.eclipse.che.ide.api.editor.codeassist.AdditionalInfoCallback;
import org.eclipse.che.ide.api.editor.codeassist.CompletionProposal;
import org.eclipse.che.ide.api.editor.codeassist.CompletionReadyCallback;
import org.eclipse.che.ide.api.editor.codeassist.CompletionsSource;
@ -61,7 +63,6 @@ import org.eclipse.che.ide.api.editor.text.Region;
import org.eclipse.che.ide.api.editor.text.RegionImpl;
import org.eclipse.che.ide.api.editor.text.TextRange;
import org.eclipse.che.ide.api.editor.text.annotation.Annotation;
import org.eclipse.che.ide.api.editor.texteditor.CompositeEditorWidget;
import org.eclipse.che.ide.api.editor.texteditor.ContentInitializedHandler;
import org.eclipse.che.ide.api.editor.texteditor.EditorWidget;
import org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo;
@ -76,12 +77,11 @@ import org.eclipse.che.ide.editor.orion.client.events.HasScrollHandlers;
import org.eclipse.che.ide.editor.orion.client.events.ScrollEvent;
import org.eclipse.che.ide.editor.orion.client.events.ScrollHandler;
import org.eclipse.che.ide.editor.orion.client.incremental.find.IncrementalFindReportStatusObserver;
import org.eclipse.che.ide.status.message.StatusMessageReporter;
import org.eclipse.che.ide.editor.orion.client.jso.OrionEditorOptionsOverlay;
import org.eclipse.che.ide.editor.orion.client.jso.OrionAnnotationModelOverlay;
import org.eclipse.che.ide.editor.orion.client.jso.OrionAnnotationOverlay;
import org.eclipse.che.ide.editor.orion.client.jso.OrionCodeEditWidgetOverlay;
import org.eclipse.che.ide.editor.orion.client.jso.OrionContentAssistOverlay;
import org.eclipse.che.ide.editor.orion.client.jso.OrionEditorOptionsOverlay;
import org.eclipse.che.ide.editor.orion.client.jso.OrionEditorOverlay;
import org.eclipse.che.ide.editor.orion.client.jso.OrionEditorViewOverlay;
import org.eclipse.che.ide.editor.orion.client.jso.OrionEventTargetOverlay;
@ -99,9 +99,10 @@ import org.eclipse.che.ide.editor.orion.client.jso.StatusMessageReporterOverlay;
import org.eclipse.che.ide.editor.orion.client.jso.UiUtilsOverlay;
import org.eclipse.che.ide.editor.preferences.editorproperties.EditorPropertiesManager;
import org.eclipse.che.ide.editor.preferences.keymaps.KeyMapsPreferencePresenter;
import org.eclipse.che.plugin.requirejs.ide.ModuleHolder;
import org.eclipse.che.ide.status.message.StatusMessageReporter;
import org.eclipse.che.ide.util.browser.UserAgent;
import org.eclipse.che.ide.util.loging.Log;
import org.eclipse.che.plugin.requirejs.ide.ModuleHolder;
import java.util.ArrayList;
import java.util.List;
@ -116,10 +117,11 @@ import static org.eclipse.che.ide.editor.orion.client.KeyMode.VI;
*
* @author "Mickaël Leduque"
*/
public class OrionEditorWidget extends CompositeEditorWidget implements HasChangeHandlers,
HasCursorActivityHandlers,
HasScrollHandlers,
HasGutter {
public class OrionEditorWidget extends Composite implements EditorWidget,
HasChangeHandlers,
HasCursorActivityHandlers,
HasScrollHandlers,
HasGutter {
/** The UI binder instance. */
private static final OrionEditorWidgetUiBinder UIBINDER = GWT.create(OrionEditorWidgetUiBinder.class);
@ -133,7 +135,7 @@ public class OrionEditorWidget extends CompositeEditorWidget implements HasChang
private final JavaScriptObject uiUtilsOverlay;
private final ContentAssistWidgetFactory contentAssistWidgetFactory;
private final DialogFactory dialogFactory;
private final PreferencesManager preferencesManager;
private final PreferencesManager preferencesManager;
@UiField
SimplePanel panel;
@ -152,9 +154,9 @@ public class OrionEditorWidget extends CompositeEditorWidget implements HasChang
private OrionKeyModeOverlay cheContentAssistMode;
private EditorPropertiesManager editorPropertiesManager;
private Keymap keymap;
private ContentAssistWidget assistWidget;
private Gutter gutter;
private Keymap keymap;
private ContentAssistWidget assistWidget;
private Gutter gutter;
private boolean changeHandlerAdded = false;
private boolean focusHandlerAdded = false;
@ -203,7 +205,7 @@ public class OrionEditorWidget extends CompositeEditorWidget implements HasChang
OrionEditorOptionsOverlay editorOptions = initEditorOptions(editorOptionsProvider.get(), statusMessageReporter);
orionCodeEditWidgetProvider.get().createEditorView(panel.getElement(), editorOptions)
.then(new EditorViewCreatedOperation(widgetInitializedCallback));
.then(new EditorViewCreatedOperation(widgetInitializedCallback));
incrementalFindObserver.setEditorWidget(this);
statusMessageReporter.registerObserver(incrementalFindObserver);
@ -538,11 +540,11 @@ public class OrionEditorWidget extends CompositeEditorWidget implements HasChang
boolean modifier3 = keyBinding.isAlt();
boolean modifier4 = UserAgent.isMac() ? keyBinding.isControl() : false;
if (keyBinding.isCharacterBinding()) {
strokeOverlay = OrionKeyStrokeOverlay.create(keyBinding.getCharacter(), modifier1, modifier2, modifier3,
modifier4, type, keyBindingModule);
strokeOverlay = OrionKeyStrokeOverlay.create(keyBinding.getCharacter(), modifier1, modifier2, modifier3,
modifier4, type, keyBindingModule);
} else {
strokeOverlay = OrionKeyStrokeOverlay.create(keyBinding.getKeyCodeNumber(), modifier1, modifier2, modifier3,
modifier4, type, keyBindingModule);
strokeOverlay = OrionKeyStrokeOverlay.create(keyBinding.getKeyCodeNumber(), modifier1, modifier2, modifier3,
modifier4, type, keyBindingModule);
}
String actionId = "che-action-" + keyBinding.getAction().toString();
editorOverlay.getTextView().setKeyBinding(strokeOverlay, actionId);
@ -655,6 +657,11 @@ public class OrionEditorWidget extends CompositeEditorWidget implements HasChang
editorOverlay.getContentAssist().activate();
}
@Override
public void showCompletionProposals(final CompletionsSource completionsSource, final AdditionalInfoCallback additionalInfoCallback) {
showCompletionProposals(completionsSource);
}
@Override
public void refresh() {
this.editorOverlay.getTextView().redraw();
@ -692,7 +699,7 @@ public class OrionEditorWidget extends CompositeEditorWidget implements HasChang
}
private String getSeverity(String type, OrionAnnotationSeverityProvider provider) {
if(provider != null ){
if (provider != null) {
return provider.getSeverity(type);
} else {
return "error";
@ -806,19 +813,19 @@ public class OrionEditorWidget extends CompositeEditorWidget implements HasChang
/**
* Registers global prompt function to be accessible directly from JavaScript.
*
* <p/>
* Function promptIDE(title, text, defaultValue, callback)
* title Dialog title
* text The text to display in the dialog box
* defaultValue The default value
* callback function(value)
* clicking "OK" will return input value
* clicking "Cancel" will return null
* title Dialog title
* text The text to display in the dialog box
* defaultValue The default value
* callback function(value)
* clicking "OK" will return input value
* clicking "Cancel" will return null
*/
private native void registerPromptFunction() /*-{
if (!$wnd["promptIDE"]) {
var instance = this;
$wnd["promptIDE"] = function(title, text, defaultValue, callback) {
$wnd["promptIDE"] = function (title, text, defaultValue, callback) {
instance.@org.eclipse.che.ide.editor.orion.client.OrionEditorWidget::askLineNumber(*)(title, text, defaultValue, callback);
};
}
@ -840,8 +847,7 @@ public class OrionEditorWidget extends CompositeEditorWidget implements HasChang
var callback = this.@org.eclipse.che.ide.editor.orion.client.OrionEditorWidget.InputCallback::callback;
callback(value);
}-*/;
};
}
private void askLineNumber(String title, String text, String defaultValue, final JavaScriptObject callback) {
if (defaultValue == null) {
@ -854,5 +860,4 @@ public class OrionEditorWidget extends CompositeEditorWidget implements HasChang
dialogFactory.createInputDialog(title, text, defaultValue, 0, defaultValue.length(), new InputCallback(callback), null).show();
}
}

View File

@ -8,14 +8,14 @@
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.api.editor.texteditor;
import java.util.ArrayList;
import java.util.List;
package org.eclipse.che.ide.editor.orion.client;
import org.eclipse.che.ide.api.editor.keymap.KeyBinding;
import org.eclipse.che.ide.api.editor.texteditor.HasKeyBindings;
import java.util.ArrayList;
import java.util.List;
/** Hold {@link KeyBinding} until the editor is ready to accept them. */
public class TemporaryKeyBindingsManager implements HasKeyBindings {