This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
/
RepositoryEditorView.java
199 lines (168 loc) · 6.66 KB
/
RepositoryEditorView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
* Copyright 2012 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.guvnor.structure.client.editors.repository.edit;
import java.util.List;
import javax.annotation.PostConstruct;
import com.github.gwtbootstrap.client.ui.Button;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.InlineHTML;
import com.google.gwt.user.client.ui.RequiresResize;
import com.google.gwt.user.client.ui.Widget;
import org.guvnor.structure.client.navigator.CommitNavigator;
import org.guvnor.structure.client.resources.i18n.CommonConstants;
import org.guvnor.structure.repositories.PublicURI;
import org.uberfire.ext.widgets.common.client.common.BusyPopup;
import org.uberfire.ext.widgets.core.client.resources.i18n.CoreConstants;
import org.uberfire.java.nio.base.version.VersionRecord;
import org.uberfire.mvp.ParameterizedCommand;
public class RepositoryEditorView extends Composite
implements
RequiresResize,
RepositoryEditorPresenter.View {
interface RepositoryEditorViewBinder
extends
UiBinder<Widget, RepositoryEditorView> {
}
private static RepositoryEditorViewBinder uiBinder = GWT.create( RepositoryEditorViewBinder.class );
@UiField
public InlineHTML ownerReference;
@UiField
public InlineHTML repoName;
@UiField
public InlineHTML repoDesc;
@UiField
public InlineHTML gitDaemonURI;
@UiField
public Button myGitCopyButton;
@UiField
public FlowPanel linksPanel;
@UiField
public FlowPanel history;
@UiField
public Button loadMore;
private CommitNavigator commitNavigator = null;
private RepositoryEditorPresenter presenter;
@PostConstruct
public void init() {
initWidget( uiBinder.createAndBindUi( this ) );
}
@Override
public void init( final RepositoryEditorPresenter presenter ) {
this.presenter = presenter;
}
public void setRepositoryInfo( final String repositoryName,
final String owner,
final List<PublicURI> publicURIs,
final String description,
final List<VersionRecord> initialVersionList ) {
if ( owner != null && !owner.isEmpty() ) {
ownerReference.setText( owner + " / " );
}
repoName.setText( repositoryName );
repoDesc.setText( description );
int count = 0;
if ( publicURIs.size() > 0 ) {
linksPanel.add( new InlineHTML() {{
setText( CoreConstants.INSTANCE.AvailableProtocols() );
getElement().getStyle().setPaddingLeft( 10, Style.Unit.PX );
}} );
}
for ( final PublicURI publicURI : publicURIs ) {
if ( count == 0 ) {
gitDaemonURI.setText( publicURI.getURI() );
}
final String protocol = publicURI.getProtocol() == null ? "default" : publicURI.getProtocol();
final Anchor anchor = new Anchor( protocol );
anchor.addClickHandler( new ClickHandler() {
@Override
public void onClick( ClickEvent event ) {
gitDaemonURI.setText( publicURI.getURI() );
}
} );
if ( count != 0 ) {
anchor.getElement().getStyle().setPaddingLeft( 5, Style.Unit.PX );
}
linksPanel.add( anchor );
count++;
}
if ( initialVersionList != null && !initialVersionList.isEmpty() ) {
commitNavigator = new CommitNavigator() {{
setOnRevertCommand( new ParameterizedCommand<VersionRecord>() {
@Override
public void execute( final VersionRecord record ) {
BusyPopup.showMessage( CoreConstants.INSTANCE.Reverting() );
presenter.revert( record );
}
} );
loadContent( initialVersionList );
}};
history.add( commitNavigator );
} else {
history.setVisible( false );
}
loadMore.addClickHandler( new ClickHandler() {
@Override
public void onClick( ClickEvent event ) {
if ( commitNavigator != null ) {
presenter.getLoadMoreHistory( commitNavigator.getLastIndex() );
}
}
} );
final String uriId = "uri-for-" + repositoryName;
gitDaemonURI.getElement().setId( uriId );
myGitCopyButton.getElement().setAttribute( "data-clipboard-target", uriId );
myGitCopyButton.getElement().setAttribute( "data-clipboard-text", gitDaemonURI.getText() );
myGitCopyButton.getElement().setId( "button-" + uriId );
myGitCopyButton.getElement().setTitle( CommonConstants.INSTANCE.copyRepositoryUrl() );
glueCopy( myGitCopyButton.getElement() );
}
@Override
public void reloadHistory( final List<VersionRecord> versionList ) {
commitNavigator.loadContent( versionList );
BusyPopup.close();
}
@Override
public void addHistory( List<VersionRecord> versionList ) {
if ( commitNavigator != null ) {
if ( !versionList.isEmpty() ) {
commitNavigator.addContent( versionList );
} else {
loadMore.setEnabled( false );
}
}
}
@Override
public void clear() {
}
@Override
public void onResize() {
int height = getParent().getOffsetHeight();
int width = getParent().getOffsetWidth();
setPixelSize( width, height );
}
public static native void glueCopy( final Element element ) /*-{
var clip = new $wnd.ZeroClipboard(element);
}-*/;
}