Skip to content

Commit

Permalink
Code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
artbez committed Mar 21, 2017
1 parent a5badfb commit 4aee01d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {DiagramElement} from "../model/DiagramElement";
import {SubprogramNode} from "../model/SubprogramNode";
import {Property} from "../model/Property";
import {NodeType} from "../model/NodeType";
import {Scroller} from "../model/Scroller";
import {Scroller, Direction} from "../model/Scroller";
import {DiagramElementListener} from "./DiagramElementListener";
import {SceneCommandFactory} from "../model/commands/SceneCommandFactory";
import {DiagramEditorController} from "./DiagramEditorController";
Expand Down Expand Up @@ -428,38 +428,38 @@ export class SceneController {
this.borderUnCrossed();
if (event.pageX + this.scene.getGridSize() * this.scene.getZoom() >= boundingBox.right) {
this.scroller.setDirection(Direction.Right);
this.borderCrossed(node, event);
this.borderCrossed(node, event, cellView);
} else if (event.pageX - this.scene.getGridSize() * this.scene.getZoom() <= boundingBox.left) {
this.scroller.setDirection(Direction.Left);
this.borderCrossed(node, event);
this.borderCrossed(node, event, cellView);
} else if (event.pageY + this.scene.getGridSize() * this.scene.getZoom() >= boundingBox.bottom) {
this.scroller.setDirection(Direction.Down);
this.borderCrossed(node, event);
this.borderCrossed(node, event, cellView);
} else if (event.pageY - this.scene.getGridSize() * this.scene.getZoom() <= boundingBox.top) {
this.scroller.setDirection(Direction.Up);
this.borderCrossed(node, event);
this.borderCrossed(node, event, cellView);
}
this.updateLastCellScrollPosition(event);
}

