Skip to content

Commit

Permalink
Set and check if it's first time opening
Browse files Browse the repository at this point in the history
Issue: BMS-5074
Reviewer: Clary
  • Loading branch information
vmaletta committed Aug 29, 2018
1 parent 10f5d05 commit 1a62576
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
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 @@ -175,14 +175,10 @@ public void afterPropertiesSet() throws Exception {
public void updateButtons(final Object itemId) {
if (itemId instanceof String) {
// this means its the ROOT Folder
this.addFolderBtn.setEnabled(true);
this.renameFolderBtn.setEnabled(false);
this.deleteFolderBtn.setEnabled(false);
this.setButtonStatus(false);

} else if (this.studyTree.isFolder((Integer) itemId)) {
this.addFolderBtn.setEnabled(true);
this.renameFolderBtn.setEnabled(true);
this.deleteFolderBtn.setEnabled(true);
this.setButtonStatus(true);
// The rest of the local lists
} else {
this.addFolderBtn.setEnabled(true);
Expand All @@ -192,6 +188,12 @@ public void updateButtons(final Object itemId) {

}

public void setButtonStatus(final boolean b) {
this.addFolderBtn.setEnabled(true);
this.renameFolderBtn.setEnabled(b);
this.deleteFolderBtn.setEnabled(b);
}

protected Button getAddFolderBtn() {
return this.addFolderBtn;
}
Expand Down Expand Up @@ -232,4 +234,11 @@ protected void setStudyTree(final StudyTree studyTree) {
this.studyTree = studyTree;
}

public void updateButtons(final Object itemId, final boolean isFirstTimeOpening) {
if (isFirstTimeOpening) {
this.setButtonStatus(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

4 comments on commit 1a62576

@nahuel-soldevilla
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm, I'm not sure, it looks like a hack
Also, the setButtonStatus doesn't add to much value and perhaps even make it less readable. I would keep it inline.

@vmaletta

@vmaletta
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I could revert the setButtonStatus. What would you suggest to change the boolean? It's very creapy code

@nahuel-soldevilla
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure :(
Let's keep it, we can add a FIXME

@vmaletta
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good!

Please sign in to comment.