-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
QuickDocPresenter.java
68 lines (58 loc) · 2.61 KB
/
QuickDocPresenter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*******************************************************************************
* Copyright (c) 2012-2016 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.ext.java.client.documentation;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.editor.EditorAgent;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.ext.java.client.projecttree.JavaSourceFolderUtil;
import org.eclipse.che.ide.api.editor.position.PositionConverter;
import org.eclipse.che.ide.api.editor.texteditor.TextEditorPresenter;
import org.eclipse.che.ide.util.loging.Log;
/**
* @author Evgen Vidolob
*/
@Singleton
public class QuickDocPresenter implements QuickDocumentation, QuickDocView.ActionDelegate {
private final QuickDocView view;
private final AppContext appContext;
private final EditorAgent editorAgent;
@Inject
public QuickDocPresenter(QuickDocView view,
AppContext appContext,
EditorAgent editorAgent) {
this.view = view;
this.appContext = appContext;
this.editorAgent = editorAgent;
}
@Override
public void showDocumentation() {
EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
if (activeEditor == null) {
return;
}
if (!(activeEditor instanceof TextEditorPresenter)) {
Log.error(getClass(), "Quick Document support only TextEditorPresenter as editor");
return;
}
TextEditorPresenter editor = ((TextEditorPresenter)activeEditor);
int offset = editor.getCursorOffset();
final PositionConverter.PixelCoordinates coordinates = editor.getPositionConverter().offsetToPixel(offset);
view.show(appContext.getDevMachine().getWsAgentBaseUrl() + "/java/javadoc/find?fqn=" +
JavaSourceFolderUtil.getFQNForFile(editor.getEditorInput().getFile()) + "&projectpath=" +
appContext.getCurrentProject().getProjectConfig().getPath() + "&offset=" + offset, coordinates.getX(),
coordinates.getY());
}
@Override
public void onCloseView() {
}
}