1 /*
2  * SVNResolveDialog.java
3  *
4  * Copyright (C) 2021 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant
7  * to the terms of a commercial license agreement with RStudio, then
8  * this program is licensed to you under the terms of version 3 of the
9  * GNU Affero General Public License. This program is distributed WITHOUT
10  * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
11  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
12  * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
13  *
14  */
15 package org.rstudio.studio.client.workbench.views.vcs.svn;
16 
17 import com.google.gwt.aria.client.Id;
18 import com.google.gwt.aria.client.Roles;
19 import com.google.gwt.core.client.GWT;
20 import com.google.gwt.dom.client.DivElement;
21 import com.google.gwt.dom.client.InputElement;
22 import com.google.gwt.dom.client.LabelElement;
23 import com.google.gwt.dom.client.SpanElement;
24 import com.google.gwt.dom.client.TableCellElement;
25 import com.google.gwt.dom.client.TableElement;
26 import com.google.gwt.uibinder.client.UiBinder;
27 import com.google.gwt.uibinder.client.UiField;
28 import com.google.gwt.user.client.ui.HTMLPanel;
29 import com.google.gwt.user.client.ui.Widget;
30 import org.rstudio.core.client.ElementIds;
31 import org.rstudio.core.client.widget.ModalDialog;
32 import org.rstudio.core.client.widget.OperationWithInput;
33 
34 public class SVNResolveDialog extends ModalDialog<String>
35 {
36    interface Binder extends UiBinder<HTMLPanel, SVNResolveDialog>
37    {}
38 
SVNResolveDialog(int fileCount, String caption, OperationWithInput<String> operation)39    public SVNResolveDialog(int fileCount,
40                            String caption,
41                            OperationWithInput<String> operation)
42    {
43       super(caption, Roles.getDialogRole(), operation);
44       fileCount_ = fileCount;
45    }
46 
47    @Override
collectInput()48    protected String collectInput()
49    {
50       for (InputElement el : inputElements_)
51       {
52          if (el.isChecked())
53             return el.getValue();
54       }
55 
56       return null;
57    }
58 
59    @Override
validate(String input)60    protected boolean validate(String input)
61    {
62       return input != null;
63    }
64 
65    @Override
createMainWidget()66    protected Widget createMainWidget()
67    {
68       HTMLPanel widget = GWT.<Binder>create(Binder.class).createAndBindUi(this);
69 
70       ElementIds.assignElementId(groupLabel_, ElementIds.SVN_RESOLVE_GROUP);
71       Roles.getGroupRole().set(layoutTable_);
72       Roles.getGroupRole().setAriaLabelledbyProperty(layoutTable_, Id.of(groupLabel_));
73 
74       inputElements_ = new InputElement[] {
75             radioWorking_,
76             radioMineConflict_,
77             radioTheirsConflict_,
78             radioMineAll_,
79             radioTheirsAll_,
80       };
81 
82       spanTargetNoun_.setInnerText(fileCount_ == 1 ? "path" : "paths");
83 
84       ElementIds.assignElementId(radioWorking_, ElementIds.SVN_RESOLVE_MINE);
85       ElementIds.assignElementId(descriptionWorking_, ElementIds.SVN_RESOLVE_MINE_DESC);
86       Roles.getRadioRole().setAriaDescribedbyProperty(radioWorking_, Id.of(descriptionWorking_));
87 
88       ElementIds.assignElementId(radioMineConflict_, ElementIds.SVN_RESOLVE_MINE_CONFLICT);
89       ElementIds.assignElementId(descriptionMineConflict_, ElementIds.SVN_RESOLVE_MINE_CONFLICT_DESC);
90       Roles.getRadioRole().setAriaDescribedbyProperty(radioMineConflict_, Id.of(descriptionMineConflict_));
91 
92       ElementIds.assignElementId(radioTheirsConflict_, ElementIds.SVN_RESOLVE_THEIRS_CONFLICT);
93       ElementIds.assignElementId(descriptionTheirsConflict_, ElementIds.SVN_RESOLVE_THEIRS_CONFLICT_DESC);
94       Roles.getRadioRole().setAriaDescribedbyProperty(radioTheirsConflict_, Id.of(descriptionTheirsConflict_));
95 
96       ElementIds.assignElementId(radioMineAll_, ElementIds.SVN_RESOLVE_MINE_ALL);
97       ElementIds.assignElementId(descriptionMineAll_, ElementIds.SVN_RESOLVE_MINE_ALL_DESC);
98       Roles.getRadioRole().setAriaDescribedbyProperty(radioMineAll_, Id.of(descriptionMineAll_));
99 
100       ElementIds.assignElementId(radioTheirsAll_, ElementIds.SVN_RESOLVE_THEIRS_ALL);
101       ElementIds.assignElementId(descriptionTheirsAll_, ElementIds.SVN_RESOLVE_THEIRS_ALL_DESC);
102       Roles.getRadioRole().setAriaDescribedbyProperty(radioTheirsAll_, Id.of(descriptionTheirsAll_));
103 
104       labelWorking_.setAttribute("for", radioWorking_.getId());
105       labelMineConflict_.setAttribute("for", radioMineConflict_.getId());
106       labelTheirsConflict_.setAttribute("for", radioTheirsConflict_.getId());
107       labelMineAll_.setAttribute("for", radioMineAll_.getId());
108       labelTheirsAll_.setAttribute("for", radioTheirsAll_.getId());
109 
110       return widget;
111    }
112 
113    @UiField DivElement groupLabel_;
114    @UiField SpanElement spanTargetNoun_;
115    @UiField TableElement layoutTable_;
116 
117    @UiField InputElement radioWorking_;
118    @UiField LabelElement labelWorking_;
119    @UiField TableCellElement descriptionWorking_;
120 
121    @UiField InputElement radioMineConflict_;
122    @UiField LabelElement labelMineConflict_;
123    @UiField TableCellElement descriptionMineConflict_;
124 
125    @UiField InputElement radioTheirsConflict_;
126    @UiField LabelElement labelTheirsConflict_;
127    @UiField TableCellElement descriptionTheirsConflict_;
128 
129    @UiField InputElement radioMineAll_;
130    @UiField LabelElement labelMineAll_;
131    @UiField TableCellElement descriptionMineAll_;
132 
133    @UiField InputElement radioTheirsAll_;
134    @UiField LabelElement labelTheirsAll_;
135    @UiField TableCellElement descriptionTheirsAll_;
136 
137    private final int fileCount_;
138    private InputElement[] inputElements_;
139 }
140