Skip to content

Commit

Permalink
CHE-1860: make it possible to move packages (#4659)
Browse files Browse the repository at this point in the history
  • Loading branch information
Valeriy Svydenko authored Mar 31, 2017
1 parent 1f4666c commit a108070
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public final Change perform(IProgressMonitor pm) throws CoreException, Operation
IPackageFragment pack= getPackage();
ResourceMapping mapping= JavaElementResourceMapping.create(pack);
final Change result= doPerformReorg(pm);
markAsExecuted(pack, mapping);
//markAsExecuted(pack, mapping);
return result;
} finally {
pm.done();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.eclipse.che.ide.api.editor.EditorAgent;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
import org.eclipse.che.ide.api.event.ng.FileTrackingEvent;
import org.eclipse.che.ide.api.notification.NotificationManager;
import org.eclipse.che.ide.api.notification.StatusNotification.Status;
import org.eclipse.che.ide.api.resources.Container;
Expand Down Expand Up @@ -51,9 +50,6 @@
import java.util.ArrayList;
import java.util.List;

import static org.eclipse.che.api.project.shared.dto.event.FileTrackingOperationDto.Type.MOVE;
import static org.eclipse.che.api.project.shared.dto.event.FileTrackingOperationDto.Type.RESUME;
import static org.eclipse.che.api.project.shared.dto.event.FileTrackingOperationDto.Type.SUSPEND;
import static org.eclipse.che.ide.api.event.ng.FileTrackingEvent.newFileTrackingMoveEvent;
import static org.eclipse.che.ide.api.event.ng.FileTrackingEvent.newFileTrackingResumeEvent;
import static org.eclipse.che.ide.api.event.ng.FileTrackingEvent.newFileTrackingSuspendEvent;
Expand Down Expand Up @@ -185,7 +181,7 @@ public void apply(List<JavaProject> projects) throws OperationException {
for (JavaProject project : projects) {
currentProject.add(project);
}
view.setTreeOfDestinations(currentProject);
view.setTreeOfDestinations(refactorInfo, currentProject);
view.show(refactorInfo);
}
}).catchError(new Operation<PromiseError>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ interface MoveView extends View<MoveView.ActionDelegate> {
*
* @param projects
* list of projects from current workspace
* @param refactorInfo
* information about refactoring operation
*/
void setTreeOfDestinations(List<JavaProject> projects);
void setTreeOfDestinations(RefactorInfo refactorInfo, List<JavaProject> projects);

/**
* Show information message into bottom of view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public void clearErrorLabel() {

/** {@inheritDoc} */
@Override
public void setTreeOfDestinations(List<JavaProject> projects) {
public void setTreeOfDestinations(RefactorInfo refactorInfo, List<JavaProject> projects) {
final SingleSelectionModel<Object> selectionModel = new SingleSelectionModel<>();
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
@Override
Expand All @@ -198,7 +198,9 @@ public void onSelectionChange(SelectionChangeEvent event) {
}
}
});
CellTree tree = new CellTree(new ProjectsAndPackagesModel(projects, selectionModel, resources), null, cellTreeResources);
CellTree tree = new CellTree(new ProjectsAndPackagesModel(projects, refactorInfo, selectionModel, resources),
null,
cellTreeResources);
tree.setAnimationEnabled(true);
treePanel.clear();
treePanel.add(tree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.google.gwt.view.client.TreeViewModel;

import org.eclipse.che.ide.ext.java.client.JavaResources;
import org.eclipse.che.ide.ext.java.client.refactoring.RefactorInfo;
import org.eclipse.che.ide.ext.java.client.refactoring.move.RefactoredItemType;
import org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject;
import org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragment;
import org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragmentRoot;
Expand All @@ -31,11 +33,16 @@
*/
public class ProjectsAndPackagesModel implements TreeViewModel {
private List<JavaProject> projects;
private final RefactorInfo refactorInfo;
private SingleSelectionModel<Object> selectionModel;
private JavaResources resources;

public ProjectsAndPackagesModel(List<JavaProject> projects, SingleSelectionModel<Object> selectionModel, JavaResources resources) {
public ProjectsAndPackagesModel(List<JavaProject> projects,
RefactorInfo refactorInfo,
SingleSelectionModel<Object> selectionModel,
JavaResources resources) {
this.projects = projects;
this.refactorInfo = refactorInfo;
this.selectionModel = selectionModel;
this.resources = resources;
}
Expand Down Expand Up @@ -72,6 +79,9 @@ public void render(Context context, PackageFragmentRoot value,
}

if (value instanceof PackageFragmentRoot) {
if (RefactoredItemType.PACKAGE.equals(refactorInfo.getRefactoredItemType())) {
return null;
}
return new DefaultNodeInfo<>(new ListDataProvider<>(((PackageFragmentRoot)value).getPackageFragments()),
new AbstractCell<PackageFragment>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void moveWizardShouldBeShowed() throws Exception {
verify(projectsPromise).then(projectsOperation.capture());
projectsOperation.getValue().apply(javaProjects);

verify(moveView).setTreeOfDestinations(any());
verify(moveView).setTreeOfDestinations(any(), any());
verify(moveView).show(refactorInfo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,28 +142,35 @@ public RefactoringResult apply() {
}

CompositeChange operationChange = (CompositeChange)operation.getUndoChange();
Change[] changes = operationChange.getChildren();
if (operationChange == null) {
return DtoConverter.toRefactoringResultDto(new RefactoringStatus());
}

Change[] changes = operationChange.getChildren();
RefactoringStatus validationStatus = operation.getValidationStatus();
if (validationStatus != null) {
List<ChangeInfo> changesInfo = new ArrayList<>();

prepareChangesInfo(changes, changesInfo);
if (validationStatus == null) {
return DtoConverter.toRefactoringResultDto(new RefactoringStatus());
}

RefactoringResult status = DtoConverter.toRefactoringResultDto(validationStatus);
status.setChanges(changesInfo);
List<ChangeInfo> changesInfo = new ArrayList<>();

return status;
}
prepareChangesInfo(changes, changesInfo);

RefactoringResult status = DtoConverter.toRefactoringResultDto(validationStatus);
status.setChanges(changesInfo);

return status;

return DtoConverter.toRefactoringResultDto(new RefactoringStatus());
}

/**
* Prepare the information about changes which were applied.
*
* @param changes array of the applied changes
* @param changesInfo prepared list of {@link ChangeInfo}
* @param changes
* array of the applied changes
* @param changesInfo
* prepared list of {@link ChangeInfo}
*/
public void prepareChangesInfo(Change[] changes, List<ChangeInfo> changesInfo) {
for (Change ch : changes) {
Expand Down

0 comments on commit a108070

Please sign in to comment.