1 /*******************************************************************************
2 * Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.eclipse
.egit
.ui
.internal
.components
;
12 import java
.util
.Collections
;
13 import java
.util
.List
;
15 import org
.eclipse
.jgit
.transport
.RemoteConfig
;
16 import org
.eclipse
.jgit
.transport
.URIish
;
19 * Data class representing selection of remote repository made by user.
20 * Selection is an URI or remote repository configuration.
22 * Each immutable instance has at least one of two class fields (URI, remote
23 * config) set to null. null value indicates that it has illegal value or this
24 * form of repository selection is not selected.
26 * If remote configuration is selected, it always has non-empty URIs list.
28 public class RepositorySelection
{
31 private RemoteConfig config
;
33 static final RepositorySelection INVALID_SELECTION
= new RepositorySelection(
38 * the new specified URI. null if the new URI is invalid or user
39 * chosen to specify repository as remote config instead of URI.
41 * the new remote config. null if user chosen to specify
44 public RepositorySelection(final URIish uri
, final RemoteConfig config
) {
45 if (config
!= null && uri
!= null)
46 throw new IllegalArgumentException(
47 "URI and config cannot be set at the same time."); //$NON-NLS-1$
53 * @return the selected URI (if specified by user as valid custom URI) or
54 * first URI from selected configuration (if specified by user as
55 * May be null if there is no valid selection.
57 public URIish
getURI() {
58 if (isConfigSelected())
59 return config
.getURIs().get(0);
64 * @return list of all selected URIs - either the one specified as custom
65 * URI or all URIs from selected configuration. May be null in case
66 * of no valid selection.
68 public List
<URIish
> getAllURIs() {
70 return Collections
.singletonList(uri
);
71 if (isConfigSelected())
72 return config
.getURIs();
77 * @return list of all selected URIs - either the one specified as custom
78 * URI or all URIs from selected configuration. May be null in case
79 * of no valid selection.
81 public List
<URIish
> getPushURIs() {
83 return Collections
.singletonList(uri
);
84 if (isConfigSelected())
85 return config
.getPushURIs();
90 * @return the selected remote configuration. null if user chosen to select
93 public RemoteConfig
getConfig() {
98 * @return selected remote configuration name or null if selection is not a
99 * remote configuration.
101 public String
getConfigName() {
102 if (isConfigSelected())
103 return config
.getName();
108 * @return true if selection contains valid URI or remote config, false if
109 * there is no valid selection.
111 public boolean isValidSelection() {
112 return uri
!= null || config
!= null;
116 * @return true if user selected valid URI, false if user selected invalid
117 * URI or remote config.
119 public boolean isURISelected() {
124 * @return true if user selected remote configuration, false if user
125 * selected (invalid or valid) URI.
127 public boolean isConfigSelected() {
128 return config
!= null;
132 public boolean equals(final Object obj
) {
133 if (obj
instanceof RepositorySelection
) {
134 final RepositorySelection other
= (RepositorySelection
) obj
;
135 if (uri
== null ^ other
.uri
== null)
137 if (uri
!= null && !uri
.equals(other
.uri
))
140 if (config
!= other
.config
)