Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bms 5074 edit delete folder #221

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void addListeners() {
private static final long serialVersionUID = 1L;

@Override
public void buttonClick(ClickEvent event) {
public void buttonClick(final ClickEvent event) {
StudyBrowserMain.this.openBrowseForStudyWindow();
}
});
Expand All @@ -141,7 +141,7 @@ public void buttonClick(ClickEvent event) {
private static final long serialVersionUID = 1L;

@Override
public void buttonClick(ClickEvent event) {
public void buttonClick(final ClickEvent event) {
StudyBrowserMain.this.openSearchForStudyWindow();
}
});
Expand All @@ -154,7 +154,7 @@ public void layoutComponents() {

final HeaderLabelLayout headingLayout = new HeaderLabelLayout(StudyBrowserMain.STUDY_DETAILS_ICON, this.headingLabel);

HorizontalLayout directionLayout = new HorizontalLayout();
final HorizontalLayout directionLayout = new HorizontalLayout();
directionLayout.addStyleName("study-browser-main");
directionLayout.setHeight("16px");
directionLayout.setSpacing(true);
Expand Down Expand Up @@ -183,6 +183,7 @@ public void updateLabels() {
}

public void openBrowseForStudyWindow() {
this.browseTreeComponent.setFirstTimeOpening(true);
this.browseTreeComponent.refreshTree();
this.launchListSelectionWindow(this.getWindow(), this.browseTreeComponent, this.messageSource.getMessage(Message.BROWSE_STUDIES))
.addListener(this.browseTreeComponent.getSaveTreeStateListener());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class BrowseStudyTreeComponent extends VerticalLayout
private Map<Integer, Integer> parentChildItemIdMap;
private StudyTreeButtonsPanel buttonsPanel;
private StudyTypeFilterComponent studyTypeFilterComponent;
private boolean isFirstTimeOpening;

public BrowseStudyTreeComponent(final StudyBrowserMain studyBrowserMain) {
this.studyBrowserMain = studyBrowserMain;
Expand Down Expand Up @@ -261,7 +262,7 @@ private void buildChildMap(final Integer studyId, final Boolean endNode) {
}

public void updateButtons(final Object itemId) {
this.buttonsPanel.updateButtons(itemId);
this.buttonsPanel.updateButtons(itemId, this.isFirstTimeOpening);

}

Expand Down Expand Up @@ -350,4 +351,11 @@ protected void setButtonsPanel(final StudyTreeButtonsPanel buttonsPanel) {
this.buttonsPanel = buttonsPanel;
}

public boolean isFirstTimeOpening() {
return this.isFirstTimeOpening;
}

public void setFirstTimeOpening(final boolean firstTimeOpening) {
this.isFirstTimeOpening = firstTimeOpening;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,25 @@ public void addListeners() {

@Override
public void buttonClick(final Button.ClickEvent event) {
final Object selectedStudyTreeNodeId = StudyTreeButtonsPanel.this.studyTree.getValue();
final int studyId = Integer.valueOf(selectedStudyTreeNodeId.toString());
final Study study = StudyTreeButtonsPanel.this.studyDataManager.getStudy(studyId);
if (null == study.getProgramUUID()) {
if (StudyTreeButtonsPanel.this.getWindow() != null) {
MessageNotifier.showError(StudyTreeButtonsPanel.this.getWindow(),
if (StudyTreeButtonsPanel.this.studyTree != null && StudyTreeButtonsPanel.this.studyTree.getValue() != null) {
final Object selectedStudyTreeNodeId = StudyTreeButtonsPanel.this.studyTree.getValue();
final int studyId = Integer.valueOf(selectedStudyTreeNodeId.toString());
final Study study = StudyTreeButtonsPanel.this.studyDataManager.getStudy(studyId);
if (null == study.getProgramUUID()) {
if (StudyTreeButtonsPanel.this.getWindow() != null) {
MessageNotifier.showError(StudyTreeButtonsPanel.this.getWindow(),
StudyTreeButtonsPanel.this.messageSource.getMessage(Message.ERROR), "Program templates cannot be renamed.");
}
} else {
final String name = StudyTreeButtonsPanel.this.studyTree.getItemCaption(selectedStudyTreeNodeId);
StudyTreeButtonsPanel.this.browseTreeComponent.getParentComponent().getWindow()
.addWindow(new StudyTreeRenameItemWindow(
studyId, name, StudyTreeButtonsPanel.this.studyTree, StudyTreeButtonsPanel.this.studyTabSheet));
}
} else {
final String name = StudyTreeButtonsPanel.this.studyTree.getItemCaption(selectedStudyTreeNodeId);
StudyTreeButtonsPanel.this.browseTreeComponent.getParentComponent().getWindow().addWindow(new StudyTreeRenameItemWindow(
studyId, name, StudyTreeButtonsPanel.this.studyTree, StudyTreeButtonsPanel.this.studyTabSheet));
}
else {
MessageNotifier.showError(StudyTreeButtonsPanel.this.getWindow(),
StudyTreeButtonsPanel.this.messageSource.getMessage(Message.ERROR), "Please choose a Program folder.");
}
}
});
Expand All @@ -120,10 +127,16 @@ public void buttonClick(final Button.ClickEvent event) {

@Override
public void buttonClick(final Button.ClickEvent event) {
final int studyId = Integer.valueOf(StudyTreeButtonsPanel.this.studyTree.getValue().toString());
final StudyTreeDeleteItemHandler deleteHandler = new StudyTreeDeleteItemHandler(StudyTreeButtonsPanel.this.studyTree,
if (StudyTreeButtonsPanel.this.studyTree != null && StudyTreeButtonsPanel.this.studyTree.getValue() != null) {
final int studyId = Integer.valueOf(StudyTreeButtonsPanel.this.studyTree.getValue().toString());
final StudyTreeDeleteItemHandler deleteHandler = new StudyTreeDeleteItemHandler(StudyTreeButtonsPanel.this.studyTree,
StudyTreeButtonsPanel.this, StudyTreeButtonsPanel.this.browseTreeComponent.getParentComponent().getWindow());
deleteHandler.showConfirmDeletionDialog(studyId);
deleteHandler.showConfirmDeletionDialog(studyId);
}
else {
MessageNotifier.showError(StudyTreeButtonsPanel.this.getWindow(),
StudyTreeButtonsPanel.this.messageSource.getMessage(Message.ERROR), "Please choose a Program folder.");
}
}
});

Expand Down Expand Up @@ -219,4 +232,13 @@ protected void setStudyTree(final StudyTree studyTree) {
this.studyTree = studyTree;
}

public void updateButtons(final Object itemId, final boolean isFirstTimeOpening) {
if (isFirstTimeOpening) {
this.addFolderBtn.setEnabled(true);
this.renameFolderBtn.setEnabled(false);
this.deleteFolderBtn.setEnabled(false);
} else {
this.updateButtons(itemId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public void itemClick(final ItemClickEvent event) {
}

public void studyTreeItemClickAction(final Object itemId) {
this.browseStudyTreeComponent.setFirstTimeOpening(false);
this.studyTree.expandOrCollapseStudyTreeNode(itemId);
if (!StudyTree.STUDY_ROOT_NODE.equals(itemId)) {
final int studyId = Integer.valueOf(itemId.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void testCreateStudyInfoTabWhenStudyTabExists() {
public void testUpdateButtons() {
this.browseTreeComponent.setButtonsPanel(this.buttonsPanel);
this.browseTreeComponent.updateButtons(STUDY_ID);
Mockito.verify(this.buttonsPanel).updateButtons(STUDY_ID);
Mockito.verify(this.buttonsPanel).updateButtons(STUDY_ID, false);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public class StudyTreeItemClickListenerTest {
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
Mockito.doReturn(ClickEvent.BUTTON_LEFT).when(clickEvent).getButton();
Mockito.doReturn(STUDY_ID).when(clickEvent).getItemId();
Mockito.doReturn(ClickEvent.BUTTON_LEFT).when(this.clickEvent).getButton();
Mockito.doReturn(STUDY_ID).when(this.clickEvent).getItemId();
Mockito.doReturn(false).when(this.studyTree).hasChildStudy(STUDY_ID);
Mockito.doReturn(true).when(this.studyTree).hasChildStudy(FOLDER_ID);
Mockito.doReturn(false).when(this.studyTree).isFolder(STUDY_ID);
Expand All @@ -43,38 +43,36 @@ public void setup() {

@Test
public void testItemClickWhenRightClick() {
Mockito.doReturn(ClickEvent.BUTTON_RIGHT).when(clickEvent).getButton();
this.clickListener.itemClick(clickEvent);
Mockito.doReturn(ClickEvent.BUTTON_RIGHT).when(this.clickEvent).getButton();
this.clickListener.itemClick(this.clickEvent);
Mockito.verifyZeroInteractions(this.studyTree);
Mockito.verifyZeroInteractions(this.browseTreeComponent);
}

@Test
public void testItemClickWhenItemIsStudy(){
this.clickListener.itemClick(clickEvent);
this.clickListener.itemClick(this.clickEvent);
Mockito.verify(this.studyTree).expandOrCollapseStudyTreeNode(STUDY_ID);
Mockito.verify(this.browseTreeComponent).createStudyInfoTab(STUDY_ID);
Mockito.verify(this.studyTree).selectItem(STUDY_ID);
}

@Test
public void testItemClickWhenItemIsFolder(){
Mockito.doReturn(FOLDER_ID).when(clickEvent).getItemId();
this.clickListener.itemClick(clickEvent);
Mockito.doReturn(FOLDER_ID).when(this.clickEvent).getItemId();
this.clickListener.itemClick(this.clickEvent);
Mockito.verify(this.studyTree).expandOrCollapseStudyTreeNode(FOLDER_ID);
Mockito.verify(this.studyTree).selectItem(FOLDER_ID);
Mockito.verifyZeroInteractions(this.browseTreeComponent);
}

@Test
public void testItemClickWhenItemIsRootNode(){
Mockito.doReturn(StudyTree.STUDY_ROOT_NODE).when(clickEvent).getItemId();
this.clickListener.itemClick(clickEvent);
Mockito.doReturn(StudyTree.STUDY_ROOT_NODE).when(this.clickEvent).getItemId();
this.clickListener.itemClick(this.clickEvent);
Mockito.verify(this.studyTree).expandOrCollapseStudyTreeNode(StudyTree.STUDY_ROOT_NODE);
Mockito.verify(this.studyTree).selectItem(StudyTree.STUDY_ROOT_NODE);
Mockito.verify(this.studyTree, Mockito.never()).hasChildStudy(Matchers.anyInt());
Mockito.verify(this.studyTree, Mockito.never()).isFolder(Matchers.anyInt());
Mockito.verifyZeroInteractions(this.browseTreeComponent);
}

}