Skip to content

Commit

Permalink
Language Server Protocol Rename implementation (#6615)
Browse files Browse the repository at this point in the history
* #1806 add service and UI for rename feature
Signed-off-by: Yevhen Vydolob <evidolob@codenvy.com>
  • Loading branch information
evidolob authored Oct 9, 2017
1 parent c9a8d8f commit 59abab9
Show file tree
Hide file tree
Showing 54 changed files with 2,159 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
package org.eclipse.che.ide.api.editor.texteditor;

import javax.validation.constraints.NotNull;
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.api.editor.document.Document;
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.keymap.KeyBinding;
import org.eclipse.che.ide.api.editor.position.PositionConverter;
import org.eclipse.che.ide.api.editor.text.LinearRange;
import org.eclipse.che.ide.api.editor.text.Position;
import org.eclipse.che.ide.api.editor.text.TextPosition;
import org.eclipse.che.ide.api.editor.text.TextRange;

Expand Down Expand Up @@ -175,4 +177,13 @@ public interface TextEditor extends EditorPartPresenter {
* @param action the action to add
*/
void addEditorUpdateAction(EditorUpdateAction action);

/**
* Get word position under offset.
*
* @param offset the offset for look for a word
* @return the word position
*/
@Nullable
Position getWordAtOffset(int offset);
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,11 @@ void addPart(
* @param container container in which need expose view
*/
void go(@NotNull AcceptsOneWidget container);

/**
* Get current active part
*
* @return the active part
*/
PartPresenter getActivePart();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@
@SDK(title = "ide.api.ui.workspace")
public interface WorkspaceAgent {

/**
* Activate given part
*
* @param part
*/
void setActivePart(PartPresenter part);

void setActivePart(@NotNull PartPresenter part, PartStackType type);

/**
Expand Down Expand Up @@ -69,4 +62,18 @@ public interface WorkspaceAgent {
* @return the part stack found, else null
*/
PartStack getPartStack(PartStackType type);

/**
* Get current active part
*
* @return the active part
*/
PartPresenter getActivePart();

/**
* Activate given part
*
* @param part
*/
void setActivePart(PartPresenter part);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.eclipse.che.ide.api.editor.EditorAgent;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.api.notification.NotificationManager;
import org.eclipse.che.ide.api.parts.WorkspaceAgent;
import org.eclipse.che.ide.api.resources.RenamingSupport;
import org.eclipse.che.ide.api.resources.Resource;
import org.eclipse.che.ide.resource.Path;
Expand All @@ -60,6 +61,7 @@ public class RenameItemAction extends AbstractPerspectiveAction {
private final NotificationManager notificationManager;
private final DialogFactory dialogFactory;
private final AppContext appContext;
private final WorkspaceAgent workspaceAgent;

@Inject
public RenameItemAction(
Expand All @@ -69,7 +71,8 @@ public RenameItemAction(
EditorAgent editorAgent,
NotificationManager notificationManager,
DialogFactory dialogFactory,
AppContext appContext) {
AppContext appContext,
WorkspaceAgent workspaceAgent) {
super(
singletonList(PROJECT_PERSPECTIVE_ID),
localization.renameItemActionText(),
Expand All @@ -82,6 +85,7 @@ public RenameItemAction(
this.notificationManager = notificationManager;
this.dialogFactory = dialogFactory;
this.appContext = appContext;
this.workspaceAgent = workspaceAgent;
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -115,7 +119,7 @@ public void actionPerformed(ActionEvent e) {
new InputCallback() {
@Override
public void accepted(final String value) {
//we shouldn't perform renaming file with the same name
// we shouldn't perform renaming file with the same name
if (!value.trim().equals(resourceName)) {

closeRelatedEditors(resource);
Expand Down Expand Up @@ -165,6 +169,13 @@ private void closeRelatedEditors(Resource resource) {
/** {@inheritDoc} */
@Override
public void updateInPerspective(@NotNull ActionEvent e) {

if (workspaceAgent.getActivePart() == null
|| workspaceAgent.getActivePart() instanceof EditorPartPresenter) {
e.getPresentation().setEnabledAndVisible(false);
return;
}

final Resource[] resources = appContext.getResources();
e.getPresentation().setVisible(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
import static org.eclipse.che.ide.processes.ProcessTreeNode.ProcessNodeType.MACHINE_NODE;

import com.google.gwt.core.client.Scheduler;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Node;
import com.google.gwt.dom.client.NodeList;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.FlowPanel;
Expand All @@ -37,13 +32,13 @@
import org.eclipse.che.ide.CoreLocalizationConstant;
import org.eclipse.che.ide.api.parts.PartStackUIResources;
import org.eclipse.che.ide.api.parts.base.BaseView;
import org.eclipse.che.ide.api.theme.Style;
import org.eclipse.che.ide.machine.MachineResources;
import org.eclipse.che.ide.processes.ProcessDataAdapter;
import org.eclipse.che.ide.processes.ProcessTreeNode;
import org.eclipse.che.ide.processes.ProcessTreeRenderer;
import org.eclipse.che.ide.processes.StopProcessHandler;
import org.eclipse.che.ide.terminal.TerminalOptionsJso;
import org.eclipse.che.ide.ui.SplitterFancyUtil;
import org.eclipse.che.ide.ui.multisplitpanel.SubPanel;
import org.eclipse.che.ide.ui.multisplitpanel.SubPanelFactory;
import org.eclipse.che.ide.ui.multisplitpanel.WidgetToShow;
Expand Down Expand Up @@ -98,7 +93,8 @@ public ProcessesPanelViewImpl(
ProcessDataAdapter adapter,
ProcessesPartViewImplUiBinder uiBinder,
SubPanelFactory subPanelFactory,
CoreLocalizationConstant localizationConstants) {
CoreLocalizationConstant localizationConstants,
SplitterFancyUtil splitterFancyUtil) {
super(partStackUIResources);
setTitle(localizationConstants.viewProcessesTitle());
this.machineResources = machineResources;
Expand Down Expand Up @@ -190,65 +186,11 @@ public void onKeyboard(KeyboardEvent event) {}
splitLayoutPanel.add(subPanel.getView());
focusedSubPanel = subPanel;

tuneSplitter();
splitterFancyUtil.tuneSplitter(splitLayoutPanel);
splitLayoutPanel.setWidgetHidden(navigationPanel, true);
navigationPanelVisible = false;
}

/** Improves splitter visibility. */
private void tuneSplitter() {
NodeList<Node> nodes = splitLayoutPanel.getElement().getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.getItem(i);
if (node.hasChildNodes()) {
com.google.gwt.dom.client.Element el = node.getFirstChild().cast();
if ("gwt-SplitLayoutPanel-HDragger".equals(el.getClassName())) {
tuneSplitter(el);
return;
}
}
}
}

/**
* Tunes splitter. Makes it wider and adds double border to seem rich.
*
* @param el element to tune
*/
private void tuneSplitter(Element el) {
/** Add Z-Index to move the splitter on the top and make content visible */
el.getParentElement().getStyle().setProperty("zIndex", "1000");
el.getParentElement().getStyle().setProperty("overflow", "visible");

/** Tune splitter catch panel */
el.getStyle().setProperty("boxSizing", "border-box");
el.getStyle().setProperty("width", "5px");
el.getStyle().setProperty("overflow", "hidden");
el.getStyle().setProperty("marginLeft", "-3px");
el.getStyle().setProperty("backgroundColor", "transparent");

/** Add small border */
DivElement smallBorder = Document.get().createDivElement();
smallBorder.getStyle().setProperty("position", "absolute");
smallBorder.getStyle().setProperty("width", "1px");
smallBorder.getStyle().setProperty("height", "100%");
smallBorder.getStyle().setProperty("left", "3px");
smallBorder.getStyle().setProperty("top", "0px");
smallBorder.getStyle().setProperty("backgroundColor", Style.getSplitterSmallBorderColor());
el.appendChild(smallBorder);

/** Add large border */
DivElement largeBorder = Document.get().createDivElement();
largeBorder.getStyle().setProperty("position", "absolute");
largeBorder.getStyle().setProperty("width", "2px");
largeBorder.getStyle().setProperty("height", "100%");
largeBorder.getStyle().setProperty("left", "1px");
largeBorder.getStyle().setProperty("top", "0px");
largeBorder.getStyle().setProperty("opacity", "0.4");
largeBorder.getStyle().setProperty("backgroundColor", Style.getSplitterLargeBorderColor());
el.appendChild(largeBorder);
}

@Override
public void addWidget(
final String processId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ public PartStack getPartStack(PartStackType type) {
return activePerspective.getPartStack(type);
}

@Override
public PartPresenter getActivePart() {
return activePerspective.getActivePart();
}

@Override
public JsonObject getState() {
JsonObject state = Json.createObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ public PartStack getPartStack(@NotNull PartStackType type) {
return partStacks.get(type);
}

@Override
public PartPresenter getActivePart() {
return activePart;
}

@Override
public JsonObject getState() {
JsonObject state = Json.createObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.che.ide.actions;

import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand All @@ -24,7 +25,10 @@
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.dialogs.DialogFactory;
import org.eclipse.che.ide.api.editor.EditorAgent;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.api.notification.NotificationManager;
import org.eclipse.che.ide.api.parts.PartPresenter;
import org.eclipse.che.ide.api.parts.WorkspaceAgent;
import org.eclipse.che.ide.api.project.ProjectServiceClient;
import org.eclipse.che.ide.api.resources.RenamingSupport;
import org.eclipse.che.ide.api.resources.Resource;
Expand Down Expand Up @@ -54,6 +58,9 @@ public class RenameItemActionTest {
@Mock private ActionEvent event;
@Mock private Presentation presentation;

@Mock private WorkspaceAgent workspaceAgent;
@Mock private PartPresenter partPresenter;

private Resource[] selectedResources = new Resource[1];
private Set<RenamingSupport> renamingSupport = new HashSet<>();

Expand All @@ -63,6 +70,7 @@ public void setUp() throws Exception {

when(appContext.getResources()).thenReturn(selectedResources);
when(event.getPresentation()).thenReturn(presentation);
when(workspaceAgent.getActivePart()).thenReturn(partPresenter);
}

@Test
Expand Down Expand Up @@ -102,7 +110,8 @@ public void actionShouldBeDisabledIfSomeRenameValidatorForbidsRenameOperation()
editorAgent,
notificationManager,
dialogFactory,
appContext);
appContext,
workspaceAgent);
action.updateInPerspective(event);

verify(presentation).setVisible(true);
Expand All @@ -122,10 +131,20 @@ public void actionShouldBeEnabled() throws Exception {
editorAgent,
notificationManager,
dialogFactory,
appContext);
appContext,
workspaceAgent);
action.updateInPerspective(event);

verify(presentation).setVisible(true);
verify(presentation).setEnabled(true);
}

@Test
public void actionShouldBeDisabledIfEditorActive() {
when(workspaceAgent.getActivePart()).thenReturn(mock(EditorPartPresenter.class));

action.updateInPerspective(event);

verify(presentation).setEnabledAndVisible(false);
}
}
4 changes: 4 additions & 0 deletions ide/che-core-ide-ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-assistedinject</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
Expand Down
Loading

0 comments on commit 59abab9

Please sign in to comment.