private borderCrossed(node: DiagramNode, event): void {
private borderCrossed(node: DiagramNode, event, cellView): void {
this.scroller.setScroll(true);
var that = this;
switch (this.scroller.getDirection()) {
case Direction.Right: {
this.scroller.setIntervalId(setInterval(() => that.scrollRight(node, event), 150));
this.scroller.setIntervalId(setInterval(() => that.scrollRight(node, event, cellView), 150));
break;
}
case Direction.Left: {
this.scroller.setIntervalId(setInterval(() => that.scrollLeft(node, event), 150));
this.scroller.setIntervalId(setInterval(() => that.scrollLeft(node, event, cellView), 150));
break;
}
case Direction.Down: {
this.scroller.setIntervalId(setInterval(() => that.scrollBottom(node, event), 150));
this.scroller.setIntervalId(setInterval(() => that.scrollBottom(node, event, cellView), 150));
break;
}
case Direction.Up: {
this.scroller.setIntervalId(setInterval(() => that.scrollTop(node, event), 150));
this.scroller.setIntervalId(setInterval(() => that.scrollTop(node, event, cellView), 150));
break;
}
}
Expand All @@ -474,36 +474,40 @@ export class SceneController {
}
}

private scrollRight(node: DiagramNode, event) : void {
private scrollRight(node: DiagramNode, event, cellView) : void {
var sceneWrapper : HTMLDivElement = (<HTMLDivElement> $(".scene-wrapper")[0]);
sceneWrapper.scrollLeft += this.scene.getGridSize() * this.scene.getZoom();
if (node.getX() + 3 * this.scene.getGridSize() <= DiagramScene.WIDTH) {
this.updateLastCellScrollPosition(event);
node.setPosition(this.lastCellScrollPosition.x, this.lastCellScrollPosition.y, this.scene.getZoom());
node.setPosition(this.lastCellScrollPosition.x,
this.lastCellScrollPosition.y, this.scene.getZoom(), cellView);
}
}

private scrollLeft(node: DiagramNode, event) : void {
private scrollLeft(node: DiagramNode, event, cellView) : void {
(<HTMLDivElement> $(".scene-wrapper")[0]).scrollLeft -= this.scene.getGridSize() * this.scene.getZoom();
if (node.getX() >= this.scene.getGridSize()) {
this.updateLastCellScrollPosition(event);
node.setPosition(this.lastCellScrollPosition.x, this.lastCellScrollPosition.y, this.scene.getZoom());
node.setPosition(this.lastCellScrollPosition.x,
this.lastCellScrollPosition.y, this.scene.getZoom(), cellView);
}
}

private scrollBottom(node: DiagramNode, event) : void {
private scrollBottom(node: DiagramNode, event, cellView) : void {
(<HTMLDivElement> $(".scene-wrapper")[0]).scrollTop += this.scene.getGridSize() * this.scene.getZoom();
if (node.getY() + 3 * this.scene.getGridSize() <= DiagramScene.HEIGHT) {
this.updateLastCellScrollPosition(event);
node.setPosition(this.lastCellScrollPosition.x, this.lastCellScrollPosition.y, this.scene.getZoom());
node.setPosition(this.lastCellScrollPosition.x,
this.lastCellScrollPosition.y, this.scene.getZoom(), cellView);
}
}

private scrollTop(node: DiagramNode, event) : void {
private scrollTop(node: DiagramNode, event, cellView) : void {
(<HTMLDivElement> $(".scene-wrapper")[0]).scrollTop -= this.scene.getGridSize() * this.scene.getZoom();
if (node.getY() >= this.scene.getGridSize()) {
this.updateLastCellScrollPosition(event);
node.setPosition(this.lastCellScrollPosition.x, this.lastCellScrollPosition.y, this.scene.getZoom());
node.setPosition(this.lastCellScrollPosition.x,
this.lastCellScrollPosition.y, this.scene.getZoom(), cellView);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
enum Direction {
export enum Direction {
Up, Down, Left, Right, None
}

class Scroller {
export class Scroller {

private scroll: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class DiagramMenuController {
}

public saveDiagramAs(): void {
$('#diagrams').modal('show');
this.showFolderMenu();
this.showFolderTable(this.currentFolder);
this.showSavingMenu();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.qreal.wmp.uitesting.headerpanel.folderwindow;

import com.codeborne.selenide.Condition;
import com.codeborne.selenide.Selectors;
import com.codeborne.selenide.SelenideElement;
import com.google.common.base.Predicate;
import org.openqa.selenium.By;
Expand All @@ -12,6 +11,7 @@
import java.util.function.Function;

import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Selectors.byText;
import static com.codeborne.selenide.Selenide.$;

/** {@inheritDoc} */
Expand Down Expand Up @@ -48,7 +48,7 @@ public FolderArea moveForward(String name) {
}
String oldPath = getCurrentPath();
oldPath = "".equals(oldPath) ? name : oldPath + "/" + name;
$(selector).find(By.className("folders")).find(Selectors.byText(name)).click();
$(selector).find(By.className("folders")).find(byText(name)).click();
waitUntilEquals(oldPath, FolderArea::getCurrentPath);
return this;
}
Expand Down Expand Up @@ -87,11 +87,11 @@ public FolderArea move(String path) {
@Override
public FolderArea deleteFolder(String name) {
if (!isFolderExist(name)) {
throw new NullPointerException("Folder is not exist");
throw new IllegalArgumentException("Folder is not exist");
}
$(selector).find(By.className("folders")).find(Selectors.byText(name)).contextClick();
$(selector).find(By.className("folders")).find(byText(name)).contextClick();
$(By.id("open-diagram-context-menu")).should(Condition.visible);
$(By.id("open-diagram-context-menu")).click();
$(By.id("open-diagram-context-menu")).find(byText("Delete")).click();
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.ArrayList;
import java.util.List;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AppInit.class, loader = AnnotationConfigContextLoader.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class SaveOpenDiaTest {

private static final Logger logger = LoggerFactory.getLogger(SaveOpenDiaTest.class);

@Autowired
private PageLoader pageLoader;

Expand All @@ -48,6 +46,7 @@ public class SaveOpenDiaTest {

private String diagram;

/** Opens editor page and add initial set of elements. */
@Before
public void openEditor() {
EditorPage editorPage = pageLoader.load(Page.EditorRobots);
Expand All @@ -64,12 +63,14 @@ public void saveDiagramTest() {
assert headerPanel.isDiagramExist(diagram);
}

@Test
public void openDiagramTest() {
headerPanel.newDiagram();
headerPanel.openDiagram(diagram);
assert headerPanel.equalsDiagrams(diagram);
}
/*
@Test
public void openDiagramTest() {
headerPanel.newDiagram();
headerPanel.openDiagram(diagram);
assert headerPanel.equalsDiagrams(diagram);
}
*/

@Test
public void equalsTrueTest() {
Expand Down

0 comments on commit 4aee01d

Please sign in to comment.