CHE-165: show move wizard after performing 'Cut' operation in project explorer for the java items

6.19.x
Valeriy Svydenko 2016-02-22 15:13:19 +02:00
parent bc33e015ad
commit 7a2df06164
7 changed files with 233 additions and 19 deletions

View File

@ -722,6 +722,13 @@ public class ProjectService extends Service {
logProjectCreatedEvent(name, projectType);
}
}
eventService.publish(new ProjectItemModifiedEvent(ProjectItemModifiedEvent.EventType.CREATED,
workspace,
projectPath(copy.getPath()),
copy.getPath(),
copy.isFolder()));
return Response.created(location).build();
}

View File

@ -31,6 +31,7 @@ import org.eclipse.che.ide.ext.java.client.action.OpenDeclarationAction;
import org.eclipse.che.ide.ext.java.client.action.OpenImplementationAction;
import org.eclipse.che.ide.ext.java.client.action.QuickDocumentationAction;
import org.eclipse.che.ide.ext.java.client.action.FileStructureAction;
import org.eclipse.che.ide.ext.java.client.refactoring.move.CutJavaSourceAction;
import org.eclipse.che.ide.ext.java.client.refactoring.move.MoveAction;
import org.eclipse.che.ide.ext.java.client.refactoring.rename.RenameRefactoringAction;
import org.eclipse.che.ide.ext.java.shared.Constants;
@ -69,6 +70,7 @@ public class JavaExtension {
NewJavaSourceFileAction newJavaSourceFileAction,
ActionManager actionManager,
MoveAction moveAction,
CutJavaSourceAction cutAction,
FileStructureAction fileStructureAction,
RenameRefactoringAction renameRefactoringAction,
QuickDocumentationAction quickDocumentationAction,
@ -101,6 +103,7 @@ public class JavaExtension {
actionManager.registerAction("openImplementation", openImplementationAction);
actionManager.registerAction("javaRenameRefactoring", renameRefactoringAction);
actionManager.registerAction("javaMoveRefactoring", moveAction);
actionManager.registerAction("javaCutRefactoring", cutAction);
actionManager.registerAction("javaFindUsages", findUsagesAction);
actionManager.registerAction("javaClassStructure", fileStructureAction);
@ -121,6 +124,7 @@ public class JavaExtension {
}
keyBinding.getGlobal().addKey(new KeyBuilder().none().charCode(KeyCodeMap.F4).build(), "openJavaDeclaration");
keyBinding.getGlobal().addKey(new KeyBuilder().shift().charCode(KeyCodeMap.F6).build(), "javaRenameRefactoring");
keyBinding.getGlobal().addKey(new KeyBuilder().action().charCode('x').build(), "javaCutRefactoring");
keyBinding.getGlobal().addKey(new KeyBuilder().charCode(KeyCodeMap.F6).build(), "javaMoveRefactoring");
keyBinding.getGlobal().addKey(new KeyBuilder().alt().charCode(KeyCodeMap.F7).build(), "javaFindUsages");
}

View File

@ -0,0 +1,64 @@
/*******************************************************************************
* 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.refactoring.move;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.EventBus;
import org.eclipse.che.ide.api.action.Action;
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.api.event.ActivePartChangedEvent;
import org.eclipse.che.ide.api.event.ActivePartChangedHandler;
import org.eclipse.che.ide.ext.java.client.JavaLocalizationConstant;
/**
* The action is called Move presenter when the user has clicked Ctrl+X on some class or package into the 'Project Explorer'.
*
* @author Valeriy Svydenko
*/
@Singleton
public class CutJavaSourceAction extends Action implements ActivePartChangedHandler {
private final MoveAction moveAction;
private boolean isEditorPartActive;
@Inject
public CutJavaSourceAction(JavaLocalizationConstant locale, MoveAction moveAction, EventBus eventBus) {
super(locale.moveActionName(), locale.moveActionDescription());
this.moveAction = moveAction;
eventBus.addHandler(ActivePartChangedEvent.TYPE, this);
}
@Override
public void update(ActionEvent actionEvent) {
actionEvent.getPresentation().setEnabled(isActionEnable());
}
@Override
public void actionPerformed(ActionEvent actionEvent) {
if (isActionEnable()) {
moveAction.actionPerformed(actionEvent);
}
}
@Override
public void onActivePartChanged(ActivePartChangedEvent event) {
isEditorPartActive = event.getActivePart() instanceof EditorPartPresenter;
}
private boolean isActionEnable() {
return !isEditorPartActive && moveAction.isActionEnable();
}
}

View File

@ -33,6 +33,7 @@ import static org.eclipse.che.ide.ext.java.client.refactoring.move.RefactoredIte
/**
* @author Dmitry Shnurenko
* @author Valeriy Svydenko
*/
@Singleton
public class MoveAction extends Action {
@ -58,7 +59,12 @@ public class MoveAction extends Action {
actionEvent.getPresentation().setEnabled(isActionEnable());
}
private boolean isActionEnable() {
/**
* Check if action can be applied.
*
* @return {@code true} if action should be enabled otherwise return {@code false}
*/
public boolean isActionEnable() {
Selection<?> selection = selectionAgent.getSelection();
if (selection == null || selection.isEmpty()) {

View File

@ -182,17 +182,12 @@ public class MovePresenter implements MoveView.ActionDelegate {
projectsPromise.then(new Operation<List<JavaProject>>() {
@Override
public void apply(List<JavaProject> projects) throws OperationException {
List<JavaProject> currentProject = new ArrayList<>();
for (JavaProject project : projects) {
if (project.getPath().equals(getPathToProject())) {
List<JavaProject> currentProject = new ArrayList<>();
currentProject.add(project);
view.setTreeOfDestinations(currentProject);
view.show(refactorInfo);
return;
}
}
view.setTreeOfDestinations(currentProject);
view.show(refactorInfo);
}
}).catchError(new Operation<PromiseError>() {
@Override

View File

@ -18,7 +18,6 @@ import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.CellTree;
import com.google.gwt.user.cellview.client.TreeNode;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.FlowPanel;
@ -205,7 +204,6 @@ final class MoveViewImpl extends Window implements MoveView {
tree.setAnimationEnabled(true);
treePanel.clear();
treePanel.add(tree);
expandAll(tree.getRootTreeNode());
}
/** {@inheritDoc} */
@ -289,12 +287,4 @@ final class MoveViewImpl extends Window implements MoveView {
}
return null;
}
private void expandAll(TreeNode node) {
for (int i = 0; i < node.getChildCount(); i++) {
if (!node.isChildLeaf(i)) {
expandAll(node.setChildOpen(i, true));
}
}
}
}

View File

@ -0,0 +1,148 @@
/*******************************************************************************
* 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.refactoring.move;
import com.google.gwtmockito.GwtMockitoTestRunner;
import com.google.web.bindery.event.shared.EventBus;
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.action.Presentation;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.api.event.ActivePartChangedEvent;
import org.eclipse.che.ide.api.parts.PartPresenter;
import org.eclipse.che.ide.ext.java.client.JavaLocalizationConstant;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* @author Valeriy Svydenko
*/
@RunWith(GwtMockitoTestRunner.class)
public class CutJavaSourceActionTest {
@Mock
private JavaLocalizationConstant locale;
@Mock
private MoveAction moveAction;
@Mock
private EventBus eventBus;
@Mock
private ActivePartChangedEvent event;
@Mock
private ActionEvent updateActionEvent;
@Mock
private EditorPartPresenter editorPartPresenter;
@Mock
private PartPresenter partPresenter;
@Mock
private Presentation presentation;
private CutJavaSourceAction action;
@Before
public void setUp() throws Exception {
action = new CutJavaSourceAction(locale, moveAction, eventBus);
}
@Test
public void constructorShouldPerform() throws Exception {
verify(locale).moveActionName();
verify(locale).moveActionDescription();
verify(eventBus).addHandler(ActivePartChangedEvent.TYPE, action);
}
@Test
public void actionShouldBeEnabledIfEditorPartIsNotActiveAndMoveActionIsEnable() throws Exception {
when(updateActionEvent.getPresentation()).thenReturn(presentation);
when(event.getActivePart()).thenReturn(partPresenter);
when(moveAction.isActionEnable()).thenReturn(true);
action.onActivePartChanged(event);
action.update(updateActionEvent);
verify(presentation).setEnabled(true);
}
@Test
public void actionShouldBeDisabledIfEditorPartIsNotActiveAndMoveActionIsNotEnable() throws Exception {
when(updateActionEvent.getPresentation()).thenReturn(presentation);
when(event.getActivePart()).thenReturn(partPresenter);
when(moveAction.isActionEnable()).thenReturn(false);
action.onActivePartChanged(event);
action.update(updateActionEvent);
verify(presentation).setEnabled(false);
}
@Test
public void actionShouldBeDisabledIfEditorPartIsActive() throws Exception {
when(updateActionEvent.getPresentation()).thenReturn(presentation);
when(event.getActivePart()).thenReturn(editorPartPresenter);
action.onActivePartChanged(event);
action.update(updateActionEvent);
verify(presentation).setEnabled(false);
}
@Test
public void actionPerformsIfEditorPartIsNotActiveAndMoveActionIsEnable() throws Exception {
when(updateActionEvent.getPresentation()).thenReturn(presentation);
when(event.getActivePart()).thenReturn(partPresenter);
when(moveAction.isActionEnable()).thenReturn(true);
action.onActivePartChanged(event);
action.actionPerformed(updateActionEvent);
verify(moveAction).actionPerformed(updateActionEvent);
}
@Test
public void actionDoesNotPerformIfEditorPartIsNotActiveAndMoveActionIsNotEnable() throws Exception {
when(updateActionEvent.getPresentation()).thenReturn(presentation);
when(event.getActivePart()).thenReturn(partPresenter);
when(moveAction.isActionEnable()).thenReturn(false);
action.onActivePartChanged(event);
action.actionPerformed(updateActionEvent);
verify(moveAction, never()).actionPerformed(updateActionEvent);
}
@Test
public void actionDoesPerformIfEditorPartIsActive() throws Exception {
when(updateActionEvent.getPresentation()).thenReturn(presentation);
when(event.getActivePart()).thenReturn(editorPartPresenter);
action.onActivePartChanged(event);
action.actionPerformed(updateActionEvent);
verify(moveAction, never()).actionPerformed(updateActionEvent);
}
@Test
public void partShouldBeChanged() throws Exception {
when(event.getActivePart()).thenReturn(editorPartPresenter);
action.onActivePartChanged(event);
assertTrue(event.getActivePart() instanceof EditorPartPresenter);
}
}