From 7a2df06164a78d6e8cb059ac9ada6914668d0546 Mon Sep 17 00:00:00 2001 From: Valeriy Svydenko Date: Mon, 22 Feb 2016 15:13:19 +0200 Subject: [PATCH] CHE-165: show move wizard after performing 'Cut' operation in project explorer for the java items --- .../api/project/server/ProjectService.java | 7 + .../ide/ext/java/client/JavaExtension.java | 4 + .../refactoring/move/CutJavaSourceAction.java | 64 ++++++++ .../client/refactoring/move/MoveAction.java | 8 +- .../move/wizard/MovePresenter.java | 11 +- .../refactoring/move/wizard/MoveViewImpl.java | 10 -- .../move/CutJavaSourceActionTest.java | 148 ++++++++++++++++++ 7 files changed, 233 insertions(+), 19 deletions(-) create mode 100644 plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/refactoring/move/CutJavaSourceAction.java create mode 100644 plugins/plugin-java/che-plugin-java-ext-lang-client/src/test/java/org/eclipse/che/ide/ext/java/client/refactoring/move/CutJavaSourceActionTest.java diff --git a/core/platform-api/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectService.java b/core/platform-api/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectService.java index 817e369733..700014d8ab 100644 --- a/core/platform-api/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectService.java +++ b/core/platform-api/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectService.java @@ -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(); } diff --git a/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/JavaExtension.java b/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/JavaExtension.java index 932cf4b22d..c3c29c169d 100644 --- a/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/JavaExtension.java +++ b/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/JavaExtension.java @@ -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"); } diff --git a/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/refactoring/move/CutJavaSourceAction.java b/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/refactoring/move/CutJavaSourceAction.java new file mode 100644 index 0000000000..42e904ce9f --- /dev/null +++ b/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/refactoring/move/CutJavaSourceAction.java @@ -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(); + } +} diff --git a/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/refactoring/move/MoveAction.java b/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/refactoring/move/MoveAction.java index e6a7b886cf..96c781cea5 100644 --- a/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/refactoring/move/MoveAction.java +++ b/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/refactoring/move/MoveAction.java @@ -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()) { diff --git a/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/refactoring/move/wizard/MovePresenter.java b/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/refactoring/move/wizard/MovePresenter.java index f6ff7ba6a4..f87064eb31 100644 --- a/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/refactoring/move/wizard/MovePresenter.java +++ b/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/refactoring/move/wizard/MovePresenter.java @@ -182,17 +182,12 @@ public class MovePresenter implements MoveView.ActionDelegate { projectsPromise.then(new Operation>() { @Override public void apply(List projects) throws OperationException { + List currentProject = new ArrayList<>(); for (JavaProject project : projects) { - if (project.getPath().equals(getPathToProject())) { - List currentProject = new ArrayList<>(); currentProject.add(project); - - view.setTreeOfDestinations(currentProject); - view.show(refactorInfo); - - return; - } } + view.setTreeOfDestinations(currentProject); + view.show(refactorInfo); } }).catchError(new Operation() { @Override diff --git a/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/refactoring/move/wizard/MoveViewImpl.java b/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/refactoring/move/wizard/MoveViewImpl.java index f98e883c11..7586fe092d 100644 --- a/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/refactoring/move/wizard/MoveViewImpl.java +++ b/plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/refactoring/move/wizard/MoveViewImpl.java @@ -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)); - } - } - } } \ No newline at end of file diff --git a/plugins/plugin-java/che-plugin-java-ext-lang-client/src/test/java/org/eclipse/che/ide/ext/java/client/refactoring/move/CutJavaSourceActionTest.java b/plugins/plugin-java/che-plugin-java-ext-lang-client/src/test/java/org/eclipse/che/ide/ext/java/client/refactoring/move/CutJavaSourceActionTest.java new file mode 100644 index 0000000000..ddf310a218 --- /dev/null +++ b/plugins/plugin-java/che-plugin-java-ext-lang-client/src/test/java/org/eclipse/che/ide/ext/java/client/refactoring/move/CutJavaSourceActionTest.java @@ -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); + } +} \ No newline at end of file